[PATCH] D130856: [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.
Xiang Li via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 1 13:25:03 PDT 2022
python3kgae updated this revision to Diff 449109.
python3kgae added a comment.
Call createPassConfig to make sure passes get initialized.
Skip Global Variable which not have section when emitGlobalVariable.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130856/new/
https://reviews.llvm.org/D130856
Files:
llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
Index: llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
===================================================================
--- llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
+++ llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
@@ -67,6 +67,14 @@
}
FunctionPass *createTargetRegisterAllocator(bool) override { return nullptr; }
+ void addCodeGenPrepare() override {
+ addPass(createDXILOpLoweringLegacyPass());
+ addPass(createDXILPrepareModulePass());
+ addPass(createDXILTranslateMetadataPass());
+ if (TargetPassConfig::willCompleteCodeGenPipeline()) {
+ addPass(createDXILEmbedderPass());
+ }
+ }
};
DirectXTargetMachine::DirectXTargetMachine(const Target &T, const Triple &TT,
@@ -91,12 +99,9 @@
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());
- if (TargetPassConfig::willCompleteCodeGenPipeline()) {
- PM.add(createDXILEmbedderPass());
- }
+ TargetPassConfig *PassConfig = createPassConfig(PM);
+ PassConfig->addCodeGenPrepare();
+
switch (FileType) {
case CGFT_AssemblyFile:
PM.add(createPrintModulePass(Out, "", true));
Index: llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
+++ llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp
@@ -46,6 +46,8 @@
// 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130856.449109.patch
Type: text/x-patch
Size: 1904 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220801/56749531/attachment-0001.bin>
More information about the llvm-commits
mailing list