Commit more code over to new cast style
authorChris Lattner <sabre@nondot.org>
Tue, 2 Oct 2001 03:41:24 +0000 (03:41 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 2 Oct 2001 03:41:24 +0000 (03:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@697 91177308-0d34-0410-b5e6-96231b3b80d8

42 files changed:
docs/ChrisNotes.txt
docs/CodingStandards.html
include/llvm/Assembly/Writer.h
include/llvm/BasicBlock.h
include/llvm/CodeGen/InstrForest.h
include/llvm/ConstPoolVals.h
include/llvm/DerivedTypes.h
include/llvm/Function.h
include/llvm/GlobalVariable.h
include/llvm/InstrTypes.h
include/llvm/Instruction.h
include/llvm/Module.h
include/llvm/Type.h
include/llvm/Value.h
include/llvm/iMemory.h
include/llvm/iOther.h
include/llvm/iTerminators.h
lib/Analysis/Expressions.cpp
lib/Analysis/IPA/CallGraph.cpp
lib/Analysis/ModuleAnalyzer.cpp
lib/AsmParser/llvmAsmParser.y
lib/Bytecode/Reader/ConstantReader.cpp
lib/Bytecode/Reader/InstructionReader.cpp
lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Writer/ConstantWriter.cpp
lib/CodeGen/InstrSched/SchedGraph.cpp
lib/CodeGen/InstrSelection/InstrForest.cpp
lib/ExecutionEngine/Interpreter/Execution.cpp
lib/Target/SparcV9/InstrSched/SchedGraph.cpp
lib/Target/SparcV9/InstrSelection/InstrForest.cpp
lib/Target/SparcV9/SparcV9InstrSelection.cpp
lib/Target/TargetData.cpp
lib/Transforms/IPO/InlineSimple.cpp
lib/Transforms/Scalar/ADCE.cpp
lib/Transforms/Scalar/ConstantProp.cpp
lib/Transforms/Scalar/DCE.cpp
lib/Transforms/Scalar/InductionVars.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/BasicBlock.cpp
lib/VMCore/ConstPoolVals.cpp
lib/VMCore/Type.cpp

index 4c1f9c9e62f05abd1066c1cdee186b68fabb25ff..652b7694eb6fc39c76a1a3f190ee4f127a1d7b5c 100644 (file)
@@ -1,3 +1,6 @@
+* grep '[A-Za-z][A-Za-z]*\*)' `./getsrcs.sh ` | & less
+
+
 * Need to implement getelementptr, load, and store for indirection through
   arrays and multidim arrays
 * Indirect calls should use the icall instruction
index 489e47694c7b9f0b63b35b3799d8c014ae0e834b..62288cc9e868a079cf46c1b8d63e6b9d48c96bb6 100644 (file)
@@ -262,7 +262,7 @@ To further assist with debugging, make sure to put some kind of error message in
 
 <pre>
   inline Value *getOperand(unsigned i) { 
-    assert(i < Operands.size() && "getOperand() out of range!");
+    assert(i &lt; Operands.size() && "getOperand() out of range!");
     return Operands[i]; 
   }
 </pre>
@@ -270,15 +270,15 @@ To further assist with debugging, make sure to put some kind of error message in
 Here are some examples:
 
 <pre>
-  assert(Ty->isPointerType() && "Can't allocate a non pointer type!");
+  assert(Ty-&gt;isPointerType() && "Can't allocate a non pointer type!");
 
   assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
 
-  assert(idx < getNumSuccessors() && "Successor # out of range!");
+  assert(idx &lt; getNumSuccessors() && "Successor # out of range!");
 
   assert(V1.getType() == V2.getType() && "Constant types must be identical!");
 
-  assert(Succ->front()->isPHINode() && "Only works on PHId BBs!");
+  assert(isa&lt;PHINode&gt;(Succ-&gt;front()) && "Only works on PHId BBs!");
 </pre><p>
 
 You get the idea...<p>
@@ -646,7 +646,7 @@ If you get some free time, and you haven't read them: do so, you might learn som
 <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
 <!-- Created: Tue Jan 23 15:19:28 CST 2001 -->
 <!-- hhmts start -->
-Last modified: Mon Oct  1 08:17:21 CDT 2001
+Last modified: Mon Oct  1 15:33:40 CDT 2001
 <!-- hhmts end -->
 </font>
 </body></html>
index 39b0cb6cfb50fe354bf07c1c9a7700fb74b35de7..020989e5d92fa9beb5d2e543a53684b1b1963399 100644 (file)
@@ -92,13 +92,13 @@ inline ostream &operator<<(ostream &o, const Type *T) {
 inline ostream &operator<<(ostream &o, const Value *I) {
   switch (I->getValueType()) {
   case Value::TypeVal:       return o << cast<const Type>(I);
-  case Value::ConstantVal:   WriteToAssembly((const ConstPoolVal*)I,o);break;
+  case Value::ConstantVal:   WriteToAssembly(cast<ConstPoolVal>(I)  , o); break;
   case Value::MethodArgumentVal: return o << I->getType() << " "<< I->getName();
-  case Value::InstructionVal:WriteToAssembly((const Instruction *)I, o);break;
-  case Value::BasicBlockVal: WriteToAssembly((const BasicBlock  *)I, o);break;
-  case Value::MethodVal:     WriteToAssembly((const Method      *)I, o);break;
-  case Value::GlobalVal:     WriteToAssembly((const GlobalVariable*)I,o);break;
-  case Value::ModuleVal:     WriteToAssembly((const Module      *)I,o); break;
+  case Value::InstructionVal:WriteToAssembly(cast<Instruction>(I)   , o); break;
+  case Value::BasicBlockVal: WriteToAssembly(cast<BasicBlock>(I)    , o); break;
+  case Value::MethodVal:     WriteToAssembly(cast<Method>(I)        , o); break;
+  case Value::GlobalVal:     WriteToAssembly(cast<GlobalVariable>(I), o); break;
+  case Value::ModuleVal:     WriteToAssembly(cast<Module>(I)        , o); break;
   default: return o << "<unknown value type: " << I->getValueType() << ">";
   }
   return o;
index 1d1623bf9782ea060e20224cb5342afeca788d6e..cf29cbd00e7ba84dedd1010e2bf8b94faaa36ad2 100644 (file)
@@ -110,8 +110,8 @@ public:
         InstListType &getInstList()       { return InstList; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const BasicBlock *BB) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const BasicBlock *BB) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == Value::BasicBlockVal;
   }
 
@@ -168,9 +168,7 @@ public:
     inline void advancePastConstPool() {
       // TODO: This is bad
       // Loop to ignore constant pool references
-      while (It != BB->use_end() && 
-             (((*It)->getValueType() != Value::InstructionVal) ||
-              !(((Instruction*)(*It))->isTerminator())))
+      while (It != BB->use_end() && !isa<TerminatorInst>(*It))
         ++It;
     }
   
index 6fe622d9fc3f0771dec8bf193a3c374da70f7044..113e35e32b2fa5ff579b7f0a908cd4c4e8fa3706 100644 (file)
@@ -171,7 +171,7 @@ public:
 
   Instruction *getInstruction() const {
     assert(treeNodeType == NTInstructionNode);
-    return (Instruction*)val;
+    return cast<Instruction>(val);
   }
 protected:
   virtual void dumpNode(int indent) const;
@@ -234,7 +234,7 @@ protected:
 // 
 //------------------------------------------------------------------------ 
 
-class InstrForest : private hash_map<const Instruction*, InstructionNode*> {
+class InstrForest : private hash_map<const Instruction *, InstructionNode*> {
 private:
   hash_set<InstructionNode*> treeRoots;
   
index 342070c9caf9f661f406bb55be8be0f5951450c7..4edfa807a181d27ffd55364c12946bf2dc39cb36 100644 (file)
@@ -34,8 +34,8 @@ public:
   static ConstPoolVal *getNullConstant(const Type *Ty);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const ConstPoolVal *) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const ConstPoolVal *) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == Value::ConstantVal;
   }
 };
@@ -68,12 +68,12 @@ public:
   inline bool getValue() const { return Val; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const ConstPoolBool *) { return true; }
-  static bool isa(const ConstPoolVal *CPV) {
+  static inline bool classof(const ConstPoolBool *) { return true; }
+  static bool classof(const ConstPoolVal *CPV) {
     return (CPV == True) | (CPV == False);
   }
-  static inline bool isa(const Value *V) {
-    return ::isa<ConstPoolVal>(V) && isa(cast<ConstPoolVal>(V));
+  static inline bool classof(const Value *V) {
+    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
   }
 };
 
@@ -108,10 +108,10 @@ public:
   static ConstPoolInt *get(const Type *Ty, unsigned char V);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const ConstPoolInt *) { return true; }
