Skip to content

Commit 0022b58

Browse files
committed
[DAG/AMDGPU] Use UniformityAnalysis in DAGISel
Switch DAGISel over to UniformityAnalysis, which was one of the last remaining users of the DivergenceAnalysis. No explosions seen during internal testing so this looks like a smooth transition. Reviewed By: sameerds Differential Revision: https://reviews.llvm.org/D145918
1 parent a1fae98 commit 0022b58

File tree

10 files changed

+62
-49
lines changed

10 files changed

+62
-49
lines changed

llvm/include/llvm/CodeGen/FunctionLoweringInfo.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ namespace llvm {
3535
class Argument;
3636
class BasicBlock;
3737
class BranchProbabilityInfo;
38-
class LegacyDivergenceAnalysis;
3938
class Function;
4039
class Instruction;
4140
class MachineFunction;
@@ -45,6 +44,11 @@ class MVT;
4544
class SelectionDAG;
4645
class TargetLowering;
4746

47+
template <typename T> class GenericSSAContext;
48+
using SSAContext = GenericSSAContext<Function>;
49+
template <typename T> class GenericUniformityInfo;
50+
using UniformityInfo = GenericUniformityInfo<SSAContext>;
51+
4852
//===--------------------------------------------------------------------===//
4953
/// FunctionLoweringInfo - This contains information that is global to a
5054
/// function that is used when lowering a region of the function.
@@ -56,7 +60,7 @@ class FunctionLoweringInfo {
5660
const TargetLowering *TLI;
5761
MachineRegisterInfo *RegInfo;
5862
BranchProbabilityInfo *BPI;
59-
const LegacyDivergenceAnalysis *DA;
63+
const UniformityInfo *UA;
6064
/// CanLowerReturn - true iff the function's return value can be lowered to
6165
/// registers.
6266
bool CanLowerReturn;

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class FunctionLoweringInfo;
7171
class FunctionVarLocs;
7272
class GlobalValue;
7373
struct KnownBits;
74-
class LegacyDivergenceAnalysis;
7574
class LLVMContext;
7675
class MachineBasicBlock;
7776
class MachineConstantPoolValue;
@@ -89,6 +88,11 @@ class TargetMachine;
8988
class TargetSubtargetInfo;
9089
class Value;
9190

91+
template <typename T> class GenericSSAContext;
92+
using SSAContext = GenericSSAContext<Function>;
93+
template <typename T> class GenericUniformityInfo;
94+
using UniformityInfo = GenericUniformityInfo<SSAContext>;
95+
9296
class SDVTListNode : public FoldingSetNode {
9397
friend struct FoldingSetTrait<SDVTListNode>;
9498

@@ -229,7 +233,7 @@ class SelectionDAG {
229233
LLVMContext *Context;
230234
CodeGenOpt::Level OptLevel;
231235

232-
LegacyDivergenceAnalysis * DA = nullptr;
236+
UniformityInfo *UA = nullptr;
233237
FunctionLoweringInfo * FLI = nullptr;
234238

235239
/// The function-level optimization remark emitter. Used to emit remarks
@@ -451,7 +455,7 @@ class SelectionDAG {
451455
/// Prepare this SelectionDAG to process code in the given MachineFunction.
452456
void init(MachineFunction &NewMF, OptimizationRemarkEmitter &NewORE,
453457
Pass *PassPtr, const TargetLibraryInfo *LibraryInfo,
454-
LegacyDivergenceAnalysis *Divergence, ProfileSummaryInfo *PSIin,
458+
UniformityInfo *UA, ProfileSummaryInfo *PSIin,
455459
BlockFrequencyInfo *BFIin, FunctionVarLocs const *FnVarLocs);
456460

457461
void setFunctionLoweringInfo(FunctionLoweringInfo * FuncInfo) {
@@ -474,7 +478,7 @@ class SelectionDAG {
474478
const TargetLowering &getTargetLoweringInfo() const { return *TLI; }
475479
const TargetLibraryInfo &getLibInfo() const { return *LibInfo; }
476480
const SelectionDAGTargetInfo &getSelectionDAGInfo() const { return *TSI; }
477-
const LegacyDivergenceAnalysis *getDivergenceAnalysis() const { return DA; }
481+
const UniformityInfo *getUniformityInfo() const { return UA; }
478482
/// Returns the result of the AssignmentTrackingAnalysis pass if it's
479483
/// available, otherwise return nullptr.
480484
const FunctionVarLocs *getFunctionVarLocs() const { return FnVarLocs; }

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class GISelKnownBits;
7474
class IntrinsicInst;
7575
class IRBuilderBase;
7676
struct KnownBits;
77-
class LegacyDivergenceAnalysis;
7877
class LLVMContext;
7978
class MachineBasicBlock;
8079
class MachineFunction;
@@ -3537,7 +3536,7 @@ class TargetLowering : public TargetLoweringBase {
35373536

35383537
virtual bool isSDNodeSourceOfDivergence(const SDNode *N,
35393538
FunctionLoweringInfo *FLI,
3540-
LegacyDivergenceAnalysis *DA) const {
3539+
UniformityInfo *UA) const {
35413540
return false;
35423541
}
35433542

llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include "llvm/CodeGen/FunctionLoweringInfo.h"
1515
#include "llvm/ADT/APInt.h"
16-
#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
16+
#include "llvm/Analysis/UniformityAnalysis.h"
1717
#include "llvm/CodeGen/Analysis.h"
1818
#include "llvm/CodeGen/MachineFrameInfo.h"
1919
#include "llvm/CodeGen/MachineFunction.h"
@@ -83,7 +83,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
8383
TLI = MF->getSubtarget().getTargetLowering();
8484
RegInfo = &MF->getRegInfo();
8585
const TargetFrameLowering *TFI = MF->getSubtarget().getFrameLowering();
86-
DA = DAG->getDivergenceAnalysis();
86+
UA = DAG->getUniformityInfo();
8787

8888
// Check whether the function can return without sret-demotion.
8989
SmallVector<ISD::OutputArg, 4> Outs;
@@ -381,8 +381,8 @@ Register FunctionLoweringInfo::CreateRegs(Type *Ty, bool isDivergent) {
381381
}
382382

383383
Register FunctionLoweringInfo::CreateRegs(const Value *V) {
384-
return CreateRegs(V->getType(), DA && DA->isDivergent(V) &&
385-
!TLI->requiresUniformRegister(*MF, V));
384+
return CreateRegs(V->getType(), UA && UA->isDivergent(V) &&
385+
!TLI->requiresUniformRegister(*MF, V));
386386
}
387387

388388
/// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,8 +1311,8 @@ SelectionDAG::SelectionDAG(const TargetMachine &tm, CodeGenOpt::Level OL)
13111311
void SelectionDAG::init(MachineFunction &NewMF,
13121312
OptimizationRemarkEmitter &NewORE, Pass *PassPtr,
13131313
const TargetLibraryInfo *LibraryInfo,
1314-
LegacyDivergenceAnalysis *Divergence,
1315-
ProfileSummaryInfo *PSIin, BlockFrequencyInfo *BFIin,
1314+
UniformityInfo *NewUA, ProfileSummaryInfo *PSIin,
1315+
BlockFrequencyInfo *BFIin,
13161316
FunctionVarLocs const *VarLocs) {
13171317
MF = &NewMF;
13181318
SDAGISelPass = PassPtr;
@@ -1321,7 +1321,7 @@ void SelectionDAG::init(MachineFunction &NewMF,
13211321
TSI = getSubtarget().getSelectionDAGInfo();
13221322
LibInfo = LibraryInfo;
13231323
Context = &MF->getFunction().getContext();
1324-
DA = Divergence;
1324+
UA = NewUA;
13251325
PSI = PSIin;
13261326
BFI = BFIin;
13271327
FnVarLocs = VarLocs;
@@ -2175,7 +2175,7 @@ SDValue SelectionDAG::getRegister(unsigned RegNo, EVT VT) {
21752175
return SDValue(E, 0);
21762176

21772177
auto *N = newSDNode<RegisterSDNode>(RegNo, VT);
2178-
N->SDNodeBits.IsDivergent = TLI->isSDNodeSourceOfDivergence(N, FLI, DA);
2178+
N->SDNodeBits.IsDivergent = TLI->isSDNodeSourceOfDivergence(N, FLI, UA);
21792179
CSEMap.InsertNode(N, IP);
21802180
InsertNode(N);
21812181
return SDValue(N, 0);
@@ -10659,11 +10659,11 @@ class RAUOVWUpdateListener : public SelectionDAG::DAGUpdateListener {
1065910659

1066010660
bool SelectionDAG::calculateDivergence(SDNode *N) {
1066110661
if (TLI->isSDNodeAlwaysUniform(N)) {
10662-
assert(!TLI->isSDNodeSourceOfDivergence(N, FLI, DA) &&
10662+
assert(!TLI->isSDNodeSourceOfDivergence(N, FLI, UA) &&
1066310663
"Conflicting divergence information!");
1066410664
return false;
1066510665
}
10666-
if (TLI->isSDNodeSourceOfDivergence(N, FLI, DA))
10666+
if (TLI->isSDNodeSourceOfDivergence(N, FLI, UA))
1066710667
return true;
1066810668
for (const auto &Op : N->ops()) {
1066910669
if (Op.Val.getValueType() != MVT::Other && Op.getNode()->isDivergent())
@@ -12158,7 +12158,7 @@ void SelectionDAG::createOperands(SDNode *Node, ArrayRef<SDValue> Vals) {
1215812158
Node->NumOperands = Vals.size();
1215912159
Node->OperandList = Ops;
1216012160
if (!TLI->isSDNodeAlwaysUniform(Node)) {
12161-
IsDivergent |= TLI->isSDNodeSourceOfDivergence(Node, FLI, DA);
12161+
IsDivergent |= TLI->isSDNodeSourceOfDivergence(Node, FLI, UA);
1216212162
Node->SDNodeBits.IsDivergent = IsDivergent;
1216312163
}
1216412164
checkForCycles(Node);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
#include "llvm/Analysis/BranchProbabilityInfo.h"
2727
#include "llvm/Analysis/CFG.h"
2828
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
29-
#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
3029
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
3130
#include "llvm/Analysis/ProfileSummaryInfo.h"
3231
#include "llvm/Analysis/TargetLibraryInfo.h"
3332
#include "llvm/Analysis/TargetTransformInfo.h"
33+
#include "llvm/Analysis/UniformityAnalysis.h"
3434
#include "llvm/CodeGen/AssignmentTrackingAnalysis.h"
3535
#include "llvm/CodeGen/CodeGenCommonISel.h"
3636
#include "llvm/CodeGen/FastISel.h"
@@ -425,9 +425,10 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
425425

426426
LLVM_DEBUG(dbgs() << "\n\n\n=== " << Fn.getName() << "\n");
427427

428-
CurDAG->init(*MF, *ORE, this, LibInfo,
429-
getAnalysisIfAvailable<LegacyDivergenceAnalysis>(), PSI, BFI,
430-
FnVarLocs);
428+
UniformityInfo *UA = nullptr;
429+
if (auto *UAPass = getAnalysisIfAvailable<UniformityInfoWrapperPass>())
430+
UA = &UAPass->getUniformityInfo();
431+
CurDAG->init(*MF, *ORE, this, LibInfo, UA, PSI, BFI, FnVarLocs);
431432
FuncInfo->set(Fn, *MF, CurDAG);
432433
SwiftError->setFunction(*MF);
433434

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "MCTargetDesc/R600MCTargetDesc.h"
2121
#include "R600RegisterInfo.h"
2222
#include "SIMachineFunctionInfo.h"
23-
#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
23+
#include "llvm/Analysis/UniformityAnalysis.h"
2424
#include "llvm/Analysis/ValueTracking.h"
2525
#include "llvm/CodeGen/FunctionLoweringInfo.h"
2626
#include "llvm/CodeGen/SelectionDAG.h"
@@ -101,7 +101,7 @@ INITIALIZE_PASS_BEGIN(AMDGPUDAGToDAGISel, "amdgpu-isel",
101101
"AMDGPU DAG->DAG Pattern Instruction Selection", false, false)
102102
INITIALIZE_PASS_DEPENDENCY(AMDGPUArgumentUsageInfo)
103103
INITIALIZE_PASS_DEPENDENCY(AMDGPUPerfHintAnalysis)
104-
INITIALIZE_PASS_DEPENDENCY(LegacyDivergenceAnalysis)
104+
INITIALIZE_PASS_DEPENDENCY(UniformityInfoWrapperPass)
105105
#ifdef EXPENSIVE_CHECKS
106106
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
107107
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
@@ -199,7 +199,7 @@ bool AMDGPUDAGToDAGISel::fp16SrcZerosHighBits(unsigned Opc) const {
199199

200200
void AMDGPUDAGToDAGISel::getAnalysisUsage(AnalysisUsage &AU) const {
201201
AU.addRequired<AMDGPUArgumentUsageInfo>();
202-
AU.addRequired<LegacyDivergenceAnalysis>();
202+
AU.addRequired<UniformityInfoWrapperPass>();
203203
#ifdef EXPENSIVE_CHECKS
204204
AU.addRequired<DominatorTreeWrapperPass>();
205205
AU.addRequired<LoopInfoWrapperPass>();

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "SIRegisterInfo.h"
2020
#include "llvm/ADT/FloatingPointMode.h"
2121
#include "llvm/ADT/Statistic.h"
22-
#include "llvm/Analysis/LegacyDivergenceAnalysis.h"
2322
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
23+
#include "llvm/Analysis/UniformityAnalysis.h"
2424
#include "llvm/BinaryFormat/ELF.h"
2525
#include "llvm/CodeGen/Analysis.h"
2626
#include "llvm/CodeGen/FunctionLoweringInfo.h"
@@ -35,8 +35,8 @@
3535
#include "llvm/IR/IntrinsicsAMDGPU.h"
3636
#include "llvm/IR/IntrinsicsR600.h"
3737
#include "llvm/Support/CommandLine.h"
38-
#include "llvm/Support/ModRef.h"
3938
#include "llvm/Support/KnownBits.h"
39+
#include "llvm/Support/ModRef.h"
4040

4141
using namespace llvm;
4242

@@ -12871,9 +12871,9 @@ static bool isCopyFromRegOfInlineAsm(const SDNode *N) {
1287112871
return false;
1287212872
}
1287312873

12874-
bool SITargetLowering::isSDNodeSourceOfDivergence(
12875-
const SDNode *N, FunctionLoweringInfo *FLI,
12876-
LegacyDivergenceAnalysis *KDA) const {
12874+
bool SITargetLowering::isSDNodeSourceOfDivergence(const SDNode *N,
12875+
FunctionLoweringInfo *FLI,
12876+
UniformityInfo *UA) const {
1287712877
switch (N->getOpcode()) {
1287812878
case ISD::CopyFromReg: {
1287912879
const RegisterSDNode *R = cast<RegisterSDNode>(N->getOperand(1));
@@ -12886,7 +12886,7 @@ bool SITargetLowering::isSDNodeSourceOfDivergence(
1288612886
return !TRI->isSGPRReg(MRI, Reg);
1288712887

1288812888
if (const Value *V = FLI->getValueFromVirtualReg(R->getReg()))
12889-
return KDA->isDivergent(V);
12889+
return UA->isDivergent(V);
1289012890

1289112891
assert(Reg == FLI->DemoteRegister || isCopyFromRegOfInlineAsm(N));
1289212892
return !TRI->isSGPRReg(MRI, Reg);
@@ -13167,6 +13167,8 @@ SITargetLowering::getRegClassFor(MVT VT, bool isDivergent) const {
1316713167
// uniform values (as produced by the mask results of control flow intrinsics)
1316813168
// used outside of divergent blocks. The phi users need to also be treated as
1316913169
// always uniform.
13170+
//
13171+
// FIXME: DA is no longer in-use. Does this still apply to UniformityAnalysis?
1317013172
static bool hasCFUser(const Value *V, SmallPtrSet<const Value *, 16> &Visited,
1317113173
unsigned WaveSize) {
1317213174
// FIXME: We assume we never cast the mask results of a control flow

llvm/lib/Target/AMDGPU/SIISelLowering.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ class SITargetLowering final : public AMDGPUTargetLowering {
466466
Align computeKnownAlignForTargetInstr(GISelKnownBits &Analysis, Register R,
467467
const MachineRegisterInfo &MRI,
468468
unsigned Depth = 0) const override;
469-
bool isSDNodeSourceOfDivergence(const SDNode *N,
470-
FunctionLoweringInfo *FLI, LegacyDivergenceAnalysis *DA) const override;
469+
bool isSDNodeSourceOfDivergence(const SDNode *N, FunctionLoweringInfo *FLI,
470+
UniformityInfo *UA) const override;
471471

472472
bool hasMemSDNodeUser(SDNode *N) const;
473473

llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@
9898
; GCN-O0-NEXT: Safe Stack instrumentation pass
9999
; GCN-O0-NEXT: Insert stack protectors
100100
; GCN-O0-NEXT: Dominator Tree Construction
101-
; GCN-O0-NEXT: Post-Dominator Tree Construction
102-
; GCN-O0-NEXT: Natural Loop Information
103-
; GCN-O0-NEXT: Legacy Divergence Analysis
101+
; GCN-O0-NEXT: Cycle Info Analysis
102+
; GCN-O0-NEXT: Uniformity Analysis
104103
; GCN-O0-NEXT: Assignment Tracking Analysis
105104
; GCN-O0-NEXT: AMDGPU DAG->DAG Pattern Instruction Selection
106105
; GCN-O0-NEXT: MachineDominator Tree Construction
@@ -292,11 +291,12 @@
292291
; GCN-O1-NEXT: Safe Stack instrumentation pass
293292
; GCN-O1-NEXT: Insert stack protectors
294293
; GCN-O1-NEXT: Dominator Tree Construction
295-
; GCN-O1-NEXT: Post-Dominator Tree Construction
296-
; GCN-O1-NEXT: Natural Loop Information
297-
; GCN-O1-NEXT: Legacy Divergence Analysis
294+
; GCN-O1-NEXT: Cycle Info Analysis
295+
; GCN-O1-NEXT: Uniformity Analysis
298296
; GCN-O1-NEXT: Basic Alias Analysis (stateless AA impl)
299297
; GCN-O1-NEXT: Function Alias Analysis Results
298+
; GCN-O1-NEXT: Natural Loop Information
299+
; GCN-O1-NEXT: Post-Dominator Tree Construction
300300
; GCN-O1-NEXT: Branch Probability Analysis
301301
; GCN-O1-NEXT: Assignment Tracking Analysis
302302
; GCN-O1-NEXT: Lazy Branch Probability Analysis
@@ -590,11 +590,12 @@
590590
; GCN-O1-OPTS-NEXT: Safe Stack instrumentation pass
591591
; GCN-O1-OPTS-NEXT: Insert stack protectors
592592
; GCN-O1-OPTS-NEXT: Dominator Tree Construction
593-
; GCN-O1-OPTS-NEXT: Post-Dominator Tree Construction
594-
; GCN-O1-OPTS-NEXT: Natural Loop Information
595-
; GCN-O1-OPTS-NEXT: Legacy Divergence Analysis
593+
; GCN-O1-OPTS-NEXT: Cycle Info Analysis
594+
; GCN-O1-OPTS-NEXT: Uniformity Analysis
596595
; GCN-O1-OPTS-NEXT: Basic Alias Analysis (stateless AA impl)
597596
; GCN-O1-OPTS-NEXT: Function Alias Analysis Results
597+
; GCN-O1-OPTS-NEXT: Natural Loop Information
598+
; GCN-O1-OPTS-NEXT: Post-Dominator Tree Construction
598599
; GCN-O1-OPTS-NEXT: Branch Probability Analysis
599600
; GCN-O1-OPTS-NEXT: Assignment Tracking Analysis
600601
; GCN-O1-OPTS-NEXT: Lazy Branch Probability Analysis
@@ -897,11 +898,12 @@
897898
; GCN-O2-NEXT: Safe Stack instrumentation pass
898899
; GCN-O2-NEXT: Insert stack protectors
899900
; GCN-O2-NEXT: Dominator Tree Construction
900-
; GCN-O2-NEXT: Post-Dominator Tree Construction
901-
; GCN-O2-NEXT: Natural Loop Information
902-
; GCN-O2-NEXT: Legacy Divergence Analysis
901+
; GCN-O2-NEXT: Cycle Info Analysis
902+
; GCN-O2-NEXT: Uniformity Analysis
903903
; GCN-O2-NEXT: Basic Alias Analysis (stateless AA impl)
904904
; GCN-O2-NEXT: Function Alias Analysis Results
905+
; GCN-O2-NEXT: Natural Loop Information
906+
; GCN-O2-NEXT: Post-Dominator Tree Construction
905907
; GCN-O2-NEXT: Branch Probability Analysis
906908
; GCN-O2-NEXT: Assignment Tracking Analysis
907909
; GCN-O2-NEXT: Lazy Branch Probability Analysis
@@ -1216,11 +1218,12 @@
12161218
; GCN-O3-NEXT: Safe Stack instrumentation pass
12171219
; GCN-O3-NEXT: Insert stack protectors
12181220
; GCN-O3-NEXT: Dominator Tree Construction
1219-
; GCN-O3-NEXT: Post-Dominator Tree Construction
1220-
; GCN-O3-NEXT: Natural Loop Information
1221-
; GCN-O3-NEXT: Legacy Divergence Analysis
1221+
; GCN-O3-NEXT: Cycle Info Analysis
1222+
; GCN-O3-NEXT: Uniformity Analysis
12221223
; GCN-O3-NEXT: Basic Alias Analysis (stateless AA impl)
12231224
; GCN-O3-NEXT: Function Alias Analysis Results
1225+
; GCN-O3-NEXT: Natural Loop Information
1226+
; GCN-O3-NEXT: Post-Dominator Tree Construction
12241227
; GCN-O3-NEXT: Branch Probability Analysis
12251228
; GCN-O3-NEXT: Assignment Tracking Analysis
12261229
; GCN-O3-NEXT: Lazy Branch Probability Analysis

0 commit comments

Comments
 (0)