[llvm] 20f7f9b - [NFC][DirectX backend] Fix crash when emit_obj for DirectX backend.
Xiang Li via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 12:09:14 PDT 2022
Author: Xiang Li
Date: 2022-08-02T12:09:07-07:00
New Revision: 20f7f9b709dfb1dafd6827c9708928ecac547d87
URL: https://github.com/llvm/llvm-project/commit/20f7f9b709dfb1dafd6827c9708928ecac547d87
DIFF: https://github.com/llvm/llvm-project/commit/20f7f9b709dfb1dafd6827c9708928ecac547d87.diff
LOG: [NFC][DirectX backend] Fix crash when emit_obj for DirectX backend.
When emit-obj from clang directly, DirectX backend will hit assert caused by not initialize passes for AsmPrinter.
The fix will initialize the passes by calling createPassConfig.
Also ignore global variable which not has section in DXILAsmPrinter::emitGlobalVariable to avoid hit llvm_unreachable in DXILTargetObjectFile::SelectSectionForGlobal.
Reviewed By: beanz
Differential Revision: https://reviews.llvm.org/D130856
Added:
Modified:
llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp b/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
index cea3283f6756d..ad1f6b3cf2b68 100644
--- a/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
+++ b/llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
@@ -46,6 +46,8 @@ void DXILAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
// Skip the LLVM metadata
if (GV->getSection() == "llvm.metadata")
return;
+ if (!GV->hasSection())
+ return;
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
MCSection *TheSection = getObjFileLowering().SectionForGlobal(GV, GVKind, TM);
OutStreamer->switchSection(TheSection);
diff --git a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
index 44bef80ea6fb8..8ea074cb5cb6f 100644
--- a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
+++ b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
@@ -67,6 +67,11 @@ class DirectXPassConfig : public TargetPassConfig {
}
FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
+ void addCodeGenPrepare() override {
+ addPass(createDXILOpLoweringLegacyPass());
+ addPass(createDXILPrepareModulePass());
+ addPass(createDXILTranslateMetadataPass());
+ }
};
DirectXTargetMachine::DirectXTargetMachine(const Target &T, const Triple &TT,
@@ -91,9 +96,9 @@ bool DirectXTargetMachine::addPassesToEmitFile(
PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
CodeGenFileType FileType, bool DisableVerify,
MachineModuleInfoWrapperPass *MMIWP) {
- PM.add(createDXILOpLoweringLegacyPass());
- PM.add(createDXILPrepareModulePass());
- PM.add(createDXILTranslateMetadataPass());
+ TargetPassConfig *PassConfig = createPassConfig(PM);
+ PassConfig->addCodeGenPrepare();
+
if (TargetPassConfig::willCompleteCodeGenPipeline()) {
PM.add(createDXILEmbedderPass());
}
More information about the llvm-commits
mailing list