-  static bool isa(const ConstPoolVal *CPV);  // defined in CPV.cpp
-  static inline bool isa(const Value *V) {
-    return ::isa<ConstPoolVal>(V) && isa(cast<ConstPoolVal>(V));
+  static inline bool classof(const ConstPoolInt *) { return true; }
+  static bool classof(const ConstPoolVal *CPV);  // defined in CPV.cpp
+  static inline bool classof(const Value *V) {
+    return isa<ConstPoolVal>(V) && classof(cast<ConstPoolVal>(V));
   }
 };
 
index 5a51e64339b62fd2142513e4dd6241cf4cbde722..750b284b55710e323967472e35f21e321a0b24a1 100644 (file)
@@ -80,12 +80,12 @@ public:
   void refineAbstractTypeTo(const Type *NewType);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const DerivedType *T) { return true; }
-  static inline bool isa(const Type *T) {
+  static inline bool classof(const DerivedType *T) { return true; }
+  static inline bool classof(const Type *T) {
     return T->isDerivedType();
   }
-  static inline bool isa(const Value *V) {
-    return ::isa<Type>(V) && isa(cast<const Type>(V));
+  static inline bool classof(const Value *V) {
+    return isa<Type>(V) && classof(cast<const Type>(V));
   }
 };
 
@@ -133,12 +133,12 @@ public:
 
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const MethodType *T) { return true; }
-  static inline bool isa(const Type *T) {
+  static inline bool classof(const MethodType *T) { return true; }
+  static inline bool classof(const Type *T) {
     return T->getPrimitiveID() == MethodTyID;
   }
-  static inline bool isa(const Value *V) {
-    return ::isa<Type>(V) && isa(cast<const Type>(V));
+  static inline bool classof(const Value *V) {
+    return isa<Type>(V) && classof(cast<const Type>(V));
   }
 };
 
@@ -181,12 +181,12 @@ public:
   static ArrayType *get(const Type *ElementType, int NumElements = -1);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const ArrayType *T) { return true; }
-  static inline bool isa(const Type *T) {
+  static inline bool classof(const ArrayType *T) { return true; }
+  static inline bool classof(const Type *T) {
     return T->getPrimitiveID() == ArrayTyID;
   }
-  static inline bool isa(const Value *V) {
-    return ::isa<Type>(V) && isa(cast<const Type>(V));
+  static inline bool classof(const Value *V) {
+    return isa<Type>(V) && classof(cast<const Type>(V));
   }
 };
 
@@ -226,12 +226,12 @@ public:
   static StructType *get(const vector<const Type*> &Params);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const StructType *T) { return true; }
-  static inline bool isa(const Type *T) {
+  static inline bool classof(const StructType *T) { return true; }
+  static inline bool classof(const Type *T) {
     return T->getPrimitiveID() == StructTyID;
   }
-  static inline bool isa(const Value *V) {
-    return ::isa<Type>(V) && isa(cast<const Type>(V));
+  static inline bool classof(const Value *V) {
+    return isa<Type>(V) && classof(cast<const Type>(V));
   }
 };
 
@@ -269,12 +269,12 @@ public:
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const PointerType *T) { return true; }
-  static inline bool isa(const Type *T) {
+  static inline bool classof(const PointerType *T) { return true; }
+  static inline bool classof(const Type *T) {
     return T->getPrimitiveID() == PointerTyID;
   }
-  static inline bool isa(const Value *V) {
-    return ::isa<Type>(V) && isa(cast<const Type>(V));
+  static inline bool classof(const Value *V) {
+    return isa<Type>(V) && classof(cast<const Type>(V));
   }
 };
 
@@ -299,12 +299,12 @@ public:
   }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const OpaqueType *T) { return true; }
-  static inline bool isa(const Type *T) {
+  static inline bool classof(const OpaqueType *T) { return true; }
+  static inline bool classof(const Type *T) {
     return T->getPrimitiveID() == OpaqueTyID;
   }
-  static inline bool isa(const Value *V) {
-    return ::isa<Type>(V) && isa(cast<const Type>(V));
+  static inline bool classof(const Value *V) {
+    return isa<Type>(V) && classof(cast<const Type>(V));
   }
 };
 
index f6c8aa214c099ec4aeb015dc26abf3f110174e27..227ab53cd0d467a36c2d249f094804e9bdeb0813 100644 (file)
@@ -93,8 +93,8 @@ public:
 
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const Method *T) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const Method *T) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == Value::MethodVal;
   }
 
index f301844bd72df859eb059b6c3556fdf6677807fd..3ee7f6d45a2bd3966e984ebb15f6a86702946ba0 100644 (file)
@@ -61,8 +61,8 @@ public:
   inline bool isConstant() const { return Constant; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const GlobalVariable *) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const GlobalVariable *) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == Value::GlobalVal;
   }
 };
index 75c4943e44504f0b7499be77a6c268e5d38c20cf..db85a397c8df5bdfecf4031f12091e1265534ce3 100644 (file)
@@ -40,6 +40,15 @@ public:
   inline BasicBlock *getSuccessor(unsigned idx) {
     return (BasicBlock*)((const TerminatorInst *)this)->getSuccessor(idx);
   }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const TerminatorInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() >= FirstTermOp && I->getOpcode() < NumTermOps; 
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -70,6 +79,15 @@ public:
   }
 
   virtual const char *getOpcodeName() const = 0;
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const UnaryOperator *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() >= FirstUnaryOp && I->getOpcode() < NumUnaryOps; 
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -111,6 +129,15 @@ public:
   void swapOperands() {
     swap(Operands[0], Operands[1]);
   }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const BinaryOperator *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() >= FirstBinaryOp && I->getOpcode() < NumBinaryOps; 
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 #endif
index 93b68a2c628ae110045b509bece125b6e61090f7..71bb8e25a1d749764ae7b212a79107baf03aa127 100644 (file)
@@ -66,7 +66,7 @@ public:
   unsigned getInstType() const { return iType; }
 
   inline bool isTerminator() const {   // Instance of TerminatorInst?
-    return iType >= FirstTermOp && iType < NumTermOps; 
+    return iType >= FirstTermOp && iType < NumTermOps;
   }
   inline bool isDefinition() const { return !isTerminator(); }
   inline bool isUnaryOp() const {
@@ -76,9 +76,6 @@ public:
     return iType >= FirstBinaryOp && iType < NumBinaryOps;
   }
 
-  // isPHINode() - This is used frequently enough to allow it to exist
-  inline bool isPHINode() const { return iType == PHINode; }
-
   // dropAllReferences() - This function is in charge of "letting go" of all
   // objects that this Instruction refers to.  This first lets go of all
   // references to hidden values generated code for this instruction,
@@ -88,8 +85,8 @@ public:
 
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const Instruction *I) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const Instruction *I) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == Value::InstructionVal;
   }
   
index a9f920edcb040f7d9cc31d8c54e00e6955ee4379..823d4d82f06f1366189fd1f9a8f1b3082d83a99f 100644 (file)
@@ -94,8 +94,8 @@ public:
   inline       Method            *back()       { return MethodList.back(); }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const Module *T) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const Module *T) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == Value::ModuleVal;
   }
 
index 687b12afb050749349c2e3040e92933fee644282..cc682669ce51c939501d1c71d6bd00011e0e1e8d 100644 (file)
@@ -189,42 +189,19 @@ public:
   inline bool isDerivedType()   const { return ID >= FirstDerivedTyID; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const Type *T) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const Type *T) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == Value::TypeVal;
   }
 
-  // Methods for determining the subtype of this Type.  The cast*() methods are
-  // equilivent to using dynamic_cast<>... if the cast is successful, this is
-  // returned, otherwise you get a null pointer, allowing expressions like this:
-  //
-  // if (MethodType *MTy = Ty->dyncastMethodType()) { ... }
-  //
-  // This section also defines a family of isArrayType(), isLabelType(), 
-  // etc functions...
-  //
-  // The family of functions Ty->cast<type>() is used in the same way as the
-  // Ty->dyncast<type>() instructions, but they assert the expected type instead
-  // of checking it at runtime.
+  // Methods for determining the subtype of this Type. This section defines a
+  // family of isArrayType(), isLabelType(),  etc functions...
   //
 #define HANDLE_PRIM_TYPE(NAME, SIZE)                                      \
   inline bool is##NAME##Type() const { return ID == NAME##TyID; }
 #define HANDLE_DERV_TYPE(NAME, CLASS)                                     \
-  inline bool is##NAME##Type() const { return ID == NAME##TyID; }         \
-  inline const CLASS *dyncast##NAME##Type() const { /*const version */    \
-    return is##NAME##Type() ? (const CLASS*)this : 0;                     \
-  }                                                                       \
-  inline CLASS *dyncast##NAME##Type() {         /* nonconst version */    \
-    return is##NAME##Type() ? (CLASS*)this : 0;                           \
-  }                                                                       \
-  inline const CLASS *cast##NAME##Type() const {    /*const version */    \
-    assert(is##NAME##Type() && "Expected TypeTy: " #NAME);                \
-    return (const CLASS*)this;                                            \
-  }                                                                       \
-  inline CLASS *cast##NAME##Type() {            /* nonconst version */    \
-    assert(is##NAME##Type() && "Expected TypeTy: " #NAME);                \
-    return (CLASS*)this;                                                  \
-  }
+  inline bool is##NAME##Type() const { return ID == NAME##TyID; }
+
 #include "llvm/Type.def"
 
 private:
