From f70e39ec173192058976805a2c51ac438bb2ff2f Mon Sep 17 00:00:00 2001 From: Rahman Lavaee Date: Fri, 27 Oct 2023 21:49:39 -0700 Subject: [BasicBlockSections] Apply path cloning with -basic-block-sections. (#68860) https://github.com/llvm/llvm-project/commit/28b912687900bc0a67cd61c374fce296b09963c4 introduced the path cloning format in the basic-block-sections profile. This PR validates and applies path clonings. A path cloning is valid if all of these conditions hold: 1. All bb ids in the path are mapped to existing blocks. 2. Each two consecutive bb ids in the path have a successor relationship in the CFG. 3. The path does not include a block with indirect branches, except possibly as the last block. Applying a path cloning involves cloning all blocks in the path (except the first one) and setting up their branches. Once all clonings are applied, the cluster information is used to guide block layout in the modified function. --- llvm/lib/CodeGen/MachineFunction.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen/MachineFunction.cpp') diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 9e67dcb..07eb0ba 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -457,16 +457,17 @@ void MachineFunction::deleteMachineInstr(MachineInstr *MI) { /// Allocate a new MachineBasicBlock. Use this instead of /// `new MachineBasicBlock'. MachineBasicBlock * -MachineFunction::CreateMachineBasicBlock(const BasicBlock *bb) { +MachineFunction::CreateMachineBasicBlock(const BasicBlock *BB, + std::optional BBID) { MachineBasicBlock *MBB = new (BasicBlockRecycler.Allocate(Allocator)) - MachineBasicBlock(*this, bb); + MachineBasicBlock(*this, BB); // Set BBID for `-basic-block=sections=labels` and // `-basic-block-sections=list` to allow robust mapping of profiles to basic // blocks. if (Target.getBBSectionsType() == BasicBlockSection::Labels || Target.getBBSectionsType() == BasicBlockSection::List) - MBB->setBBID(NextBBID++); + MBB->setBBID(BBID.has_value() ? *BBID : UniqueBBID{NextBBID++, 0}); return MBB; } -- cgit v1.1