Convert more code to use new style casts
authorChris Lattner <sabre@nondot.org>
Mon, 1 Oct 2001 20:11:19 +0000 (20:11 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 1 Oct 2001 20:11:19 +0000 (20:11 +0000)
Eliminate old style casts from value.h

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@696 91177308-0d34-0410-b5e6-96231b3b80d8

29 files changed:
include/llvm/Analysis/ConstantsScanner.h
include/llvm/Analysis/InstForest.h
include/llvm/ConstPoolVals.h
include/llvm/Value.h
lib/Analysis/Expressions.cpp
lib/AsmParser/ParserInternals.h
lib/Bytecode/Reader/ConstantReader.cpp
lib/Bytecode/Reader/InstructionReader.cpp
lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Reader/ReaderInternals.h
lib/Bytecode/Writer/SlotCalculator.cpp
lib/Bytecode/Writer/Writer.cpp
lib/CodeGen/InstrSched/SchedGraph.cpp
lib/CodeGen/InstrSelection/InstrForest.cpp
lib/CodeGen/MachineInstr.cpp
lib/ExecutionEngine/Interpreter/Execution.cpp
lib/ExecutionEngine/Interpreter/UserInput.cpp
lib/Target/SparcV9/InstrSched/SchedGraph.cpp
lib/Target/SparcV9/InstrSelection/InstrForest.cpp
lib/Target/SparcV9/SparcV9InstrSelection.cpp
lib/Transforms/IPO/InlineSimple.cpp
lib/Transforms/Scalar/ConstantProp.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/Function.cpp
lib/VMCore/SlotCalculator.cpp

index cbf976573e0768e15eb10957b2018970092a1cef..4c86834d214947789ca84d2edbe76db6de8900aa 100644 (file)
@@ -24,7 +24,7 @@ class constant_iterator
   inline bool isAtConstant() const {
     assert(!InstI.atEnd() && OpIdx < InstI->getNumOperands() &&
           "isAtConstant called with invalid arguments!");
-    return InstI->getOperand(OpIdx)->isConstant();
+    return isa<ConstPoolVal>(InstI->getOperand(OpIdx));
   }
 
 public:
index eac08f91e580b0ab53d0e4893d0c484d70934375..967ed45ec967022374778e3c89980051a3c4a4b1 100644 (file)
@@ -116,7 +116,7 @@ public:
     }
 
     o << getValue();
-    if (!getValue()->isInstruction()) o << "\n";
+    if (!isa<Instruction>(getValue())) o << "\n";
 
     for (unsigned i = 0; i < getNumChildren(); ++i)
       getChild(i)->print(o, Indent+1);
@@ -229,7 +229,7 @@ InstTreeNode<Payload>::InstTreeNode(InstForest<Payload> &IF, Value *V,
                                    InstTreeNode *Parent) : super(Parent) {
   getTreeData().first.first = V;   // Save tree node
  
-  if (!V->isInstruction()) {
+  if (!isa<Instruction>(V)) {
     assert((isa<ConstPoolVal>(V) || isa<BasicBlock>(V) ||
            isa<MethodArgument>(V) || isa<GlobalVariable>(V)) &&
           "Unrecognized value type for InstForest Partition!");
index 1bd2dce8117eb9b3ab6ca4a2282d6a365f341995..342070c9caf9f661f406bb55be8be0f5951450c7 100644 (file)
@@ -66,6 +66,15 @@ public:
 
   virtual string getStrValue() const;
   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) {
+    return (CPV == True) | (CPV == False);
+  }
+  static inline bool isa(const Value *V) {
+    return ::isa<ConstPoolVal>(V) && isa(cast<ConstPoolVal>(V));
+  }
 };
 
 
@@ -97,6 +106,13 @@ public:
   // specified value.  as above, we work only with very small values here.
   //
   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));
+  }
 };
 
 
@@ -117,7 +133,6 @@ public:
   inline int64_t getValue() const { return Val.Signed; }
 };
 
-
 //===---------------------------------------------------------------------------
 // ConstPoolUInt - Unsigned Integer Values [ubyte, ushort, uint, ulong]
 //
index 3ef46cac86a12008cedabcdbb62f0855c579977e..1acf2e299ddb90dbea08cf1dc7d149f598fb70ff 100644 (file)
@@ -79,34 +79,12 @@ public:
   // equivalent to using dynamic_cast<>... if the cast is successful, this is
   // returned, otherwise you get a null pointer.
   //
-  // This section also defines a family of isType, isConstant,
-  // isMethodArgument, etc functions...
-  //
   // The family of functions Val->cast<type>Asserting() is used in the same
   // way as the Val->cast<type>() instructions, but they assert the expected
   // type instead of checking it at runtime.
   //
   inline ValueTy getValueType() const { return VTy; }
   
