Skip to content

Commit 6e56c35

Browse files
committed
[SpeculativeExecution] Add only-if-divergent-target pass option
The optimization pipeline enables this option, but it was not preserved in -print-pipeline-passes output.
1 parent 6b43764 commit 6e56c35

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

llvm/include/llvm/Transforms/Scalar/SpeculativeExecution.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class SpeculativeExecutionPass
7373

7474
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
7575

76+
void printPipeline(raw_ostream &OS,
77+
function_ref<StringRef(StringRef)> MapClassName2PassName);
78+
7679
// Glue for old PM
7780
bool runImpl(Function &F, TargetTransformInfo *TTI);
7881

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,11 @@ Expected<bool> parseMemorySSAPrinterPassOptions(StringRef Params) {
10821082
"MemorySSAPrinterPass");
10831083
}
10841084

1085+
Expected<bool> parseSpeculativeExecutionPassOptions(StringRef Params) {
1086+
return parseSinglePassOption(Params, "only-if-divergent-target",
1087+
"SpeculativeExecutionPass");
1088+
}
1089+
10851090
Expected<std::string> parseMemProfUsePassOptions(StringRef Params) {
10861091
std::string Result;
10871092
while (!Params.empty()) {

llvm/lib/Passes/PassRegistry.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ FUNCTION_PASS("sccp", SCCPPass())
424424
FUNCTION_PASS("sink", SinkingPass())
425425
FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
426426
FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
427-
FUNCTION_PASS("speculative-execution", SpeculativeExecutionPass())
428427
FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
429428
FUNCTION_PASS("structurizecfg", StructurizeCFGPass())
430429
FUNCTION_PASS("tailcallelim", TailCallElimPass())
@@ -588,6 +587,13 @@ FUNCTION_PASS_WITH_PARAMS("print<memoryssa>",
588587
},
589588
parseMemorySSAPrinterPassOptions,
590589
"no-ensure-optimized-uses")
590+
FUNCTION_PASS_WITH_PARAMS("speculative-execution",
591+
"SpeculativeExecutionPass",
592+
[](bool OnlyIfDivergentTarget) {
593+
return SpeculativeExecutionPass(OnlyIfDivergentTarget);
594+
},
595+
parseSpeculativeExecutionPassOptions,
596+
"only-if-divergent-target")
591597
#undef FUNCTION_PASS_WITH_PARAMS
592598

593599
#ifndef LOOPNEST_PASS

llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,14 @@ PreservedAnalyses SpeculativeExecutionPass::run(Function &F,
346346
PA.preserveSet<CFGAnalyses>();
347347
return PA;
348348
}
349+
350+
void SpeculativeExecutionPass::printPipeline(
351+
raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) {
352+
static_cast<PassInfoMixin<SpeculativeExecutionPass> *>(this)->printPipeline(
353+
OS, MapClassName2PassName);
354+
OS << '<';
355+
if (OnlyIfDivergentTarget)
356+
OS << "only-if-divergent-target";
357+
OS << '>';
358+
}
349359
} // namespace llvm

llvm/test/CodeGen/NVPTX/speculative-execution-divergent-target.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
; RUN: opt < %s -S -mtriple=nvptx-nvidia-cuda -passes=speculative-execution \
77
; RUN: -spec-exec-only-if-divergent-target | \
88
; RUN: FileCheck --check-prefix=ON %s
9+
; RUN: opt < %s -S -mtriple=nvptx-nvidia-cuda \
10+
; RUN: -passes='speculative-execution<only-if-divergent-target>' | \
11+
; RUN: FileCheck --check-prefix=ON %s
912
; RUN: opt < %s -S -passes=speculative-execution -spec-exec-only-if-divergent-target | \
1013
; RUN: FileCheck --check-prefix=OFF %s
14+
; RUN: opt < %s -S -passes='speculative-execution<only-if-divergent-target>' | \
15+
; RUN: FileCheck --check-prefix=OFF %s
1116

1217
; Hoist in if-then pattern.
1318
define void @f() {

llvm/test/Other/new-pm-print-pipeline.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,6 @@
120120

121121
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='globaldce<vfe-linkage-unit-visibility>' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-35
122122
; CHECK-35: globaldce<vfe-linkage-unit-visibility>
123+
124+
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='speculative-execution<only-if-divergent-target>' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-36
125+
; CHECK-36: function(speculative-execution<only-if-divergent-target>)

0 commit comments

Comments
 (0)