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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
At first glance this seems like the wrong solution. Initialization of the DirectX target should not be initializing common LLVM code.
Are the other LLVM library initializers not being called somewhere that is causing you to hit this issue?
Okay, digging into this more. The issue with GCModuleInfoPass looks like a 12-ish year old bug where it was left off the list of passes initialized in InitializeCodeGen, the MachineOptimizationRemarkEmitterPass is handled there, so as long as clang is properly initializing LLVM CodeGen all you should need to do is add initializeGCModuleInfoPass to llvm::initializeCodeGen.
@bogner, does that seem right to you?
addPassesToGenerateCode is not called. Since we don't do real code gen.
That's where createPassConfig is called which calls initializeCodeGen.
Maybe we can initialize these passes for AsmPrinter in DirectXTargetMachine::addPassesToEmitFile instead of initalizeCodeGen which will initialize a lot of passes we don't need.
The DirectX backend needs to be constructing a target pass config. The bug is that our override of addPassesToEmitFile isn't creating the pass config.
Call createPassConfig to make sure passes get initialized.
Skip Global Variable which not have section when emitGlobalVariable.
llvm/lib/Target/DirectX/DirectXTargetMachine.cpp | ||
---|---|---|
75 | this pass we should probably keep in the addPassesToEmitFile override. This needs to be done last before emitting an object file, so keeping it separate will reduce the likelihood of introducing errors. |
LGTM.
Please fix the title to be brief and descriptive of the change, and add an appropriate change description before merging.
this pass we should probably keep in the addPassesToEmitFile override. This needs to be done last before emitting an object file, so keeping it separate will reduce the likelihood of introducing errors.