Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 1 | //===-- 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 Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "ptx-asm-printer" |
| 16 | |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 17 | #include "PTX.h" |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 18 | #include "PTXMachineFunctionInfo.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 19 | #include "PTXTargetMachine.h" |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 20 | #include "llvm/DerivedTypes.h" |
| 21 | #include "llvm/Module.h" |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallString.h" |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
| 24 | #include "llvm/ADT/Twine.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/AsmPrinter.h" |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineInstr.h" |
| 27 | #include "llvm/MC/MCStreamer.h" |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCSymbol.h" |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 29 | #include "llvm/Target/Mangler.h" |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetRegistry.h" |
Che-Liang Chiou | 21d8b9b | 2010-11-30 10:14:14 +0000 | [diff] [blame] | 32 | #include "llvm/Support/CommandLine.h" |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Debug.h" |
| 34 | #include "llvm/Support/ErrorHandling.h" |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 35 | #include "llvm/Support/MathExtras.h" |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 36 | #include "llvm/Support/raw_ostream.h" |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 37 | |
| 38 | using namespace llvm; |
| 39 | |
Che-Liang Chiou | 21d8b9b | 2010-11-30 10:14:14 +0000 | [diff] [blame] | 40 | static cl::opt<std::string> |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 41 | OptPTXVersion("ptx-version", cl::desc("Set PTX version"), cl::init("1.4")); |
Che-Liang Chiou | 21d8b9b | 2010-11-30 10:14:14 +0000 | [diff] [blame] | 42 | |
| 43 | static cl::opt<std::string> |
| 44 | OptPTXTarget("ptx-target", cl::desc("Set GPU target (comma-separated list)"), |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 45 | cl::init("sm_10")); |
Che-Liang Chiou | 21d8b9b | 2010-11-30 10:14:14 +0000 | [diff] [blame] | 46 | |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 47 | namespace { |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 48 | class PTXAsmPrinter : public AsmPrinter { |
| 49 | public: |
| 50 | explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) |
| 51 | : AsmPrinter(TM, Streamer) {} |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 52 | |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 53 | const char *getPassName() const { return "PTX Assembly Printer"; } |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 54 | |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 55 | bool doFinalization(Module &M); |
| 56 | |
Che-Liang Chiou | 21d8b9b | 2010-11-30 10:14:14 +0000 | [diff] [blame] | 57 | virtual void EmitStartOfAsmFile(Module &M); |
| 58 | |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 59 | virtual bool runOnMachineFunction(MachineFunction &MF); |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 60 | |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 61 | virtual void EmitFunctionBodyStart(); |
| 62 | virtual void EmitFunctionBodyEnd() { OutStreamer.EmitRawText(Twine("}")); } |
| 63 | |
| 64 | virtual void EmitInstruction(const MachineInstr *MI); |
| 65 | |
| 66 | void printOperand(const MachineInstr *MI, int opNum, raw_ostream &OS); |
Che-Liang Chiou | 3f8e617 | 2010-11-30 07:34:44 +0000 | [diff] [blame] | 67 | void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS, |
| 68 | const char *Modifier = 0); |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 69 | void printParamOperand(const MachineInstr *MI, int opNum, raw_ostream &OS, |
| 70 | const char *Modifier = 0); |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 71 | |
| 72 | // autogen'd. |
| 73 | void printInstruction(const MachineInstr *MI, raw_ostream &OS); |
| 74 | static const char *getRegisterName(unsigned RegNo); |
| 75 | |
| 76 | private: |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 77 | void EmitVariableDeclaration(const GlobalVariable *gv); |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 78 | void EmitFunctionDeclaration(); |
| 79 | }; // class PTXAsmPrinter |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 80 | } // namespace |
| 81 | |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 82 | static const char PARAM_PREFIX[] = "__param_"; |
| 83 | |
Che-Liang Chiou | 3f8e617 | 2010-11-30 07:34:44 +0000 | [diff] [blame] | 84 | static const char *getRegisterTypeName(unsigned RegNo) { |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 85 | #define TEST_REGCLS(cls, clsstr) \ |
| 86 | if (PTX::cls ## RegisterClass->contains(RegNo)) return # clsstr; |
Che-Liang Chiou | f717202 | 2011-02-28 06:34:09 +0000 | [diff] [blame^] | 87 | TEST_REGCLS(RRegf32, f32); |
Che-Liang Chiou | 3f409f7 | 2010-11-17 08:08:49 +0000 | [diff] [blame] | 88 | TEST_REGCLS(RRegs32, s32); |
| 89 | TEST_REGCLS(Preds, pred); |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 90 | #undef TEST_REGCLS |
| 91 | |
| 92 | llvm_unreachable("Not in any register class!"); |
| 93 | return NULL; |
| 94 | } |
| 95 | |
Che-Liang Chiou | 3f8e617 | 2010-11-30 07:34:44 +0000 | [diff] [blame] | 96 | static const char *getInstructionTypeName(const MachineInstr *MI) { |
Che-Liang Chiou | 3f409f7 | 2010-11-17 08:08:49 +0000 | [diff] [blame] | 97 | for (int i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 98 | const MachineOperand &MO = MI->getOperand(i); |
| 99 | if (MO.getType() == MachineOperand::MO_Register) |
| 100 | return getRegisterTypeName(MO.getReg()); |
| 101 | } |
| 102 | |
| 103 | llvm_unreachable("No reg operand found in instruction!"); |
| 104 | return NULL; |
| 105 | } |
| 106 | |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 107 | static const char *getStateSpaceName(unsigned addressSpace) { |
Che-Liang Chiou | d34f19f | 2010-12-30 10:41:27 +0000 | [diff] [blame] | 108 | switch (addressSpace) { |
| 109 | default: llvm_unreachable("Unknown state space"); |
| 110 | case PTX::GLOBAL: return "global"; |
| 111 | case PTX::CONSTANT: return "const"; |
| 112 | case PTX::LOCAL: return "local"; |
| 113 | case PTX::PARAMETER: return "param"; |
| 114 | case PTX::SHARED: return "shared"; |
| 115 | } |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 116 | return NULL; |
| 117 | } |
| 118 | |
Che-Liang Chiou | f717202 | 2011-02-28 06:34:09 +0000 | [diff] [blame^] | 119 | static const char *getTypeName(const Type* type) { |
| 120 | while (true) { |
| 121 | switch (type->getTypeID()) { |
| 122 | default: llvm_unreachable("Unknown type"); |
| 123 | case Type::FloatTyID: return ".f32"; |
| 124 | case Type::IntegerTyID: return ".s32"; // TODO: Handle 64-bit types. |
| 125 | case Type::ArrayTyID: |
| 126 | case Type::PointerTyID: |
| 127 | type = dyn_cast<const SequentialType>(type)->getElementType(); |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | return NULL; |
| 132 | } |
| 133 | |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 134 | bool PTXAsmPrinter::doFinalization(Module &M) { |
| 135 | // XXX Temproarily remove global variables so that doFinalization() will not |
| 136 | // emit them again (global variables are emitted at beginning). |
| 137 | |
| 138 | Module::GlobalListType &global_list = M.getGlobalList(); |
| 139 | int i, n = global_list.size(); |
| 140 | GlobalVariable **gv_array = new GlobalVariable* [n]; |
| 141 | |
| 142 | // first, back-up GlobalVariable in gv_array |
| 143 | i = 0; |
| 144 | for (Module::global_iterator I = global_list.begin(), E = global_list.end(); |
| 145 | I != E; ++I) |
| 146 | gv_array[i++] = &*I; |
| 147 | |
| 148 | // second, empty global_list |
| 149 | while (!global_list.empty()) |
| 150 | global_list.remove(global_list.begin()); |
| 151 | |
| 152 | // call doFinalization |
| 153 | bool ret = AsmPrinter::doFinalization(M); |
| 154 | |
| 155 | // now we restore global variables |
| 156 | for (i = 0; i < n; i ++) |
| 157 | global_list.insert(global_list.end(), gv_array[i]); |
| 158 | |
| 159 | delete[] gv_array; |
| 160 | return ret; |
| 161 | } |
| 162 | |
Che-Liang Chiou | 21d8b9b | 2010-11-30 10:14:14 +0000 | [diff] [blame] | 163 | void PTXAsmPrinter::EmitStartOfAsmFile(Module &M) |
| 164 | { |
| 165 | OutStreamer.EmitRawText(Twine("\t.version " + OptPTXVersion)); |
| 166 | OutStreamer.EmitRawText(Twine("\t.target " + OptPTXTarget)); |
| 167 | OutStreamer.AddBlankLine(); |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 168 | |
| 169 | // declare global variables |
| 170 | for (Module::const_global_iterator i = M.global_begin(), e = M.global_end(); |
| 171 | i != e; ++i) |
| 172 | EmitVariableDeclaration(i); |
Che-Liang Chiou | 21d8b9b | 2010-11-30 10:14:14 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 175 | bool PTXAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
| 176 | SetupMachineFunction(MF); |
| 177 | EmitFunctionDeclaration(); |
| 178 | EmitFunctionBody(); |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | void PTXAsmPrinter::EmitFunctionBodyStart() { |
| 183 | OutStreamer.EmitRawText(Twine("{")); |
| 184 | |
| 185 | const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>(); |
| 186 | |
| 187 | // Print local variable definition |
| 188 | for (PTXMachineFunctionInfo::reg_iterator |
| 189 | i = MFI->localVarRegBegin(), e = MFI->localVarRegEnd(); i != e; ++ i) { |
| 190 | unsigned reg = *i; |
| 191 | |
Che-Liang Chiou | 3f409f7 | 2010-11-17 08:08:49 +0000 | [diff] [blame] | 192 | std::string def = "\t.reg ."; |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 193 | def += getRegisterTypeName(reg); |
| 194 | def += ' '; |
| 195 | def += getRegisterName(reg); |
| 196 | def += ';'; |
| 197 | OutStreamer.EmitRawText(Twine(def)); |
| 198 | } |
| 199 | } |
| 200 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 201 | void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
Che-Liang Chiou | 3608d2a | 2010-12-01 11:45:53 +0000 | [diff] [blame] | 202 | std::string str; |
| 203 | str.reserve(64); |
| 204 | |
| 205 | // Write instruction to str |
| 206 | raw_string_ostream OS(str); |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 207 | printInstruction(MI, OS); |
| 208 | OS << ';'; |
Che-Liang Chiou | 3608d2a | 2010-12-01 11:45:53 +0000 | [diff] [blame] | 209 | OS.flush(); |
Che-Liang Chiou | 3f409f7 | 2010-11-17 08:08:49 +0000 | [diff] [blame] | 210 | |
| 211 | // Replace "%type" if found |
Che-Liang Chiou | 3f409f7 | 2010-11-17 08:08:49 +0000 | [diff] [blame] | 212 | size_t pos; |
Che-Liang Chiou | 3608d2a | 2010-12-01 11:45:53 +0000 | [diff] [blame] | 213 | if ((pos = str.find("%type")) != std::string::npos) |
Che-Liang Chiou | 3f8e617 | 2010-11-30 07:34:44 +0000 | [diff] [blame] | 214 | str.replace(pos, /*strlen("%type")==*/5, getInstructionTypeName(MI)); |
Che-Liang Chiou | 3f8e617 | 2010-11-30 07:34:44 +0000 | [diff] [blame] | 215 | |
Che-Liang Chiou | 3608d2a | 2010-12-01 11:45:53 +0000 | [diff] [blame] | 216 | StringRef strref = StringRef(str); |
Che-Liang Chiou | 3f8e617 | 2010-11-30 07:34:44 +0000 | [diff] [blame] | 217 | OutStreamer.EmitRawText(strref); |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum, |
| 221 | raw_ostream &OS) { |
| 222 | const MachineOperand &MO = MI->getOperand(opNum); |
| 223 | |
| 224 | switch (MO.getType()) { |
| 225 | default: |
| 226 | llvm_unreachable("<unknown operand type>"); |
| 227 | break; |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 228 | case MachineOperand::MO_GlobalAddress: |
| 229 | OS << *Mang->getSymbol(MO.getGlobal()); |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 230 | break; |
| 231 | case MachineOperand::MO_Immediate: |
| 232 | OS << (int) MO.getImm(); |
| 233 | break; |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 234 | case MachineOperand::MO_Register: |
| 235 | OS << getRegisterName(MO.getReg()); |
| 236 | break; |
Che-Liang Chiou | f717202 | 2011-02-28 06:34:09 +0000 | [diff] [blame^] | 237 | case MachineOperand::MO_FPImmediate: |
| 238 | APInt constFP = MO.getFPImm()->getValueAPF().bitcastToAPInt(); |
| 239 | if (constFP.getZExtValue() > 0) { |
| 240 | OS << "0F" << constFP.toString(16, false); |
| 241 | } |
| 242 | else { |
| 243 | OS << "0F00000000"; |
| 244 | } |
| 245 | break; |
Che-Liang Chiou | b48f2c2 | 2010-10-19 13:14:40 +0000 | [diff] [blame] | 246 | } |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Che-Liang Chiou | 3f8e617 | 2010-11-30 07:34:44 +0000 | [diff] [blame] | 249 | void PTXAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum, |
| 250 | raw_ostream &OS, const char *Modifier) { |
| 251 | printOperand(MI, opNum, OS); |
| 252 | |
| 253 | if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() == 0) |
| 254 | return; // don't print "+0" |
| 255 | |
| 256 | OS << "+"; |
| 257 | printOperand(MI, opNum+1, OS); |
| 258 | } |
| 259 | |
Che-Liang Chiou | 8e5d01c | 2011-02-10 12:01:24 +0000 | [diff] [blame] | 260 | void PTXAsmPrinter::printParamOperand(const MachineInstr *MI, int opNum, |
| 261 | raw_ostream &OS, const char *Modifier) { |
| 262 | OS << PARAM_PREFIX << (int) MI->getOperand(opNum).getImm() + 1; |
| 263 | } |
| 264 | |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 265 | void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) { |
| 266 | // Check to see if this is a special global used by LLVM, if so, emit it. |
| 267 | if (EmitSpecialLLVMGlobal(gv)) |
| 268 | return; |
| 269 | |
| 270 | MCSymbol *gvsym = Mang->getSymbol(gv); |
| 271 | |
| 272 | assert(gvsym->isUndefined() && "Cannot define a symbol twice!"); |
| 273 | |
| 274 | std::string decl; |
| 275 | |
| 276 | // check if it is defined in some other translation unit |
| 277 | if (gv->isDeclaration()) |
| 278 | decl += ".extern "; |
| 279 | |
| 280 | // state space: e.g., .global |
| 281 | decl += "."; |
| 282 | decl += getStateSpaceName(gv->getType()->getAddressSpace()); |
| 283 | decl += " "; |
| 284 | |
| 285 | // alignment (optional) |
| 286 | unsigned alignment = gv->getAlignment(); |
| 287 | if (alignment != 0) { |
| 288 | decl += ".align "; |
| 289 | decl += utostr(Log2_32(gv->getAlignment())); |
| 290 | decl += " "; |
| 291 | } |
| 292 | |
Che-Liang Chiou | f717202 | 2011-02-28 06:34:09 +0000 | [diff] [blame^] | 293 | decl += getTypeName(gv->getType()); |
| 294 | decl += " "; |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 295 | |
| 296 | decl += gvsym->getName(); |
| 297 | |
| 298 | if (ArrayType::classof(gv->getType()) || PointerType::classof(gv->getType())) |
| 299 | decl += "[]"; |
| 300 | |
| 301 | decl += ";"; |
| 302 | |
| 303 | OutStreamer.EmitRawText(Twine(decl)); |
| 304 | |
| 305 | OutStreamer.AddBlankLine(); |
| 306 | } |
| 307 | |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 308 | void PTXAsmPrinter::EmitFunctionDeclaration() { |
| 309 | // The function label could have already been emitted if two symbols end up |
| 310 | // conflicting due to asm renaming. Detect this and emit an error. |
| 311 | if (!CurrentFnSym->isUndefined()) { |
| 312 | report_fatal_error("'" + Twine(CurrentFnSym->getName()) + |
| 313 | "' label emitted multiple times to assembly file"); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>(); |
| 318 | const bool isKernel = MFI->isKernel(); |
| 319 | unsigned reg; |
| 320 | |
| 321 | std::string decl = isKernel ? ".entry" : ".func"; |
| 322 | |
| 323 | // Print return register |
| 324 | reg = MFI->retReg(); |
| 325 | if (!isKernel && reg != PTX::NoRegister) { |
Che-Liang Chiou | 3f409f7 | 2010-11-17 08:08:49 +0000 | [diff] [blame] | 326 | decl += " (.reg ."; // FIXME: could it return in .param space? |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 327 | decl += getRegisterTypeName(reg); |
| 328 | decl += " "; |
| 329 | decl += getRegisterName(reg); |
| 330 | decl += ")"; |
| 331 | } |
| 332 | |
| 333 | // Print function name |
| 334 | decl += " "; |
| 335 | decl += CurrentFnSym->getName().str(); |
| 336 | |
| 337 | // Print parameter list |
| 338 | if (!MFI->argRegEmpty()) { |
| 339 | decl += " ("; |
| 340 | if (isKernel) { |
| 341 | for (int i = 0, e = MFI->getNumArg(); i != e; ++i) { |
| 342 | if (i != 0) |
| 343 | decl += ", "; |
Che-Liang Chiou | fc7072c | 2010-12-22 10:38:51 +0000 | [diff] [blame] | 344 | decl += ".param .s32 "; // TODO: add types |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 345 | decl += PARAM_PREFIX; |
| 346 | decl += utostr(i + 1); |
| 347 | } |
| 348 | } else { |
| 349 | for (PTXMachineFunctionInfo::reg_iterator |
| 350 | i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i; i != e; ++i) { |
| 351 | reg = *i; |
| 352 | assert(reg != PTX::NoRegister && "Not a valid register!"); |
| 353 | if (i != b) |
| 354 | decl += ", "; |
Che-Liang Chiou | 3f409f7 | 2010-11-17 08:08:49 +0000 | [diff] [blame] | 355 | decl += ".reg ."; |
Che-Liang Chiou | df65963 | 2010-11-08 03:06:08 +0000 | [diff] [blame] | 356 | decl += getRegisterTypeName(reg); |
| 357 | decl += " "; |
| 358 | decl += getRegisterName(reg); |
| 359 | } |
| 360 | } |
| 361 | decl += ")"; |
| 362 | } |
| 363 | |
| 364 | OutStreamer.EmitRawText(Twine(decl)); |
| 365 | } |
| 366 | |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 367 | #include "PTXGenAsmWriter.inc" |
| 368 | |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 369 | // Force static initialization. |
Eric Christopher | 50880d0 | 2010-09-18 18:52:28 +0000 | [diff] [blame] | 370 | extern "C" void LLVMInitializePTXAsmPrinter() { |
Nick Lewycky | f7a3c50 | 2010-09-07 18:14:24 +0000 | [diff] [blame] | 371 | RegisterAsmPrinter<PTXAsmPrinter> X(ThePTXTarget); |
| 372 | } |