#include "llvm/MC/MCSymbol.h"
#include "llvm/Target/Mangler.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
-#include "llvm/Target/TargetRegistry.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
const char *Modifier = 0);
void printPredicateOperand(const MachineInstr *MI, raw_ostream &O);
+ void printCall(const MachineInstr *MI, raw_ostream &O);
+
unsigned GetOrCreateSourceID(StringRef FileName,
StringRef DirName);
#define TEST_REGCLS(cls, clsstr) \
if (PTX::cls ## RegisterClass->contains(RegNo)) return # clsstr;
TEST_REGCLS(RegPred, pred);
- TEST_REGCLS(RegI8, b8);
TEST_REGCLS(RegI16, b16);
TEST_REGCLS(RegI32, b32);
TEST_REGCLS(RegI64, b64);
return NULL;
}
-static const char *getTypeName(const Type* type) {
+static const char *getTypeName(Type* type) {
while (true) {
switch (type->getTypeID()) {
default: llvm_unreachable("Unknown type");
case Type::IntegerTyID:
switch (type->getPrimitiveSizeInBits()) {
default: llvm_unreachable("Unknown integer bit-width");
- case 8: return ".u8";
case 16: return ".u16";
case 32: return ".u32";
case 64: return ".u64";
}
case Type::ArrayTyID:
case Type::PointerTyID:
- type = dyn_cast<const SequentialType>(type)->getElementType();
+ type = dyn_cast<SequentialType>(type)->getElementType();
break;
}
}
OutStreamer.EmitRawText(Twine(def));
}
}
+
+ unsigned Index = 1;
+ // Print parameter passing params
+ for (PTXMachineFunctionInfo::param_iterator
+ i = MFI->paramBegin(), e = MFI->paramEnd(); i != e; ++i) {
+ std::string def = "\t.param .b";
+ def += utostr(*i);
+ def += " __ret_";
+ def += utostr(Index);
+ Index++;
+ def += ";";
+ OutStreamer.EmitRawText(Twine(def));
+ }
}
void PTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
printPredicateOperand(MI, OS);
// Write instruction to str
- printInstruction(MI, OS);
+ if (MI->getOpcode() == PTX::CALL) {
+ printCall(MI, OS);
+ } else {
+ printInstruction(MI, OS);
+ }
OS << ';';
OS.flush();
if (PointerType::classof(gv->getType())) {
- const PointerType* pointerTy = dyn_cast<const PointerType>(gv->getType());
- const Type* elementTy = pointerTy->getElementType();
+ PointerType* pointerTy = dyn_cast<PointerType>(gv->getType());
+ Type* elementTy = pointerTy->getElementType();
decl += ".b8 ";
decl += gvsym->getName();
{
assert(elementTy->isArrayTy() && "Only pointers to arrays are supported");
- const ArrayType* arrayTy = dyn_cast<const ArrayType>(elementTy);
+ ArrayType* arrayTy = dyn_cast<ArrayType>(elementTy);
elementTy = arrayTy->getElementType();
unsigned numElements = arrayTy->getNumElements();
while (elementTy->isArrayTy()) {
- arrayTy = dyn_cast<const ArrayType>(elementTy);
+ arrayTy = dyn_cast<ArrayType>(elementTy);
elementTy = arrayTy->getElementType();
numElements *= arrayTy->getNumElements();
}
}
+void PTXAsmPrinter::
+printCall(const MachineInstr *MI, raw_ostream &O) {
+
+ O << "\tcall.uni\t";
+
+ const GlobalValue *Address = MI->getOperand(2).getGlobal();
+ O << Address->getName() << ", (";
+
+ // (0,1) : predicate register/flag
+ // (2) : callee
+ for (unsigned i = 3; i < MI->getNumOperands(); ++i) {
+ //const MachineOperand& MO = MI->getOperand(i);
+
+ printReturnOperand(MI, i, O);
+ if (i < MI->getNumOperands()-1) {
+ O << ", ";
+ }
+ }
+
+ O << ")";
+}
+
unsigned PTXAsmPrinter::GetOrCreateSourceID(StringRef FileName,
StringRef DirName) {
// If FE did not provide a file name, then assume stdin.