diff options
author | Chris Lattner <sabre@nondot.org> | 2001-10-02 03:41:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-10-02 03:41:24 +0000 |
commit | b00c582b6d40e6b9ff2d1ed4f5eaf7930e792ace (patch) | |
tree | 44b5f879c16e7ecb2e9334ad120e3454270e1bb3 | |
parent | 1d87bcf4909b06dcd86320722653341f08b8b396 (diff) |
Commit more code over to new cast style
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@697 91177308-0d34-0410-b5e6-96231b3b80d8
42 files changed, 349 insertions, 233 deletions
diff --git a/docs/ChrisNotes.txt b/docs/ChrisNotes.txt index 4c1f9c9e62..652b7694eb 100644 --- a/docs/ChrisNotes.txt +++ b/docs/ChrisNotes.txt @@ -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 diff --git a/docs/CodingStandards.html b/docs/CodingStandards.html index 489e47694c..62288cc9e8 100644 --- a/docs/CodingStandards.html +++ b/docs/CodingStandards.html @@ -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 < 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->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 < 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<PHINode>(Succ->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> diff --git a/include/llvm/Assembly/Writer.h b/include/llvm/Assembly/Writer.h index 39b0cb6cfb..020989e5d9 100644 --- a/include/llvm/Assembly/Writer.h +++ b/include/llvm/Assembly/Writer.h @@ -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; diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 1d1623bf97..cf29cbd00e 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -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; } diff --git a/include/llvm/CodeGen/InstrForest.h b/include/llvm/CodeGen/InstrForest.h index 6fe622d9fc..113e35e32b 100644 --- a/include/llvm/CodeGen/InstrForest.h +++ b/include/llvm/CodeGen/InstrForest.h @@ -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; diff --git a/include/llvm/ConstPoolVals.h b/include/llvm/ConstPoolVals.h index 342070c9ca..4edfa807a1 100644 --- a/include/llvm/ConstPoolVals.h +++ b/include/llvm/ConstPoolVals.h @@ -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)); } }; diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 5a51e64339..750b284b55 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -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)); } }; diff --git a/include/llvm/Function.h b/include/llvm/Function.h index f6c8aa214c..227ab53cd0 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -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; } diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index f301844bd7..3ee7f6d45a 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -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; } }; diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h index 75c4943e44..db85a397c8 100644 --- a/include/llvm/InstrTypes.h +++ b/include/llvm/InstrTypes.h @@ -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 diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 93b68a2c62..71bb8e25a1 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -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; } diff --git a/include/llvm/Module.h b/include/llvm/Module.h index a9f920edcb..823d4d82f0 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -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; } diff --git a/include/llvm/Type.h b/include/llvm/Type.h index 687b12afb0..cc682669ce 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -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: diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 1acf2e299d..5716d29c66 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -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 diff --git a/include/llvm/iMemory.h b/include/llvm/iMemory.h index 5667da6c8f..147ff18e94 100644 --- a/include/llvm/iMemory.h +++ b/include/llvm/iMemory.h @@ -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: |