Skip to content

Commit 18a2584

Browse files
committed
Add dependency on ProfileData from ScalarOpts
1 parent f5d2843 commit 18a2584

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

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

0 commit comments

Comments
 (0)