aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
diff options
context:
space:
mode:
authorXiang Li <python3kgae@outlook.com>2022-07-31 14:15:28 -0700
committerXiang Li <python3kgae@outlook.com>2022-08-02 12:09:07 -0700
commit20f7f9b709dfb1dafd6827c9708928ecac547d87 (patch)
treed21e225be94b737c302d676e9d1d96e53a0e21df /llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
parenta1a30dc933b928a7a8277d5b5f7bd25670e68884 (diff)
downloadllvm-20f7f9b709dfb1dafd6827c9708928ecac547d87.zip
llvm-20f7f9b709dfb1dafd6827c9708928ecac547d87.tar.gz
llvm-20f7f9b709dfb1dafd6827c9708928ecac547d87.tar.bz2
[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
Diffstat (limited to 'llvm/lib/Target/DirectX/DirectXTargetMachine.cpp')
-rw-r--r--llvm/lib/Target/DirectX/DirectXTargetMachine.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
index 44bef80..8ea074cb 100644
--- a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
+++ b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
@@ -67,6 +67,11 @@ public:
}
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());
}