-  // Use a macro to define the functions, otherwise these definitions are just
-  // really long and ugly.
-#define CAST_FN(NAME, CLASS)                                              \
-  inline bool is##NAME() const { return VTy == NAME##Val; }               \
-  inline const CLASS *cast##NAME() const { /*const version */             \
-    return is##NAME() ? (const CLASS*)this : 0;                           \
-  }                                                                       \
-  inline CLASS *cast##NAME() {         /* nonconst version */             \
-    return is##NAME() ? (CLASS*)this : 0;                                 \
-  }                                                                       \
-
-  CAST_FN(Constant      ,       ConstPoolVal  )
-  CAST_FN(MethodArgument,       MethodArgument)
-  CAST_FN(Instruction   ,       Instruction   )
-  CAST_FN(BasicBlock    ,       BasicBlock    )
-  CAST_FN(Method        ,       Method        )
-  CAST_FN(Global        ,       GlobalVariable)
-#undef CAST_FN
-
   // replaceAllUsesWith - Go through the uses list for this definition and make
   // each use point to "D" instead of "this".  After this completes, 'this's 
   // use list should be empty.
@@ -207,7 +185,7 @@ template <class X> class real_type <class UseTy<X> > { typedef X *Type; };
 //  if (isa<Type>(myVal)) { ... }
 //
 template <class X, class Y>
-bool isa(Y Val) { return X::isa(Val); }
+inline bool isa(Y Val) { return X::isa(Val); }
 
 
 // cast<X> - Return the argument parameter cast to the specified type.  This
@@ -218,7 +196,7 @@ bool isa(Y Val) { return X::isa(Val); }
 //  cast<const Instruction>(myVal)->getParent()
 //
 template <class X, class Y>
