From 9636a91649f168f41b477cba705287665e054f79 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 1 Oct 2001 16:18:37 +0000 Subject: [PATCH] Add support for new style casts git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@694 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/InstForest.h | 22 ++++++------- include/llvm/BasicBlock.h | 8 ++++- include/llvm/CodeGen/MachineInstr.h | 2 +- include/llvm/ConstPoolVals.h | 6 ++++ include/llvm/DerivedTypes.h | 10 ++++++ include/llvm/Function.h | 5 +++ include/llvm/Module.h | 5 +++ include/llvm/Value.h | 25 ++++++++++----- include/llvm/iOther.h | 14 +++++--- include/llvm/iTerminators.h | 12 +++---- lib/Analysis/Expressions.cpp | 2 +- lib/AsmParser/llvmAsmParser.y | 32 +++++++++++-------- lib/Bytecode/Writer/InstructionWriter.cpp | 2 +- lib/Bytecode/Writer/Writer.cpp | 2 +- lib/CodeGen/InstrSched/SchedGraph.cpp | 2 +- lib/ExecutionEngine/Interpreter/Execution.cpp | 2 +- lib/ExecutionEngine/Interpreter/UserInput.cpp | 2 +- lib/Target/SparcV9/InstrSched/SchedGraph.cpp | 2 +- lib/Target/SparcV9/SparcV9AsmPrinter.cpp | 4 +-- lib/Transforms/Scalar/ADCE.cpp | 2 +- lib/Transforms/Scalar/ConstantProp.cpp | 4 +-- lib/Transforms/Scalar/InductionVars.cpp | 2 +- lib/Transforms/Scalar/SCCP.cpp | 4 +-- lib/VMCore/AsmWriter.cpp | 14 ++++---- 24 files changed, 119 insertions(+), 66 deletions(-) diff --git a/include/llvm/Analysis/InstForest.h b/include/llvm/Analysis/InstForest.h index 12fcd3026d8..fd9677d961d 100644 --- a/include/llvm/Analysis/InstForest.h +++ b/include/llvm/Analysis/InstForest.h @@ -80,26 +80,26 @@ public: return getValue()->castConstantAsserting(); } inline BasicBlock *getBasicBlock() { - return getValue()->castBasicBlockAsserting(); + return cast(getValue()); } inline const BasicBlock *getBasicBlock() const { - return getValue()->castBasicBlockAsserting(); + return cast(getValue()); } inline Instruction *getInstruction() { assert(isInstruction() && "getInstruction() on non instruction node!"); - return getValue()->castInstructionAsserting(); + return cast(getValue()); } inline const Instruction *getInstruction() const { assert(isInstruction() && "getInstruction() on non instruction node!"); - return getValue()->castInstructionAsserting(); + return cast(getValue()); } inline Instruction *getTemporary() { assert(isTemporary() && "getTemporary() on non temporary node!"); - return getValue()->castInstructionAsserting(); + return cast(getValue()); } inline const Instruction *getTemporary() const { assert(isTemporary() && "getTemporary() on non temporary node!"); - return getValue()->castInstructionAsserting(); + return cast(getValue()); } public: @@ -216,7 +216,7 @@ inline ostream &operator<<(ostream &o, const InstForest &IF) { template bool InstTreeNode::CanMergeInstIntoTree(Instruction *I) { if (I->use_size() > 1) return false; - return I->getParent() == getValue()->castInstructionAsserting()->getParent(); + return I->getParent() == cast(getValue())->getParent(); } @@ -244,7 +244,7 @@ InstTreeNode::InstTreeNode(InstForest &IF, Value *V, } // Must be an instruction then... see if we can include it in this tree! - Instruction *I = V->castInstructionAsserting(); + Instruction *I = cast(V); if (Parent && !Parent->CanMergeInstIntoTree(I)) { // Not root node of tree, but mult uses? getTreeData().first.second = TemporaryNode; // Must be a temporary! @@ -264,10 +264,10 @@ InstTreeNode::InstTreeNode(InstForest &IF, Value *V, // for (Instruction::op_iterator OI = I->op_begin(); OI != I->op_end(); ++OI) { Value *Operand = *OI; - InstTreeNode *IN = IF.getInstNode(Operand->castInstruction()); - if (IN && CanMergeInstIntoTree(Operand->castInstructionAsserting())) { + InstTreeNode *IN = IF.getInstNode(dyn_cast(Operand)); + if (IN && CanMergeInstIntoTree(cast(Operand))) { Children.push_back(IN); - IF.removeInstFromRootList(Operand->castInstructionAsserting()); + IF.removeInstFromRootList(cast(Operand)); } else { // No node for this child yet... create one now! Children.push_back(new InstTreeNode(IF, *OI, this)); diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 08516c8ca83..1d1623bf978 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -109,6 +109,12 @@ public: const InstListType &getInstList() const { return InstList; } 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) { + return V->getValueType() == Value::BasicBlockVal; + } + // hasConstantPoolReferences() - This predicate is true if there is a // reference to this basic block in the constant pool for this method. For // example, if a block is reached through a switch table, that table resides @@ -163,7 +169,7 @@ public: // TODO: This is bad // Loop to ignore constant pool references while (It != BB->use_end() && - ((!isa(*It)) || + (((*It)->getValueType() != Value::InstructionVal) || !(((Instruction*)(*It))->isTerminator()))) ++It; } diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index c9c5c51ed19..21976a099b5 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -402,7 +402,7 @@ public: // and inlining it avoids a serious circurality in link order. inline void dropAllReferences() { for (unsigned i=0, N=tempVec.size(); i < N; i++) - if (Instruction *I = tempVec[i]->castInstruction()) + if (Instruction *I = dyn_cast(tempVec[i])) I->dropAllReferences(); } }; diff --git a/include/llvm/ConstPoolVals.h b/include/llvm/ConstPoolVals.h index 7ebe3f3ce28..1bd2dce8117 100644 --- a/include/llvm/ConstPoolVals.h +++ b/include/llvm/ConstPoolVals.h @@ -32,6 +32,12 @@ public: // Static constructor to get a '0' constant of arbitrary type... 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) { + return V->getValueType() == Value::ConstantVal; + } }; diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 3f93459b232..4bc4f0ddb86 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -121,6 +121,16 @@ public: virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy); static MethodType *get(const Type *Result, const vector &Params); + + + // 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) { + return T->getPrimitiveID() == MethodTyID; + } + static inline bool isa(const Value *V) { + return ::isa(V) && MethodType::isa(cast(V)); + } }; diff --git a/include/llvm/Function.h b/include/llvm/Function.h index a7075af0cc3..f6c8aa214c0 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -92,6 +92,11 @@ public: inline BasicBlock *back() { return BasicBlocks.back(); } + // 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) { + return V->getValueType() == Value::MethodVal; + } // dropAllReferences() - This function causes all the subinstructions to "let // go" of all references that they are maintaining. This allows one to diff --git a/include/llvm/Module.h b/include/llvm/Module.h index bf710d1223d..a9f920edcb0 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -93,6 +93,11 @@ public: inline const Method *back() const { return MethodList.back(); } 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) { + return V->getValueType() == Value::ModuleVal; + } // dropAllReferences() - This function causes all the subinstructions to "let // go" of all references that they are maintaining. This allows one to diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 14794dc4c92..271d2d4dfe5 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -77,9 +77,7 @@ public: // Methods for determining the subtype of this Value. The getValueType() // method returns the type of the value directly. The cast*() methods are // equivalent to using dynamic_cast<>... if the cast is successful, this is - // returned, otherwise you get a null pointer, allowing expressions like: - // - // if (Instruction *I = Val->castInstruction()) { ... } + // returned, otherwise you get a null pointer. // // This section also defines a family of isType, isConstant, // isMethodArgument, etc functions... @@ -197,6 +195,9 @@ public: inline ValueSubclass *operator->() { return Val; } inline const ValueSubclass *operator->() const { return Val; } + inline ValueSubclass *get() { return Val; } + inline const ValueSubclass *get() const { return Val; } + inline UseTy &operator=(const UseTy &user) { if (Val) Val->killUse(U); Val = user.Val; @@ -207,6 +208,13 @@ public: typedef UseTy Use; // Provide Use as a common UseTy type +// real_type - Provide a macro to get the real type of a value that might be +// a use. This provides a typedef 'Type' that is the argument type for all +// non UseTy types, and is the contained pointer type of the use if it is a +// UseTy. +// +template class real_type { typedef X Type; }; +template class real_type > { typedef X *Type; }; //===----------------------------------------------------------------------===// // Type Checking Templates @@ -218,7 +226,7 @@ typedef UseTy Use; // Provide Use as a common UseTy type // if (isa(myVal)) { ... } // template -bool isa(Y *Val) { return X::isa(Val); } +bool isa(Y Val) { return X::isa(Val); } // cast - Return the argument parameter cast to the specified type. This @@ -229,9 +237,9 @@ bool isa(Y *Val) { return X::isa(Val); } // cast(myVal)->getParent() // template -X *cast(Y *Val) { +X *cast(Y Val) { assert(isa(Val) && "Invalid cast argument type!"); - return (X*)Val; + return (X*)(real_type::Type)Val; } @@ -242,9 +250,10 @@ X *cast(Y *Val) { // // if (const Instruction *I = dyn_cast(myVal)) { ... } // + template -X *dyn_cast(Y *Val) { - return isa(Val) ? (X*)Val : 0; +X *dyn_cast(Y Val) { + return isa(Val) ? cast(Val) : 0; } #endif diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h index e723d4e9751..1e4733d79ac 100644 --- a/include/llvm/iOther.h +++ b/include/llvm/iOther.h @@ -43,10 +43,10 @@ public: // getIncomingBlock - Return incoming basic block #x inline const BasicBlock *getIncomingBlock(unsigned i) const { - return Operands[i*2+1]->castBasicBlockAsserting(); + return cast(Operands[i*2+1]); } inline BasicBlock *getIncomingBlock(unsigned i) { - return Operands[i*2+1]->castBasicBlockAsserting(); + return cast(Operands[i*2+1]); } // addIncoming - Add an incoming value to the end of the PHI list @@ -103,6 +103,12 @@ public: inline const Method *getParent() const { return Parent; } inline Method *getParent() { return Parent; } + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool isa(const MethodArgument *) { return true; } + static inline bool isa(const Value *V) { + return V->getValueType() == MethodArgumentVal; + } }; @@ -122,10 +128,10 @@ public: const Method *getCalledMethod() const { - return Operands[0]->castMethodAsserting(); + return cast(Operands[0]); } Method *getCalledMethod() { - return Operands[0]->castMethodAsserting(); + return cast(Operands[0]); } }; diff --git a/include/llvm/iTerminators.h b/include/llvm/iTerminators.h index d43c7e5582b..43cf509a705 100644 --- a/include/llvm/iTerminators.h +++ b/include/llvm/iTerminators.h @@ -96,9 +96,9 @@ public: // terminator instruction. // virtual const BasicBlock *getSuccessor(unsigned i) const { - return (i == 0) ? Operands[0]->castBasicBlockAsserting() : + return (i == 0) ? cast(Operands[0]) : ((i == 1 && Operands.size() > 1) - ? Operands[1]->castBasicBlockAsserting() : 0); + ? cast(Operands[1]) : 0); } inline BasicBlock *getSuccessor(unsigned idx) { return (BasicBlock*)((const BranchInst *)this)->getSuccessor(idx); @@ -127,10 +127,10 @@ public: inline const Value *getCondition() const { return Operands[0]; } inline Value *getCondition() { return Operands[0]; } inline const BasicBlock *getDefaultDest() const { - return Operands[1]->castBasicBlockAsserting(); + return cast(Operands[1]); } inline BasicBlock *getDefaultDest() { - return Operands[1]->castBasicBlockAsserting(); + return cast(Operands[1]); } void dest_push_back(ConstPoolVal *OnVal, BasicBlock *Dest); @@ -143,11 +143,11 @@ public: // virtual const BasicBlock *getSuccessor(unsigned idx) const { if (idx >= Operands.size()/2) return 0; - return Operands[idx*2+1]->castBasicBlockAsserting(); + return cast(Operands[idx*2+1]); } inline BasicBlock *getSuccessor(unsigned idx) { if (idx >= Operands.size()/2) return 0; - return Operands[idx*2+1]->castBasicBlockAsserting(); + return cast(Operands[idx*2+1]); } // getSuccessorValue - Return the value associated with the specified diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp index 2235cdaa37b..a6f889f698d 100644 --- a/lib/Analysis/Expressions.cpp +++ b/lib/Analysis/Expressions.cpp @@ -233,7 +233,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) { return Expr; } - Instruction *I = Expr->castInstructionAsserting(); + Instruction *I = cast(Expr); const Type *Ty = I->getType(); switch (I->getOpcode()) { // Handle each instruction type seperately diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index a02b7d82955..7a32813fc17 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -408,7 +408,13 @@ static void setValueName(Value *V, char *NameStr) { return; } - // Otherwise, we are a simple redefinition of a value, baaad + // Otherwise, we are a simple redefinition of a value, check to see if it + // is defined the same as the old one... + if (const Type *Ty = dyn_cast(Existing)) { + if (Ty == cast(V)) return; // Yes, it's equal. + } else { + + } ThrowException("Redefinition of value name '" + Name + "' in the '" + V->getType()->getDescription() + "' type plane!"); } @@ -996,7 +1002,7 @@ MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' { Method *M = 0; if (SymbolTable *ST = CurModule.CurrentModule->getSymbolTable()) { if (Value *V = ST->lookup(MT, $2)) { // Method already in symtab? - M = V->castMethodAsserting(); + M = cast(V); // Yes it is. If this is the case, either we need to be a forward decl, // or it needs to be. @@ -1136,16 +1142,16 @@ BBTerminatorInst : RET ResolvedVal { // Return with a result... $$ = new ReturnInst(); } | BR LABEL ValueRef { // Unconditional Branch... - $$ = new BranchInst(getVal(Type::LabelTy, $3)->castBasicBlockAsserting()); + $$ = new BranchInst(cast(getVal(Type::LabelTy, $3))); } // Conditional Branch... | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef { - $$ = new BranchInst(getVal(Type::LabelTy, $6)->castBasicBlockAsserting(), - getVal(Type::LabelTy, $9)->castBasicBlockAsserting(), + $$ = new BranchInst(cast(getVal(Type::LabelTy, $6)), + cast(getVal(Type::LabelTy, $9)), getVal(Type::BoolTy, $3)); } | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { SwitchInst *S = new SwitchInst(getVal($2, $3), - getVal(Type::LabelTy, $6)->castBasicBlockAsserting()); + cast(getVal(Type::LabelTy, $6))); $$ = S; list >::iterator I = $8->begin(), @@ -1160,7 +1166,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { if (V == 0) ThrowException("May only switch on a constant pool value!"); - $$->push_back(make_pair(V, getVal($5, $6)->castBasicBlockAsserting())); + $$->push_back(make_pair(V, cast(getVal($5, $6)))); } | IntType ConstValueRef ',' LABEL ValueRef { $$ = new list >(); @@ -1169,7 +1175,7 @@ JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { if (V == 0) ThrowException("May only switch on a constant pool value!"); - $$->push_back(make_pair(V, getVal($4, $5)->castBasicBlockAsserting())); + $$->push_back(make_pair(V, cast(getVal($4, $5)))); } Inst : OptAssign InstVal { @@ -1182,13 +1188,13 @@ Inst : OptAssign InstVal { PHIList : Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes $$ = new list >(); $$->push_back(make_pair(getVal(*$1, $3), - getVal(Type::LabelTy, $5)->castBasicBlockAsserting())); + cast(getVal(Type::LabelTy, $5)))); delete $1; } | PHIList ',' '[' ValueRef ',' ValueRef ']' { $$ = $1; $1->push_back(make_pair(getVal($1->front().first->getType(), $4), - getVal(Type::LabelTy, $6)->castBasicBlockAsserting())); + cast(getVal(Type::LabelTy, $6)))); } @@ -1238,7 +1244,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef { | CALL TypesV ValueRef '(' ValueRefListE ')' { const MethodType *Ty; - if (!(Ty = (*$2)->dyncastMethodType())) { + if (!(Ty = dyn_cast($2->get()))) { // Pull out the types of all of the arguments... vector ParamTypes; for (list::iterator I = $5->begin(), E = $5->end(); I != E; ++I) @@ -1251,7 +1257,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef { // Create the call node... if (!$5) { // Has no arguments? - $$ = new CallInst(V->castMethodAsserting(), vector()); + $$ = new CallInst(cast(V), vector()); } else { // Has arguments? // Loop through MethodType's arguments and ensure they are specified // correctly! @@ -1268,7 +1274,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef { if (I != E || (ArgI != ArgE && !Ty->isVarArg())) ThrowException("Invalid number of parameters detected!"); - $$ = new CallInst(V->castMethodAsserting(), + $$ = new CallInst(cast(V), vector($5->begin(), $5->end())); } delete $5; diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp index bb0990d1c21..256f7c82889 100644 --- a/lib/Bytecode/Writer/InstructionWriter.cpp +++ b/lib/Bytecode/Writer/InstructionWriter.cpp @@ -215,7 +215,7 @@ void BytecodeWriter::processInstruction(const Instruction *I) { if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1]; NumOperands++; } else if (I->getOpcode() == Instruction::Call && // Handle VarArg calls - I->getOperand(0)->getType()->castMethodType()->isVarArg()) { + cast(I->getOperand(0)->getType())->isVarArg()) { outputInstrVarArgsCall(I, Table, Type, Out); return; } diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index da480180a8b..04a0ca4624f 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -108,7 +108,7 @@ void BytecodeWriter::outputConstants(bool isMethod) { // << Out.size() << "\n"; outputConstant(CPV); } else { - const Type *Ty = V->castTypeAsserting(); + const Type *Ty = cast(V); outputType(Ty); } } diff --git a/lib/CodeGen/InstrSched/SchedGraph.cpp b/lib/CodeGen/InstrSched/SchedGraph.cpp index 2656cd21cc1..40601300f76 100644 --- a/lib/CodeGen/InstrSched/SchedGraph.cpp +++ b/lib/CodeGen/InstrSched/SchedGraph.cpp @@ -535,7 +535,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node, if (!val->isInstruction()) return; const Instruction* thisVMInstr = node->getInstr(); - const Instruction* defVMInstr = val->castInstructionAsserting(); + const Instruction* defVMInstr = cast(val); // Phi instructions are the only ones that produce a value but don't get // any non-dummy machine instructions. Return here as an optimization. diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index ff4e037ce2d..3ecc3ec0eab 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -810,7 +810,7 @@ void Interpreter::printValue(const string &Name) { Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name)); if (!PickedVal) return; - if (const Method *M = PickedVal->castMethod()) { + if (const Method *M = dyn_cast(PickedVal)) { cout << M; // Print the method } else { // Otherwise there should be an annotation for the slot# printValue(PickedVal->getType(), diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp index 508bd4a3246..eb5725feddc 100644 --- a/lib/ExecutionEngine/Interpreter/UserInput.cpp +++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp @@ -144,7 +144,7 @@ bool Interpreter::callMethod(const string &Name) { if (PickedMeth == 0) return true; - Method *M = PickedMeth->castMethodAsserting(); + Method *M = cast(PickedMeth); vector Args; // TODO, get args from user... diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp index 2656cd21cc1..40601300f76 100644 --- a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp +++ b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp @@ -535,7 +535,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node, if (!val->isInstruction()) return; const Instruction* thisVMInstr = node->getInstr(); - const Instruction* defVMInstr = val->castInstructionAsserting(); + const Instruction* defVMInstr = cast(val); // Phi instructions are the only ones that produce a value but don't get // any non-dummy machine instructions. Return here as an optimization. diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index c37dae16ac5..9001c746e74 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp @@ -158,8 +158,8 @@ void SparcAsmPrinter::emitMachineInst(const MachineInstr *MI) { const Value *Val = Op.getVRegValue(); if (!Val) { Out << "\t<*NULL Value*>"; - } else if (Val->isBasicBlock()) { - Out << getID(Val->castBasicBlockAsserting()); + } else if (const BasicBlock *BB = dyn_cast(Val)) { + Out << getID(BB); } else { Out << ""; } diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 480a2696b56..ea36745c68a 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -152,7 +152,7 @@ bool ADCE::doADCE() { // they are known to be alive as well... // for (unsigned op = 0, End = I->getNumOperands(); op != End; ++op) { - if (Instruction *Operand = I->getOperand(op)->castInstruction()) + if (Instruction *Operand = dyn_cast(I->getOperand(op))) markInstructionLive(Operand); } } diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp index fdf58cb56d4..8b879162426 100644 --- a/lib/Transforms/Scalar/ConstantProp.cpp +++ b/lib/Transforms/Scalar/ConstantProp.cpp @@ -85,8 +85,8 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) { if (T->getOpcode() == Instruction::Br) { BranchInst *BI = (BranchInst*)T; if (BI->isUnconditional()) return false; // Can't optimize uncond branch - BasicBlock *Dest1 = BI->getOperand(0)->castBasicBlockAsserting(); - BasicBlock *Dest2 = BI->getOperand(1)->castBasicBlockAsserting(); + BasicBlock *Dest1 = cast(BI->getOperand(0)); + BasicBlock *Dest2 = cast(BI->getOperand(1)); if (BI->getCondition()->isConstant()) { // Are we branching on constant? // YES. Change to unconditional branch... diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index 69521d6c8b3..6815ccb9a40 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/lib/Transforms/Scalar/InductionVars.cpp @@ -76,7 +76,7 @@ static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V, if (isLoopInvariant(Int, V)) return isLIC; // loop variant computations must be instructions! - Instruction *I = V->castInstructionAsserting(); + Instruction *I = cast(V); switch (I->getOpcode()) { // Handle each instruction seperately case Instruction::Add: case Instruction::Sub: { diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 268b654d140..78b6c3df7b4 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -127,7 +127,7 @@ private: // inline bool markOverdefined(Value *V) { if (ValueState[V].markOverdefined()) { - if (Instruction *I = V->castInstruction()) { + if (Instruction *I = dyn_cast(V)) { //cerr << "markOverdefined: " << V; InstWorkList.push_back(I); // Only instructions go on the work list } @@ -497,7 +497,7 @@ void SCCP::UpdateInstruction(Instruction *I) { // void SCCP::OperandChangedState(User *U) { // Only instructions use other variable values! - Instruction *I = U->castInstructionAsserting(); + Instruction *I = cast(U); if (!BBExecutable.count(I->getParent())) return; // Inst not executable yet! UpdateInstruction(I); diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 24d7cc8e7f3..e40006c2330 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -35,24 +35,24 @@ ostream &WriteAsOperand(ostream &Out, const Value *V, bool PrintType, if (PrintName && V->hasName()) { Out << " %" << V->getName(); } else { - if (const ConstPoolVal *CPV = V->castConstant()) { + if (const ConstPoolVal *CPV = dyn_cast(V)) { Out << " " << CPV->getStrValue(); } else { int Slot; if (Table) { Slot = Table->getValSlot(V); } else { - if (const Type *Ty = V->castType()) { + if (const Type *Ty = dyn_cast(V)) { return Out << " " << Ty; - } else if (const MethodArgument *MA = V->castMethodArgument()) { + } else if (const MethodArgument *MA =dyn_cast(V)){ Table = new SlotCalculator(MA->getParent(), true); - } else if (const Instruction *I = V->castInstruction()) { + } else if (const Instruction *I = dyn_cast(V)) { Table = new SlotCalculator(I->getParent()->getParent(), true); - } else if (const BasicBlock *BB = V->castBasicBlock()) { + } else if (const BasicBlock *BB = dyn_cast(V)) { Table = new SlotCalculator(BB->getParent(), true); - } else if (const Method *Meth = V->castMethod()) { + } else if (const Method *Meth = dyn_cast(V)) { Table = new SlotCalculator(Meth, true); - } else if (const Module *Mod = V->castModule()) { + } else if (const Module *Mod = dyn_cast(V)) { Table = new SlotCalculator(Mod, true); } else { return Out << "BAD VALUE TYPE!"; -- 2.34.1