Skip to content

Commit 37416aa

Browse files
committed
Based on offline discussion moved function to TII. Fix ambiguity in IGLP instr utility functions.
1 parent ee4e158 commit 37416aa

File tree

9 files changed

+37
-46
lines changed

9 files changed

+37
-46
lines changed

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,6 @@ namespace llvm {
374374
void addVRegDefDeps(SUnit *SU, unsigned OperIdx);
375375
void addVRegUseDeps(SUnit *SU, unsigned OperIdx);
376376

377-
/// Returns true if MI is an instruction we are unable to reason about
378-
/// (like a call or something with unmodeled side effects).
379-
virtual bool isGlobalMemoryObject(MachineInstr *MI);
380-
381377
/// Returns a mask for which lanes get read/written by the given (register)
382378
/// machine operand.
383379
LaneBitmask getLaneMaskForMO(const MachineOperand &MO) const;

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ class TargetInstrInfo : public MCInstrInfo {
136136
const TargetRegisterInfo *TRI,
137137
const MachineFunction &MF) const;
138138

139+
/// Returns true if MI is an instruction we are unable to reason about
140+
/// (like a call or something with unmodeled side effects).
141+
virtual bool isGlobalMemoryObject(const MachineInstr *MI) const;
142+
139143
/// Return true if the instruction is trivially rematerializable, meaning it
140144
/// has no side effects and requires no operands that aren't always available.
141145
/// This means the only allowed uses are constants and unallocatable physical

llvm/lib/CodeGen/ScheduleDAGInstrs.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/CodeGen/ScheduleDAG.h"
3636
#include "llvm/CodeGen/ScheduleDFS.h"
3737
#include "llvm/CodeGen/SlotIndexes.h"
38+
#include "llvm/CodeGen/TargetInstrInfo.h"
3839
#include "llvm/CodeGen/TargetRegisterInfo.h"
3940
#include "llvm/CodeGen/TargetSubtargetInfo.h"
4041
#include "llvm/Config/llvm-config.h"
@@ -547,12 +548,6 @@ void ScheduleDAGInstrs::addVRegUseDeps(SUnit *SU, unsigned OperIdx) {
547548
}
548549
}
549550

550-
/// Returns true if MI is an instruction we are unable to reason about
551-
/// (like a call or something with unmodeled side effects).
552-
bool ScheduleDAGInstrs::isGlobalMemoryObject(MachineInstr *MI) {
553-
return MI->isCall() || MI->hasUnmodeledSideEffects() ||
554-
(MI->hasOrderedMemoryRef() && !MI->isDereferenceableInvariantLoad());
555-
}
556551

