diff options
author | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:21 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-06-25 16:13:21 +0000 |
commit | 0b12b5f50ec77a8bd01b92d287c52d748619bb4b (patch) | |
tree | 5764db59facb124b023f1de96f0e45d37657c82e /lib | |
parent | 18961504fc2b299578dba817900a0696cf3ccc4d (diff) | |
download | external_llvm-0b12b5f50ec77a8bd01b92d287c52d748619bb4b.zip external_llvm-0b12b5f50ec77a8bd01b92d287c52d748619bb4b.tar.gz external_llvm-0b12b5f50ec77a8bd01b92d287c52d748619bb4b.tar.bz2 |
MEGAPATCH checkin.
For details, See: docs/2002-06-25-MegaPatchInfo.txt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
24 files changed, 634 insertions, 705 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index c4ab67f..f84ad56 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -18,7 +18,6 @@ #include "llvm/Constants.h" #include "llvm/iPHINode.h" #include "llvm/iOther.h" -#include "llvm/Argument.h" #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> @@ -312,7 +311,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, delete M; return failure(true); // Parse error... :( } - M->getBasicBlocks().push_back(BB); + M->getBasicBlockList().push_back(BB); break; } @@ -368,7 +367,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, // If the method is empty, we don't need the method argument entries... if (M->isExternal()) - M->getArgumentList().delete_all(); + M->getArgumentList().clear(); DeclareNewGlobalValue(M, MethSlot); diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp index 227980a..36414be 100644 --- a/lib/Bytecode/Writer/InstructionWriter.cpp +++ b/lib/Bytecode/Writer/InstructionWriter.cpp @@ -169,15 +169,15 @@ static void outputInstructionFormat3(const Instruction *I, output(Bits, Out); } -void BytecodeWriter::processInstruction(const Instruction *I) { - assert(I->getOpcode() < 64 && "Opcode too big???"); +void BytecodeWriter::processInstruction(const Instruction &I) { + assert(I.getOpcode() < 64 && "Opcode too big???"); - unsigned NumOperands = I->getNumOperands(); + unsigned NumOperands = I.getNumOperands(); int MaxOpSlot = 0; int Slots[3]; Slots[0] = (1 << 12)-1; // Marker to signify 0 operands for (unsigned i = 0; i < NumOperands; ++i) { - const Value *Def = I->getOperand(i); + const Value *Def = I.getOperand(i); int slot = Table.getValSlot(Def); assert(slot != -1 && "Broken bytecode!"); if (slot > MaxOpSlot) MaxOpSlot = slot; @@ -191,17 +191,17 @@ void BytecodeWriter::processInstruction(const Instruction *I) { // we take the type of the instruction itself. // const Type *Ty; - switch (I->getOpcode()) { + switch (I.getOpcode()) { case Instruction::Malloc: case Instruction::Alloca: - Ty = I->getType(); // Malloc & Alloca ALWAYS want to encode the return type + Ty = I.getType(); // Malloc & Alloca ALWAYS want to encode the return type break; case Instruction::Store: - Ty = I->getOperand(1)->getType(); // Encode the pointer type... + Ty = I.getOperand(1)->getType(); // Encode the pointer type... assert(isa<PointerType>(Ty) && "Store to nonpointer type!?!?"); break; default: // Otherwise use the default behavior... - Ty = NumOperands ? I->getOperand(0)->getType() : I->getType(); + Ty = NumOperands ? I.getOperand(0)->getType() : I.getType(); break; } @@ -219,20 +219,20 @@ void BytecodeWriter::processInstruction(const Instruction *I) { if (isa<CastInst>(I)) { // Cast has to encode the destination type as the second argument in the // packet, or else we won't know what type to cast to! - Slots[1] = Table.getValSlot(I->getType()); + Slots[1] = Table.getValSlot(I.getType()); assert(Slots[1] != -1 && "Cast return type unknown?"); if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1]; NumOperands++; - } else if (const CallInst *CI = dyn_cast<CallInst>(I)) {// Handle VarArg calls + } else if (const CallInst *CI = dyn_cast<CallInst>(&I)){// Handle VarArg calls const PointerType *Ty = cast<PointerType>(CI->getCalledValue()->getType()); if (cast<FunctionType>(Ty->getElementType())->isVarArg()) { - outputInstrVarArgsCall(I, Table, Type, Out); + outputInstrVarArgsCall(CI, Table, Type, Out); return; } - } else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) { // ... & Invokes + } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {// ... & Invokes const PointerType *Ty = cast<PointerType>(II->getCalledValue()->getType()); if (cast<FunctionType>(Ty->getElementType())->isVarArg()) { - outputInstrVarArgsCall(I, Table, Type, Out); + outputInstrVarArgsCall(II, Table, Type, Out); return; } } @@ -246,21 +246,21 @@ void BytecodeWriter::processInstruction(const Instruction *I) { case 0: case 1: if (MaxOpSlot < (1 << 12)-1) { // -1 because we use 4095 to indicate 0 ops - outputInstructionFormat1(I, Table, Slots, Type, Out); + outputInstructionFormat1(&I, Table, Slots, Type, Out); return; } break; case 2: if (MaxOpSlot < (1 << 8)) { - outputInstructionFormat2(I, Table, Slots, Type, Out); + outputInstructionFormat2(&I, Table, Slots, Type, Out); return; } break; case 3: if (MaxOpSlot < (1 << 6)) { - outputInstructionFormat3(I, Table, Slots, Type, Out); + outputInstructionFormat3(&I, Table, Slots, Type, Out); return; } break; @@ -268,5 +268,5 @@ void BytecodeWriter::processInstruction(const Instruction *I) { // If we weren't handled before here, we either have a large number of // operands or a large operand index that we are refering to. - outputInstructionFormat0(I, Table, Type, Out); + outputInstructionFormat0(&I, Table, Type, Out); } diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 145004b..5545834 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -21,9 +21,6 @@ #include "WriterInternals.h" #include "llvm/Module.h" -#include "llvm/GlobalVariable.h" -#include "llvm/Function.h" -#include "llvm/BasicBlock.h" #include "llvm/SymbolTable.h" #include "llvm/DerivedTypes.h" #include "Support/STLExtras.h" @@ -49,8 +46,8 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M) outputModuleInfoBlock(M); // Do the whole module now! Process each function at a time... - for_each(M->begin(), M->end(), - bind_obj(this, &BytecodeWriter::processMethod)); + for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) + processMethod(I); // If needed, output the symbol table for the module... if (M->hasSymbolTable()) @@ -112,19 +109,18 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { // Output the types for the global variables in the module... for (Module::const_giterator I = M->gbegin(), End = M->gend(); I != End;++I) { - const GlobalVariable *GV = *I; - int Slot = Table.getValSlot(GV->getType()); + int Slot = Table.getValSlot(I->getType()); assert(Slot != -1 && "Module global vars is broken!"); // Fields: bit0 = isConstant, bit1 = hasInitializer, bit2=InternalLinkage, // bit3+ = slot# - unsigned oSlot = ((unsigned)Slot << 3) | (GV->hasInternalLinkage() << 2) | - (GV->hasInitializer() << 1) | GV->isConstant(); + unsigned oSlot = ((unsigned)Slot << 3) | (I->hasInternalLinkage() << 2) | + (I->hasInitializer() << 1) | I->isConstant(); output_vbr(oSlot, Out); // If we have an initializer, output it now. - if (GV->hasInitializer()) { - Slot = Table.getValSlot((Value*)GV->getInitializer()); + if (I->hasInitializer()) { + Slot = Table.getValSlot((Value*)I->getInitializer()); assert(Slot != -1 && "No slot for global var initializer!"); output_vbr((unsigned)Slot, Out); } @@ -133,7 +129,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { // Output the types of the functions in this module... for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) { - int Slot = Table.getValSlot((*I)->getType()); + int Slot = Table.getValSlot(I->getType()); assert(Slot != -1 && "Module const pool is broken!"); assert(Slot >= Type::FirstDerivedTyID && "Derived type not in range!"); output_vbr((unsigned)Slot, Out); @@ -144,36 +140,36 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { align32(Out); } -void BytecodeWriter::processMethod(const Function *M) { +void BytecodeWriter::processMethod(const Function *F) { BytecodeBlock FunctionBlock(BytecodeFormat::Function, Out); - output_vbr((unsigned)M->hasInternalLinkage(), Out); + output_vbr((unsigned)F->hasInternalLinkage(), Out); // Only output the constant pool and other goodies if needed... - if (!M->isExternal()) { + if (!F->isExternal()) { // Get slot information about the function... - Table.incorporateFunction(M); + Table.incorporateFunction(F); // Output information about the constants in the function... outputConstants(true); // Output basic block nodes... - for_each(M->begin(), M->end(), - bind_obj(this, &BytecodeWriter::processBasicBlock)); + for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I) + processBasicBlock(*I); // If needed, output the symbol table for the function... - if (M->hasSymbolTable()) - outputSymbolTable(*M->getSymbolTable()); + if (F->hasSymbolTable()) + outputSymbolTable(*F->getSymbolTable()); Table.purgeFunction(); } } -void BytecodeWriter::processBasicBlock(const BasicBlock *BB) { +void BytecodeWriter::processBasicBlock(const BasicBlock &BB) { BytecodeBlock FunctionBlock(BytecodeFormat::BasicBlock, Out); // Process all the instructions in the bb... - for_each(BB->begin(), BB->end(), - bind_obj(this, &BytecodeWriter::processInstruction)); + for(BasicBlock::const_iterator I = BB.begin(), E = BB.end(); I != E; ++I) + processInstruction(*I); } void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) { diff --git a/lib/Bytecode/Writer/WriterInternals.h b/lib/Bytecode/Writer/WriterInternals.h index bd4a328..7b54a56 100644 --- a/lib/Bytecode/Writer/WriterInternals.h +++ b/lib/Bytecode/Writer/WriterInternals.h @@ -27,8 +27,8 @@ public: protected: void outputConstants(bool isMethod); void processMethod(const Function *F); - void processBasicBlock(const BasicBlock *BB); - void processInstruction(const Instruction *I); + void processBasicBlock(const BasicBlock &BB); + void processInstruction(const Instruction &I); private : inline void outputSignature() { diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp index 4a08c24..a95f1e3 100644 --- a/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/lib/CodeGen/InstrSelection/InstrForest.cpp @@ -25,7 +25,6 @@ #include "llvm/iTerminators.h" #include "llvm/iMemory.h" #include "llvm/Constant.h" -#include "llvm/BasicBlock.h" #include "llvm/Type.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/STLExtras.h" @@ -188,10 +187,9 @@ LabelNode::dumpNode(int indent) const InstrForest::InstrForest(Function *F) { - for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) { - BasicBlock *BB = *FI; - for_each(BB->begin(), BB->end(), - bind_obj(this, &InstrForest::buildTreeForInstruction)); + for (Function::iterator BB = F->begin(), FE = F->end(); BB != FE; ++BB) { + for(BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) + buildTreeForInstruction(I); } } diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp index 614c5f6..b27f902 100644 --- a/lib/CodeGen/InstrSelection/InstrSelection.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp @@ -123,14 +123,10 @@ SelectInstructionsForMethod(Function *F, TargetMachine &target) // Record instructions in the vector for each basic block // for (Function::iterator BI = F->begin(), BE = F->end(); BI != BE; ++BI) - { - MachineCodeForBasicBlock& bbMvec = (*BI)->getMachineInstrVec(); - for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) - { - MachineCodeForInstruction &mvec =MachineCodeForInstruction::get(*II); - for (unsigned i=0; i < mvec.size(); i++) - bbMvec.push_back(mvec[i]); - } + for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) { + MachineCodeForInstruction &mvec =MachineCodeForInstruction::get(II); + for (unsigned i=0; i < mvec.size(); i++) + BI->getMachineInstrVec().push_back(mvec[i]); } // Insert phi elimination code -- added by Ruchira @@ -191,49 +187,38 @@ InsertCode4AllPhisInMeth(Function *F, TargetMachine &target) { // for all basic blocks in function // - for (Function::iterator BI = F->begin(); BI != F->end(); ++BI) { - - BasicBlock *BB = *BI; - const BasicBlock::InstListType &InstList = BB->getInstList(); - BasicBlock::InstListType::const_iterator IIt = InstList.begin(); - - // for all instructions in the basic block - // - for( ; IIt != InstList.end(); ++IIt ) { - - if (PHINode *PN = dyn_cast<PHINode>(*IIt)) { - // FIXME: This is probably wrong... - Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:"); - - // for each incoming value of the phi, insert phi elimination - // - for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) - { // insert the copy instruction to the predecessor BB - vector<MachineInstr*> mvec, CpVec; - target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, - mvec); - for (vector<MachineInstr*>::iterator MI=mvec.begin(); - MI != mvec.end(); ++MI) - { - vector<MachineInstr*> CpVec2 = - FixConstantOperandsForInstr(PN, *MI, target); - CpVec2.push_back(*MI); - CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end()); - } - - InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); - } + for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) { + BasicBlock::InstListType &InstList = BB->getInstList(); + for (BasicBlock::iterator IIt = InstList.begin(); + PHINode *PN = dyn_cast<PHINode>(&*IIt); ++IIt) { + // FIXME: This is probably wrong... + Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:"); - vector<MachineInstr*> mvec; - target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec); + // for each incoming value of the phi, insert phi elimination + // + for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { + // insert the copy instruction to the predecessor BB + vector<MachineInstr*> mvec, CpVec; + target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, + mvec); + for (vector<MachineInstr*>::iterator MI=mvec.begin(); + MI != mvec.end(); ++MI) { + vector<MachineInstr*> CpVec2 = + FixConstantOperandsForInstr(PN, *MI, target); + CpVec2.push_back(*MI); + CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end()); + } - // get an iterator to machine instructions in the BB - MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); - - bbMvec.insert( bbMvec.begin(), mvec.begin(), mvec.end()); + InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); } - else break; // since PHI nodes can only be at the top + vector<MachineInstr*> mvec; + target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec); + + // get an iterator to machine instructions in the BB + MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); + + bbMvec.insert(bbMvec.begin(), mvec.begin(), mvec.end()); } // for each Phi Instr in BB } // for all BBs in function } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 06e0666..4d50f89 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -60,43 +60,40 @@ ComputeMaxOptionalArgsSize(const TargetMachine& target, const Function *F, { const MachineFrameInfo& frameInfo = target.getFrameInfo(); - unsigned int maxSize = 0; + unsigned maxSize = 0; - for (Function::const_iterator MI = F->begin(), ME = F->end(); MI != ME; ++MI) - { - const BasicBlock *BB = *MI; - for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) - if (CallInst *callInst = dyn_cast<CallInst>(*I)) - { - unsigned int numOperands = callInst->getNumOperands() - 1; - int numExtra =(int)numOperands-frameInfo.getNumFixedOutgoingArgs(); - if (numExtra <= 0) - continue; - - unsigned int sizeForThisCall; - if (frameInfo.argsOnStackHaveFixedSize()) - { - int argSize = frameInfo.getSizeOfEachArgOnStack(); - sizeForThisCall = numExtra * (unsigned) argSize; - } - else - { - assert(0 && "UNTESTED CODE: Size per stack argument is not " - "fixed on this architecture: use actual arg sizes to " - "compute MaxOptionalArgsSize"); - sizeForThisCall = 0; - for (unsigned i=0; i < numOperands; ++i) - sizeForThisCall += target.findOptimalStorageSize(callInst-> - getOperand(i)->getType()); - } - - if (maxSize < sizeForThisCall) - maxSize = sizeForThisCall; - - if (((int) maxOptionalNumArgs) < numExtra) - maxOptionalNumArgs = (unsigned) numExtra; - } - } + for (Function::const_iterator BB = F->begin(), BBE = F->end(); BB !=BBE; ++BB) + for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) + if (const CallInst *callInst = dyn_cast<CallInst>(&*I)) + { + unsigned numOperands = callInst->getNumOperands() - 1; + int numExtra = (int)numOperands-frameInfo.getNumFixedOutgoingArgs(); + if (numExtra <= 0) + continue; + + unsigned int sizeForThisCall; + if (frameInfo.argsOnStackHaveFixedSize()) + { + int argSize = frameInfo.getSizeOfEachArgOnStack(); + sizeForThisCall = numExtra * (unsigned) argSize; + } + else + { + assert(0 && "UNTESTED CODE: Size per stack argument is not " + "fixed on this architecture: use actual arg sizes to " + "compute MaxOptionalArgsSize"); + sizeForThisCall = 0; + for (unsigned i = 0; i < numOperands; ++i) + sizeForThisCall += target.findOptimalStorageSize(callInst-> + getOperand(i)->getType()); + } + + if (maxSize < sizeForThisCall) + maxSize = sizeForThisCall; + + if ((int)maxOptionalNumArgs < numExtra) + maxOptionalNumArgs = (unsigned) numExtra; + } return maxSize; } @@ -278,12 +275,11 @@ MachineCodeForMethod::dump() const std::cerr << "\n" << method->getReturnType() << " \"" << method->getName() << "\"\n"; - for (Function::const_iterator BI = method->begin(); BI != method->end(); ++BI) + for (Function::const_iterator BB = method->begin(); BB != method->end(); ++BB) { - BasicBlock* bb = *BI; - std::cerr << "\n" << bb->getName() << " (" << bb << ")" << ":\n"; + std::cerr << "\n" << BB->getName() << " (" << *BB << ")" << ":\n"; - MachineCodeForBasicBlock& mvec = bb->getMachineInstrVec(); + MachineCodeForBasicBlock& mvec = BB->getMachineInstrVec(); for (unsigned i=0; i < mvec.size(); i++) std::cerr << "\t" << *mvec[i]; } diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 8ba4115..07ad800 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -168,7 +168,7 @@ void Interpreter::initializeExecutionEngine() { // InitializeMemory - Recursive function to apply a Constant value into the // specified memory location... // -static void InitializeMemory(Constant *Init, char *Addr) { +static void InitializeMemory(const Constant *Init, char *Addr) { #define INITIALIZE_MEMORY(TYID, CLASS, TY) \ case Type::TYID##TyID: { \ TY Tmp = cast<CLASS>(Init)->getValue(); \ @@ -190,7 +190,7 @@ static void InitializeMemory(Constant *Init, char *Addr) { #undef INITIALIZE_MEMORY case Type::ArrayTyID: { - ConstantArray *CPA = cast<ConstantArray>(Init); + const ConstantArray *CPA = cast<ConstantArray>(Init); const vector<Use> &Val = CPA->getValues(); unsigned ElementSize = TD.getTypeSize(cast<ArrayType>(CPA->getType())->getElementType()); @@ -200,7 +200,7 @@ static void InitializeMemory(Constant *Init, char *Addr) { } case Type::StructTyID: { - ConstantStruct *CPS = cast<ConstantStruct>(Init); + const ConstantStruct *CPS = cast<ConstantStruct>(Init); const StructLayout *SL=TD.getStructLayout(cast<StructType>(CPS->getType())); const vector<Use> &Val = CPS->getValues(); for (unsigned i = 0; i < Val.size(); ++i) @@ -212,7 +212,8 @@ static void InitializeMemory(Constant *Init, char *Addr) { case Type::PointerTyID: if (isa<ConstantPointerNull>(Init)) { *(void**)Addr = 0; - } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Init)) { + } else if (const ConstantPointerRef *CPR = + dyn_cast<ConstantPointerRef>(Init)) { GlobalAddress *Address = (GlobalAddress*)CPR->getValue()->getOrCreateAnnotation(GlobalAddressAID); *(void**)Addr = (GenericValue*)Address->Ptr; @@ -266,9 +267,9 @@ Annotation *GlobalAddress::Create(AnnotationID AID, const Annotable *O, void *){ #define IMPLEMENT_UNARY_OPERATOR(OP, TY) \ case Type::TY##TyID: Dest.TY##Val = OP Src.TY##Val; break -static void executeNotInst(UnaryOperator *I, ExecutionContext &SF) { - const Type *Ty = I->getOperand(0)->getType(); - GenericValue Src = getOperandValue(I->getOperand(0), SF); +static void executeNotInst(UnaryOperator &I, ExecutionContext &SF) { + const Type *Ty = I.getOperand(0)->getType(); + GenericValue Src = getOperandValue(I.getOperand(0), SF); GenericValue Dest; switch (Ty->getPrimitiveID()) { IMPLEMENT_UNARY_OPERATOR(~, UByte); @@ -283,7 +284,7 @@ static void executeNotInst(UnaryOperator *I, ExecutionContext &SF) { default: cout << "Unhandled type for Not instruction: " << Ty << "\n"; } - SetValue(I, Dest, SF); + SetValue(&I, Dest, SF); } //===----------------------------------------------------------------------===// @@ -592,13 +593,13 @@ static GenericValue executeSetGTInst(GenericValue Src1, GenericValue Src2, return Dest; } -static void executeBinaryInst(BinaryOperator *I, ExecutionContext &SF) { - const Type *Ty = I->getOperand(0)->getType(); - GenericValue Src1 = getOperandValue(I->getOperand(0), SF); - GenericValue Src2 = getOperandValue(I->getOperand(1), SF); +static void executeBinaryInst(BinaryOperator &I, ExecutionContext &SF) { + const Type *Ty = I.getOperand(0)->getType(); + GenericValue Src1 = getOperandValue(I.getOperand(0), SF); + GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue R; // Result - switch (I->getOpcode()) { + switch (I.getOpcode()) { case Instruction::Add: R = executeAddInst (Src1, Src2, Ty, SF); break; case Instruction::Sub: R = executeSubInst (Src1, Src2, Ty, SF); break; case Instruction::Mul: R = executeMulInst (Src1, Src2, Ty, SF); break; @@ -618,7 +619,7 @@ static void executeBinaryInst(BinaryOperator *I, ExecutionContext &SF) { R = Src1; } - SetValue(I, R, SF); + SetValue(&I, R, SF); } //===----------------------------------------------------------------------===// @@ -683,14 +684,14 @@ void Interpreter::exitCalled(GenericValue GV) { PerformExitStuff(); } -void Interpreter::executeRetInst(ReturnInst *I, ExecutionContext &SF) { +void Interpreter::executeRetInst(ReturnInst &I, ExecutionContext &SF) { const Type *RetTy = 0; GenericValue Result; // Save away the return value... (if we are not 'ret void') - if (I->getNumOperands()) { - RetTy = I->getReturnValue()->getType(); - Result = getOperandValue(I->getReturnValue(), SF); + if (I.getNumOperands()) { + RetTy = I.getReturnValue()->getType(); + Result = getOperandValue(I.getReturnValue(), SF); } // Save previously executing meth @@ -737,16 +738,16 @@ void Interpreter::executeRetInst(ReturnInst *I, ExecutionContext &SF) { } } -void Interpreter::executeBrInst(BranchInst *I, ExecutionContext &SF) { +void Interpreter::executeBrInst(BranchInst &I, ExecutionContext &SF) { SF.PrevBB = SF.CurBB; // Update PrevBB so that PHI nodes work... BasicBlock *Dest; - Dest = I->getSuccessor(0); // Uncond branches have a fixed dest... - if (!I->isUnconditional()) { - Value *Cond = I->getCondition(); + Dest = I.getSuccessor(0); // Uncond branches have a fixed dest... + if (!I.isUnconditional()) { + Value *Cond = I.getCondition(); GenericValue CondVal = getOperandValue(Cond, SF); if (CondVal.BoolVal == 0) // If false cond... - Dest = I->getSuccessor(1); + Dest = I.getSuccessor(1); } SF.CurBB = Dest; // Update CurBB to branch destination SF.CurInst = SF.CurBB->begin(); // Update new instruction ptr... @@ -756,11 +757,11 @@ void Interpreter::executeBrInst(BranchInst *I, ExecutionContext &SF) { // Memory Instruction Implementations //===----------------------------------------------------------------------===// -void Interpreter::executeAllocInst(AllocationInst *I, ExecutionContext &SF) { - const Type *Ty = I->getType()->getElementType(); // Type to be allocated +void Interpreter::executeAllocInst(AllocationInst &I, ExecutionContext &SF) { + const Type *Ty = I.getType()->getElementType(); // Type to be allocated // Get the number of elements being allocated by the array... - unsigned NumElements = getOperandValue(I->getOperand(0), SF).UIntVal; + unsigned NumElements = getOperandValue(I.getOperand(0), SF).UIntVal; // Allocate enough memory to hold the type... // FIXME: Don't use CALLOC, use a tainted malloc. @@ -769,15 +770,15 @@ void Interpreter::executeAllocInst(AllocationInst *I, ExecutionContext &SF) { GenericValue Result; Result.PointerVal = (PointerTy)Memory; assert(Result.PointerVal != 0 && "Null pointer returned by malloc!"); - SetValue(I, Result, SF); + SetValue(&I, Result, SF); - if (I->getOpcode() == Instruction::Alloca) + if (I.getOpcode() == Instruction::Alloca) ECStack.back().Allocas.add(Memory); } -static void executeFreeInst(FreeInst *I, ExecutionContext &SF) { - assert(isa<PointerType>(I->getOperand(0)->getType()) && "Freeing nonptr?"); - GenericValue Value = getOperandValue(I->getOperand(0), SF); +static void executeFreeInst(FreeInst &I, ExecutionContext &SF) { + assert(isa<PointerType>(I.getOperand(0)->getType()) && "Freeing nonptr?"); + GenericValue Value = getOperandValue(I.getOperand(0), SF); // TODO: Check to make sure memory is allocated free((void*)Value.PointerVal); // Free memory } @@ -787,20 +788,20 @@ static void executeFreeInst(FreeInst *I, ExecutionContext &SF) { // function returns the offset that arguments ArgOff+1 -> NumArgs specify for // the pointer type specified by argument Arg. // -static PointerTy getElementOffset(MemAccessInst *I, ExecutionContext &SF) { - assert(isa<PointerType>(I->getPointerOperand()->getType()) && +static PointerTy getElementOffset(MemAccessInst &I, ExecutionContext &SF) { + assert(isa<PointerType>(I.getPointerOperand()->getType()) && "Cannot getElementOffset of a nonpointer type!"); PointerTy Total = 0; - const Type *Ty = I->getPointerOperand()->getType(); + const Type *Ty = I.getPointerOperand()->getType(); - unsigned ArgOff = I->getFirstIndexOperandNumber(); - while (ArgOff < I->getNumOperands()) { + unsigned ArgOff = I.getFirstIndexOperandNumber(); + while (ArgOff < I.getNumOperands()) { if (const StructType *STy = dyn_cast<StructType>(Ty)) { const StructLayout *SLO = TD.getStructLayout(STy); // Indicies must be ubyte constants... - const ConstantUInt *CPU = cast<ConstantUInt>(I->getOperand(ArgOff++)); + const ConstantUInt *CPU = cast<ConstantUInt>(I.getOperand(ArgOff++)); assert(CPU->getType() == Type::UByteTy); unsigned Index = CPU->getValue(); @@ -818,13 +819,13 @@ static PointerTy getElementOffset(MemAccessInst *I, ExecutionContext &SF) { } else if (const SequentialType *ST = cast<SequentialType>(Ty)) { // Get the index number for the array... which must be uint type... - assert(I->getOperand(ArgOff)->getType() == Type::UIntTy); - unsigned Idx = getOperandValue(I->getOperand(ArgOff++), SF).UIntVal; + assert(I.getOperand(ArgOff)->getType() == Type::UIntTy); + unsigned Idx = getOperandValue(I.getOperand(ArgOff++), SF).UIntVal; if (const ArrayType *AT = dyn_cast<ArrayType>(ST)) if (Idx >= AT->getNumElements() && ArrayChecksEnabled) { cerr << "Out of range memory access to element #" << Idx << " of a " << AT->getNumElements() << " element array." - << " Subscript #" << (ArgOff-I->getFirstIndexOperandNumber()) + << " Subscript #" << (ArgOff-I.getFirstIndexOperandNumber()) << "\n"; // Get outta here!!! siglongjmp(SignalRecoverBuffer, SIGTRAP); @@ -839,17 +840,17 @@ static PointerTy getElementOffset(MemAccessInst *I, ExecutionContext &SF) { return Total; } -static void executeGEPInst(GetElementPtrInst *I, ExecutionContext &SF) { - GenericValue SRC = getOperandValue(I->getPointerOperand(), SF); +static void executeGEPInst(GetElementPtrInst &I, ExecutionContext &SF) { + GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); PointerTy SrcPtr = SRC.PointerVal; GenericValue Result; Result.PointerVal = SrcPtr + getElementOffset(I, SF); - SetValue(I, Result, SF); + SetValue(&I, Result, SF); } -static void executeLoadInst(LoadInst *I, ExecutionContext &SF) { - GenericValue SRC = getOperandValue(I->getPointerOperand(), SF); +static void executeLoadInst(LoadInst &I, ExecutionContext &SF) { + GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); PointerTy SrcPtr = SRC.PointerVal; PointerTy Offset = getElementOffset(I, SF); // Handle any structure indices SrcPtr += Offset; @@ -857,7 +858,7 @@ static void executeLoadInst(LoadInst *I, ExecutionContext &SF) { GenericValue *Ptr = (GenericValue*)SrcPtr; GenericValue Result; - switch (I->getType()->getPrimitiveID()) { + switch (I.getType()->getPrimitiveID()) { case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID: Result.SByteVal = Ptr->SByteVal; break; @@ -871,21 +872,21 @@ static void executeLoadInst(LoadInst *I, ExecutionContext &SF) { case Type::FloatTyID: Result.FloatVal = Ptr->FloatVal; break; case Type::DoubleTyID: Result.DoubleVal = Ptr->DoubleVal; break; default: - cout << "Cannot load value of type " << I->getType() << "!\n"; + cout << "Cannot load value of type " << I.getType() << "!\n"; } - SetValue(I, Result, SF); + SetValue(&I, Result, SF); } -static void executeStoreInst(StoreInst *I, ExecutionContext &SF) { - GenericValue SRC = getOperandValue(I->getPointerOperand(), SF); +static void executeStoreInst(StoreInst &I, ExecutionContext &SF) { + GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); PointerTy SrcPtr = SRC.PointerVal; SrcPtr += getElementOffset(I, SF); // Handle any structure indices GenericValue *Ptr = (GenericValue *)SrcPtr; - GenericValue Val = getOperandValue(I->getOperand(0), SF); + GenericValue Val = getOperandValue(I.getOperand(0), SF); - switch (I->getOperand(0)->getType()->getPrimitiveID()) { + switch (I.getOperand(0)->getType()->getPrimitiveID()) { case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID: Ptr->SByteVal = Val.SByteVal; break; @@ -899,7 +900,7 @@ static void executeStoreInst(StoreInst *I, ExecutionContext &SF) { case Type::FloatTyID: Ptr->FloatVal = Val.FloatVal; break; case Type::DoubleTyID: Ptr->DoubleVal = Val.DoubleVal; break; default: - cout << "Cannot store value of type " << I->getType() << "!\n"; + cout << "Cannot store value of type " << I.getType() << "!\n"; } } @@ -908,44 +909,44 @@ static void executeStoreInst(StoreInst *I, ExecutionContext &SF) { // Miscellaneous Instruction Implementations //===----------------------------------------------------------------------===// -void Interpreter::executeCallInst(CallInst *I, ExecutionContext &SF) { - ECStack.back().Caller = I; +void Interpreter::executeCallInst(CallInst &I, ExecutionContext &SF) { + ECStack.back().Caller = &I; vector<GenericValue> ArgVals; - ArgVals.reserve(I->getNumOperands()-1); - for (unsigned i = 1; i < I->getNumOperands(); ++i) - ArgVals.push_back(getOperandValue(I->getOperand(i), SF)); + ArgVals.reserve(I.getNumOperands()-1); + for (unsigned i = 1; i < I.getNumOperands(); ++i) + ArgVals.push_back(getOperandValue(I.getOperand(i), SF)); // To handle indirect calls, we must get the pointer value from the argument // and treat it as a function pointer. - GenericValue SRC = getOperandValue(I->getCalledValue(), SF); + GenericValue SRC = getOperandValue(I.getCalledValue(), SF); callMethod((Function*)SRC.PointerVal, ArgVals); } -static void executePHINode(PHINode *I, ExecutionContext &SF) { +static void executePHINode(PHINode &I, ExecutionContext &SF) { BasicBlock *PrevBB = SF.PrevBB; Value *IncomingValue = 0; // Search for the value corresponding to this previous bb... - for (unsigned i = I->getNumIncomingValues(); i > 0;) { - if (I->getIncomingBlock(--i) == PrevBB) { - IncomingValue = I->getIncomingValue(i); + for (unsigned i = I.getNumIncomingValues(); i > 0;) { + if (I.getIncomingBlock(--i) == PrevBB) { + IncomingValue = I.getIncomingValue(i); break; } } assert(IncomingValue && "No PHI node predecessor for current PrevBB!"); // Found the value, set as the result... - SetValue(I, getOperandValue(IncomingValue, SF), SF); + SetValue(&I, getOperandValue(IncomingValue, SF), SF); } #define IMPLEMENT_SHIFT(OP, TY) \ case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.UByteVal; break -static void executeShlInst(ShiftInst *I, ExecutionContext &SF) { - const Type *Ty = I->getOperand(0)->getType(); - GenericValue Src1 = getOperandValue(I->getOperand(0), SF); - GenericValue Src2 = getOperandValue(I->getOperand(1), SF); +static void executeShlInst(ShiftInst &I, ExecutionContext &SF) { + const Type *Ty = I.getOperand(0)->getType(); + GenericValue Src1 = getOperandValue(I.getOperand(0), SF); + GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue Dest; switch (Ty->getPrimitiveID()) { @@ -960,13 +961,13 @@ static void executeShlInst(ShiftInst *I, ExecutionContext &SF) { default: cout << "Unhandled type for Shl instruction: " << Ty << "\n"; } - SetValue(I, Dest, SF); + SetValue(&I, Dest, SF); } -static void executeShrInst(ShiftInst *I, ExecutionContext &SF) { - const Type *Ty = I->getOperand(0)->getType(); - GenericValue Src1 = getOperandValue(I->getOperand(0), SF); - GenericValue Src2 = getOperandValue(I->getOperand(1), SF); +static void executeShrInst(ShiftInst &I, ExecutionContext &SF) { + const Type *Ty = I.getOperand(0)->getType(); + GenericValue Src1 = getOperandValue(I.getOperand(0), SF); + GenericValue Src2 = getOperandValue(I.getOperand(1), SF); GenericValue Dest; switch (Ty->getPrimitiveID()) { @@ -981,7 +982,7 @@ static void executeShrInst(ShiftInst *I, ExecutionContext &SF) { default: cout << "Unhandled type for Shr instruction: " << Ty << "\n"; } - SetValue(I, Dest, SF); + SetValue(&I, Dest, SF); } #define IMPLEMENT_CAST(DTY, DCTY, STY) \ @@ -1016,10 +1017,10 @@ static void executeShrInst(ShiftInst *I, ExecutionContext &SF) { IMPLEMENT_CAST_CASE_FP_IMP(DESTTY, DESTCTY); \ IMPLEMENT_CAST_CASE_END() -static void executeCastInst(CastInst *I, ExecutionContext &SF) { - const Type *Ty = I->getType(); - const Type *SrcTy = I->getOperand(0)->getType(); - GenericValue Src = getOperandValue(I->getOperand(0), SF); +static void executeCastInst(CastInst &I, ExecutionContext &SF) { + const Type *Ty = I.getType(); + const Type *SrcTy = I.getOperand(0)->getType(); + GenericValue Src = getOperandValue(I.getOperand(0), SF); GenericValue Dest; switch (Ty->getPrimitiveID()) { @@ -1037,7 +1038,7 @@ static void executeCastInst(CastInst *I, ExecutionContext &SF) { default: cout << "Unhandled dest type for cast instruction: " << Ty << "\n"; } - SetValue(I, Dest, SF); + SetValue(&I, Dest, SF); } @@ -1047,22 +1048,17 @@ static void executeCastInst(CastInst *I, ExecutionContext &SF) { // Dispatch and Execution Code //===----------------------------------------------------------------------===// -MethodInfo::MethodInfo(Function *M) : Annotation(MethodInfoAID) { +MethodInfo::MethodInfo(Function *F) : Annotation(MethodInfoAID) { // Assign slot numbers to the function arguments... - const Function::ArgumentListType &ArgList = M->getArgumentList(); - for (Function::ArgumentListType::const_iterator AI = ArgList.begin(), - AE = ArgList.end(); AI != AE; ++AI) - ((Value*)(*AI))->addAnnotation(new SlotNumber(getValueSlot((Value*)*AI))); + for (Function::const_aiterator AI = F->abegin(), E = F->aend(); AI != E; ++AI) + AI->addAnnotation(new SlotNumber(getValueSlot(AI))); // Iterate over all of the instructions... unsigned InstNum = 0; - for (Function::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) { - BasicBlock *BB = *MI; - for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; ++II){ - Instruction *I = *II; // For each instruction... Add Annote - I->addAnnotation(new InstNumber(++InstNum, getValueSlot(I))); - } - } + for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB) + for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; ++II) + // For each instruction... Add Annote + II->addAnnotation(new InstNumber(++InstNum, getValueSlot(II))); } unsigned MethodInfo::getValueSlot(const Value *V) { @@ -1116,7 +1112,7 @@ void Interpreter::callMethod(Function *M, const vector<GenericValue> &ArgVals) { ExecutionContext &StackFrame = ECStack.back(); // Fill it in... StackFrame.CurMethod = M; - StackFrame.CurBB = M->front(); + StackFrame.CurBB = M->begin(); StackFrame.CurInst = StackFrame.CurBB->begin(); StackFrame.MethInfo = MethInfo; @@ -1134,13 +1130,11 @@ void Interpreter::callMethod(Function *M, const vector<GenericValue> &ArgVals) { // Run through the function arguments and initialize their values... - assert(ArgVals.size() == M->getArgumentList().size() && + assert(ArgVals.size() == M->asize() && "Invalid number of values passed to function invocation!"); unsigned i = 0; - for (Function::ArgumentListType::iterator AI = M->getArgumentList().begin(), - AE = M->getArgumentList().end(); AI != AE; ++AI, ++i) { - SetValue((Value*)*AI, ArgVals[i], StackFrame); - } + for (Function::aiterator AI = M->abegin(), E = M->aend(); AI != E; ++AI, ++i) + SetValue(AI, ArgVals[i], StackFrame); } // executeInstruction - Interpret a single instruction, increment the "PC", and @@ -1150,7 +1144,7 @@ bool Interpreter::executeInstruction() { assert(!ECStack.empty() && "No program running, cannot execute inst!"); ExecutionContext &SF = ECStack.back(); // Current stack frame - Instruction *I = *SF.CurInst++; // Increment before execute + Instruction &I = *SF.CurInst++; // Increment before execute if (Trace) CW << "Run:" << I; @@ -1175,17 +1169,17 @@ bool Interpreter::executeInstruction() { } InInstruction = true; - if (I->isBinaryOp()) { + if (I.isBinaryOp()) { executeBinaryInst(cast<BinaryOperator>(I), SF); } else { - switch (I->getOpcode()) { + switch (I.getOpcode()) { case Instruction::Not: executeNotInst(cast<UnaryOperator>(I),SF); break; // Terminators case Instruction::Ret: executeRetInst (cast<ReturnInst>(I), SF); break; case Instruction::Br: executeBrInst (cast<BranchInst>(I), SF); break; // Memory Instructions case Instruction::Alloca: - case Instruction::Malloc: executeAllocInst((AllocationInst*)I, SF); break; + case Instruction::Malloc: executeAllocInst((AllocationInst&)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; @@ -1210,7 +1204,7 @@ bool Interpreter::executeInstruction() { if (CurFrame == -1) return false; // No breakpoint if no code // Return true if there is a breakpoint annotation on the instruction... - return (*ECStack[CurFrame].CurInst)->getAnnotation(BreakpointAID) != 0; + return ECStack[CurFrame].CurInst->getAnnotation(BreakpointAID) != 0; } void Interpreter::stepInstruction() { // Do the 'step' command @@ -1235,7 +1229,7 @@ void Interpreter::nextInstruction() { // Do the 'next' command // If this is a call instruction, step over the call instruction... // TODO: ICALL, CALL WITH, ... - if ((*ECStack.back().CurInst)->getOpcode() == Instruction::Call) { + if (ECStack.back().CurInst->getOpcode() == Instruction::Call) { unsigned StackSize = ECStack.size(); // Step into the function... if (executeInstruction()) { @@ -1308,8 +1302,8 @@ void Interpreter::printCurrentInstruction() { if (ECStack.back().CurBB->begin() == ECStack.back().CurInst) // print label WriteAsOperand(cout, ECStack.back().CurBB) << ":\n"; - Instruction *I = *ECStack.back().CurInst; - InstNumber *IN = (InstNumber*)I->getAnnotation(SlotNumberAID); + Instruction &I = *ECStack.back().CurInst; + InstNumber *IN = (InstNumber*)I.getAnnotation(SlotNumberAID); assert(IN && "Instruction has no numbering annotation!"); cout << "#" << IN->InstNum << I; } @@ -1373,22 +1367,27 @@ void Interpreter::infoValue(const std::string &Name) { // void Interpreter::printStackFrame(int FrameNo = -1) { if (FrameNo == -1) FrameNo = CurFrame; - Function *Func = ECStack[FrameNo].CurMethod; - const Type *RetTy = Func->getReturnType(); + Function *F = ECStack[FrameNo].CurMethod; + const Type *RetTy = F->getReturnType(); CW << ((FrameNo == CurFrame) ? '>' : '-') << "#" << FrameNo << ". " - << (Value*)RetTy << " \"" << Func->getName() << "\"("; + << (Value*)RetTy << " \"" << F->getName() << "\"("; - Function::ArgumentListType &Args = Func->getArgumentList(); - for (unsigned i = 0; i < Args.size(); ++i) { + unsigned i = 0; + for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++i) { if (i != 0) cout << ", "; - CW << (Value*)Args[i] << "="; + CW << *I << "="; - printValue(((Value*)Args[i])->getType(), - getOperandValue((Value*)Args[i], ECStack[FrameNo])); + printValue(I->getType(), getOperandValue(I, ECStack[FrameNo])); } cout << ")\n"; - CW << *(ECStack[FrameNo].CurInst-(FrameNo != int(ECStack.size()-1))); + + if (FrameNo != int(ECStack.size()-1)) { + BasicBlock::iterator I = ECStack[FrameNo].CurInst; + CW << --I; + } else { + CW << *ECStack[FrameNo].CurInst; + } } diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index a16f317..6d1354c 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -135,7 +135,8 @@ GenericValue lle_X_printVal(FunctionType *M, const vector<GenericValue> &ArgVal) assert(ArgVal.size() == 1 && "generic print only takes one argument!"); // Specialize print([ubyte {x N} ] *) and print(sbyte *) - if (PointerType *PTy = dyn_cast<PointerType>(M->getParamTypes()[0].get())) + if (const PointerType *PTy = + dyn_cast<PointerType>(M->getParamTypes()[0].get())) if (PTy->getElementType() == Type::SByteTy || isa<ArrayType>(PTy->getElementType())) { return lle_VP_printstr(M, ArgVal); diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h index e7c7942..3ead31a 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.h +++ b/lib/ExecutionEngine/Interpreter/Interpreter.h @@ -144,10 +144,10 @@ public: void finish(); // Do the 'finish' command // Opcode Implementations - void executeCallInst(CallInst *I, ExecutionContext &SF); - void executeRetInst(ReturnInst *I, ExecutionContext &SF); - void executeBrInst(BranchInst *I, ExecutionContext &SF); - void executeAllocInst(AllocationInst *I, ExecutionContext &SF); + void executeCallInst(CallInst &I, ExecutionContext &SF); + void executeRetInst(ReturnInst &I, ExecutionContext &SF); + void executeBrInst(BranchInst &I, ExecutionContext &SF); + void executeAllocInst(AllocationInst &I, ExecutionContext &SF); GenericValue callExternalMethod(Function *F, const std::vector<GenericValue> &ArgVals); void exitCalled(GenericValue GV); diff --git a/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp b/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp index fdf8f3e..141361d1 100644 --- a/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp +++ b/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp @@ -61,13 +61,13 @@ namespace { const char *getPassName() const { return "Emit Bytecode to Sparc Assembly";} - virtual bool run(Module *M) { + virtual bool run(Module &M) { // Write bytecode out to the sparc assembly stream Out << "\n\n!LLVM BYTECODE OUTPUT\n\t.section \".rodata\"\n\t.align 8\n"; Out << "\t.global LLVMBytecode\n\t.type LLVMBytecode,#object\n"; Out << "LLVMBytecode:\n"; osparcasmstream OS(Out); - WriteBytecodeToFile(M, OS); + WriteBytecodeToFile(&M, OS); Out << ".end_LLVMBytecode:\n"; Out << "\t.size LLVMBytecode, .end_LLVMBytecode-LLVMBytecode\n\n"; diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp index 4a08c24..a95f1e3 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp @@ -25,7 +25,6 @@ #include "llvm/iTerminators.h" #include "llvm/iMemory.h" #include "llvm/Constant.h" -#include "llvm/BasicBlock.h" #include "llvm/Type.h" #include "llvm/CodeGen/MachineInstr.h" #include "Support/STLExtras.h" @@ -188,10 +187,9 @@ LabelNode::dumpNode(int indent) const InstrForest::InstrForest(Function *F) { - for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) { - BasicBlock *BB = *FI; - for_each(BB->begin(), BB->end(), - bind_obj(this, &InstrForest::buildTreeForInstruction)); + for (Function::iterator BB = F->begin(), FE = F->end(); BB != FE; ++BB) { + for(BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) + buildTreeForInstruction(I); } } diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp index 614c5f6..b27f902 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp @@ -123,14 +123,10 @@ SelectInstructionsForMethod(Function *F, TargetMachine &target) // Record instructions in the vector for each basic block // for (Function::iterator BI = F->begin(), BE = F->end(); BI != BE; ++BI) - { - MachineCodeForBasicBlock& bbMvec = (*BI)->getMachineInstrVec(); - for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) - { - MachineCodeForInstruction &mvec =MachineCodeForInstruction::get(*II); - for (unsigned i=0; i < mvec.size(); i++) - bbMvec.push_back(mvec[i]); - } + for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) { + MachineCodeForInstruction &mvec =MachineCodeForInstruction::get(II); + for (unsigned i=0; i < mvec.size(); i++) + BI->getMachineInstrVec().push_back(mvec[i]); } // Insert phi elimination code -- added by Ruchira @@ -191,49 +187,38 @@ InsertCode4AllPhisInMeth(Function *F, TargetMachine &target) { // for all basic blocks in function // - for (Function::iterator BI = F->begin(); BI != F->end(); ++BI) { - - BasicBlock *BB = *BI; - const BasicBlock::InstListType &InstList = BB->getInstList(); - BasicBlock::InstListType::const_iterator IIt = InstList.begin(); - - // for all instructions in the basic block - // - for( ; IIt != InstList.end(); ++IIt ) { - - if (PHINode *PN = dyn_cast<PHINode>(*IIt)) { - // FIXME: This is probably wrong... - Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:"); - - // for each incoming value of the phi, insert phi elimination - // - for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) - { // insert the copy instruction to the predecessor BB - vector<MachineInstr*> mvec, CpVec; - target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, - mvec); - for (vector<MachineInstr*>::iterator MI=mvec.begin(); - MI != mvec.end(); ++MI) - { - vector<MachineInstr*> CpVec2 = - FixConstantOperandsForInstr(PN, *MI, target); - CpVec2.push_back(*MI); - CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end()); - } - - InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); - } + for (Function::iterator BB = F->begin(); BB != F->end(); ++BB) { + BasicBlock::InstListType &InstList = BB->getInstList(); + for (BasicBlock::iterator IIt = InstList.begin(); + PHINode *PN = dyn_cast<PHINode>(&*IIt); ++IIt) { + // FIXME: This is probably wrong... + Value *PhiCpRes = new PHINode(PN->getType(), "PhiCp:"); - vector<MachineInstr*> mvec; - target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec); + // for each incoming value of the phi, insert phi elimination + // + for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { + // insert the copy instruction to the predecessor BB + vector<MachineInstr*> mvec, CpVec; + target.getRegInfo().cpValue2Value(PN->getIncomingValue(i), PhiCpRes, + mvec); + for (vector<MachineInstr*>::iterator MI=mvec.begin(); + MI != mvec.end(); ++MI) { + vector<MachineInstr*> CpVec2 = + FixConstantOperandsForInstr(PN, *MI, target); + CpVec2.push_back(*MI); + CpVec.insert(CpVec.end(), CpVec2.begin(), CpVec2.end()); + } - // get an iterator to machine instructions in the BB - MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); - - bbMvec.insert( bbMvec.begin(), mvec.begin(), mvec.end()); + InsertPhiElimInstructions(PN->getIncomingBlock(i), CpVec); } - else break; // since PHI nodes can only be at the top + vector<MachineInstr*> mvec; + target.getRegInfo().cpValue2Value(PhiCpRes, PN, mvec); + + // get an iterator to machine instructions in the BB + MachineCodeForBasicBlock& bbMvec = BB->getMachineInstrVec(); + + bbMvec.insert(bbMvec.begin(), mvec.begin(), mvec.end()); } // for each Phi Instr in BB } // for all BBs in function } diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index db5b6cd..b0eb21e 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp @@ -68,19 +68,19 @@ public: : idTable(0), toAsm(os), Target(T), CurSection(Unknown) {} // (start|end)(Module|Function) - Callback methods to be invoked by subclasses - void startModule(Module *M) { + void startModule(Module &M) { // Create the global id table if it does not already exist - idTable = (GlobalIdTable*) M->getAnnotation(GlobalIdTable::AnnotId); + idTable = (GlobalIdTable*)M.getAnnotation(GlobalIdTable::AnnotId); if (idTable == NULL) { - idTable = new GlobalIdTable(M); - M->addAnnotation(idTable); + idTable = new GlobalIdTable(&M); + M.addAnnotation(idTable); } } - void startFunction(Function *F) { + void startFunction(Function &F) { // Make sure the slot table has information about this function... - idTable->Table.incorporateFunction(F); + idTable->Table.incorporateFunction(&F); } - void endFunction(Function *F) { + void endFunction(Function &) { idTable->Table.purgeFunction(); // Forget all about F } void endModule() { @@ -194,19 +194,19 @@ struct SparcFunctionAsmPrinter : public FunctionPass, public AsmPrinter { return "Output Sparc Assembly for Functions"; } - virtual bool doInitialization(Module *M) { + virtual bool doInitialization(Module &M) { startModule(M); return false; } - virtual bool runOnFunction(Function *F) { + virtual bool runOnFunction(Function &F) { startFunction(F); emitFunction(F); endFunction(F); return false; } - virtual bool doFinalization(Module *M) { + virtual bool doFinalization(Module &M) { endModule(); return false; } @@ -215,7 +215,7 @@ struct SparcFunctionAsmPrinter : public FunctionPass, public AsmPrinter { AU.setPreservesAll(); } - void emitFunction(const Function *F); + void emitFunction(const Function &F); private : void emitBasicBlock(const BasicBlock *BB); void emitMachineInst(const MachineInstr *MI); @@ -385,9 +385,9 @@ SparcFunctionAsmPrinter::emitBasicBlock(const BasicBlock *BB) } void -SparcFunctionAsmPrinter::emitFunction(const Function *M) +SparcFunctionAsmPrinter::emitFunction(const Function &F) { - string methName = getID(M); + string methName = getID(&F); toAsm << "!****** Outputing Function: " << methName << " ******\n"; enterSection(AsmPrinter::Text); toAsm << "\t.align\t4\n\t.global\t" << methName << "\n"; @@ -396,8 +396,8 @@ SparcFunctionAsmPrinter::emitFunction(const Function *M) toAsm << methName << ":\n"; // Output code for all of the basic blocks in the function... - for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I) - emitBasicBlock(*I); + for (Function::const_iterator I = F.begin(), E = F.end(); I != E; ++I) + emitBasicBlock(I); // Output a .size directive so the debugger knows the extents of the function toAsm << ".EndOf_" << methName << ":\n\t.size " @@ -431,7 +431,7 @@ public: const char *getPassName() const { return "Output Sparc Assembly for Module"; } - virtual bool run(Module *M) { + virtual bool run(Module &M) { startModule(M); emitGlobalsAndConstants(M); endModule(); @@ -443,14 +443,14 @@ public: } private: - void emitGlobalsAndConstants(const Module *M); + void emitGlobalsAndConstants(const Module &M); void printGlobalVariable(const GlobalVariable *GV); void printSingleConstant( const Constant* CV); void printConstantValueOnly(const Constant* CV); void printConstant( const Constant* CV, std::string valID = ""); - static void FoldConstants(const Module *M, + static void FoldConstants(const Module &M, std::hash_set<const Constant*> &moduleConstants); }; @@ -716,12 +716,12 @@ SparcModuleAsmPrinter::printConstant(const Constant* CV, string valID) } -void SparcModuleAsmPrinter::FoldConstants(const Module *M, +void SparcModuleAsmPrinter::FoldConstants(const Module &M, std::hash_set<const Constant*> &MC) { - for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) - if (!(*I)->isExternal()) { + for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) + if (!I->isExternal()) { const std::hash_set<const Constant*> &pool = - MachineCodeForMethod::get(*I).getConstantPoolValues(); + MachineCodeForMethod::get(I).getConstantPoolValues(); MC.insert(pool.begin(), pool.end()); } } @@ -743,7 +743,7 @@ void SparcModuleAsmPrinter::printGlobalVariable(const GlobalVariable* GV) } -void SparcModuleAsmPrinter::emitGlobalsAndConstants(const Module *M) { +void SparcModuleAsmPrinter::emitGlobalsAndConstants(const Module &M) { // First, get the constants there were marked by the code generator for // inclusion in the assembly code data area and fold them all into a // single constant pool since there may be lots of duplicates. Also, @@ -758,9 +758,9 @@ void SparcModuleAsmPrinter::emitGlobalsAndConstants(const Module *M) { // Section 1 : Read-only data section (implies initialized) enterSection(AsmPrinter::ReadOnlyData); - for (Module::const_giterator GI=M->gbegin(), GE=M->gend(); GI != GE; ++GI) - if ((*GI)->hasInitializer() && (*GI)->isConstant()) - printGlobalVariable(*GI); + for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) + if (GI->hasInitializer() && GI->isConstant()) + printGlobalVariable(GI); for (std::hash_set<const Constant*>::const_iterator I = moduleConstants.begin(), @@ -769,15 +769,15 @@ void SparcModuleAsmPrinter::emitGlobalsAndConstants(const Module *M) { // Section 2 : Initialized read-write data section enterSection(AsmPrinter::InitRWData); - for (Module::const_giterator GI=M->gbegin(), GE=M->gend(); GI != GE; ++GI) - if ((*GI)->hasInitializer() && ! (*GI)->isConstant()) - printGlobalVariable(*GI); + for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) + if (GI->hasInitializer() && !GI->isConstant()) + printGlobalVariable(GI); // Section 3 : Uninitialized read-write data section enterSection(AsmPrinter::UninitRWData); - for (Module::const_giterator GI=M->gbegin(), GE=M->gend(); GI != GE; ++GI) - if (! (*GI)->hasInitializer()) - printGlobalVariable(*GI); + for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI) + if (!GI->hasInitializer()) + printGlobalVariable(GI); toAsm << "\n"; } diff --git a/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp b/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp index b42e777..7243149 100644 --- a/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp +++ b/lib/Target/SparcV9/SparcV9PrologEpilogInserter.cpp @@ -20,26 +20,25 @@ #include "llvm/Instruction.h" namespace { - -class InsertPrologEpilogCode : public FunctionPass { - TargetMachine &Target; -public: - InsertPrologEpilogCode(TargetMachine &T) : Target(T) {} - - const char *getPassName() const { return "Sparc Prolog/Epilog Inserter"; } - - bool runOnFunction(Function *F) { - MachineCodeForMethod &mcodeInfo = MachineCodeForMethod::get(F); - if (!mcodeInfo.isCompiledAsLeafMethod()) { - InsertPrologCode(F); - InsertEpilogCode(F); + class InsertPrologEpilogCode : public FunctionPass { + TargetMachine &Target; + public: + InsertPrologEpilogCode(TargetMachine &T) : Target(T) {} + + const char *getPassName() const { return "Sparc Prolog/Epilog Inserter"; } + + bool runOnFunction(Function &F) { + MachineCodeForMethod &mcodeInfo = MachineCodeForMethod::get(&F); + if (!mcodeInfo.isCompiledAsLeafMethod()) { + InsertPrologCode(F); + InsertEpilogCode(F); + } + return false; } - return false; - } - - void InsertPrologCode(Function *F); - void InsertEpilogCode(Function *F); -}; + + void InsertPrologCode(Function &F); + void InsertEpilogCode(Function &F); + }; } // End anonymous namespace @@ -51,10 +50,8 @@ public: // Create prolog and epilog code for procedure entry and exit //------------------------------------------------------------------------ -void InsertPrologEpilogCode::InsertPrologCode(Function *F) +void InsertPrologEpilogCode::InsertPrologCode(Function &F) { - BasicBlock *entryBB = F->getEntryNode(); - vector<MachineInstr*> mvec; MachineInstr* M; const MachineFrameInfo& frameInfo = Target.getFrameInfo(); @@ -64,7 +61,7 @@ void InsertPrologEpilogCode::InsertPrologCode(Function *F) // We will assume that local register `l0' is unused since the SAVE // instruction must be the first instruction in each procedure. // - MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(F); + MachineCodeForMethod& mcInfo = MachineCodeForMethod::get(&F); unsigned int staticStackSize = mcInfo.getStaticStackSize(); if (staticStackSize < (unsigned) frameInfo.getMinStackFrameSize()) @@ -104,26 +101,23 @@ void InsertPrologEpilogCode::InsertPrologCode(Function *F) mvec.push_back(M); } - MachineCodeForBasicBlock& bbMvec = entryBB->getMachineInstrVec(); - bbMvec.insert(entryBB->getMachineInstrVec().begin(), - mvec.begin(), mvec.end()); + MachineCodeForBasicBlock& bbMvec = F.getEntryNode().getMachineInstrVec(); + bbMvec.insert(bbMvec.begin(), mvec.begin(), mvec.end()); } -void InsertPrologEpilogCode::InsertEpilogCode(Function *F) +void InsertPrologEpilogCode::InsertEpilogCode(Function &F) { - for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) { - Instruction *TermInst = (Instruction*)(*I)->getTerminator(); + for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) { + Instruction *TermInst = (Instruction*)I->getTerminator(); if (TermInst->getOpcode() == Instruction::Ret) { - BasicBlock* exitBB = *I; - MachineInstr *Restore = new MachineInstr(RESTORE); Restore->SetMachineOperandReg(0, Target.getRegInfo().getZeroRegNum()); Restore->SetMachineOperandConst(1, MachineOperand::MO_SignExtendedImmed, (int64_t)0); Restore->SetMachineOperandReg(2, Target.getRegInfo().getZeroRegNum()); - MachineCodeForBasicBlock& bbMvec = exitBB->getMachineInstrVec(); + MachineCodeForBasicBlock& bbMvec = I->getMachineInstrVec(); MachineCodeForInstruction &termMvec = MachineCodeForInstruction::get(TermInst); diff --git a/lib/Target/SparcV9/SparcV9RegInfo.cpp b/lib/Target/SparcV9/SparcV9RegInfo.cpp index a86e4f9..6aa4d81 100644 --- a/lib/Target/SparcV9/SparcV9RegInfo.cpp +++ b/lib/Target/SparcV9/SparcV9RegInfo.cpp @@ -286,29 +286,26 @@ void UltraSparcRegInfo::suggestRegs4MethodArgs(const Function *Meth, // check if this is a varArgs function. needed for choosing regs. bool isVarArgs = isVarArgsFunction(Meth->getType()); - // get the argument list - const Function::ArgumentListType& ArgList = Meth->getArgumentList(); - // for each argument. count INT and FP arguments separately. - for( unsigned argNo=0, intArgNo=0, fpArgNo=0; - argNo != ArgList.size(); ++argNo) - { - // get the LR of arg - LiveRange *LR = LRI.getLiveRangeForValue((const Value *)ArgList[argNo]); - assert( LR && "No live range found for method arg"); - - unsigned regType = getRegType( LR ); - unsigned regClassIDOfArgReg = MAXINT; // reg class of chosen reg (unused) - - int regNum = (regType == IntRegType) - ? regNumForIntArg(/*inCallee*/ true, isVarArgs, - argNo, intArgNo++, fpArgNo, regClassIDOfArgReg) - : regNumForFPArg(regType, /*inCallee*/ true, isVarArgs, - argNo, intArgNo, fpArgNo++, regClassIDOfArgReg); - - if(regNum != InvalidRegNum) - LR->setSuggestedColor(regNum); - } + unsigned argNo=0, intArgNo=0, fpArgNo=0; + for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend(); + I != E; ++I, ++argNo) { + // get the LR of arg + LiveRange *LR = LRI.getLiveRangeForValue(I); + assert(LR && "No live range found for method arg"); + + unsigned regType = getRegType(LR); + unsigned regClassIDOfArgReg = MAXINT; // reg class of chosen reg (unused) + + int regNum = (regType == IntRegType) + ? regNumForIntArg(/*inCallee*/ true, isVarArgs, + argNo, intArgNo++, fpArgNo, regClassIDOfArgReg) + : regNumForFPArg(regType, /*inCallee*/ true, isVarArgs, + argNo, intArgNo, fpArgNo++, regClassIDOfArgReg); + + if(regNum != InvalidRegNum) + LR->setSuggestedColor(regNum); + } } @@ -323,16 +320,15 @@ void UltraSparcRegInfo::colorMethodArgs(const Function *Meth, // check if this is a varArgs function. needed for choosing regs. bool isVarArgs = isVarArgsFunction(Meth->getType()); - // get the argument list - const Function::ArgumentListType& ArgList = Meth->getArgumentList(); - // get an iterator to arg list MachineInstr *AdMI; // for each argument - for( unsigned argNo=0, intArgNo=0, fpArgNo=0; - argNo != ArgList.size(); ++argNo) { + // for each argument. count INT and FP arguments separately. + unsigned argNo=0, intArgNo=0, fpArgNo=0; + for(Function::const_aiterator I = Meth->abegin(), E = Meth->aend(); + I != E; ++I, ++argNo) { // get the LR of arg - LiveRange *LR = LRI.getLiveRangeForValue((Value*)ArgList[argNo]); + LiveRange *LR = LRI.getLiveRangeForValue(I); assert( LR && "No live range found for method arg"); unsigned regType = getRegType( LR ); diff --git a/lib/Target/SparcV9/SparcV9TargetMachine.cpp b/lib/Target/SparcV9/SparcV9TargetMachine.cpp index fecdf23..be6e9f4 100644 --- a/lib/Target/SparcV9/SparcV9TargetMachine.cpp +++ b/lib/Target/SparcV9/SparcV9TargetMachine.cpp @@ -135,8 +135,8 @@ public: return "Sparc ConstructMachineCodeForFunction"; } - bool runOnFunction(Function *F) { - MachineCodeForMethod::construct(F, Target); + bool runOnFunction(Function &F) { + MachineCodeForMethod::construct(&F, Target); return false; } }; @@ -147,9 +147,9 @@ public: inline InstructionSelection(TargetMachine &T) : Target(T) {} const char *getPassName() const { return "Sparc Instruction Selection"; } - bool runOnFunction(Function *F) { - if (SelectInstructionsForMethod(F, Target)) { - cerr << "Instr selection failed for function " << F->getName() << "\n"; + bool runOnFunction(Function &F) { + if (SelectInstructionsForMethod(&F, Target)) { + cerr << "Instr selection failed for function " << F.getName() << "\n"; abort(); } return false; @@ -159,20 +159,17 @@ public: struct FreeMachineCodeForFunction : public FunctionPass { const char *getPassName() const { return "Sparc FreeMachineCodeForFunction"; } - static void freeMachineCode(Instruction *I) { - MachineCodeForInstruction::destroy(I); + static void freeMachineCode(Instruction &I) { + MachineCodeForInstruction::destroy(&I); } - bool runOnFunction(Function *F) { - for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) - for (BasicBlock::iterator I = (*FI)->begin(), E = (*FI)->end(); - I != E; ++I) - MachineCodeForInstruction::get(*I).dropAllReferences(); + bool runOnFunction(Function &F) { + for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) + for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I) + MachineCodeForInstruction::get(I).dropAllReferences(); - for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI) - for (BasicBlock::iterator I = (*FI)->begin(), E = (*FI)->end(); - I != E; ++I) - freeMachineCode(*I); + for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) + for_each(FI->begin(), FI->end(), freeMachineCode); return false; } diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp index 8da9f04..d69a998 100644 --- a/lib/Transforms/IPO/GlobalDCE.cpp +++ b/lib/Transforms/IPO/GlobalDCE.cpp @@ -15,7 +15,7 @@ static Statistic<> NumRemoved("globaldce\t- Number of global values removed"); -static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) { +static bool RemoveUnreachableFunctions(Module &M, CallGraph &CallGraph) { // Calculate which functions are reachable from the external functions in the // call graph. // @@ -27,10 +27,10 @@ static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) { // The second pass removes the functions that need to be removed. // std::vector<CallGraphNode*> FunctionsToDelete; // Track unused functions - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { - CallGraphNode *N = CallGraph[*I]; + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + CallGraphNode *N = CallGraph[I]; if (!ReachableNodes.count(N)) { // Not reachable?? - (*I)->dropAllReferences(); + I->dropAllReferences(); N->removeAllCalledMethods(); FunctionsToDelete.push_back(N); ++NumRemoved; @@ -50,17 +50,16 @@ static bool RemoveUnreachableFunctions(Module *M, CallGraph &CallGraph) { return true; } -static bool RemoveUnreachableGlobalVariables(Module *M) { +static bool RemoveUnreachableGlobalVariables(Module &M) { bool Changed = false; // Eliminate all global variables that are unused, and that are internal, or // do not have an initializer. // - for (Module::giterator I = M->gbegin(); I != M->gend(); ) - if (!(*I)->use_empty() || - ((*I)->hasExternalLinkage() && (*I)->hasInitializer())) + for (Module::giterator I = M.gbegin(); I != M.gend(); ) + if (!I->use_empty() || (I->hasExternalLinkage() && I->hasInitializer())) ++I; // Cannot eliminate global variable else { - delete M->getGlobalList().remove(I); + I = M.getGlobalList().erase(I); ++NumRemoved; Changed = true; } @@ -74,7 +73,7 @@ namespace { // run - Do the GlobalDCE pass on the specified module, optionally updating // the specified callgraph to reflect the changes. // - bool run(Module *M) { + bool run(Module &M) { return RemoveUnreachableFunctions(M, getAnalysis<CallGraph>()) | RemoveUnreachableGlobalVariables(M); } diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp index 279c7eb..ff0b790 100644 --- a/lib/Transforms/IPO/Internalize.cpp +++ b/lib/Transforms/IPO/Internalize.cpp @@ -17,10 +17,10 @@ static Statistic<> NumChanged("internalize\t- Number of functions internal'd"); class InternalizePass : public Pass { const char *getPassName() const { return "Internalize Functions"; } - virtual bool run(Module *M) { + virtual bool run(Module &M) { bool FoundMain = false; // Look for a function named main... - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) - if ((*I)->getName() == "main" && !(*I)->isExternal()) { + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (I->getName() == "main" && !I->isExternal()) { FoundMain = true; break; } @@ -30,10 +30,10 @@ class InternalizePass : public Pass { bool Changed = false; // Found a main function, mark all functions not named main as internal. - for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) - if ((*I)->getName() != "main" && // Leave the main function external - !(*I)->isExternal()) { // Function must be defined here - (*I)->setInternalLinkage(true); + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (I->getName() != "main" && // Leave the main function external + !I->isExternal()) { // Function must be defined here + I->setInternalLinkage(true); Changed = true; ++NumChanged; } diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp index 758c41f..31692f8 100644 --- a/lib/Transforms/IPO/MutateStructTypes.cpp +++ b/lib/Transforms/IPO/MutateStructTypes.cpp @@ -95,7 +95,7 @@ const Type *MutateStructTypes::ConvertType(const Type *Ty) { assert(DestTy && "Type didn't get created!?!?"); // Refine our little placeholder value into a real type... - cast<DerivedType>(PlaceHolder.get())->refineAbstractTypeTo(DestTy); + ((DerivedType*)PlaceHolder.get())->refineAbstractTypeTo(DestTy); TypeMap.insert(std::make_pair(Ty, PlaceHolder.get())); return PlaceHolder.get(); @@ -139,9 +139,9 @@ Value *MutateStructTypes::ConvertValue(const Value *V) { // Ignore null values and simple constants.. if (V == 0) return 0; - if (Constant *CPV = dyn_cast<Constant>(V)) { + if (const Constant *CPV = dyn_cast<Constant>(V)) { if (V->getType()->isPrimitiveType()) - return CPV; + return (Value*)CPV; if (isa<ConstantPointerNull>(CPV)) return ConstantPointerNull::get( @@ -150,11 +150,11 @@ Value *MutateStructTypes::ConvertValue(const Value *V) { } // Check to see if this is an out of function reference first... - if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) { + if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { // Check to see if the value is in the map... map<const GlobalValue*, GlobalValue*>::iterator I = GlobalMap.find(GV); if (I == GlobalMap.end()) - return GV; // Not mapped, just return value itself + return (Value*)GV; // Not mapped, just return value itself return I->second; } @@ -221,7 +221,7 @@ void MutateStructTypes::setTransforms(const TransformsType &XForm) { // types... // const Type *OldTypeStub = TypeMap.find(OldTy)->second.get(); - cast<DerivedType>(OldTypeStub)->refineAbstractTypeTo(NSTy); + ((DerivedType*)OldTypeStub)->refineAbstractTypeTo(NSTy); // Add the transformation to the Transforms map. Transforms.insert(std::make_pair(OldTy, @@ -239,52 +239,46 @@ void MutateStructTypes::clearTransforms() { "Local Value Map should always be empty between transformations!"); } -// doInitialization - This loops over global constants defined in the +// processGlobals - This loops over global constants defined in the // module, converting them to their new type. // -void MutateStructTypes::processGlobals(Module *M) { +void MutateStructTypes::processGlobals(Module &M) { // Loop through the functions in the module and create a new version of the - // function to contained the transformed code. Don't use an iterator, because - // we will be adding values to the end of the vector, and it could be - // reallocated. Also, we don't want to process the values that we add. + // function to contained the transformed code. Also, be careful to not + // process the values that we add. // - unsigned NumFunctions = M->size(); - for (unsigned i = 0; i < NumFunctions; ++i) { - Function *Meth = M->begin()[i]; - - if (!Meth->isExternal()) { + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (!I->isExternal()) { const FunctionType *NewMTy = - cast<FunctionType>(ConvertType(Meth->getFunctionType())); + cast<FunctionType>(ConvertType(I->getFunctionType())); // Create a new function to put stuff into... - Function *NewMeth = new Function(NewMTy, Meth->hasInternalLinkage(), - Meth->getName()); - if (Meth->hasName()) - Meth->setName("OLD."+Meth->getName()); + Function *NewMeth = new Function(NewMTy, I->hasInternalLinkage(), + I->getName()); + if (I->hasName()) + I->setName("OLD."+I->getName()); // Insert the new function into the function list... to be filled in later - M->getFunctionList().push_back(NewMeth); + M.getFunctionList().push_back(NewMeth); // Keep track of the association... - GlobalMap[Meth] = NewMeth; + GlobalMap[I] = NewMeth; } - } // TODO: HANDLE GLOBAL VARIABLES // Remap the symbol table to refer to the types in a nice way // - if (M->hasSymbolTable()) { - SymbolTable *ST = M->getSymbolTable(); + if (SymbolTable *ST = M.getSymbolTable()) { SymbolTable::iterator I = ST->find(Type::TypeTy); if (I != ST->end()) { // Get the type plane for Type's SymbolTable::VarMap &Plane = I->second; for (SymbolTable::type_iterator TI = Plane.begin(), TE = Plane.end(); TI != TE; ++TI) { - // This is gross, I'm reaching right into a symbol table and mucking - // around with it's internals... but oh well. + // FIXME: This is gross, I'm reaching right into a symbol table and + // mucking around with it's internals... but oh well. // - TI->second = cast<Type>(ConvertType(cast<Type>(TI->second))); + TI->second = (Value*)cast<Type>(ConvertType(cast<Type>(TI->second))); } } } @@ -293,20 +287,20 @@ void MutateStructTypes::processGlobals(Module *M) { // removeDeadGlobals - For this pass, all this does is remove the old versions // of the functions and global variables that we no longer need. -void MutateStructTypes::removeDeadGlobals(Module *M) { +void MutateStructTypes::removeDeadGlobals(Module &M) { // Prepare for deletion of globals by dropping their interdependencies... - for(Module::iterator I = M->begin(); I != M->end(); ++I) { - if (GlobalMap.find(*I) != GlobalMap.end()) - (*I)->Function::dropAllReferences(); + for(Module::iterator I = M.begin(); I != M.end(); ++I) { + if (GlobalMap.find(I) != GlobalMap.end()) + I->dropAllReferences(); } // Run through and delete the functions and global variables... #if 0 // TODO: HANDLE GLOBAL VARIABLES - M->getGlobalList().delete_span(M->gbegin(), M->gbegin()+NumGVars/2); + M->getGlobalList().delete_span(M.gbegin(), M.gbegin()+NumGVars/2); #endif - for(Module::iterator I = M->begin(); I != M->end();) { - if (GlobalMap.find(*I) != GlobalMap.end()) - delete M->getFunctionList().remove(I); + for(Module::iterator I = M.begin(); I != M.end();) { + if (GlobalMap.find(I) != GlobalMap.end()) + I = M.getFunctionList().erase(I); else ++I; } @@ -326,46 +320,43 @@ void MutateStructTypes::transformFunction(Function *m) { Function *NewMeth = cast<Function>(GMI->second); // Okay, first order of business, create the arguments... - for (unsigned i = 0, e = M->getArgumentList().size(); i != e; ++i) { - const Argument *OFA = M->getArgumentList()[i]; - Argument *NFA = new Argument(ConvertType(OFA->getType()), OFA->getName()); + for (Function::aiterator I = m->abegin(), E = m->aend(); I != E; ++I) { + Argument *NFA = new Argument(ConvertType(I->getType()), I->getName()); NewMeth->getArgumentList().push_back(NFA); - LocalValueMap[OFA] = NFA; // Keep track of value mapping + LocalValueMap[I] = NFA; // Keep track of value mapping } // Loop over all of the basic blocks copying instructions over... - for (Function::const_iterator BBI = M->begin(), BBE = M->end(); BBI != BBE; - ++BBI) { - + for (Function::const_iterator BB = M->begin(), BBE = M->end(); BB != BBE; + ++BB) { // Create a new basic block and establish a mapping between the old and new - const BasicBlock *BB = *BBI; BasicBlock *NewBB = cast<BasicBlock>(ConvertValue(BB)); - NewMeth->getBasicBlocks().push_back(NewBB); // Add block to function + NewMeth->getBasicBlockList().push_back(NewBB); // Add block to function // Copy over all of the instructions in the basic block... for (BasicBlock::const_iterator II = BB->begin(), IE = BB->end(); II != IE; ++II) { - const Instruction *I = *II; // Get the current instruction... + const Instruction &I = *II; // Get the current instruction... Instruction *NewI = 0; - switch (I->getOpcode()) { + switch (I.getOpcode()) { // Terminator Instructions case Instruction::Ret: NewI = new ReturnInst( - ConvertValue(cast<ReturnInst>(I)->getReturnValue())); + ConvertValue(cast<ReturnInst>(I).getReturnValue())); break; case Instruction::Br: { - const BranchInst *BI = cast<BranchInst>(I); - if (BI->isConditional()) { + const BranchInst &BI = cast<BranchInst>(I); + if (BI.isConditional()) { NewI = - new BranchInst(cast<BasicBlock>(ConvertValue(BI->getSuccessor(0))), - cast<BasicBlock>(ConvertValue(BI->getSuccessor(1))), - ConvertValue(BI->getCondition())); + new BranchInst(cast<BasicBlock>(ConvertValue(BI.getSuccessor(0))), + cast<BasicBlock>(ConvertValue(BI.getSuccessor(1))), + ConvertValue(BI.getCondition())); } else { NewI = - new BranchInst(cast<BasicBlock>(ConvertValue(BI->getSuccessor(0)))); + new BranchInst(cast<BasicBlock>(ConvertValue(BI.getSuccessor(0)))); } break; } @@ -375,8 +366,8 @@ void MutateStructTypes::transformFunction(Function *m) { // Unary Instructions case Instruction::Not: - NewI = UnaryOperator::create((Instruction::UnaryOps)I->getOpcode(), - ConvertValue(I->getOperand(0))); + NewI = UnaryOperator::create((Instruction::UnaryOps)I.getOpcode(), + ConvertValue(I.getOperand(0))); break; // Binary Instructions @@ -397,41 +388,41 @@ void MutateStructTypes::transformFunction(Function *m) { case Instruction::SetGE: case Instruction::SetLT: case Instruction::SetGT: - NewI = BinaryOperator::create((Instruction::BinaryOps)I->getOpcode(), - ConvertValue(I->getOperand(0)), - ConvertValue(I->getOperand(1))); + NewI = BinaryOperator::create((Instruction::BinaryOps)I.getOpcode(), + ConvertValue(I.getOperand(0)), + ConvertValue(I.getOperand(1))); break; case Instruction::Shr: case Instruction::Shl: - NewI = new ShiftInst(cast<ShiftInst>(I)->getOpcode(), - ConvertValue(I->getOperand(0)), - ConvertValue(I->getOperand(1))); + NewI = new ShiftInst(cast<ShiftInst>(I).getOpcode(), + ConvertValue(I.getOperand(0)), + ConvertValue(I.getOperand(1))); break; // Memory Instructions case Instruction::Alloca: NewI = - new AllocaInst(ConvertType(I->getType()), - I->getNumOperands()?ConvertValue(I->getOperand(0)):0); + new AllocaInst(ConvertType(I.getType()), + I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0); break; case Instruction::Malloc: NewI = - new MallocInst(ConvertType(I->getType()), - I->getNumOperands()?ConvertValue(I->getOperand(0)):0); + new MallocInst(ConvertType(I.getType()), + I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0); break; case Instruction::Free: - NewI = new FreeInst(ConvertValue(I->getOperand(0))); + NewI = new FreeInst(ConvertValue(I.getOperand(0))); break; case Instruction::Load: case Instruction::Store: case Instruction::GetElementPtr: { - const MemAccessInst *MAI = cast<MemAccessInst>(I); - vector<Value*> Indices(MAI->idx_begin(), MAI->idx_end()); - const Value *Ptr = MAI->getPointerOperand(); + const MemAccessInst &MAI = cast<MemAccessInst>(I); + vector<Value*> Indices(MAI.idx_begin(), MAI.idx_end()); + const Value *Ptr = MAI.getPointerOperand(); Value *NewPtr = ConvertValue(Ptr); if (!Indices.empty()) { const Type *PTy = cast<PointerType>(Ptr->getType())->getElementType(); @@ -441,7 +432,7 @@ void MutateStructTypes::transformFunction(Function *m) { if (isa<LoadInst>(I)) { NewI = new LoadInst(NewPtr, Indices); } else if (isa<StoreInst>(I)) { - NewI = new StoreInst(ConvertValue(I->getOperand(0)), NewPtr, Indices); + NewI = new StoreInst(ConvertValue(I.getOperand(0)), NewPtr, Indices); } else if (isa<GetElementPtrInst>(I)) { NewI = new GetElementPtrInst(NewPtr, Indices); } else { @@ -452,23 +443,23 @@ void MutateStructTypes::transformFunction(Function *m) { // Miscellaneous Instructions case Instruction::PHINode: { - const PHINode *OldPN = cast<PHINode>(I); - PHINode *PN = new PHINode(ConvertType(I->getType())); - for (unsigned i = 0; i < OldPN->getNumIncomingValues(); ++i) - PN->addIncoming(ConvertValue(OldPN->getIncomingValue(i)), - cast<BasicBlock>(ConvertValue(OldPN->getIncomingBlock(i)))); + const PHINode &OldPN = cast<PHINode>(I); + PHINode *PN = new PHINode(ConvertType(OldPN.getType())); + for (unsigned i = 0; i < OldPN.getNumIncomingValues(); ++i) + PN->addIncoming(ConvertValue(OldPN.getIncomingValue(i)), + cast<BasicBlock>(ConvertValue(OldPN.getIncomingBlock(i)))); NewI = PN; break; } case Instruction::Cast: - NewI = new CastInst(ConvertValue(I->getOperand(0)), - ConvertType(I->getType())); + NewI = new CastInst(ConvertValue(I.getOperand(0)), + ConvertType(I.getType())); break; case Instruction::Call: { - Value *Meth = ConvertValue(I->getOperand(0)); + Value *Meth = ConvertValue(I.getOperand(0)); vector<Value*> Operands; - for (unsigned i = 1; i < I->getNumOperands(); ++i) - Operands.push_back(ConvertValue(I->getOperand(i))); + for (unsigned i = 1; i < I.getNumOperands(); ++i) + Operands.push_back(ConvertValue(I.getOperand(i))); NewI = new CallInst(Meth, Operands); break; } @@ -478,11 +469,11 @@ void MutateStructTypes::transformFunction(Function *m) { break; } - NewI->setName(I->getName()); + NewI->setName(I.getName()); NewBB->getInstList().push_back(NewI); // Check to see if we had to make a placeholder for this value... - map<const Value*,Value*>::iterator LVMI = LocalValueMap.find(I); + map<const Value*,Value*>::iterator LVMI = LocalValueMap.find(&I); if (LVMI != LocalValueMap.end()) { // Yup, make sure it's a placeholder... Instruction *I = cast<Instruction>(LVMI->second); @@ -495,7 +486,7 @@ void MutateStructTypes::transformFunction(Function *m) { // Keep track of the fact the the local implementation of this instruction // is NewI. - LocalValueMap[I] = NewI; + LocalValueMap[&I] = NewI; } } @@ -503,11 +494,11 @@ void MutateStructTypes::transformFunction(Function *m) { } -bool MutateStructTypes::run(Module *M) { +bool MutateStructTypes::run(Module &M) { processGlobals(M); - for_each(M->begin(), M->end(), - bind_obj(this, &MutateStructTypes::transformFunction)); + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + transformFunction(I); removeDeadGlobals(M); return true; diff --git a/lib/Transforms/IPO/OldPoolAllocate.cpp b/lib/Transforms/IPO/OldPoolAllocate.cpp index 5190dd2..5182df4 100644 --- a/lib/Transforms/IPO/OldPoolAllocate.cpp +++ b/lib/Transforms/IPO/OldPoolAllocate.cpp @@ -13,8 +13,6 @@ #include "llvm/Transforms/Utils/CloneFunction.h" #include "llvm/Analysis/DataStructureGraph.h" #include "llvm/Module.h" -#include "llvm/Function.h" -#include "llvm/BasicBlock.h" #include "llvm/iMemory.h" #include "llvm/iTerminators.h" #include "llvm/iPHINode.h" @@ -23,7 +21,6 @@ #include "llvm/Constants.h" #include "llvm/Target/TargetData.h" #include "llvm/Support/InstVisitor.h" -#include "llvm/Argument.h" #include "Support/DepthFirstIterator.h" #include "Support/STLExtras.h" #include <algorithm> @@ -62,9 +59,9 @@ const Type *POINTERTYPE; static TargetData TargetData("test"); static const Type *getPointerTransformedType(const Type *Ty) { - if (PointerType *PT = dyn_cast<PointerType>(Ty)) { + if (const PointerType *PT = dyn_cast<PointerType>(Ty)) { return POINTERTYPE; - } else if (StructType *STy = dyn_cast<StructType>(Ty)) { + } else if (const StructType *STy = dyn_cast<StructType>(Ty)) { vector<const Type *> NewElTypes; NewElTypes.reserve(STy->getElementTypes().size()); for (StructType::ElementTypes::const_iterator @@ -72,7 +69,7 @@ static const Type *getPointerTransformedType(const Type *Ty) { E = STy->getElementTypes().end(); I != E; ++I) NewElTypes.push_back(getPointerTransformedType(*I)); return StructType::get(NewElTypes); - } else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { + } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { return ArrayType::get(getPointerTransformedType(ATy->getElementType()), ATy->getNumElements()); } else { @@ -233,7 +230,7 @@ namespace { return Result; } - bool run(Module *M); + bool run(Module &M); // getAnalysisUsage - This function requires data structure information // to be able to see what is pool allocatable. @@ -273,7 +270,7 @@ namespace { // specified module and update the Pool* instance variables to point to // them. // - void addPoolPrototypes(Module *M); + void addPoolPrototypes(Module &M); // CreatePools - Insert instructions into the function we are processing to @@ -410,12 +407,13 @@ class NewInstructionCreator : public InstVisitor<NewInstructionCreator> { return 0; } - BasicBlock::iterator ReplaceInstWith(Instruction *I, Instruction *New) { - BasicBlock *BB = I->getParent(); - BasicBlock::iterator RI = find(BB->begin(), BB->end(), I); - BB->getInstList().replaceWith(RI, New); - XFormMap[I] = New; - return RI; + BasicBlock::iterator ReplaceInstWith(Instruction &I, Instruction *New) { + BasicBlock *BB = I.getParent(); + BasicBlock::iterator RI = &I; + BB->getInstList().remove(RI); + BB->getInstList().insert(RI, New); + XFormMap[&I] = New; + return New; } Instruction *createPoolBaseInstruction(Value *PtrVal) { @@ -471,36 +469,36 @@ public: // NewInstructionCreator instance... //===--------------------------------------------------------------------===// - void visitGetElementPtrInst(GetElementPtrInst *I) { + void visitGetElementPtrInst(GetElementPtrInst &I) { assert(0 && "Cannot transform get element ptr instructions yet!"); } // Replace the load instruction with a new one. - void visitLoadInst(LoadInst *I) { + void visitLoadInst(LoadInst &I) { vector<Instruction *> BeforeInsts; // Cast our index to be a UIntTy so we can use it to index into the pool... CastInst *Index = new CastInst(Constant::getNullValue(POINTERTYPE), - Type::UIntTy, I->getOperand(0)->getName()); + Type::UIntTy, I.getOperand(0)->getName()); BeforeInsts.push_back(Index); - ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I->getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I.getOperand(0))); // Include the pool base instruction... - Instruction *PoolBase = createPoolBaseInstruction(I->getOperand(0)); + Instruction *PoolBase = createPoolBaseInstruction(I.getOperand(0)); BeforeInsts.push_back(PoolBase); Instruction *IdxInst = - BinaryOperator::create(Instruction::Add, *I->idx_begin(), Index, - I->getName()+".idx"); + BinaryOperator::create(Instruction::Add, *I.idx_begin(), Index, + I.getName()+".idx"); BeforeInsts.push_back(IdxInst); - vector<Value*> Indices(I->idx_begin(), I->idx_end()); + vector<Value*> Indices(I.idx_begin(), I.idx_end()); Indices[0] = IdxInst; Instruction *Address = new GetElementPtrInst(PoolBase, Indices, - I->getName()+".addr"); + I.getName()+".addr"); BeforeInsts.push_back(Address); - Instruction *NewLoad = new LoadInst(Address, I->getName()); + Instruction *NewLoad = new LoadInst(Address, I.getName()); // Replace the load instruction with the new load instruction... BasicBlock::iterator II = ReplaceInstWith(I, NewLoad); @@ -512,57 +510,58 @@ public: // If not yielding a pool allocated pointer, use the new load value as the // value in the program instead of the old load value... // - if (!getScalar(I)) - I->replaceAllUsesWith(NewLoad); + if (!getScalar(&I)) + I.replaceAllUsesWith(NewLoad); } // Replace the store instruction with a new one. In the store instruction, // the value stored could be a pointer type, meaning that the new store may // have to change one or both of it's operands. // - void visitStoreInst(StoreInst *I) { - assert(getScalar(I->getOperand(1)) && + void visitStoreInst(StoreInst &I) { + assert(getScalar(I.getOperand(1)) && "Store inst found only storing pool allocated pointer. " "Not imp yet!"); - Value *Val = I->getOperand(0); // The value to store... + Value *Val = I.getOperand(0); // The value to store... // Check to see if the value we are storing is a data structure pointer... - //if (const ScalarInfo *ValScalar = getScalar(I->getOperand(0))) - if (isa<PointerType>(I->getOperand(0)->getType())) + //if (const ScalarInfo *ValScalar = getScalar(I.getOperand(0))) + if (isa<PointerType>(I.getOperand(0)->getType())) Val = Constant::getNullValue(POINTERTYPE); // Yes, store a dummy - Instruction *PoolBase = createPoolBaseInstruction(I->getOperand(1)); + Instruction *PoolBase = createPoolBaseInstruction(I.getOperand(1)); // Cast our index to be a UIntTy so we can use it to index into the pool... CastInst *Index = new CastInst(Constant::getNullValue(POINTERTYPE), - Type::UIntTy, I->getOperand(1)->getName()); - ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I->getOperand(1))); + Type::UIntTy, I.getOperand(1)->getName()); + ReferencesToUpdate.push_back(RefToUpdate(Index, 0, I.getOperand(1))); // Instructions to add after the Index... vector<Instruction*> AfterInsts; Instruction *IdxInst = - BinaryOperator::create(Instruction::Add, *I->idx_begin(), Index, "idx"); + BinaryOperator::create(Instruction::Add, *I.idx_begin(), Index, "idx"); AfterInsts.push_back(IdxInst); - vector<Value*> Indices(I->idx_begin(), I->idx_end()); + vector<Value*> Indices(I.idx_begin(), I.idx_end()); Indices[0] = IdxInst; Instruction *Address = new GetElementPtrInst(PoolBase, Indices, - I->getName()+"storeaddr"); + I.getName()+"storeaddr"); AfterInsts.push_back(Address); Instruction *NewStore = new StoreInst(Val, Address); AfterInsts.push_back(NewStore); - if (Val != I->getOperand(0)) // Value stored was a pointer? - ReferencesToUpdate.push_back(RefToUpdate(NewStore, 0, I->getOperand(0))); + if (Val != I.getOperand(0)) // Value stored was a pointer? + ReferencesToUpdate.push_back(RefToUpdate(NewStore, 0, I.getOperand(0))); // Replace the store instruction with the cast instruction... BasicBlock::iterator II = ReplaceInstWith(I, Index); // Add the pool base calculator instruction before the index... - II = Index->getParent()->getInstList().insert(II, PoolBase)+2; + II = ++Index->getParent()->getInstList().insert(II, PoolBase); + ++II; // Add the instructions that go after the index... Index->getParent()->getInstList().insert(II, AfterInsts.begin(), @@ -571,42 +570,42 @@ public: // Create call to poolalloc for every malloc instruction - void visitMallocInst(MallocInst *I) { - const ScalarInfo &SCI = getScalarRef(I); + void visitMallocInst(MallocInst &I) { + const ScalarInfo &SCI = getScalarRef(&I); vector<Value*> Args; CallInst *Call; - if (!I->isArrayAllocation()) { + if (!I.isArrayAllocation()) { Args.push_back(SCI.Pool.Handle); - Call = new CallInst(PoolAllocator.PoolAlloc, Args, I->getName()); + Call = new CallInst(PoolAllocator.PoolAlloc, Args, I.getName()); } else { - Args.push_back(I->getArraySize()); + Args.push_back(I.getArraySize()); Args.push_back(SCI.Pool.Handle); - Call = new CallInst(PoolAllocator.PoolAllocArray, Args, I->getName()); + Call = new CallInst(PoolAllocator.PoolAllocArray, Args, I.getName()); } ReplaceInstWith(I, Call); } // Convert a call to poolfree for every free instruction... - void visitFreeInst(FreeInst *I) { + void visitFreeInst(FreeInst &I) { // Create a new call to poolfree before the free instruction vector<Value*> Args; Args.push_back(Constant::getNullValue(POINTERTYPE)); - Args.push_back(getScalarRef(I->getOperand(0)).Pool.Handle); + Args.push_back(getScalarRef(I.getOperand(0)).Pool.Handle); Instruction *NewCall = new CallInst(PoolAllocator.PoolFree, Args); ReplaceInstWith(I, NewCall); - ReferencesToUpdate.push_back(RefToUpdate(NewCall, 1, I->getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(NewCall, 1, I.getOperand(0))); } // visitCallInst - Create a new call instruction with the extra arguments for // all of the memory pools that the call needs. // - void visitCallInst(CallInst *I) { - TransformFunctionInfo &TI = CallMap[I]; + void visitCallInst(CallInst &I) { + TransformFunctionInfo &TI = CallMap[&I]; // Start with all of the old arguments... - vector<Value*> Args(I->op_begin()+1, I->op_end()); + vector<Value*> Args(I.op_begin()+1, I.op_end()); for (unsigned i = 0, e = TI.ArgInfo.size(); i != e; ++i) { // Replace all of the pointer arguments with our new pointer typed values. @@ -618,7 +617,7 @@ public: } Function *NF = PoolAllocator.getTransformedFunction(TI); - Instruction *NewCall = new CallInst(NF, Args, I->getName()); + Instruction *NewCall = new CallInst(NF, Args, I.getName()); ReplaceInstWith(I, NewCall); // Keep track of the mapping of operands so that we can resolve them to real @@ -627,7 +626,7 @@ public: for (unsigned i = 0, e = TI.ArgInfo.size(); i != e; ++i) if (TI.ArgInfo[i].ArgNo != -1) ReferencesToUpdate.push_back(RefToUpdate(NewCall, TI.ArgInfo[i].ArgNo+1, - I->getOperand(TI.ArgInfo[i].ArgNo+1))); + I.getOperand(TI.ArgInfo[i].ArgNo+1))); else RetVal = 0; // If returning a pointer, don't change retval... @@ -635,47 +634,47 @@ public: // instead of the old call... // if (RetVal) - I->replaceAllUsesWith(RetVal); + I.replaceAllUsesWith(RetVal); } // visitPHINode - Create a new PHI node of POINTERTYPE for all of the old Phi // nodes... // - void visitPHINode(PHINode *PN) { + void visitPHINode(PHINode &PN) { Value *DummyVal = Constant::getNullValue(POINTERTYPE); - PHINode *NewPhi = new PHINode(POINTERTYPE, PN->getName()); - for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { - NewPhi->addIncoming(DummyVal, PN->getIncomingBlock(i)); + PHINode *NewPhi = new PHINode(POINTERTYPE, PN.getName()); + for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) { + NewPhi->addIncoming(DummyVal, PN.getIncomingBlock(i)); ReferencesToUpdate.push_back(RefToUpdate(NewPhi, i*2, - PN->getIncomingValue(i))); + PN.getIncomingValue(i))); } ReplaceInstWith(PN, NewPhi); } // visitReturnInst - Replace ret instruction with a new return... - void visitReturnInst(ReturnInst *I) { + void visitReturnInst(ReturnInst &I) { Instruction *Ret = new ReturnInst(Constant::getNullValue(POINTERTYPE)); ReplaceInstWith(I, Ret); - ReferencesToUpdate.push_back(RefToUpdate(Ret, 0, I->getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(Ret, 0, I.getOperand(0))); } // visitSetCondInst - Replace a conditional test instruction with a new one - void visitSetCondInst(SetCondInst *SCI) { - BinaryOperator *I = (BinaryOperator*)SCI; + void visitSetCondInst(SetCondInst &SCI) { + BinaryOperator &I = (BinaryOperator&)SCI; Value *DummyVal = Constant::getNullValue(POINTERTYPE); - BinaryOperator *New = BinaryOperator::create(I->getOpcode(), DummyVal, - DummyVal, I->getName()); + BinaryOperator *New = BinaryOperator::create(I.getOpcode(), DummyVal, + DummyVal, I.getName()); ReplaceInstWith(I, New); - ReferencesToUpdate.push_back(RefToUpdate(New, 0, I->getOperand(0))); - ReferencesToUpdate.push_back(RefToUpdate(New, 1, I->getOperand(1))); + ReferencesToUpdate.push_back(RefToUpdate(New, 0, I.getOperand(0))); + ReferencesToUpdate.push_back(RefToUpdate(New, 1, I.getOperand(1))); // Make sure branches refer to the new condition... - I->replaceAllUsesWith(New); + I.replaceAllUsesWith(New); } - void visitInstruction(Instruction *I) { + void visitInstruction(Instruction &I) { cerr << "Unknown instruction to FunctionBodyTransformer:\n" << I; } }; @@ -729,8 +728,8 @@ public: } #ifdef DEBUG_POOLBASE_LOAD_ELIMINATOR - void visitFunction(Function *F) { - cerr << "Pool Load Elim '" << F->getName() << "'\t"; + void visitFunction(Function &F) { + cerr << "Pool Load Elim '" << F.getName() << "'\t"; } ~PoolBaseLoadEliminator() { unsigned Total = Eliminated+Remaining; @@ -745,7 +744,7 @@ public: // local transformation, we reset all of our state when we enter a new basic // block. // - void visitBasicBlock(BasicBlock *) { + void visitBasicBlock(BasicBlock &) { PoolDescMap.clear(); // Forget state. } @@ -754,25 +753,25 @@ public: // indicating that we have a value available to recycle next time we see the // poolbase of this instruction being loaded. // - void visitLoadInst(LoadInst *LI) { - Value *LoadAddr = LI->getPointerOperand(); + void visitLoadInst(LoadInst &LI) { + Value *LoadAddr = LI.getPointerOperand(); map<Value*, LoadInst*>::iterator VIt = PoolDescMap.find(LoadAddr); if (VIt != PoolDescMap.end()) { // We already have a value for this load? - LI->replaceAllUsesWith(VIt->second); // Make the current load dead + LI.replaceAllUsesWith(VIt->second); // Make the current load dead ++Eliminated; } else { // This load might not be a load of a pool pointer, check to see if it is - if (LI->getNumOperands() == 4 && // load pool, uint 0, ubyte 0, ubyte 0 + if (LI.getNumOperands() == 4 && // load pool, uint 0, ubyte 0, ubyte 0 find(PoolDescValues.begin(), PoolDescValues.end(), LoadAddr) != PoolDescValues.end()) { assert("Make sure it's a load of the pool base, not a chaining field" && - LI->getOperand(1) == Constant::getNullValue(Type::UIntTy) && - LI->getOperand(2) == Constant::getNullValue(Type::UByteTy) && - LI->getOperand(3) == Constant::getNullValue(Type::UByteTy)); + LI.getOperand(1) == Constant::getNullValue(Type::UIntTy) && + LI.getOperand(2) == Constant::getNullValue(Type::UByteTy) && + LI.getOperand(3) == Constant::getNullValue(Type::UByteTy)); // If it is a load of a pool base, keep track of it for future reference - PoolDescMap.insert(make_pair(LoadAddr, LI)); + PoolDescMap.insert(make_pair(LoadAddr, &LI)); ++Remaining; } } @@ -784,7 +783,7 @@ public: // function might call one of these functions, so be conservative. Through // more analysis, this could be improved in the future. // - void visitCallInst(CallInst *) { + void visitCallInst(CallInst &) { PoolDescMap.clear(); } }; @@ -845,8 +844,9 @@ static void CalculateNodeMapping(Function *F, TransformFunctionInfo &TFI, NodeMapping); } else { // Figure out which node argument # ArgNo points to in the called graph. - Value *Arg = F->getArgumentList()[TFI.ArgInfo[i].ArgNo]; - addNodeMapping(TFI.ArgInfo[i].Node, CalledGraph.getValueMap()[Arg], + Function::aiterator AI = F->abegin(); + std::advance(AI, TFI.ArgInfo[i].ArgNo); + addNodeMapping(TFI.ArgInfo[i].Node, CalledGraph.getValueMap()[AI], NodeMapping); } LastArgNo = TFI.ArgInfo[i].ArgNo; @@ -923,9 +923,9 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, Done = false; } - for (unsigned i = 0, e = Func->getArgumentList().size(); i != e; ++i) { - Argument *Arg = Func->getArgumentList()[i]; - if (isa<PointerType>(Arg->getType())) { + unsigned i = 0; + for (Function::aiterator I = Func->abegin(), E = Func->aend(); I!=E; ++I,++i){ + if (isa<PointerType>(I->getType())) { if (PtrNo < ArgInfo.size() && ArgInfo[PtrNo++].ArgNo == (int)i) { // We DO transform this arg... skip all possible entries for argument while (PtrNo < ArgInfo.size() && ArgInfo[PtrNo].ArgNo == (int)i) @@ -989,9 +989,10 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, if (i == 0) // Only process retvals once (performance opt) markReachableNodes(CalledDS.getRetNodes(), ReachableNodes); } else { // If it's an argument value... - Argument *Arg = Func->getArgumentList()[ArgInfo[i].ArgNo]; - if (isa<PointerType>(Arg->getType())) - markReachableNodes(CalledDS.getValueMap()[Arg], ReachableNodes); + Function::aiterator AI = Func->abegin(); + std::advance(AI, ArgInfo[i].ArgNo); + if (isa<PointerType>(AI->getType())) + markReachableNodes(CalledDS.getValueMap()[AI], ReachableNodes); } } @@ -1035,9 +1036,9 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, } } - for (unsigned i = 0, e = Func->getArgumentList().size(); i != e; ++i) { - Argument *Arg = Func->getArgumentList()[i]; - if (isa<PointerType>(Arg->getType())) { + i = 0; + for (Function::aiterator I = Func->abegin(), E = Func->aend(); I!=E; ++I, ++i) + if (isa<PointerType>(I->getType())) { if (PtrNo < ArgInfo.size() && ArgInfo[PtrNo++].ArgNo == (int)i) { // We DO transform this arg... skip all possible entries for argument while (PtrNo < ArgInfo.size() && ArgInfo[PtrNo].ArgNo == (int)i) @@ -1045,13 +1046,13 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, } else { // This should generalize to any number of nodes, just see if any are // reachable. - assert(CalledDS.getValueMap()[Arg].size() == 1 && + assert(CalledDS.getValueMap()[I].size() == 1 && "Only handle case where pointing to one node so far!"); // If the arg is not marked as being passed in, but it NEEDS to // be transformed, then make it known now. // - DSNode *N = CalledDS.getValueMap()[Arg][0].Node; + DSNode *N = CalledDS.getValueMap()[I][0].Node; if (ReachableNodes.count(N)) { #ifdef DEBUG_TRANSFORM_PROGRESS cerr << "ensure dependant arguments adds for arg #" << i << "\n"; @@ -1063,7 +1064,6 @@ void TransformFunctionInfo::ensureDependantArgumentsIncluded(DataStructure *DS, } } } - } } @@ -1222,7 +1222,7 @@ void PoolAllocate::transformFunctionBody(Function *F, FunctionDSGraph &IPFGraph, if (PoolDescs.count(RetNode.Node)) { // Loop over all of the basic blocks, adding return instructions... for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) - if (ReturnInst *RI = dyn_cast<ReturnInst>((*I)->getTerminator())) + if (ReturnInst *RI = dyn_cast<ReturnInst>(I->getTerminator())) InstToFix.push_back(RI); } } @@ -1246,7 +1246,7 @@ void PoolAllocate::transformFunctionBody(Function *F, FunctionDSGraph &IPFGraph, #ifdef DEBUG_TRANSFORM_PROGRESS for (unsigned i = 0, e = InstToFix.size(); i != e; ++i) { cerr << "Fixing: " << InstToFix[i]; - NIC.visit(InstToFix[i]); + NIC.visit(*InstToFix[i]); } #else NIC.visit(InstToFix.begin(), InstToFix.end()); @@ -1264,16 +1264,15 @@ void PoolAllocate::transformFunctionBody(Function *F, FunctionDSGraph &IPFGraph, // FunctionType::ParamTypes::const_iterator TI = F->getFunctionType()->getParamTypes().begin(); - for (Function::ArgumentListType::iterator I = F->getArgumentList().begin(), - E = F->getArgumentList().end(); I != E; ++I, ++TI) { - Argument *Arg = *I; - if (Arg->getType() != *TI) { - assert(isa<PointerType>(Arg->getType()) && *TI == POINTERTYPE); - Argument *NewArg = new Argument(*TI, Arg->getName()); - XFormMap[Arg] = NewArg; // Map old arg into new arg... + for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++TI) { + if (I->getType() != *TI) { + assert(isa<PointerType>(I->getType()) && *TI == POINTERTYPE); + Argument *NewArg = new Argument(*TI, I->getName()); + XFormMap[I] = NewArg; // Map old arg into new arg... // Replace the old argument and then delete it... - delete F->getArgumentList().replaceWith(I, NewArg); + I = F->getArgumentList().erase(I); + I = F->getArgumentList().insert(I, NewArg); } } @@ -1366,9 +1365,9 @@ void PoolAllocate::transformFunction(TransformFunctionInfo &TFI, // Add arguments to the function... starting with all of the old arguments vector<Value*> ArgMap; - for (unsigned i = 0, e = TFI.Func->getArgumentList().size(); i != e; ++i) { - const Argument *OFA = TFI.Func->getArgumentList()[i]; - Argument *NFA = new Argument(OFA->getType(), OFA->getName()); + for (Function::const_aiterator I = TFI.Func->abegin(), E = TFI.Func->aend(); + I != E; ++I) { + Argument *NFA = new Argument(I->getType(), I->getName()); NewFunc->getArgumentList().push_back(NFA); ArgMap.push_back(NFA); // Keep track of the arguments } @@ -1457,11 +1456,13 @@ void PoolAllocate::transformFunction(TransformFunctionInfo &TFI, #ifdef DEBUG_TRANSFORM_PROGRESS cerr << "Should be argument #: " << ArgNo << "[i = " << a << "]\n"; #endif - assert(ArgNo < NewFunc->getArgumentList().size() && + assert(ArgNo < NewFunc->asize() && "Call already has pool arguments added??"); // Map the pool argument into the called function... - CalleeValue = NewFunc->getArgumentList()[ArgNo]; + Function::aiterator AI = NewFunc->abegin(); + std::advance(AI, ArgNo); + CalleeValue = AI; break; // Found value, quit loop } @@ -1501,12 +1502,12 @@ void PoolAllocate::transformFunction(TransformFunctionInfo &TFI, static unsigned countPointerTypes(const Type *Ty) { if (isa<PointerType>(Ty)) { return 1; - } else if (StructType *STy = dyn_cast<StructType>(Ty)) { + } else if (const StructType *STy = dyn_cast<StructType>(Ty)) { unsigned Num = 0; for (unsigned i = 0, e = STy->getElementTypes().size(); i != e; ++i) Num += countPointerTypes(STy->getElementTypes()[i]); return Num; - } else if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { + } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { return countPointerTypes(ATy->getElementType()); } else { assert(Ty->isPrimitiveType() && "Unknown derived type!"); @@ -1524,8 +1525,8 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // Find all of the return nodes in the function... vector<BasicBlock*> ReturnNodes; for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) - if (isa<ReturnInst>((*I)->getTerminator())) - ReturnNodes.push_back(*I); + if (isa<ReturnInst>(I->getTerminator())) + ReturnNodes.push_back(I); #ifdef DEBUG_CREATE_POOLS cerr << "Allocs that we are pool allocating:\n"; @@ -1595,11 +1596,10 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // The actual struct type could change each time through the loop, so it's // NOT loop invariant. - StructType *PoolTy = cast<StructType>(PoolTyH.get()); + const StructType *PoolTy = cast<StructType>(PoolTyH.get()); // Get the opaque type... - DerivedType *ElTy = - cast<DerivedType>(PoolTy->getElementTypes()[p+1].get()); + DerivedType *ElTy = (DerivedType*)(PoolTy->getElementTypes()[p+1].get()); #ifdef DEBUG_CREATE_POOLS cerr << "Refining " << ElTy << " of " << PoolTy << " to " @@ -1653,7 +1653,7 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // Insert it before the return instruction... BasicBlock *RetNode = ReturnNodes[EN]; - RetNode->getInstList().insert(RetNode->end()-1, Destroy); + RetNode->getInstList().insert(RetNode->end()--, Destroy); } } @@ -1683,7 +1683,7 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, } // Insert the entry node code into the entry block... - F->getEntryNode()->getInstList().insert(F->getEntryNode()->begin()+1, + F->getEntryNode().getInstList().insert(++F->getEntryNode().begin(), EntryNodeInsts.begin(), EntryNodeInsts.end()); } @@ -1692,45 +1692,43 @@ void PoolAllocate::CreatePools(Function *F, const vector<AllocDSNode*> &Allocs, // addPoolPrototypes - Add prototypes for the pool functions to the specified // module and update the Pool* instance variables to point to them. // -void PoolAllocate::addPoolPrototypes(Module *M) { +void PoolAllocate::addPoolPrototypes(Module &M) { // Get poolinit function... vector<const Type*> Args; Args.push_back(Type::UIntTy); // Num bytes per element FunctionType *PoolInitTy = FunctionType::get(Type::VoidTy, Args, true); - PoolInit = M->getOrInsertFunction("poolinit", PoolInitTy); + PoolInit = M.getOrInsertFunction("poolinit", PoolInitTy); // Get pooldestroy function... Args.pop_back(); // Only takes a pool... FunctionType *PoolDestroyTy = FunctionType::get(Type::VoidTy, Args, true); - PoolDestroy = M->getOrInsertFunction("pooldestroy", PoolDestroyTy); + PoolDestroy = M.getOrInsertFunction("pooldestroy", PoolDestroyTy); // Get the poolalloc function... FunctionType *PoolAllocTy = FunctionType::get(POINTERTYPE, Args, true); - PoolAlloc = M->getOrInsertFunction("poolalloc", PoolAllocTy); + PoolAlloc = M.getOrInsertFunction("poolalloc", PoolAllocTy); // Get the poolfree function... Args.push_back(POINTERTYPE); // Pointer to free FunctionType *PoolFreeTy = FunctionType::get(Type::VoidTy, Args, true); - PoolFree = M->getOrInsertFunction("poolfree", PoolFreeTy); + PoolFree = M.getOrInsertFunction("poolfree", PoolFreeTy); Args[0] = Type::UIntTy; // Number of slots to allocate FunctionType *PoolAllocArrayTy = FunctionType::get(POINTERTYPE, Args, true); - PoolAllocArray = M->getOrInsertFunction("poolallocarray", PoolAllocArrayTy); + PoolAllocArray = M.getOrInsertFunction("poolallocarray", PoolAllocArrayTy); } -bool PoolAllocate::run(Module *M) { +bool PoolAllocate::run(Module &M) { addPoolPrototypes(M); - CurModule = M; + CurModule = &M; DS = &getAnalysis<DataStructure>(); bool Changed = false; - // We cannot use an iterator here because it will get invalidated when we add - // functions to the module later... - for (unsigned i = 0; i != M->size(); ++i) - if (!M->getFunctionList()[i]->isExternal()) { - Changed |= processFunction(M->getFunctionList()[i]); + for (Module::iterator I = M.begin(); I != M.end(); ++I) + if (!I->isExternal()) { + Changed |= processFunction(I); if (Changed) { cerr << "Only processing one function\n"; break; diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp index 908b5b1..7f18f31 100644 --- a/lib/Transforms/IPO/SimpleStructMutation.cpp +++ b/lib/Transforms/IPO/SimpleStructMutation.cpp @@ -32,7 +32,7 @@ namespace { const char *getPassName() const { return "Simple Struct Mutation"; } - virtual bool run(Module *M) { + virtual bool run(Module &M) { setTransforms(getTransforms(M, CurrentXForm)); bool Changed = MutateStructTypes::run(M); clearTransforms(); @@ -49,7 +49,7 @@ namespace { } private: - TransformsType getTransforms(Module *M, enum Transform); + TransformsType getTransforms(Module &M, enum Transform); }; } // end anonymous namespace @@ -124,7 +124,7 @@ static inline void GetTransformation(const StructType *ST, SimpleStructMutation::TransformsType - SimpleStructMutation::getTransforms(Module *M, enum Transform XForm) { + SimpleStructMutation::getTransforms(Module &, enum Transform XForm) { // We need to know which types to modify, and which types we CAN'T modify // TODO: Do symbol tables as well diff --git a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp index f8d7616..1c09705 100644 --- a/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp +++ b/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp @@ -34,7 +34,7 @@ void getEdgeCode::getCode(Instruction *rInst, case 1:{ Value *val=ConstantSInt::get(Type::IntTy,inc); Instruction *stInst=new StoreInst(val, rInst); - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,stInst); break; } @@ -42,7 +42,7 @@ void getEdgeCode::getCode(Instruction *rInst, case 2:{ Value *val=ConstantSInt::get(Type::IntTy,0); Instruction *stInst=new StoreInst(val, rInst); - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,stInst); break; } @@ -54,9 +54,9 @@ void getEdgeCode::getCode(Instruction *rInst, create(Instruction::Add, ldInst, val,"ti2"); Instruction *stInst=new StoreInst(addIn, rInst); - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -74,9 +74,9 @@ void getEdgeCode::getCode(Instruction *rInst, StoreInst(addIn, countInst, vector<Value *> (1, ConstantUInt::get(Type::UIntTy,inc))); - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -102,12 +102,12 @@ void getEdgeCode::getCode(Instruction *rInst, StoreInst(addIn, countInst, vector<Value *>(1,castInst)); - here=instList.insert(here,ldIndex)+1; - here=instList.insert(here,addIndex)+1; - here=instList.insert(here,castInst)+1; - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldIndex); + here=++instList.insert(here,addIndex); + here=++instList.insert(here,castInst); + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -129,11 +129,11 @@ void getEdgeCode::getCode(Instruction *rInst, Instruction *stInst=new StoreInst(addIn, countInst, vector<Value *>(1,castInst2)); - here=instList.insert(here,ldIndex)+1; - here=instList.insert(here,castInst2)+1; - here=instList.insert(here,ldInst)+1; - here=instList.insert(here,addIn)+1; - here=instList.insert(here,stInst)+1; + here=++instList.insert(here,ldIndex); + here=++instList.insert(here,castInst2); + here=++instList.insert(here,ldInst); + here=++instList.insert(here,addIn); + here=++instList.insert(here,stInst); break; } @@ -175,8 +175,8 @@ void insertInTopBB(BasicBlock *front, //now push all instructions in front of the BB BasicBlock::InstListType& instList=front->getInstList(); BasicBlock::iterator here=instList.begin(); - here=front->getInstList().insert(here, rVar)+1; - here=front->getInstList().insert(here,countVar)+1; + here=++front->getInstList().insert(here, rVar); + here=++front->getInstList().insert(here,countVar); //Initialize Count[...] with 0 for(int i=0;i<k; i++){ @@ -184,10 +184,10 @@ void insertInTopBB(BasicBlock *front, StoreInst(ConstantInt::get(Type::IntTy, 0), countVar, std::vector<Value *> (1,ConstantUInt::get(Type::UIntTy, i))); - here=front->getInstList().insert(here,stInstrC)+1; + here=++front->getInstList().insert(here,stInstrC); } - here=front->getInstList().insert(here,stInstr)+1; + here=++front->getInstList().insert(here,stInstr); } @@ -226,27 +226,24 @@ void insertBB(Edge ed, Value *cond=BI->getCondition(); BasicBlock *fB, *tB; - if(BI->getSuccessor(0)==BB2){ + if (BI->getSuccessor(0) == BB2){ tB=newBB; fB=BI->getSuccessor(1); - } - else{ + } else { fB=newBB; tB=BI->getSuccessor(0); } - delete BB1->getInstList().pop_back(); - Instruction *newBI=new BranchInst(tB,fB,cond); - Instruction *newBI2=new BranchInst(BB2); - BB1->getInstList().push_back(newBI); - newBB->getInstList().push_back(newBI2); + BB1->getInstList().pop_back(); + BB1->getInstList().push_back(new BranchInst(tB,fB,cond)); + newBB->getInstList().push_back(new BranchInst(BB2)); } //now iterate over BB2, and set its Phi nodes right - for(BasicBlock::iterator BB2Inst=BB2->begin(), BBend=BB2->end(); - BB2Inst!=BBend; ++BB2Inst){ + for(BasicBlock::iterator BB2Inst = BB2->begin(), BBend = BB2->end(); + BB2Inst != BBend; ++BB2Inst){ - if(PHINode *phiInst=dyn_cast<PHINode>(*BB2Inst)){ + if(PHINode *phiInst=dyn_cast<PHINode>(&*BB2Inst)){ DEBUG(cerr<<"YYYYYYYYYYYYYYYYY\n"); int bbIndex=phiInst->getBasicBlockIndex(BB1); diff --git a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp index dcab136..42ef33c 100644 --- a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp +++ b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp @@ -37,7 +37,7 @@ using std::vector; struct ProfilePaths : public FunctionPass { const char *getPassName() const { return "ProfilePaths"; } - bool runOnFunction(Function *F); + bool runOnFunction(Function &F); // Before this pass, make sure that there is only one // entry and only one exit node for the function in the CFG of the function @@ -64,7 +64,7 @@ static Node *findBB(std::set<Node *> &st, BasicBlock *BB){ } //Per function pass for inserting counters and trigger code -bool ProfilePaths::runOnFunction(Function *M){ +bool ProfilePaths::runOnFunction(Function &F){ // Transform the cfg s.t. we have just one exit node BasicBlock *ExitNode = getAnalysis<UnifyFunctionExitNodes>().getExitNode(); @@ -78,20 +78,20 @@ bool ProfilePaths::runOnFunction(Function *M){ // That is, no two nodes must hav same BB* // First enter just nodes: later enter edges - for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){ - Node *nd=new Node(*BB); + for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB) { + Node *nd=new Node(BB); nodes.insert(nd); - if(*BB==ExitNode) + if(&*BB == ExitNode) exitNode=nd; - if(*BB==M->front()) + if(&*BB==F.begin()) startNode=nd; } // now do it againto insert edges - for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){ - Node *nd=findBB(nodes, *BB); + for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB){ + Node *nd=findBB(nodes, BB); assert(nd && "No node for this edge!"); - for(BasicBlock::succ_iterator s=succ_begin(*BB), se=succ_end(*BB); + for(BasicBlock::succ_iterator s=succ_begin(BB), se=succ_end(BB); s!=se; ++s){ Node *nd2=findBB(nodes,*s); assert(nd2 && "No node for this edge!"); @@ -104,10 +104,10 @@ bool ProfilePaths::runOnFunction(Function *M){ DEBUG(printGraph(g)); - BasicBlock *fr=M->front(); + BasicBlock *fr=&F.front(); // If only one BB, don't instrument - if (M->getBasicBlocks().size() == 1) { + if (++F.begin() == F.end()) { // The graph is made acyclic: this is done // by removing back edges for now, and adding them later on vector<Edge> be; @@ -148,7 +148,7 @@ bool ProfilePaths::runOnFunction(Function *M){ // insert initialization code in first (entry) BB // this includes initializing r and count - insertInTopBB(M->getEntryNode(),numPaths, rVar, countVar); + insertInTopBB(&F.getEntryNode(),numPaths, rVar, countVar); // now process the graph: get path numbers, // get increments along different paths, |