summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/NVPTX
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2018-05-01 00:10:13 +0000
committerEric Christopher <echristo@gmail.com>2018-05-01 00:10:13 +0000
commitc9fe4515a373654876c82cda083dd836dd3e8b5c (patch)
tree7dc3399a84d0337d4ac81a5711ba3cae715e54d4 /llvm/lib/Target/NVPTX
parent7621615146ba4ede7b9756601b3deff5b2871042 (diff)
Temporarily revert "[DEBUG] Initial adaptation of NVPTX target for debug info emission."
This appears to have some issues associated with the file directive output causing multiple global symbols with the name "file" to be emitted into a startup section. I'm investigating more specific causes and working with the original author. This reverts commit r330271. Also Revert "[DEBUGINFO, NVPTX] Add the test for the debug info of the local" This reverts commit r330592 and the follow up of 330779 as the testcase is dependent upon r330271.
Diffstat (limited to 'llvm/lib/Target/NVPTX')
-rw-r--r--llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt1
-rw-r--r--llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp26
-rw-r--r--llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h11
-rw-r--r--llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp12
-rw-r--r--llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp94
-rw-r--r--llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h46
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp150
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h8
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp28
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXSection.h45
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h59
11 files changed, 273 insertions, 207 deletions
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt
index 9b4eadd59a3..dbbf23554aa 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt
@@ -1,5 +1,4 @@
add_llvm_library(LLVMNVPTXDesc
NVPTXMCAsmInfo.cpp
NVPTXMCTargetDesc.cpp
- NVPTXTargetStreamer.cpp
)
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
index f6cbd23f01c..bdd0f156c8a 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
@@ -13,9 +13,16 @@
#include "NVPTXMCAsmInfo.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/Support/CommandLine.h"
using namespace llvm;
+// -debug-compile - Command line option to inform opt and llc passes to
+// compile for debugging
+static cl::opt<bool> CompileForDebugging("debug-compile",
+ cl::desc("Compile for debugging"),
+ cl::Hidden, cl::init(false));
+
void NVPTXMCAsmInfo::anchor() {}
NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple) {
@@ -30,7 +37,7 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple) {
InlineAsmStart = " begin inline asm";
InlineAsmEnd = " end inline asm";
- SupportsDebugInformation = true;
+ SupportsDebugInformation = CompileForDebugging;
// PTX does not allow .align on functions.
HasFunctionAlignment = false;
HasDotTypeDotSizeDirective = false;
@@ -38,16 +45,13 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple) {
HiddenDeclarationVisibilityAttr = HiddenVisibilityAttr = MCSA_Invalid;
ProtectedVisibilityAttr = MCSA_Invalid;
- // FIXME: remove comment once debug info is properly supported.
- Data8bitsDirective = "// .b8 ";
- Data16bitsDirective = nullptr; // not supported
- Data32bitsDirective = "// .b32 ";
- Data64bitsDirective = "// .b64 ";
- ZeroDirective = "// .b8";
- AsciiDirective = nullptr; // not supported
- AscizDirective = nullptr; // not supported
- SupportsQuotedNames = false;
- SupportsExtendedDwarfLocDirective = false;
+ Data8bitsDirective = " .b8 ";
+ Data16bitsDirective = " .b16 ";
+ Data32bitsDirective = " .b32 ";
+ Data64bitsDirective = " .b64 ";
+ ZeroDirective = " .b8";
+ AsciiDirective = " .b8";
+ AscizDirective = " .b8";
// @TODO: Can we just disable this?
WeakDirective = "\t// .weak\t";
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
index 9fd7600cf67..9ac3c8850f7 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
@@ -25,17 +25,6 @@ class NVPTXMCAsmInfo : public MCAsmInfo {
public:
explicit NVPTXMCAsmInfo(const Triple &TheTriple);
-
- /// Return true if the .section directive should be omitted when
- /// emitting \p SectionName. For example:
- ///
- /// shouldOmitSectionDirective(".text")
- ///
- /// returns false => .section .text,#alloc,#execinstr
- /// returns true => .text
- bool shouldOmitSectionDirective(StringRef SectionName) const override {
- return true;
- }
};
} // namespace llvm
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp
index b1a77a17ec1..12f99274936 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp
@@ -11,10 +11,9 @@
//
//===----------------------------------------------------------------------===//
+#include "NVPTXMCTargetDesc.h"
#include "InstPrinter/NVPTXInstPrinter.h"
#include "NVPTXMCAsmInfo.h"
-#include "NVPTXMCTargetDesc.h"
-#include "NVPTXTargetStreamer.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
@@ -59,12 +58,6 @@ static MCInstPrinter *createNVPTXMCInstPrinter(const Triple &T,
return nullptr;
}
-static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
- formatted_raw_ostream &,
- MCInstPrinter *, bool) {
- return new NVPTXTargetStreamer(S);
-}
-
// Force static initialization.
extern "C" void LLVMInitializeNVPTXTargetMC() {
for (Target *T : {&getTheNVPTXTarget32(), &getTheNVPTXTarget64()}) {
@@ -82,8 +75,5 @@ extern "C" void LLVMInitializeNVPTXTargetMC() {
// Register the MCInstPrinter.
TargetRegistry::RegisterMCInstPrinter(*T, createNVPTXMCInstPrinter);
-
- // Register the MCTargetStreamer.
- TargetRegistry::RegisterAsmTargetStreamer(*T, createTargetAsmStreamer);
}
}
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
deleted file mode 100644
index aeb90eca3a0..00000000000
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-//=====- NVPTXTargetStreamer.cpp - NVPTXTargetStreamer class ------------=====//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the NVPTXTargetStreamer class.
-//
-//===----------------------------------------------------------------------===//
-
-#include "NVPTXTargetStreamer.h"
-#include "llvm/MC/MCAsmInfo.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCObjectFileInfo.h"
-
-using namespace llvm;
-
-//
-// NVPTXTargetStreamer Implemenation
-//
-NVPTXTargetStreamer::NVPTXTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
-
-NVPTXTargetStreamer::~NVPTXTargetStreamer() = default;
-
-void NVPTXTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
- DwarfFiles.emplace_back(Directive);
-}
-
-static bool isDwarfSection(const MCObjectFileInfo *FI,
- const MCSection *Section) {
- // FIXME: the checks for the DWARF sections are very fragile and should be
- // fixed up in a followup patch.
- if (!Section || Section->getKind().isText() ||
- Section->getKind().isWriteable())
- return false;
- return Section == FI->getDwarfAbbrevSection() ||
- Section == FI->getDwarfInfoSection() ||
- Section == FI->getDwarfMacinfoSection() ||
- Section == FI->getDwarfFrameSection() ||
- Section == FI->getDwarfAddrSection() ||
- Section == FI->getDwarfRangesSection() ||
- Section == FI->getDwarfARangesSection() ||
- Section == FI->getDwarfLocSection() ||
- Section == FI->getDwarfStrSection() ||
- Section == FI->getDwarfLineSection() ||
- Section == FI->getDwarfStrOffSection() ||
- Section == FI->getDwarfLineStrSection() ||
- Section == FI->getDwarfPubNamesSection() ||
- Section == FI->getDwarfPubTypesSection() ||
- Section == FI->getDwarfSwiftASTSection() ||
- Section == FI->getDwarfTypesDWOSection() ||
- Section == FI->getDwarfAbbrevDWOSection() ||
- Section == FI->getDwarfAccelObjCSection() ||
- Section == FI->getDwarfAccelNamesSection() ||
- Section == FI->getDwarfAccelTypesSection() ||
- Section == FI->getDwarfAccelNamespaceSection() ||
- Section == FI->getDwarfLocDWOSection() ||
- Section == FI->getDwarfStrDWOSection() ||
- Section == FI->getDwarfCUIndexSection() ||
- Section == FI->getDwarfInfoDWOSection() ||
- Section == FI->getDwarfLineDWOSection() ||
- Section == FI->getDwarfTUIndexSection() ||
- Section == FI->getDwarfStrOffDWOSection() ||
- Section == FI->getDwarfDebugNamesSection() ||
- Section == FI->getDwarfDebugInlineSection() ||
- Section == FI->getDwarfGnuPubNamesSection() ||
- Section == FI->getDwarfGnuPubTypesSection();
-}
-
-void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
- MCSection *Section,
- const MCExpr *SubSection,
- raw_ostream &OS) {
- assert(!SubSection && "SubSection is not null!");
- const MCObjectFileInfo *FI = getStreamer().getContext().getObjectFileInfo();
- // FIXME: remove comment once debug info is properly supported.
- // Emit closing brace for DWARF sections only.
- if (isDwarfSection(FI, CurSection))
- OS << "//\t}\n";
- if (isDwarfSection(FI, Section)) {
- // Emit DWARF .file directives in the outermost scope.
- for (const std::string &S : DwarfFiles)
- getStreamer().EmitRawText(S.data());
- DwarfFiles.clear();
- OS << "//\t.section";
- Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(),
- FI->getTargetTriple(), OS, SubSection);
- // DWARF sections are enclosed into braces - emit the open one.
- OS << "//\t{\n";
- }
-}
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h
deleted file mode 100644
index 30831ab8bbe..00000000000
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h
+++ /dev/null
@@ -1,46 +0,0 @@
-//=====-- NVPTXTargetStreamer.h - NVPTX Target Streamer ------*- C++ -*--=====//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXTARGETSTREAMER_H
-#define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXTARGETSTREAMER_H
-
-#include "llvm/MC/MCStreamer.h"
-
-namespace llvm {
-class MCSection;
-
-/// Implments NVPTX-specific streamer.
-class NVPTXTargetStreamer : public MCTargetStreamer {
-private:
- SmallVector<std::string, 4> DwarfFiles;
-
-public:
- NVPTXTargetStreamer(MCStreamer &S);
- ~NVPTXTargetStreamer() override;
-
- /// Record DWARF file directives for later output.
- /// According to PTX ISA, CUDA Toolkit documentation, 11.5.3. Debugging
- /// Directives: .file
- /// (http://docs.nvidia.com/cuda/parallel-thread-execution/index.html#debugging-directives-file),
- /// The .file directive is allowed only in the outermost scope, i.e., at the
- /// same level as kernel and device function declarations. Also, the order of
- /// the .loc and .file directive does not matter, .file directives may follow
- /// the .loc directives where the file is referenced.
- /// LLVM emits .file directives immediately the location debug info is
- /// emitted, i.e. they may be emitted inside functions. We gather all these
- /// directives and emit them outside of the sections and, thus, outside of the
- /// functions.
- void emitDwarfFileDirective(StringRef Directive) override;
- void changeSection(const MCSection *CurSection, MCSection *Section,
- const MCExpr *SubSection, raw_ostream &OS) override;
-};
-
-} // end namespace llvm
-
-#endif
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index a346e3335e1..2fd0689b1aa 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -93,6 +93,16 @@ using namespace llvm;
#define DEPOTNAME "__local_depot"
+static cl::opt<bool>
+EmitLineNumbers("nvptx-emit-line-numbers", cl::Hidden,
+ cl::desc("NVPTX Specific: Emit Line numbers even without -G"),
+ cl::init(true));
+
+static cl::opt<bool>
+InterleaveSrc("nvptx-emit-src", cl::ZeroOrMore, cl::Hidden,
+ cl::desc("NVPTX Specific: Emit source line in ptx file"),
+ cl::init(false));
+
/// DiscoverDependentGlobals - Return a set of GlobalVariables on which \p V
/// depends.
static void
@@ -141,7 +151,56 @@ VisitGlobalVariableForEmission(const GlobalVariable *GV,
Visiting.erase(GV);
}
+void NVPTXAsmPrinter::emitLineNumberAsDotLoc(const MachineInstr &MI) {
+ if (!EmitLineNumbers)
+ return;
+ if (ignoreLoc(MI))
+ return;
+
+ const DebugLoc &curLoc = MI.getDebugLoc();
+
+ if (!prevDebugLoc && !curLoc)
+ return;
+
+ if (prevDebugLoc == curLoc)
+ return;
+
+ prevDebugLoc = curLoc;
+
+ if (!curLoc)
+ return;
+
+ auto *Scope = cast_or_null<DIScope>(curLoc.getScope());
+ if (!Scope)
+ return;
+
+ StringRef fileName(Scope->getFilename());
+ StringRef dirName(Scope->getDirectory());
+ SmallString<128> FullPathName = dirName;
+ if (!dirName.empty() && !sys::path::is_absolute(fileName)) {
+ sys::path::append(FullPathName, fileName);
+ fileName = FullPathName;
+ }
+
+ if (filenameMap.find(fileName) == filenameMap.end())
+ return;
+
+ // Emit the line from the source file.
+ if (InterleaveSrc)
+ this->emitSrcInText(fileName, curLoc.getLine());
+
+ std::stringstream temp;
+ temp << "\t.loc " << filenameMap[fileName] << " " << curLoc.getLine()
+ << " " << curLoc.getCol();
+ OutStreamer->EmitRawText(temp.str());
+}
+
void NVPTXAsmPrinter::EmitInstruction(const MachineInstr *MI) {
+ SmallString<128> Str;
+ raw_svector_ostream OS(Str);
+ if (static_cast<NVPTXTargetMachine &>(TM).getDrvInterface() == NVPTX::CUDA)
+ emitLineNumberAsDotLoc(*MI);
+
MCInst Inst;
lowerToMCInst(MI, Inst);
EmitToStreamer(*OutStreamer, Inst);
@@ -446,7 +505,7 @@ void NVPTXAsmPrinter::EmitFunctionEntryLabel() {
emitGlobals(*MF->getFunction().getParent());
GlobalsEmitted = true;
}
-
+
// Set up
MRI = &MF->getRegInfo();
F = &MF->getFunction();
@@ -467,25 +526,14 @@ void NVPTXAsmPrinter::EmitFunctionEntryLabel() {
OutStreamer->EmitRawText(O.str());
+ prevDebugLoc = DebugLoc();
+}
+
+void NVPTXAsmPrinter::EmitFunctionBodyStart() {
VRegMapping.clear();
- // Emit open brace for function body.
OutStreamer->EmitRawText(StringRef("{\n"));
setAndEmitFunctionVirtualRegisters(*MF);
-}
-
-bool NVPTXAsmPrinter::runOnMachineFunction(MachineFunction &F) {
- nvptxSubtarget = &F.getSubtarget<NVPTXSubtarget>();
- bool Result = AsmPrinter::runOnMachineFunction(F);
- // Emit closing brace for the body of function F.
- // The closing brace must be emitted here because we need to emit additional
- // debug labels/data after the last basic block.
- // We need to emit the closing brace here because we don't have function that
- // finished emission of the function body.
- OutStreamer->EmitRawText(StringRef("}\n"));
- return Result;
-}
-void NVPTXAsmPrinter::EmitFunctionBodyStart() {
SmallString<128> Str;
raw_svector_ostream O(Str);
emitDemotedVars(&MF->getFunction(), O);
@@ -493,6 +541,7 @@ void NVPTXAsmPrinter::EmitFunctionBodyStart() {
}
void NVPTXAsmPrinter::EmitFunctionBodyEnd() {
+ OutStreamer->EmitRawText(StringRef("}\n"));
VRegMapping.clear();
}
@@ -769,6 +818,42 @@ void NVPTXAsmPrinter::emitDeclarations(const Module &M, raw_ostream &O) {
}
}
+void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) {
+ DebugInfoFinder DbgFinder;
+ DbgFinder.processModule(M);
+
+ unsigned i = 1;
+ for (const DICompileUnit *DIUnit : DbgFinder.compile_units()) {
+ StringRef Filename = DIUnit->getFilename();
+ StringRef Dirname = DIUnit->getDirectory();
+ SmallString<128> FullPathName = Dirname;
+ if (!Dirname.empty() && !sys::path::is_absolute(Filename)) {
+ sys::path::append(FullPathName, Filename);
+ Filename = FullPathName;
+ }
+ if (filenameMap.find(Filename) != filenameMap.end())
+ continue;
+ filenameMap[Filename] = i;
+ OutStreamer->EmitDwarfFileDirective(i, "", Filename);
+ ++i;
+ }
+
+ for (DISubprogram *SP : DbgFinder.subprograms()) {
+ StringRef Filename = SP->getFilename();
+ StringRef Dirname = SP->getDirectory();
+ SmallString<128> FullPathName = Dirname;
+ if (!Dirname.empty() && !sys::path::is_absolute(Filename)) {
+ sys::path::append(FullPathName, Filename);
+ Filename = FullPathName;
+ }
+ if (filenameMap.find(Filename) != filenameMap.end())
+ continue;
+ filenameMap[Filename] = i;
+ OutStreamer->EmitDwarfFileDirective(i, "", Filename);
+ ++i;
+ }
+}
+
static bool isEmptyXXStructor(GlobalVariable *GV) {
if (!GV) return true;
const ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
@@ -804,13 +889,24 @@ bool NVPTXAsmPrinter::doInitialization(Module &M) {
SmallString<128> Str1;
raw_svector_ostream OS1(Str1);
+ MMI = getAnalysisIfAvailable<MachineModuleInfo>();
+
// We need to call the parent's one explicitly.
- bool Result = AsmPrinter::doInitialization(M);
+ //bool Result = AsmPrinter::doInitialization(M);
+
+ // Initialize TargetLoweringObjectFile since we didn't do in
+ // AsmPrinter::doInitialization either right above or where it's commented out
+ // below.
+ const_cast<TargetLoweringObjectFile &>(getObjFileLowering())
+ .Initialize(OutContext, TM);
// Emit header before any dwarf directives are emitted below.
emitHeader(M, OS1, STI);
OutStreamer->EmitRawText(OS1.str());
+ // Already commented out
+ //bool Result = AsmPrinter::doInitialization(M);
+
// Emit module-level inline asm if it exists.
if (!M.getModuleInlineAsm().empty()) {
OutStreamer->AddComment("Start of file scope inline assembly");
@@ -821,9 +917,13 @@ bool NVPTXAsmPrinter::doInitialization(Module &M) {
OutStreamer->AddBlankLine();
}
- GlobalsEmitted = false;
+ // If we're not NVCL we're CUDA, go ahead and emit filenames.
+ if (TM.getTargetTriple().getOS() != Triple::NVCL)
+ recordAndEmitFilenames(M);
- return Result;
+ GlobalsEmitted = false;
+
+ return false; // success
}
void NVPTXAsmPrinter::emitGlobals(const Module &M) {
@@ -875,9 +975,8 @@ void NVPTXAsmPrinter::emitHeader(Module &M, raw_ostream &O,
if (NTM.getDrvInterface() == NVPTX::NVCL)
O << ", texmode_independent";
- // FIXME: remove comment once debug info is properly supported.
- if (MMI && MMI->hasDebugInfo())
- O << "//, debug";
+ if (MAI->doesSupportDebugInformation())
+ O << ", debug";
O << "\n";
@@ -892,8 +991,6 @@ void NVPTXAsmPrinter::emitHeader(Module &M, raw_ostream &O,
}
bool NVPTXAsmPrinter::doFinalization(Module &M) {
- bool HasDebugInfo = MMI && MMI->hasDebugInfo();
-
// If we did not emit any functions, then the global declarations have not
// yet been emitted.
if (!GlobalsEmitted) {
@@ -928,11 +1025,6 @@ bool NVPTXAsmPrinter::doFinalization(Module &M) {
clearAnnotationCache(&M);
delete[] gv_array;
- // FIXME: remove comment once debug info is properly supported.
- // Close the last emitted section
- if (HasDebugInfo)
- OutStreamer->EmitRawText("//\t}");
-
return ret;
//bool Result = AsmPrinter::doFinalization(M);
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
index 9fe9c1e736f..8ec3476b871 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
@@ -344,7 +344,10 @@ public:
delete reader;
}
- bool runOnMachineFunction(MachineFunction &F) override;
+ bool runOnMachineFunction(MachineFunction &F) override {
+ nvptxSubtarget = &F.getSubtarget<NVPTXSubtarget>();
+ return AsmPrinter::runOnMachineFunction(F);
+ }
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<MachineLoopInfo>();
@@ -354,6 +357,9 @@ public:
bool ignoreLoc(const MachineInstr &);
std::string getVirtualRegisterName(unsigned) const;
+
+ DebugLoc prevDebugLoc;
+ void emitLineNumberAsDotLoc(const MachineInstr &);
};
} // end namespace llvm
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index 527f0997e64..159023170f9 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -15,6 +15,7 @@
#include "NVPTXISelLowering.h"
#include "MCTargetDesc/NVPTXBaseInfo.h"
#include "NVPTX.h"
+#include "NVPTXSection.h"
#include "NVPTXSubtarget.h"
#include "NVPTXTargetMachine.h"
#include "NVPTXTargetObjectFile.h"
@@ -4737,8 +4738,31 @@ void NVPTXTargetLowering::ReplaceNodeResults(
}
}
-// Pin NVPTXTargetObjectFile's vtables to this file.
-NVPTXTargetObjectFile::~NVPTXTargetObjectFile() {}
+// Pin NVPTXSection's and NVPTXTargetObjectFile's vtables to this file.
+void NVPTXSection::anchor() {}
+
+NVPTXTargetObjectFile::~NVPTXTargetObjectFile() {
+ delete static_cast<NVPTXSection *>(TextSection);
+ delete static_cast<NVPTXSection *>(DataSection);
+ delete static_cast<NVPTXSection *>(BSSSection);
+ delete static_cast<NVPTXSection *>(ReadOnlySection);
+
+ delete static_cast<NVPTXSection *>(StaticCtorSection);
+ delete static_cast<NVPTXSection *>(StaticDtorSection);
+ delete static_cast<NVPTXSection *>(LSDASection);
+ delete static_cast<NVPTXSection *>(EHFrameSection);
+ delete static_cast<NVPTXSection *>(DwarfAbbrevSection);
+ delete static_cast<NVPTXSection *>(DwarfInfoSection);
+ delete static_cast<NVPTXSection *>(DwarfLineSection);
+ delete static_cast<NVPTXSection *>(DwarfFrameSection);
+ delete static_cast<NVPTXSection *>(DwarfPubTypesSection);
+ delete static_cast<const NVPTXSection *>(DwarfDebugInlineSection);
+ delete static_cast<NVPTXSection *>(DwarfStrSection);
+ delete static_cast<NVPTXSection *>(DwarfLocSection);
+ delete static_cast<NVPTXSection *>(DwarfARangesSection);
+ delete static_cast<NVPTXSection *>(DwarfRangesSection);
+ delete static_cast<NVPTXSection *>(DwarfMacinfoSection);
+}
MCSection *NVPTXTargetObjectFile::SelectSectionForGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
diff --git a/llvm/lib/Target/NVPTX/NVPTXSection.h b/llvm/lib/Target/NVPTX/NVPTXSection.h
new file mode 100644
index 00000000000..d736eaa4130
--- /dev/null
+++ b/llvm/lib/Target/NVPTX/NVPTXSection.h
@@ -0,0 +1,45 @@
+//===- NVPTXSection.h - NVPTX-specific section representation ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the NVPTXSection class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXSECTION_H
+#define LLVM_LIB_TARGET_NVPTX_NVPTXSECTION_H
+
+#include "llvm/MC/MCSection.h"
+#include "llvm/MC/SectionKind.h"
+
+namespace llvm {
+
+/// Represents a section in PTX PTX does not have sections. We create this class
+/// in order to use the ASMPrint interface.
+///
+class NVPTXSection final : public MCSection {
+ virtual void anchor();
+
+public:
+ NVPTXSection(SectionVariant V, SectionKind K) : MCSection(V, K, nullptr) {}
+ ~NVPTXSection() = default;
+
+ /// Override this as NVPTX has its own way of printing switching
+ /// to a section.
+ void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
+ raw_ostream &OS,
+ const MCExpr *Subsection) const override {}
+
+ /// Base address of PTX sections is zero.
+ bool UseCodeAlign() const override { return false; }
+ bool isVirtualSection() const override { return false; }
+};
+
+} // end namespace llvm
+
+#endif // LLVM_LIB_TARGET_NVPTX_NVPTXSECTION_H
diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h b/llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h
index c706b053ab8..69c59d0296a 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h
@@ -10,6 +10,7 @@
#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXTARGETOBJECTFILE_H
#define LLVM_LIB_TARGET_NVPTX_NVPTXTARGETOBJECTFILE_H
+#include "NVPTXSection.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
@@ -18,12 +19,68 @@ namespace llvm {
class NVPTXTargetObjectFile : public TargetLoweringObjectFile {
public:
- NVPTXTargetObjectFile() : TargetLoweringObjectFile() {}
+ NVPTXTargetObjectFile() {
+ TextSection = nullptr;
+ DataSection = nullptr;
+ BSSSection = nullptr;
+ ReadOnlySection = nullptr;
+
+ StaticCtorSection = nullptr;
+ StaticDtorSection = nullptr;
+ LSDASection = nullptr;
+ EHFrameSection = nullptr;
+ DwarfAbbrevSection = nullptr;
+ DwarfInfoSection = nullptr;
+ DwarfLineSection = nullptr;
+ DwarfFrameSection = nullptr;
+ DwarfPubTypesSection = nullptr;
+ DwarfDebugInlineSection = nullptr;
+ DwarfStrSection = nullptr;
+ DwarfLocSection = nullptr;
+ DwarfARangesSection = nullptr;
+ DwarfRangesSection = nullptr;
+ DwarfMacinfoSection = nullptr;
+ }
~NVPTXTargetObjectFile() override;
void Initialize(MCContext &ctx, const TargetMachine &TM) override {
TargetLoweringObjectFile::Initialize(ctx, TM);
+ TextSection = new NVPTXSection(MCSection::SV_ELF, SectionKind::getText());
+ DataSection = new NVPTXSection(MCSection::SV_ELF, SectionKind::getData());
+ BSSSection = new NVPTXSection(MCSection::SV_ELF, SectionKind::getBSS());
+ ReadOnlySection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getReadOnly());
+ StaticCtorSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ StaticDtorSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ LSDASection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ EHFrameSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfAbbrevSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfInfoSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfLineSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfFrameSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfPubTypesSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfDebugInlineSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfStrSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfLocSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfARangesSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfRangesSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
+ DwarfMacinfoSection =
+ new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata());
}
MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,