index 1acf2e299ddb90dbea08cf1dc7d149f598fb70ff..5716d29c6651275c5c42819b19bbb74b3a4e51ee 100644 (file)
@@ -185,7 +185,7 @@ template <class X> class real_type <class UseTy<X> > { typedef X *Type; };
 //  if (isa<Type>(myVal)) { ... }
 //
 template <class X, class Y>
-inline bool isa(Y Val) { return X::isa(Val); }
+inline bool isa(Y Val) { return X::classof(Val); }
 
 
 // cast<X> - Return the argument parameter cast to the specified type.  This
index 5667da6c8ff1428c4e69a9f201cd80def8720563..147ff18e94abc1ca6cc8cbfea810e8df79d143ec 100644 (file)
@@ -27,16 +27,16 @@ public:
 
     if (ArraySize) {
       // Make sure they didn't try to specify a size for !(unsized array) type
-      assert((getType()->getValueType()->isArrayType() && 
-             ((const ArrayType*)getType()->getValueType())->isUnsized()) && 
-          "Trying to allocate something other than unsized array, with size!");
+      assert(getType()->getValueType()->isArrayType() && 
+             cast<ArrayType>(getType()->getValueType())->isUnsized() && 
+           "Trying to allocate something other than unsized array, with size!");
 
       Operands.reserve(1);
       Operands.push_back(Use(ArraySize, this));
     } else {
       // Make sure that the pointer is not to an unsized array!
       assert(!getType()->getValueType()->isArrayType() ||
-            ((const ArrayType*)getType()->getValueType())->isSized() && 
+            cast<const ArrayType>(getType()->getValueType())->isSized() && 
             "Trying to allocate unsized array without size!");
     }
   }
@@ -64,6 +64,15 @@ public:
   }
 
   virtual const char *getOpcodeName() const { return "malloc"; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const MallocInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Malloc);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -81,6 +90,15 @@ public:
   }
 
   virtual const char *getOpcodeName() const { return "alloca"; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const AllocaInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Alloca);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -102,6 +120,15 @@ public:
   virtual const char *getOpcodeName() const { return "free"; }
 
   virtual bool hasSideEffects() const { return true; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const FreeInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Free);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -160,6 +187,15 @@ public:
   virtual const char*  getOpcodeName() const { return "load"; }  
   virtual Value*       getPtrOperand() { return this->getOperand(0); }
   virtual int getFirstOffsetIdx() const { return (this->getNumOperands() > 1)? 1 : -1;}
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const LoadInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Load);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -182,6 +218,15 @@ public:
   virtual bool hasSideEffects() const { return true; }
   virtual Value*       getPtrOperand() { return this->getOperand(1); }
   virtual int getFirstOffsetIdx() const { return (this->getNumOperands() > 2)? 2 : -1;}
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const StoreInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Store);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -206,6 +251,16 @@ public:
   
   inline bool isArraySelector() const { return !isStructSelector(); }
   bool isStructSelector() const;
+
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const GetElementPtrInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::GetElementPtr);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 #endif // LLVM_IMEMORY_H
index 1e4733d79ac8a3bd0d5da8fc9787a70812e5f7c7..d0e0e2e195254dca90a026d9d66a5fd89a9962ca 100644 (file)
@@ -55,6 +55,16 @@ public:
   // removeIncomingValue - Remove an incoming value.  This is useful if a
   // predecessor basic block is deleted.  The value removed is returned.
   Value *removeIncomingValue(const BasicBlock *BB);
+
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const PHINode *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::PHINode; 
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -79,6 +89,15 @@ public:
 
   virtual Instruction *clone() const { return new CastInst(*this); }
   virtual const char *getOpcodeName() const { return "cast"; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const CastInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() == Cast;
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -105,8 +124,8 @@ public:
   inline       Method *getParent()       { return Parent; }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
-  static inline bool isa(const MethodArgument *) { return true; }
-  static inline bool isa(const Value *V) {
+  static inline bool classof(const MethodArgument *) { return true; }
+  static inline bool classof(const Value *V) {
     return V->getValueType() == MethodArgumentVal;
   }
 };
@@ -133,6 +152,15 @@ public:
   Method *getCalledMethod() {
     return  cast<Method>(Operands[0]); 
   }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const CallInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return I->getOpcode() == Instruction::Call; 
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -161,6 +189,16 @@ public:
   virtual const char *getOpcodeName() const {
     return getOpcode() == Shl ? "shl" : "shr"; 
   }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const ShiftInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Shr) | 
+           (I->getOpcode() == Instruction::Shl);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 #endif
index 6978da54986c9f19c8b50a717160f5220575fe5e..e1b53f023555b1ee53bab1de6fce98e05a83cb60 100644 (file)
@@ -56,6 +56,15 @@ public:
   //
   virtual const BasicBlock *getSuccessor(unsigned idx) const { return 0; }
   virtual unsigned getNumSuccessors() const { return 0; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const ReturnInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Ret);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -105,6 +114,15 @@ public:
   }
 
   virtual unsigned getNumSuccessors() const { return 1+!isUnconditional(); }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const BranchInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Br);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 
@@ -161,6 +179,15 @@ public:
     return cast<ConstPoolVal>(Operands[idx*2]);
   }
   virtual unsigned getNumSuccessors() const { return Operands.size()/2; }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static inline bool classof(const SwitchInst *) { return true; }
+  static inline bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::Switch);
+  }
+  static inline bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
 };
 
 #endif
