Skip to content

Commit a508ea2

Browse files
authored
Add dependency on ProfileData from ScalarOpts (#153651)
Fixing buildbot failures after PR #153305, e.g. https://lab.llvm.org/buildbot/#/builders/203/builds/19861 Analysis already depends on `ProfileData`, so the transitive closure of the dependencies of `ScalarOpts` doesn't change. Also avoided an extra dependency (and very unnecessary) on `Instrumentation`. The API previously used doesn't need to live in Instrumentation to begin with, but that's something to address in a follow-up.
1 parent 2912c9c commit a508ea2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

llvm/lib/Transforms/Scalar/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ add_llvm_component_library(LLVMScalarOpts
9595
Analysis
9696
Core
9797
InstCombine
98+
ProfileData
9899
Support
99100
TransformUtils
100101
)

llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/ProfileData/InstrProf.h"
2323
#include "llvm/Support/CommandLine.h"
2424
#include "llvm/Support/Error.h"
25-
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
2625
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
2726
#include <limits>
2827

@@ -181,8 +180,14 @@ expandToSwitch(CallBase *CB, const JumpTableTy &JT, DomTreeUpdater &DTU,
181180
if (HadProfile && !ProfcheckDisableMetadataFixes) {
182181
// At least one of the targets must've been taken.
183182
assert(llvm::any_of(BranchWeights, [](uint64_t V) { return V != 0; }));
184-
setProfMetadata(F.getParent(), Switch, BranchWeights,
185-
*llvm::max_element(BranchWeights));
183+
// FIXME: this duplicates logic in instrumentation. Note: since there's at
184+
// least a nonzero and these are unsigned values, it follows MaxBW != 0.
185+
uint64_t MaxBW = *llvm::max_element(BranchWeights);
186+
SmallVector<uint32_t> ScaledBranchWeights(
187+
llvm::map_range(BranchWeights, [MaxBW](uint64_t V) {
188+
return static_cast<uint32_t>(V / MaxBW);
189+
}));
190+
setBranchWeights(*Switch, ScaledBranchWeights, /*IsExpected=*/false);
186191
} else
187192
setExplicitlyUnknownBranchWeights(*Switch);
188193
if (PHI)

0 commit comments

Comments
 (0)