-X *cast(Y Val) {
+inline X *cast(Y Val) {
   assert(isa<X>(Val) && "Invalid cast argument type!");
   return (X*)(real_type<Y>::Type)Val;
 }
@@ -233,7 +211,7 @@ X *cast(Y Val) {
 //
 
 template <class X, class Y>
-X *dyn_cast(Y Val) {
+inline X *dyn_cast(Y Val) {
   return isa<X>(Val) ? cast<X>(Val) : 0;
 }
 
@@ -241,28 +219,52 @@ X *dyn_cast(Y Val) {
 // isa - Provide some specializations of isa so that we have to include the
 // subtype header files to test to see if the value is a subclass...
 //
-template <> bool isa<Type, Value*>(Value *Val) { 
+template <> inline bool isa<Type, const Value*>(const Value *Val) { 
   return Val->getValueType() == Value::TypeVal;
 }
-template <> bool isa<ConstPoolVal, Value*>(Value *Val) { 
+template <> inline bool isa<Type, Value*>(Value *Val) { 
+  return Val->getValueType() == Value::TypeVal;
+}
+template <> inline bool isa<ConstPoolVal, const Value*>(const Value *Val) { 
   return Val->getValueType() == Value::ConstantVal; 
 }
-template <> bool isa<MethodArgument, Value*>(Value *Val) { 
+template <> inline bool isa<ConstPoolVal, Value*>(Value *Val) { 
+  return Val->getValueType() == Value::ConstantVal; 
+}
+template <> inline bool isa<MethodArgument, const Value*>(const Value *Val) { 
+  return Val->getValueType() == Value::MethodArgumentVal;
+}
+template <> inline bool isa<MethodArgument, Value*>(Value *Val) { 
   return Val->getValueType() == Value::MethodArgumentVal;
 }
-template <> bool isa<Instruction, Value*>(Value *Val) { 
+template <> inline bool isa<Instruction, const Value*>(const Value *Val) { 
+  return Val->getValueType() == Value::InstructionVal;
+}
+template <> inline bool isa<Instruction, Value*>(Value *Val) { 
   return Val->getValueType() == Value::InstructionVal;
 }
-template <> bool isa<BasicBlock, Value*>(Value *Val) { 
+template <> inline bool isa<BasicBlock, const Value*>(const Value *Val) { 
+  return Val->getValueType() == Value::BasicBlockVal;
+}
+template <> inline bool isa<BasicBlock, Value*>(Value *Val) { 
   return Val->getValueType() == Value::BasicBlockVal;
 }
-template <> bool isa<Method, Value*>(Value *Val) { 
+template <> inline bool isa<Method, const Value*>(const Value *Val) { 
+  return Val->getValueType() == Value::MethodVal;
+}
+template <> inline bool isa<Method, Value*>(Value *Val) { 
   return Val->getValueType() == Value::MethodVal;
 }
-template <> bool isa<GlobalVariable, Value*>(Value *Val) { 
+template <> inline bool isa<GlobalVariable, const Value*>(const Value *Val) { 
   return Val->getValueType() == Value::GlobalVal;
 }
-template <> bool isa<Module, Value*>(Value *Val) { 
+template <> inline bool isa<GlobalVariable, Value*>(Value *Val) { 
+  return Val->getValueType() == Value::GlobalVal;
+}
+template <> inline bool isa<Module, const Value*>(const Value *Val) { 
+  return Val->getValueType() == Value::ModuleVal;
+}
+template <> inline bool isa<Module, Value*>(Value *Val) { 
   return Val->getValueType() == Value::ModuleVal;
 }
 
index 8c9d75f2bd299fa624e091a1ae12224d07941d42..cb83d41236ed1a3866a82d510c98e0249f9d74e6 100644 (file)
@@ -16,14 +16,17 @@ using namespace opt;  // Get all the constant handling stuff
 using namespace analysis;
 
 ExprType::ExprType(Value *Val) {
-  if (Val && Val->isConstant() && Val->getType()->isIntegral()) {
-    Offset = (ConstPoolInt*)Val->castConstant();
-    Var = 0;
-    ExprTy = Constant;
-  } else {
-    Var = Val; Offset = 0;
-    ExprTy = Var ? Linear : Constant;
-  }
+  if (Val) 
+    if (ConstPoolInt *CPI = dyn_cast<ConstPoolInt>(Val)) {
+      Offset = CPI;
+      Var = 0;
+      ExprTy = Constant;
+      Scale = 0;
+      return;
+    }
+
+  Var = Val; Offset = 0;
+  ExprTy = Var ? Linear : Constant;
   Scale = 0;
 }
 
index 88986c288ab8aed2631193a68d639bcfecf9d481..bedb65f4a861837df95f5a3cb27403a12179a5a8 100644 (file)
@@ -167,10 +167,7 @@ struct BBPlaceHolderHelper : public BasicBlock {
 };
 
 struct MethPlaceHolderHelper : public Method {
-  MethPlaceHolderHelper(const Type *Ty) 
-    : Method((const MethodType*)Ty) {
-    assert(Ty->isMethodType() && "Method placeholders must be method types!");
-  }
+  MethPlaceHolderHelper(const Type *Ty) : Method(cast<const MethodType>(Ty)) {}
 };
 
 typedef PlaceholderValue<TypePlaceHolderHelper>  TypePlaceHolder;
index 67cfff7b973fb2ecea2bc6b5f15f4057ae439515..aaecedddfa7aed174359788c3384d545ff947638 100644 (file)
@@ -241,8 +241,8 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
       unsigned Slot;
       if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
       Value *V = getValue(AT->getElementType(), Slot, false);
-      if (!V || !V->isConstant()) return failure(true);
-      Elements.push_back((ConstPoolVal*)V);
+      if (!V || !isa<ConstPoolVal>(V)) return failure(true);
+      Elements.push_back(cast<ConstPoolVal>(V));
     }
     V = ConstPoolArray::get(AT, Elements);
     break;
@@ -257,9 +257,9 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf,
       unsigned Slot;
       if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
       Value *V = getValue(ET[i], Slot, false);
-      if (!V || !V->isConstant())
+      if (!V || !isa<ConstPoolVal>(V))
        return failure(true);
-      Elements.push_back((ConstPoolVal*)V);      
+      Elements.push_back(cast<ConstPoolVal>(V));      
     }
 
     V = ConstPoolStruct::get(ST, Elements);
index 8c3e08ff94e4f5940cac3e98cf0ca8a580749319..300c40999eb17d599957cf34d8e9d4abf29ce90a 100644 (file)
@@ -266,25 +266,25 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
     case 0: cerr << "Invalid load encountered!\n"; return failure(true);
     case 1: break;
     case 2: V = getValue(Type::UByteTy, Raw.Arg2);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
             break;
     case 3: V = getValue(Type::UByteTy, Raw.Arg2);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
            V = getValue(Type::UByteTy, Raw.Arg3);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
             break;
     default:
       V = getValue(Type::UByteTy, Raw.Arg2);
-      if (!V->isConstant()) return failure(true);
-      Idx.push_back(V->castConstant());
+      if (!isa<ConstPoolVal>(V)) return failure(true);
+      Idx.push_back(cast<ConstPoolVal>(V));
       vector<unsigned> &args = *Raw.VarArgs;
       for (unsigned i = 0, E = args.size(); i != E; ++i) {
        V = getValue(Type::UByteTy, args[i]);
-       if (!V->isConstant()) return failure(true);
-       Idx.push_back(V->castConstant());
+       if (!isa<ConstPoolVal>(V)) return failure(true);
+       Idx.push_back(cast<ConstPoolVal>(V));
       }
       delete Raw.VarArgs; 
       break;
@@ -304,15 +304,15 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
     case 1: cerr << "Invalid store encountered!\n"; return failure(true);
     case 2: break;
     case 3: V = getValue(Type::UByteTy, Raw.Arg3);
-            if (!V->isConstant()) return failure(true);
-            Idx.push_back(V->castConstant());
+            if (!isa<ConstPoolVal>(V)) return failure(true);
+            Idx.push_back(cast<ConstPoolVal>(V));
             break;
     default:
       vector<unsigned> &args = *Raw.VarArgs;
       for (unsigned i = 0, E = args.size(); i != E; ++i) {
        V = getValue(Type::UByteTy, args[i]);
-       if (!V->isConstant()) return failure(true);
-       Idx.push_back(V->castConstant());
+       if (!isa<ConstPoolVal>(V)) return failure(true);
+       Idx.push_back(cast<ConstPoolVal>(V));
       }
       delete Raw.VarArgs; 
       break;
index b7904bb60f797d20a5c729ac545bb284913acc80..0e4883034e61b50e6fd06ad0eaad90b24a6ae4d2 100644 (file)
@@ -206,7 +206,7 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf,
        return failure(true);
       }
       BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D;
-               if (!D->isInstruction()) cerr << endl);
+               if (!isa<Instruction>(D)) cerr << endl);
 
       D->setName(Name, ST);
     }
@@ -291,7 +291,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
 
   Value *MethPHolder = getValue(MTy, MethSlot, false);
   assert(MethPHolder && "Something is broken no placeholder found!");
-  assert(MethPHolder->isMethod() && "Not a method?");
+  assert(isa<Method>(MethPHolder) && "Not a method?");
 
   unsigned type;  // Type slot
   assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
@@ -359,7 +359,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
   if (read_vbr(Buf, End, MethSignature)) return failure(true);
   while (MethSignature != Type::VoidTyID) { // List is terminated by Void
     const Type *Ty = getType(MethSignature);
-    if (!Ty || !Ty->isMethodType()) { 
+    if (!Ty || !isa<MethodType>(Ty)) { 
       cerr << "Method not meth type!  Ty = " << Ty << endl;
       return failure(true); 
     }
index ed4f1a4bba2d8c3d2316bcd09d3423ca0a78159c..cf5a43ef3bbc7d80939abfbd037ab528f7321673 100644 (file)
@@ -129,8 +129,7 @@ struct BBPlaceHolderHelper : public BasicBlock {
 
 struct MethPlaceHolderHelper : public Method {
   MethPlaceHolderHelper(const Type *Ty) 
-    : Method((const MethodType*)Ty) {
-    assert(Ty->isMethodType() && "Method placeholders must be method types!");
+    : Method(cast<const MethodType>(Ty)) {
   }
 };
 
index d0f37fb723e9f7b3a525cb5e818d359d9817fea2..38980e5e63a9ea43fe0254c2f985220e1d9e10b1 100644 (file)
@@ -106,7 +106,7 @@ void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
   for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
     for (SymbolTable::type_const_iterator TI = I->second.begin(), 
           TE = I->second.end(); TI != TE; ++TI)
-      if (TI->second->isConstant())
+      if (isa<ConstPoolVal>(TI->second))
        insertValue(TI->second);
 }
 
@@ -223,7 +223,7 @@ int SlotCalculator::getValSlot(const Value *D) const {
 
 
 int SlotCalculator::insertValue(const Value *D) {
-  if (D->isConstant() || D->isGlobal()) {
+  if (isa<ConstPoolVal>(D) || isa<GlobalVariable>(D)) {
     const User *U = (const User *)D;
     // This makes sure that if a constant has uses (for example an array
     // of const ints), that they are inserted also.  Same for global variable
index 94cbcec328df2129dab21f132a30740dd977ecd3..5df2fdabde5aff860ed495c73ff816c5625847fe 100644 (file)
@@ -79,7 +79,7 @@ void BytecodeWriter::outputConstants(bool isMethod) {
       ValNo = Type::FirstDerivedTyID; // Start emitting at the derived types...
     
     // Scan through and ignore method arguments...
-    for (; ValNo < Plane.size() && Plane[ValNo]->isMethodArgument(); ValNo++)
+    for (; ValNo < Plane.size() && isa<MethodArgument>(Plane[ValNo]); ValNo++)
       /*empty*/;
 
     unsigned NC = ValNo;              // Number of constants
@@ -103,7 +103,7 @@ void BytecodeWriter::outputConstants(bool isMethod) {
 
     for (unsigned i = ValNo; i < ValNo+NC; ++i) {
       const Value *V = Plane[i];
-      if (const ConstPoolVal *CPV = V->castConstant()) {
+      if (const ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
        //cerr << "Serializing value: <" << V->getType() << ">: " 
        //     << ((const ConstPoolVal*)V)->getStrValue() << ":" 
        //     << Out.size() << "\n";
@@ -127,7 +127,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
 
     // Fields: bit0 = isConstant, bit1 = hasInitializer, bit2+ = slot#
     unsigned oSlot = ((unsigned)Slot << 2) | (GV->hasInitializer() << 1) | 
-                        GV->isConstant();
+                        isa<ConstPoolVal>(GV);
     output_vbr(oSlot, Out);
 
     // If we have an initialized, output it now.
index 40601300f764e537b16bbd51d15b437df04e4f84..852c4f2686ab7fddbd1109c896bad5628d92a370 100644 (file)
@@ -532,7 +532,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node,
                       const Value* val,
                       const TargetMachine& target)
 {
-  if (!val->isInstruction()) return;
+  if (!isa<Instruction>(val)) return;
   
   const Instruction* thisVMInstr = node->getInstr();
   const Instruction* defVMInstr  = cast<const Instruction>(val);
@@ -642,7 +642,6 @@ void
 SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
                                    const TargetMachine& target)
 {
-  assert(instr->isInstruction());
   if (instr->isPHINode())
     return;
 
index 9f4df08d3842fead1af7eaa4fc26440f0a6d9062..f5a524707b932b62d60b62f978a187a66fe73a7b 100644 (file)
@@ -275,12 +275,12 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
     
       // Check latter condition here just to simplify the next IF.
       bool includeAddressOperand =
-       (operand->isBasicBlock() || operand->isMethod())
+       (isa<BasicBlock>(operand) || isa<Method>(operand))
        && !instr->isTerminator();
     
-      if (includeAddressOperand || operand->isInstruction() ||
-         operand->isConstant() || operand->isMethodArgument() ||
-         operand->isGlobal()) 
+      if (includeAddressOperand || isa<Instruction>(operand) ||
+         isa<ConstPoolVal>(operand) || isa<MethodArgument>(operand) ||
+         isa<GlobalVariable>(operand))
        {
          // This operand is a data value
        
@@ -300,15 +300,15 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
          // is used directly, i.e., made a child of the instruction node.
          // 
          InstrTreeNode* opTreeNode;
-         if (operand->isInstruction() && operand->use_size() == 1 &&
-             ((Instruction*)operand)->getParent() == instr->getParent() &&
+         if (isa<Instruction>(operand) && operand->use_size() == 1 &&
+             cast<Instruction>(operand)->getParent() == instr->getParent() &&
              ! instr->isPHINode() &&
              instr->getOpcode() != Instruction::Call)
            {
              // Recursively create a treeNode for it.
              opTreeNode = buildTreeForInstruction((Instruction*)operand);
            }
-         else if (ConstPoolVal *CPV = operand->castConstant())
+         else if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(operand))
            {
              // Create a leaf node for a constant
              opTreeNode = new ConstantNode(CPV);
index 1e3300763de2b3dda02f48f7f3a1febe1671cccb..64076286f4bf0da54c39f4aa4ffafe5d2d0a9a34 100644 (file)
@@ -141,7 +141,7 @@ operator<<(ostream &os, const MachineOperand &mop)
     case MachineOperand::MO_PCRelativeDisp:
       {
         const Value* opVal = mop.getVRegValue();
-        bool isLabel = opVal->isMethod() || opVal->isBasicBlock();
+        bool isLabel = isa<Method>(opVal) || isa<BasicBlock>(opVal);
         return os << "%disp("
                   << (isLabel? "label " : "addr-of-val ")
                   << opVal << ")";
@@ -221,7 +221,7 @@ Set3OperandsFromInstrJUNK(MachineInstr* minstr,
     minstr->SetMachineOperand(op1Position, /*regNum*/ target.zeroRegNum);
   else
     {
-      if (op1Value->isConstant())
+      if (isa<ConstPoolVal>(op1Value))
        {
          // value is constant and must be loaded from constant pool
          returnFlags = returnFlags | (1 << op1Position);
@@ -247,7 +247,7 @@ Set3OperandsFromInstrJUNK(MachineInstr* minstr,
        minstr->SetMachineOperand(op2Position, machineRegNum);
       else if (op2type == MachineOperand::MO_VirtualRegister)
        {
-         if (op2Value->isConstant())
+         if (isa<ConstPoolVal>(op2Value))
            {
              // value is constant and must be loaded from constant pool
              returnFlags = returnFlags | (1 << op2Position);
@@ -318,7 +318,7 @@ ChooseRegOrImmed(Value* val,
   
   // Check for the common case first: argument is not constant
   // 
-  ConstPoolVal *CPV = val->castConstant();
+  ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(val);
   if (!CPV) return opType;
 
   if (CPV->getType() == Type::BoolTy)
index 3ecc3ec0eab2939541602a7dbe9272a44109a00f..d88d91ff1f9e7fb416337a62b5b4b03392b67862 100644 (file)
@@ -25,7 +25,7 @@ static unsigned getOperandSlot(Value *V) {
   case Type::TY##TyID: Result.TY##Val = ((CLASS*)CPV)->getValue(); break
 
 static GenericValue getOperandValue(Value *V, ExecutionContext &SF) {
-  if (ConstPoolVal *CPV = V->castConstant()) {
+  if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {
     GenericValue Result;
     switch (CPV->getType()->getPrimitiveID()) {
       GET_CONST_VAL(Bool   , ConstPoolBool);
@@ -48,7 +48,7 @@ static GenericValue getOperandValue(Value *V, ExecutionContext &SF) {
 }
 
 static void printOperandInfo(Value *V, ExecutionContext &SF) {
-  if (!V->isConstant()) {
+  if (!isa<ConstPoolVal>(V)) {
     unsigned TyP  = V->getType()->getUniqueID();   // TypePlane for value
     unsigned Slot = getOperandSlot(V);
     cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
index eb5725feddc2ff8f321ed642b231a1d17c5e5293..e9fc9db3436234adebe8a603bc6988381326ead4 100644 (file)
@@ -134,7 +134,7 @@ bool Interpreter::callMethod(const string &Name) {
   vector<Value*> Options = LookupMatchingNames(Name);
 
   for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches...
-    if (!Options[i]->isMethod()) {
+    if (!isa<Method>(Options[i])) {
       Options.erase(Options.begin()+i);
       --i;
     }
index 40601300f764e537b16bbd51d15b437df04e4f84..852c4f2686ab7fddbd1109c896bad5628d92a370 100644 (file)
@@ -532,7 +532,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node,
                       const Value* val,
                       const TargetMachine& target)
 {
-  if (!val->isInstruction()) return;
+  if (!isa<Instruction>(val)) return;
   
   const Instruction* thisVMInstr = node->getInstr();
   const Instruction* defVMInstr  = cast<const Instruction>(val);
@@ -642,7 +642,6 @@ void
 SchedGraph::addNonSSAEdgesForValue(const Instruction* instr,
                                    const TargetMachine& target)
 {
-  assert(instr->isInstruction());
   if (instr->isPHINode())
     return;
 
index 9f4df08d3842fead1af7eaa4fc26440f0a6d9062..f5a524707b932b62d60b62f978a187a66fe73a7b 100644 (file)
@@ -275,12 +275,12 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
     
       // Check latter condition here just to simplify the next IF.
       bool includeAddressOperand =
-       (operand->isBasicBlock() || operand->isMethod())
+       (isa<BasicBlock>(operand) || isa<Method>(operand))
        && !instr->isTerminator();
     
-      if (includeAddressOperand || operand->isInstruction() ||
-         operand->isConstant() || operand->isMethodArgument() ||
-         operand->isGlobal()) 
+      if (includeAddressOperand || isa<Instruction>(operand) ||
+         isa<ConstPoolVal>(operand) || isa<MethodArgument>(operand) ||
+         isa<GlobalVariable>(operand))
        {
          // This operand is a data value
        
@@ -300,15 +300,15 @@ InstrForest::buildTreeForInstruction(Instruction *instr)
          // is used directly, i.e., made a child of the instruction node.
          // 
          InstrTreeNode* opTreeNode;
-         if (operand->isInstruction() && operand->use_size() == 1 &&
-             ((Instruction*)operand)->getParent() == instr->getParent() &&
+         if (isa<Instruction>(operand) && operand->use_size() == 1 &&
+             cast<Instruction>(operand)->getParent() == instr->getParent() &&
              ! instr->isPHINode() &&
              instr->getOpcode() != Instruction::Call)
            {
              // Recursively create a treeNode for it.
              opTreeNode = buildTreeForInstruction((Instruction*)operand);
            }
-         else if (ConstPoolVal *CPV = operand->castConstant())
+         else if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(operand))
            {
              // Create a leaf node for a constant
              opTreeNode = new ConstantNode(CPV);
index 572e1b175b3cdb173f307cabc5e3a551e62cf8c3..b1b5e01aff5c13cb9646506a8fa3bec872e915a6 100644 (file)
@@ -60,7 +60,7 @@ static int64_t
 GetConstantValueAsSignedInt(const Value *V,
                             bool &isValidConstant)
 {
-  if (!V->isConstant())
+  if (!isa<ConstPoolVal>(V))
     {
       isValidConstant = false;
       return 0;
@@ -374,8 +374,8 @@ ChooseAddInstructionByType(const Type* resultType)
   MachineOpCode opCode = INVALID_OPCODE;
   
   if (resultType->isIntegral() ||
-      resultType->isPointerType() ||
-      resultType->isMethodType() ||
+      isa<PointerType>(resultType) ||
+      isa<MethodType>(resultType) ||
       resultType->isLabelType() ||
       resultType == Type::BoolTy)
     {
@@ -419,7 +419,7 @@ CreateAddConstInstruction(const InstructionNode* instrNode)
   MachineInstr* minstr = NULL;
   
   Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
-  assert(constOp->isConstant());
+  assert(isa<ConstPoolVal>(constOp));
   
   // Cases worth optimizing are:
   // (1) Add with 0 for float or double: use an FMOV of appropriate type,
@@ -469,7 +469,7 @@ CreateSubConstInstruction(const InstructionNode* instrNode)
   MachineInstr* minstr = NULL;
   
   Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
-  assert(constOp->isConstant());
+  assert(isa<ConstPoolVal>(constOp));
   
   // Cases worth optimizing are:
   // (1) Sub with 0 for float or double: use an FMOV of appropriate type,
@@ -575,7 +575,7 @@ CreateMulConstInstruction(TargetMachine &target,
   bool needNeg = false;
 
   Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
-  assert(constOp->isConstant());
+  assert(isa<ConstPoolVal>(constOp));
   
   // Cases worth optimizing are:
   // (1) Multiply by 0 or 1 for any type: replace with copy (ADD or FMOV)
@@ -699,7 +699,7 @@ CreateDivConstInstruction(TargetMachine &target,
   getMinstr2 = NULL;
   
   Value* constOp = ((InstrTreeNode*) instrNode->rightChild())->getValue();
-  assert(constOp->isConstant());
+  assert(isa<ConstPoolVal>(constOp));
   
   // Cases worth optimizing are:
   // (1) Divide by 1 for any type: replace with copy (ADD or FMOV)
@@ -952,7 +952,7 @@ SetMemOperands_Internal(MachineInstr* minstr,
           assert(arrayOffsetVal != NULL
                  && "Expect to be given Value* for array offsets");
           
-          if (ConstPoolVal *CPV = arrayOffsetVal->castConstant())
+          if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(arrayOffsetVal))
             {
               isConstantOffset = true;  // always constant for structs
               assert(arrayOffsetVal->getType()->isIntegral());
@@ -1037,7 +1037,7 @@ CreateLoadConstInstr(const TargetMachine &target,
                      Instruction* dest,
                      MachineInstr*& getMinstr2)
 {
-  assert(val->isConstant());
+  assert(isa<ConstPoolVal>(val));
   
   MachineInstr* minstr1 = NULL;
   
@@ -1183,7 +1183,7 @@ FixConstantOperands(const InstructionNode* vmInstrNode,
           
           Value* opValue = mop.getVRegValue();
           
-          if (opValue->isConstant())
+          if (isa<ConstPoolVal>(opValue))
             {
               unsigned int machineRegNum;
               int64_t immedValue;
@@ -1298,7 +1298,7 @@ CreateCopyInstructionsByType(const TargetMachine& target,
   
   // if `src' is a constant that doesn't fit in the immed field, generate
   // a load instruction instead of an add
-  if (src->isConstant())
+  if (isa<ConstPoolVal>(src))
     {
       unsigned int machineRegNum;
       int64_t immedValue;
index 27ef66e42e3ac33a7c014fed1ed3775aa2b35289..8bc0a77cd1f2f8d6be9341c7e56b8ac7828c7fdc 100644 (file)
@@ -40,7 +40,7 @@ static inline void RemapInstruction(Instruction *I,
   for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
     const Value *Op = I->getOperand(op);
     Value *V = ValueMap[Op];
-    if (!V && (Op->isMethod() || Op->isConstant()))
+    if (!V && (isa<Method>(Op) || isa<ConstPoolVal>(Op)))
       continue;  // Methods and constants don't get relocated
 
     if (!V) {
index 8b879162426cbd44e4c4a9fb26090f47195735d8..d43f693dd17955b36f8ccb48e3399e5912a20667 100644 (file)
@@ -88,9 +88,9 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) {
     BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0));
     BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1));
 
-    if (BI->getCondition()->isConstant()) {    // Are we branching on constant?
+    if (ConstPoolBool *Cond = dyn_cast<ConstPoolBool>(BI->getCondition())) {
+      // Are we branching on constant?
       // YES.  Change to unconditional branch...
-      ConstPoolBool *Cond = (ConstPoolBool*)BI->getCondition();
       BasicBlock *Destination = Cond->getValue() ? Dest1 : Dest2;
       BasicBlock *OldDest     = Cond->getValue() ? Dest2 : Dest1;
 
@@ -137,14 +137,14 @@ inline static bool
 ConstantFoldInstruction(Method *M, Method::inst_iterator &II) {
   Instruction *Inst = *II;
   if (Inst->isBinaryOp()) {
-    ConstPoolVal *D1 = Inst->getOperand(0)->castConstant();
-    ConstPoolVal *D2 = Inst->getOperand(1)->castConstant();
+    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);
 
   } else if (Inst->isUnaryOp()) {
-    ConstPoolVal *D = Inst->getOperand(0)->castConstant();
+    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);
index 6815ccb9a405708e9d085faacc0b916fbeaef858..f2dcb451535c1148f0d634f4fe8b420bb5284696 100644 (file)
@@ -36,9 +36,9 @@ using namespace opt;
 // an interval invariant computation.
 //
 static bool isLoopInvariant(cfg::Interval *Int, Value *V) {
-  assert(V->isConstant() || V->isInstruction() || V->isMethodArgument());
+  assert(isa<ConstPoolVal>(V) || isa<Instruction>(V) || isa<MethodArgument>(V));
 
-  if (!V->isInstruction())
+  if (!isa<Instruction>(V))
     return true;  // Constants and arguments are always loop invariant
 
   BasicBlock *ValueBlock = ((Instruction*)V)->getParent();
@@ -132,7 +132,7 @@ static inline bool isLinearInductionVariable(cfg::Interval *Int, Value *V,
 static inline bool isSimpleInductionVar(PHINode *PN) {
   assert(PN->getNumIncomingValues() == 2 && "Must have cannonical PHI node!");
   Value *Initializer = PN->getIncomingValue(0);
-  if (!Initializer->isConstant()) return false;
+  if (!isa<ConstPoolVal>(Initializer)) return false;
 
   if (Initializer->getType()->isSigned()) {  // Signed constant value...
     if (((ConstPoolSInt*)Initializer)->getValue() != 0) return false;
@@ -143,18 +143,18 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
   }
 
   Value *StepExpr = PN->getIncomingValue(1);
-  if (!StepExpr->isInstruction() ||
+  if (!isa<Instruction>(StepExpr) ||
       ((Instruction*)StepExpr)->getOpcode() != Instruction::Add)
     return false;
 
   BinaryOperator *I = (BinaryOperator*)StepExpr;
-  assert(I->getOperand(0)->isInstruction() && 
+  assert(isa<Instruction>(I->getOperand(0)) && 
       ((Instruction*)I->getOperand(0))->isPHINode() &&
         "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.
   Value *StepSize = I->getOperand(1);
-  if (!StepSize->isConstant()) return false;
+  if (!isa<ConstPoolVal>(StepSize)) return false;
 
   if (StepSize->getType()->isSigned()) {  // Signed constant value...
     if (((ConstPoolSInt*)StepSize)->getValue() != 1) return false;
index 78b6c3df7b41cbf52c2adeef443bc66749135eba..91e002d8be99ae22e6ea0af0fbbb9c07991619b2 100644 (file)
@@ -146,9 +146,9 @@ private:
     map<Value*, InstVal>::iterator I = ValueState.find(V);
     if (I != ValueState.end()) return I->second;  // Common case, in the map
       
-    if (ConstPoolVal *CPV = V->castConstant()) {  // Constants are constant
+    if (ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(V)) {//Constants are constant
       ValueState[CPV].markConstant(CPV);
-    } else if (V->isMethodArgument()) {           // MethodArgs are overdefined
+    } else if (isa<MethodArgument>(V)) {          // MethodArgs are overdefined
       ValueState[V].markOverdefined();
     } 
     // All others are underdefined by default...
index 3c67c2ca088c6eb70163a0f4c621a588587b557b..b9a1c6dbeed2ff47169ff834878a2f8c4fa12ee8 100644 (file)
@@ -143,9 +143,9 @@ void AssemblyWriter::processSymbolTable(const SymbolTable &ST) {
     
     for (; I != End; ++I) {
       const Value *V = I->second;
-      if (const ConstPoolVal *CPV = cast<const ConstPoolVal>(V)) {
+      if (const ConstPoolVal *CPV = dyn_cast<const ConstPoolVal>(V)) {
        processConstant(CPV);
-      } else if (const Type *Ty = cast<const Type>(V)) {
+      } else if (const Type *Ty = dyn_cast<const Type>(V)) {
        Out << "\t%" << I->first << " = type " << Ty->getDescription() << endl;
       }
     }
index 7d97c85f7de3001f264727c33ada8eddcd3bcb75..81c1f11616e11cf88071dc844e7bb6b3755d50dd 100644 (file)
@@ -77,7 +77,7 @@ void BasicBlock::dropAllReferences() {
 //
 bool BasicBlock::hasConstantPoolReferences() const {
   for (use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
-    if ((*I)->isConstant())
+    if (::isa<ConstPoolVal>(*I))
       return true;
 
   return false;
index 374c583ab9bb5e8e2d4cc97295e953185c0d959c..bf538bd25166f2d704a8f8bd9f6252b646ca2c18 100644 (file)
@@ -51,7 +51,9 @@ ConstPoolVal *ConstPoolVal::getNullConstant(const Type *Ty) {
   }
 }
 
-
+bool ConstPoolInt::isa(const ConstPoolVal *CPV) {
+  return CPV->getType()->isIntegral();
+}
 
 //===----------------------------------------------------------------------===//
 //                            ConstPoolXXX Classes
index 5d1132f0a7d6f2d78df77cb1bb28138527ca1fbb..9eb8277a272606bd000d45befb851a5e21c8596d 100644 (file)
@@ -28,7 +28,7 @@ template class ValueHolder<BasicBlock    , Method, Method>;
 Method::Method(const MethodType *Ty, const string &name) 
   : Value(Ty, Value::MethodVal, name), SymTabValue(this), BasicBlocks(this), 
     ArgumentList(this, this) {
-  assert(Ty->isMethodType() && "Method signature must be of method type!");
+  assert(::isa<MethodType>(Ty) && "Method signature must be of method type!");
   Parent = 0;
 }
 
index d0f37fb723e9f7b3a525cb5e818d359d9817fea2..38980e5e63a9ea43fe0254c2f985220e1d9e10b1 100644 (file)
@@ -106,7 +106,7 @@ void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
   for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
     for (SymbolTable::type_const_iterator TI = I->second.begin(), 
           TE = I->second.end(); TI != TE; ++TI)
-      if (TI->second->isConstant())
+      if (isa<ConstPoolVal>(TI->second))
        insertValue(TI->second);
 }
 
@@ -223,7 +223,7 @@ int SlotCalculator::getValSlot(const Value *D) const {
 
 
 int SlotCalculator::insertValue(const Value *D) {
-  if (D->isConstant() || D->isGlobal()) {
+  if (isa<ConstPoolVal>(D) || isa<GlobalVariable>(D)) {
     const User *U = (const User *)D;
     // This makes sure that if a constant has uses (for example an array
     // of const ints), that they are inserted also.  Same for global variable