index cb83d41236ed1a3866a82d510c98e0249f9d74e6..abe2a18b941447033ab757503fb0db5714262967 100644 (file)
@@ -97,7 +97,7 @@ static const ConstPoolInt *Add(const ConstPoolInt *Arg1,
   ConstPoolVal *Result = *Arg1 + *Arg2;
   assert(Result && Result->getType() == Arg1->getType() &&
         "Couldn't perform addition!");
-  ConstPoolInt *ResultI = (ConstPoolInt*)Result;
+  ConstPoolInt *ResultI = cast<ConstPoolInt>(Result);
 
   // Check to see if the result is one of the special cases that we want to
   // recognize...
@@ -147,7 +147,7 @@ inline const ConstPoolInt *Mul(const ConstPoolInt *Arg1,
   ConstPoolVal *Result = *Arg1 * *Arg2;
   assert(Result && Result->getType() == Arg1->getType() && 
         "Couldn't perform mult!");
-  ConstPoolInt *ResultI = (ConstPoolInt*)Result;
+  ConstPoolInt *ResultI = cast<ConstPoolInt>(Result);
 
   // Check to see if the result is one of the special cases that we want to
   // recognize...
@@ -203,7 +203,7 @@ static inline ExprType negate(const ExprType &E, Value *V) {
   const Type *ETy = E.getExprType(Ty);
   ConstPoolInt *Zero   = getUnsignedConstant(0, ETy);
   ConstPoolInt *One    = getUnsignedConstant(1, ETy);
-  ConstPoolInt *NegOne = (ConstPoolInt*)(*Zero - *One);
+  ConstPoolInt *NegOne = cast<ConstPoolInt>(*Zero - *One);
   if (NegOne == 0) return V;  // Couldn't subtract values...
 
   return ExprType(DefOne (E.Scale , Ty) * NegOne, E.Var,
@@ -230,7 +230,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) {
   case Value::ConstantVal:              // Constant value, just return constant
     ConstPoolVal *CPV = cast<ConstPoolVal>(Expr);
     if (CPV->getType()->isIntegral()) { // It's an integral constant!
-      ConstPoolInt *CPI = (ConstPoolInt*)Expr;
+      ConstPoolInt *CPI = cast<ConstPoolInt>(Expr);
       return ExprType(CPI->equalsInt(0) ? 0 : CPI);
     }
     return Expr;
@@ -297,7 +297,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) {
     const ConstPoolVal *CPV =ConstRules::get(*Offs)->castTo(Offs, DestTy);
     if (!CPV) return I;
     assert(CPV->getType()->isIntegral() && "Must have an integral type!");
-    return (ConstPoolInt*)CPV;
+    return cast<ConstPoolInt>(CPV);
   } // end case Instruction::Cast
     // TODO: Handle SUB, SHR?
 
index b1a272f032e050cb0a4c636acb29b25d587acb84..87dbf2b4255d3698ed181de63b58ba421621bc1e 100644 (file)
@@ -38,10 +38,8 @@ void CallGraph::addToCallGraph(Method *M) {
 
   for (Method::inst_iterator II = M->inst_begin(), IE = M->inst_end();
        II != IE; ++II) {
-    if (II->getOpcode() == Instruction::Call) {
-      CallInst *CI = (CallInst*)*II;
+    if (CallInst *CI = dyn_cast<CallInst>(*II))
       Node->addCalledMethod(getNodeFor(CI->getCalledMethod()));
-    }
   }
 }
 
index 8212287962352aff683d6c16615054ef42819b9b..d5432163496cbcd0e5435e6a9b8aa4274867aaba 100644 (file)
@@ -46,7 +46,7 @@ inline bool ModuleAnalyzer::handleType(set<const Type *> &TypeSet,
     break;
 
   case Type::StructTyID: {
-    const StructType *ST = (const StructType*)T;
+    const StructType *ST = cast<const StructType>(T);
     const StructType::ElementTypes &Elements = ST->getElementTypes();
     for (StructType::ElementTypes::const_iterator I = Elements.begin();
         I != Elements.end(); ++I)
index 819f96290f479983ee07fd41f1bfa948432740d7..a0c96733a0e76347cf4f3c8a59c2eb633f8f050e 100644 (file)
@@ -397,10 +397,9 @@ static void setValueName(Value *V, char *NameStr) {
     // There is only one case where this is allowed: when we are refining an
     // opaque type.  In this case, Existing will be an opaque type.
     if (const Type *Ty = cast<const Type>(Existing))
-      if (Ty->isOpaqueType()) {
+      if (OpaqueType *OpTy = dyn_cast<OpaqueType>(Ty)) {
        // We ARE replacing an opaque type!
-
-       cast<DerivedType>(Ty)->refineAbstractTypeTo(cast<Type>(V));
+       OpTy->refineAbstractTypeTo(cast<Type>(V));
        return;
       }
 
@@ -1232,7 +1231,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef {
     while ($2->begin() != $2->end()) {
       if ($2->front().first->getType() != Ty) 
        ThrowException("All elements of a PHI node must be of the same type!");
-      ((PHINode*)$$)->addIncoming($2->front().first, $2->front().second);
+      cast<PHINode>($$)->addIncoming($2->front().first, $2->front().second);
       $2->pop_front();
     }
     delete $2;  // Free the list...
@@ -1291,7 +1290,7 @@ MemoryInst : MALLOC Types {
     delete $2;
   }
   | MALLOC Types ',' UINT ValueRef {
-    if (!(*$2)->isArrayType() || ((const ArrayType*)$2->get())->isSized())
+    if (!(*$2)->isArrayType() || cast<const ArrayType>($2->get())->isSized())
       ThrowException("Trying to allocate " + (*$2)->getName() + 
                     " as unsized array!");
     const Type *Ty = PointerType::get(*$2);
@@ -1303,7 +1302,7 @@ MemoryInst : MALLOC Types {
     delete $2;
   }
   | ALLOCA Types ',' UINT ValueRef {
-    if (!(*$2)->isArrayType() || ((const ArrayType*)$2->get())->isSized())
+    if (!(*$2)->isArrayType() || cast<const ArrayType>($2->get())->isSized())
       ThrowException("Trying to allocate " + (*$2)->getName() + 
                     " as unsized array!");
     const Type *Ty = PointerType::get(*$2);
index aaecedddfa7aed174359788c3384d545ff947638..4c7f7c9ac270002e84607b56d56f46c2985321ea 100644 (file)
@@ -229,7 +229,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
     abort();
 
   case Type::ArrayTyID: {
-    const ArrayType *AT = (const ArrayType*)Ty;
+    const ArrayType *AT = cast<const ArrayType>(Ty);
     unsigned NumElements;
     if (AT->isSized())          // Sized array, # elements stored in type!
       NumElements = (unsigned)AT->getNumElements();
@@ -249,7 +249,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
   }
 
   case Type::StructTyID: {
-    const StructType *ST = Ty->castStructType();
+    const StructType *ST = cast<StructType>(Ty);
     const StructType::ElementTypes &ET = ST->getElementTypes();
 
     vector<ConstPoolVal *> Elements;
@@ -267,7 +267,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
   }    
 
   case Type::PointerTyID: {
-    const PointerType *PT = Ty->castPointerType();
+    const PointerType *PT = cast<const PointerType>(Ty);
     unsigned SubClass;
     if (read_vbr(Buf, EndBuf, SubClass)) return failure(true);
     if (SubClass != 0) return failure(true);
index 300c40999eb17d599957cf34d8e9d4abf29ce90a..b6eec664913e1a74def14861510ded4f7814822b 100644 (file)
@@ -122,11 +122,11 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
             delete PN; 
            return failure(true);
     case 2: PN->addIncoming(getValue(Raw.Ty, Raw.Arg1),
-                           (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2)); 
+                           cast<BasicBlock>(getValue(Type::LabelTy,Raw.Arg2)));
       break;
     default:
       PN->addIncoming(getValue(Raw.Ty, Raw.Arg1), 
-                     (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2));
+                     cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)));
       if (Raw.VarArgs->size() & 1) {
        cerr << "PHI Node with ODD number of arguments!\n";
        delete PN;
@@ -135,7 +135,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
         vector<unsigned> &args = *Raw.VarArgs;
         for (unsigned i = 0; i < args.size(); i+=2)
           PN->addIncoming(getValue(Raw.Ty, args[i]),
-                         (BasicBlock*)getValue(Type::LabelTy, args[i+1]));
+                         cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
       }
       delete Raw.VarArgs; 
       break;
@@ -160,12 +160,12 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
 
   case Instruction::Br:
     if (Raw.NumOperands == 1) {
-      Res = new BranchInst((BasicBlock*)getValue(Type::LabelTy, Raw.Arg1));
+      Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg1)));
       return false;
     } else if (Raw.NumOperands == 3) {
-      Res = new BranchInst((BasicBlock*)getValue(Type::LabelTy, Raw.Arg1),
-                          (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2),
-                                       getValue(Type::BoolTy , Raw.Arg3));
+      Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg1)),
+                          cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)),
+                                            getValue(Type::BoolTy , Raw.Arg3));
       return false;
     }
     break;
@@ -173,7 +173,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
   case Instruction::Switch: {
     SwitchInst *I = 
       new SwitchInst(getValue(Raw.Ty, Raw.Arg1), 
-                     (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2));
+                     cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)));
     Res = I;
     if (Raw.NumOperands < 3) return false;  // No destinations?  Wierd.
 
@@ -185,15 +185,15 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
     
     vector<unsigned> &args = *Raw.VarArgs;
     for (unsigned i = 0; i < args.size(); i += 2)
