ptx: add command-line options for gpu target and ptx version
authorChe-Liang Chiou <clchiou@gmail.com>
Tue, 30 Nov 2010 10:14:14 +0000 (10:14 +0000)
committerChe-Liang Chiou <clchiou@gmail.com>
Tue, 30 Nov 2010 10:14:14 +0000 (10:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120423 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PTX/PTXAsmPrinter.cpp
test/CodeGen/PTX/options.ll [new file with mode: 0644]

index 03f177b2fa8aab23348041af51dba0bdfc6dc1f5..8fb1f53d2b5bff9463baf94b759b7f3904e3a0aa 100644 (file)
 #include "llvm/MC/MCSymbol.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/raw_ostream.h"
 
 using namespace llvm;
 
+static cl::opt<std::string>
+OptPTXVersion("ptx-version", cl::desc("Set PTX version"),
+           cl::init("1.4"));
+
+static cl::opt<std::string>
+OptPTXTarget("ptx-target", cl::desc("Set GPU target (comma-separated list)"),
+           cl::init("sm_10"));
+
 namespace {
 class PTXAsmPrinter : public AsmPrinter {
 public:
@@ -41,6 +50,8 @@ public:
 
   const char *getPassName() const { return "PTX Assembly Printer"; }
 
+  virtual void EmitStartOfAsmFile(Module &M);
+
   virtual bool runOnMachineFunction(MachineFunction &MF);
 
   virtual void EmitFunctionBodyStart();
@@ -85,6 +96,13 @@ static const char *getInstructionTypeName(const MachineInstr *MI) {
   return NULL;
 }
 
+void PTXAsmPrinter::EmitStartOfAsmFile(Module &M)
+{
+  OutStreamer.EmitRawText(Twine("\t.version " + OptPTXVersion));
+  OutStreamer.EmitRawText(Twine("\t.target " + OptPTXTarget));
+  OutStreamer.AddBlankLine();
+}
+
 bool PTXAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   SetupMachineFunction(MF);
   EmitFunctionDeclaration();
diff --git a/test/CodeGen/PTX/options.ll b/test/CodeGen/PTX/options.ll
new file mode 100644 (file)
index 0000000..a14d5c9
--- /dev/null
@@ -0,0 +1,6 @@
+; RUN: llc < %s -march=ptx -ptx-version=2.0 | grep ".version 2.0"
+; RUN: llc < %s -march=ptx -ptx-target=sm_20 | grep ".target sm_20"
+
+define ptx_device void @t1() {
+       ret void
+}