2010-09-07 18:14:24 +00:00
|
|
|
//===-- PTXAsmPrinter.cpp - PTX LLVM assembly writer ----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to PTX assembly language.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
#define DEBUG_TYPE "ptx-asm-printer"
|
|
|
|
|
2010-09-07 18:14:24 +00:00
|
|
|
#include "PTX.h"
|
2010-11-08 03:06:08 +00:00
|
|
|
#include "PTXMachineFunctionInfo.h"
|
2010-09-07 18:14:24 +00:00
|
|
|
#include "PTXTargetMachine.h"
|
2010-12-22 10:38:51 +00:00
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Module.h"
|
2010-09-18 18:52:28 +00:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2010-11-08 03:06:08 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2010-09-07 18:14:24 +00:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2010-09-18 18:52:28 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2011-03-02 03:20:28 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2010-09-18 18:52:28 +00:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-11-08 03:06:08 +00:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-12-22 10:38:51 +00:00
|
|
|
#include "llvm/Target/Mangler.h"
|
2010-11-08 03:06:08 +00:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2010-09-07 18:14:24 +00:00
|
|
|
#include "llvm/Target/TargetRegistry.h"
|
2010-11-30 10:14:14 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2010-11-08 03:06:08 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-12-22 10:38:51 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2010-11-08 03:06:08 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-09-07 18:14:24 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
2010-11-08 03:06:08 +00:00
|
|
|
class PTXAsmPrinter : public AsmPrinter {
|
|
|
|
public:
|
|
|
|
explicit PTXAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
|
|
|
|
: AsmPrinter(TM, Streamer) {}
|
|
|
|
|
|
|
|
const char *getPassName() const { return "PTX Assembly Printer"; }
|
|
|
|
|
2010-12-22 10:38:51 +00:00
|
|
|
bool doFinalization(Module &M);
|
|
|
|
|
2010-11-30 10:14:14 +00:00
|
|
|
virtual void EmitStartOfAsmFile(Module &M);
|
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
2010-09-18 18:52:28 +00:00
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
virtual void EmitFunctionBodyStart();
|
|
|
|
virtual void EmitFunctionBodyEnd() { OutStreamer.EmitRawText(Twine("}")); }
|
2010-09-18 18:52:28 +00:00
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
virtual void EmitInstruction(const MachineInstr *MI);
|
2010-10-19 13:14:40 +00:00
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
|
2010-11-30 07:34:44 +00:00
|
|
|
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
|
|
|
|
const char *Modifier = 0);
|
2011-02-10 12:01:24 +00:00
|
|
|
void printParamOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
|
|
|
|
const char *Modifier = 0);
|
2011-03-13 17:26:00 +00:00
|
|
|
void printPredicateOperand(const MachineInstr *MI, raw_ostream &O);
|
2010-11-08 03:06:08 +00:00
|
|
|
|
|
|
|
// autogen'd.
|
|
|
|
void printInstruction(const MachineInstr *MI, raw_ostream &OS);
|
|
|
|
static const char *getRegisterName(unsigned RegNo);
|
|
|
|
|
|
|
|
private:
|
2010-12-22 10:38:51 +00:00
|
|
|
void EmitVariableDeclaration(const GlobalVariable *gv);
|
2010-11-08 03:06:08 +00:00
|
|
|
void EmitFunctionDeclaration();
|
|
|
|
}; // class PTXAsmPrinter
|
2010-09-07 18:14:24 +00:00
|
|
|
} // namespace
|
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
static const char PARAM_PREFIX[] = "__param_";
|
|
|
|
|
2010-11-30 07:34:44 +00:00
|
|
|
static const char *getRegisterTypeName(unsigned RegNo) {
|
2011-03-02 03:20:28 +00:00
|
|
|
#define TEST_REGCLS(cls, clsstr) \
|
2010-11-08 03:06:08 +00:00
|
|
|
if (PTX::cls ## RegisterClass->contains(RegNo)) return # clsstr;
|
2010-11-17 08:08:49 +00:00
|
|
|
TEST_REGCLS(Preds, pred);
|
2011-03-02 03:20:28 +00:00
|
|
|
TEST_REGCLS(RRegu16, u16);
|
|
|
|
TEST_REGCLS(RRegu32, u32);
|
|
|
|
TEST_REGCLS(RRegu64, u64);
|
|
|
|
TEST_REGCLS(RRegf32, f32);
|
|
|
|
TEST_REGCLS(RRegf64, f64);
|
2010-11-08 03:06:08 +00:00
|
|
|
#undef TEST_REGCLS
|
|
|
|
|
|
|
|
llvm_unreachable("Not in any register class!");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-22 10:38:51 +00:00
|
|
|
static const char *getStateSpaceName(unsigned addressSpace) {
|
2010-12-30 10:41:27 +00:00
|
|
|
switch (addressSpace) {
|
|
|
|
default: llvm_unreachable("Unknown state space");
|
|
|
|
case PTX::GLOBAL: return "global";
|
|
|
|
case PTX::CONSTANT: return "const";
|
|
|
|
case PTX::LOCAL: return "local";
|
|
|
|
case PTX::PARAMETER: return "param";
|
|
|
|
case PTX::SHARED: return "shared";
|
|
|
|
}
|
2010-12-22 10:38:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-28 06:34:09 +00:00
|
|
|
static const char *getTypeName(const Type* type) {
|
|
|
|
while (true) {
|
|
|
|
switch (type->getTypeID()) {
|
|
|
|
default: llvm_unreachable("Unknown type");
|
|
|
|
case Type::FloatTyID: return ".f32";
|
2011-03-02 03:20:28 +00:00
|
|
|
case Type::DoubleTyID: return ".f64";
|
|
|
|
case Type::IntegerTyID:
|
|
|
|
switch (type->getPrimitiveSizeInBits()) {
|
|
|
|
default: llvm_unreachable("Unknown integer bit-width");
|
|
|
|
case 16: return ".u16";
|
|
|
|
case 32: return ".u32";
|
|
|
|
case 64: return ".u64";
|
|
|
|
}
|
2011-02-28 06:34:09 +00:00
|
|
|
case Type::ArrayTyID:
|
|
|
|
case Type::PointerTyID:
|
|
|
|
type = dyn_cast<const SequentialType>(type)->getElementType();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-22 10:38:51 +00:00
|
|
|
bool PTXAsmPrinter::doFinalization(Module &M) {
|
|
|
|
// XXX Temproarily remove global variables so that doFinalization() will not
|
|
|
|
// emit them again (global variables are emitted at beginning).
|
|
|
|
|
|
|
|
Module::GlobalListType &global_list = M.getGlobalList();
|
|
|
|
int i, n = global_list.size();
|
|
|
|
GlobalVariable **gv_array = new GlobalVariable* [n];
|
|
|
|
|
|
|
|
// first, back-up GlobalVariable in gv_array
|
|
|
|
i = 0;
|
|
|
|
for (Module::global_iterator I = global_list.begin(), E = global_list.end();
|
|
|
|
I != E; ++I)
|
|
|
|
gv_array[i++] = &*I;
|
|
|
|
|
|
|
|
// second, empty global_list
|
|
|
|
while (!global_list.empty())
|
|
|
|
global_list.remove(global_list.begin());
|
|
|
|
|
|
|
|
// call doFinalization
|
|
|
|
bool ret = AsmPrinter::doFinalization(M);
|
|
|
|
|
|
|
|
// now we restore global variables
|
|
|
|
for (i = 0; i < n; i ++)
|
|
|
|
global_list.insert(global_list.end(), gv_array[i]);
|
|
|
|
|
|
|
|
delete[] gv_array;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-30 10:14:14 +00:00
|
|
|
void PTXAsmPrinter::EmitStartOfAsmFile(Module &M)
|
|
|
|
{
|
2011-03-02 03:20:28 +00:00
|
|
|
const PTXSubtarget& ST = TM.getSubtarget<PTXSubtarget>();
|
|
|
|
|
|
|
|
OutStreamer.EmitRawText(Twine("\t.version " + ST.getPTXVersionString()));
|
|
|
|
OutStreamer.EmitRawText(Twine("\t.target " + ST.getTargetString() +
|
2011-03-03 13:34:29 +00:00
|
|
|
(ST.supportsDouble() ? ""
|
|
|
|
: ", map_f64_to_f32")));
|
2010-11-30 10:14:14 +00:00
|
|
|
OutStreamer.AddBlankLine();
|
2010-12-22 10:38:51 +00:00
|
|
|
|
|
|
|
// declare global variables
|
|
|
|
for (Module::const_global_iterator i = M.global_begin(), e = M.global_end();
|
|
|
|
i != e; ++i)
|
|
|
|
EmitVariableDeclaration(i);
|
2010-11-30 10:14:14 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
bool PTXAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
SetupMachineFunction(MF);
|
|
|
|
EmitFunctionDeclaration();
|
|
|
|
EmitFunctionBody();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PTXAsmPrinter::EmitFunctionBodyStart() {
|
|
|
|
OutStreamer.EmitRawText(Twine("{"));
|
|
|
|
|
|
|
|
const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>();
|
|
|
|
|
|
|
|
// Print local variable definition
|
|
|
|
for (PTXMachineFunctionInfo::reg_iterator
|
|
|
|
i = MFI->localVarRegBegin(), e = MFI->localVarRegEnd(); i != e; ++ i) {
|
|
|
|
unsigned reg = *i;
|
|
|
|
|
2010-11-17 08:08:49 +00:00
|
|
|
std::string def = "\t.reg .";
|
2010-11-08 03:06:08 +00:00
|
|
|
def += getRegisterTypeName(reg);
|
|
|
|
def += ' ';
|
|
|
|
def += getRegisterName(reg);
|
|
|
|
def += ';';
|
|
|
|
OutStreamer.EmitRawText(Twine(def));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-18 18:52:28 +00:00
|
|
|
void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
2010-12-01 11:45:53 +00:00
|
|
|
std::string str;
|
|
|
|
str.reserve(64);
|
|
|
|
|
|
|
|
raw_string_ostream OS(str);
|
2011-03-13 17:26:00 +00:00
|
|
|
|
|
|
|
// Emit predicate
|
|
|
|
printPredicateOperand(MI, OS);
|
|
|
|
|
|
|
|
// Write instruction to str
|
2010-10-19 13:14:40 +00:00
|
|
|
printInstruction(MI, OS);
|
|
|
|
OS << ';';
|
2010-12-01 11:45:53 +00:00
|
|
|
OS.flush();
|
2010-11-17 08:08:49 +00:00
|
|
|
|
2010-12-01 11:45:53 +00:00
|
|
|
StringRef strref = StringRef(str);
|
2010-11-30 07:34:44 +00:00
|
|
|
OutStreamer.EmitRawText(strref);
|
2010-10-19 13:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(opNum);
|
|
|
|
|
|
|
|
switch (MO.getType()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("<unknown operand type>");
|
|
|
|
break;
|
2010-12-22 10:38:51 +00:00
|
|
|
case MachineOperand::MO_GlobalAddress:
|
|
|
|
OS << *Mang->getSymbol(MO.getGlobal());
|
2010-10-19 13:14:40 +00:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_Immediate:
|
2011-04-28 00:19:50 +00:00
|
|
|
OS << (long) MO.getImm();
|
2010-10-19 13:14:40 +00:00
|
|
|
break;
|
2011-03-18 11:08:52 +00:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
OS << *MO.getMBB()->getSymbol();
|
|
|
|
break;
|
2010-12-22 10:38:51 +00:00
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
OS << getRegisterName(MO.getReg());
|
|
|
|
break;
|
2011-02-28 06:34:09 +00:00
|
|
|
case MachineOperand::MO_FPImmediate:
|
|
|
|
APInt constFP = MO.getFPImm()->getValueAPF().bitcastToAPInt();
|
2011-03-02 03:20:28 +00:00
|
|
|
bool isFloat = MO.getFPImm()->getType()->getTypeID() == Type::FloatTyID;
|
|
|
|
// Emit 0F for 32-bit floats and 0D for 64-bit doubles.
|
|
|
|
if (isFloat) {
|
|
|
|
OS << "0F";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
OS << "0D";
|
|
|
|
}
|
|
|
|
// Emit the encoded floating-point value.
|
2011-02-28 06:34:09 +00:00
|
|
|
if (constFP.getZExtValue() > 0) {
|
2011-03-02 03:20:28 +00:00
|
|
|
OS << constFP.toString(16, false);
|
2011-02-28 06:34:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-03-02 03:20:28 +00:00
|
|
|
OS << "00000000";
|
|
|
|
// If We have a double-precision zero, pad to 8-bytes.
|
|
|
|
if (!isFloat) {
|
|
|
|
OS << "00000000";
|
|
|
|
}
|
2011-02-28 06:34:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-10-19 13:14:40 +00:00
|
|
|
}
|
2010-09-18 18:52:28 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 07:34:44 +00:00
|
|
|
void PTXAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
|
|
|
|
raw_ostream &OS, const char *Modifier) {
|
|
|
|
printOperand(MI, opNum, OS);
|
|
|
|
|
|
|
|
if (MI->getOperand(opNum+1).isImm() && MI->getOperand(opNum+1).getImm() == 0)
|
|
|
|
return; // don't print "+0"
|
|
|
|
|
|
|
|
OS << "+";
|
|
|
|
printOperand(MI, opNum+1, OS);
|
|
|
|
}
|
|
|
|
|
2011-02-10 12:01:24 +00:00
|
|
|
void PTXAsmPrinter::printParamOperand(const MachineInstr *MI, int opNum,
|
|
|
|
raw_ostream &OS, const char *Modifier) {
|
|
|
|
OS << PARAM_PREFIX << (int) MI->getOperand(opNum).getImm() + 1;
|
|
|
|
}
|
|
|
|
|
2010-12-22 10:38:51 +00:00
|
|
|
void PTXAsmPrinter::EmitVariableDeclaration(const GlobalVariable *gv) {
|
|
|
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
|
|
|
if (EmitSpecialLLVMGlobal(gv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
MCSymbol *gvsym = Mang->getSymbol(gv);
|
|
|
|
|
|
|
|
assert(gvsym->isUndefined() && "Cannot define a symbol twice!");
|
|
|
|
|
|
|
|
std::string decl;
|
|
|
|
|
|
|
|
// check if it is defined in some other translation unit
|
|
|
|
if (gv->isDeclaration())
|
|
|
|
decl += ".extern ";
|
|
|
|
|
|
|
|
// state space: e.g., .global
|
|
|
|
decl += ".";
|
|
|
|
decl += getStateSpaceName(gv->getType()->getAddressSpace());
|
|
|
|
decl += " ";
|
|
|
|
|
|
|
|
// alignment (optional)
|
|
|
|
unsigned alignment = gv->getAlignment();
|
|
|
|
if (alignment != 0) {
|
|
|
|
decl += ".align ";
|
|
|
|
decl += utostr(Log2_32(gv->getAlignment()));
|
|
|
|
decl += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-14 15:40:11 +00:00
|
|
|
if (PointerType::classof(gv->getType())) {
|
|
|
|
const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
|
|
|
|
const Type* elementTy = pointerTy->getElementType();
|
|
|
|
|
2011-04-28 00:19:50 +00:00
|
|
|
decl += ".b8 ";
|
|
|
|
decl += gvsym->getName();
|
|
|
|
decl += "[";
|
|
|
|
|
|
|
|
if (elementTy->isArrayTy())
|
|
|
|
{
|
|
|
|
assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
|
2011-03-18 19:24:28 +00:00
|
|
|
|
2011-04-28 00:19:50 +00:00
|
|
|
const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
|
2011-03-18 19:24:28 +00:00
|
|
|
elementTy = arrayTy->getElementType();
|
|
|
|
|
2011-04-28 00:19:50 +00:00
|
|
|
unsigned numElements = arrayTy->getNumElements();
|
|
|
|
|
|
|
|
while (elementTy->isArrayTy()) {
|
|
|
|
|
|
|
|
arrayTy = dyn_cast<const ArrayType>(elementTy);
|
|
|
|
elementTy = arrayTy->getElementType();
|
2011-03-18 19:24:28 +00:00
|
|
|
|
2011-04-28 00:19:50 +00:00
|
|
|
numElements *= arrayTy->getNumElements();
|
|
|
|
}
|
2011-03-14 15:40:11 +00:00
|
|
|
|
2011-04-28 00:19:50 +00:00
|
|
|
// FIXME: isPrimitiveType() == false for i16?
|
|
|
|
assert(elementTy->isSingleValueType() &&
|
|
|
|
"Non-primitive types are not handled");
|
2010-12-22 10:38:51 +00:00
|
|
|
|
2011-04-28 00:19:50 +00:00
|
|
|
// Compute the size of the array, in bytes.
|
|
|
|
uint64_t arraySize = (elementTy->getPrimitiveSizeInBits() >> 3)
|
|
|
|
* numElements;
|
|
|
|
|
|
|
|
decl += utostr(arraySize);
|
|
|
|
}
|
|
|
|
|
2011-03-14 15:40:11 +00:00
|
|
|
decl += "]";
|
2011-04-28 00:19:50 +00:00
|
|
|
|
|
|
|
// handle string constants (assume ConstantArray means string)
|
|
|
|
|
|
|
|
if (gv->hasInitializer())
|
|
|
|
{
|
|
|
|
Constant *C = gv->getInitializer();
|
|
|
|
if (const ConstantArray *CA = dyn_cast<ConstantArray>(C))
|
|
|
|
{
|
|
|
|
decl += " = {";
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
|
|
|
|
{
|
|
|
|
if (i > 0) decl += ",";
|
|
|
|
|
|
|
|
decl += "0x" + utohexstr(cast<ConstantInt>(CA->getOperand(i))->getZExtValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
decl += "}";
|
|
|
|
}
|
|
|
|
}
|
2011-03-14 15:40:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Note: this is currently the fall-through case and most likely generates
|
|
|
|
// incorrect code.
|
|
|
|
decl += getTypeName(gv->getType());
|
|
|
|
decl += " ";
|
|
|
|
|
|
|
|
decl += gvsym->getName();
|
|
|
|
|
|
|
|
if (ArrayType::classof(gv->getType()) ||
|
|
|
|
PointerType::classof(gv->getType()))
|
|
|
|
decl += "[]";
|
|
|
|
}
|
2010-12-22 10:38:51 +00:00
|
|
|
|
|
|
|
decl += ";";
|
|
|
|
|
|
|
|
OutStreamer.EmitRawText(Twine(decl));
|
|
|
|
|
|
|
|
OutStreamer.AddBlankLine();
|
|
|
|
}
|
|
|
|
|
2010-11-08 03:06:08 +00:00
|
|
|
void PTXAsmPrinter::EmitFunctionDeclaration() {
|
|
|
|
// The function label could have already been emitted if two symbols end up
|
|
|
|
// conflicting due to asm renaming. Detect this and emit an error.
|
|
|
|
if (!CurrentFnSym->isUndefined()) {
|
|
|
|
report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
|
|
|
|
"' label emitted multiple times to assembly file");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PTXMachineFunctionInfo *MFI = MF->getInfo<PTXMachineFunctionInfo>();
|
|
|
|
const bool isKernel = MFI->isKernel();
|
|
|
|
unsigned reg;
|
|
|
|
|
|
|
|
std::string decl = isKernel ? ".entry" : ".func";
|
|
|
|
|
|
|
|
// Print return register
|
|
|
|
reg = MFI->retReg();
|
|
|
|
if (!isKernel && reg != PTX::NoRegister) {
|
2010-11-17 08:08:49 +00:00
|
|
|
decl += " (.reg ."; // FIXME: could it return in .param space?
|
2010-11-08 03:06:08 +00:00
|
|
|
decl += getRegisterTypeName(reg);
|
|
|
|
decl += " ";
|
|
|
|
decl += getRegisterName(reg);
|
|
|
|
decl += ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print function name
|
|
|
|
decl += " ";
|
|
|
|
decl += CurrentFnSym->getName().str();
|
|
|
|
|
|
|
|
// Print parameter list
|
|
|
|
if (!MFI->argRegEmpty()) {
|
|
|
|
decl += " (";
|
|
|
|
if (isKernel) {
|
2011-03-02 03:20:28 +00:00
|
|
|
unsigned cnt = 0;
|
2011-03-18 11:23:56 +00:00
|
|
|
for(PTXMachineFunctionInfo::reg_iterator
|
|
|
|
i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i;
|
2011-03-02 07:58:46 +00:00
|
|
|
i != e; ++i) {
|
2011-03-02 03:20:28 +00:00
|
|
|
reg = *i;
|
|
|
|
assert(reg != PTX::NoRegister && "Not a valid register!");
|
|
|
|
if (i != b)
|
2010-11-08 03:06:08 +00:00
|
|
|
decl += ", ";
|
2011-03-02 07:36:48 +00:00
|
|
|
decl += ".param .";
|
|
|
|
decl += getRegisterTypeName(reg);
|
2011-03-02 03:20:28 +00:00
|
|
|
decl += " ";
|
2010-11-08 03:06:08 +00:00
|
|
|
decl += PARAM_PREFIX;
|
2011-03-02 03:20:28 +00:00
|
|
|
decl += utostr(++cnt);
|
2010-11-08 03:06:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-03-18 11:23:56 +00:00
|
|
|
for (PTXMachineFunctionInfo::reg_iterator
|
|
|
|
i = MFI->argRegBegin(), e = MFI->argRegEnd(), b = i;
|
2011-03-02 07:58:46 +00:00
|
|
|
i != e; ++i) {
|
2010-11-08 03:06:08 +00:00
|
|
|
reg = *i;
|
|
|
|
assert(reg != PTX::NoRegister && "Not a valid register!");
|
|
|
|
if (i != b)
|
|
|
|
decl += ", ";
|
2010-11-17 08:08:49 +00:00
|
|
|
decl += ".reg .";
|
2010-11-08 03:06:08 +00:00
|
|
|
decl += getRegisterTypeName(reg);
|
|
|
|
decl += " ";
|
|
|
|
decl += getRegisterName(reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
decl += ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
OutStreamer.EmitRawText(Twine(decl));
|
|
|
|
}
|
|
|
|
|
2011-03-13 17:26:00 +00:00
|
|
|
void PTXAsmPrinter::
|
|
|
|
printPredicateOperand(const MachineInstr *MI, raw_ostream &O) {
|
|
|
|
int i = MI->findFirstPredOperandIdx();
|
|
|
|
if (i == -1)
|
|
|
|
llvm_unreachable("missing predicate operand");
|
|
|
|
|
|
|
|
unsigned reg = MI->getOperand(i).getReg();
|
|
|
|
int predOp = MI->getOperand(i+1).getImm();
|
|
|
|
|
|
|
|
DEBUG(dbgs() << "predicate: (" << reg << ", " << predOp << ")\n");
|
|
|
|
|
2011-03-14 11:26:01 +00:00
|
|
|
if (reg != PTX::NoRegister) {
|
2011-03-13 17:26:00 +00:00
|
|
|
O << '@';
|
|
|
|
if (predOp == PTX::PRED_NEGATE)
|
|
|
|
O << '!';
|
|
|
|
O << getRegisterName(reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-18 18:52:28 +00:00
|
|
|
#include "PTXGenAsmWriter.inc"
|
|
|
|
|
2010-09-07 18:14:24 +00:00
|
|
|
// Force static initialization.
|
2010-09-18 18:52:28 +00:00
|
|
|
extern "C" void LLVMInitializePTXAsmPrinter() {
|
2011-04-20 15:37:17 +00:00
|
|
|
RegisterAsmPrinter<PTXAsmPrinter> X(ThePTX32Target);
|
|
|
|
RegisterAsmPrinter<PTXAsmPrinter> Y(ThePTX64Target);
|
2010-09-07 18:14:24 +00:00
|
|
|
}
|