Skip to content

Commit 251e9bf

Browse files
committed
Address comments
1 parent a397bcc commit 251e9bf

File tree

3 files changed

+13
-126
lines changed

3 files changed

+13
-126
lines changed

llvm/include/llvm/CodeGen/CodeGenPassBuilder.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ template <typename DerivedT> class CodeGenPassBuilder {
187187
"Only module pass and function pass are supported.");
188188

189189
// Add Function Pass
190-
if constexpr (is_detected<is_function_pass_t, PassT>::value)
190+
if constexpr (is_detected<is_function_pass_t, PassT>::value) {
191191
FPM.addPass(std::forward<PassT>(Pass));
192-
else {
192+
} else {
193193
// Add Module Pass
194194
if (!FPM.isEmpty()) {
195195
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));

llvm/lib/Passes/PassBuilder.cpp

+2-98
Original file line numberDiff line numberDiff line change
@@ -300,109 +300,13 @@ cl::opt<bool> PrintPipelinePasses(
300300
"(best-effort only)."));
301301
} // namespace llvm
302302

303-
namespace {
304-
305-
// The following passes/analyses have custom names, otherwise their name will
306-
// include `(anonymous namespace)`. These are special since they are only for
307-
// testing purposes and don't live in a header file.
308-
309-
/// No-op module pass which does nothing.
310-
struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
311-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
312-
return PreservedAnalyses::all();
313-
}
314-
315-
static StringRef name() { return "NoOpModulePass"; }
316-
};
317-
318-
/// No-op module analysis.
319-
class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
320-
friend AnalysisInfoMixin<NoOpModuleAnalysis>;
321-
static AnalysisKey Key;
322-
323-
public:
324-
struct Result {};
325-
Result run(Module &, ModuleAnalysisManager &) { return Result(); }
326-
static StringRef name() { return "NoOpModuleAnalysis"; }
327-
};
328-
329-
/// No-op CGSCC pass which does nothing.
330-
struct NoOpCGSCCPass : PassInfoMixin<NoOpCGSCCPass> {
331-
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
332-
LazyCallGraph &, CGSCCUpdateResult &UR) {
333-
return PreservedAnalyses::all();
334-
}
335-
static StringRef name() { return "NoOpCGSCCPass"; }
336-
};
337-
338-
/// No-op CGSCC analysis.
339-
class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
340-
friend AnalysisInfoMixin<NoOpCGSCCAnalysis>;
341-
static AnalysisKey Key;
342-
343-
public:
344-
struct Result {};
345-
Result run(LazyCallGraph::SCC &, CGSCCAnalysisManager &, LazyCallGraph &G) {
346-
return Result();
347-
}
348-
static StringRef name() { return "NoOpCGSCCAnalysis"; }
349-
};
350-
351-
/// No-op function pass which does nothing.
352-
struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
353-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
354-
return PreservedAnalyses::all();
355-
}
356-
static StringRef name() { return "NoOpFunctionPass"; }
357-
};
358-
359-
/// No-op function analysis.
360-
class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
361-
friend AnalysisInfoMixin<NoOpFunctionAnalysis>;
362-
static AnalysisKey Key;
363-
364-
public:
365-
struct Result {};
366-
Result run(Function &, FunctionAnalysisManager &) { return Result(); }
367-
static StringRef name() { return "NoOpFunctionAnalysis"; }
368-
};
369-
370-
/// No-op loop nest pass which does nothing.
371-
struct NoOpLoopNestPass : PassInfoMixin<NoOpLoopNestPass> {
372-
PreservedAnalyses run(LoopNest &L, LoopAnalysisManager &,
373-
LoopStandardAnalysisResults &, LPMUpdater &) {
374-
return PreservedAnalyses::all();
375-
}
376-
static StringRef name() { return "NoOpLoopNestPass"; }
377-
};
378-
379-
/// No-op loop pass which does nothing.
380-
struct NoOpLoopPass : PassInfoMixin<NoOpLoopPass> {
381-
PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
382-
LoopStandardAnalysisResults &, LPMUpdater &) {
383-
return PreservedAnalyses::all();
384-
}
385-
static StringRef name() { return "NoOpLoopPass"; }
386-
};
387-
388-
/// No-op loop analysis.
389-
class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
390-
friend AnalysisInfoMixin<NoOpLoopAnalysis>;
391-
static AnalysisKey Key;
392-
393-
public:
394-
struct Result {};
395-
Result run(Loop &, LoopAnalysisManager &, LoopStandardAnalysisResults &) {
396-
return Result();
397-
}
398-
static StringRef name() { return "NoOpLoopAnalysis"; }
399-
};
400-
401303
AnalysisKey NoOpModuleAnalysis::Key;
402304
AnalysisKey NoOpCGSCCAnalysis::Key;
403305
AnalysisKey NoOpFunctionAnalysis::Key;
404306
AnalysisKey NoOpLoopAnalysis::Key;
405307

