1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Broad superficial changes:

* Renamed getOpcode to getOpcodeName
* Changed getOpcodeName to return a const char * instead of string
* Added a getOpcode method to replace getInstType
* Changed code to use getOpcode instead of getInstType

llvm-svn: 152
This commit is contained in:
Chris Lattner 2001-07-07 19:24:15 +00:00
parent cd5bbb0001
commit c00392210d
16 changed files with 73 additions and 66 deletions

View File

@ -30,7 +30,7 @@ public:
// Terminators must implement the methods required by Instruction...
virtual Instruction *clone() const = 0;
virtual string getOpcode() const = 0;
virtual const char *getOpcodeName() const = 0;
// Additionally, they must provide a method to get at the successors of this
// terminator instruction. If 'idx' is out of range, a null pointer shall be
@ -64,10 +64,10 @@ public:
}
virtual Instruction *clone() const {
return create(getInstType(), Operands[0]);
return create(getOpcode(), Operands[0]);
}
virtual string getOpcode() const = 0;
virtual const char *getOpcodeName() const = 0;
};
@ -96,10 +96,10 @@ public:
}
virtual Instruction *clone() const {
return create(getInstType(), Operands[0], Operands[1]);
return create(getOpcode(), Operands[0], Operands[1]);
}
virtual string getOpcode() const = 0;
virtual const char *getOpcodeName() const = 0;
};
#endif

View File

@ -45,9 +45,12 @@ public:
// Subclass classification... getInstType() returns a member of
// one of the enums that is coming soon (down below)...
//
virtual string getOpcode() const = 0;
virtual const char *getOpcodeName() const = 0;
unsigned getOpcode() const { return iType; }
// getInstType is deprecated, use getOpcode() instead.
unsigned getInstType() const { return iType; }
inline bool isTerminator() const { // Instance of TerminatorInst?
return iType >= FirstTermOp && iType < NumTermOps;
}

View File

@ -46,7 +46,7 @@ public:
return new MallocInst(getType(), Operands.size() ? Operands[1] : 0);
}
virtual string getOpcode() const { return "malloc"; }
virtual const char *getOpcodeName() const { return "malloc"; }
};
class AllocaInst : public AllocationInst {
@ -58,7 +58,7 @@ public:
return new AllocaInst(getType(), Operands.size() ? Operands[1] : 0);
}
virtual string getOpcode() const { return "alloca"; }
virtual const char *getOpcodeName() const { return "alloca"; }
};
@ -75,7 +75,7 @@ public:
virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
virtual string getOpcode() const { return "free"; }
virtual const char *getOpcodeName() const { return "free"; }
};
#endif // LLVM_IMEMORY_H

View File

@ -17,15 +17,13 @@
//
class GenericBinaryInst : public BinaryOperator {
const char *OpcodeString;
public:
GenericBinaryInst(unsigned Opcode, Value *S1, Value *S2,
const char *OpcodeStr, const string &Name = "")
const string &Name = "")
: BinaryOperator(Opcode, S1, S2, Name) {
OpcodeString = OpcodeStr;
}
virtual string getOpcode() const { return OpcodeString; }
virtual const char *getOpcodeName() const;
};
class SetCondInst : public BinaryOperator {
@ -34,7 +32,7 @@ public:
SetCondInst(BinaryOps opType, Value *S1, Value *S2,
const string &Name = "");
virtual string getOpcode() const;
virtual const char *getOpcodeName() const;
};
#endif

View File

