[pkg-d-commits] [ldc] 42/211: PGO: remove unnecessary instrumentationn BBs for switch statements in instrumentation-disabled functions.
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:08 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.1.0
in repository ldc.
commit 8d84cc7f8cec7777659efc3baba51078c0d5405f
Author: Johan Engelen <jbc.engelen at gmail.com>
Date: Tue Sep 27 12:18:10 2016 +0200
PGO: remove unnecessary instrumentationn BBs for switch statements in instrumentation-disabled functions.
---
gen/pgo.h | 4 +++
gen/statements.cpp | 14 ++++----
tests/PGO/switch_disable.d | 79 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 90 insertions(+), 7 deletions(-)
diff --git a/gen/pgo.h b/gen/pgo.h
index 0f0906c..2f5b0ea 100644
--- a/gen/pgo.h
+++ b/gen/pgo.h
@@ -42,6 +42,7 @@ class ForeachRangeStatement;
class CodeGenPGO {
public:
CodeGenPGO() {}
+ bool emitsInstrumentation() const { return false; }
bool haveRegionCounts() const { return false; }
uint64_t getCurrentRegionCount() const { return 0; }
void setCurrentRegionCount(uint64_t) {}
@@ -102,6 +103,9 @@ public:
{
}
+ /// Whether or not we emit PGO instrumentation for the current function.
+ bool emitsInstrumentation() const { return emitInstrumentation; }
+
/// Whether or not we have PGO region data for the current function. This is
/// false both when we have no data at all and when our data has been
/// discarded.
diff --git a/gen/statements.cpp b/gen/statements.cpp
index 75031ea..4595f49 100644
--- a/gen/statements.cpp
+++ b/gen/statements.cpp
@@ -955,7 +955,7 @@ public:
// statement bodies, because the counters should only count the jumps
// directly from the switch statement and not "goto default", etc.
llvm::SwitchInst *si;
- if (!global.params.genInstrProf) {
+ if (!PGO.emitsInstrumentation()) {
si = llvm::SwitchInst::Create(condVal, defaultTargetBB, caseCount,
irs->scopebb());
for (size_t i = 0; i < caseCount; ++i) {
@@ -982,11 +982,11 @@ public:
const auto cs = (*cases)[i];
const auto body = funcGen.switchTargets.get(cs);
- auto incrCaseCounter = irs->insertBBBefore(body, "incrCaseCounter");
- irs->scope() = IRScope(incrCaseCounter);
+ auto casecntr = irs->insertBBBefore(body, "casecntr");
+ irs->scope() = IRScope(casecntr);
PGO.emitCounterIncrement(cs);
- llvm::BranchInst::Create(body, incrCaseCounter);
- si->addCase(isaConstantInt(indices[i]), incrCaseCounter);
+ llvm::BranchInst::Create(body, casecntr);
+ si->addCase(isaConstantInt(indices[i]), casecntr);
}
}
@@ -1014,7 +1014,7 @@ public:
llvm::BasicBlock *nextbb = irs->insertBBBefore(endbb, "checkcase");
llvm::BranchInst::Create(nextbb, irs->scopebb());
- if (global.params.genInstrProf) {
+ if (PGO.emitsInstrumentation()) {
// Prepend extra BB to "default:" to increment profiling counter.
llvm::BasicBlock *defaultcntr =
irs->insertBBBefore(defaultTargetBB, "defaultcntr");
@@ -1034,7 +1034,7 @@ public:
// Add case counters for PGO in front of case body
const auto cs = (*cases)[i];
auto casejumptargetbb = funcGen.switchTargets.get(cs);
- if (global.params.genInstrProf) {
+ if (PGO.emitsInstrumentation()) {
llvm::BasicBlock *casecntr =
irs->insertBBBefore(casejumptargetbb, "casecntr");
auto savedbb = irs->scope();
diff --git a/tests/PGO/switch_disable.d b/tests/PGO/switch_disable.d
new file mode 100644
index 0000000..a80f285
--- /dev/null
+++ b/tests/PGO/switch_disable.d
@@ -0,0 +1,79 @@
+// Test function-level enabling/disabling of instrumentation of switch statements.
+
+// RUN: %ldc -boundscheck=off -c -output-ll -fprofile-instr-generate -of=%t.ll %s && FileCheck %s --check-prefix=PROFGEN < %t.ll
+
+extern (C): // simplify name mangling for simpler string matching
+
+// PROFGEN-LABEL: @enabled(
+int enabled(int i)
+{
+ pragma(LDC_profile_instr, true);
+
+ switch (i)
+ {
+ // PROFGEN: casecntr
+ case 1:
+ return 1;
+ // PROFGEN: casecntr
+ case 2:
+ return 2;
+ // PROFGEN: defaultcntr
+ default:
+ return 3;
+ }
+}
+
+// PROFGEN-LABEL: @disabled(
+// PROFGEN-NOT: casecntr
+// PROFGEN-NOT: defaultcntr
+int disabled(int i)
+{
+ pragma(LDC_profile_instr, false);
+
+ switch (i)
+ {
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ }
+}
+
+// PROFGEN-LABEL: @bunch_of_branches_enabled(
+int bunch_of_branches_enabled(int i, int two)
+{
+ pragma(LDC_profile_instr, true);
+
+ switch (i)
+ {
+// PROFGEN: casecntr
+ case 1:
+ return 1;
+// PROFGEN: casecntr
+ case two:
+ return 2;
+// PROFGEN: defaultcntr
+ default:
+ return 3;
+ }
+}
+
+// PROFGEN-LABEL: @bunch_of_branches_disabled(
+// PROFGEN-NOT: casecntr
+// PROFGEN-NOT: defaultcntr
+int bunch_of_branches_disabled(int i, int two)
+{
+ pragma(LDC_profile_instr, false);
+
+ switch (i)
+ {
+ case 1:
+ return 1;
+ case two:
+ return 2;
+ default:
+ return 3;
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list