308+
namespace {
309+
406310
/// Whether or not we should populate a PassInstrumentationCallbacks's class to
407311
/// pass name map.
408312
///

llvm/unittests/CodeGen/CodeGenPassBuilderTest.cpp

+9-26
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@ using namespace llvm;
2323

2424
namespace {
2525

26-
struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
27-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
28-
return PreservedAnalyses::all();
29-
}
30-
31-
static StringRef name() { return "NoOpModulePass"; }
32-
};
33-
34-
struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
35-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
36-
return PreservedAnalyses::all();
37-
}
38-
static StringRef name() { return "NoOpFunctionPass"; }
39-
};
40-
4126
class DummyCodeGenPassBuilder
4227
: public CodeGenPassBuilder<DummyCodeGenPassBuilder> {
4328
public:
@@ -67,6 +52,7 @@ class CodeGenPassBuilderTest : public testing::Test {
6752
InitializeAllTargets();
6853
InitializeAllTargetMCs();
6954

55+
// TODO: Move this test to normal lit test when llc supports new pm.
7056
static const char *argv[] = {
7157
"test",
7258
"-print-pipeline-passes",
@@ -85,6 +71,8 @@ class CodeGenPassBuilderTest : public testing::Test {
8571
TargetOptions Options;
8672
TM = static_cast<LLVMTargetMachine *>(
8773
TheTarget->createTargetMachine("", "", "", Options, std::nullopt));
74+
if (!TM)
75+
GTEST_SKIP();
8876
}
8977
};
9078

@@ -118,16 +106,10 @@ TEST_F(CodeGenPassBuilderTest, basic) {
118106
return PassName.empty() ? Name : PassName;
119107
});
120108
const char ExpectedIRPipeline[] =
121-
"require<profile-summary>,require<collector-metadata>,"
122-
"PreISelIntrinsicLoweringPass,function(verify,loop-mssa(loop-reduce),"
123-
"mergeicmps,expand-memcmp,gc-lowering),shadow-stack-gc-lowering,function("
124-
"lower-constant-intrinsics,UnreachableBlockElimPass,consthoist,"
125-
"ReplaceWithVeclib,partially-inline-libcalls,ee-instrument<post-inline>,"
126-
"scalarize-masked-mem-intrin,ExpandReductionsPass,codegenprepare,"
127-
"dwarf-eh-prepare),no-op-module,function(no-op-function,no-op-function,"
128-
"no-op-function),no-op-module,function(no-op-function,callbrprepare,"
129-
"safe-stack,stack-protector,verify)";
130-
EXPECT_EQ(IRPipeline, ExpectedIRPipeline);
109+
"no-op-module,function(no-op-function,"
110+
"no-op-function,no-op-function),no-op-module";
111+
// TODO: Move this test to normal lit test when llc supports new pm.
112+
EXPECT_TRUE(StringRef(IRPipeline).contains(ExpectedIRPipeline));
131113

132114
std::string MIRPipeline;
133115
raw_string_ostream MIROS(MIRPipeline);
@@ -151,8 +133,9 @@ TEST_F(CodeGenPassBuilderTest, basic) {
151133
"FEntryInserterPass,XRayInstrumentationPass,PatchableFunctionPass,"
152134
"FuncletLayoutPass,StackMapLivenessPass,LiveDebugValuesPass,"
153135
"MachineSanitizerBinaryMetadata,FreeMachineFunctionPass";
154-
EXPECT_EQ(MIRPipeline, ExpectedMIRPipeline);
155136
// TODO: Check pipeline string when all pass names are populated.
137+
// TODO: Move this test to normal lit test when llc supports new pm.
138+
EXPECT_EQ(MIRPipeline, ExpectedMIRPipeline);
156139
}
157140

158141
} // namespace

0 commit comments

Comments
 (0)