@ -26,7 +26,7 @@ public:
PHINode(const Type *Ty, const string &Name = "");
virtual Instruction *clone() const { return new PHINode(*this); }
virtual string getOpcode() const { return "phi"; }
virtual const char *getOpcodeName() const { return "phi"; }
// getNumIncomingValues - Return the number of incoming edges the PHI node has
inline unsigned getNumIncomingValues() const { return Operands.size()/2; }
@ -89,7 +89,7 @@ class CallInst : public Instruction {
public:
CallInst(Method *M, vector<Value*> &params, const string &Name = "");
virtual string getOpcode() const { return "call"; }
virtual const char *getOpcodeName() const { return "call"; }
virtual Instruction *clone() const { return new CallInst(*this); }
bool hasSideEffects() const { return true; }

View File

@ -41,7 +41,7 @@ public:
virtual Instruction *clone() const { return new ReturnInst(*this); }
virtual string getOpcode() const { return "ret"; }
virtual const char *getOpcodeName() const { return "ret"; }
inline const Value *getReturnValue() const {
return Operands.size() ? Operands[0] : 0;
@ -81,7 +81,7 @@ public:
return isUnconditional() ? 0 : Operands[2];
}
virtual string getOpcode() const { return "br"; }
virtual const char *getOpcodeName() const { return "br"; }
// setUnconditionalDest - Change the current branch to an unconditional branch
// targeting the specified block.
@ -135,7 +135,7 @@ public:
void dest_push_back(ConstPoolVal *OnVal, BasicBlock *Dest);
virtual string getOpcode() const { return "switch"; }
virtual const char *getOpcodeName() const { return "switch"; }
// Additionally, they must provide a method to get at the successors of this
// terminator instruction. If 'idx' is out of range, a null pointer shall be

View File

@ -118,7 +118,7 @@ struct InstPlaceHolderHelper : public Instruction {
InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {}
virtual Instruction *clone() const { abort(); }
virtual string getOpcode() const { return "placeholder"; }
virtual const char *getOpcodeName() const { return "placeholder"; }
};
struct BBPlaceHolderHelper : public BasicBlock {

View File

@ -94,7 +94,7 @@ public:
struct InstPlaceHolderHelper : public Instruction {
InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {}
virtual string getOpcode() const { return "placeholder"; }
virtual const char *getOpcodeName() const { return "placeholder"; }
virtual Instruction *clone() const { abort(); return 0; }
};

View File

@ -29,7 +29,7 @@ static void outputInstructionFormat0(const Instruction *I,
const SlotCalculator &Table,
unsigned Type, vector<uchar> &Out) {
// Opcode must have top two bits clear...
output_vbr(I->getInstType(), Out); // Instruction Opcode ID
output_vbr(I->getOpcode(), Out); // Instruction Opcode ID
output_vbr(Type, Out); // Result type
unsigned NumArgs = I->getNumOperands();
@ -51,7 +51,7 @@ static void outputInstructionFormat0(const Instruction *I,
static void outputInstructionFormat1(const Instruction *I,
const SlotCalculator &Table, int *Slots,
unsigned Type, vector<uchar> &Out) {
unsigned IType = I->getInstType(); // Instruction Opcode ID
unsigned IType = I->getOpcode(); // Instruction Opcode ID
// bits Instruction format:
// --------------------------
@ -72,7 +72,7 @@ static void outputInstructionFormat1(const Instruction *I,
static void outputInstructionFormat2(const Instruction *I,
const SlotCalculator &Table, int *Slots,
unsigned Type, vector<uchar> &Out) {
unsigned IType = I->getInstType(); // Instruction Opcode ID
unsigned IType = I->getOpcode(); // Instruction Opcode ID
// bits Instruction format:
// --------------------------
@ -96,7 +96,7 @@ static void outputInstructionFormat2(const Instruction *I,
static void outputInstructionFormat3(const Instruction *I,
const SlotCalculator &Table, int *Slots,
unsigned Type, vector<uchar> &Out) {
unsigned IType = I->getInstType(); // Instruction Opcode ID
unsigned IType = I->getOpcode(); // Instruction Opcode ID
// bits Instruction format:
// --------------------------
@ -115,7 +115,7 @@ static void outputInstructionFormat3(const Instruction *I,
}
bool BytecodeWriter::processInstruction(const Instruction *I) {
assert(I->getInstType() < 64 && "Opcode too big???");
assert(I->getOpcode() < 64 && "Opcode too big???");
unsigned NumOperands = I->getNumOperands();
int MaxOpSlot = 0;
@ -136,8 +136,8 @@ bool BytecodeWriter::processInstruction(const Instruction *I) {
// we take the type of the instruction itself.
//
const Type *Ty = NumOperands ? I->getOperand(0)->getType() : I->getType();
if (I->getInstType() == Instruction::Malloc ||
I->getInstType() == Instruction::Alloca)
if (I->getOpcode() == Instruction::Malloc ||
I->getOpcode() == Instruction::Alloca)
Ty = I->getType(); // Malloc & Alloca ALWAYS want to encode the return type
unsigned Type;

View File

@ -63,7 +63,7 @@ static inline void RemapInstruction(Instruction *I,
// method by one level.
//
bool opt::InlineMethod(BasicBlock::iterator CIIt) {
assert((*CIIt)->getInstType() == Instruction::Call &&
assert((*CIIt)->getOpcode() == Instruction::Call &&
"InlineMethod only works on CallInst nodes!");
assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
assert((*CIIt)->getParent()->getParent() && "Instruction not in method!");
@ -149,7 +149,7 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) {
}
// Copy over the terminator now...
switch (TI->getInstType()) {
switch (TI->getOpcode()) {
case Instruction::Ret: {
const ReturnInst *RI = (const ReturnInst*)TI;
@ -209,7 +209,7 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) {
// block of the inlined method.
//
TerminatorInst *Br = OrigBB->getTerminator();
assert(Br && Br->getInstType() == Instruction::Br &&
assert(Br && Br->getOpcode() == Instruction::Br &&
"splitBasicBlock broken!");
Br->setOperand(0, ValueMap[CalledMeth->front()]);
@ -249,7 +249,7 @@ static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) {
static inline bool DoMethodInlining(BasicBlock *BB) {
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
if ((*I)->getInstType() == Instruction::Call) {
if ((*I)->getOpcode() == Instruction::Call) {
// Check to see if we should inline this method
CallInst *CI = (CallInst*)*I;
Method *M = CI->getCalledMethod();

View File

@ -73,7 +73,7 @@ inline static bool
ConstantFoldUnaryInst(Method *M, Method::inst_iterator &DI,
UnaryOperator *Op, ConstPoolVal *D) {
ConstPoolVal *ReplaceWith =
opt::ConstantFoldUnaryInstruction(Op->getInstType(), D);
opt::ConstantFoldUnaryInstruction(Op->getOpcode(), D);
if (!ReplaceWith) return false; // Nothing new to change...
@ -100,7 +100,7 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
BinaryOperator *Op,
ConstPoolVal *D1, ConstPoolVal *D2) {
ConstPoolVal *ReplaceWith =
opt::ConstantFoldBinaryInstruction(Op->getInstType(), D1, D2);
opt::ConstantFoldBinaryInstruction(Op->getOpcode(), D1, D2);
if (!ReplaceWith) return false; // Nothing new to change...
// Add the new value to the constant pool...
@ -126,7 +126,7 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
//
bool opt::ConstantFoldTerminator(TerminatorInst *T) {
// Branch - See if we are conditional jumping on constant
if (T->getInstType() == Instruction::Br) {
if (T->getOpcode() == Instruction::Br) {
BranchInst *BI = (BranchInst*)T;
if (BI->isUnconditional()) return false; // Can't optimize uncond branch
BasicBlock *Dest1 = BI->getOperand(0)->castBasicBlockAsserting();

View File

@ -78,7 +78,7 @@ static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V,
// loop variant computations must be instructions!
Instruction *I = V->castInstructionAsserting();
switch (I->getInstType()) { // Handle each instruction seperately
switch (I->getOpcode()) { // Handle each instruction seperately
case Instruction::Neg: {
Value *SubV = ((UnaryOperator*)I)->getOperand(0);
LIVType SubLIVType = isLinearInductionVariableH(Int, SubV, PN);
@ -107,12 +107,12 @@ static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V,
// either a Loop Invariant computation, or a LIV type.
if (SubLIVType1 == isLIC) {
// Loop invariant computation, we know this is a LIV then.
return (I->getInstType() == Instruction::Add) ?
return (I->getOpcode() == Instruction::Add) ?
SubLIVType2 : neg(SubLIVType2);
}
// If the LHS is also a LIV Expression, we cannot add two LIVs together
if (I->getInstType() == Instruction::Add) return isOther;
if (I->getOpcode() == Instruction::Add) return isOther;
// We can only subtract two LIVs if they are the same type, which yields
// a LIC, because the LIVs cancel each other out.
@ -155,7 +155,7 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
Value *StepExpr = PN->getIncomingValue(1);
if (!StepExpr->isInstruction() ||
((Instruction*)StepExpr)->getInstType() != Instruction::Add)
((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
return false;
BinaryOperator *I = (BinaryOperator*)StepExpr;

View File

@ -307,7 +307,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
if (IValue.isOverdefined())
return; // If already overdefined, we aren't going to effect anything
switch (I->getInstType()) {
switch (I->getOpcode()) {
//===-----------------------------------------------------------------===//
// Handle PHI nodes...
//
@ -424,7 +424,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
}
default: break; // Handle math operators as groups.
} // end switch(I->getInstType())
} // end switch(I->getOpcode())
//===-------------------------------------------------------------------===//
@ -437,7 +437,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
markOverdefined(I);
} else if (VState.isConstant()) { // Propogate constant value
ConstPoolVal *Result =
opt::ConstantFoldUnaryInstruction(I->getInstType(),
opt::ConstantFoldUnaryInstruction(I->getOpcode(),
VState.getConstant());
if (Result) {
@ -466,7 +466,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
markOverdefined(I);
} else if (V1State.isConstant() && V2State.isConstant()) {
ConstPoolVal *Result =
opt::ConstantFoldBinaryInstruction(I->getInstType(),
opt::ConstantFoldBinaryInstruction(I->getOpcode(),
V1State.getConstant(),
V2State.getConstant());
if (Result) {

View File

@ -25,7 +25,7 @@ BasicBlock *cfg::UnifyAllExitNodes(Method *M) {
// return.
//
for(Method::iterator I = M->begin(), E = M->end(); I != E; ++I)
if ((*I)->getTerminator()->getInstType() == Instruction::Ret)
if ((*I)->getTerminator()->getOpcode() == Instruction::Ret)
ReturningBlocks.push_back(*I);
if (ReturningBlocks.size() == 0)

View File

@ -154,20 +154,20 @@ bool AssemblyWriter::processInstruction(const Instruction *I) {
Out << "%" << I->getName() << " = ";
// Print out the opcode...
Out << I->getOpcode();
Out << I->getOpcodeName();
// Print out the type of the operands...
const Value *Operand = I->getNumOperands() ? I->getOperand(0) : 0;
// Special case conditional branches to swizzle the condition out to the front
if (I->getInstType() == Instruction::Br && I->getNumOperands() > 1) {
if (I->getOpcode() == Instruction::Br && I->getNumOperands() > 1) {
writeOperand(I->getOperand(2), true);
Out << ",";
writeOperand(Operand, true);
Out << ",";
writeOperand(I->getOperand(1), true);
} else if (I->getInstType() == Instruction::Switch) {
} else if (I->getOpcode() == Instruction::Switch) {
// Special case switch statement to get formatting nice and correct...
writeOperand(Operand , true); Out << ",";
writeOperand(I->getOperand(1), true); Out << " [";
@ -188,9 +188,9 @@ bool AssemblyWriter::processInstruction(const Instruction *I) {
writeOperand(I->getOperand(op ), false); Out << ",";
writeOperand(I->getOperand(op+1), false); Out << " ]";
}
} else if (I->getInstType() == Instruction::Ret && !Operand) {
} else if (I->getOpcode() == Instruction::Ret && !Operand) {
Out << " void";
} else if (I->getInstType() == Instruction::Call) {
} else if (I->getOpcode() == Instruction::Call) {
writeOperand(Operand, true);
Out << "(";
if (I->getNumOperands() > 1) writeOperand(I->getOperand(1), true);
@ -200,8 +200,8 @@ bool AssemblyWriter::processInstruction(const Instruction *I) {
}
Out << " )";
} else if (I->getInstType() == Instruction::Malloc ||
I->getInstType() == Instruction::Alloca) {
} else if (I->getOpcode() == Instruction::Malloc ||
I->getOpcode() == Instruction::Alloca) {
Out << " " << ((const PointerType*)I->getType())->getValueType();
if (I->getNumOperands()) {
Out << ",";

View File

@ -10,25 +10,31 @@
BinaryOperator *BinaryOperator::create(unsigned Op, Value *S1, Value *S2,
const string &Name) {
switch (Op) {
// Standard binary operators...
case Add: return new GenericBinaryInst(Op, S1, S2, "add", Name);
case Sub: return new GenericBinaryInst(Op, S1, S2, "sub", Name);
case Mul: return new GenericBinaryInst(Op, S1, S2, "mul", Name);
case Div: return new GenericBinaryInst(Op, S1, S2, "div", Name);
case Rem: return new GenericBinaryInst(Op, S1, S2, "rem", Name);
// Logical operators...
case And: return new GenericBinaryInst(Op, S1, S2, "and", Name);
case Or : return new GenericBinaryInst(Op, S1, S2, "or", Name);
case Xor: return new GenericBinaryInst(Op, S1, S2, "xor", Name);
// Binary comparison operators...
case SetLT: case SetGT: case SetLE:
case SetGE: case SetEQ: case SetNE:
return new SetCondInst((BinaryOps)Op, S1, S2, Name);
default:
cerr << "Don't know how to GetBinaryOperator " << Op << endl;
return new GenericBinaryInst(Op, S1, S2, Name);
}
}
const char *GenericBinaryInst::getOpcodeName() const {
switch (getOpcode()) {
// Standard binary operators...
case Add: return "add";
case Sub: return "sub";
case Mul: return "mul";
case Div: return "div";
case Rem: return "rem";
// Logical operators...
case And: return "and";
case Or : return "or";
case Xor: return "xor";
default:
cerr << "Invalid binary operator type!" << getOpcode() << endl;
return 0;
}
}
@ -45,10 +51,10 @@ SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2,
setType(Type::BoolTy); // setcc instructions always return bool type.
// Make sure it's a valid type...
assert(getOpcode() != "Invalid opcode type to SetCondInst class!");
assert(getOpcodeName() != 0);
}
string SetCondInst::getOpcode() const {
const char *SetCondInst::getOpcodeName() const {
switch (OpType) {
case SetLE: return "setle";
case SetGE: return "setge";