Skip to content

Commit 3729b17

Browse files
committed
[Alignment][NFC] Use llvm::Align for TargetLowering::getPrefLoopAlignment
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Reviewed By: courbet Subscribers: wuzish, arsenm, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, MaskRay, jsji, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67386 llvm-svn: 371511
1 parent bc48588 commit 3729b17

File tree

7 files changed

+32
-28
lines changed

7 files changed

+32
-28
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class MachineBasicBlock
103103
using LiveInVector = std::vector<RegisterMaskPair>;
104104
LiveInVector LiveIns;
105105

106-
/// Alignment of the basic block. Zero if the basic block does not need to be
107-
/// aligned. The alignment is specified as log2(bytes).
108-
unsigned LogAlignment = 0;
106+
/// Alignment of the basic block. One if the basic block does not need to be
107+
/// aligned.
108+
llvm::Align Alignment;
109109

110110
/// Indicate that this basic block is entered via an exception handler.
111111
bool IsEHPad = false;
@@ -374,11 +374,15 @@ class MachineBasicBlock
374374

375375
/// Return alignment of the basic block. The alignment is specified as
376376
/// log2(bytes).
377-
unsigned getLogAlignment() const { return LogAlignment; }
377+
/// FIXME: Remove the Log versions once migration to llvm::Align is over.
378+
unsigned getLogAlignment() const { return Log2(Alignment); }
379+
llvm::Align getAlignment() const { return Alignment; }
378380

379381
/// Set alignment of the basic block. The alignment is specified as
380382
/// log2(bytes).
381-
void setLogAlignment(unsigned A) { LogAlignment = A; }
383+
/// FIXME: Remove the Log versions once migration to llvm::Align is over.
384+
void setLogAlignment(unsigned A) { Alignment = llvm::Align(1ULL << A); }
385+
void setAlignment(llvm::Align A) { Alignment = A; }
382386

383387
/// Returns true if the block is a landing pad. That is this basic block is
384388
/// entered via an exception handler.

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,8 @@ class TargetLoweringBase {
15931593
}
15941594

