File tree Expand file tree Collapse file tree 9 files changed +59
-22
lines changed Expand file tree Collapse file tree 9 files changed +59
-22
lines changed Original file line number Diff line number Diff line change @@ -2000,7 +2000,8 @@ class TargetTransformInfo {
20002000 // / Returns true if GEP should not be used to index into vectors for this
20012001 // / target.
20022002 LLVM_ABI bool allowVectorElementIndexingUsingGEP () const ;
2003- InstructionUniformity getInstructionUniformity (const Instruction &I) const ;
2003+
2004+ InstructionUniformity getInstructionUniformity (const Value *V) const ;
20042005
20052006private:
20062007 std::unique_ptr<const TargetTransformInfoImplBase> TTIImpl;
Original file line number Diff line number Diff line change @@ -1153,8 +1153,11 @@ class TargetTransformInfoImplBase {
11531153 SmallVectorImpl<std::pair<StringRef, int64_t >> &LB) const {}
11541154
11551155 virtual bool allowVectorElementIndexingUsingGEP () const { return true ; }
1156- virtual InstructionUniformity
1157- getInstructionUniformity (const Instruction &I) const {
1156+
1157+ // New API for uniformity classification
1158+ // Targets should override this to provide target-specific uniformity analysis
1159+ // The default implementation returns Default (conservative behavior)
1160+ virtual InstructionUniformity getInstructionUniformity (const Value *V) const {
11581161 return InstructionUniformity::Default;
11591162 }
11601163
Original file line number Diff line number Diff line change @@ -1518,8 +1518,8 @@ bool TargetTransformInfo::allowVectorElementIndexingUsingGEP() const {
15181518}
15191519
15201520InstructionUniformity
1521- TargetTransformInfo::getInstructionUniformity (const Instruction &I ) const {
1522- return TTIImpl->getInstructionUniformity (I );
1521+ TargetTransformInfo::getInstructionUniformity (const Value *V ) const {
1522+ return TTIImpl->getInstructionUniformity (V );
15231523}
15241524
15251525TargetTransformInfoImplBase::~TargetTransformInfoImplBase () = default ;
Original file line number Diff line number Diff line change @@ -32,16 +32,24 @@ bool llvm::GenericUniformityAnalysisImpl<SSAContext>::markDefsDivergent(
3232
3333template <> void llvm::GenericUniformityAnalysisImpl<SSAContext>::initialize() {
3434 for (auto &I : instructions (F)) {
35- if (TTI->isSourceOfDivergence (&I))
35+ InstructionUniformity IU = TTI->getInstructionUniformity (&I);
36+ switch (IU) {
37+ case InstructionUniformity::NeverUniform:
3638 markDivergent (I);
37- else if (TTI->isAlwaysUniform (&I))
39+ break ;
40+ case InstructionUniformity::AlwaysUniform:
3841 addUniformOverride (I);
39- InstructionUniformity IU = TTI->getInstructionUniformity (I);
40- if (IU != InstructionUniformity::Default)
42+ break ;
43+ case InstructionUniformity::Default:
44+ break ;
45+ default :
4146 addUniformInstruction (&I, IU);
47+ break ;
48+ }
4249 }
4350 for (auto &Arg : F.args ()) {
44- if (TTI->isSourceOfDivergence (&Arg)) {
51+ if (TTI->getInstructionUniformity (&Arg) ==
52+ InstructionUniformity::NeverUniform) {
4553 markDivergent (&Arg);
4654 }
4755 }
Original file line number Diff line number Diff line change @@ -148,15 +148,11 @@ bool llvm::GenericUniformityAnalysisImpl<MachineSSAContext>::isDivergentUse(
148148 return isTemporalDivergent (*UseInstr->getParent (), *DefInstr);
149149}
150150
151+ // This can be defined later depending on use of the MachineUniformityAnalysis.
151152template <>
152153bool GenericUniformityAnalysisImpl<MachineSSAContext>::isOperandUniform(
153- const MachineInstr &I, InstructionUniformity IU) const {
154- switch (IU) {
155- case InstructionUniformity::AnyOfFirstTwoUseOp:
156- return !isDivergentUse (I.getOperand (1 )) || !isDivergentUse (I.getOperand (2 ));
157- default :
158- return false ;
159- }
154+ const MachineInstr &MI, InstructionUniformity IU) const {
155+ return false ;
160156}
161157
162158// This ensures explicit instantiation of
Original file line number Diff line number Diff line change @@ -1575,16 +1575,31 @@ unsigned GCNTTIImpl::getNumberOfParts(Type *Tp) const {
15751575 return BaseT::getNumberOfParts (Tp);
15761576}
15771577
1578+ // New API that wraps the old isSourceOfDivergence and isAlwaysUniform APIs
1579+ // with additional support for new uniformity classifications
15781580InstructionUniformity
1579- GCNTTIImpl::getInstructionUniformity (const Instruction &I) const {
1580- if (const auto *II = dyn_cast<IntrinsicInst>(&I)) {
1581- switch (II->getIntrinsicID ()) {
1581+ GCNTTIImpl::getInstructionUniformity (const Value *V) const {
1582+ // Check for new special cases first (permlane16/permlanex16)
1583+ // These need operand-dependent uniformity analysis
1584+ if (const IntrinsicInst *Intrinsic = dyn_cast<IntrinsicInst>(V)) {
1585+ switch (Intrinsic->getIntrinsicID ()) {
15821586 case Intrinsic::amdgcn_permlane16:
15831587 case Intrinsic::amdgcn_permlanex16:
1588+ // Result value can be uniform if either of first two operands are uniform
15841589 return InstructionUniformity::AnyOfFirstTwoUseOp;
15851590 default :
15861591 break ;
15871592 }
15881593 }
1594+
1595+ // Delegate to old APIs for backward compatibility
1596+ if (isAlwaysUniform (V))
1597+ return InstructionUniformity::AlwaysUniform;
1598+
1599+ // Check if source of divergence
1600+ if (isSourceOfDivergence (V))
1601+ return InstructionUniformity::NeverUniform;
1602+
1603+ // Default behavior
15891604 return InstructionUniformity::Default;
15901605}
Original file line number Diff line number Diff line change @@ -302,8 +302,8 @@ class GCNTTIImpl final : public BasicTTIImplBase<GCNTTIImpl> {
302302 // / together under a single i32 value. Otherwise fall back to base
303303 // / implementation.
304304 unsigned getNumberOfParts (Type *Tp) const override ;
305- InstructionUniformity
306- getInstructionUniformity (const Instruction &I ) const override ;
305+
306+ InstructionUniformity getInstructionUniformity (const Value *V ) const override ;
307307};
308308
309309} // end namespace llvm
Original file line number Diff line number Diff line change @@ -635,3 +635,16 @@ void NVPTXTTIImpl::collectKernelLaunchBounds(
635635 if (MaxNTID.size () > 2 )
636636 LB.push_back ({" maxntidz" , MaxNTID[2 ]});
637637}
638+
639+ // New API that wraps the old isSourceOfDivergence API
640+ // NVPTX doesn't have isAlwaysUniform, so we only delegate to
641+ // isSourceOfDivergence
642+ InstructionUniformity
643+ NVPTXTTIImpl::getInstructionUniformity (const Value *V) const {
644+ // Delegate to old API for backward compatibility
645+ if (isSourceOfDivergence (V))
646+ return InstructionUniformity::NeverUniform;
647+
648+ // Default behavior
649+ return InstructionUniformity::Default;
650+ }
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ class NVPTXTTIImpl final : public BasicTTIImplBase<NVPTXTTIImpl> {
195195 // Self-referential globals are not supported.
196196 return false ;
197197 }
198+ InstructionUniformity getInstructionUniformity (const Value *V) const override ;
198199};
199200
200201} // end namespace llvm
You can’t perform that action at this time.
0 commit comments