557552
void ScheduleDAGInstrs::addChainDependency (SUnit *SUa, SUnit *SUb,
558553
unsigned Latency) {
@@ -899,8 +894,9 @@ void ScheduleDAGInstrs::buildSchedGraph(AAResults *AA,
899894
// isLoadFromStackSLot are not usable after stack slots are lowered to
900895
// actual addresses).
901896

897+
const TargetInstrInfo *TII = ST.getInstrInfo();
902898
// This is a barrier event that acts as a pivotal node in the DAG.
903-
if (isGlobalMemoryObject(&MI)) {
899+
if (TII->isGlobalMemoryObject(&MI)) {
904900

905901
// Become the barrier chain.
906902
if (BarrierChain)

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,3 +1917,8 @@ bool TargetInstrInfo::isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,
19171917
}
19181918
return true;
19191919
}
1920+
1921+
bool TargetInstrInfo::isGlobalMemoryObject(const MachineInstr *MI) const {
1922+
return MI->isCall() || MI->hasUnmodeledSideEffects() ||
1923+
(MI->hasOrderedMemoryRef() && !MI->isDereferenceableInvariantLoad());
1924+
}

llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "AMDGPUIGroupLP.h"
2828
#include "SIMachineFunctionInfo.h"
2929
#include "llvm/CodeGen/RegisterClassInfo.h"
30-
#include "llvm/CodeGen/ScheduleDAGInstrs.h"
3130

3231
#define DEBUG_TYPE "machine-scheduler"
3332

@@ -189,6 +188,12 @@ static void getRegisterPressures(
189188
Pressure[AMDGPU::RegisterPressureSets::AGPR_32] = NewPressure.getAGPRNum();
190189
}
191190

191+
// Return true if the instruction is mutually exclusive with all non-IGLP DAG
192+
// mutations, requiring all other mutations to be disabled.
193+
static bool isIGLPMutationOnly(unsigned Opcode) {
194+
return Opcode == AMDGPU::SCHED_GROUP_BARRIER || Opcode == AMDGPU::IGLP_OPT;
195+
}
196+
192197
void GCNSchedStrategy::initCandidate(SchedCandidate &Cand, SUnit *SU,
193198
bool AtTop,
194199
const RegPressureTracker &RPTracker,
@@ -1153,8 +1158,7 @@ bool GCNSchedStage::initGCNRegion() {
11531158
StageID == GCNSchedStageID::ILPInitialSchedule) {
11541159
for (auto &I : DAG) {
11551160
Unsched.push_back(&I);
1156-
if (I.getOpcode() == AMDGPU::SCHED_GROUP_BARRIER ||
1157-
I.getOpcode() == AMDGPU::IGLP_OPT)
1161+
if (isIGLPMutationOnly(I.getOpcode()))
11581162
DAG.RegionsWithIGLPInstrs[RegionIdx] = true;
11591163
}
11601164
} else {
@@ -1893,43 +1897,17 @@ void GCNScheduleDAGMILive::updateRegionBoundaries(
18931897
}
18941898
}
18951899

1896-
static bool isIGLPInstr(MachineInstr *MI) {
1897-
switch (MI->getOpcode()) {
1898-
case AMDGPU::IGLP_OPT:
1899-
case AMDGPU::SCHED_BARRIER:
1900-
case AMDGPU::SCHED_GROUP_BARRIER:
1901-
return true;
1902-
default:
1903-
return false;
1904-
}
1905-
}
1906-
19071900
static bool hasIGLPInstrs(ScheduleDAGInstrs *DAG) {
19081901
return any_of(*DAG, [](MachineBasicBlock::iterator MI) {
1909-
unsigned Opc = MI->getOpcode();
1910-
return Opc == AMDGPU::SCHED_GROUP_BARRIER || Opc == AMDGPU::IGLP_OPT;
1902+
return isIGLPMutationOnly(MI->getOpcode());
19111903
});
19121904
}
19131905

1914-
bool GCNScheduleDAGMILive::isGlobalMemoryObject(MachineInstr *MI) {
1915-
if (isIGLPInstr(MI))
1916-
return false;
1917-
1918-
return ScheduleDAGInstrs::isGlobalMemoryObject(MI);
1919-
}
1920-
19211906
GCNPostScheduleDAGMILive::GCNPostScheduleDAGMILive(
19221907
MachineSchedContext *C, std::unique_ptr<MachineSchedStrategy> S,
19231908
bool RemoveKillFlags)
19241909
: ScheduleDAGMI(C, std::move(S), RemoveKillFlags) {}
19251910

1926-
bool GCNPostScheduleDAGMILive::isGlobalMemoryObject(MachineInstr *MI) {
1927-
if (isIGLPInstr(MI))
1928-
return false;
1929-
1930-
return ScheduleDAGInstrs::isGlobalMemoryObject(MI);
1931-
}
1932-
19331911
void GCNPostScheduleDAGMILive::schedule() {
19341912
HasIGLPInstrs = hasIGLPInstrs(this);
19351913
if (HasIGLPInstrs) {

llvm/lib/Target/AMDGPU/GCNSchedStrategy.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,6 @@ class GCNScheduleDAGMILive final : public ScheduleDAGMILive {
297297

298298
std::unique_ptr<GCNSchedStage> createSchedStage(GCNSchedStageID SchedStageID);
299299

300-
bool isGlobalMemoryObject(MachineInstr *MI) override;
301-
302300
public:
303301
GCNScheduleDAGMILive(MachineSchedContext *C,
304302
std::unique_ptr<MachineSchedStrategy> S);
@@ -492,8 +490,6 @@ class GCNPostScheduleDAGMILive final : public ScheduleDAGMI {
492490

493491
bool HasIGLPInstrs = false;
494492

495-
bool isGlobalMemoryObject(MachineInstr *MI) override;
496-
497493
public:
498494
void schedule() override;
499495

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10051,3 +10051,10 @@ void SIInstrInfo::enforceOperandRCAlignment(MachineInstr &MI,
1005110051
Op.setSubReg(AMDGPU::sub0);
1005210052
MI.addOperand(MachineOperand::CreateReg(NewVR, false, true));
1005310053
}
10054+
10055+
bool SIInstrInfo::isGlobalMemoryObject(const MachineInstr *MI) const {
10056+
if (isIGLP(*MI))
10057+
return false;
10058+
10059+
return TargetInstrInfo::isGlobalMemoryObject(MI);
10060+
}

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
242242
bool areLoadsFromSameBasePtr(SDNode *Load0, SDNode *Load1, int64_t &Offset0,
243243
int64_t &Offset1) const override;
244244

245+
bool isGlobalMemoryObject(const MachineInstr *MI) const override;
246+
245247
bool getMemOperandsWithOffsetWidth(
246248
const MachineInstr &LdSt,
247249
SmallVectorImpl<const MachineOperand *> &BaseOps, int64_t &Offset,
@@ -968,6 +970,13 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
968970
return get(Opcode).TSFlags & SIInstrFlags::TiedSourceNotRead;
969971
}
970972

973+
bool isIGLP(unsigned Opcode) const {
974+
return Opcode == AMDGPU::SCHED_BARRIER ||
975+
Opcode == AMDGPU::SCHED_GROUP_BARRIER || Opcode == AMDGPU::IGLP_OPT;
976+
}
977+
978+
bool isIGLP(const MachineInstr &MI) const { return isIGLP(MI.getOpcode()); }
979+
971980
static unsigned getNonSoftWaitcntOpcode(unsigned Opcode) {
972981
switch (Opcode) {
973982
case AMDGPU::S_WAITCNT_soft:

llvm/test/CodeGen/AMDGPU/llvm.amdgcn.iglp.opt.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ entry:
288288
define amdgpu_kernel void @test_iglp_opt_asm_sideeffect(ptr addrspace(3) noalias %in, ptr addrspace(3) noalias %out) #0 {
289289
; GCN-LABEL: test_iglp_opt_asm_sideeffect:
290290
; GCN: ; %bb.0: ; %entry
291-
; GCN-NEXT: s_load_dwordx2 s[0:1], s[2:3], 0x24
291+
; GCN-NEXT: s_load_dwordx2 s[0:1], s[4:5], 0x24
292292
; GCN-NEXT: v_lshlrev_b32_e32 v0, 2, v0
293293
; GCN-NEXT: v_and_b32_e32 v0, 0xffc, v0
294294
; GCN-NEXT: ; iglp_opt mask(0x00000000)

0 commit comments

Comments
 (0)