blob: 6f6fc29673e2c8ba96844240bb998654f79b5c62 [file] [log] [blame]
Nick Lewyckyf7a3c502010-09-07 18:14:24 +00001//===-- PTXAsmPrinter.cpp - PTX LLVM assembly writer ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to PTX assembly language.
12//
13//===----------------------------------------------------------------------===//
14
Che-Liang Chioudf659632010-11-08 03:06:08 +000015#define DEBUG_TYPE "ptx-asm-printer"
16
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000017#include "PTX.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000018#include "PTXMachineFunctionInfo.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000019#include "PTXTargetMachine.h"
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000020#include "llvm/DerivedTypes.h"
21#include "llvm/Module.h"
Eric Christopher50880d02010-09-18 18:52:28 +000022#include "llvm/ADT/SmallString.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000023#include "llvm/ADT/StringExtras.h"
24#include "llvm/ADT/Twine.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000025#include "llvm/CodeGen/AsmPrinter.h"
Justin Holewinskidf1c8d82011-06-20 15:56:20 +000026#include "llvm/CodeGen/MachineFrameInfo.h"
Eric Christopher50880d02010-09-18 18:52:28 +000027#include "llvm/CodeGen/MachineInstr.h"
Che-Liang Chioufd8978b2011-03-02 03:20:28 +000028#include "llvm/CodeGen/MachineRegisterInfo.h"
Eric Christopher50880d02010-09-18 18:52:28 +000029#include "llvm/MC/MCStreamer.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000030#include "llvm/MC/MCSymbol.h"
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000031#include "llvm/Target/Mangler.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000032#include "llvm/Target/TargetLoweringObjectFile.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000033#include "llvm/Target/TargetRegistry.h"
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +000034#include "llvm/Support/CommandLine.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000035#include "llvm/Support/Debug.h"
36#include "llvm/Support/ErrorHandling.h"
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000037#include "llvm/Support/MathExtras.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000038#include "llvm/Support/raw_ostream.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000039
40using namespace llvm;
41
42namespace {
Che-Liang Chioudf659632010-11-08 03:06:08 +000043class PTXAsmPrinter : public AsmPrinter {
44public:
45 explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
46 : AsmPrinter(TM, Streamer) {}
Eric Christopher50880d02010-09-18 18:52:28 +000047
Che-Liang Chioudf659632010-11-08 03:06:08 +000048 const char *getPassName() const { return "PTX Assembly Printer"; }
Eric Christopher50880d02010-09-18 18:52:28 +000049
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000050 bool doFinalization(Module &M);
51
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +000052 virtual void EmitStartOfAsmFile(Module &M);
53
Che-Liang Chioudf659632010-11-08 03:06:08 +000054 virtual bool runOnMachineFunction(MachineFunction &MF);
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000055
Che-Liang Chioudf659632010-11-08 03:06:08 +000056 virtual void EmitFunctionBodyStart();
57 virtual void EmitFunctionBodyEnd() { OutStreamer.EmitRawText(Twine("}")); }
58
59 virtual void EmitInstruction(const MachineInstr *MI);
60
61 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +000062 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
63 const char *Modifier = 0);
Che-Liang Chiou8e5d01c2011-02-10 12:01:24 +000064 void printParamOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
65 const char *Modifier = 0);
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +000066 void printPredicateOperand(const MachineInstr *MI, raw_ostream &O);
Che-Liang Chioudf659632010-11-08 03:06:08 +000067
68 // autogen'd.
69 void printInstruction(const MachineInstr *MI, raw_ostream &OS);
70 static const char *getRegisterName(unsigned RegNo);
71
72private:
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000073 void EmitVariableDeclaration(const GlobalVariable *gv);
Che-Liang Chioudf659632010-11-08 03:06:08 +000074 void EmitFunctionDeclaration();
75}; // class PTXAsmPrinter
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000076} // namespace
77
Che-Liang Chioudf659632010-11-08 03:06:08 +000078static const char PARAM_PREFIX[] = "__param_";
79
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +000080static const char *getRegisterTypeName(unsigned RegNo) {
Che-Liang Chioufd8978b2011-03-02 03:20:28 +000081#define TEST_REGCLS(cls, clsstr) \
Che-Liang Chioudf659632010-11-08 03:06:08 +000082 if (PTX::cls ## RegisterClass->contains(RegNo)) return # clsstr;
Justin Holewinski1b91bcd2011-06-16 17:49:58 +000083 TEST_REGCLS(RegPred, pred);
Justin Holewinskie0aef2d2011-06-16 17:50:00 +000084 TEST_REGCLS(RegI16, b16);
85 TEST_REGCLS(RegI32, b32);
86 TEST_REGCLS(RegI64, b64);
87 TEST_REGCLS(RegF32, b32);
88 TEST_REGCLS(RegF64, b64);
Che-Liang Chioudf659632010-11-08 03:06:08 +000089#undef TEST_REGCLS
90
91 llvm_unreachable("Not in any register class!");
92 return NULL;
93}
94
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000095static const char *getStateSpaceName(unsigned addressSpace) {
Che-Liang Chioud34f19f2010-12-30 10:41:27 +000096 switch (addressSpace) {
97 default: llvm_unreachable("Unknown state space");
98 case PTX::GLOBAL: return "global";
99 case PTX::CONSTANT: return "const";
100 case PTX::LOCAL: return "local";
101 case PTX::PARAMETER: return "param";
102 case PTX::SHARED: return "shared";
103 }
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000104 return NULL;
105}
106
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000107static const char *getTypeName(const Type* type) {
108 while (true) {
109 switch (type->getTypeID()) {
110 default: llvm_unreachable("Unknown type");
111 case Type::FloatTyID: return ".f32";
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000112 case Type::DoubleTyID: return ".f64";
113 case Type::IntegerTyID:
114 switch (type->getPrimitiveSizeInBits()) {
115 default: llvm_unreachable("Unknown integer bit-width");
116 case 16: return ".u16";
117 case 32: return ".u32";
118 case 64: return ".u64";
119 }
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000120 case Type::ArrayTyID:
121 case Type::PointerTyID:
122 type = dyn_cast<const SequentialType>(type)->getElementType();
123 break;
124 }
125 }
126 return NULL;
127}
128
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000129bool PTXAsmPrinter::doFinalization(Module &M) {
130 // XXX Temproarily remove global variables so that doFinalization() will not
131 // emit them again (global variables are emitted at beginning).
132
133 Module::GlobalListType &global_list = M.getGlobalList();
134 int i, n = global_list.size();
135 GlobalVariable **gv_array = new GlobalVariable* [n];
136
137 // first, back-up GlobalVariable in gv_array
138 i = 0;
139 for (Module::global_iterator I = global_list.begin(), E = global_list.end();
140 I != E; ++I)
141 gv_array[i++] = &*I;
142
143 // second, empty global_list
144 while (!global_list.empty())
145 global_list.remove(global_list.begin());
146
147 // call doFinalization
148 bool ret = AsmPrinter::doFinalization(M);
149
150 // now we restore global variables
151 for (i = 0; i < n; i ++)
152 global_list.insert(global_list.end(), gv_array[i]);
153
154 delete[] gv_array;
155 return ret;
156}
157
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +0000158void PTXAsmPrinter::EmitStartOfAsmFile(Module &M)
159{
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000160 const PTXSubtarget& ST = TM.getSubtarget<PTXSubtarget>();
161
162 OutStreamer.EmitRawText(Twine("\t.version " + ST.getPTXVersionString()));
163 OutStreamer.EmitRawText(Twine("\t.target " + ST.getTargetString() +
Justin Holewinski12785e82011-03-03 13:34:29 +0000164 (ST.supportsDouble() ? ""
165 : ", map_f64_to_f32")));
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +0000166 OutStreamer.AddBlankLine();
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000167
168 // declare global variables
169 for (Module::const_global_iterator i = M.global_begin(), e = M.global_end();
170 i != e; ++i)
171 EmitVariableDeclaration(i);
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +0000172}
173
Che-Liang Chioudf659632010-11-08 03:06:08 +0000174bool PTXAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
175 SetupMachineFunction(MF);
176 EmitFunctionDeclaration();
177 EmitFunctionBody();
178 return false;
179}
180
181void PTXAsmPrinter::EmitFunctionBodyStart() {
182 OutStreamer.EmitRawText(Twine("{"));
183
184 const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>();
185
186 // Print local variable definition
187 for (PTXMachineFunctionInfo::reg_iterator
188 i = MFI->localVarRegBegin(), e = MFI->localVarRegEnd(); i != e; ++ i) {
189 unsigned reg = *i;
190
Che-Liang Chiou3f409f72010-11-17 08:08:49 +0000191 std::string def = "\t.reg .";
Che-Liang Chioudf659632010-11-08 03:06:08 +0000192 def += getRegisterTypeName(reg);
193 def += ' ';
194 def += getRegisterName(reg);
195 def += ';';
196 OutStreamer.EmitRawText(Twine(def));
197 }
Justin Holewinskidf1c8d82011-06-20 15:56:20 +0000198
199 const MachineFrameInfo* FrameInfo = MF->getFrameInfo();
200 DEBUG(dbgs() << "Have " << FrameInfo->getNumObjects() << " frame object(s)\n");
201 for (unsigned i = 0, e = FrameInfo->getNumObjects(); i != e; ++i) {
202 DEBUG(dbgs() << "Size of object: " << FrameInfo->getObjectSize(i) << "\n");
203 std::string def = "\t.reg .b";
204 def += utostr(FrameInfo->getObjectSize(i)*8); // Convert to bits
205 def += " s";
206 def += utostr(i);
207 def += ";";
208 OutStreamer.EmitRawText(Twine(def));
209 }
Che-Liang Chioudf659632010-11-08 03:06:08 +0000210}
211
Eric Christopher50880d02010-09-18 18:52:28 +0000212void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000213 std::string str;
214 str.reserve(64);
215
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000216 raw_string_ostream OS(str);
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +0000217
218 // Emit predicate
219 printPredicateOperand(MI, OS);
220
221 // Write instruction to str
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000222 printInstruction(MI, OS);
223 OS << ';';
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000224 OS.flush();
Che-Liang Chiou3f409f72010-11-17 08:08:49 +0000225
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000226 StringRef strref = StringRef(str);
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +0000227 OutStreamer.EmitRawText(strref);
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000228}
229
230void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
231 raw_ostream &OS) {
232 const MachineOperand &MO = MI->getOperand(opNum);
233
234 switch (MO.getType()) {
235 default:
236 llvm_unreachable("<unknown operand type>");
237 break;
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000238 case MachineOperand::MO_GlobalAddress:
239 OS << *Mang->getSymbol(MO.getGlobal());
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000240 break;
241 case MachineOperand::MO_Immediate:
Justin Holewinski9583a862011-04-28 00:19:50 +0000242 OS << (long) MO.getImm();
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000243 break;
Che-Liang Chiou88d33672011-03-18 11:08:52 +0000244 case MachineOperand::MO_MachineBasicBlock:
245 OS << *MO.getMBB()->getSymbol();
246 break;
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000247 case MachineOperand::MO_Register:
248 OS << getRegisterName(MO.getReg());
249 break;
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000250 case MachineOperand::MO_FPImmediate:
251 APInt constFP = MO.getFPImm()->getValueAPF().bitcastToAPInt();
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000252 bool isFloat = MO.getFPImm()->getType()->getTypeID() == Type::FloatTyID;
253 // Emit 0F for 32-bit floats and 0D for 64-bit doubles.
254 if (isFloat) {
255 OS << "0F";
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000256 }
257 else {
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000258 OS << "0D";
259 }
260 // Emit the encoded floating-point value.
261 if (constFP.getZExtValue() > 0) {
262 OS << constFP.toString(16, false);
263 }
264 else {
265 OS << "00000000";
266 // If We have a double-precision zero, pad to 8-bytes.
267 if (!isFloat) {
268 OS << "00000000";
269 }
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000270 }
271 break;
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000272 }
Eric Christopher50880d02010-09-18 18:52:28 +0000273}
274
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +0000275void PTXAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
276 raw_ostream &OS, const char *Modifier) {
277 printOperand(MI, opNum, OS);
278
279 if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() == 0)
280 return; // don't print "+0"
281
282 OS << "+";
283 printOperand(MI, opNum+1, OS);
284}
285
Che-Liang Chiou8e5d01c2011-02-10 12:01:24 +0000286void PTXAsmPrinter::printParamOperand(const MachineInstr *MI, int opNum,
287 raw_ostream &OS, const char *Modifier) {
288 OS << PARAM_PREFIX << (int) MI->getOperand(opNum).getImm() + 1;
289}
290
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000291void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) {
292 // Check to see if this is a special global used by LLVM, if so, emit it.
293 if (EmitSpecialLLVMGlobal(gv))
294 return;
295
296 MCSymbol *gvsym = Mang->getSymbol(gv);
297
298 assert(gvsym->isUndefined() && "Cannot define a symbol twice!");
299
300 std::string decl;
301
302 // check if it is defined in some other translation unit
303 if (gv->isDeclaration())
304 decl += ".extern ";
305
306 // state space: e.g., .global
307 decl += ".";
308 decl += getStateSpaceName(gv->getType()->getAddressSpace());
309 decl += " ";
310
311 // alignment (optional)
312 unsigned alignment = gv->getAlignment();
313 if (alignment != 0) {
314 decl += ".align ";
315 decl += utostr(Log2_32(gv->getAlignment()));
316 decl += " ";
317 }
318
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000319
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000320 if (PointerType::classof(gv->getType())) {
321 const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
322 const Type* elementTy = pointerTy->getElementType();
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000323
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000324 decl += ".b8 ";
325 decl += gvsym->getName();
326 decl += "[";
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000327
Justin Holewinski9583a862011-04-28 00:19:50 +0000328 if (elementTy->isArrayTy())
329 {
330 assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
331
332 const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
333 elementTy = arrayTy->getElementType();
334
335 unsigned numElements = arrayTy->getNumElements();
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000336
Justin Holewinski9583a862011-04-28 00:19:50 +0000337 while (elementTy->isArrayTy()) {
338
339 arrayTy = dyn_cast<const ArrayType>(elementTy);
340 elementTy = arrayTy->getElementType();
341
342 numElements *= arrayTy->getNumElements();
343 }
344
345 // FIXME: isPrimitiveType() == false for i16?
346 assert(elementTy->isSingleValueType() &&
347 "Non-primitive types are not handled");
348
349 // Compute the size of the array, in bytes.
350 uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
351 * numElements;
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000352
Justin Holewinski9583a862011-04-28 00:19:50 +0000353 decl += utostr(arraySize);
354 }
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000355
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000356 decl += "]";
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000357
Justin Holewinski9583a862011-04-28 00:19:50 +0000358 // handle string constants (assume ConstantArray means string)
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000359
Justin Holewinski9583a862011-04-28 00:19:50 +0000360 if (gv->hasInitializer())
361 {
Jay Foad7d715df2011-06-19 18:37:11 +0000362 const Constant *C = gv->getInitializer();
Justin Holewinski9583a862011-04-28 00:19:50 +0000363 if (const ConstantArray *CA = dyn_cast<ConstantArray>(C))
364 {
365 decl += " = {";
366
367 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
368 {
369 if (i > 0) decl += ",";
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000370
371 decl += "0x" +
372 utohexstr(cast<ConstantInt>(CA->getOperand(i))->getZExtValue());
Justin Holewinski9583a862011-04-28 00:19:50 +0000373 }
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000374
Justin Holewinski9583a862011-04-28 00:19:50 +0000375 decl += "}";
376 }
377 }
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000378 }
379 else {
380 // Note: this is currently the fall-through case and most likely generates
381 // incorrect code.
382 decl += getTypeName(gv->getType());
383 decl += " ";
384
385 decl += gvsym->getName();
386
387 if (ArrayType::classof(gv->getType()) ||
388 PointerType::classof(gv->getType()))
389 decl += "[]";
390 }
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000391
392 decl += ";";
393
394 OutStreamer.EmitRawText(Twine(decl));
395
396 OutStreamer.AddBlankLine();
397}
398
Che-Liang Chioudf659632010-11-08 03:06:08 +0000399void PTXAsmPrinter::EmitFunctionDeclaration() {
400 // The function label could have already been emitted if two symbols end up
401 // conflicting due to asm renaming. Detect this and emit an error.
402 if (!CurrentFnSym->isUndefined()) {
403 report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
404 "' label emitted multiple times to assembly file");
405 return;
406 }
407
408 const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>();
409 const bool isKernel = MFI->isKernel();
Che-Liang Chioudf659632010-11-08 03:06:08 +0000410
411 std::string decl = isKernel ? ".entry" : ".func";
412
Justin Holewinskie0aef2d2011-06-16 17:50:00 +0000413 if (!isKernel) {
414 decl += " (";
415
416 for (PTXMachineFunctionInfo::ret_iterator
417 i = MFI->retRegBegin(), e = MFI->retRegEnd(), b = i;
418 i != e; ++i) {
419 if (i != b) {
420 decl += ", ";
421 }
422 decl += ".reg .";
423 decl += getRegisterTypeName(*i);
424 decl += " ";
425 decl += getRegisterName(*i);
426 }
Che-Liang Chioudf659632010-11-08 03:06:08 +0000427 decl += ")";
428 }
429
430 // Print function name
431 decl += " ";
432 decl += CurrentFnSym->getName().str();
433
Justin Holewinskie0aef2d2011-06-16 17:50:00 +0000434 decl += " (";
435
436 unsigned cnt = 0;
437
438 // Print parameters
439 for (PTXMachineFunctionInfo::reg_iterator
440 i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i;
441 i != e; ++i) {
442 if (i != b) {
443 decl += ", ";
Che-Liang Chioudf659632010-11-08 03:06:08 +0000444 }
Justin Holewinskie0aef2d2011-06-16 17:50:00 +0000445 if (isKernel) {
446 decl += ".param .b";
447 decl += utostr(*i);
448 decl += " ";
449 decl += PARAM_PREFIX;
450 decl += utostr(++cnt);
451 } else {
452 decl += ".reg .";
453 decl += getRegisterTypeName(*i);
454 decl += " ";
455 decl += getRegisterName(*i);
456 }
Che-Liang Chioudf659632010-11-08 03:06:08 +0000457 }
Justin Holewinskie0aef2d2011-06-16 17:50:00 +0000458 decl += ")";
459
460 // // Print parameter list
461 // if (!MFI->argRegEmpty()) {
462 // decl += " (";
463 // if (isKernel) {
464 // unsigned cnt = 0;
465 // for(PTXMachineFunctionInfo::reg_iterator
466 // i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i;
467 // i != e; ++i) {
468 // reg = *i;
469 // assert(reg != PTX::NoRegister && "Not a valid register!");
470 // if (i != b)
471 // decl += ", ";
472 // decl += ".param .";
473 // decl += getRegisterTypeName(reg);
474 // decl += " ";
475 // decl += PARAM_PREFIX;
476 // decl += utostr(++cnt);
477 // }
478 // } else {
479 // for (PTXMachineFunctionInfo::reg_iterator
480 // i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i;
481 // i != e; ++i) {
482 // reg = *i;
483 // assert(reg != PTX::NoRegister && "Not a valid register!");
484 // if (i != b)
485 // decl += ", ";
486 // decl += ".reg .";
487 // decl += getRegisterTypeName(reg);
488 // decl += " ";
489 // decl += getRegisterName(reg);
490 // }
491 // }
492 // decl += ")";
493 // }
Che-Liang Chioudf659632010-11-08 03:06:08 +0000494
495 OutStreamer.EmitRawText(Twine(decl));
496}
497
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +0000498void PTXAsmPrinter::
499printPredicateOperand(const MachineInstr *MI, raw_ostream &O) {
500 int i = MI->findFirstPredOperandIdx();
501 if (i == -1)
502 llvm_unreachable("missing predicate operand");
503
504 unsigned reg = MI->getOperand(i).getReg();
505 int predOp = MI->getOperand(i+1).getImm();
506
507 DEBUG(dbgs() << "predicate: (" << reg << ", " << predOp << ")\n");
508
Che-Liang Chiouf78847e2011-03-14 11:26:01 +0000509 if (reg != PTX::NoRegister) {
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +0000510 O << '@';
511 if (predOp == PTX::PRED_NEGATE)
512 O << '!';
513 O << getRegisterName(reg);
514 }
515}
516
Eric Christopher50880d02010-09-18 18:52:28 +0000517#include "PTXGenAsmWriter.inc"
518
Nick Lewyckyf7a3c502010-09-07 18:14:24 +0000519// Force static initialization.
Eric Christopher50880d02010-09-18 18:52:28 +0000520extern "C" void LLVMInitializePTXAsmPrinter() {
Justin Holewinskie1fee482011-04-20 15:37:17 +0000521 RegisterAsmPrinter<PTXAsmPrinter> X(ThePTX32Target);
522 RegisterAsmPrinter<PTXAsmPrinter> Y(ThePTX64Target);
Nick Lewyckyf7a3c502010-09-07 18:14:24 +0000523}