@@ -1009,6 +1009,82 @@ struct AAAMDGPUNoAGPR
1009
1009
1010
1010
const char AAAMDGPUNoAGPR::ID = 0 ;
1011
1011
1012
+ struct AAAMDGPUInreg
1013
+ : public IRAttribute<Attribute::InReg,
1014
+ StateWrapper<BooleanState, AbstractAttribute>,
1015
+ AAAMDGPUInreg> {
1016
+ AAAMDGPUInreg (const IRPosition &IRP, Attributor &A) : IRAttribute(IRP) {}
1017
+
1018
+ // / Create an abstract attribute view for the position \p IRP.
1019
+ static AAAMDGPUInreg &createForPosition (const IRPosition &IRP, Attributor &A);
1020
+
1021
+ // / See AbstractAttribute::getName()
1022
+ const std::string getName () const override { return " AAAMDGPUInreg" ; }
1023
+
1024
+ const std::string getAsStr (Attributor *A) const override {
1025
+ return getAssumed () ? " inreg" : " non-inreg" ;
1026
+ }
1027
+
1028
+ void trackStatistics () const override {}
1029
+
1030
+ // / See AbstractAttribute::getIdAddr()
1031
+ const char *getIdAddr () const override { return &ID; }
1032
+
1033
+ // / This function should return true if the type of the \p AA is AAAMDGPUInreg
1034
+ static bool classof (const AbstractAttribute *AA) {
1035
+ return (AA->getIdAddr () == &ID);
1036
+ }
1037
+
1038
+ // / Unique ID (due to the unique address)
1039
+ static const char ID;
1040
+ };
1041
+
1042
+ const char AAAMDGPUInreg::ID = 0 ;
1043
+
1044
+ namespace {
1045
+
1046
+ struct AAAMDGPUInregArgument : public AAAMDGPUInreg {
1047
+ AAAMDGPUInregArgument (const IRPosition &IRP, Attributor &A)
1048
+ : AAAMDGPUInreg(IRP, A) {}
1049
+
1050
+ void initialize (Attributor &A) override {
1051
+ if (getAssociatedArgument ()->hasAttribute (Attribute::InReg))
1052
+ indicateOptimisticFixpoint ();
1053
+ }
1054
+
1055
+ ChangeStatus updateImpl (Attributor &A) override {
1056
+ const auto &InfoCache =
1057
+ static_cast <AMDGPUInformationCache &>(A.getInfoCache ());
1058
+ unsigned ArgNo = getAssociatedArgument ()->getArgNo ();
1059
+
1060
+ auto Pred = [&](AbstractCallSite ACS) -> bool {
1061
+ CallBase *CB = ACS.getInstruction ();
1062
+ auto TTI = InfoCache.TM .getTargetTransformInfo (*CB->getFunction ());
1063
+ Value *V = CB->getArgOperandUse (ArgNo);
1064
+ return TTI.isAlwaysUniform (V);
1065
+ };
1066
+
1067
+ bool UsedAssumedInformation = false ;
1068
+ if (!A.checkForAllCallSites (Pred, *this , /* RequireAllCallSites=*/ true ,
1069
+ UsedAssumedInformation))
1070
+ return indicatePessimisticFixpoint ();
1071
+
1072
+ return ChangeStatus::UNCHANGED;
1073
+ }
1074
+ };
1075
+
1076
+ } // namespace
1077
+
1078
+ AAAMDGPUInreg &AAAMDGPUInreg::createForPosition (const IRPosition &IRP,
1079
+ Attributor &A) {
1080
+ switch (IRP.getPositionKind ()) {
1081
+ case IRPosition::IRP_ARGUMENT:
1082
+ return *new (A.Allocator ) AAAMDGPUInregArgument (IRP, A);
1083
+ default :
1084
+ llvm_unreachable (" not a valid position for AAAMDGPUInreg" );
1085
+ }
1086
+ }
1087
+
1012
1088
static void addPreloadKernArgHint (Function &F, TargetMachine &TM) {
1013
1089
const GCNSubtarget &ST = TM.getSubtarget <GCNSubtarget>(F);
1014
1090
for (unsigned I = 0 ;
@@ -1041,7 +1117,7 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
1041
1117
&AAAMDWavesPerEU::ID, &AAAMDGPUNoAGPR::ID, &AACallEdges::ID,
1042
1118
&AAPointerInfo::ID, &AAPotentialConstantValues::ID,
1043
1119
&AAUnderlyingObjects::ID, &AAAddressSpace::ID, &AAIndirectCallInfo::ID,
1044
- &AAInstanceInfo::ID});
1120
+ &AAInstanceInfo::ID, &AAAMDGPUInreg::ID });
1045
1121
1046
1122
AttributorConfig AC (CGUpdater);
1047
1123
AC.IsClosedWorldModule = Options.IsClosedWorld ;
@@ -1091,6 +1167,11 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM,
1091
1167
IRPosition::value (*SI->getPointerOperand ()));
1092
1168
}
1093
1169
}
1170
+
1171
+ if (F.getCallingConv () != CallingConv::AMDGPU_KERNEL) {
1172
+ for (auto &Arg : F.args ())
1173
+ A.getOrCreateAAFor <AAAMDGPUInreg>(IRPosition::argument (Arg));
1174
+ }
1094
1175
}
1095
1176
1096
1177
ChangeStatus Change = A.run ();
0 commit comments