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
This commit is contained in:
Chris Lattner 2001-07-07 19:24:15 +00:00
parent 30f24a402c
commit a41f50dea8
16 changed files with 73 additions and 66 deletions

View File

@ -30,7 +30,7 @@ public:
// Terminators must implement the methods required by Instruction... // Terminators must implement the methods required by Instruction...
virtual Instruction *clone() const = 0; 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 // 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 // terminator instruction. If 'idx' is out of range, a null pointer shall be
@ -64,10 +64,10 @@ public:
} }
virtual Instruction *clone() const { 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 { 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 #endif

View File

@ -45,9 +45,12 @@ public:
// Subclass classification... getInstType() returns a member of // Subclass classification... getInstType() returns a member of
// one of the enums that is coming soon (down below)... // 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; } unsigned getInstType() const { return iType; }
inline bool isTerminator() const { // Instance of TerminatorInst? inline bool isTerminator() const { // Instance of TerminatorInst?
return iType >= FirstTermOp && iType < NumTermOps; return iType >= FirstTermOp && iType < NumTermOps;
} }

View File

@ -46,7 +46,7 @@ public:
return new MallocInst(getType(), Operands.size() ? Operands[1] : 0); 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 { class AllocaInst : public AllocationInst {
@ -58,7 +58,7 @@ public:
return new AllocaInst(getType(), Operands.size() ? Operands[1] : 0); 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 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 #endif // LLVM_IMEMORY_H

View File

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

View File

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

View File

@ -41,7 +41,7 @@ public:
virtual Instruction *clone() const { return new ReturnInst(*this); } 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 { inline const Value *getReturnValue() const {
return Operands.size() ? Operands[0] : 0; return Operands.size() ? Operands[0] : 0;
@ -81,7 +81,7 @@ public:
return isUnconditional() ? 0 : Operands[2]; 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 // setUnconditionalDest - Change the current branch to an unconditional branch
// targeting the specified block. // targeting the specified block.
@ -135,7 +135,7 @@ public:
void dest_push_back(ConstPoolVal *OnVal, BasicBlock *Dest); 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 // 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 // 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, "") {} InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {}
virtual Instruction *clone() const { abort(); } virtual Instruction *clone() const { abort(); }
virtual string getOpcode() const { return "placeholder"; } virtual const char *getOpcodeName() const { return "placeholder"; }
}; };
struct BBPlaceHolderHelper : public BasicBlock { struct BBPlaceHolderHelper : public BasicBlock {

View File

@ -94,7 +94,7 @@ public:
struct InstPlaceHolderHelper : public Instruction { struct InstPlaceHolderHelper : public Instruction {
InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {} 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; } virtual Instruction *clone() const { abort(); return 0; }
}; };

View File

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

View File

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

View File

@ -73,7 +73,7 @@ inline static bool
ConstantFoldUnaryInst(Method *M, Method::inst_iterator &DI, ConstantFoldUnaryInst(Method *M, Method::inst_iterator &DI,
UnaryOperator *Op, ConstPoolVal *D) { UnaryOperator *Op, ConstPoolVal *D) {
ConstPoolVal *ReplaceWith = ConstPoolVal *ReplaceWith =
opt::ConstantFoldUnaryInstruction(Op->getInstType(), D); opt::ConstantFoldUnaryInstruction(Op->getOpcode(), D);
if (!ReplaceWith) return false; // Nothing new to change... if (!ReplaceWith) return false; // Nothing new to change...
@ -100,7 +100,7 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
BinaryOperator *Op, BinaryOperator *Op,
ConstPoolVal *D1, ConstPoolVal *D2) { ConstPoolVal *D1, ConstPoolVal *D2) {
ConstPoolVal *ReplaceWith = ConstPoolVal *ReplaceWith =
opt::ConstantFoldBinaryInstruction(Op->getInstType(), D1, D2); opt::ConstantFoldBinaryInstruction(Op->getOpcode(), D1, D2);
if (!ReplaceWith) return false; // Nothing new to change... if (!ReplaceWith) return false; // Nothing new to change...
// Add the new value to the constant pool... // Add the new value to the constant pool...
@ -126,7 +126,7 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
// //
bool opt::ConstantFoldTerminator(TerminatorInst *T) { bool opt::ConstantFoldTerminator(TerminatorInst *T) {
// Branch - See if we are conditional jumping on constant // Branch - See if we are conditional jumping on constant
if (T->getInstType() == Instruction::Br) { if (T->getOpcode() == Instruction::Br) {
BranchInst *BI = (BranchInst*)T; BranchInst *BI = (BranchInst*)T;
if (BI->isUnconditional()) return false; // Can't optimize uncond branch if (BI->isUnconditional()) return false; // Can't optimize uncond branch
BasicBlock *Dest1 = BI->getOperand(0)->castBasicBlockAsserting(); 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! // loop variant computations must be instructions!
Instruction *I = V->castInstructionAsserting(); Instruction *I = V->castInstructionAsserting();
switch (I->getInstType()) { // Handle each instruction seperately switch (I->getOpcode()) { // Handle each instruction seperately
case Instruction::Neg: { case Instruction::Neg: {
Value *SubV = ((UnaryOperator*)I)->getOperand(0); Value *SubV = ((UnaryOperator*)I)->getOperand(0);
LIVType SubLIVType = isLinearInductionVariableH(Int, SubV, PN); 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. // either a Loop Invariant computation, or a LIV type.
if (SubLIVType1 == isLIC) { if (SubLIVType1 == isLIC) {
// Loop invariant computation, we know this is a LIV then. // Loop invariant computation, we know this is a LIV then.
return (I->getInstType() == Instruction::Add) ? return (I->getOpcode() == Instruction::Add) ?
SubLIVType2 : neg(SubLIVType2); SubLIVType2 : neg(SubLIVType2);
} }
// If the LHS is also a LIV Expression, we cannot add two LIVs together // 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 // We can only subtract two LIVs if they are the same type, which yields
// a LIC, because the LIVs cancel each other out. // a LIC, because the LIVs cancel each other out.
@ -155,7 +155,7 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
Value *StepExpr = PN->getIncomingValue(1); Value *StepExpr = PN->getIncomingValue(1);
if (!StepExpr->isInstruction() || if (!StepExpr->isInstruction() ||
((Instruction*)StepExpr)->getInstType() != Instruction::Add) ((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
return false; return false;
BinaryOperator *I = (BinaryOperator*)StepExpr; BinaryOperator *I = (BinaryOperator*)StepExpr;

View File

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

View File

@ -25,7 +25,7 @@ BasicBlock *cfg::UnifyAllExitNodes(Method *M) {
// return. // return.
// //
for(Method::iterator I = M->begin(), E = M->end(); I != E; ++I) 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); ReturningBlocks.push_back(*I);
if (ReturningBlocks.size() == 0) if (ReturningBlocks.size() == 0)

View File

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

View File

@ -10,25 +10,31 @@
BinaryOperator *BinaryOperator::create(unsigned Op, Value *S1, Value *S2, BinaryOperator *BinaryOperator::create(unsigned Op, Value *S1, Value *S2,
const string &Name) { const string &Name) {
switch (Op) { 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... // Binary comparison operators...
case SetLT: case SetGT: case SetLE: case SetLT: case SetGT: case SetLE:
case SetGE: case SetEQ: case SetNE: case SetGE: case SetEQ: case SetNE:
return new SetCondInst((BinaryOps)Op, S1, S2, Name); return new SetCondInst((BinaryOps)Op, S1, S2, Name);
default: 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; return 0;
} }
} }
@ -45,10 +51,10 @@ SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2,
setType(Type::BoolTy); // setcc instructions always return bool type. setType(Type::BoolTy); // setcc instructions always return bool type.
// Make sure it's a valid 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) { switch (OpType) {
case SetLE: return "setle"; case SetLE: return "setle";
case SetGE: return "setge"; case SetGE: return "setge";