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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h
index 086cc35..105775f 100644
--- a/include/llvm/InstrTypes.h
+++ b/include/llvm/InstrTypes.h
@@ -30,7 +30,7 @@
// 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 @@
}
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 @@
}
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
diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h
index 7066523..96f2637 100644
--- a/include/llvm/Instruction.h
+++ b/include/llvm/Instruction.h
@@ -45,9 +45,12 @@
// 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;
}
diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h
index fafe4c3..0ef3ee1 100644
--- a/include/llvm/iMemory.h
+++ b/include/llvm/iMemory.h
@@ -46,7 +46,7 @@
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 @@
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 @@
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
diff --git a/include/llvm/iOperators.h b/include/llvm/iOperators.h
index 99e4bf3..76e4e39 100644
--- a/include/llvm/iOperators.h
+++ b/include/llvm/iOperators.h
@@ -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 @@
SetCondInst(BinaryOps opType, Value *S1, Value *S2,
const string &Name = "");
- virtual string getOpcode() const;
+ virtual const char *getOpcodeName() const;
};
#endif
diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h
index f6cdcf9..ebd6475 100644
--- a/include/llvm/iOther.h
+++ b/include/llvm/iOther.h
@@ -26,7 +26,7 @@
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 @@
public:
CallInst(Method *M, vector<Value*> ¶ms, 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; }
diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h
index 9dbaf7b..d43c7e5 100644
--- a/include/llvm/iTerminators.h
+++ b/include/llvm/iTerminators.h
@@ -41,7 +41,7 @@
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 @@
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 @@
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
diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h
index 3aa0e7c..bd26fdb 100644
--- a/lib/AsmParser/ParserInternals.h
+++ b/lib/AsmParser/ParserInternals.h
@@ -118,7 +118,7 @@
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 {
diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h
index fffcdb8..c73b6c0 100644
--- a/lib/Bytecode/Reader/ReaderInternals.h
+++ b/lib/Bytecode/Reader/ReaderInternals.h
@@ -94,7 +94,7 @@
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; }
};
diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp
index 0cd93c0..3bd9a09 100644
--- a/lib/Bytecode/Writer/InstructionWriter.cpp
+++ b/lib/Bytecode/Writer/InstructionWriter.cpp
@@ -29,7 +29,7 @@
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 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 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 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 @@
}
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 @@
// 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;
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index de76dcd..b7cefac 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -63,7 +63,7 @@
// 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 @@
}
// Copy over the terminator now...
- switch (TI->getInstType()) {
+ switch (TI->getOpcode()) {
case Instruction::Ret: {
const ReturnInst *RI = (const ReturnInst*)TI;
@@ -209,7 +209,7 @@
// 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 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();
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index 91a21c3..f6b76c9 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -73,7 +73,7 @@
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 @@
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 @@
//
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();
diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp
index b39a523..c59a441 100644
--- a/lib/Transforms/Scalar/InductionVars.cpp
+++ b/lib/Transforms/Scalar/InductionVars.cpp
@@ -78,7 +78,7 @@
// 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 @@
// 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 @@
Value *StepExpr = PN->getIncomingValue(1);
if (!StepExpr->isInstruction() ||
- ((Instruction*)StepExpr)->getInstType() != Instruction::Add)
+ ((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
return false;
BinaryOperator *I = (BinaryOperator*)StepExpr;
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 5bb75c7..43eb26f 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -307,7 +307,7 @@
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 @@
}
default: break; // Handle math operators as groups.
- } // end switch(I->getInstType())
+ } // end switch(I->getOpcode())
//===-------------------------------------------------------------------===//
@@ -437,7 +437,7 @@
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 @@
markOverdefined(I);
} else if (V1State.isConstant() && V2State.isConstant()) {
ConstPoolVal *Result =
- opt::ConstantFoldBinaryInstruction(I->getInstType(),
+ opt::ConstantFoldBinaryInstruction(I->getOpcode(),
V1State.getConstant(),
V2State.getConstant());
if (Result) {
diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
index 0217ce0..ab600bd 100644
--- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
+++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
@@ -25,7 +25,7 @@
// 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)
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index e2b2495..398f7a8 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -154,20 +154,20 @@
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 @@
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 @@
}
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 << ",";
diff --git a/lib/VMCore/iOperators.cpp b/lib/VMCore/iOperators.cpp
index c1efb42..ef6933a 100644
--- a/lib/VMCore/iOperators.cpp
+++ b/lib/VMCore/iOperators.cpp
@@ -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 @@
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";