Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 1 | //===- MappingInfo.cpp - create LLVM info and output to .s file ---------===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame^] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 9 | // |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 10 | // This file contains a FunctionPass called MappingInfoAsmPrinter, |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 11 | // which creates two maps: one between LLVM Instructions and MachineInstrs |
| 12 | // (the "LLVM I TO MI MAP"), and another between MachineBasicBlocks and |
| 13 | // MachineInstrs (the "BB TO MI MAP"). |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 14 | // |
| 15 | // As a side effect, it outputs this information as .byte directives to |
| 16 | // the assembly file. The output is designed to survive the SPARC assembler, |
| 17 | // in order that the Reoptimizer may read it in from memory later when the |
| 18 | // binary is loaded. Therefore, it may contain some hidden SPARC-architecture |
| 19 | // dependencies. Currently this question is purely theoretical as the |
| 20 | // Reoptimizer works only on the SPARC. |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 21 | // |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 22 | // The LLVM I TO MI MAP consists of a set of information for each |
| 23 | // BasicBlock in a Function, ordered from begin() to end(). The information |
| 24 | // for a BasicBlock consists of |
| 25 | // 1) its (0-based) index in the Function, |
| 26 | // 2) the number of LLVM Instructions it contains, and |
| 27 | // 3) information for each Instruction, in sequence from the begin() |
| 28 | // to the end() of the BasicBlock. The information for an Instruction |
| 29 | // consists of |
| 30 | // 1) its (0-based) index in the BasicBlock, |
| 31 | // 2) the number of MachineInstrs that correspond to that Instruction |
| 32 | // (as reported by MachineCodeForInstruction), and |
| 33 | // 3) the MachineInstr number calculated by create_MI_to_number_Key, |
| 34 | // for each of the MachineInstrs that correspond to that Instruction. |
| 35 | // |
| 36 | // The BB TO MI MAP consists of a three-element tuple for each |
| 37 | // MachineBasicBlock in a function, ordered from begin() to end() of |
| 38 | // its MachineFunction: first, the index of the MachineBasicBlock in the |
| 39 | // function; second, the number of the MachineBasicBlock in the function |
| 40 | // as computed by create_BB_to_MInumber_Key; and third, the number of |
| 41 | // MachineInstrs in the MachineBasicBlock. |
| 42 | // |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 43 | //===--------------------------------------------------------------------===// |
| 44 | |
Chris Lattner | 48e6079 | 2003-08-13 02:38:16 +0000 | [diff] [blame] | 45 | #include "MappingInfo.h" |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 46 | #include "llvm/Pass.h" |
| 47 | #include "llvm/Module.h" |
Misha Brukman | b7551ef | 2002-10-28 20:00:31 +0000 | [diff] [blame] | 48 | #include "llvm/CodeGen/MachineFunction.h" |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 49 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 50 | #include "Support/StringExtras.h" |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 51 | |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 52 | namespace { |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 53 | class MappingInfoAsmPrinter : public FunctionPass { |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 54 | std::ostream &Out; |
| 55 | public: |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 56 | MappingInfoAsmPrinter(std::ostream &out) : Out(out){} |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 57 | const char *getPassName () const { return "Instr. Mapping Info Collector"; } |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 58 | bool runOnFunction(Function &FI); |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 59 | typedef std::map<const MachineInstr*, unsigned> InstructionKey; |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 60 | private: |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 61 | MappingInfo *currentOutputMap; |
| 62 | std::map<Function *, unsigned> Fkey; // Function # for all functions. |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 63 | bool doInitialization(Module &M); |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 64 | void create_BB_to_MInumber_Key(Function &FI, InstructionKey &key); |
| 65 | void create_MI_to_number_Key(Function &FI, InstructionKey &key); |
| 66 | void buildBBMIMap (Function &FI, MappingInfo &Map); |
| 67 | void buildLMIMap (Function &FI, MappingInfo &Map); |
| 68 | void writeNumber(unsigned X); |
| 69 | void selectOutputMap (MappingInfo &m) { currentOutputMap = &m; } |
| 70 | void outByte (unsigned char b) { currentOutputMap->outByte (b); } |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 71 | bool doFinalization (Module &M); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 72 | }; |
| 73 | } |
| 74 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 75 | /// getMappingInfoAsmPrinterPass - Static factory method: returns a new |
| 76 | /// MappingInfoAsmPrinter Pass object, which uses OUT as its output |
| 77 | /// stream for assembly output. |
| 78 | /// |
| 79 | Pass *getMappingInfoAsmPrinterPass(std::ostream &out){ |
| 80 | return (new MappingInfoAsmPrinter(out)); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 83 | /// runOnFunction - Builds up the maps for the given function FI and then |
Brian Gaeke | fc97c8b | 2003-06-03 19:30:15 +0000 | [diff] [blame] | 84 | /// writes them out as assembly code to the current output stream OUT. |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 85 | /// This is an entry point to the pass, called by the PassManager. |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 86 | /// |
| 87 | bool MappingInfoAsmPrinter::runOnFunction(Function &FI) { |
Brian Gaeke | fc97c8b | 2003-06-03 19:30:15 +0000 | [diff] [blame] | 88 | unsigned num = Fkey[&FI]; // Function number for the current function. |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 89 | |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 90 | // Create objects to hold the maps. |
| 91 | MappingInfo LMIMap ("LLVM I TO MI MAP", "LMIMap", num); |
| 92 | MappingInfo BBMIMap ("BB TO MI MAP", "BBMIMap", num); |
| 93 | |
| 94 | // Now, build the maps. |
| 95 | buildLMIMap (FI, LMIMap); |
| 96 | buildBBMIMap (FI, BBMIMap); |
| 97 | |
Brian Gaeke | fc97c8b | 2003-06-03 19:30:15 +0000 | [diff] [blame] | 98 | // Now, write out the maps. |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 99 | LMIMap.dumpAssembly (Out); |
| 100 | BBMIMap.dumpAssembly (Out); |
Brian Gaeke | fc97c8b | 2003-06-03 19:30:15 +0000 | [diff] [blame] | 101 | |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 102 | return false; |
| 103 | } |
| 104 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 105 | /// writeNumber - Write out the number X as a sequence of .byte |
Brian Gaeke | fc97c8b | 2003-06-03 19:30:15 +0000 | [diff] [blame] | 106 | /// directives to the current output stream Out. This method performs a |
| 107 | /// run-length encoding of the unsigned integers X that are output. |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 108 | /// |
| 109 | void MappingInfoAsmPrinter::writeNumber(unsigned X) { |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 110 | unsigned i=0; |
| 111 | do { |
| 112 | unsigned tmp = X & 127; |
| 113 | X >>= 7; |
| 114 | if (X) tmp |= 128; |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 115 | outByte (tmp); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 116 | ++i; |
| 117 | } while(X); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 120 | /// doInitialization - Assign a number to each Function, as follows: |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 121 | /// Functions are numbered starting at 0 at the begin() of each Module. |
| 122 | /// Functions which are External (and thus have 0 basic blocks) are not |
| 123 | /// inserted into the maps, and are not assigned a number. The side-effect |
| 124 | /// of this method is to fill in Fkey to contain the mapping from Functions |
| 125 | /// to numbers. (This method is called automatically by the PassManager.) |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 126 | /// |
| 127 | bool MappingInfoAsmPrinter::doInitialization(Module &M) { |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 128 | unsigned i = 0; |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 129 | for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) { |
| 130 | if (FI->isExternal()) continue; |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 131 | Fkey[FI] = i; |
| 132 | ++i; |
| 133 | } |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 134 | return false; // Success. |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 135 | } |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 136 | |
| 137 | /// create_BB_to_MInumber_Key -- Assign a number to each MachineBasicBlock |
| 138 | /// in the given Function, as follows: Numbering starts at zero in each |
| 139 | /// Function. MachineBasicBlocks are numbered from begin() to end() |
| 140 | /// in the Function's corresponding MachineFunction. Each successive |
| 141 | /// MachineBasicBlock increments the numbering by the number of instructions |
Misha Brukman | cf00c4a | 2003-10-10 17:57:28 +0000 | [diff] [blame] | 142 | /// it contains. The side-effect of this method is to fill in the parameter |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 143 | /// KEY with the mapping of MachineBasicBlocks to numbers. KEY |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 144 | /// is keyed on MachineInstrs, so each MachineBasicBlock is represented |
| 145 | /// therein by its first MachineInstr. |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 146 | /// |
| 147 | void MappingInfoAsmPrinter::create_BB_to_MInumber_Key(Function &FI, |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 148 | InstructionKey &key) { |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 149 | unsigned i = 0; |
Misha Brukman | b7551ef | 2002-10-28 20:00:31 +0000 | [diff] [blame] | 150 | MachineFunction &MF = MachineFunction::get(&FI); |
| 151 | for (MachineFunction::iterator BI = MF.begin(), BE = MF.end(); |
| 152 | BI != BE; ++BI) { |
| 153 | MachineBasicBlock &miBB = *BI; |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 154 | key[miBB[0]] = i; |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 155 | i = i+(miBB.size()); |
| 156 | } |
| 157 | } |
| 158 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 159 | /// create_MI_to_number_Key - Assign a number to each MachineInstr |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 160 | /// in the given Function with respect to its enclosing MachineBasicBlock, as |
| 161 | /// follows: Numberings start at 0 in each MachineBasicBlock. MachineInstrs |
| 162 | /// are numbered from begin() to end() in their MachineBasicBlock. Each |
| 163 | /// MachineInstr is numbered, then the numbering is incremented by 1. The |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 164 | /// side-effect of this method is to fill in the parameter KEY |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 165 | /// with the mapping from MachineInstrs to numbers. |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 166 | /// |
| 167 | void MappingInfoAsmPrinter::create_MI_to_number_Key(Function &FI, |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 168 | InstructionKey &key) { |
Misha Brukman | b7551ef | 2002-10-28 20:00:31 +0000 | [diff] [blame] | 169 | MachineFunction &MF = MachineFunction::get(&FI); |
| 170 | for (MachineFunction::iterator BI=MF.begin(), BE=MF.end(); BI != BE; ++BI) { |
| 171 | MachineBasicBlock &miBB = *BI; |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 172 | unsigned j = 0; |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 173 | for(MachineBasicBlock::iterator miI = miBB.begin(), miE = miBB.end(); |
| 174 | miI != miE; ++miI, ++j) { |
| 175 | key[*miI] = j; |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 180 | /// buildBBMIMap - Build the BB TO MI MAP for the function FI, |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 181 | /// and save it into the parameter MAP. |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 182 | /// |
| 183 | void MappingInfoAsmPrinter::buildBBMIMap(Function &FI, MappingInfo &Map) { |
Misha Brukman | b7551ef | 2002-10-28 20:00:31 +0000 | [diff] [blame] | 184 | unsigned bb = 0; |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 185 | |
| 186 | // First build temporary table used to write out the map. |
| 187 | InstructionKey BBkey; |
| 188 | create_BB_to_MInumber_Key(FI, BBkey); |
| 189 | |
| 190 | selectOutputMap (Map); |
Misha Brukman | b7551ef | 2002-10-28 20:00:31 +0000 | [diff] [blame] | 191 | MachineFunction &MF = MachineFunction::get(&FI); |
| 192 | for (MachineFunction::iterator BI = MF.begin(), BE = MF.end(); |
| 193 | BI != BE; ++BI, ++bb) { |
| 194 | MachineBasicBlock &miBB = *BI; |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 195 | writeNumber(bb); |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 196 | writeNumber(BBkey[miBB[0]]); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 197 | writeNumber(miBB.size()); |
| 198 | } |
| 199 | } |
| 200 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 201 | /// buildLMIMap - Build the LLVM I TO MI MAP for the function FI, |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 202 | /// and save it into the parameter MAP. |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 203 | /// |
| 204 | void MappingInfoAsmPrinter::buildLMIMap(Function &FI, MappingInfo &Map) { |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 205 | unsigned bb = 0; |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 206 | // First build temporary table used to write out the map. |
| 207 | InstructionKey MIkey; |
| 208 | create_MI_to_number_Key(FI, MIkey); |
| 209 | |
| 210 | selectOutputMap (Map); |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 211 | for (Function::iterator BI = FI.begin(), BE = FI.end(); |
Misha Brukman | b7551ef | 2002-10-28 20:00:31 +0000 | [diff] [blame] | 212 | BI != BE; ++BI, ++bb) { |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 213 | unsigned li = 0; |
| 214 | writeNumber(bb); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 215 | writeNumber(BI->size()); |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 216 | for (BasicBlock::iterator II = BI->begin(), IE = BI->end(); II != IE; |
| 217 | ++II, ++li) { |
| 218 | MachineCodeForInstruction& miI = MachineCodeForInstruction::get(II); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 219 | writeNumber(li); |
Anand Shukla | b379470 | 2002-09-17 20:24:46 +0000 | [diff] [blame] | 220 | writeNumber(miI.size()); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 221 | for (MachineCodeForInstruction::iterator miII = miI.begin(), |
Brian Gaeke | e14ccaf | 2003-06-03 07:56:05 +0000 | [diff] [blame] | 222 | miIE = miI.end(); miII != miIE; ++miII) { |
| 223 | writeNumber(MIkey[*miII]); |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | } |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void MappingInfo::byteVector::dumpAssembly (std::ostream &Out) { |
| 230 | for (iterator i = begin (), e = end (); i != e; ++i) |
| 231 | Out << ".byte " << (int)*i << "\n"; |
| 232 | } |
| 233 | |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 234 | static void writePrologue (std::ostream &Out, const std::string &comment, |
| 235 | const std::string &symName) { |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 236 | // Prologue: |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 237 | // Output a comment describing the object. |
Brian Gaeke | aeab1e1 | 2003-06-04 22:07:12 +0000 | [diff] [blame] | 238 | Out << "!" << comment << "\n"; |
| 239 | // Switch the current section to .rodata in the assembly output: |
| 240 | Out << "\t.section \".rodata\"\n\t.align 8\n"; |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 241 | // Output a global symbol naming the object: |
| 242 | Out << "\t.global " << symName << "\n"; |
| 243 | Out << "\t.type " << symName << ",#object\n"; |
| 244 | Out << symName << ":\n"; |
Anand Shukla | b85d265 | 2002-08-27 22:47:33 +0000 | [diff] [blame] | 245 | } |
Brian Gaeke | 866dc1d | 2003-09-18 17:37:25 +0000 | [diff] [blame] | 246 | |
| 247 | static void writeEpilogue (std::ostream &Out, const std::string &symName) { |
| 248 | // Epilogue: |
| 249 | // Output a local symbol marking the end of the object: |
| 250 | Out << ".end_" << symName << ":\n"; |
| 251 | // Output size directive giving the size of the object: |
| 252 | Out << "\t.size " << symName << ", .end_" << symName << "-" << symName |
| 253 | << "\n"; |
| 254 | } |
| 255 | |
| 256 | void MappingInfo::dumpAssembly (std::ostream &Out) { |
| 257 | const std::string &name (symbolPrefix + utostr (functionNumber)); |
| 258 | writePrologue (Out, comment, name); |
| 259 | // The LMIMap and BBMIMap are supposed to start with a length word: |
| 260 | Out << "\t.word .end_" << name << "-" << name << "\n"; |
| 261 | bytes.dumpAssembly (Out); |
| 262 | writeEpilogue (Out, name); |
| 263 | } |
| 264 | |
| 265 | /// doFinalization - This method writes out two tables, named |
| 266 | /// FunctionBB and FunctionLI, which map Function numbers (as in |
| 267 | /// doInitialization) to the BBMIMap and LMIMap tables. (This used to |
| 268 | /// be the "FunctionInfo" pass.) |
| 269 | /// |
| 270 | bool MappingInfoAsmPrinter::doFinalization (Module &M) { |
| 271 | unsigned f; |
| 272 | |
| 273 | writePrologue(Out, "FUNCTION TO BB MAP", "FunctionBB"); |
| 274 | f=0; |
| 275 | for(Module::iterator FI = M.begin (), FE = M.end (); FE != FI; ++FI) { |
| 276 | if (FI->isExternal ()) |
| 277 | continue; |
| 278 | Out << "\t.xword BBMIMap" << f << "\n"; |
| 279 | ++f; |
| 280 | } |
| 281 | writeEpilogue(Out, "FunctionBB"); |
| 282 | |
| 283 | writePrologue(Out, "FUNCTION TO LI MAP", "FunctionLI"); |
| 284 | f=0; |
| 285 | for(Module::iterator FI = M.begin (), FE = M.end (); FE != FI; ++FI) { |
| 286 | if (FI->isExternal ()) |
| 287 | continue; |
| 288 | Out << "\t.xword LMIMap" << f << "\n"; |
| 289 | ++f; |
| 290 | } |
| 291 | writeEpilogue(Out, "FunctionLI"); |
| 292 | |
| 293 | return false; |
| 294 | } |
| 295 | |