From 1d87bcf4909b06dcd86320722653341f08b8b396 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 1 Oct 2001 20:11:19 +0000 Subject: [PATCH] Convert more code to use new style casts Eliminate old style casts from value.h git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@696 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/ConstantsScanner.h | 2 +- include/llvm/Analysis/InstForest.h | 4 +- include/llvm/ConstPoolVals.h | 17 ++++- include/llvm/Value.h | 68 ++++++++++--------- lib/Analysis/Expressions.cpp | 19 +++--- lib/AsmParser/ParserInternals.h | 5 +- lib/Bytecode/Reader/ConstantReader.cpp | 8 +-- lib/Bytecode/Reader/InstructionReader.cpp | 28 ++++---- lib/Bytecode/Reader/Reader.cpp | 6 +- lib/Bytecode/Reader/ReaderInternals.h | 3 +- lib/Bytecode/Writer/SlotCalculator.cpp | 4 +- lib/Bytecode/Writer/Writer.cpp | 6 +- lib/CodeGen/InstrSched/SchedGraph.cpp | 3 +- lib/CodeGen/InstrSelection/InstrForest.cpp | 14 ++-- lib/CodeGen/MachineInstr.cpp | 8 +-- lib/ExecutionEngine/Interpreter/Execution.cpp | 4 +- lib/ExecutionEngine/Interpreter/UserInput.cpp | 2 +- lib/Target/SparcV9/InstrSched/SchedGraph.cpp | 3 +- .../SparcV9/InstrSelection/InstrForest.cpp | 14 ++-- lib/Target/SparcV9/SparcV9InstrSelection.cpp | 22 +++--- lib/Transforms/IPO/InlineSimple.cpp | 2 +- lib/Transforms/Scalar/ConstantProp.cpp | 10 +-- lib/Transforms/Scalar/InductionVars.cpp | 12 ++-- lib/Transforms/Scalar/SCCP.cpp | 4 +- lib/VMCore/AsmWriter.cpp | 4 +- lib/VMCore/BasicBlock.cpp | 2 +- lib/VMCore/ConstPoolVals.cpp | 4 +- lib/VMCore/Function.cpp | 2 +- lib/VMCore/SlotCalculator.cpp | 4 +- 29 files changed, 150 insertions(+), 134 deletions(-) diff --git a/include/llvm/Analysis/ConstantsScanner.h b/include/llvm/Analysis/ConstantsScanner.h index cbf976573e0..4c86834d214 100644 --- a/include/llvm/Analysis/ConstantsScanner.h +++ b/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(InstI->getOperand(OpIdx)); } public: diff --git a/include/llvm/Analysis/InstForest.h b/include/llvm/Analysis/InstForest.h index eac08f91e58..967ed45ec96 100644 --- a/include/llvm/Analysis/InstForest.h +++ b/include/llvm/Analysis/InstForest.h @@ -116,7 +116,7 @@ public: } o << getValue(); - if (!getValue()->isInstruction()) o << "\n"; + if (!isa(getValue())) o << "\n"; for (unsigned i = 0; i < getNumChildren(); ++i) getChild(i)->print(o, Indent+1); @@ -229,7 +229,7 @@ InstTreeNode::InstTreeNode(InstForest &IF, Value *V, InstTreeNode *Parent) : super(Parent) { getTreeData().first.first = V; // Save tree node - if (!V->isInstruction()) { + if (!isa(V)) { assert((isa(V) || isa(V) || isa(V) || isa(V)) && "Unrecognized value type for InstForest Partition!"); diff --git a/include/llvm/ConstPoolVals.h b/include/llvm/ConstPoolVals.h index 1bd2dce8117..342070c9caf 100644 --- a/include/llvm/ConstPoolVals.h +++ b/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(V) && isa(cast(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(V) && isa(cast(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/include/llvm/Value.h b/include/llvm/Value.h index 3ef46cac86a..1acf2e299dd 100644 --- a/include/llvm/Value.h +++ b/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->castAsserting() is used in the same // way as the Val->cast() 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 real_type > { typedef X *Type; }; // if (isa(myVal)) { ... } // template -bool isa(Y Val) { return X::isa(Val); } +inline bool isa(Y Val) { return X::isa(Val); } // cast - Return the argument parameter cast to the specified type. This @@ -218,7 +196,7 @@ bool isa(Y Val) { return X::isa(Val); } // cast(myVal)->getParent() // template -X *cast(Y Val) { +inline X *cast(Y Val) { assert(isa(Val) && "Invalid cast argument type!"); return (X*)(real_type::Type)Val; } @@ -233,7 +211,7 @@ X *cast(Y Val) { // template -X *dyn_cast(Y Val) { +inline X *dyn_cast(Y Val) { return isa(Val) ? cast(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(Value *Val) { +template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::TypeVal; } -template <> bool isa(Value *Val) { +template <> inline bool isa(Value *Val) { + return Val->getValueType() == Value::TypeVal; +} +template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::ConstantVal; } -template <> bool isa(Value *Val) { +template <> inline bool isa(Value *Val) { + return Val->getValueType() == Value::ConstantVal; +} +template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::MethodArgumentVal; } -template <> bool isa(Value *Val) { +template <> inline bool isa(Value *Val) { + return Val->getValueType() == Value::MethodArgumentVal; +} +template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::InstructionVal; } -template <> bool isa(Value *Val) { +template <> inline bool isa(Value *Val) { + return Val->getValueType() == Value::InstructionVal; +} +template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::BasicBlockVal; } -template <> bool isa(Value *Val) { +template <> inline bool isa(Value *Val) { + return Val->getValueType() == Value::BasicBlockVal; +} +template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::MethodVal; } -template <> bool isa(Value *Val) { +template <> inline bool isa(Value *Val) { + return Val->getValueType() == Value::MethodVal; +} +template <> inline bool isa(const Value *Val) { return Val->getValueType() == Value::GlobalVal; } -template <> bool isa(Value *Val) { +template <> inline bool isa(Value *Val) { + return Val->getValueType() == Value::GlobalVal; +} +template <> inline bool isa(const Value *Val) { + return Val->getValueType() == Value::ModuleVal; +} +template <> inline bool isa(Value *Val) { return Val->getValueType() == Value::ModuleVal; } diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp index 8c9d75f2bd2..cb83d41236e 100644 --- a/lib/Analysis/Expressions.cpp +++ b/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(Val)) { + Offset = CPI; + Var = 0; + ExprTy = Constant; + Scale = 0; + return; + } + + Var = Val; Offset = 0; + ExprTy = Var ? Linear : Constant; Scale = 0; } diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h index 88986c288ab..bedb65f4a86 100644 --- a/lib/AsmParser/ParserInternals.h +++ b/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(Ty)) {} }; typedef PlaceholderValue TypePlaceHolder; diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index 67cfff7b973..aaecedddfa7 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/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(V)) return failure(true); + Elements.push_back(cast(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(V)) return failure(true); - Elements.push_back((ConstPoolVal*)V); + Elements.push_back(cast(V)); } V = ConstPoolStruct::get(ST, Elements); diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index 8c3e08ff94e..300c40999eb 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/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(V)) return failure(true); + Idx.push_back(cast(V)); break; case 3: V = getValue(Type::UByteTy, Raw.Arg2); - if (!V->isConstant()) return failure(true); - Idx.push_back(V->castConstant()); + if (!isa(V)) return failure(true); + Idx.push_back(cast(V)); V = getValue(Type::UByteTy, Raw.Arg3); - if (!V->isConstant()) return failure(true); - Idx.push_back(V->castConstant()); + if (!isa(V)) return failure(true); + Idx.push_back(cast(V)); break; default: V = getValue(Type::UByteTy, Raw.Arg2); - if (!V->isConstant()) return failure(true); - Idx.push_back(V->castConstant()); + if (!isa(V)) return failure(true); + Idx.push_back(cast(V)); vector &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(V)) return failure(true); + Idx.push_back(cast(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(V)) return failure(true); + Idx.push_back(cast(V)); break; default: vector &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(V)) return failure(true); + Idx.push_back(cast(V)); } delete Raw.VarArgs; break; diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index b7904bb60f7..0e4883034e6 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/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(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(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(Ty)) { cerr << "Method not meth type! Ty = " << Ty << endl; return failure(true); } diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h index ed4f1a4bba2..cf5a43ef3bb 100644 --- a/lib/Bytecode/Reader/ReaderInternals.h +++ b/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(Ty)) { } }; diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index d0f37fb723e..38980e5e63a 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/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(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(D) || isa(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 diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 94cbcec328d..5df2fdabde5 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/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(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(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(GV); output_vbr(oSlot, Out); // If we have an initialized, output it now. diff --git a/lib/CodeGen/InstrSched/SchedGraph.cpp b/lib/CodeGen/InstrSched/SchedGraph.cpp index 40601300f76..852c4f2686a 100644 --- a/lib/CodeGen/InstrSched/SchedGraph.cpp +++ b/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(val)) return; const Instruction* thisVMInstr = node->getInstr(); const Instruction* defVMInstr = cast(val); @@ -642,7 +642,6 @@ void SchedGraph::addNonSSAEdgesForValue(const Instruction* instr, const TargetMachine& target) { - assert(instr->isInstruction()); if (instr->isPHINode()) return; diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp index 9f4df08d384..f5a524707b9 100644 --- a/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/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(operand) || isa(operand)) && !instr->isTerminator(); - if (includeAddressOperand || operand->isInstruction() || - operand->isConstant() || operand->isMethodArgument() || - operand->isGlobal()) + if (includeAddressOperand || isa(operand) || + isa(operand) || isa(operand) || + isa(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(operand) && operand->use_size() == 1 && + cast(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(operand)) { // Create a leaf node for a constant opTreeNode = new ConstantNode(CPV); diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 1e3300763de..64076286f4b 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/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(opVal) || isa(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(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(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(val); if (!CPV) return opType; if (CPV->getType() == Type::BoolTy) diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 3ecc3ec0eab..d88d91ff1f9 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/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(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(V)) { unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value unsigned Slot = getOperandSlot(V); cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp index eb5725feddc..e9fc9db3436 100644 --- a/lib/ExecutionEngine/Interpreter/UserInput.cpp +++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp @@ -134,7 +134,7 @@ bool Interpreter::callMethod(const string &Name) { vector Options = LookupMatchingNames(Name); for (unsigned i = 0; i < Options.size(); ++i) { // Remove nonmethod matches... - if (!Options[i]->isMethod()) { + if (!isa(Options[i])) { Options.erase(Options.begin()+i); --i; } diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp index 40601300f76..852c4f2686a 100644 --- a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp +++ b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp @@ -532,7 +532,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node, const Value* val, const TargetMachine& target) { - if (!val->isInstruction()) return; + if (!isa(val)) return; const Instruction* thisVMInstr = node->getInstr(); const Instruction* defVMInstr = cast(val); @@ -642,7 +642,6 @@ void SchedGraph::addNonSSAEdgesForValue(const Instruction* instr, const TargetMachine& target) { - assert(instr->isInstruction()); if (instr->isPHINode()) return; diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp index 9f4df08d384..f5a524707b9 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp +++ b/lib/Target/SparcV9/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(operand) || isa(operand)) && !instr->isTerminator(); - if (includeAddressOperand || operand->isInstruction() || - operand->isConstant() || operand->isMethodArgument() || - operand->isGlobal()) + if (includeAddressOperand || isa(operand) || + isa(operand) || isa(operand) || + isa(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(operand) && operand->use_size() == 1 && + cast(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(operand)) { // Create a leaf node for a constant opTreeNode = new ConstantNode(CPV); diff --git a/lib/Target/SparcV9/SparcV9InstrSelection.cpp b/lib/Target/SparcV9/SparcV9InstrSelection.cpp index 572e1b175b3..b1b5e01aff5 100644 --- a/lib/Target/SparcV9/SparcV9InstrSelection.cpp +++ b/lib/Target/SparcV9/SparcV9InstrSelection.cpp @@ -60,7 +60,7 @@ static int64_t GetConstantValueAsSignedInt(const Value *V, bool &isValidConstant) { - if (!V->isConstant()) + if (!isa(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(resultType) || + isa(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(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(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(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(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(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(val)); MachineInstr* minstr1 = NULL; @@ -1183,7 +1183,7 @@ FixConstantOperands(const InstructionNode* vmInstrNode, Value* opValue = mop.getVRegValue(); - if (opValue->isConstant()) + if (isa(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(src)) { unsigned int machineRegNum; int64_t immedValue; diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index 27ef66e42e3..8bc0a77cd1f 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/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(Op) || isa(Op))) continue; // Methods and constants don't get relocated if (!V) { diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp index 8b879162426..d43f693dd17 100644 --- a/lib/Transforms/Scalar/ConstantProp.cpp +++ b/lib/Transforms/Scalar/ConstantProp.cpp @@ -88,9 +88,9 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) { BasicBlock *Dest1 = cast(BI->getOperand(0)); BasicBlock *Dest2 = cast(BI->getOperand(1)); - if (BI->getCondition()->isConstant()) { // Are we branching on constant? + if (ConstPoolBool *Cond = dyn_cast(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(Inst->getOperand(0)); + ConstPoolVal *D2 = dyn_cast(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(Inst->getOperand(0)); if (D) return ConstantFoldUnaryInst(M, II, (UnaryOperator*)Inst, D); } else if (Inst->isTerminator()) { return opt::ConstantFoldTerminator((TerminatorInst*)Inst); diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index 6815ccb9a40..f2dcb451535 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/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(V) || isa(V) || isa(V)); - if (!V->isInstruction()) + if (!isa(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(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(StepExpr) || ((Instruction*)StepExpr)->getOpcode() != Instruction::Add) return false; BinaryOperator *I = (BinaryOperator*)StepExpr; - assert(I->getOperand(0)->isInstruction() && + assert(isa(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(StepSize)) return false; if (StepSize->getType()->isSigned()) { // Signed constant value... if (((ConstPoolSInt*)StepSize)->getValue() != 1) return false; diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 78b6c3df7b4..91e002d8be9 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -146,9 +146,9 @@ private: map::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(V)) {//Constants are constant ValueState[CPV].markConstant(CPV); - } else if (V->isMethodArgument()) { // MethodArgs are overdefined + } else if (isa(V)) { // MethodArgs are overdefined ValueState[V].markOverdefined(); } // All others are underdefined by default... diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 3c67c2ca088..b9a1c6dbeed 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 = cast(V)) { + if (const ConstPoolVal *CPV = dyn_cast(V)) { processConstant(CPV); - } else if (const Type *Ty = cast(V)) { + } else if (const Type *Ty = dyn_cast(V)) { Out << "\t%" << I->first << " = type " << Ty->getDescription() << endl; } } diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 7d97c85f7de..81c1f11616e 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/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(*I)) return true; return false; diff --git a/lib/VMCore/ConstPoolVals.cpp b/lib/VMCore/ConstPoolVals.cpp index 374c583ab9b..bf538bd2516 100644 --- a/lib/VMCore/ConstPoolVals.cpp +++ b/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/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 5d1132f0a7d..9eb8277a272 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -28,7 +28,7 @@ template class ValueHolder; 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(Ty) && "Method signature must be of method type!"); Parent = 0; } diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index d0f37fb723e..38980e5e63a 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/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(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(D) || isa(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