// 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
}
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;
};
}
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
// 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;
}
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 {
return new AllocaInst(getType(), Operands.size() ? Operands[1] : 0);
}
- virtual string getOpcode() const { return "alloca"; }
+ virtual const char *getOpcodeName() const { return "alloca"; }
};
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
//
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 {
SetCondInst(BinaryOps opType, Value *S1, Value *S2,
const string &Name = "");
- virtual string getOpcode() const;
+ virtual const char *getOpcodeName() const;
};
#endif
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; }
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; }
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;
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.
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
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 {
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; }
};
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();
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:
// --------------------------
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:
// --------------------------
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:
// --------------------------
}
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;
// 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;
// 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!");
}
// Copy over the terminator now...
- switch (TI->getInstType()) {
+ switch (TI->getOpcode()) {
case Instruction::Ret: {
const ReturnInst *RI = (const ReturnInst*)TI;
// 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()]);
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();
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...
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...
//
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();
// 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);
// 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.
Value *StepExpr = PN->getIncomingValue(1);
if (!StepExpr->isInstruction() ||
- ((Instruction*)StepExpr)->getInstType() != Instruction::Add)
+ ((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
return false;
BinaryOperator *I = (BinaryOperator*)StepExpr;
if (IValue.isOverdefined())
return; // If already overdefined, we aren't going to effect anything
- switch (I->getInstType()) {
+ switch (I->getOpcode()) {
//===-----------------------------------------------------------------===//
// Handle PHI nodes...
//
}
default: break; // Handle math operators as groups.
- } // end switch(I->getInstType())
+ } // end switch(I->getOpcode())
//===-------------------------------------------------------------------===//
markOverdefined(I);
} else if (VState.isConstant()) { // Propogate constant value
ConstPoolVal *Result =
- opt::ConstantFoldUnaryInstruction(I->getInstType(),
+ opt::ConstantFoldUnaryInstruction(I->getOpcode(),
VState.getConstant());
if (Result) {
markOverdefined(I);
} else if (V1State.isConstant() && V2State.isConstant()) {
ConstPoolVal *Result =
- opt::ConstantFoldBinaryInstruction(I->getInstType(),
+ opt::ConstantFoldBinaryInstruction(I->getOpcode(),
V1State.getConstant(),
V2State.getConstant());
if (Result) {
// 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)
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 << " [";
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);
}
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 << ",";
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;
}
}
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";