diff options
Diffstat (limited to 'lib')
25 files changed, 127 insertions, 133 deletions
diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp index cb83d41236..abe2a18b94 100644 --- a/lib/Analysis/Expressions.cpp +++ b/lib/Analysis/Expressions.cpp @@ -97,7 +97,7 @@ static const ConstPoolInt *Add(const ConstPoolInt *Arg1, ConstPoolVal *Result = *Arg1 + *Arg2; assert(Result && Result->getType() == Arg1->getType() && "Couldn't perform addition!"); - ConstPoolInt *ResultI = (ConstPoolInt*)Result; + ConstPoolInt *ResultI = cast<ConstPoolInt>(Result); // Check to see if the result is one of the special cases that we want to // recognize... @@ -147,7 +147,7 @@ inline const ConstPoolInt *Mul(const ConstPoolInt *Arg1, ConstPoolVal *Result = *Arg1 * *Arg2; assert(Result && Result->getType() == Arg1->getType() && "Couldn't perform mult!"); - ConstPoolInt *ResultI = (ConstPoolInt*)Result; + ConstPoolInt *ResultI = cast<ConstPoolInt>(Result); // Check to see if the result is one of the special cases that we want to // recognize... @@ -203,7 +203,7 @@ static inline ExprType negate(const ExprType &E, Value *V) { const Type *ETy = E.getExprType(Ty); ConstPoolInt *Zero = getUnsignedConstant(0, ETy); ConstPoolInt *One = getUnsignedConstant(1, ETy); - ConstPoolInt *NegOne = (ConstPoolInt*)(*Zero - *One); + ConstPoolInt *NegOne = cast<ConstPoolInt>(*Zero - *One); if (NegOne == 0) return V; // Couldn't subtract values... return ExprType(DefOne (E.Scale , Ty) * NegOne, E.Var, @@ -230,7 +230,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) { case Value::ConstantVal: // Constant value, just return constant ConstPoolVal *CPV = cast<ConstPoolVal>(Expr); if (CPV->getType()->isIntegral()) { // It's an integral constant! - ConstPoolInt *CPI = (ConstPoolInt*)Expr; + ConstPoolInt *CPI = cast<ConstPoolInt>(Expr); return ExprType(CPI->equalsInt(0) ? 0 : CPI); } return Expr; @@ -297,7 +297,7 @@ ExprType analysis::ClassifyExpression(Value *Expr) { const ConstPoolVal *CPV =ConstRules::get(*Offs)->castTo(Offs, DestTy); if (!CPV) return I; assert(CPV->getType()->isIntegral() && "Must have an integral type!"); - return (ConstPoolInt*)CPV; + return cast<ConstPoolInt>(CPV); } // end case Instruction::Cast // TODO: Handle SUB, SHR? diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp index b1a272f032..87dbf2b425 100644 --- a/lib/Analysis/IPA/CallGraph.cpp +++ b/lib/Analysis/IPA/CallGraph.cpp @@ -38,10 +38,8 @@ void CallGraph::addToCallGraph(Method *M) { for (Method::inst_iterator II = M->inst_begin(), IE = M->inst_end(); II != IE; ++II) { - if (II->getOpcode() == Instruction::Call) { - CallInst *CI = (CallInst*)*II; + if (CallInst *CI = dyn_cast<CallInst>(*II)) Node->addCalledMethod(getNodeFor(CI->getCalledMethod())); - } } } diff --git a/lib/Analysis/ModuleAnalyzer.cpp b/lib/Analysis/ModuleAnalyzer.cpp index 8212287962..d543216349 100644 --- a/lib/Analysis/ModuleAnalyzer.cpp +++ b/lib/Analysis/ModuleAnalyzer.cpp @@ -46,7 +46,7 @@ inline bool ModuleAnalyzer::handleType(set<const Type *> &TypeSet, break; case Type::StructTyID: { - const StructType *ST = (const StructType*)T; + const StructType *ST = cast<const StructType>(T); const StructType::ElementTypes &Elements = ST->getElementTypes(); for (StructType::ElementTypes::const_iterator I = Elements.begin(); I != Elements.end(); ++I) diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 819f96290f..a0c96733a0 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -397,10 +397,9 @@ static void setValueName(Value *V, char *NameStr) { // 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 = cast<const Type>(Existing)) - if (Ty->isOpaqueType()) { + if (OpaqueType *OpTy = dyn_cast<OpaqueType>(Ty)) { // We ARE replacing an opaque type! - - cast<DerivedType>(Ty)->refineAbstractTypeTo(cast<Type>(V)); + OpTy->refineAbstractTypeTo(cast<Type>(V)); return; } @@ -1232,7 +1231,7 @@ InstVal : BinaryOps Types ValueRef ',' ValueRef { while ($2->begin() != $2->end()) { if ($2->front().first->getType() != Ty) ThrowException("All elements of a PHI node must be of the same type!"); - ((PHINode*)$$)->addIncoming($2->front().first, $2->front().second); + cast<PHINode>($$)->addIncoming($2->front().first, $2->front().second); $2->pop_front(); } delete $2; // Free the list... @@ -1291,7 +1290,7 @@ MemoryInst : MALLOC Types { delete $2; } | MALLOC Types ',' UINT ValueRef { - if (!(*$2)->isArrayType() || ((const ArrayType*)$2->get())->isSized()) + if (!(*$2)->isArrayType() || cast<const ArrayType>($2->get())->isSized()) ThrowException("Trying to allocate " + (*$2)->getName() + " as unsized array!"); const Type *Ty = PointerType::get(*$2); @@ -1303,7 +1302,7 @@ MemoryInst : MALLOC Types { delete $2; } | ALLOCA Types ',' UINT ValueRef { - if (!(*$2)->isArrayType() || ((const ArrayType*)$2->get())->isSized()) + if (!(*$2)->isArrayType() || cast<const ArrayType>($2->get())->isSized()) ThrowException("Trying to allocate " + (*$2)->getName() + " as unsized array!"); const Type *Ty = PointerType::get(*$2); diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index aaecedddfa..4c7f7c9ac2 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -229,7 +229,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf, abort(); case Type::ArrayTyID: { - const ArrayType *AT = (const ArrayType*)Ty; + const ArrayType *AT = cast<const ArrayType>(Ty); unsigned NumElements; if (AT->isSized()) // Sized array, # elements stored in type! NumElements = (unsigned)AT->getNumElements(); @@ -249,7 +249,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf, } case Type::StructTyID: { - const StructType *ST = Ty->castStructType(); + const StructType *ST = cast<StructType>(Ty); const StructType::ElementTypes &ET = ST->getElementTypes(); vector<ConstPoolVal *> Elements; @@ -267,7 +267,7 @@ bool BytecodeParser::parseConstPoolValue(const uchar *&Buf, } case Type::PointerTyID: { - const PointerType *PT = Ty->castPointerType(); + const PointerType *PT = cast<const PointerType>(Ty); unsigned SubClass; if (read_vbr(Buf, EndBuf, SubClass)) return failure(true); if (SubClass != 0) return failure(true); diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index 300c40999e..b6eec66491 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/lib/Bytecode/Reader/InstructionReader.cpp @@ -122,11 +122,11 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, delete PN; return failure(true); case 2: PN->addIncoming(getValue(Raw.Ty, Raw.Arg1), - (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2)); + cast<BasicBlock>(getValue(Type::LabelTy,Raw.Arg2))); break; default: PN->addIncoming(getValue(Raw.Ty, Raw.Arg1), - (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2)); + cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2))); if (Raw.VarArgs->size() & 1) { cerr << "PHI Node with ODD number of arguments!\n"; delete PN; @@ -135,7 +135,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, vector<unsigned> &args = *Raw.VarArgs; for (unsigned i = 0; i < args.size(); i+=2) PN->addIncoming(getValue(Raw.Ty, args[i]), - (BasicBlock*)getValue(Type::LabelTy, args[i+1])); + cast<BasicBlock>(getValue(Type::LabelTy, args[i+1]))); } delete Raw.VarArgs; break; @@ -160,12 +160,12 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, case Instruction::Br: if (Raw.NumOperands == 1) { - Res = new BranchInst((BasicBlock*)getValue(Type::LabelTy, Raw.Arg1)); + Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg1))); return false; } else if (Raw.NumOperands == 3) { - Res = new BranchInst((BasicBlock*)getValue(Type::LabelTy, Raw.Arg1), - (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2), - getValue(Type::BoolTy , Raw.Arg3)); + Res = new BranchInst(cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg1)), + cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2)), + getValue(Type::BoolTy , Raw.Arg3)); return false; } break; @@ -173,7 +173,7 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, case Instruction::Switch: { SwitchInst *I = new SwitchInst(getValue(Raw.Ty, Raw.Arg1), - (BasicBlock*)getValue(Type::LabelTy, Raw.Arg2)); + cast<BasicBlock>(getValue(Type::LabelTy, Raw.Arg2))); Res = I; if (Raw.NumOperands < 3) return false; // No destinations? Wierd. @@ -185,15 +185,15 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, vector<unsigned> &args = *Raw.VarArgs; for (unsigned i = 0; i < args.size(); i += 2) - I->dest_push_back((ConstPoolVal*)getValue(Raw.Ty, args[i]), - (BasicBlock*)getValue(Type::LabelTy, args[i+1])); + I->dest_push_back(cast<ConstPoolVal>(getValue(Raw.Ty, args[i])), + cast<BasicBlock>(getValue(Type::LabelTy, args[i+1]))); delete Raw.VarArgs; return false; } case Instruction::Call: { - Method *M = (Method*)getValue(Raw.Ty, Raw.Arg1); + Method *M = cast<Method>(getValue(Raw.Ty, Raw.Arg1)); if (M == 0) return failure(true); vector<Value *> Params; diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 0e4883034e..14e89e2d20 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -338,7 +338,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, unsigned InitSlot; if (read_vbr(Buf, End, InitSlot)) return failure(true); - Value *V = getValue(Ty->castPointerType()->getValueType(), + Value *V = getValue(cast<const PointerType>(Ty)->getValueType(), InitSlot, false); if (V == 0) return failure(true); Initializer = cast<ConstPoolVal>(V); @@ -382,7 +382,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, // Keep track of this information in a linked list that is emptied as // methods are loaded... // - MethodSignatureList.push_back(make_pair((const MethodType*)Ty, SlotNo)); + MethodSignatureList.push_back(make_pair(cast<const MethodType>(Ty),SlotNo)); if (read_vbr(Buf, End, MethSignature)) return failure(true); BCR_TRACE(2, "Method of type: " << Ty << endl); } diff --git a/lib/Bytecode/Writer/ConstantWriter.cpp b/lib/Bytecode/Writer/ConstantWriter.cpp index dde47d52b1..d0c58f1ae6 100644 --- a/lib/Bytecode/Writer/ConstantWriter.cpp +++ b/lib/Bytecode/Writer/ConstantWriter.cpp @@ -23,7 +23,7 @@ void BytecodeWriter::outputType(const Type *T) { switch (T->getPrimitiveID()) { // Handle derived types now. case Type::MethodTyID: { - const MethodType *MT = (const MethodType*)T; + const MethodType *MT = cast<const MethodType>(T); int Slot = Table.getValSlot(MT->getReturnType()); assert(Slot != -1 && "Type used but not available!!"); output_vbr((unsigned)Slot, Out); @@ -46,7 +46,7 @@ void BytecodeWriter::outputType(const Type *T) { } case Type::ArrayTyID: { - const ArrayType *AT = (const ArrayType*)T; + const ArrayType *AT = cast<const ArrayType>(T); int Slot = Table.getValSlot(AT->getElementType()); assert(Slot != -1 && "Type used but not available!!"); output_vbr((unsigned)Slot, Out); @@ -57,7 +57,7 @@ void BytecodeWriter::outputType(const Type *T) { } case Type::StructTyID: { - const StructType *ST = (const StructType*)T; + const StructType *ST = cast<const StructType>(T); // Output all of the element types... StructType::ElementTypes::const_iterator I = ST->getElementTypes().begin(); @@ -73,7 +73,7 @@ void BytecodeWriter::outputType(const Type *T) { } case Type::PointerTyID: { - const PointerType *PT = (const PointerType*)T; + const PointerType *PT = cast<const PointerType>(T); int Slot = Table.getValSlot(PT->getValueType()); assert(Slot != -1 && "Type used but not available!!"); output_vbr((unsigned)Slot, Out); @@ -91,7 +91,7 @@ void BytecodeWriter::outputType(const Type *T) { bool BytecodeWriter::outputConstant(const ConstPoolVal *CPV) { switch (CPV->getType()->getPrimitiveID()) { case Type::BoolTyID: // Boolean Types - if (((const ConstPoolBool*)CPV)->getValue()) + if (cast<const ConstPoolBool>(CPV)->getValue()) output_vbr((unsigned)1, Out); else output_vbr((unsigned)0, Out); diff --git a/lib/CodeGen/InstrSched/SchedGraph.cpp b/lib/CodeGen/InstrSched/SchedGraph.cpp index 852c4f2686..fd09e9e777 100644 --- a/lib/CodeGen/InstrSched/SchedGraph.cpp +++ b/lib/CodeGen/InstrSched/SchedGraph.cpp @@ -21,6 +21,7 @@ #include "llvm/Target/MachineInstrInfo.h" #include "llvm/Target/MachineRegInfo.h" #include "llvm/Support/StringExtras.h" +#include "llvm/iOther.h" #include <algorithm> @@ -540,7 +541,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node, // Phi instructions are the only ones that produce a value but don't get // any non-dummy machine instructions. Return here as an optimization. // - if (defVMInstr->isPHINode()) + if (isa<PHINode>(defVMInstr)) return; // Now add the graph edge for the appropriate machine instruction(s). @@ -642,7 +643,7 @@ void SchedGraph::addNonSSAEdgesForValue(const Instruction* instr, const TargetMachine& target) { - if (instr->isPHINode()) + if (isa<PHINode>(instr)) return; MachineCodeForVMInstr& mvec = instr->getMachineInstrVec(); diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp index f5a524707b..199ed6569b 100644 --- a/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/lib/CodeGen/InstrSelection/InstrForest.cpp @@ -26,6 +26,7 @@ #include "llvm/Method.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" +#include "llvm/iOther.h" #include "llvm/ConstPoolVals.h" #include "llvm/BasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" @@ -57,11 +58,11 @@ InstructionNode::InstructionNode(Instruction* I) // Distinguish special cases of some instructions such as Ret and Br // - if (opLabel == Instruction::Ret && ((ReturnInst*)I)->getReturnValue()) + if (opLabel == Instruction::Ret && cast<ReturnInst>(I)->getReturnValue()) { opLabel = RetValueOp; // ret(value) operation } - else if (opLabel == Instruction::Br && ! ((BranchInst*)I)->isUnconditional()) + else if (opLabel ==Instruction::Br && !cast<BranchInst>(I)->isUnconditional()) { opLabel = BrCondOp; // br(cond) operation } @@ -302,7 +303,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr) InstrTreeNode* opTreeNode; if (isa<Instruction>(operand) && operand->use_size() == 1 && cast<Instruction>(operand)->getParent() == instr->getParent() && - ! instr->isPHINode() && + !isa<PHINode>(instr) && instr->getOpcode() != Instruction::Call) { // Recursively create a treeNode for it. diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index d88d91ff1f..34a80fedd4 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -351,9 +351,9 @@ void Interpreter::executeAllocInst(AllocationInst *I, ExecutionContext &SF) { unsigned NumElements = 1; if (I->getNumOperands()) { // Allocating a unsized array type? - assert(Ty->isArrayType() && Ty->castArrayType()->isUnsized() && + assert(isa<ArrayType>(Ty) && cast<const ArrayType>(Ty)->isUnsized() && "Allocation inst with size operand for !unsized array type???"); - Ty = ((const ArrayType*)Ty)->getElementType(); // Get the actual type... + Ty = cast<const ArrayType>(Ty)->getElementType(); // Get the actual type... // Get the number of elements being allocated by the array... GenericValue NumEl = getOperandValue(I->getOperand(0), SF); @@ -665,16 +665,16 @@ bool Interpreter::executeInstruction() { // Memory Instructions case Instruction::Alloca: case Instruction::Malloc: executeAllocInst ((AllocationInst*)I, SF); break; - case Instruction::Free: executeFreeInst ((FreeInst*) I, SF); break; - case Instruction::Load: executeLoadInst ((LoadInst*) I, SF); break; - case Instruction::Store: executeStoreInst ((StoreInst*) I, SF); break; + case Instruction::Free: executeFreeInst (cast<FreeInst> (I), SF); break; + case Instruction::Load: executeLoadInst (cast<LoadInst> (I), SF); break; + case Instruction::Store: executeStoreInst (cast<StoreInst>(I), SF); break; // Miscellaneous Instructions - case Instruction::Call: executeCallInst ((CallInst*) I, SF); break; - case Instruction::PHINode: executePHINode ((PHINode*) I, SF); break; - case Instruction::Shl: executeShlInst ((ShiftInst*) I, SF); break; - case Instruction::Shr: executeShrInst ((ShiftInst*) I, SF); break; - case Instruction::Cast: executeCastInst ((CastInst*) I, SF); break; + case Instruction::Call: executeCallInst (cast<CallInst> (I), SF); break; + case Instruction::PHINode: executePHINode (cast<PHINode> (I), SF); break; + case Instruction::Shl: executeShlInst (cast<ShiftInst>(I), SF); break; + case Instruction::Shr: executeShrInst (cast<ShiftInst>(I), SF); break; + case Instruction::Cast: executeCastInst (cast<CastInst> (I), SF); break; default: cout << "Don't know how to execute this instruction!\n-->" << I; } diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp index 852c4f2686..fd09e9e777 100644 --- a/lib/Target/SparcV9/InstrSched/SchedGraph.cpp +++ b/lib/Target/SparcV9/InstrSched/SchedGraph.cpp @@ -21,6 +21,7 @@ #include "llvm/Target/MachineInstrInfo.h" #include "llvm/Target/MachineRegInfo.h" #include "llvm/Support/StringExtras.h" +#include "llvm/iOther.h" #include <algorithm> @@ -540,7 +541,7 @@ SchedGraph::addSSAEdge(SchedGraphNode* node, // Phi instructions are the only ones that produce a value but don't get // any non-dummy machine instructions. Return here as an optimization. // - if (defVMInstr->isPHINode()) + if (isa<PHINode>(defVMInstr)) return; // Now add the graph edge for the appropriate machine instruction(s). @@ -642,7 +643,7 @@ void SchedGraph::addNonSSAEdgesForValue(const Instruction* instr, const TargetMachine& target) { - if (instr->isPHINode()) + if (isa<PHINode>(instr)) return; MachineCodeForVMInstr& mvec = instr->getMachineInstrVec(); diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp index f5a524707b..199ed6569b 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp @@ -26,6 +26,7 @@ #include "llvm/Method.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" +#include "llvm/iOther.h" #include "llvm/ConstPoolVals.h" #include "llvm/BasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" @@ -57,11 +58,11 @@ InstructionNode::InstructionNode(Instruction* I) // Distinguish special cases of some instructions such as Ret and Br // - if (opLabel == Instruction::Ret && ((ReturnInst*)I)->getReturnValue()) + if (opLabel == Instruction::Ret && cast<ReturnInst>(I)->getReturnValue()) { opLabel = RetValueOp; // ret(value) operation } - else if (opLabel == Instruction::Br && ! ((BranchInst*)I)->isUnconditional()) + else if (opLabel ==Instruction::Br && !cast<BranchInst>(I)->isUnconditional()) { opLabel = BrCondOp; // br(cond) operation } @@ -302,7 +303,7 @@ InstrForest::buildTreeForInstruction(Instruction *instr) InstrTreeNode* opTreeNode; if (isa<Instruction>(operand) && operand->use_size() == 1 && cast<Instruction>(operand)->getParent() == instr->getParent() && - ! instr->isPHINode() && + !isa<PHINode>(instr) && instr->getOpcode() != Instruction::Call) { // Recursively create a treeNode for it. diff --git a/lib/Target/SparcV9/SparcV9InstrSelection.cpp b/lib/Target/SparcV9/SparcV9InstrSelection.cpp index b1b5e01aff..e4ae8a8400 100644 --- a/lib/Target/SparcV9/SparcV9InstrSelection.cpp +++ b/lib/Target/SparcV9/SparcV9InstrSelection.cpp @@ -2010,9 +2010,8 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, // Also, mark the operands of the Call as implicit operands // of the machine instruction. { - CallInst* callInstr = (CallInst*) subtreeRoot->getInstruction(); + CallInst *callInstr = cast<CallInst>(subtreeRoot->getInstruction()); Method* callee = callInstr->getCalledMethod(); - assert(callInstr->getOpcode() == Instruction::Call); Instruction* jmpAddrReg = new TmpInstruction(Instruction::UserOp1, callee, NULL); diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 24a5e852a2..0b4dc98233 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -147,14 +147,14 @@ unsigned char TargetData::getTypeAlignment(const Type *Ty) const { unsigned TargetData::getIndexedOffset(const Type *ptrTy, const vector<ConstPoolVal*> &Idx) const { - const PointerType *PtrTy = ptrTy->castPointerType(); + const PointerType *PtrTy = cast<const PointerType>(ptrTy); unsigned Result = 0; // Get the type pointed to... const Type *Ty = PtrTy->getValueType(); for (unsigned CurIDX = 0; CurIDX < Idx.size(); ++CurIDX) { - if (const StructType *STy = Ty->dyncastStructType()) { + if (const StructType *STy = dyn_cast<const StructType>(Ty)) { assert(Idx[CurIDX]->getType() == Type::UByteTy && "Illegal struct idx"); unsigned FieldNo = ((ConstPoolUInt*)Idx[CurIDX++])->getValue(); @@ -168,7 +168,7 @@ unsigned TargetData::getIndexedOffset(const Type *ptrTy, // Update Ty to refer to current element Ty = STy->getElementTypes()[FieldNo]; - } else if (const ArrayType *ATy = Ty->dyncastArrayType()) { + } else if (const ArrayType *ATy = dyn_cast<const ArrayType>(Ty)) { assert(0 && "Loading from arrays not implemented yet!"); } else { assert(0 && "Indexing type that is not struct or array?"); diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index 8bc0a77cd1..c8afc27e3e 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -63,12 +63,11 @@ static inline void RemapInstruction(Instruction *I, // method by one level. // bool opt::InlineMethod(BasicBlock::iterator CIIt) { - assert((*CIIt)->getOpcode() == Instruction::Call && - "InlineMethod only works on CallInst nodes!"); + assert(isa<CallInst>(*CIIt) && "InlineMethod only works on CallInst nodes!"); assert((*CIIt)->getParent() && "Instruction not embedded in basic block!"); assert((*CIIt)->getParent()->getParent() && "Instruction not in method!"); - CallInst *CI = (CallInst*)*CIIt; + CallInst *CI = cast<CallInst>(*CIIt); const Method *CalledMeth = CI->getCalledMethod(); if (CalledMeth->isExternal()) return false; // Can't inline external method! Method *CurrentMeth = CI->getParent()->getParent(); @@ -152,13 +151,13 @@ bool opt::InlineMethod(BasicBlock::iterator CIIt) { // Copy over the terminator now... switch (TI->getOpcode()) { case Instruction::Ret: { - const ReturnInst *RI = (const ReturnInst*)TI; + const ReturnInst *RI = cast<const ReturnInst>(TI); if (PHI) { // The PHI node should include this value! assert(RI->getReturnValue() && "Ret should have value!"); assert(RI->getReturnValue()->getType() == PHI->getType() && "Ret value not consistent in method!"); - PHI->addIncoming((Value*)RI->getReturnValue(), (BasicBlock*)BB); + PHI->addIncoming((Value*)RI->getReturnValue(), cast<BasicBlock>(BB)); } // Add a branch to the code that was after the original Call. @@ -236,9 +235,8 @@ static inline bool ShouldInlineMethod(const CallInst *CI, const Method *M) { static inline bool DoMethodInlining(BasicBlock *BB) { for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) { - if ((*I)->getOpcode() == Instruction::Call) { + if (CallInst *CI = dyn_cast<CallInst>(*I)) { // Check to see if we should inline this method - CallInst *CI = (CallInst*)*I; Method *M = CI->getCalledMethod(); if (ShouldInlineMethod(CI, M)) return InlineMethod(I); diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index ea36745c68..18c851b118 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/DepthFirstIterator.h" #include "llvm/Analysis/Writer.h" #include "llvm/iTerminators.h" +#include "llvm/iOther.h" #include <set> #include <algorithm> @@ -171,15 +172,15 @@ bool ADCE::doADCE() { set<BasicBlock*> VisitedBlocks; BasicBlock *EntryBlock = fixupCFG(M->front(), VisitedBlocks, AliveBlocks); if (EntryBlock && EntryBlock != M->front()) { - if (EntryBlock->front()->isPHINode()) { + if (isa<PHINode>(EntryBlock->front())) { // Cannot make the first block be a block with a PHI node in it! Instead, // strip the first basic block of the method to contain no instructions, // then add a simple branch to the "real" entry node... // BasicBlock *E = M->front(); - if (!E->front()->isTerminator() || // Check for an actual change... - ((TerminatorInst*)E->front())->getNumSuccessors() != 1 || - ((TerminatorInst*)E->front())->getSuccessor(0) != EntryBlock) { + if (!isa<TerminatorInst>(E->front()) || // Check for an actual change... + cast<TerminatorInst>(E->front())->getNumSuccessors() != 1 || + cast<TerminatorInst>(E->front())->getSuccessor(0) != EntryBlock) { E->getInstList().delete_all(); // Delete all instructions in block E->getInstList().push_back(new BranchInst(EntryBlock)); MadeChanges = true; diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp index d43f693dd1..61c026a139 100644 --- a/lib/Transforms/Scalar/ConstantProp.cpp +++ b/lib/Transforms/Scalar/ConstantProp.cpp @@ -82,8 +82,7 @@ ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI, // bool opt::ConstantFoldTerminator(TerminatorInst *T) { // Branch - See if we are conditional jumping on constant - if (T->getOpcode() == Instruction::Br) { - BranchInst *BI = (BranchInst*)T; + if (BranchInst *BI = dyn_cast<BranchInst>(T)) { if (BI->isUnconditional()) return false; // Can't optimize uncond branch BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0)); BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1)); @@ -136,22 +135,22 @@ bool opt::ConstantFoldTerminator(TerminatorInst *T) { inline static bool ConstantFoldInstruction(Method *M, Method::inst_iterator &II) { Instruction *Inst = *II; - if (Inst->isBinaryOp()) { + if (BinaryOperator *BInst = dyn_cast<BinaryOperator>(Inst)) { ConstPoolVal *D1 = dyn_cast<ConstPoolVal>(Inst->getOperand(0)); ConstPoolVal *D2 = dyn_cast<ConstPoolVal>(Inst->getOperand(1)); if (D1 && D2) - return ConstantFoldBinaryInst(M, II, (BinaryOperator*)Inst, D1, D2); + return ConstantFoldBinaryInst(M, II, cast<BinaryOperator>(Inst), D1, D2); - } else if (Inst->isUnaryOp()) { - ConstPoolVal *D = dyn_cast<ConstPoolVal>(Inst->getOperand(0)); - if (D) return ConstantFoldUnaryInst(M, II, (UnaryOperator*)Inst, D); - } else if (Inst->isTerminator()) { - return opt::ConstantFoldTerminator((TerminatorInst*)Inst); + } else if (UnaryOperator *UInst = dyn_cast<UnaryOperator>(Inst)) { + ConstPoolVal *D = dyn_cast<ConstPoolVal>(UInst->getOperand(0)); + if (D) return ConstantFoldUnaryInst(M, II, UInst, D); + } else if (TerminatorInst *TInst = dyn_cast<TerminatorInst>(Inst)) { + return opt::ConstantFoldTerminator(TInst); - } else if (Inst->isPHINode()) { - PHINode *PN = (PHINode*)Inst; // If it's a PHI node and only has one operand - // Then replace it directly with that operand. + } else if (PHINode *PN = dyn_cast<PHINode>(Inst)) { + // If it's a PHI node and only has one operand + // Then replace it directly with that operand. assert(PN->getOperand(0) && "PHI Node must have at least one operan |