Skip to content

Commit e36b22f

Browse files
author
Howard Roark
committed
Revert "[PGO] Preserve analysis results when nothing was instrumented (#93421)"
This reverts commit 23c64be.
1 parent 732b804 commit e36b22f

File tree

2 files changed

+19
-53
lines changed

2 files changed

+19
-53
lines changed

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,7 +1916,6 @@ static bool InstrumentAllFunctions(
19161916
std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
19171917
collectComdatMembers(M, ComdatMembers);
19181918

1919-
bool AnythingInstrumented = false;
19201919
for (auto &F : M) {
19211920
if (skipPGOGen(F))
19221921
continue;
@@ -1926,9 +1925,8 @@ static bool InstrumentAllFunctions(
19261925
FunctionInstrumenter FI(M, F, TLI, ComdatMembers, BPI, BFI,
19271926
InstrumentationType);
19281927
FI.instrument();
1929-
AnythingInstrumented = true;
19301928
}
1931-
return AnythingInstrumented;
1929+
return true;
19321930
}
19331931

19341932
PreservedAnalyses

llvm/unittests/Transforms/Instrumentation/PGOInstrumentationTest.cpp

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,9 @@ class MockModuleAnalysisHandle
103103
ModuleAnalysisManager::Invalidator &));
104104
};
105105

106-
template <typename ParamType> struct PGOTestName {
107-
std::string operator()(const TestParamInfo<ParamType> &Info) const {
108-
return std::get<1>(Info.param).str();
109-
}
110-
};
111-
112-
struct PGOInstrumentationGenTest : public Test {
106+
struct PGOInstrumentationGenTest
107+
: public Test,
108+
WithParamInterface<std::tuple<StringRef, StringRef>> {
113109
ModulePassManager MPM;
114110
PassBuilder PB;
115111
MockModuleAnalysisHandle MMAHandle;
@@ -145,47 +141,12 @@ struct PGOInstrumentationGenTest : public Test {
145141
}
146142
};
147143

148-
struct PGOInstrumentationGenInstrumentTest
149-
: PGOInstrumentationGenTest,
150-
WithParamInterface<std::tuple<StringRef, StringRef>> {};
151-
152144
static constexpr StringRef CodeWithFuncDefs = R"(
153145
define i32 @f(i32 %n) {
154146
entry:
155147
ret i32 0
156148
})";
157149

158-
INSTANTIATE_TEST_SUITE_P(
159-
PGOInstrumetationGenTestSuite, PGOInstrumentationGenInstrumentTest,
160-
Values(std::make_tuple(CodeWithFuncDefs, "instrument_function_defs")),
161-
PGOTestName<PGOInstrumentationGenInstrumentTest::ParamType>());
162-
163-
TEST_P(PGOInstrumentationGenInstrumentTest, Instrumented) {
164-
const StringRef Code = std::get<0>(GetParam());
165-
parseAssembly(Code);
166-
167-
ASSERT_THAT(M, NotNull());
168-
169-
Sequence PassSequence;
170-
EXPECT_CALL(MMAHandle, run(Ref(*M), _))
171-
.InSequence(PassSequence)
172-
.WillOnce(DoDefault());
173-
EXPECT_CALL(MMAHandle, invalidate(Ref(*M), _, _))
174-
.InSequence(PassSequence)
175-
.WillOnce(DoDefault());
176-
177-
MPM.run(*M, MAM);
178-
179-
const auto *IRInstrVar =
180-
M->getNamedGlobal(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
181-
ASSERT_THAT(IRInstrVar, NotNull());
182-
EXPECT_FALSE(IRInstrVar->isDeclaration());
183-
}
184-
185-
struct PGOInstrumentationGenIgnoreTest
186-
: PGOInstrumentationGenTest,
187-
WithParamInterface<std::tuple<StringRef, StringRef>> {};
188-
189150
static constexpr StringRef CodeWithFuncDecls = R"(
190151
declare i32 @f(i32);
191152
)";
@@ -196,26 +157,33 @@ static constexpr StringRef CodeWithGlobals = R"(
196157
)";
197158

198159
INSTANTIATE_TEST_SUITE_P(
199-
PGOInstrumetationGenIgnoreTestSuite, PGOInstrumentationGenIgnoreTest,
200-
Values(std::make_tuple(CodeWithFuncDecls, "instrument_function_decls"),
160+
PGOInstrumetationGenTestSuite, PGOInstrumentationGenTest,
161+
Values(std::make_tuple(CodeWithFuncDefs, "instrument_function_defs"),
162+
std::make_tuple(CodeWithFuncDecls, "instrument_function_decls"),
201163
std::make_tuple(CodeWithGlobals, "instrument_globals")),
202-
PGOTestName<PGOInstrumentationGenIgnoreTest::ParamType>());
164+
[](const TestParamInfo<PGOInstrumentationGenTest::ParamType> &Info) {
165+
return std::get<1>(Info.param).str();
166+
});
203167

204-
TEST_P(PGOInstrumentationGenIgnoreTest, NotInstrumented) {
168+
TEST_P(PGOInstrumentationGenTest, Instrumented) {
205169
const StringRef Code = std::get<0>(GetParam());
206-
207170
parseAssembly(Code);
208171

209172
ASSERT_THAT(M, NotNull());
210173

211-
EXPECT_CALL(MMAHandle, run(Ref(*M), _)).WillOnce(DoDefault());
212-
EXPECT_CALL(MMAHandle, invalidate(Ref(*M), _, _)).Times(0);
174+
Sequence PassSequence;
175+
EXPECT_CALL(MMAHandle, run(Ref(*M), _))
176+
.InSequence(PassSequence)
177+
.WillOnce(DoDefault());
178+
EXPECT_CALL(MMAHandle, invalidate(Ref(*M), _, _))
179+
.InSequence(PassSequence)
180+
.WillOnce(DoDefault());
213181

214182
MPM.run(*M, MAM);
215183

216184
const auto *IRInstrVar =
217185
M->getNamedGlobal(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
218-
ASSERT_THAT(IRInstrVar, NotNull());
186+
EXPECT_THAT(IRInstrVar, NotNull());
219187
EXPECT_FALSE(IRInstrVar->isDeclaration());
220188
}
221189

0 commit comments

Comments
 (0)