[PATCH] D100808: Use Propeller ID instead of MBB IDs.
Rahman Lavaee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 7 20:08:33 PDT 2021
rahmanl created this revision.
rahmanl added a reviewer: tmsriram.
Herald added subscribers: rupprecht, hiraditya.
Herald added a reviewer: jhenderson.
rahmanl updated this revision to Diff 338689.
rahmanl added a comment.
rahmanl updated this revision to Diff 341389.
Herald added a subscriber: pengfei.
rahmanl edited the summary of this revision.
rahmanl updated this revision to Diff 343803.
Herald added a subscriber: emaste.
rahmanl published this revision for review.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.
Refactoring.
rahmanl added a comment.
- Fix tests.
rahmanl added a comment.
- Fix tests.
- Add support for MIR printing and parsing.
Let Propeller use specialized IDs for basic blocks, instead of MBB number.
This allows optimizations not just prior to asm-printer, but throughout the entire codegen.
Background
----------
Today Propeller uses machine basic block (MBB) IDs, which already exist, to map native assembly to machine IR. This is done as follows.
- These IDs are captured and dumped into a specially created section named “bb_addr_map” and is created just before the AsmPrinter pass which writes out object files. This also ensures that we have a mapping that is close to assembly.
- Annotation works by taking a virtual address of an instruction and looking up the bb_addr_map to find the MBB ID it corresponds to.
- While this works well today, we need to do better when we scale Propeller to target other Machine IR optimizations like spill code optimization. Register allocation happens earlier in the Machine IR pipeline and we need an annotation mechanism that is valid at that point.
- The current scheme will not work in this scenario because the MBB ID of a particular basic block is not fixed and changes over the course of codegen (via renumbering, adding, and removing the basic blocks).
- In other words, the MBB IDs do not provide a one-to-one correspondence throughout the lifetime of Machine IR, due to their volatility. Profile annotation using MBB IDs is restricted to be fixed point; only valid at the exact point where it was dumped.
- Further, the object code can only be dumped before AsmPrinter and cannot be dumped at an arbitrary point in the Machine IR pass pipeline. Hence, MBB IDs are not suitable and we need something else.
Solution
--------
We propose using unique incremental Propeller IDs for basic blocks instead of MBB IDs. These IDs are assigned upon the creation of machine basic blocks. We modify `MachineFunction::CreateMachineBasicBlock` to assign the Propeller ID to every newly created basic block. It assigns `MachineFunction::NextPropellerID` to the Propeller ID and then increments it, which ensures having unique IDs.
To ensure correct profile attribution, multiple equivalent compilations must generate the same Propeller IDs. This is guaranteed as long as the MachineFunction passes run in the same order. Since the `NextPropellerID` variable is scoped to `MachineFunction`, interleaving of codegen for different functions won't cause any inconistencies.
Impact on `llvm_bb_addr_map` Size
---------------------------------
Emitting the Propeller ID results in a 23% increase in the size of the `llvm_bb_addr_map` section.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100808
Files:
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/include/llvm/CodeGen/MachineFunction.h
llvm/include/llvm/Object/ELFTypes.h
llvm/include/llvm/ObjectYAML/ELFYAML.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/BasicBlockSections.cpp
llvm/lib/CodeGen/MIRParser/MILexer.cpp
llvm/lib/CodeGen/MIRParser/MILexer.h
llvm/lib/CodeGen/MIRParser/MIParser.cpp
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/lib/CodeGen/MachineFunction.cpp
llvm/lib/Object/ELF.cpp
llvm/lib/ObjectYAML/ELFEmitter.cpp
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/test/CodeGen/X86/basic-block-labels-mir-parse.mir
llvm/test/CodeGen/X86/basic-block-sections-labels.ll
llvm/test/CodeGen/X86/basic-block-sections-mir-print.ll
llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test
llvm/test/tools/obj2yaml/ELF/bb-addr-map.yaml
llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml
llvm/tools/llvm-readobj/ELFDumper.cpp
llvm/tools/obj2yaml/elf2yaml.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100808.343803.patch
Type: text/x-patch
Size: 35097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210508/c1f04dc8/attachment.bin>
More information about the llvm-commits
mailing list