From: Chris Lattner Date: Mon, 1 Oct 2001 18:26:53 +0000 (+0000) Subject: Add more support for new style casts X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=cfe26c930ae691ff3012736555846c45087e1a9e;p=oota-llvm.git Add more support for new style casts Convert more code to use them git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@695 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/ConstantsScanner.h b/include/llvm/Analysis/ConstantsScanner.h index 3a496c31302..cbf976573e0 100644 --- a/include/llvm/Analysis/ConstantsScanner.h +++ b/include/llvm/Analysis/ConstantsScanner.h @@ -45,7 +45,7 @@ public: inline pointer operator*() const { assert(isAtConstant() && "Dereferenced an iterator at the end!"); - return InstI->getOperand(OpIdx)->castConstantAsserting(); + return cast(InstI->getOperand(OpIdx)); } inline pointer operator->() const { return operator*(); } diff --git a/include/llvm/Analysis/InstForest.h b/include/llvm/Analysis/InstForest.h index fd9677d961d..eac08f91e58 100644 --- a/include/llvm/Analysis/InstForest.h +++ b/include/llvm/Analysis/InstForest.h @@ -20,8 +20,8 @@ namespace analysis { -template class InstTreeNode; -template class InstForest; +template class InstTreeNode; +template class InstForest; //===----------------------------------------------------------------------===// @@ -74,10 +74,10 @@ public: // Accessors for different node types... inline ConstPoolVal *getConstant() { - return getValue()->castConstantAsserting(); + return cast(getValue()); } inline const ConstPoolVal *getConstant() const { - return getValue()->castConstantAsserting(); + return cast(getValue()); } inline BasicBlock *getBasicBlock() { return cast(getValue()); @@ -230,12 +230,12 @@ InstTreeNode::InstTreeNode(InstForest &IF, Value *V, getTreeData().first.first = V; // Save tree node if (!V->isInstruction()) { - assert((V->isConstant() || V->isBasicBlock() || - V->isMethodArgument() || V->isGlobal()) && + assert((isa(V) || isa(V) || + isa(V) || isa(V)) && "Unrecognized value type for InstForest Partition!"); - if (V->isConstant()) + if (isa(V)) getTreeData().first.second = ConstNode; - else if (V->isBasicBlock()) + else if (isa(V)) getTreeData().first.second = BasicBlockNode; else getTreeData().first.second = TemporaryNode; diff --git a/include/llvm/Assembly/Writer.h b/include/llvm/Assembly/Writer.h index aa207604a22..39b0cb6cfb5 100644 --- a/include/llvm/Assembly/Writer.h +++ b/include/llvm/Assembly/Writer.h @@ -91,7 +91,7 @@ inline ostream &operator<<(ostream &o, const Type *T) { inline ostream &operator<<(ostream &o, const Value *I) { switch (I->getValueType()) { - case Value::TypeVal: return o << I->castTypeAsserting(); + case Value::TypeVal: return o << cast(I); case Value::ConstantVal: WriteToAssembly((const ConstPoolVal*)I,o);break; case Value::MethodArgumentVal: return o << I->getType() << " "<< I->getName(); case Value::InstructionVal:WriteToAssembly((const Instruction *)I, o);break; diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 4bc4f0ddb86..5a51e64339b 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -78,6 +78,15 @@ public: // type NewType and for 'this' to be deleted. // 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) { + return T->isDerivedType(); + } + static inline bool isa(const Value *V) { + return ::isa(V) && isa(cast(V)); + } }; @@ -129,7 +138,7 @@ public: return T->getPrimitiveID() == MethodTyID; } static inline bool isa(const Value *V) { - return ::isa(V) && MethodType::isa(cast(V)); + return ::isa(V) && isa(cast(V)); } }; @@ -170,6 +179,15 @@ public: virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy); 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) { + return T->getPrimitiveID() == ArrayTyID; + } + static inline bool isa(const Value *V) { + return ::isa(V) && isa(cast(V)); + } }; @@ -206,6 +224,15 @@ public: virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy); static StructType *get(const vector &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) { + return T->getPrimitiveID() == StructTyID; + } + static inline bool isa(const Value *V) { + return ::isa(V) && isa(cast(V)); + } }; @@ -240,6 +267,15 @@ public: // concrete type. // 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) { + return T->getPrimitiveID() == PointerTyID; + } + static inline bool isa(const Value *V) { + return ::isa(V) && isa(cast(V)); + } }; @@ -261,6 +297,15 @@ public: static OpaqueType *get() { return new OpaqueType(); // All opaque types are distinct } + + // 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) { + return T->getPrimitiveID() == OpaqueTyID; + } + static inline bool isa(const Value *V) { + return ::isa(V) && isa(cast(V)); + } }; @@ -272,11 +317,11 @@ public: // template void PATypeHandle::addUser() { if (Ty->isAbstract()) - Ty->castDerivedTypeAsserting()->addAbstractTypeUser(User); + cast(Ty)->addAbstractTypeUser(User); } template void PATypeHandle::removeUser() { if (Ty->isAbstract()) - Ty->castDerivedTypeAsserting()->removeAbstractTypeUser(User); + cast(Ty)->removeAbstractTypeUser(User); } #endif diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index 4ee1df9c725..f301844bd72 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -46,10 +46,10 @@ public: // inline bool hasInitializer() const { return !Operands.empty(); } inline const ConstPoolVal *getInitializer() const { - return Operands[0]->castConstantAsserting(); + return (const ConstPoolVal*)Operands[0].get(); } inline ConstPoolVal *getInitializer() { - return Operands[0]->castConstantAsserting(); + return (ConstPoolVal*)Operands[0].get(); } inline void setInitializer(ConstPoolVal *CPV) { Operands[0] = (Value*)CPV; } @@ -59,6 +59,12 @@ public: // leads to undefined behavior. // 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) { + return V->getValueType() == Value::GlobalVal; + } }; #endif diff --git a/include/llvm/SymbolTable.h b/include/llvm/SymbolTable.h index 18ccf136c0c..bae9eb14812 100644 --- a/include/llvm/SymbolTable.h +++ b/include/llvm/SymbolTable.h @@ -19,6 +19,11 @@ #include "llvm/Value.h" #include +#ifndef NDEBUG // Only for assertions +#include "llvm/Type.h" +#include "llvm/ConstPoolVals.h" +#endif + class Value; class Type; @@ -63,7 +68,7 @@ public: // (constant/type)s. // inline void insert(const string &Name, Value *V) { - assert((V->isType() || V->isConstant()) && + assert((isa(V) || isa(V)) && "Can only insert types and constants here!"); insertEntry(Name, V); } diff --git a/include/llvm/Type.h b/include/llvm/Type.h index 2a43153acd0..687b12afb05 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -187,13 +187,6 @@ public: inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; } inline bool isDerivedType() const { return ID >= FirstDerivedTyID; } - inline const DerivedType *castDerivedType() const { - return isDerivedType() ? (const DerivedType*)this : 0; - } - inline const DerivedType *castDerivedTypeAsserting() const { - assert(isDerivedType()); - return (const DerivedType*)this; - } // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool isa(const Type *T) { return true; } diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 271d2d4dfe5..3ef46cac86a 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -98,14 +98,6 @@ public: inline CLASS *cast##NAME() { /* nonconst version */ \ return is##NAME() ? (CLASS*)this : 0; \ } \ - inline const CLASS *cast##NAME##Asserting() const { /*const version */ \ - assert(is##NAME() && "Expected Value Type: " #NAME); \ - return (const CLASS*)this; \ - } \ - inline CLASS *cast##NAME##Asserting() { /* nonconst version */ \ - assert(is##NAME() && "Expected Value Type: " #NAME); \ - return (CLASS*)this; \ - } \ CAST_FN(Constant , ConstPoolVal ) CAST_FN(MethodArgument, MethodArgument) @@ -113,19 +105,8 @@ public: CAST_FN(BasicBlock , BasicBlock ) CAST_FN(Method , Method ) CAST_FN(Global , GlobalVariable) - CAST_FN(Module , Module ) #undef CAST_FN - // Type value is special, because there is no nonconst version of functions! - inline bool isType() const { return VTy == TypeVal; } - inline const Type *castType() const { - return (VTy == TypeVal) ? (const Type*)this : 0; - } - inline const Type *castTypeAsserting() const { - assert(isType() && "Expected Value Type: Type"); - return (const Type*)this; - } - // 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. @@ -256,4 +237,33 @@ X *dyn_cast(Y Val) { return isa(Val) ? cast(Val) : 0; } + +// 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(Value *Val) { + return Val->getValueType() == Value::TypeVal; +} +template <> bool isa(Value *Val) { + return Val->getValueType() == Value::ConstantVal; +} +template <> bool isa(Value *Val) { + return Val->getValueType() == Value::MethodArgumentVal; +} +template <> bool isa(Value *Val) { + return Val->getValueType() == Value::InstructionVal; +} +template <> bool isa(Value *Val) { + return Val->getValueType() == Value::BasicBlockVal; +} +template <> bool isa(Value *Val) { + return Val->getValueType() == Value::MethodVal; +} +template <> bool isa(Value *Val) { + return Val->getValueType() == Value::GlobalVal; +} +template <> bool isa(Value *Val) { + return Val->getValueType() == Value::ModuleVal; +} + #endif diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h index 43cf509a705..6978da54986 100644 --- a/include/llvm/iTerminators.h +++ b/include/llvm/iTerminators.h @@ -154,11 +154,11 @@ public: // successor. WARNING: This does not gracefully accept idx's out of range! inline const ConstPoolVal *getSuccessorValue(unsigned idx) const { assert(idx < getNumSuccessors() && "Successor # out of range!"); - return Operands[idx*2]->castConstantAsserting(); + return cast(Operands[idx*2]); } inline ConstPoolVal *getSuccessorValue(unsigned idx) { assert(idx < getNumSuccessors() && "Successor # out of range!"); - return Operands[idx*2]->castConstantAsserting(); + return cast(Operands[idx*2]); } virtual unsigned getNumSuccessors() const { return Operands.size()/2; } }; diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp index a6f889f698d..8c9d75f2bd2 100644 --- a/lib/Analysis/Expressions.cpp +++ b/lib/Analysis/Expressions.cpp @@ -225,7 +225,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) { case Value::MethodArgumentVal: // nothing known, return variable itself return Expr; case Value::ConstantVal: // Constant value, just return constant - ConstPoolVal *CPV = Expr->castConstantAsserting(); + ConstPoolVal *CPV = cast(Expr); if (CPV->getType()->isIntegral()) { // It's an integral constant! ConstPoolInt *CPI = (ConstPoolInt*)Expr; return ExprType(CPI->equalsInt(0) ? 0 : CPI); diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 7a32813fc17..819f96290f4 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -155,7 +155,7 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) { } D.destroy(); // Free old strdup'd memory... - return N->castTypeAsserting(); + return cast(N); } default: ThrowException("Invalid symbol type reference!"); @@ -267,7 +267,7 @@ static Value *getVal(const Type *Ty, const ValID &D, case ValID::ConstNullVal: if (!Ty->isPointerType()) ThrowException("Cannot create a a non pointer null!"); - CPV = ConstPoolPointer::getNullPointer(Ty->castPointerType()); + CPV = ConstPoolPointer::getNullPointer(cast(Ty)); break; default: assert(0 && "Unhandled case!"); @@ -341,7 +341,7 @@ static void ResolveDefinitions(vector &LateResolvers) { getLineNumFromPlaceHolder(V)); } - assert(!V->isType() && "Types should be in LateResolveTypes!"); + assert(!isa(V) && "Types should be in LateResolveTypes!"); V->replaceAllUsesWith(TheRealValue); delete V; @@ -371,11 +371,8 @@ static void ResolveTypes(vector > &LateResolveTypes) { getLineNumFromPlaceHolder(Ty)); } - // FIXME: When types are not const - DerivedType *DTy = const_cast(Ty->castDerivedTypeAsserting()); - // Refine the opaque type we had to the new type we are getting. - DTy->refineAbstractTypeTo(TheRealType); + cast(Ty)->refineAbstractTypeTo(TheRealType); // No need to delete type, refine does that for us. LateResolveTypes.pop_back(); @@ -399,12 +396,11 @@ static void setValueName(Value *V, char *NameStr) { if (Existing) { // Inserting a name that is already defined??? // There is only one case where this is allowed: when we are refining an // opaque type. In this case, Existing will be an opaque type. - if (const Type *Ty = Existing->castType()) + if (const Type *Ty = cast(Existing)) if (Ty->isOpaqueType()) { // We ARE replacing an opaque type! - // TODO: FIXME when types are not const! - const_cast(Ty->castDerivedTypeAsserting())->refineAbstractTypeTo(V->castTypeAsserting()); + cast(Ty)->refineAbstractTypeTo(cast(V)); return; } @@ -899,7 +895,7 @@ ConstPool : ConstPool OptAssign ConstVal { | ConstPool OptAssign GlobalType ResolvedVal { const Type *Ty = $4->getType(); // Global declarations appear in Constant Pool - ConstPoolVal *Initializer = $4->castConstant(); + ConstPoolVal *Initializer = cast($4); if (Initializer == 0) ThrowException("Global value initializer is not a constant!"); @@ -913,7 +909,7 @@ ConstPool : ConstPool OptAssign ConstVal { | ConstPool OptAssign UNINIT GlobalType Types { const Type *Ty = *$5; // Global declarations appear in Constant Pool - if (Ty->isArrayType() && Ty->castArrayType()->isUnsized()) { + if (isa(Ty) && cast(Ty)->isUnsized()) { ThrowException("Type '" + Ty->getDescription() + "' is not a sized type!"); } @@ -1162,7 +1158,7 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { $$ = $1; - ConstPoolVal *V = getVal($2, $3, true)->castConstantAsserting(); + ConstPoolVal *V = cast(getVal($2, $3, true)); if (V == 0) ThrowException("May only switch on a constant pool value!"); @@ -1170,7 +1166,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { } | IntType ConstValueRef ',' LABEL ValueRef { $$ = new list >(); - ConstPoolVal *V = getVal($1, $2, true)->castConstantAsserting(); + ConstPoolVal *V = cast(getVal($1, $2, true)); if (V == 0) ThrowException("May only switch on a constant pool value!"); diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index ae206daa370..67cfff7b973 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -149,8 +149,7 @@ bool BytecodeParser::parseTypeConstants(const uchar *&Buf, const uchar *EndBuf, // abstract type to use the newty. This also will cause the opaque type // to be deleted... // - // FIXME when types are not const - const_cast(Tab[i+BaseLevel]->castDerivedTypeAsserting())->refineAbstractTypeTo(NewTy); + cast(Tab[i+BaseLevel].get())->refineAbstractTypeTo(NewTy); // This should have replace the old opaque type with the new type in the // value table... @@ -159,7 +158,7 @@ bool BytecodeParser::parseTypeConstants(const uchar *&Buf, const uchar *EndBuf, BCR_TRACE(5, "Resulting types:\n"); for (unsigned i = 0; i < NumEntries; i++) { - BCR_TRACE(5, Tab[i+BaseLevel]->castTypeAsserting() << "\n"); + BCR_TRACE(5, cast(Tab[i+BaseLevel]) << "\n"); } return false; } diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index a2038edf342..b7904bb60f7 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -55,7 +55,7 @@ const Type *BytecodeParser::getType(unsigned ID) { const Value *D = getValue(Type::TypeTy, ID, false); if (D == 0) return failure(0); - return D->castTypeAsserting(); + return cast(D); } bool BytecodeParser::insertValue(Value *Val, vector &ValueTab) { @@ -341,7 +341,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, Value *V = getValue(Ty->castPointerType()->getValueType(), InitSlot, false); if (V == 0) return failure(true); - Initializer = V->castConstantAsserting(); + Initializer = cast(V); } // Create the global variable... diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index cac8f2e953c..d0f37fb723e 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -250,13 +250,13 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore = false) { if (!dontIgnore) // Don't ignore nonignorables! if (D->getType() == Type::VoidTy || // Ignore void type nodes (IgnoreNamedNodes && // Ignore named and constants - (D->hasName() || D->isConstant()) && !D->isType())) { + (D->hasName() || isa(D)) && !isa(D))) { SC_DEBUG("ignored value " << D << endl); return -1; // We do need types unconditionally though } // If it's a type, make sure that all subtypes of the type are included... - if (const Type *TheTy = D->castType()) { + if (const Type *TheTy = dyn_cast(D)) { SC_DEBUG(" Inserted type: " << TheTy->getDescription() << endl); // Loop over any contained types in the definition... in reverse depth first @@ -289,7 +289,7 @@ int SlotCalculator::doInsertVal(const Value *D) { // Used for debugging DefSlot=-1 assertion... //if (Typ == Type::TypeTy) - // cerr << "Inserting type '" << D->castTypeAsserting()->getDescription() << "'!\n"; + // cerr << "Inserting type '" << cast(D)->getDescription() << "'!\n"; if (Typ->isDerivedType()) { int DefSlot = getValSlot(Typ); diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 04a0ca4624f..94cbcec328d 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -84,7 +84,8 @@ void BytecodeWriter::outputConstants(bool isMethod) { unsigned NC = ValNo; // Number of constants for (; NC < Plane.size() && - (Plane[NC]->isConstant() || Plane[NC]->isType()); NC++) /*empty*/; + (isa(Plane[NC]) || + isa(Plane[NC])); NC++) /*empty*/; NC -= ValNo; // Convert from index into count if (NC == 0) continue; // Skip empty type planes... diff --git a/lib/Target/SparcV9/SparcV9InstrSelection.cpp b/lib/Target/SparcV9/SparcV9InstrSelection.cpp index e7cdbc03896..572e1b175b3 100644 --- a/lib/Target/SparcV9/SparcV9InstrSelection.cpp +++ b/lib/Target/SparcV9/SparcV9InstrSelection.cpp @@ -1525,8 +1525,8 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, case 208: // stmt: BrCond(boolconst) { // boolconst => boolean is a constant; use BA to first or second label - ConstPoolVal* constVal = - subtreeRoot->leftChild()->getValue()->castConstantAsserting(); + ConstPoolVal* constVal = + cast(subtreeRoot->leftChild()->getValue()); unsigned dest = ((ConstPoolBool*) constVal)->getValue()? 0 : 1; mvec[0] = new MachineInstr(BA); diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index e1415c73e87..24a5e852a21 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -61,7 +61,7 @@ Annotation *TargetData::TypeAnFactory(AnnotationID AID, const Annotable *T, void *D) { const TargetData &TD = *(const TargetData*)D; assert(AID == TD.AID && "Target data annotation ID mismatch!"); - const Type *Ty = ((const Value *)T)->castTypeAsserting(); + const Type *Ty = cast((const Value *)T); assert(Ty->isStructType() && "Can only create StructLayout annotation on structs!"); return new StructLayout((const StructType *)Ty, TD); diff --git a/lib/Transforms/Scalar/SymbolStripping.cpp b/lib/Transforms/Scalar/SymbolStripping.cpp index 2f40f585d0c..6104b62e431 100644 --- a/lib/Transforms/Scalar/SymbolStripping.cpp +++ b/lib/Transforms/Scalar/SymbolStripping.cpp @@ -29,7 +29,7 @@ static bool StripSymbolTable(SymbolTable *SymTab) { SymbolTable::type_iterator B; while ((B = Plane.begin()) != Plane.end()) { // Found nonempty type plane! Value *V = B->second; - if (V->isConstant() || V->isType()) + if (isa(V) || isa(V)) SymTab->type_remove(B); else V->setName("", SymTab); // Set name to "", removing from symbol table! diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index e40006c2330..3c67c2ca088 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/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 = V->castConstant()) { + if (const ConstPoolVal *CPV = cast(V)) { processConstant(CPV); - } else if (const Type *Ty = V->castType()) { + } else if (const Type *Ty = cast(V)) { Out << "\t%" << I->first << " = type " << Ty->getDescription() << endl; } } diff --git a/lib/VMCore/ConstPoolVals.cpp b/lib/VMCore/ConstPoolVals.cpp index 152209dcc7d..374c583ab9b 100644 --- a/lib/VMCore/ConstPoolVals.cpp +++ b/lib/VMCore/ConstPoolVals.cpp @@ -127,10 +127,10 @@ string ConstPoolArray::getStrValue() const { string Result = "["; if (Operands.size()) { Result += " " + Operands[0]->getType()->getDescription() + - " " + Operands[0]->castConstantAsserting()->getStrValue(); + " " + cast(Operands[0])->getStrValue(); for (unsigned i = 1; i < Operands.size(); i++) Result += ", " + Operands[i]->getType()->getDescription() + - " " + Operands[i]->castConstantAsserting()->getStrValue(); + " " + cast(Operands[i])->getStrValue(); } return Result + " ]"; @@ -140,10 +140,10 @@ string ConstPoolStruct::getStrValue() const { string Result = "{"; if (Operands.size()) { Result += " " + Operands[0]->getType()->getDescription() + - " " + Operands[0]->castConstantAsserting()->getStrValue(); + " " + cast(Operands[0])->getStrValue(); for (unsigned i = 1; i < Operands.size(); i++) Result += ", " + Operands[i]->getType()->getDescription() + - " " + Operands[i]->castConstantAsserting()->getStrValue(); + " " + cast(Operands[i])->getStrValue(); } return Result + " }"; diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 3974bf3e886..c899d7d1f3d 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -238,7 +238,7 @@ struct DirectRules // Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) { assert(AID == ConstRules::AID && "Bad annotation for factory!"); - const Type *Ty = ((const Value*)TyA)->castTypeAsserting(); + const Type *Ty = cast((const Value*)TyA); switch (Ty->getPrimitiveID()) { case Type::BoolTyID: return new BoolRules(); diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index cac8f2e953c..d0f37fb723e 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -250,13 +250,13 @@ int SlotCalculator::insertVal(const Value *D, bool dontIgnore = false) { if (!dontIgnore) // Don't ignore nonignorables! if (D->getType() == Type::VoidTy || // Ignore void type nodes (IgnoreNamedNodes && // Ignore named and constants - (D->hasName() || D->isConstant()) && !D->isType())) { + (D->hasName() || isa(D)) && !isa(D))) { SC_DEBUG("ignored value " << D << endl); return -1; // We do need types unconditionally though } // If it's a type, make sure that all subtypes of the type are included... - if (const Type *TheTy = D->castType()) { + if (const Type *TheTy = dyn_cast(D)) { SC_DEBUG(" Inserted type: " << TheTy->getDescription() << endl); // Loop over any contained types in the definition... in reverse depth first @@ -289,7 +289,7 @@ int SlotCalculator::doInsertVal(const Value *D) { // Used for debugging DefSlot=-1 assertion... //if (Typ == Type::TypeTy) - // cerr << "Inserting type '" << D->castTypeAsserting()->getDescription() << "'!\n"; + // cerr << "Inserting type '" << cast(D)->getDescription() << "'!\n"; if (Typ->isDerivedType()) { int DefSlot = getValSlot(Typ); diff --git a/lib/VMCore/SymbolTable.cpp b/lib/VMCore/SymbolTable.cpp index 491d7adc90f..12bf0c7f1ba 100644 --- a/lib/VMCore/SymbolTable.cpp +++ b/lib/VMCore/SymbolTable.cpp @@ -8,10 +8,6 @@ #include "llvm/InstrTypes.h" #include "llvm/Support/StringExtras.h" #include "llvm/DerivedTypes.h" -#ifndef NDEBUG -#include "llvm/BasicBlock.h" // Required for assertions to work. -#include "llvm/Type.h" -#endif SymbolTable::~SymbolTable() { // Drop all abstract type references in the type plane... @@ -19,16 +15,16 @@ SymbolTable::~SymbolTable() { if (TyPlane != end()) { VarMap &TyP = TyPlane->second; for (VarMap::iterator I = TyP.begin(), E = TyP.end(); I != E; ++I) { - const Type *Ty = I->second->castTypeAsserting(); + const Type *Ty = cast(I->second); if (Ty->isAbstract()) // If abstract, drop the reference... - Ty->castDerivedTypeAsserting()->removeAbstractTypeUser(this); + cast(Ty)->removeAbstractTypeUser(this); } } #ifndef NDEBUG // Only do this in -g mode... bool LeftoverValues = true; for (iterator i = begin(); i != end(); ++i) { for (type_iterator I = i->second.begin(); I != i->second.end(); ++I) - if (!I->second->isConstant() && !I->second->isType()) { + if (!isa(I->second) && !isa(I->second)) { cerr << "Value still in symbol table! Type = '" << i->first->getDescription() << "' Name = '" << I->first << "'\n"; LeftoverValues = false; @@ -112,9 +108,9 @@ Value *SymbolTable::type_remove(const type_iterator &It) { // If we are removing an abstract type, remove the symbol table from it's use // list... if (Ty == Type::TypeTy) { - const Type *T = Result->castTypeAsserting(); + const Type *T = cast(Result); if (T->isAbstract()) - T->castDerivedTypeAsserting()->removeAbstractTypeUser(this); + cast(T)->removeAbstractTypeUser(this); } return Result; @@ -149,9 +145,9 @@ void SymbolTable::insertEntry(const string &Name, Value *V) { // If we are adding an abstract type, add the symbol table to it's use list. if (VTy == Type::TypeTy) { - const Type *T = V->castTypeAsserting(); + const Type *T = cast(V); if (T->isAbstract()) - T->castDerivedTypeAsserting()->addAbstractTypeUser(this); + cast(T)->addAbstractTypeUser(this); } } @@ -174,6 +170,6 @@ void SymbolTable::refineAbstractType(const DerivedType *OldType, OldType->removeAbstractTypeUser(this); I->second = (Value*)NewType; // TODO FIXME when types aren't const if (NewType->isAbstract()) - NewType->castDerivedTypeAsserting()->addAbstractTypeUser(this); + cast(NewType)->addAbstractTypeUser(this); } }