@@ -1009,6 +1009,113 @@ struct AAAMDGPUNoAGPR
10091009
10101010const char AAAMDGPUNoAGPR::ID = 0 ;
10111011
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+ // / See AbstractAttribute::getIdAddr()
1025+ const char *getIdAddr () const override { return &ID; }
1026+
1027+ // / This function should return true if the type of the \p AA is AAAMDGPUInreg
1028+ static bool classof (const AbstractAttribute *AA) {
1029+ return (AA->getIdAddr () == &ID);
1030+ }
1031+
1032+ // / Unique ID (due to the unique address)
1033+ static const char ID;
1034+ };
1035+
1036+ const char AAAMDGPUInreg::ID = 0 ;
1037+
1038+ namespace {
1039+
1040+ struct AAAMDGPUInregCallSiteArgument : public AAAMDGPUInreg {
1041+ AAAMDGPUInregCallSiteArgument (const IRPosition &IRP, Attributor &A)
1042+ : AAAMDGPUInreg(IRP, A) {}
1043+
1044+ void initialize (Attributor &A) override {}
1045+
1046+ const std::string getAsStr (Attributor *A) const override {
1047+ return getAssumed () ? " inreg" : " non-inreg" ;
1048+ }
1049+
1050+ void trackStatistics () const override {}
1051+
1052+ ChangeStatus updateImpl (Attributor &A) override {
1053+ return ChangeStatus::UNCHANGED;
1054+ }
1055+ };
1056+
1057+ struct AAAMDGPUInregArgument : public AAAMDGPUInreg {
1058+ AAAMDGPUInregArgument (const IRPosition &IRP, Attributor &A)
1059+ : AAAMDGPUInreg(IRP, A) {}
1060+
1061+ void initialize (Attributor &A) override {
1062+ if (getAssociatedArgument ()->hasAttribute (Attribute::InReg))
1063+ indicateOptimisticFixpoint ();
1064+ }
1065+
1066+ const std::string getAsStr (Attributor *A) const override {
1067+ return getAssumed () ? " inreg" : " non-inreg" ;
1068+ }
1069+
1070+ void trackStatistics () const override {}
1071+
1072+ ChangeStatus updateImpl (Attributor &A) override {
1073+ unsigned ArgNo = getAssociatedArgument ()->getArgNo ();
1074+ unsigned NumCallSites = 0 ;
1075+ unsigned NumInregCallSites = 0 ;
1076+
1077+ auto Pred = [&](AbstractCallSite ACS) -> bool {
1078+ auto *AA = A.getOrCreateAAFor <AAAMDGPUInreg>(
1079+ IRPosition::callsite_argument (*ACS.getInstruction (), ArgNo), this ,
1080+ DepClassTy::REQUIRED);
1081+ if (!AA || !AA->isValidState ())
1082+ return false ;
1083+ ++NumCallSites;
1084+ if (AA->isAssumed ())
1085+ ++NumInregCallSites;
1086+ return true ;
1087+ };
1088+
1089+ bool UsedAssumedInformation = false ;
1090+ if (!A.checkForAllCallSites (Pred, *this , /* RequireAllCallSites=*/ true ,
1091+ UsedAssumedInformation))
1092+ return indicatePessimisticFixpoint ();
1093+
1094+ if (NumCallSites == NumInregCallSites)
1095+ return ChangeStatus::UNCHANGED;
1096+
1097+ if (getAssumed () && NumInregCallSites == 0 ) {
1098+ setAssumed (false );
1099+ return ChangeStatus::CHANGED;
1100+ }
1101+
1102+ return ChangeStatus::UNCHANGED;
1103+ }
1104+ };
1105+ }
1106+
1107+ AAAMDGPUInreg &AAAMDGPUInreg::createForPosition (const IRPosition &IRP,
1108+ Attributor &A) {
1109+ switch (IRP.getPositionKind ()) {
1110+ case IRPosition::IRP_CALL_SITE_ARGUMENT:
1111+ return *new (A.Allocator ) AAAMDGPUInregCallSiteArgument (IRP, A);
1112+ case IRPosition::IRP_ARGUMENT:
1113+ return *new (A.Allocator ) AAAMDGPUInregArgument (IRP, A);
1114+ default :
1115+ llvm_unreachable (" not a valid position for AAAMDGPUInreg" );
1116+ }
1117+ }
1118+
10121119static void addPreloadKernArgHint (Function &F, TargetMachine &TM) {
10131120 const GCNSubtarget &ST = TM.getSubtarget <GCNSubtarget>(F);
10141121 for (unsigned I = 0 ;
0 commit comments