summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp22
-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
12 files changed, 222 insertions, 280 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index a8e36ec66e5..c8740d72b00 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -312,7 +312,11 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
} else
TheAccelTableKind = AccelTables;
- UseInlineStrings = DwarfInlinedStrings == Enable;
+ if (DwarfInlinedStrings == Default)
+ UseInlineStrings = TT.isNVPTX();
+ else
+ UseInlineStrings = DwarfInlinedStrings == Enable;
+
HasAppleExtensionAttributes = tuneForLLDB();
// Handle split DWARF.
@@ -327,14 +331,18 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
unsigned DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
: MMI->getModule()->getDwarfVersion();
- // Use dwarf 4 by default if nothing is requested.
- DwarfVersion = DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION;
+ // Use dwarf 4 by default if nothing is requested. For NVPTX, use dwarf 2.
+ DwarfVersion =
+ TT.isNVPTX() ? 2 : (DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION);
- UsePubSections = !NoDwarfPubSections;
- UseRangesSection = !NoDwarfRangesSection;
+ UsePubSections = !NoDwarfPubSections && !TT.isNVPTX();
+ UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX();
- // Use sections as references.
- UseSectionsAsReferences = DwarfSectionsAsReferences == Enable;
+ // Use sections as references. Force for NVPTX.
+ if (DwarfSectionsAsReferences == Default)
+ UseSectionsAsReferences = TT.isNVPTX();
+ else
+ UseSectionsAsReferences = DwarfSectionsAsReferences == Enable;
// Work around a GDB bug. GDB doesn't support the standard opcode;
// SCE doesn't support GNU's; LLDB prefers the standard opcode, which
diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt
index dbbf23554aa..9b4eadd59a3 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt
@@ -1,4 +1,5 @@
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 bdd0f156c8a..f6cbd23f01c 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
@@ -13,16 +13,9 @@
#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) {
@@ -37,7 +30,7 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple) {
InlineAsmStart = " begin inline asm";
InlineAsmEnd = " end inline asm";
- SupportsDebugInformation = CompileForDebugging;
+ SupportsDebugInformation = true;
// PTX does not allow .align on functions.
HasFunctionAlignment = false;
HasDotTypeDotSizeDirective = false;
@@ -45,13 +38,16 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const Triple &TheTriple) {
HiddenDeclarationVisibilityAttr = HiddenVisibilityAttr = MCSA_Invalid;
ProtectedVisibilityAttr = MCSA_Invalid;
- Data8bitsDirective = " .b8 ";
- Data16bitsDirective = " .b16 ";
- Data32bitsDirective = " .b32 ";
- Data64bitsDirective = " .b64 ";
- ZeroDirective = " .b8";
- AsciiDirective = " .b8";
- AscizDirective = " .b8";
+ // 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;
// @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 9ac3c8850f7..9fd7600cf67 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.h
@@ -25,6 +25,17 @@ 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 12f99274936..b1a77a17ec1 100644
--- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp
@@ -11,9 +11,10 @@
//
//===----------------------------------------------------------------------===//
-#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"
@@ -58,6 +59,12 @@ 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()}) {
@@ -75,5 +82,8 @@ 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
new file mode 100644
index 00000000000..aeb90eca3a0
--- /dev/null
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
@@ -0,0 +1,94 @@
+//=====- 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
new file mode 100644
index 00000000000..30831ab8bbe
--- /dev/null
+++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h
@@ -0,0 +1,46 @@
+//=====-- 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 2fd0689b1aa..a346e3335e1 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -93,16 +93,6 @@ 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
@@ -151,56 +141,7 @@ 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);
@@ -505,7 +446,7 @@ void NVPTXAsmPrinter::EmitFunctionEntryLabel() {
emitGlobals(*MF->getFunction().getParent());
GlobalsEmitted = true;
}
-
+
// Set up
MRI = &MF->getRegInfo();
F = &MF->getFunction();
@@ -526,14 +467,25 @@ 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);
@@ -541,7 +493,6 @@ void NVPTXAsmPrinter::EmitFunctionBodyStart() {
}
void NVPTXAsmPrinter::EmitFunctionBodyEnd() {
- OutStreamer->EmitRawText(StringRef("}\n"));
VRegMapping.clear();
}
@@ -818,42 +769,6 @@ 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());
@@ -889,24 +804,13 @@ 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);
-
- // 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);
+ bool Result = AsmPrinter::doInitialization(M);
// 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");
@@ -917,13 +821,9 @@ bool NVPTXAsmPrinter::doInitialization(Module &M) {
OutStreamer->AddBlankLine();
}
- // If we're not NVCL we're CUDA, go ahead and emit filenames.
- if (TM.getTargetTriple().getOS() != Triple::NVCL)
- recordAndEmitFilenames(M);
-
GlobalsEmitted = false;
-
- return false; // success
+
+ return Result;
}
void NVPTXAsmPrinter::emitGlobals(const Module &M) {
@@ -975,8 +875,9 @@ void NVPTXAsmPrinter::emitHeader(Module &M, raw_ostream &O,
if (NTM.getDrvInterface() == NVPTX::NVCL)
O << ", texmode_independent";
- if (MAI->doesSupportDebugInformation())
- O << ", debug";
+ // FIXME: remove comment once debug info is properly supported.
+ if (MMI && MMI->hasDebugInfo())
+ O << "//, debug";
O << "\n";
@@ -991,6 +892,8 @@ 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) {
@@ -1025,6 +928,11 @@ 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 8ec3476b871..9fe9c1e736f 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
@@ -344,10 +344,7 @@ public:
delete reader;
}
- bool runOnMachineFunction(MachineFunction &F) override {
- nvptxSubtarget = &F.getSubtarget<NVPTXSubtarget>();
- return AsmPrinter::runOnMachineFunction(F);
- }
+ bool runOnMachineFunction(MachineFunction &F) override;
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<MachineLoopInfo>();
@@ -357,9 +354,6 @@ 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 7a1bab323bd..79d17334655 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -15,7 +15,6 @@
#include "NVPTXISelLowering.h"
#include "MCTargetDesc/NVPTXBaseInfo.h"
#include "NVPTX.h"
-#include "NVPTXSection.h"
#include "NVPTXSubtarget.h"
#include "NVPTXTargetMachine.h"
#include "NVPTXTargetObjectFile.h"
@@ -4701,31 +4700,8 @@ void NVPTXTargetLowering::ReplaceNodeResults(
}
}
-// 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);
-}
+// Pin NVPTXTargetObjectFile's vtables to this file.
+NVPTXTargetObjectFile::~NVPTXTargetObjectFile() {}
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
deleted file mode 100644
index d736eaa4130..00000000000
--- a/llvm/lib/Target/NVPTX/NVPTXSection.h
+++ /dev/null
@@ -1,45 +0,0 @@
-//===- 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 69c59d0296a..c706b053ab8 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h
@@ -10,7 +10,6 @@
#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"
@@ -19,68 +18,12 @@ namespace llvm {
class NVPTXTargetObjectFile : public TargetLoweringObjectFile {
public:
- 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() : TargetLoweringObjectFile() {}
~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,
OpenPOWER on IntegriCloud