PTX: Add initial support for device function calls
- Calls are supported on SM 2.0+ for function with no return values
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137125 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/PTX/PTXAsmPrinter.cpp b/lib/Target/PTX/PTXAsmPrinter.cpp
index bb48e0a..fc0ec70 100644
--- a/lib/Target/PTX/PTXAsmPrinter.cpp
+++ b/lib/Target/PTX/PTXAsmPrinter.cpp
@@ -70,6 +70,8 @@
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);
@@ -242,6 +244,19 @@
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) {
@@ -302,7 +317,11 @@
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();
@@ -569,6 +588,28 @@
}
}
+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.