diff options
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r-- | llvm/lib/Target/Sparc/EmitAssembly.cpp | 64 | ||||
-rw-r--r-- | llvm/lib/Target/Sparc/EmitBytecodeToAssembly.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/Sparc/PrologEpilogCodeInserter.cpp | 58 | ||||
-rw-r--r-- | llvm/lib/Target/Sparc/Sparc.cpp | 29 | ||||
-rw-r--r-- | llvm/lib/Target/Sparc/SparcRegInfo.cpp | 52 |
5 files changed, 97 insertions, 110 deletions
diff --git a/llvm/lib/Target/Sparc/EmitAssembly.cpp b/llvm/lib/Target/Sparc/EmitAssembly.cpp index db5b6cd7250..b0eb21eab62 100644 --- a/llvm/lib/Target/Sparc/EmitAssembly.cpp +++ b/llvm/lib/Target/Sparc/EmitAssembly.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/llvm/lib/Target/Sparc/EmitBytecodeToAssembly.cpp b/llvm/lib/Target/Sparc/EmitBytecodeToAssembly.cpp index fdf8f3ec361..141361d1e3c 100644 --- a/llvm/lib/Target/Sparc/EmitBytecodeToAssembly.cpp +++ b/llvm/lib/Target/Sparc/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/llvm/lib/Target/Sparc/PrologEpilogCodeInserter.cpp b/llvm/lib/Target/Sparc/PrologEpilogCodeInserter.cpp index b42e7771567..72431499fb5 100644 --- a/llvm/lib/Target/Sparc/PrologEpilogCodeInserter.cpp +++ b/llvm/lib/Target/Sparc/PrologEpilogCodeInserter.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/llvm/lib/Target/Sparc/Sparc.cpp b/llvm/lib/Target/Sparc/Sparc.cpp index fecdf23e29a..be6e9f4670d 100644 --- a/llvm/lib/Target/Sparc/Sparc.cpp +++ b/llvm/lib/Target/Sparc/Sparc.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/llvm/lib/Target/Sparc/SparcRegInfo.cpp b/llvm/lib/Target/Sparc/SparcRegInfo.cpp index a86e4f93845..6aa4d816264 100644 --- a/llvm/lib/Target/Sparc/SparcRegInfo.cpp +++ b/llvm/lib/Target/Sparc/SparcRegInfo.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 ); |