[PATCH] D116465: [SPIRV 6/6] Add one essential pass and the simplest tests
Ilia Diachkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 14 13:32:18 PST 2022
iliya-diyachkov added a comment.
> This sounds like a function of emission to me. I don't see why you need a dummy MIR function or move anything for the purpose of having a global value. You could just emit the global values directly where they need to go as part of the emission of the individual operation.
>
> The AsmPrinter is a module pass, so it's possible to operate globally
> Basically the dummy function feels like an awkward hack of SPIR-V's constraints into MIR. It would be more natural to handle the structural differences in representation when actually producing the final SPIR-V
Thanks for your explanations, Matt. I agree that the dummy "global" function looks like a sort of hack, and the operation with the function is not elegant and not very convenient.
Believing that AsmPrinter can be used as a module pass, I have implemented a prototype of moved GlobalTypesAndRegNum functionality to AsmPrinter with partial success. And I have found this issue.
If GlobalTypesAndRegNum pass is removed (it was a global pass and the last pass before AsmPrinter), we have following sequence of passes/calls for a program with N functions:
SPIRVAsmPrinter::doInitialization
AsmPrinter::emitStartOfAsmFile
func1:
SPIRVGISelPass1 ... SPIRVGISelPassLast
AsmPrinter::runOnMachineFunction
SPIRVAsmPrinter::emitFunctionHeader
emit func1's instructions by SPIRVAsmPrinter::emitInstruction
***
funcN:
SPIRVGISelPass1...SPIRVGISelPassLast
AsmPrinter::runOnMachineFunction
SPIRVAsmPrinter::emitFunctionHeader
emit funcN's instructions by SPIRVAsmPrinter::emitInstruction
SPIRVAsmPrinter::emitEndOfAsmFile
I.e. at the moment of AsmPrinter::runOnMachineFunction invocation for func1 we have not whole MIR and cannot number registers globally and output global instruction at the beginning of the module but func1's instructions should be emitted.
In this pass sequence I don't see a point where all functions' MIR is available in AsmPrinter and the first func1 is not emitted yet. Therefore global register numbering and the global instruction output cannot be applied correctly (on the entire MIR).
On other hand if I leave an empty global pass as a last of post GISel passes, the sequence is different:
SPIRVAsmPrinter::doInitialization
AsmPrinter::emitStartOfAsmFile
func1:
SPIRVGISelPass1 ... SPIRVGISelPassLast
***
funcN:
SPIRVGISelPass1 ... SPIRVGISelPassLast
SPIRVDummyGlobalPass
func1:
AsmPrinter::runOnMachineFunction
SPIRVAsmPrinter::emitFunctionHeader
emit func1's instructions by SPIRVAsmPrinter::emitInstruction
***
funcN:
AsmPrinter::runOnMachineFunction
SPIRVAsmPrinter::emitFunctionHeader
emit funcN's instructions by SPIRVAsmPrinter::emitInstruction
SPIRVAsmPrinter::emitEndOfAsmFile
Now I can run the functionality ported from GlobalTypesAndRegNum on the first invocation of AsmPrinter::runOnMachineFunction and get correct register numbering and global instruction output. Using this way the backend has passed all our LIT tests.
@arsenm, when you suggested moving GlobalTypesAndRegNum' operations to AsmPrinter, did you implied that we need to insert SPIRVDummyGlobalPass after all SPIRVGISel passes to have whole MIR at the first run of AsmPrinter? Or is there another approach (or some pass configuration) to achieve the correct processing of the whole MIR in AsmPrinter?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116465/new/
https://reviews.llvm.org/D116465
More information about the llvm-commits
mailing list