Skip to content

Commit f1156fb

Browse files
authored
[AMDGPU][IGLP]: Add SchedGroupMask::TRANS (#75416)
Makes constructing SchedGroups of this type easier, and provides ability to create them with __builtin_amdgcn_sched_group_barrier
1 parent 394e481 commit f1156fb

File tree

4 files changed

+561
-9
lines changed

4 files changed

+561
-9
lines changed

llvm/docs/AMDGPUUsage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ The AMDGPU backend implements the following LLVM IR intrinsics.
11431143
- 0x0080: All DS instructions may be scheduled across sched_barrier.
11441144
- 0x0100: All DS read instructions may be scheduled accoss sched_barrier.
11451145
- 0x0200: All DS write instructions may be scheduled across sched_barrier.
1146+
- 0x0400: All Transcendental (e.g. V_EXP) instructions may be scheduled across sched_barrier.
11461147

11471148
llvm.amdgcn.sched_group_barrier Creates schedule groups with specific properties to create custom scheduling
11481149
pipelines. The ordering between groups is enforced by the instruction scheduler.

llvm/lib/Target/AMDGPU/AMDGPUIGroupLP.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ enum class SchedGroupMask {
7575
DS = 1u << 7,
7676
DS_READ = 1u << 8,
7777
DS_WRITE = 1u << 9,
78+
TRANS = 1u << 10,
7879
ALL = ALU | VALU | SALU | MFMA | VMEM | VMEM_READ | VMEM_WRITE | DS |
79-
DS_READ | DS_WRITE,
80+
DS_READ | DS_WRITE | TRANS,
8081
LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ ALL)
8182
};
8283

@@ -1435,11 +1436,12 @@ bool SchedGroup::canAddMI(const MachineInstr &MI) const {
14351436
Result = false;
14361437

14371438
else if (((SGMask & SchedGroupMask::ALU) != SchedGroupMask::NONE) &&
1438-
(TII->isVALU(MI) || TII->isMFMAorWMMA(MI) || TII->isSALU(MI)))
1439+
(TII->isVALU(MI) || TII->isMFMAorWMMA(MI) || TII->isSALU(MI) ||
1440+
TII->isTRANS(MI)))
14391441
Result = true;
14401442

14411443
else if (((SGMask & SchedGroupMask::VALU) != SchedGroupMask::NONE) &&
1442-
TII->isVALU(MI) && !TII->isMFMAorWMMA(MI))
1444+
TII->isVALU(MI) && !TII->isMFMAorWMMA(MI) && !TII->isTRANS(MI))
14431445
Result = true;
14441446

14451447
else if (((SGMask & SchedGroupMask::SALU) != SchedGroupMask::NONE) &&
@@ -1476,6 +1478,10 @@ bool SchedGroup::canAddMI(const MachineInstr &MI) const {
14761478
MI.mayStore() && TII->isDS(MI))
14771479
Result = true;
14781480

1481+
else if (((SGMask & SchedGroupMask::TRANS) != SchedGroupMask::NONE) &&
1482+
TII->isTRANS(MI))
1483+
Result = true;
1484+
14791485
LLVM_DEBUG(
14801486
dbgs() << "For SchedGroup with mask " << format_hex((int)SGMask, 10, true)
14811487
<< (Result ? " could classify " : " unable to classify ") << MI);
@@ -1635,10 +1641,13 @@ void IGroupLPDAGMutation::addSchedBarrierEdges(SUnit &SchedBarrier) {
16351641
// Remove all existing edges from the SCHED_BARRIER that were added due to the
16361642
// instruction having side effects.
16371643
resetEdges(SchedBarrier, DAG);
1644+
LLVM_DEBUG(dbgs() << "Building SchedGroup for SchedBarrier with Mask: "
1645+
<< MI.getOperand(0).getImm() << "\n");
16381646
auto InvertedMask =
16391647
invertSchedBarrierMask((SchedGroupMask)MI.getOperand(0).getImm());
16401648
SchedGroup SG(InvertedMask, std::nullopt, DAG, TII);
16411649
SG.initSchedGroup();
1650+
16421651
// Preserve original instruction ordering relative to the SCHED_BARRIER.
16431652
SG.link(
16441653
SchedBarrier,
@@ -1652,14 +1661,15 @@ IGroupLPDAGMutation::invertSchedBarrierMask(SchedGroupMask Mask) const {
16521661
// allowed past the SCHED_BARRIER.
16531662
SchedGroupMask InvertedMask = ~Mask;
16541663

1655-
// ALU implies VALU, SALU, MFMA.
1664+
// ALU implies VALU, SALU, MFMA, TRANS.
16561665
if ((InvertedMask & SchedGroupMask::ALU) == SchedGroupMask::NONE)
1657-
InvertedMask &=
1658-
~SchedGroupMask::VALU & ~SchedGroupMask::SALU & ~SchedGroupMask::MFMA;
1659-
// VALU, SALU, MFMA implies ALU.
1666+
InvertedMask &= ~SchedGroupMask::VALU & ~SchedGroupMask::SALU &
1667+
~SchedGroupMask::MFMA & ~SchedGroupMask::TRANS;
1668+
// VALU, SALU, MFMA, TRANS implies ALU.
16601669
else if ((InvertedMask & SchedGroupMask::VALU) == SchedGroupMask::NONE ||
16611670
(InvertedMask & SchedGroupMask::SALU) == SchedGroupMask::NONE ||
1662-
(InvertedMask & SchedGroupMask::MFMA) == SchedGroupMask::NONE)
1671+
(InvertedMask & SchedGroupMask::MFMA) == SchedGroupMask::NONE ||
1672+
(InvertedMask & SchedGroupMask::TRANS) == SchedGroupMask::NONE)
16631673
InvertedMask &= ~SchedGroupMask::ALU;
16641674

16651675
// VMEM implies VMEM_READ, VMEM_WRITE.
@@ -1678,6 +1688,9 @@ IGroupLPDAGMutation::invertSchedBarrierMask(SchedGroupMask Mask) const {
16781688
(InvertedMask & SchedGroupMask::DS_WRITE) == SchedGroupMask::NONE)
16791689
InvertedMask &= ~SchedGroupMask::DS;
16801690

1691+
LLVM_DEBUG(dbgs() << "After Inverting, SchedGroup Mask: " << (int)InvertedMask
1692+
<< "\n");
1693+
16811694
return InvertedMask;
16821695
}
16831696

0 commit comments

Comments
 (0)