From b85d265b16110454a466db9e909a727b746e6c30 Mon Sep 17 00:00:00 2001 From: Anand Shukla Date: Tue, 27 Aug 2002 22:47:33 +0000 Subject: [PATCH] moved this file from lib/Reoptimizer/Mapping git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3519 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/Mapping/FInfo.cpp | 75 +++++++++++ lib/Target/SparcV9/MappingInfo.cpp | 191 +++++++++++++++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100755 lib/CodeGen/Mapping/FInfo.cpp create mode 100644 lib/Target/SparcV9/MappingInfo.cpp diff --git a/lib/CodeGen/Mapping/FInfo.cpp b/lib/CodeGen/Mapping/FInfo.cpp new file mode 100755 index 00000000000..504baec154f --- /dev/null +++ b/lib/CodeGen/Mapping/FInfo.cpp @@ -0,0 +1,75 @@ +#include "llvm/Reoptimizer/Mapping/FInfo.h" +#include "llvm/Pass.h" +#include "llvm/Module.h" + + +namespace { + class FunctionInfo : public Pass { + std::ostream &Out; + public: + FunctionInfo(std::ostream &out) : Out(out){} + const char* getPassName() const{return "Sparc FunctionInfo";} + bool run(Module &M); + private: + void FunctionInfo::writePrologue(const char *area, + const char *label); + void FunctionInfo::writeEpilogue(const char *area, + const char *label); + }; +} + +Pass *getFunctionInfo(std::ostream &out){ + return new FunctionInfo(out); +} + +bool FunctionInfo::run(Module &M){ + unsigned f; + + writePrologue("FUNCTION MAP", "FunctionBB"); + f=0; + for(Module::iterator FI=M.begin(), FE=M.end(); FE!=FI; ++FI){ + if(FI->isExternal()) continue; + Out << "\t.xword BBMIMap"<isExternal()) continue; + Out << "\t.xword LMIMap"< +using std::vector; + + +// MappingInfo - This method collects mapping info +// for the mapping from LLVM to machine code. +// +namespace { + class getMappingInfoForFunction : public FunctionPass { + std::ostream &Out; + public: + getMappingInfoForFunction(std::ostream &out) : Out(out){} + const char* getPassName() const{return "Sparc MappingInformation";} + bool runOnFunction(Function &FI); + private: + std::map Fkey; //key of F to num + std::map BBkey; //key BB to num + std::map MIkey; //key MI to num + + bool doInitialization(Module &M); + void create_BB_to_MInumber_Key(Function &FI); + void create_MI_to_number_Key(Function &FI); + void writeBBToMImap(Function &FI); + void writeLLVMToMImap(Function &FI); + void getMappingInfoForFunction::writePrologue(const char * area, + const char *label, + unsigned FunctionNo); + void getMappingInfoForFunction::writeEpilogue(const char *area, + const char *label, + unsigned FunctionNo); + unsigned writeNumber(unsigned X); + }; +} + + +//pass definition +Pass *MappingInfoForFunction(std::ostream &out){ + return (new getMappingInfoForFunction(out)); +} + +//function definitions : +//create and output maps to the .s file +bool getMappingInfoForFunction::runOnFunction(Function &FI) { + + + //first create reference maps + //createFunctionKey(M); + create_BB_to_MInumber_Key(FI); + create_MI_to_number_Key(FI); + unsigned FunctionNo = Fkey[&(FI)]; + + //now print out the maps + writePrologue("BB TO MI MAP", "BBMIMap", FunctionNo); + writeBBToMImap(FI); + writeEpilogue("BB TO MI MAP", "BBMIMap", FunctionNo); + + writePrologue("LLVM I TO MI MAP", "LMIMap", FunctionNo); + writeLLVMToMImap(FI); + writeEpilogue("LLVM I TO MI MAP", "LMIMap", FunctionNo); + return false; +} + +void getMappingInfoForFunction::writePrologue(const char *area, + const char *label, + unsigned FunctionNo){ + Out << "!" << area << "\n"; + Out << "\t.section \".rodata\"\n\t.align 8\n"; + Out << "\t.global " << label << FunctionNo << "\n"; + Out << "\t.type " << label << FunctionNo << ",#object\n"; + Out << label << FunctionNo << ":\n"; + Out << "\t.word .end_" << label << FunctionNo << "-" + << label << FunctionNo << "\n"; +} + +void getMappingInfoForFunction::writeEpilogue(const char *area, + const char *label, + unsigned FunctionNo){ + Out << ".end_" << label << FunctionNo << ":\n"; + Out << "\t.size " << label << FunctionNo << ", .end_" + << label << FunctionNo << "-" << label + << FunctionNo << "\n\n\n\n"; +} + +//write out information as .byte directives +unsigned getMappingInfoForFunction::writeNumber(unsigned X) { + unsigned i=0; + do { + unsigned tmp = X & 127; + X >>= 7; + if (X) tmp |= 128; + Out << "\t.byte " << tmp << "\n"; + ++i; + } while(X); + return i; +} + +//Assign a number to each Function +bool getMappingInfoForFunction::doInitialization(Module &M){ + unsigned i = 0; + for (Module::iterator FI = M.begin(), FE = M.end(); + FI != FE; ++FI){ + //dont count F with 0 BBs + if(FI->isExternal()) continue; + Fkey[FI] = i; + ++i; + } + return false; +} + +//Assign a Number to each BB +void getMappingInfoForFunction::create_BB_to_MInumber_Key(Function &FI){ + unsigned i = 0; + for (Function::iterator BI = FI.begin(), BE = FI.end(); + BI != BE; ++BI){ + MachineCodeForBasicBlock &miBB = MachineCodeForBasicBlock::get(BI); + BBkey[miBB[0]] = i; + i = i+(miBB.size()); + } +} + +//Assign a number to each MI wrt beginning of the BB +void getMappingInfoForFunction::create_MI_to_number_Key(Function &FI){ + for (Function::iterator BI=FI.begin(), BE=FI.end(); + BI != BE; ++BI){ + MachineCodeForBasicBlock &miBB = MachineCodeForBasicBlock::get(BI); + unsigned j = 0; + for(MachineCodeForBasicBlock::iterator miI=miBB.begin(), miE=miBB.end(); + miI!=miE; ++miI, ++j){ + MIkey[*miI]=j; + } + } +} + +//BBtoMImap: contains F#, BB#, +// MI#[wrt beginning of F], #MI in BB +void getMappingInfoForFunction::writeBBToMImap(Function &FI){ + unsigned bb=0; + for (Function::iterator BI = FI.begin(), + BE = FI.end(); BI != BE; ++BI, ++bb){ + MachineCodeForBasicBlock &miBB = MachineCodeForBasicBlock::get(BI); + writeNumber(bb); + //Out << " BB: "<<(void *)BI<<"\n"; + //for(int i=0; isize()); + for (BasicBlock::iterator II = BI->begin(), + IE = BI->end(); II != IE; ++II, ++li){ + //Out << "I: "<<*II<<"\n"; + MachineCodeForInstruction& miI = + MachineCodeForInstruction::get(II); + + //do for each corr. MI + writeNumber(li); + writeNumber(miI.size()); + for (MachineCodeForInstruction::iterator miII = miI.begin(), + miIE = miI.end(); miII != miIE; ++miII){ + //Out << "MI: "<<**miII<<"\n"; + writeNumber(MIkey[*miII]); + } + } + } +}