15951595
/// Return the preferred loop alignment.
1596-
virtual unsigned getPrefLoopLogAlignment(MachineLoop *ML = nullptr) const {
1597-
return Log2(PrefLoopAlignment);
1596+
virtual llvm::Align getPrefLoopAlignment(MachineLoop *ML = nullptr) const {
1597+
return PrefLoopAlignment;
15981598
}
15991599

16001600
/// Should loops be aligned even when the function is marked OptSize (but not

llvm/lib/CodeGen/MachineBlockPlacement.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,8 +2807,8 @@ void MachineBlockPlacement::alignBlocks() {
28072807
if (!L)
28082808
continue;
28092809

2810-
unsigned LogAlign = TLI->getPrefLoopLogAlignment(L);
2811-
if (!LogAlign)
2810+
const llvm::Align Align = TLI->getPrefLoopAlignment(L);
2811+
if (Align == 1)
28122812
continue; // Don't care about loop alignment.
28132813

28142814
// If the block is cold relative to the function entry don't waste space
@@ -2832,7 +2832,7 @@ void MachineBlockPlacement::alignBlocks() {
28322832
// Force alignment if all the predecessors are jumps. We already checked
28332833
// that the block isn't cold above.
28342834
if (!LayoutPred->isSuccessor(ChainBB)) {
2835-
ChainBB->setLogAlignment(LogAlign);
2835+
ChainBB->setLogAlignment(Log2(Align));
28362836
continue;
28372837
}
28382838

@@ -2844,7 +2844,7 @@ void MachineBlockPlacement::alignBlocks() {
28442844
MBPI->getEdgeProbability(LayoutPred, ChainBB);
28452845
BlockFrequency LayoutEdgeFreq = MBFI->getBlockFreq(LayoutPred) * LayoutProb;
28462846
if (LayoutEdgeFreq <= (Freq * ColdProb))
2847-
ChainBB->setLogAlignment(LogAlign);
2847+
ChainBB->setLogAlignment(Log2(Align));
28482848
}
28492849
}
28502850

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10673,15 +10673,15 @@ void SITargetLowering::computeKnownBitsForFrameIndex(const SDValue Op,
1067310673
Known.Zero.setHighBits(getSubtarget()->getKnownHighZeroBitsForFrameIndex());
1067410674
}
1067510675

10676-
unsigned SITargetLowering::getPrefLoopLogAlignment(MachineLoop *ML) const {
10677-
const unsigned PrefLogAlign = TargetLowering::getPrefLoopLogAlignment(ML);
10678-
const unsigned CacheLineLogAlign = 6; // log2(64)
10676+
llvm::Align SITargetLowering::getPrefLoopAlignment(MachineLoop *ML) const {
10677+
const llvm::Align PrefAlign = TargetLowering::getPrefLoopAlignment(ML);
10678+
const llvm::Align CacheLineAlign = llvm::Align(64);
1067910679

1068010680
// Pre-GFX10 target did not benefit from loop alignment
1068110681
if (!ML || DisableLoopAlignment ||
1068210682
(getSubtarget()->getGeneration() < AMDGPUSubtarget::GFX10) ||
1068310683
getSubtarget()->hasInstFwdPrefetchBug())
10684-
return PrefLogAlign;
10684+
return PrefAlign;
1068510685

1068610686
// On GFX10 I$ is 4 x 64 bytes cache lines.
1068710687
// By default prefetcher keeps one cache line behind and reads two ahead.
@@ -10695,8 +10695,8 @@ unsigned SITargetLowering::getPrefLoopLogAlignment(MachineLoop *ML) const {
1069510695

1069610696
const SIInstrInfo *TII = getSubtarget()->getInstrInfo();
1069710697
const MachineBasicBlock *Header = ML->getHeader();
10698-
if (Header->getLogAlignment() != PrefLogAlign)
10699-
return Header->getLogAlignment(); // Already processed.
10698+
if (Header->getAlignment() != PrefAlign)
10699+
return Header->getAlignment(); // Already processed.
1070010700

1070110701
unsigned LoopSize = 0;
1070210702
for (const MachineBasicBlock *MBB : ML->blocks()) {
@@ -10708,23 +10708,23 @@ unsigned SITargetLowering::getPrefLoopLogAlignment(MachineLoop *ML) const {
1070810708
for (const MachineInstr &MI : *MBB) {
1070910709
LoopSize += TII->getInstSizeInBytes(MI);
1071010710
if (LoopSize > 192)
10711-
return PrefLogAlign;
10711+
return PrefAlign;
1071210712
}
1071310713
}
1071410714

1071510715
if (LoopSize <= 64)
10716-
return PrefLogAlign;
10716+
return PrefAlign;
1071710717

1071810718
if (LoopSize <= 128)
10719-
return CacheLineLogAlign;
10719+
return CacheLineAlign;
1072010720

1072110721
// If any of parent loops is surrounded by prefetch instructions do not
1072210722
// insert new for inner loop, which would reset parent's settings.
1072310723
for (MachineLoop *P = ML->getParentLoop(); P; P = P->getParentLoop()) {
1072410724
if (MachineBasicBlock *Exit = P->getExitBlock()) {
1072510725
auto I = Exit->getFirstNonDebugInstr();
1072610726
if (I != Exit->end() && I->getOpcode() == AMDGPU::S_INST_PREFETCH)
10727-
return CacheLineLogAlign;
10727+
return CacheLineAlign;
1072810728
}
1072910729
}
1073010730

@@ -10741,7 +10741,7 @@ unsigned SITargetLowering::getPrefLoopLogAlignment(MachineLoop *ML) const {
1074110741
.addImm(2); // prefetch 1 line behind PC
1074210742
}
1074310743

10744-
return CacheLineLogAlign;
10744+
return CacheLineAlign;
1074510745
}
1074610746

1074710747
LLVM_ATTRIBUTE_UNUSED

llvm/lib/Target/AMDGPU/SIISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class SITargetLowering final : public AMDGPUTargetLowering {
379379
unsigned Depth = 0) const override;
380380
AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
381381

382-
unsigned getPrefLoopLogAlignment(MachineLoop *ML) const override;
382+
llvm::Align getPrefLoopAlignment(MachineLoop *ML) const override;
383383

384384
void allocateHSAUserSGPRs(CCState &CCInfo,
385385
MachineFunction &MF,

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14006,7 +14006,7 @@ void PPCTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
1400614006
}
1400714007
}
1400814008

14009-
unsigned PPCTargetLowering::getPrefLoopLogAlignment(MachineLoop *ML) const {
14009+
llvm::Align PPCTargetLowering::getPrefLoopAlignment(MachineLoop *ML) const {
1401014010
switch (Subtarget.getDarwinDirective()) {
1401114011
default: break;
1401214012
case PPC::DIR_970:
@@ -14027,7 +14027,7 @@ unsigned PPCTargetLowering::getPrefLoopLogAlignment(MachineLoop *ML) const {
1402714027
// Actual alignment of the loop will depend on the hotness check and other
1402814028
// logic in alignBlocks.
1402914029
if (ML->getLoopDepth() > 1 && ML->getSubLoops().empty())
14030-
return 5;
14030+
return llvm::Align(32);
1403114031
}
1403214032

1403314033
const PPCInstrInfo *TII = Subtarget.getInstrInfo();
@@ -14043,13 +14043,13 @@ unsigned PPCTargetLowering::getPrefLoopLogAlignment(MachineLoop *ML) const {
1404314043
}
1404414044

1404514045
if (LoopSize > 16 && LoopSize <= 32)
14046-
return 5;
14046+
return llvm::Align(32);
1404714047

1404814048
break;
1404914049
}
1405014050
}
1405114051

14052-
return TargetLowering::getPrefLoopLogAlignment(ML);
14052+
return TargetLowering::getPrefLoopAlignment(ML);
1405314053
}
1405414054

1405514055
/// getConstraintType - Given a constraint, return the type of

llvm/lib/Target/PowerPC/PPCISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ namespace llvm {
735735
const SelectionDAG &DAG,
736736
unsigned Depth = 0) const override;
737737

738-
unsigned getPrefLoopLogAlignment(MachineLoop *ML) const override;
738+
llvm::Align getPrefLoopAlignment(MachineLoop *ML) const override;
739739

740740
bool shouldInsertFencesForAtomic(const Instruction *I) const override {
741741
return true;

0 commit comments

Comments
 (0)