diff options
| author | Chris Lattner <sabre@nondot.org> | 2001-10-01 20:11:19 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2001-10-01 20:11:19 +0000 | 
| commit | 38569343868ee3dad90dcdddfb9fee1ca0bcf25f (patch) | |
| tree | 1b9bc0f2b6911aed0815f3a00945714c26a8a5ce /llvm | |
| parent | 8f191129239552b876f2c6717fae9619a7701a03 (diff) | |
| download | bcm5719-llvm-38569343868ee3dad90dcdddfb9fee1ca0bcf25f.tar.gz bcm5719-llvm-38569343868ee3dad90dcdddfb9fee1ca0bcf25f.zip  | |
Convert more code to use new style casts
Eliminate old style casts from value.h
llvm-svn: 696
Diffstat (limited to 'llvm')
26 files changed, 140 insertions, 123 deletions
diff --git a/llvm/include/llvm/Analysis/ConstantsScanner.h b/llvm/include/llvm/Analysis/ConstantsScanner.h index cbf976573e0..4c86834d214 100644 --- a/llvm/include/llvm/Analysis/ConstantsScanner.h +++ b/llvm/include/llvm/Analysis/ConstantsScanner.h @@ -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: diff --git a/llvm/include/llvm/Analysis/InstForest.h b/llvm/include/llvm/Analysis/InstForest.h index eac08f91e58..967ed45ec96 100644 --- a/llvm/include/llvm/Analysis/InstForest.h +++ b/llvm/include/llvm/Analysis/InstForest.h @@ -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!"); diff --git a/llvm/include/llvm/ConstPoolVals.h b/llvm/include/llvm/ConstPoolVals.h index 1bd2dce8117..342070c9caf 100644 --- a/llvm/include/llvm/ConstPoolVals.h +++ b/llvm/include/llvm/ConstPoolVals.h @@ -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]  // diff --git a/llvm/include/llvm/Value.h b/llvm/include/llvm/Value.h index 3ef46cac86a..1acf2e299dd 100644 --- a/llvm/include/llvm/Value.h +++ b/llvm/include/llvm/Value.h @@ -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;  } diff --git a/llvm/lib/Analysis/Expressions.cpp b/llvm/lib/Analysis/Expressions.cpp index 8c9d75f2bd2..cb83d41236e 100644 --- a/llvm/lib/Analysis/Expressions.cpp +++ b/llvm/lib/Analysis/Expressions.cpp @@ -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;  } diff --git a/llvm/lib/AsmParser/ParserInternals.h b/llvm/lib/AsmParser/ParserInternals.h index 88986c288ab..bedb65f4a86 100644 --- a/llvm/lib/AsmParser/ParserInternals.h +++ b/llvm/lib/AsmParser/ParserInternals.h @@ -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; diff --git a/llvm/lib/Bytecode/Reader/ConstantReader.cpp b/llvm/lib/Bytecode/Reader/ConstantReader.cpp index 67cfff7b973..aaecedddfa7 100644 --- a/llvm/lib/Bytecode/Reader/ConstantReader.cpp +++ b/llvm/lib/Bytecode/Reader/ConstantReader.cpp @@ -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); diff --git a/llvm/lib/Bytecode/Reader/InstructionReader.cpp b/llvm/lib/Bytecode/Reader/InstructionReader.cpp index 8c3e08ff94e..300c40999eb 100644 --- a/llvm/lib/Bytecode/Reader/InstructionReader.cpp +++ b/llvm/lib/Bytecode/Reader/InstructionReader.cpp @@ -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; diff --git a/llvm/lib/Bytecode/Reader/Reader.cpp b/llvm/lib/Bytecode/Reader/Reader.cpp index b7904bb60f7..0e4883034e6 100644 --- a/llvm/lib/Bytecode/Reader/Reader.cpp +++ b/llvm/lib/Bytecode/Reader/Reader.cpp @@ -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);       } diff --git a/llvm/lib/Bytecode/Reader/ReaderInternals.h b/llvm/lib/Bytecode/Reader/ReaderInternals.h index ed4f1a4bba2..cf5a43ef3bb 100644 --- a/llvm/lib/Bytecode/Reader/ReaderInternals.h +++ b/llvm/lib/Bytecode/Reader/ReaderInternals.h @@ -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)) {    }  }; diff --git a/llvm/lib/Bytecode/Writer/Writer.cpp b/llvm/lib/Bytecode/Writer/Writer.cpp index 94cbcec328d..5df2fdabde5 100644 --- a/llvm/lib/Bytecode/Writer/Writer.cpp +++ b/llvm/lib/Bytecode/Writer/Writer.cpp @@ -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. diff --git a/llvm/lib/CodeGen/InstrSched/SchedGraph.cpp b/llvm/lib/CodeGen/InstrSched/SchedGraph.cpp index 40601300f76..852c4f2686a 100644 --- a/llvm/lib/CodeGen/InstrSched/SchedGraph.cpp +++ b/llvm/lib/CodeGen/InstrSched/SchedGraph.cpp @@ -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; diff --git a/llvm/lib/CodeGen/InstrSelection/InstrForest.cpp b/llvm/lib/CodeGen/InstrSelection/InstrForest.cpp index 9f4df08d384..f5a524707b9 100644 --- a/llvm/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/llvm/lib/CodeGen/InstrSelection/InstrForest.cpp @@ -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); diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index 1e3300763de..64076286f4b 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -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) diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp index 3ecc3ec0eab..d88d91ff1f9 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -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 diff --git a/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp b/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp index eb5725feddc..e9fc9db3436 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/UserInput.cpp @@ -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;      } diff --git a/llvm/lib/Target/Sparc/SparcInstrSelection.cpp b/llvm/lib/Target/Sparc/SparcInstrSelection.cpp index 572e1b175b3..b1b5e01aff5 100644 --- a/llvm/lib/Target/Sparc/SparcInstrSelection.cpp +++ b/llvm/lib/Target/Sparc/SparcInstrSelection.cpp @@ -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; diff --git a/llvm/lib/Transforms/IPO/InlineSimple.cpp b/llvm/lib/Transforms/IPO/InlineSimple.cpp index 27ef66e42e3..8bc0a77cd1f 100644 --- a/llvm/lib/Transforms/IPO/InlineSimple.cpp +++ b/llvm/lib/Transforms/IPO/InlineSimple.cpp @@ -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) { diff --git a/llvm/lib/Transforms/Scalar/ConstantProp.cpp b/llvm/lib/Transforms/Scalar/ConstantProp.cpp index 8b879162426..d43f693dd17 100644 --- a/llvm/lib/Transforms/Scalar/ConstantProp.cpp +++ b/llvm/lib/Transforms/Scalar/ConstantProp.cpp @@ -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); diff --git a/llvm/lib/Transforms/Scalar/InductionVars.cpp b/llvm/lib/Transforms/Scalar/InductionVars.cpp index 6815ccb9a40..f2dcb451535 100644 --- a/llvm/lib/Transforms/Scalar/InductionVars.cpp +++ b/llvm/lib/Transforms/Scalar/InductionVars.cpp @@ -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; diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 78b6c3df7b4..91e002d8be9 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -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... diff --git a/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp index 3c67c2ca088..b9a1c6dbeed 100644 --- a/llvm/lib/VMCore/AsmWriter.cpp +++ b/llvm/lib/VMCore/AsmWriter.cpp @@ -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;        }      } diff --git a/llvm/lib/VMCore/BasicBlock.cpp b/llvm/lib/VMCore/BasicBlock.cpp index 7d97c85f7de..81c1f11616e 100644 --- a/llvm/lib/VMCore/BasicBlock.cpp +++ b/llvm/lib/VMCore/BasicBlock.cpp @@ -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; diff --git a/llvm/lib/VMCore/ConstPoolVals.cpp b/llvm/lib/VMCore/ConstPoolVals.cpp index 374c583ab9b..bf538bd2516 100644 --- a/llvm/lib/VMCore/ConstPoolVals.cpp +++ b/llvm/lib/VMCore/ConstPoolVals.cpp @@ -51,7 +51,9 @@ ConstPoolVal *ConstPoolVal::getNullConstant(const Type *Ty) {    }  } - +bool ConstPoolInt::isa(const ConstPoolVal *CPV) { +  return CPV->getType()->isIntegral(); +}  //===----------------------------------------------------------------------===//  //                            ConstPoolXXX Classes diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp index 5d1132f0a7d..9eb8277a272 100644 --- a/llvm/lib/VMCore/Function.cpp +++ b/llvm/lib/VMCore/Function.cpp @@ -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;  } diff --git a/llvm/lib/VMCore/SlotCalculator.cpp b/llvm/lib/VMCore/SlotCalculator.cpp index d0f37fb723e..38980e5e63a 100644 --- a/llvm/lib/VMCore/SlotCalculator.cpp +++ b/llvm/lib/VMCore/SlotCalculator.cpp @@ -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  | 

