Skip to content

Add dependency on ProfileData from ScalarOpts #153651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/lib/Transforms/Scalar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ add_llvm_component_library(LLVMScalarOpts
Analysis
Core
InstCombine
ProfileData
Support
TransformUtils
)
11 changes: 8 additions & 3 deletions llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include <limits>

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