Broad superficial changes:
authorChris Lattner <sabre@nondot.org>
Sat, 7 Jul 2001 19:24:15 +0000 (19:24 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 7 Jul 2001 19:24:15 +0000 (19:24 +0000)
* 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

16 files changed:
include/llvm/InstrTypes.h
include/llvm/Instruction.h
include/llvm/iMemory.h
include/llvm/iOperators.h
include/llvm/iOther.h
include/llvm/iTerminators.h
lib/AsmParser/ParserInternals.h
lib/Bytecode/Reader/ReaderInternals.h
lib/Bytecode/Writer/InstructionWriter.cpp
lib/Transforms/IPO/InlineSimple.cpp
lib/Transforms/Scalar/ConstantProp.cpp
lib/Transforms/Scalar/InductionVars.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/UnifyFunctionExitNodes.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/iOperators.cpp

index 086cc35eccb4b1c70e595a5f7f54c2807f596009..105775fe84a212956a0257d267d58c3a4ef3ad5c 100644 (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
index 70665232cd5481bd14fa93b9f3ade3258f91b588..96f2637ee2bab4a87004e3f4624a21b6c658ad2c 100644 (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; 
   }
index fafe4c311a16e9708e81b767fca9dd18f78480b1..0ef3ee107db8e13c4fa149bbf1631906c447d381 100644 (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
index 99e4bf33bacee0ea0e6e3596892749f6df8bd7eb..76e4e392fe4db67f0f063b48a7f1a9b59c542e3b 100644 (file)
 //
 
 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
index f6cdcf9c7db56578126c21c519c6a6d6c5335d87..ebd6475a96f5e7704f56cef8e24c7561b85fea8d 100644 (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; }
index 9dbaf7bae1f3636f59618e3d77701aa3672a7570..d43c7e5582b2a37844e64c08f3b95ee4ae9168ca 100644 (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
index 3aa0e7c14422fbe9c416be5c1137d5d0a0ce5617..bd26fdbaaf55a13516e8ca0c270ee8b7201c7a83 100644 (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 {
index fffcdb83c7ac042c1c816f0e81c220874b86c91d..c73b6c06e7ec8aff7b40adcce897d9ff328fdf12 100644 (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; }
 };
index 0cd93c04fdb7c2b9bebecfd4bcf7f5d2156ab9bf..3bd9a0902b6970ae48b69a4aad0c406eed231e9f 100644 (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;
index de76dcd52dcd6b181574fc74d57fb649eca38629..b7cefacaf32ba82f4a65aba9de2171d624b0d452 100644 (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();
index 91a21c3c6b4ac7674f480bbd9fe88c5035a3829d..f6b76c9aa015f46d34beee7d9141aae6da3ff846 100644 (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();
index b39a523f5911dcc78694cae213ff73301a469d96..c59a441fad4904176f2f2c62a5f52cfb1d8c9101 100644 (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;
index 5bb75c7008aebc04196836fa524f4b8358162ade..43eb26fd30fdee6411ce311d559fa30168bc4c0b 100644 (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) {
index 0217ce0eab7b262ed3d65d98f4655a185b3cec32..ab600bd151a7fa9c127e458811fa239620f488d4 100644 (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) 
index e2b2495605833c5381a31f2c7d1677c2e560ddc1..398f7a87b8edbad90bd9f70f073c54ed99dfaf80 100644 (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 << ",";
index c1efb42e716fb39ee0dec6ac1a6b8f56fa406bf8..ef6933adb2535ea2d4fa4a7df03c20fae33584cc 100644 (file)
 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";