blob: cf8d461ba1a9beb837a9b61d5ba048bc29288e61 [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"
Eric Christopher50880d02010-09-18 18:52:28 +000026#include "llvm/CodeGen/MachineInstr.h"
Che-Liang Chioufd8978b2011-03-02 03:20:28 +000027#include "llvm/CodeGen/MachineRegisterInfo.h"
Eric Christopher50880d02010-09-18 18:52:28 +000028#include "llvm/MC/MCStreamer.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000029#include "llvm/MC/MCSymbol.h"
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000030#include "llvm/Target/Mangler.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000031#include "llvm/Target/TargetLoweringObjectFile.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000032#include "llvm/Target/TargetRegistry.h"
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +000033#include "llvm/Support/CommandLine.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000034#include "llvm/Support/Debug.h"
35#include "llvm/Support/ErrorHandling.h"
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000036#include "llvm/Support/MathExtras.h"
Che-Liang Chioudf659632010-11-08 03:06:08 +000037#include "llvm/Support/raw_ostream.h"
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000038
39using namespace llvm;
40
41namespace {
Che-Liang Chioudf659632010-11-08 03:06:08 +000042class PTXAsmPrinter : public AsmPrinter {
43public:
44 explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
45 : AsmPrinter(TM, Streamer) {}
Eric Christopher50880d02010-09-18 18:52:28 +000046
Che-Liang Chioudf659632010-11-08 03:06:08 +000047 const char *getPassName() const { return "PTX Assembly Printer"; }
Eric Christopher50880d02010-09-18 18:52:28 +000048
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000049 bool doFinalization(Module &M);
50
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +000051 virtual void EmitStartOfAsmFile(Module &M);
52
Che-Liang Chioudf659632010-11-08 03:06:08 +000053 virtual bool runOnMachineFunction(MachineFunction &MF);
Che-Liang Chioub48f2c22010-10-19 13:14:40 +000054
Che-Liang Chioudf659632010-11-08 03:06:08 +000055 virtual void EmitFunctionBodyStart();
56 virtual void EmitFunctionBodyEnd() { OutStreamer.EmitRawText(Twine("}")); }
57
58 virtual void EmitInstruction(const MachineInstr *MI);
59
60 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +000061 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
62 const char *Modifier = 0);
Che-Liang Chiou8e5d01c2011-02-10 12:01:24 +000063 void printParamOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
64 const char *Modifier = 0);
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +000065 void printPredicateOperand(const MachineInstr *MI, raw_ostream &O);
Che-Liang Chioudf659632010-11-08 03:06:08 +000066
67 // autogen'd.
68 void printInstruction(const MachineInstr *MI, raw_ostream &OS);
69 static const char *getRegisterName(unsigned RegNo);
70
71private:
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000072 void EmitVariableDeclaration(const GlobalVariable *gv);
Che-Liang Chioudf659632010-11-08 03:06:08 +000073 void EmitFunctionDeclaration();
74}; // class PTXAsmPrinter
Nick Lewyckyf7a3c502010-09-07 18:14:24 +000075} // namespace
76
Che-Liang Chioudf659632010-11-08 03:06:08 +000077static const char PARAM_PREFIX[] = "__param_";
78
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +000079static const char *getRegisterTypeName(unsigned RegNo) {
Che-Liang Chioufd8978b2011-03-02 03:20:28 +000080#define TEST_REGCLS(cls, clsstr) \
Che-Liang Chioudf659632010-11-08 03:06:08 +000081 if (PTX::cls ## RegisterClass->contains(RegNo)) return # clsstr;
Justin Holewinski1b91bcd2011-06-16 17:49:58 +000082 TEST_REGCLS(RegPred, pred);
83 TEST_REGCLS(RegI16, u16);
84 TEST_REGCLS(RegI32, u32);
85 TEST_REGCLS(RegI64, u64);
86 TEST_REGCLS(RegF32, f32);
87 TEST_REGCLS(RegF64, f64);
Che-Liang Chioudf659632010-11-08 03:06:08 +000088#undef TEST_REGCLS
89
90 llvm_unreachable("Not in any register class!");
91 return NULL;
92}
93
Che-Liang Chioufc7072c2010-12-22 10:38:51 +000094static const char *getStateSpaceName(unsigned addressSpace) {
Che-Liang Chioud34f19f2010-12-30 10:41:27 +000095 switch (addressSpace) {
96 default: llvm_unreachable("Unknown state space");
97 case PTX::GLOBAL: return "global";
98 case PTX::CONSTANT: return "const";
99 case PTX::LOCAL: return "local";
100 case PTX::PARAMETER: return "param";
101 case PTX::SHARED: return "shared";
102 }
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000103 return NULL;
104}
105
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000106static const char *getTypeName(const Type* type) {
107 while (true) {
108 switch (type->getTypeID()) {
109 default: llvm_unreachable("Unknown type");
110 case Type::FloatTyID: return ".f32";
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000111 case Type::DoubleTyID: return ".f64";
112 case Type::IntegerTyID:
113 switch (type->getPrimitiveSizeInBits()) {
114 default: llvm_unreachable("Unknown integer bit-width");
115 case 16: return ".u16";
116 case 32: return ".u32";
117 case 64: return ".u64";
118 }
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000119 case Type::ArrayTyID:
120 case Type::PointerTyID:
121 type = dyn_cast<const SequentialType>(type)->getElementType();
122 break;
123 }
124 }
125 return NULL;
126}
127
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000128bool PTXAsmPrinter::doFinalization(Module &M) {
129 // XXX Temproarily remove global variables so that doFinalization() will not
130 // emit them again (global variables are emitted at beginning).
131
132 Module::GlobalListType &global_list = M.getGlobalList();
133 int i, n = global_list.size();
134 GlobalVariable **gv_array = new GlobalVariable* [n];
135
136 // first, back-up GlobalVariable in gv_array
137 i = 0;
138 for (Module::global_iterator I = global_list.begin(), E = global_list.end();
139 I != E; ++I)
140 gv_array[i++] = &*I;
141
142 // second, empty global_list
143 while (!global_list.empty())
144 global_list.remove(global_list.begin());
145
146 // call doFinalization
147 bool ret = AsmPrinter::doFinalization(M);
148
149 // now we restore global variables
150 for (i = 0; i < n; i ++)
151 global_list.insert(global_list.end(), gv_array[i]);
152
153 delete[] gv_array;
154 return ret;
155}
156
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +0000157void PTXAsmPrinter::EmitStartOfAsmFile(Module &M)
158{
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000159 const PTXSubtarget& ST = TM.getSubtarget<PTXSubtarget>();
160
161 OutStreamer.EmitRawText(Twine("\t.version " + ST.getPTXVersionString()));
162 OutStreamer.EmitRawText(Twine("\t.target " + ST.getTargetString() +
Justin Holewinski12785e82011-03-03 13:34:29 +0000163 (ST.supportsDouble() ? ""
164 : ", map_f64_to_f32")));
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +0000165 OutStreamer.AddBlankLine();
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000166
167 // declare global variables
168 for (Module::const_global_iterator i = M.global_begin(), e = M.global_end();
169 i != e; ++i)
170 EmitVariableDeclaration(i);
Che-Liang Chiou21d8b9b2010-11-30 10:14:14 +0000171}
172
Che-Liang Chioudf659632010-11-08 03:06:08 +0000173bool PTXAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
174 SetupMachineFunction(MF);
175 EmitFunctionDeclaration();
176 EmitFunctionBody();
177 return false;
178}
179
180void PTXAsmPrinter::EmitFunctionBodyStart() {
181 OutStreamer.EmitRawText(Twine("{"));
182
183 const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>();
184
185 // Print local variable definition
186 for (PTXMachineFunctionInfo::reg_iterator
187 i = MFI->localVarRegBegin(), e = MFI->localVarRegEnd(); i != e; ++ i) {
188 unsigned reg = *i;
189
Che-Liang Chiou3f409f72010-11-17 08:08:49 +0000190 std::string def = "\t.reg .";
Che-Liang Chioudf659632010-11-08 03:06:08 +0000191 def += getRegisterTypeName(reg);
192 def += ' ';
193 def += getRegisterName(reg);
194 def += ';';
195 OutStreamer.EmitRawText(Twine(def));
196 }
197}
198
Eric Christopher50880d02010-09-18 18:52:28 +0000199void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000200 std::string str;
201 str.reserve(64);
202
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000203 raw_string_ostream OS(str);
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +0000204
205 // Emit predicate
206 printPredicateOperand(MI, OS);
207
208 // Write instruction to str
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000209 printInstruction(MI, OS);
210 OS << ';';
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000211 OS.flush();
Che-Liang Chiou3f409f72010-11-17 08:08:49 +0000212
Che-Liang Chiou3608d2a2010-12-01 11:45:53 +0000213 StringRef strref = StringRef(str);
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +0000214 OutStreamer.EmitRawText(strref);
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000215}
216
217void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
218 raw_ostream &OS) {
219 const MachineOperand &MO = MI->getOperand(opNum);
220
221 switch (MO.getType()) {
222 default:
223 llvm_unreachable("<unknown operand type>");
224 break;
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000225 case MachineOperand::MO_GlobalAddress:
226 OS << *Mang->getSymbol(MO.getGlobal());
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000227 break;
228 case MachineOperand::MO_Immediate:
Justin Holewinski9583a862011-04-28 00:19:50 +0000229 OS << (long) MO.getImm();
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000230 break;
Che-Liang Chiou88d33672011-03-18 11:08:52 +0000231 case MachineOperand::MO_MachineBasicBlock:
232 OS << *MO.getMBB()->getSymbol();
233 break;
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000234 case MachineOperand::MO_Register:
235 OS << getRegisterName(MO.getReg());
236 break;
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000237 case MachineOperand::MO_FPImmediate:
238 APInt constFP = MO.getFPImm()->getValueAPF().bitcastToAPInt();
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000239 bool isFloat = MO.getFPImm()->getType()->getTypeID() == Type::FloatTyID;
240 // Emit 0F for 32-bit floats and 0D for 64-bit doubles.
241 if (isFloat) {
242 OS << "0F";
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000243 }
244 else {
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000245 OS << "0D";
246 }
247 // Emit the encoded floating-point value.
248 if (constFP.getZExtValue() > 0) {
249 OS << constFP.toString(16, false);
250 }
251 else {
252 OS << "00000000";
253 // If We have a double-precision zero, pad to 8-bytes.
254 if (!isFloat) {
255 OS << "00000000";
256 }
Che-Liang Chiouf7172022011-02-28 06:34:09 +0000257 }
258 break;
Che-Liang Chioub48f2c22010-10-19 13:14:40 +0000259 }
Eric Christopher50880d02010-09-18 18:52:28 +0000260}
261
Che-Liang Chiou3f8e6172010-11-30 07:34:44 +0000262void PTXAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
263 raw_ostream &OS, const char *Modifier) {
264 printOperand(MI, opNum, OS);
265
266 if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() == 0)
267 return; // don't print "+0"
268
269 OS << "+";
270 printOperand(MI, opNum+1, OS);
271}
272
Che-Liang Chiou8e5d01c2011-02-10 12:01:24 +0000273void PTXAsmPrinter::printParamOperand(const MachineInstr *MI, int opNum,
274 raw_ostream &OS, const char *Modifier) {
275 OS << PARAM_PREFIX << (int) MI->getOperand(opNum).getImm() + 1;
276}
277
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000278void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) {
279 // Check to see if this is a special global used by LLVM, if so, emit it.
280 if (EmitSpecialLLVMGlobal(gv))
281 return;
282
283 MCSymbol *gvsym = Mang->getSymbol(gv);
284
285 assert(gvsym->isUndefined() && "Cannot define a symbol twice!");
286
287 std::string decl;
288
289 // check if it is defined in some other translation unit
290 if (gv->isDeclaration())
291 decl += ".extern ";
292
293 // state space: e.g., .global
294 decl += ".";
295 decl += getStateSpaceName(gv->getType()->getAddressSpace());
296 decl += " ";
297
298 // alignment (optional)
299 unsigned alignment = gv->getAlignment();
300 if (alignment != 0) {
301 decl += ".align ";
302 decl += utostr(Log2_32(gv->getAlignment()));
303 decl += " ";
304 }
305
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000306
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000307 if (PointerType::classof(gv->getType())) {
308 const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
309 const Type* elementTy = pointerTy->getElementType();
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000310
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000311 decl += ".b8 ";
312 decl += gvsym->getName();
313 decl += "[";
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000314
Justin Holewinski9583a862011-04-28 00:19:50 +0000315 if (elementTy->isArrayTy())
316 {
317 assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
318
319 const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
320 elementTy = arrayTy->getElementType();
321
322 unsigned numElements = arrayTy->getNumElements();
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000323
Justin Holewinski9583a862011-04-28 00:19:50 +0000324 while (elementTy->isArrayTy()) {
325
326 arrayTy = dyn_cast<const ArrayType>(elementTy);
327 elementTy = arrayTy->getElementType();
328
329 numElements *= arrayTy->getNumElements();
330 }
331
332 // FIXME: isPrimitiveType() == false for i16?
333 assert(elementTy->isSingleValueType() &&
334 "Non-primitive types are not handled");
335
336 // Compute the size of the array, in bytes.
337 uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
338 * numElements;
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000339
Justin Holewinski9583a862011-04-28 00:19:50 +0000340 decl += utostr(arraySize);
341 }
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000342
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000343 decl += "]";
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000344
Justin Holewinski9583a862011-04-28 00:19:50 +0000345 // handle string constants (assume ConstantArray means string)
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000346
Justin Holewinski9583a862011-04-28 00:19:50 +0000347 if (gv->hasInitializer())
348 {
349 Constant *C = gv->getInitializer();
350 if (const ConstantArray *CA = dyn_cast<ConstantArray>(C))
351 {
352 decl += " = {";
353
354 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
355 {
356 if (i > 0) decl += ",";
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000357
358 decl += "0x" +
359 utohexstr(cast<ConstantInt>(CA->getOperand(i))->getZExtValue());
Justin Holewinski9583a862011-04-28 00:19:50 +0000360 }
Justin Holewinskiec3141b2011-06-16 15:17:11 +0000361
Justin Holewinski9583a862011-04-28 00:19:50 +0000362 decl += "}";
363 }
364 }
Justin Holewinskiae3ce172011-03-14 15:40:11 +0000365 }
366 else {
367 // Note: this is currently the fall-through case and most likely generates
368 // incorrect code.
369 decl += getTypeName(gv->getType());
370 decl += " ";
371
372 decl += gvsym->getName();
373
374 if (ArrayType::classof(gv->getType()) ||
375 PointerType::classof(gv->getType()))
376 decl += "[]";
377 }
Che-Liang Chioufc7072c2010-12-22 10:38:51 +0000378
379 decl += ";";
380
381 OutStreamer.EmitRawText(Twine(decl));
382
383 OutStreamer.AddBlankLine();
384}
385
Che-Liang Chioudf659632010-11-08 03:06:08 +0000386void PTXAsmPrinter::EmitFunctionDeclaration() {
387 // The function label could have already been emitted if two symbols end up
388 // conflicting due to asm renaming. Detect this and emit an error.
389 if (!CurrentFnSym->isUndefined()) {
390 report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
391 "' label emitted multiple times to assembly file");
392 return;
393 }
394
395 const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>();
396 const bool isKernel = MFI->isKernel();
397 unsigned reg;
398
399 std::string decl = isKernel ? ".entry" : ".func";
400
401 // Print return register
402 reg = MFI->retReg();
403 if (!isKernel && reg != PTX::NoRegister) {
Che-Liang Chiou3f409f72010-11-17 08:08:49 +0000404 decl += " (.reg ."; // FIXME: could it return in .param space?
Che-Liang Chioudf659632010-11-08 03:06:08 +0000405 decl += getRegisterTypeName(reg);
406 decl += " ";
407 decl += getRegisterName(reg);
408 decl += ")";
409 }
410
411 // Print function name
412 decl += " ";
413 decl += CurrentFnSym->getName().str();
414
415 // Print parameter list
416 if (!MFI->argRegEmpty()) {
417 decl += " (";
418 if (isKernel) {
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000419 unsigned cnt = 0;
Che-Liang Chiou8902ecb2011-03-18 11:23:56 +0000420 for(PTXMachineFunctionInfo::reg_iterator
421 i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i;
Che-Liang Chiou31c488c2011-03-02 07:58:46 +0000422 i != e; ++i) {
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000423 reg = *i;
424 assert(reg != PTX::NoRegister && "Not a valid register!");
425 if (i != b)
Che-Liang Chioudf659632010-11-08 03:06:08 +0000426 decl += ", ";
Che-Liang Chiouf48817c2011-03-02 07:36:48 +0000427 decl += ".param .";
428 decl += getRegisterTypeName(reg);
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000429 decl += " ";
Che-Liang Chioudf659632010-11-08 03:06:08 +0000430 decl += PARAM_PREFIX;
Che-Liang Chioufd8978b2011-03-02 03:20:28 +0000431 decl += utostr(++cnt);
Che-Liang Chioudf659632010-11-08 03:06:08 +0000432 }
433 } else {
Che-Liang Chiou8902ecb2011-03-18 11:23:56 +0000434 for (PTXMachineFunctionInfo::reg_iterator
435 i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i;
Che-Liang Chiou31c488c2011-03-02 07:58:46 +0000436 i != e; ++i) {
Che-Liang Chioudf659632010-11-08 03:06:08 +0000437 reg = *i;
438 assert(reg != PTX::NoRegister && "Not a valid register!");
439 if (i != b)
440 decl += ", ";
Che-Liang Chiou3f409f72010-11-17 08:08:49 +0000441 decl += ".reg .";
Che-Liang Chioudf659632010-11-08 03:06:08 +0000442 decl += getRegisterTypeName(reg);
443 decl += " ";
444 decl += getRegisterName(reg);
445 }
446 }
447 decl += ")";
448 }
449
450 OutStreamer.EmitRawText(Twine(decl));
451}
452
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +0000453void PTXAsmPrinter::
454printPredicateOperand(const MachineInstr *MI, raw_ostream &O) {
455 int i = MI->findFirstPredOperandIdx();
456 if (i == -1)
457 llvm_unreachable("missing predicate operand");
458
459 unsigned reg = MI->getOperand(i).getReg();
460 int predOp = MI->getOperand(i+1).getImm();
461
462 DEBUG(dbgs() << "predicate: (" << reg << ", " << predOp << ")\n");
463
Che-Liang Chiouf78847e2011-03-14 11:26:01 +0000464 if (reg != PTX::NoRegister) {
Che-Liang Chiouc2ec0f92011-03-13 17:26:00 +0000465 O << '@';
466 if (predOp == PTX::PRED_NEGATE)
467 O << '!';
468 O << getRegisterName(reg);
469 }
470}
471
Eric Christopher50880d02010-09-18 18:52:28 +0000472#include "PTXGenAsmWriter.inc"
473
Nick Lewyckyf7a3c502010-09-07 18:14:24 +0000474// Force static initialization.
Eric Christopher50880d02010-09-18 18:52:28 +0000475extern "C" void LLVMInitializePTXAsmPrinter() {
Justin Holewinskie1fee482011-04-20 15:37:17 +0000476 RegisterAsmPrinter<PTXAsmPrinter> X(ThePTX32Target);
477 RegisterAsmPrinter<PTXAsmPrinter> Y(ThePTX64Target);
Nick Lewyckyf7a3c502010-09-07 18:14:24 +0000478}