OLD | NEW |
1 //===-- NVPTXAsmPrinter.h - NVPTX LLVM assembly writer --------------------===// | 1 //===-- NVPTXAsmPrinter.h - NVPTX LLVM assembly writer --------------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file contains a printer that converts from our internal representation | 10 // This file contains a printer that converts from our internal representation |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // are filled with 0s. symbolPosInBuffer[i-1] records its position | 84 // are filled with 0s. symbolPosInBuffer[i-1] records its position |
85 // in 'buffer', and Symbols[i-1] records the Value*. | 85 // in 'buffer', and Symbols[i-1] records the Value*. |
86 // | 86 // |
87 // Once we have this AggBuffer setup, we can choose how to print | 87 // Once we have this AggBuffer setup, we can choose how to print |
88 // it out. | 88 // it out. |
89 public: | 89 public: |
90 unsigned size; // size of the buffer in bytes | 90 unsigned size; // size of the buffer in bytes |
91 unsigned char *buffer; // the buffer | 91 unsigned char *buffer; // the buffer |
92 unsigned numSymbols; // number of symbol addresses | 92 unsigned numSymbols; // number of symbol addresses |
93 SmallVector<unsigned, 4> symbolPosInBuffer; | 93 SmallVector<unsigned, 4> symbolPosInBuffer; |
94 SmallVector<const Value *, 4> Symbols; | 94 SmallVector<Value *, 4> Symbols; |
95 | 95 |
96 private: | 96 private: |
97 unsigned curpos; | 97 unsigned curpos; |
98 raw_ostream &O; | 98 raw_ostream &O; |
99 NVPTXAsmPrinter &AP; | 99 NVPTXAsmPrinter &AP; |
100 | 100 |
101 public: | 101 public: |
102 AggBuffer(unsigned _size, raw_ostream &_O, NVPTXAsmPrinter &_AP) | 102 AggBuffer(unsigned _size, raw_ostream &_O, NVPTXAsmPrinter &_AP) |
103 : O(_O), AP(_AP) { | 103 : O(_O), AP(_AP) { |
104 buffer = new unsigned char[_size]; | 104 buffer = new unsigned char[_size]; |
(...skipping 16 matching lines...) Expand all Loading... |
121 return curpos; | 121 return curpos; |
122 } | 122 } |
123 unsigned addZeros(int Num) { | 123 unsigned addZeros(int Num) { |
124 assert((curpos + Num) <= size); | 124 assert((curpos + Num) <= size); |
125 for (int i = 0; i < Num; ++i) { | 125 for (int i = 0; i < Num; ++i) { |
126 buffer[curpos] = 0; | 126 buffer[curpos] = 0; |
127 curpos++; | 127 curpos++; |
128 } | 128 } |
129 return curpos; | 129 return curpos; |
130 } | 130 } |
131 void addSymbol(const Value *GVar) { | 131 void addSymbol(Value *GVar) { |
132 symbolPosInBuffer.push_back(curpos); | 132 symbolPosInBuffer.push_back(curpos); |
133 Symbols.push_back(GVar); | 133 Symbols.push_back(GVar); |
134 numSymbols++; | 134 numSymbols++; |
135 } | 135 } |
136 void print() { | 136 void print() { |
137 if (numSymbols == 0) { | 137 if (numSymbols == 0) { |
138 // print out in bytes | 138 // print out in bytes |
139 for (unsigned i = 0; i < size; i++) { | 139 for (unsigned i = 0; i < size; i++) { |
140 if (i) | 140 if (i) |
141 O << ", "; | 141 O << ", "; |
142 O << (unsigned int) buffer[i]; | 142 O << (unsigned int) buffer[i]; |
143 } | 143 } |
144 } else { | 144 } else { |
145 // print out in 4-bytes or 8-bytes | 145 // print out in 4-bytes or 8-bytes |
146 unsigned int pos = 0; | 146 unsigned int pos = 0; |
147 unsigned int nSym = 0; | 147 unsigned int nSym = 0; |
148 unsigned int nextSymbolPos = symbolPosInBuffer[nSym]; | 148 unsigned int nextSymbolPos = symbolPosInBuffer[nSym]; |
149 unsigned int nBytes = 4; | 149 unsigned int nBytes = 4; |
150 if (AP.nvptxSubtarget.is64Bit()) | 150 if (AP.nvptxSubtarget.is64Bit()) |
151 nBytes = 8; | 151 nBytes = 8; |
152 for (pos = 0; pos < size; pos += nBytes) { | 152 for (pos = 0; pos < size; pos += nBytes) { |
153 if (pos) | 153 if (pos) |
154 O << ", "; | 154 O << ", "; |
155 if (pos == nextSymbolPos) { | 155 if (pos == nextSymbolPos) { |
156 const Value *v = Symbols[nSym]; | 156 Value *v = Symbols[nSym]; |
157 if (const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) { | 157 if (GlobalValue *GVar = dyn_cast<GlobalValue>(v)) { |
158 MCSymbol *Name = AP.Mang->getSymbol(GVar); | 158 MCSymbol *Name = AP.Mang->getSymbol(GVar); |
159 O << *Name; | 159 O << *Name; |
160 } else if (const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(v)) { | 160 } else if (ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(v)) { |
161 O << *nvptx::LowerConstant(Cexpr, AP); | 161 O << *nvptx::LowerConstant(Cexpr, AP); |
162 } else | 162 } else |
163 llvm_unreachable("symbol type unknown"); | 163 llvm_unreachable("symbol type unknown"); |
164 nSym++; | 164 nSym++; |
165 if (nSym >= numSymbols) | 165 if (nSym >= numSymbols) |
166 nextSymbolPos = size + 1; | 166 nextSymbolPos = size + 1; |
167 else | 167 else |
168 nextSymbolPos = symbolPosInBuffer[nSym]; | 168 nextSymbolPos = symbolPosInBuffer[nSym]; |
169 } else if (nBytes == 4) | 169 } else if (nBytes == 4) |
170 O << *(unsigned int *)(buffer + pos); | 170 O << *(unsigned int *)(buffer + pos); |
(...skipping 27 matching lines...) Expand all Loading... |
198 const char *Modifier = 0); | 198 const char *Modifier = 0); |
199 void printLdStCode(const MachineInstr *MI, int opNum, raw_ostream &O, | 199 void printLdStCode(const MachineInstr *MI, int opNum, raw_ostream &O, |
200 const char *Modifier = 0); | 200 const char *Modifier = 0); |
201 void printVecModifiedImmediate(const MachineOperand &MO, const char *Modifier, | 201 void printVecModifiedImmediate(const MachineOperand &MO, const char *Modifier, |
202 raw_ostream &O); | 202 raw_ostream &O); |
203 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O, | 203 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O, |
204 const char *Modifier = 0); | 204 const char *Modifier = 0); |
205 void printImplicitDef(const MachineInstr *MI, raw_ostream &O) const; | 205 void printImplicitDef(const MachineInstr *MI, raw_ostream &O) const; |
206 // definition autogenerated. | 206 // definition autogenerated. |
207 void printInstruction(const MachineInstr *MI, raw_ostream &O); | 207 void printInstruction(const MachineInstr *MI, raw_ostream &O); |
208 void printModuleLevelGV(const GlobalVariable *GVar, raw_ostream &O, | 208 void printModuleLevelGV(GlobalVariable *GVar, raw_ostream &O, bool = false); |
209 bool = false); | |
210 void printParamName(int paramIndex, raw_ostream &O); | 209 void printParamName(int paramIndex, raw_ostream &O); |
211 void printParamName(Function::const_arg_iterator I, int paramIndex, | 210 void printParamName(Function::const_arg_iterator I, int paramIndex, |
212 raw_ostream &O); | 211 raw_ostream &O); |
213 void emitGlobals(const Module &M); | |
214 void emitHeader(Module &M, raw_ostream &O); | 212 void emitHeader(Module &M, raw_ostream &O); |
215 void emitKernelFunctionDirectives(const Function &F, raw_ostream &O) const; | 213 void emitKernelFunctionDirectives(const Function &F, raw_ostream &O) const; |
216 void emitVirtualRegister(unsigned int vr, bool isVec, raw_ostream &O); | 214 void emitVirtualRegister(unsigned int vr, bool isVec, raw_ostream &O); |
217 void emitFunctionExternParamList(const MachineFunction &MF); | 215 void emitFunctionExternParamList(const MachineFunction &MF); |
218 void emitFunctionParamList(const Function *, raw_ostream &O); | 216 void emitFunctionParamList(const Function *, raw_ostream &O); |
219 void emitFunctionParamList(const MachineFunction &MF, raw_ostream &O); | 217 void emitFunctionParamList(const MachineFunction &MF, raw_ostream &O); |
220 void setAndEmitFunctionVirtualRegisters(const MachineFunction &MF); | 218 void setAndEmitFunctionVirtualRegisters(const MachineFunction &MF); |
221 void emitFunctionTempData(const MachineFunction &MF, unsigned &FrameSize); | 219 void emitFunctionTempData(const MachineFunction &MF, unsigned &FrameSize); |
222 bool isImageType(const Type *Ty); | 220 bool isImageType(const Type *Ty); |
223 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, | 221 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
224 unsigned AsmVariant, const char *ExtraCode, | 222 unsigned AsmVariant, const char *ExtraCode, |
225 raw_ostream &); | 223 raw_ostream &); |
226 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, | 224 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
227 unsigned AsmVariant, const char *ExtraCode, | 225 unsigned AsmVariant, const char *ExtraCode, |
228 raw_ostream &); | 226 raw_ostream &); |
229 void printReturnValStr(const Function *, raw_ostream &O); | 227 void printReturnValStr(const Function *, raw_ostream &O); |
230 void printReturnValStr(const MachineFunction &MF, raw_ostream &O); | 228 void printReturnValStr(const MachineFunction &MF, raw_ostream &O); |
231 | 229 |
232 protected: | 230 protected: |
233 bool doInitialization(Module &M); | 231 bool doInitialization(Module &M); |
234 bool doFinalization(Module &M); | 232 bool doFinalization(Module &M); |
235 | 233 |
236 private: | 234 private: |
237 std::string CurrentBankselLabelInBasicBlock; | 235 std::string CurrentBankselLabelInBasicBlock; |
238 | 236 |
239 bool GlobalsEmitted; | |
240 | |
241 // This is specific per MachineFunction. | 237 // This is specific per MachineFunction. |
242 const MachineRegisterInfo *MRI; | 238 const MachineRegisterInfo *MRI; |
243 // The contents are specific for each | 239 // The contents are specific for each |
244 // MachineFunction. But the size of the | 240 // MachineFunction. But the size of the |
245 // array is not. | 241 // array is not. |
246 std::map<unsigned, unsigned> *VRidGlobal2LocalMap; | 242 std::map<unsigned, unsigned> *VRidGlobal2LocalMap; |
247 // cache the subtarget here. | 243 // cache the subtarget here. |
248 const NVPTXSubtarget &nvptxSubtarget; | 244 const NVPTXSubtarget &nvptxSubtarget; |
249 // Build the map between type name and ID based on module's type | 245 // Build the map between type name and ID based on module's type |
250 // symbol table. | 246 // symbol table. |
251 std::map<const Type *, std::string> TypeNameMap; | 247 std::map<const Type *, std::string> TypeNameMap; |
252 | 248 |
253 // List of variables demoted to a function scope. | 249 // List of variables demoted to a function scope. |
254 std::map<const Function *, std::vector<const GlobalVariable *> > localDecls; | 250 std::map<const Function *, std::vector<GlobalVariable *> > localDecls; |
255 | 251 |
256 // To record filename to ID mapping | 252 // To record filename to ID mapping |
257 std::map<std::string, unsigned> filenameMap; | 253 std::map<std::string, unsigned> filenameMap; |
258 void recordAndEmitFilenames(Module &); | 254 void recordAndEmitFilenames(Module &); |
259 | 255 |
260 void emitPTXGlobalVariable(const GlobalVariable *GVar, raw_ostream &O); | 256 void emitPTXGlobalVariable(const GlobalVariable *GVar, raw_ostream &O); |
261 void emitPTXAddressSpace(unsigned int AddressSpace, raw_ostream &O) const; | 257 void emitPTXAddressSpace(unsigned int AddressSpace, raw_ostream &O) const; |
262 std::string getPTXFundamentalTypeStr(const Type *Ty, bool = true) const; | 258 std::string getPTXFundamentalTypeStr(const Type *Ty, bool = true) const; |
263 void printScalarConstant(const Constant *CPV, raw_ostream &O); | 259 void printScalarConstant(Constant *CPV, raw_ostream &O); |
264 void printFPConstant(const ConstantFP *Fp, raw_ostream &O); | 260 void printFPConstant(const ConstantFP *Fp, raw_ostream &O); |
265 void bufferLEByte(const Constant *CPV, int Bytes, AggBuffer *aggBuffer); | 261 void bufferLEByte(Constant *CPV, int Bytes, AggBuffer *aggBuffer); |
266 void bufferAggregateConstant(const Constant *CV, AggBuffer *aggBuffer); | 262 void bufferAggregateConstant(Constant *CV, AggBuffer *aggBuffer); |
267 | 263 |
268 void printOperandProper(const MachineOperand &MO); | 264 void printOperandProper(const MachineOperand &MO); |
269 | 265 |
270 void emitLinkageDirective(const GlobalValue *V, raw_ostream &O); | 266 void emitLinkageDirective(const GlobalValue *V, raw_ostream &O); |
271 void emitDeclarations(const Module &, raw_ostream &O); | 267 void emitDeclarations(Module &, raw_ostream &O); |
272 void emitDeclaration(const Function *, raw_ostream &O); | 268 void emitDeclaration(const Function *, raw_ostream &O); |
273 | 269 |
274 static const char *getRegisterName(unsigned RegNo); | 270 static const char *getRegisterName(unsigned RegNo); |
275 void emitDemotedVars(const Function *, raw_ostream &); | 271 void emitDemotedVars(const Function *, raw_ostream &); |
276 | 272 |
277 LineReader *reader; | 273 LineReader *reader; |
278 LineReader *getReader(std::string); | 274 LineReader *getReader(std::string); |
279 public: | 275 public: |
280 NVPTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) | 276 NVPTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) |
281 : AsmPrinter(TM, Streamer), | 277 : AsmPrinter(TM, Streamer), |
(...skipping 11 matching lines...) Expand all Loading... |
293 bool ignoreLoc(const MachineInstr &); | 289 bool ignoreLoc(const MachineInstr &); |
294 | 290 |
295 virtual void getVirtualRegisterName(unsigned, bool, raw_ostream &); | 291 virtual void getVirtualRegisterName(unsigned, bool, raw_ostream &); |
296 | 292 |
297 DebugLoc prevDebugLoc; | 293 DebugLoc prevDebugLoc; |
298 void emitLineNumberAsDotLoc(const MachineInstr &); | 294 void emitLineNumberAsDotLoc(const MachineInstr &); |
299 }; | 295 }; |
300 } // end of namespace | 296 } // end of namespace |
301 | 297 |
302 #endif | 298 #endif |
OLD | NEW |