-      I->dest_push_back((ConstPoolVal*)getValue(Raw.Ty, args[i]),
-                        (BasicBlock*)getValue(Type::LabelTy, args[i+1]));
+      I->dest_push_back(cast<ConstPoolVal>(getValue(Raw.Ty, args[i])),
+                        cast<BasicBlock>(getValue(Type::LabelTy, args[i+1])));
 
     delete Raw.VarArgs;
     return false;
   }
 
   case Instruction::Call: {
-    Method *M = (Method*)getValue(Raw.Ty, Raw.Arg1);
+    Method *M = cast<Method>(getValue(Raw.Ty, Raw.Arg1));
     if (M == 0) return failure(true);
 
     vector<Value *> Params;
index 0e4883034e61b50e6fd06ad0eaad90b24a6ae4d2..14e89e2d20de8e5b1903bc714e9f94bcd095a451 100644 (file)
@@ -338,7 +338,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
       unsigned InitSlot;
       if (read_vbr(Buf, End, InitSlot)) return failure(true);
       
-      Value *V = getValue(Ty->castPointerType()->getValueType(),
+      Value *V = getValue(cast<const PointerType>(Ty)->getValueType(),
                          InitSlot, false);
       if (V == 0) return failure(true);
       Initializer = cast<ConstPoolVal>(V);
@@ -382,7 +382,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
     // Keep track of this information in a linked list that is emptied as 
     // methods are loaded...
     //
-    MethodSignatureList.push_back(make_pair((const MethodType*)Ty, SlotNo));
+    MethodSignatureList.push_back(make_pair(cast<const MethodType>(Ty),SlotNo));
     if (read_vbr(Buf, End, MethSignature)) return failure(true);
     BCR_TRACE(2, "Method of type: " << Ty << endl);
   }
index dde47d52b116ea919c490bb9f01ff738f1c0a6c4..d0c58f1ae6d147b1a61ed27c4b67528d6d1287fe 100644 (file)
@@ -23,7 +23,7 @@ void BytecodeWriter::outputType(const Type *T) {
   
   switch (T->getPrimitiveID()) {   // Handle derived types now.
   case Type::MethodTyID: {
-    const MethodType *MT = (const MethodType*)T;
+    const MethodType *MT = cast<const MethodType>(T);
     int Slot = Table.getValSlot(MT->getReturnType());
     assert(Slot != -1 && "Type used but not available!!");
     output_vbr((unsigned)Slot, Out);
@@ -46,7 +46,7 @@ void BytecodeWriter::outputType(const Type *T) {
   }
 
   case Type::ArrayTyID: {
-    const ArrayType *AT = (const ArrayType*)T;
+    const ArrayType *AT = cast<const ArrayType>(T);
     int Slot = Table.getValSlot(AT->getElementType());
     assert(Slot != -1 && "Type used but not available!!");
     output_vbr((unsigned)Slot, Out);
@@ -57,7 +57,7 @@ void BytecodeWriter::outputType(const Type *T) {
   }
 
   case Type::StructTyID: {
-    const StructType *ST = (const StructType*)T;
+    const StructType *ST = cast<const StructType>(T);
 
     // Output all of the element types...
     StructType::ElementTypes::const_iterator I = ST->getElementTypes().begin();
@@ -73,7 +73,7 @@ void BytecodeWriter::outputType(const Type *T) {
   }
 
   case Type::PointerTyID: {
-    const PointerType *PT = (const PointerType*)T;
+    const PointerType *PT = cast<const PointerType>(T);
     int Slot = Table.getValSlot(PT->getValueType());
     assert(Slot != -1 && "Type used but not available!!");
     output_vbr((unsigned)Slot, Out);
@@ -91,7 +91,7 @@ void BytecodeWriter::outputType(const Type *T) {
 bool BytecodeWriter::outputConstant(const ConstPoolVal *CPV) {
   switch (CPV->getType()->getPrimitiveID()) {
   case Type::BoolTyID:    // Boolean Types
-    if (((const ConstPoolBool*)CPV)->getValue())
+    if (cast<const ConstPoolBool>(CPV)->getValue())
       output_vbr((unsigned)1, Out);
     else
       output_vbr((unsigned)0, Out);
index 852c4f2686ab7fddbd1109c896bad5628d92a370..fd09e9e77785ac2da81d9431d4fcbcf207c2ed85 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/Target/MachineRegInfo.h"
 #include "llvm/Support/StringExtras.h"
+#include "llvm/iOther.h"
 #include <algorithm>
 
 
@@ -540,7 +541,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node,
   // Phi instructions are the only ones that produce a value but don't get
   // any non-dummy machine instructions.  Return here as an optimization.
   // 
-  if (defVMInstr->isPHINode())
+  if (isa<PHINode>(defVMInstr))
     return;
   
   // Now add the graph edge for the appropriate machine instruction(s).
@@ -642,7 +643,7 @@ void
 SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
                                    const TargetMachine& target)
 {
-  if (instr->isPHINode())
+  if (isa<PHINode>(instr))
     return;
 
   MachineCodeForVMInstr& mvec = instr->getMachineInstrVec();
index f5a524707b932b62d60b62f978a187a66fe73a7b..199ed6569be2e51af9ac6d46bda2f72978886d15 100644 (file)
@@ -26,6 +26,7 @@
 #include "llvm/Method.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iMemory.h"
+#include "llvm/iOther.h"
 #include "llvm/ConstPoolVals.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/CodeGen/MachineInstr.h"
@@ -57,11 +58,11 @@ InstructionNode::InstructionNode(Instruction* I)
 
   // Distinguish special cases of some instructions such as Ret and Br
   // 
-  if (opLabel == Instruction::Ret && ((ReturnInst*)I)->getReturnValue())
+  if (opLabel == Instruction::Ret && cast<ReturnInst>(I)->getReturnValue())
     {
       opLabel = RetValueOp;                     // ret(value) operation
     }
-  else if (opLabel == Instruction::Br && ! ((BranchInst*)I)->isUnconditional())
+  else if (opLabel ==Instruction::Br && !cast<BranchInst>(I)->isUnconditional())
     {
       opLabel = BrCondOp;              // br(cond) operation
     }
@@ -302,7 +303,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
          InstrTreeNode* opTreeNode;
          if (isa<Instruction>(operand) && operand->use_size() == 1 &&
              cast<Instruction>(operand)->getParent() == instr->getParent() &&
-             ! instr->isPHINode() &&
+             !isa<PHINode>(instr) &&
              instr->getOpcode() != Instruction::Call)
            {
              // Recursively create a treeNode for it.
index d88d91ff1f9e7fb416337a62b5b4b03392b67862..34a80fedd4152ad8ffd67f570592f8cd23e3af5d 100644 (file)
@@ -351,9 +351,9 @@ void Interpreter::executeAllocInst(AllocationInst *I, ExecutionContext &SF) {
   unsigned NumElements = 1;
 
   if (I->getNumOperands()) {   // Allocating a unsized array type?
-    assert(Ty->isArrayType() && Ty->castArrayType()->isUnsized() && 
+    assert(isa<ArrayType>(Ty) && cast<const ArrayType>(Ty)->isUnsized() && 
           "Allocation inst with size operand for !unsized array type???");
-    Ty = ((const ArrayType*)Ty)->getElementType();  // Get the actual type...
+    Ty = cast<const ArrayType>(Ty)->getElementType();  // Get the actual type...
 
     // Get the number of elements being allocated by the array...
     GenericValue NumEl = getOperandValue(I->getOperand(0), SF);
@@ -665,16 +665,16 @@ bool Interpreter::executeInstruction() {
       // Memory Instructions
     case Instruction::Alloca:
     case Instruction::Malloc:  executeAllocInst ((AllocationInst*)I, SF); break;
-    case Instruction::Free:    executeFreeInst  ((FreeInst*)  I, SF); break;
-    case Instruction::Load:    executeLoadInst  ((LoadInst*)  I, SF); break;
-    case Instruction::Store:   executeStoreInst ((StoreInst*) I, SF); break;
+    case Instruction::Free:    executeFreeInst  (cast<FreeInst> (I), SF); break;
+    case Instruction::Load:    executeLoadInst  (cast<LoadInst> (I), SF); break;
+    case Instruction::Store:   executeStoreInst (cast<StoreInst>(I), SF); break;
 
       // Miscellaneous Instructions
-    case Instruction::Call:    executeCallInst  ((CallInst*)  I, SF); break;
-    case Instruction::PHINode: executePHINode   ((PHINode*)   I, SF); break;
-    case Instruction::Shl:     executeShlInst   ((ShiftInst*) I, SF); break;
-    case Instruction::Shr:     executeShrInst   ((ShiftInst*) I, SF); break;
-    case Instruction::Cast:    executeCastInst  ((CastInst*)  I, SF); break;
+    case Instruction::Call:    executeCallInst  (cast<CallInst> (I), SF); break;
+    case Instruction::PHINode: executePHINode   (cast<PHINode>  (I), SF); break;
+    case Instruction::Shl:     executeShlInst   (cast<ShiftInst>(I), SF); break;
+    case Instruction::Shr:     executeShrInst   (cast<ShiftInst>(I), SF); break;
+    case Instruction::Cast:    executeCastInst  (cast<CastInst> (I), SF); break;
     default:
       cout << "Don't know how to execute this instruction!\n-->" << I;
     }
index 852c4f2686ab7fddbd1109c896bad5628d92a370..fd09e9e77785ac2da81d9431d4fcbcf207c2ed85 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/Target/MachineInstrInfo.h"
 #include "llvm/Target/MachineRegInfo.h"
 #include "llvm/Support/StringExtras.h"
+#include "llvm/iOther.h"
 #include <algorithm>
 
 
@@ -540,7 +541,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node,
   // Phi instructions are the only ones that produce a value but don't get
   // any non-dummy machine instructions.  Return here as an optimization.
   // 
-  if (defVMInstr->isPHINode())
+  if (isa<PHINode>(defVMInstr))
     return;
   
   // Now add the graph edge for the appropriate machine instruction(s).
@@ -642,7 +643,7 @@ void
 SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
                                    const TargetMachine& target)
 {
-  if (instr->isPHINode())
+  if (isa<PHINode>(instr))
     return;
 
   MachineCodeForVMInstr& mvec = instr->getMachineInstrVec();
index f5a524707b932b62d60b62f978a187a66fe73a7b..199ed6569be2e51af9ac6d46bda2f72978886d15 100644 (file)
@@ -26,6 +26,7 @@
 #include "llvm/Method.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iMemory.h"
+#include "llvm/iOther.h"
 #include "llvm/ConstPoolVals.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/CodeGen/MachineInstr.h"
@@ -57,11 +58,11 @@ InstructionNode::InstructionNode(Instruction* I)
 
   // Distinguish special cases of some instructions such as Ret and Br
   // 
-  if (opLabel == Instruction::Ret && ((ReturnInst*)I)->getReturnValue())
+  if (opLabel == Instruction::Ret && cast<ReturnInst>(I)->getReturnValue())
     {
       opLabel = RetValueOp;                     // ret(value) operation
     }
-  else if (opLabel == Instruction::Br && ! ((BranchInst*)I)->isUnconditional())
+  else if (opLabel ==Instruction::Br && !cast<BranchInst>(I)->isUnconditional())
     {
       opLabel = BrCondOp;              // br(cond) operation
     }
@@ -302,7 +303,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
          InstrTreeNode* opTreeNode;
          if (isa<Instruction>(operand) && operand->use_size() == 1 &&
              cast<Instruction>(operand)->getParent() == instr->getParent() &&
-             ! instr->isPHINode() &&
+             !isa<PHINode>(instr) &&
              instr->getOpcode() != Instruction::Call)
            {
              // Recursively create a treeNode for it.
index b1b5e01aff5c13cb9646506a8fa3bec872e915a6..e4ae8a8400a8995182ff78c966786aed387eb1cc 100644 (file)
@@ -2010,9 +2010,8 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
                 // Also, mark the operands of the Call as implicit operands
                 // of the machine instruction.
         {
-        CallInst* callInstr = (CallInst*) subtreeRoot->getInstruction();
+        CallInst *callInstr = cast<CallInst>(subtreeRoot->getInstruction());
         Method* callee = callInstr->getCalledMethod();
-        assert(callInstr->getOpcode() == Instruction::Call); 
         
         Instruction* jmpAddrReg = new TmpInstruction(Instruction::UserOp1,
                                                      callee, NULL);
index 24a5e852a219606b544d3b49f88ca063a7d5ce2d..0b4dc98233cb59b201daa80f4b749bd9e324fa55 100644 (file)
@@ -147,14 +147,14 @@ unsigned char TargetData::getTypeAlignment(const Type *Ty) const {
 
 unsigned TargetData::getIndexedOffset(const Type *ptrTy,
                                      const vector<ConstPoolVal*> &Idx) const {
-  const PointerType *PtrTy = ptrTy->castPointerType();
+  const PointerType *PtrTy = cast<const PointerType>(ptrTy);
   unsigned Result = 0;
 
   // Get the type pointed to...
   const Type *Ty = PtrTy->getValueType();
 
   for (unsigned CurIDX = 0; CurIDX < Idx.size(); ++CurIDX) {
-    if (const StructType *STy = Ty->dyncastStructType()) {
+    if (const StructType *STy = dyn_cast<const StructType>(Ty)) {
       assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx");
       unsigned FieldNo = ((ConstPoolUInt*)Idx[CurIDX++])->getValue();
 
@@ -168,7 +168,7 @@ unsigned TargetData::getIndexedOffset(const Type *ptrTy,
       // Update Ty to refer to current element
       Ty = STy->getElementTypes()[FieldNo];
 
-    } else if (const ArrayType *ATy = Ty->dyncastArrayType()) {
+    } else if (const ArrayType *ATy = dyn_cast<const ArrayType>(Ty)) {
       assert(0 && "Loading from arrays not implemented yet!");
     } else {
       assert(0 && "Indexing type that is not struct or array?");
index 8bc0a77cd1f2f8d6be9341c7e56b8ac7828c7fdc..c8afc27e3ecb03cce86cdf4562b67d77b996f6fb 100644 (file)
@@ -63,12 +63,11 @@ static inline void RemapInstruction(Instruction *I,
 // method by one level.
 //
 bool opt::InlineMethod(BasicBlock::iterator CIIt) {
-  assert((*CIIt)->getOpcode() == Instruction::Call && 
-        "InlineMethod only works on CallInst nodes!");
+  assert(isa<CallInst>(*CIIt) && "InlineMethod only works on CallInst nodes!");
   assert((*CIIt)->getParent() && "Instruction not embedded in basic block!");
   assert((*CIIt)->getParent()->getParent() && "Instruction not in method!");
 
-  CallInst *CI = (CallInst*)*CIIt;
+  CallInst *CI = cast<CallInst>(*CIIt);
   const Method *CalledMeth = CI->getCalledMethod();
   if (CalledMeth->isExternal()) return false;  // Can't inline external method!
   Method *CurrentMeth = CI->getParent()->getParent();
@@ -152,13 +151,13 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) {
     // Copy over the terminator now...
     switch (TI->getOpcode()) {
     case Instruction::Ret: {
-      const ReturnInst *RI = (const ReturnInst*)TI;
+      const ReturnInst *RI = cast<const ReturnInst>(TI);
 
       if (PHI) {   // The PHI node should include this value!
        assert(RI->getReturnValue() && "Ret should have value!");
        assert(RI->getReturnValue()->getType() == PHI->getType() && 
               "Ret value not consistent in method!");
-       PHI->addIncoming((Value*)RI->getReturnValue(), (BasicBlock*)BB);
+       PHI->addIncoming((Value*)RI->getReturnValue(), cast<BasicBlock>(BB));
       }
 
       // Add a branch to the code that was after the original Call.
@@ -236,9 +235,8 @@ 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)->getOpcode() == Instruction::Call) {
+    if (CallInst *CI = dyn_cast<CallInst>(*I)) {
       // Check to see if we should inline this method
-      CallInst *CI = (CallInst*)*I;
       Method *M = CI->getCalledMethod();
       if (ShouldInlineMethod(CI, M))
        return InlineMethod(I);
index ea36745c68a0e5f4b63b18fd19bce372e5ecb53a..18c851b1188d8fcd6908413ad0b2ba8ad5d05743 100644 (file)
@@ -14,6 +14,7 @@
 #include "llvm/Support/DepthFirstIterator.h"
 #include "llvm/Analysis/Writer.h"
 #include "llvm/iTerminators.h"
+#include "llvm/iOther.h"
 #include <set>
 #include <algorithm>
 
@@ -171,15 +172,15 @@ bool ADCE::doADCE() {
   set<BasicBlock*> VisitedBlocks;
   BasicBlock *EntryBlock = fixupCFG(M->front(), VisitedBlocks, AliveBlocks);
   if (EntryBlock && EntryBlock != M->front()) {
-    if (EntryBlock->front()->isPHINode()) {
+    if (isa<PHINode>(EntryBlock->front())) {
       // Cannot make the first block be a block with a PHI node in it! Instead,
       // strip the first basic block of the method to contain no instructions,
       // then add a simple branch to the "real" entry node...
       //
       BasicBlock *E = M->front();
-      if (!E->front()->isTerminator() ||   // Check for an actual change...
-         ((TerminatorInst*)E->front())->getNumSuccessors() != 1 ||
-         ((TerminatorInst*)E->front())->getSuccessor(0) != EntryBlock) {
+      if (!isa<TerminatorInst>(E->front()) || // Check for an actual change...
+         cast<TerminatorInst>(E->front())->getNumSuccessors() != 1 ||
+         cast<TerminatorInst>(E->front())->getSuccessor(0) != EntryBlock) {
        E->getInstList().delete_all();      // Delete all instructions in block
        E->getInstList().push_back(new BranchInst(EntryBlock));
        MadeChanges = true;
index d43f693dd17955b36f8ccb48e3399e5912a20667..61c026a139204906c2b06cc26e7197a63d00931c 100644 (file)
@@ -82,8 +82,7 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
 //
 bool opt::ConstantFoldTerminator(TerminatorInst *T) {
   // Branch - See if we are conditional jumping on constant
-  if (T->getOpcode() == Instruction::Br) {
-    BranchInst *BI = (BranchInst*)T;
+  if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
     if (BI->isUnconditional()) return false;  // Can't optimize uncond branch
     BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0));
     BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1));
@@ -136,22 +135,22 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
 inline static bool 
 ConstantFoldInstruction(Method *M, Method::inst_iterator &II) {
   Instruction *Inst = *II;
-  if (Inst->isBinaryOp()) {
+  if (BinaryOperator *BInst = dyn_cast<BinaryOperator>(Inst)) {
     ConstPoolVal *D1 = dyn_cast<ConstPoolVal>(Inst->getOperand(0));
     ConstPoolVal *D2 = dyn_cast<ConstPoolVal>(Inst->getOperand(1));
 
     if (D1 && D2)
-      return ConstantFoldBinaryInst(M, II, (BinaryOperator*)Inst, D1, D2);
+      return ConstantFoldBinaryInst(M, II, cast<BinaryOperator>(Inst), D1, D2);
 
-  } else if (Inst->isUnaryOp()) {
-    ConstPoolVal *D = dyn_cast<ConstPoolVal>(Inst->getOperand(0));
-    if (D) return ConstantFoldUnaryInst(M, II, (UnaryOperator*)Inst, D);
-  } else if (Inst->isTerminator()) {
-    return opt::ConstantFoldTerminator((TerminatorInst*)Inst);
+  } else if (UnaryOperator *UInst = dyn_cast<UnaryOperator>(Inst)) {
+    ConstPoolVal *D = dyn_cast<ConstPoolVal>(UInst->getOperand(0));
+    if (D) return ConstantFoldUnaryInst(M, II, UInst, D);
+  } else if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) {
+    return opt::ConstantFoldTerminator(TInst);
 
-  } else if (Inst->isPHINode()) {
-    PHINode *PN = (PHINode*)Inst; // If it's a PHI node and only has one operand
-                                  // Then replace it directly with that operand.
+  } else if (PHINode *PN = dyn_cast<PHINode>(Inst)) {
+    // If it's a PHI node and only has one operand
+    // Then replace it directly with that operand.
     assert(PN->getOperand(0) && "PHI Node must have at least one operand!");
     if (PN->getNumOperands() == 1) {    // If the PHI Node has exactly 1 operand
       Value *V = PN->getOperand(0);
index ba3db99279f64c3ea522cc8a79258c8a120a1101..10dcf1eeae4f64191a3f786cad02e0b9e8c8d827 100644 (file)
@@ -84,7 +84,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
     return false;   // More than one predecessor...
 
   Instruction *I = BB->front();
-  if (!I->isPHINode()) return false;  // No PHI nodes
+  if (!isa<PHINode>(I)) return false;  // No PHI nodes
 
   //cerr << "Killing PHIs from " << BB;
   //cerr << "Pred #0 = " << *BB->pred_begin();
@@ -92,7 +92,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
   //cerr << "Method == " << BB->getParent();
 
   do {
-    PHINode *PN = (PHINode*)I;
+    PHINode *PN = cast<PHINode>(I);
     assert(PN->getNumOperands() == 2 && "PHI node should only have one value!");
     Value *V = PN->getOperand(0);
 
@@ -100,7 +100,7 @@ static bool RemoveSingularPHIs(BasicBlock *BB) {
     delete BB->getInstList().remove(BB->begin());
 
     I = BB->front();
-  } while (I->isPHINode());
+  } while (isa<PHINode>(I));
        
   return true;  // Yes, we nuked at least one phi node
 }
@@ -120,7 +120,7 @@ static void ReplaceUsesWithConstant(Instruction *I) {
 // Assumption: BB is the single predecessor of Succ.
 //
 static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
-  assert(Succ->front()->isPHINode() && "Only works on PHId BBs!");
+  assert(isa<PHINode>(Succ->front()) && "Only works on PHId BBs!");
 
   // If there is more than one predecessor, and there are PHI nodes in
   // the successor, then we need to add incoming edges for the PHI nodes
@@ -129,7 +129,7 @@ static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
 
   BasicBlock::iterator I = Succ->begin();
   do {                     // Loop over all of the PHI nodes in the successor BB
-    PHINode *PN = (PHINode*)*I;
+    PHINode *PN = cast<PHINode>(*I);
     Value *OldVal = PN->removeIncomingValue(BB);
     assert(OldVal && "No entry in PHI for Pred BB!");
 
@@ -140,7 +140,7 @@ static void PropogatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
     }
 
     ++I;
-  } while ((*I)->isPHINode());
+  } while (isa<PHINode>(*I));
 }
 
 
@@ -198,7 +198,7 @@ bool opt::SimplifyCFG(Method::iterator &BBIt) {
       //cerr << "Killing Trivial BB: \n" << BB;
       
       if (Succ != BB) {   // Arg, don't hurt infinite loops!
-       if (Succ->front()->isPHINode()) {
+       if (isa<PHINode>(Succ->front())) {
          // If our successor has PHI nodes, then we need to update them to
          // include entries for BB's predecessors, not for BB itself.
          //
index f2dcb451535c1148f0d634f4fe8b420bb5284696..9a8eb12c136384b44a7b7b1cc0cf76ec81c1065b 100644 (file)
@@ -41,7 +41,7 @@ static bool isLoopInvariant(cfg::Interval *Int, Value *V) {
   if (!isa<Instruction>(V))
     return true;  // Constants and arguments are always loop invariant
 
-  BasicBlock *ValueBlock = ((Instruction*)V)->getParent();
+  BasicBlock *ValueBlock = cast<Instruction>(V)->getParent();
   assert(ValueBlock && "Instruction not embedded in basic block!");
 
   // For now, only consider values from outside of the interval, regardless of
@@ -80,8 +80,8 @@ static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V,
   switch (I->getOpcode()) {       // Handle each instruction seperately
   case Instruction::Add:
   case Instruction::Sub: {
-    Value *SubV1 = ((BinaryOperator*)I)->getOperand(0);
-    Value *SubV2 = ((BinaryOperator*)I)->getOperand(1);
+    Value *SubV1 = cast<BinaryOperator>(I)->getOperand(0);
+    Value *SubV2 = cast<BinaryOperator>(I)->getOperand(1);
     LIVType SubLIVType1 = isLinearInductionVariableH(Int, SubV1, PN);
     if (SubLIVType1 == isOther) return isOther;  // Early bailout
     LIVType SubLIVType2 = isLinearInductionVariableH(Int, SubV2, PN);
@@ -144,12 +144,11 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
 
   Value *StepExpr = PN->getIncomingValue(1);
   if (!isa<Instruction>(StepExpr) ||
-      ((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
+      cast<Instruction>(StepExpr)->getOpcode() != Instruction::Add)
     return false;
 
-  BinaryOperator *I = (BinaryOperator*)StepExpr;
-  assert(isa<Instruction>(I->getOperand(0)) && 
-      ((Instruction*)I->getOperand(0))->isPHINode() &&
+  BinaryOperator *I = cast<BinaryOperator>(StepExpr);
+  assert(isa<PHINode>(I->getOperand(0)) && 
         "PHI node should be first operand of ADD instruction!");
 
   // Get the right hand side of the ADD node.  See if it is a constant 1.
@@ -225,7 +224,7 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) {
   // Insert the Add instruction as the first (non-phi) instruction in the 
   // header node's basic block.
   BasicBlock::iterator I = IL.begin();
-  while ((*I)->isPHINode()) ++I;
+  while (isa<PHINode>(*I)) ++I;
   IL.insert(I, AddNode);
   return PN;
 }
@@ -256,8 +255,8 @@ static bool ProcessInterval(cfg::Interval *Int) {
   BasicBlock *Header = Int->getHeaderNode();
   // Loop over all of the PHI nodes in the interval header...
   for (BasicBlock::iterator I = Header->begin(), E = Header->end(); 
-       I != E && (*I)->isPHINode(); ++I) {
-    PHINode *PN = (PHINode*)*I;
+       I != E && isa<PHINode>(*I); ++I) {
+    PHINode *PN = cast<PHINode>(*I);
     if (PN->getNumIncomingValues() != 2) { // These should be eliminated by now.
       cerr << "Found interval header with more than 2 predecessors! Ignoring\n";
       return false;    // Todo, make an assertion.
index 91e002d8be99ae22e6ea0af0fbbb9c07991619b2..b92b54fd649b522d2621999740aa4509777db21e 100644 (file)
@@ -270,7 +270,7 @@ bool SCCP::doSCCP() {
       MadeChanges = true;
       continue;   // Skip the ++II at the end of the loop here...
     } else if (Inst->isTerminator()) {
-      MadeChanges |= opt::ConstantFoldTerminator((TerminatorInst*)Inst);
+      MadeChanges |= opt::ConstantFoldTerminator(cast<TerminatorInst>(Inst));
     }
 
     ++II;
@@ -312,7 +312,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
     // Handle PHI nodes...
     //
   case Instruction::PHINode: {
-    PHINode *PN = (PHINode*)I;
+    PHINode *PN = cast<PHINode>(I);
     unsigned NumValues = PN->getNumIncomingValues(), i;
     InstVal *OperandIV = 0;
 
@@ -380,7 +380,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
     //
   case Instruction::Ret: return;  // Method return doesn't affect anything
   case Instruction::Br: {        // Handle conditional branches...
-    BranchInst *BI = (BranchInst*)I;
+    BranchInst *BI = cast<BranchInst>(I);
     if (BI->isUnconditional()) 
       return; // Unconditional branches are already handled!
 
@@ -391,7 +391,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
       markExecutable(BI->getSuccessor(1));
     } else if (BCValue.isConstant()) {
       // Constant condition variables mean the branch can only go a single way.
-      ConstPoolBool *CPB = (ConstPoolBool*)BCValue.getConstant();
+      ConstPoolBool *CPB = cast<ConstPoolBool>(BCValue.getConstant());
       if (CPB->getValue())       // If the branch condition is TRUE...
        markExecutable(BI->getSuccessor(0));
       else                       // Else if the br cond is FALSE...
@@ -401,7 +401,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
   }
 
   case Instruction::Switch: {
-    SwitchInst *SI = (SwitchInst*)I;
+    SwitchInst *SI = cast<SwitchInst>(I);
     InstVal &SCValue = getValueState(SI->getCondition());
     if (SCValue.isOverdefined()) {  // Overdefined condition?  All dests are exe
       for(unsigned i = 0; BasicBlock *Succ = SI->getSuccessor(i); ++i)
@@ -432,9 +432,9 @@ void SCCP::UpdateInstruction(Instruction *I) {
   //   Also treated as unary here, are cast instructions and getelementptr
   //   instructions on struct* operands.
   //
-  if (I->isUnaryOp() || I->getOpcode() == Instruction::Cast || 
-      (I->getOpcode() == Instruction::GetElementPtr &&
-       ((GetElementPtrInst*)I)->isStructSelector())) {
+  if (isa<UnaryOperator>(I) || isa<CastInst>(I) ||
+      (isa<GetElementPtrInst>(I) &&
+       cast<GetElementPtrInst>(I)->isStructSelector())) {
 
     Value *V = I->getOperand(0);
     InstVal &VState = getValueState(V);
@@ -458,8 +458,7 @@ void SCCP::UpdateInstruction(Instruction *I) {
   //===-----------------------------------------------------------------===//
   // Handle Binary instructions...
   //
-  if (I->isBinaryOp() || I->getOpcode() == Instruction::Shl || 
-      I->getOpcode() == Instruction::Shr) {
+  if (isa<BinaryOperator>(I) || isa<ShiftInst>(I)) {
     Value *V1 = I->getOperand(0);
     Value *V2 = I->getOperand(1);
 
index b9a1c6dbeed2ff47169ff834878a2f8c4fa12ee8..d317bd72918fec40f92feead840e1bb354270bc9 100644 (file)
@@ -192,7 +192,7 @@ void AssemblyWriter::processMethod(const Method *M) {
 
 
   // Finish printing arguments...
-  const MethodType *MT = (const MethodType*)M->getType();
+  const MethodType *MT = cast<const MethodType>(M->getType());
   if (MT->isVarArg()) {
     if (MT->getParamTypes().size()) Out << ", ";
     Out << "...";  // Output varargs portion of signature!
@@ -287,7 +287,7 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
       writeOperand(I->getOperand(op+1), true);
     }
     Out << "\n\t]";
-  } else if (I->isPHINode()) {
+  } else if (isa<PHINode>(I)) {
     Out << " " << Operand->getType();
 
     Out << " [";  writeOperand(Operand, false); Out << ",";
@@ -311,7 +311,7 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
     Out << " )";
   } else if (I->getOpcode() == Instruction::Malloc || 
             I->getOpcode() == Instruction::Alloca) {
-    Out << " " << ((const PointerType*)I->getType())->getValueType();
+    Out << " " << cast<const PointerType>(I->getType())->getValueType();
     if (I->getNumOperands()) {
       Out << ",";
       writeOperand(I->getOperand(0), true);
index 81c1f11616e11cf88071dc844e7bb6b3755d50dd..462b98fb87dac9100b362e587846a007ee06e329 100644 (file)
@@ -54,14 +54,14 @@ void BasicBlock::setParent(Method *parent) {
 TerminatorInst *BasicBlock::getTerminator() {
   if (InstList.empty()) return 0;
   Instruction *T = InstList.back();
-  if (T->isTerminator()) return (TerminatorInst*)T;
+  if (isa<TerminatorInst>(T)) return cast<TerminatorInst>(T);
   return 0;
 }
 
 const TerminatorInst *const BasicBlock::getTerminator() const {
   if (InstList.empty()) return 0;
-  const Instruction *T = InstList.back();
-  if (T->isTerminator()) return (TerminatorInst*)T;
+  if (const TerminatorInst *TI = dyn_cast<TerminatorInst>(InstList.back()))
+    return TI;
   return 0;
 }
 
@@ -92,7 +92,7 @@ bool BasicBlock::hasConstantPoolReferences() const {
 void BasicBlock::removePredecessor(BasicBlock *Pred) {
   assert(find(pred_begin(), pred_end(), Pred) != pred_end() &&
         "removePredecessor: BB is not a predecessor!");
-  if (!front()->isPHINode()) return;   // Quick exit.
+  if (!isa<PHINode>(front())) return;   // Quick exit.
 
   pred_iterator PI(pred_begin()), EI(pred_end());
   unsigned max_idx;
@@ -105,8 +105,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
   // altogether.
   assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
   if (max_idx <= 2) {                // <= Two predecessors BEFORE I remove one?
-    while (front()->isPHINode()) {   // Yup, loop through and nuke the PHI nodes
-      PHINode *PN = (PHINode*)front();
+    // Yup, loop through and nuke the PHI nodes
+    while (PHINode *PN = dyn_cast<PHINode>(front())) {
       PN->removeIncomingValue(Pred); // Remove the predecessor first...
       
       assert(PN->getNumIncomingValues() == max_idx-1 && 
@@ -121,10 +121,8 @@ void BasicBlock::removePredecessor(BasicBlock *Pred) {
     // Okay, now we know that we need to remove predecessor #pred_idx from all
     // PHI nodes.  Iterate over each PHI node fixing them up
     iterator II(begin());
-    for (; (*II)->isPHINode(); ++II) {
-      PHINode *PN = (PHINode*)*II;
-      PN->removeIncomingValue(Pred);
-    }
+    for (; isa<PHINode>(*II); ++II)
+      cast<PHINode>(*II)->removeIncomingValue(Pred);
   }
 }
 
index bf538bd25166f2d704a8f8bd9f6252b646ca2c18..f53c090f70b6a7df0295824df0a89c2900a6cea4 100644 (file)
@@ -45,13 +45,13 @@ ConstPoolVal *ConstPoolVal::getNullConstant(const Type *Ty) {
   case Type::DoubleTyID: return ConstPoolFP::get(Ty, 0);
 
   case Type::PointerTyID: 
-    return ConstPoolPointer::getNullPointer(Ty->castPointerType());
+    return ConstPoolPointer::getNullPointer(cast<PointerType>(Ty));
   default:
     return 0;
   }
 }
 
-bool ConstPoolInt::isa(const ConstPoolVal *CPV) {
+bool ConstPoolInt::classof(const ConstPoolVal *CPV) {
   return CPV->getType()->isIntegral();
 }
 
index 3b95fb74e2ade91be6d2429192606d8f59928273..a103b60d7948c41b09519e0f5b908769d3a67eab 100644 (file)
@@ -192,7 +192,7 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
   if (!Ty->isAbstract() && !Ty->isRecursive() && // Base case for the recursion
       Ty->getDescription().size()) {
     Result = Ty->getDescription();               // Primitive = leaf type
-  } else if (Ty->isOpaqueType()) {               // Base case for the recursion
+  } else if (isa<OpaqueType>(Ty)) {              // Base case for the recursion
     Result = Ty->getDescription();               // Opaque = leaf type
     isAbstract = true;                           // This whole type is abstract!
   } else {
@@ -212,7 +212,7 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
       
       switch (Ty->getPrimitiveID()) {
       case Type::MethodTyID: {
-       const MethodType *MTy = (const MethodType*)Ty;
+       const MethodType *MTy = cast<const MethodType>(Ty);
        Result = getTypeProps(MTy->getReturnType(), TypeStack,
                              isAbstract, isRecursive)+" (";
        for (MethodType::ParamTypes::const_iterator
@@ -230,7 +230,7 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
        break;
       }
       case Type::StructTyID: {
-       const StructType *STy = (const StructType*)Ty;
+       const StructType *STy = cast<const StructType>(Ty);
        Result = "{ ";
        for (StructType::ElementTypes::const_iterator
               I = STy->getElementTypes().begin(),
@@ -243,13 +243,13 @@ static string getTypeProps(const Type *Ty, vector<const Type *> &TypeStack,
        break;
       }
       case Type::PointerTyID: {
-       const PointerType *PTy = (const PointerType*)Ty;
+       const PointerType *PTy = cast<const PointerType>(Ty);
        Result = getTypeProps(PTy->getValueType(), TypeStack,
                              isAbstract, isRecursive) + " *";
        break;
       }
       case Type::ArrayTyID: {
-       const ArrayType *ATy = (const ArrayType*)Ty;
+       const ArrayType *ATy = cast<const ArrayType>(Ty);
        int NumElements = ATy->getNumElements();
        Result = "[";
        if (NumElements != -1) Result += itostr(NumElements) + " x ";
@@ -319,8 +319,8 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
   // algorithm is the fact that arraytypes have sizes that differentiates types,
   // consider this now.
   if (Ty->isArrayType())
-    if (((const ArrayType*)Ty)->getNumElements() !=
-       ((const ArrayType*)Ty2)->getNumElements()) return false;
+    if (cast<const ArrayType>(Ty)->getNumElements() !=
+       cast<const ArrayType>(Ty2)->getNumElements()) return false;
 
   return I == IE && I2 == IE2;    // Types equal if both iterators are done
 }