diff --git a/lib/Target/PTX/PTXAsmPrinter.cpp b/lib/Target/PTX/PTXAsmPrinter.cpp index 03f177b2fa8..8fb1f53d2b5 100644 --- a/lib/Target/PTX/PTXAsmPrinter.cpp +++ b/lib/Target/PTX/PTXAsmPrinter.cpp @@ -27,12 +27,21 @@ #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 +OptPTXVersion("ptx-version", cl::desc("Set PTX version"), + cl::init("1.4")); + +static cl::opt +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 index 00000000000..a14d5c9c27b --- /dev/null +++ b/test/CodeGen/PTX/options.ll @@ -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 +}