diff options
author | Freddy Ye <freddy.ye@intel.com> | 2023-11-21 14:06:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-21 14:06:32 +0800 |
commit | d102f8bda1544945fe82b1fbbf4629e7c1389970 (patch) | |
tree | 6de40d18508f1b76f5d3e9760f9daa67a6f5244a /llvm/lib/CodeGen/MachineBlockPlacement.cpp | |
parent | a1de0946abe8d0195bc06651e0abe32966be47cd (diff) | |
download | llvm-d102f8bda1544945fe82b1fbbf4629e7c1389970.zip llvm-d102f8bda1544945fe82b1fbbf4629e7c1389970.tar.gz llvm-d102f8bda1544945fe82b1fbbf4629e7c1389970.tar.bz2 |
[MachineBlockPlacement][X86] Use max of MDAlign and TLIAlign to align Loops. (#71026)
This patch added backend consumption on a new loop metadata:
!1 = !{!"llvm.loop.align", i32 64}
which is generated from clang's new loop attribute:
[[clang::code_align()]]
clang patch: #70762
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockPlacement.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index f783eec..a7a8396 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -2919,8 +2919,30 @@ void MachineBlockPlacement::alignBlocks() { if (!L) continue; - const Align Align = TLI->getPrefLoopAlignment(L); - if (Align == 1) + const Align TLIAlign = TLI->getPrefLoopAlignment(L); + unsigned MDAlign = 1; + MDNode *LoopID = L->getLoopID(); + if (LoopID) { + for (unsigned I = 1, E = LoopID->getNumOperands(); I < E; ++I) { + MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(I)); + if (MD == nullptr) + continue; + MDString *S = dyn_cast<MDString>(MD->getOperand(0)); + if (S == nullptr) + continue; + if (S->getString() == "llvm.loop.align") { + assert(MD->getNumOperands() == 2 && + "per-loop align metadata should have two operands."); + MDAlign = + mdconst::extract<ConstantInt>(MD->getOperand(1))->getZExtValue(); + assert(MDAlign >= 1 && "per-loop align value must be positive."); + } + } + } + + // Use max of the TLIAlign and MDAlign + const Align LoopAlign = std::max(TLIAlign, Align(MDAlign)); + if (LoopAlign == 1) continue; // Don't care about loop alignment. // If the block is cold relative to the function entry don't waste space @@ -2959,7 +2981,7 @@ void MachineBlockPlacement::alignBlocks() { // Force alignment if all the predecessors are jumps. We already checked // that the block isn't cold above. if (!LayoutPred->isSuccessor(ChainBB)) { - ChainBB->setAlignment(Align); + ChainBB->setAlignment(LoopAlign); DetermineMaxAlignmentPadding(); continue; } @@ -2972,7 +2994,7 @@ void MachineBlockPlacement::alignBlocks() { MBPI->getEdgeProbability(LayoutPred, ChainBB); BlockFrequency LayoutEdgeFreq = MBFI->getBlockFreq(LayoutPred) * LayoutProb; if (LayoutEdgeFreq <= (Freq * ColdProb)) { - ChainBB->setAlignment(Align); + ChainBB->setAlignment(LoopAlign); DetermineMaxAlignmentPadding(); } } |