Skip to content

Commit ac1b079

Browse files
committed
[AMDGPU] Always Inline preserved analyses
When replacing all uses, the structural-hash of the IR can change, so keep track of changes using Preserved variable and return the correct IR state (changed or not).
1 parent 10ec0d2 commit ac1b079

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AMDGPUAlwaysInline : public ModulePass {
4242

4343
void getAnalysisUsage(AnalysisUsage &AU) const override {
4444
AU.setPreservesAll();
45-
}
45+
}
4646
};
4747

4848
} // End anonymous namespace
@@ -54,7 +54,8 @@ char AMDGPUAlwaysInline::ID = 0;
5454

5555
static void
5656
recursivelyVisitUsers(GlobalValue &GV,
57-
SmallPtrSetImpl<Function *> &FuncsToAlwaysInline) {
57+
SmallPtrSetImpl<Function *> &FuncsToAlwaysInline,
58+
bool &Preserved) {
5859
SmallVector<User *, 16> Stack(GV.users());
5960

6061
SmallPtrSet<const Value *, 8> Visited;
@@ -73,6 +74,7 @@ recursivelyVisitUsers(GlobalValue &GV,
7374
// Unfortunately, clang adds noinline to all functions at -O0. We have
7475
// to override this here until that's fixed.
7576
F->removeFnAttr(Attribute::NoInline);
77+
Preserved = false;
7678

7779
FuncsToAlwaysInline.insert(F);
7880
Stack.push_back(F);
@@ -89,6 +91,7 @@ recursivelyVisitUsers(GlobalValue &GV,
8991
static bool alwaysInlineImpl(Module &M, bool GlobalOpt) {
9092
std::vector<GlobalAlias*> AliasesToRemove;
9193

94+
bool Preserved = true;
9295
SmallPtrSet<Function *, 8> FuncsToAlwaysInline;
9396
SmallPtrSet<Function *, 8> FuncsToNoInline;
9497
Triple TT(M.getTargetTriple());
@@ -98,6 +101,7 @@ static bool alwaysInlineImpl(Module &M, bool GlobalOpt) {
98101
if (TT.getArch() == Triple::amdgcn &&
99102
A.getLinkage() != GlobalValue::InternalLinkage)
100103
continue;
104+
Preserved = false;
101105
A.replaceAllUsesWith(F);
102106
AliasesToRemove.push_back(&A);
103107
}
@@ -128,7 +132,7 @@ static bool alwaysInlineImpl(Module &M, bool GlobalOpt) {
128132
if ((AS == AMDGPUAS::REGION_ADDRESS) ||
129133
(AS == AMDGPUAS::LOCAL_ADDRESS &&
130134
(!AMDGPUTargetMachine::EnableLowerModuleLDS)))
131-
recursivelyVisitUsers(GV, FuncsToAlwaysInline);
135+
recursivelyVisitUsers(GV, FuncsToAlwaysInline, Preserved);
132136
}
133137

134138
if (!AMDGPUTargetMachine::EnableFunctionCalls || StressCalls) {
@@ -153,7 +157,7 @@ static bool alwaysInlineImpl(Module &M, bool GlobalOpt) {
153157
for (Function *F : FuncsToNoInline)
154158
F->addFnAttr(Attribute::NoInline);
155159

156-
return !FuncsToAlwaysInline.empty() || !FuncsToNoInline.empty();
160+
return !Preserved || !FuncsToAlwaysInline.empty() || !FuncsToNoInline.empty();
157161
}
158162

159163
bool AMDGPUAlwaysInline::runOnModule(Module &M) {
@@ -166,6 +170,6 @@ ModulePass *llvm::createAMDGPUAlwaysInlinePass(bool GlobalOpt) {
166170

167171
PreservedAnalyses AMDGPUAlwaysInlinePass::run(Module &M,
168172
ModuleAnalysisManager &AM) {
169-
alwaysInlineImpl(M, GlobalOpt);
170-
return PreservedAnalyses::all();
173+
const bool Changed = alwaysInlineImpl(M, GlobalOpt);
174+
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
171175
}

0 commit comments

Comments
 (0)