Skip to content

Commit 37d6be9

Browse files
committed
Revert "[BranchProbability] move options for 'likely' and 'unlikely'"
Upon reviewing D98898 i've come to realization that these are implementation detail of LowerExpectIntrinsicPass, and they should not be exposed to outside of it. This reverts commit ee8b538.
1 parent bcaca36 commit 37d6be9

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
#include "llvm/IR/Intrinsics.h"
4343
#include "llvm/IR/MDBuilder.h"
4444
#include "llvm/IR/Operator.h"
45-
#include "llvm/Support/BranchProbability.h"
4645
#include "llvm/Support/CRC.h"
46+
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
4747
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
4848
using namespace clang;
4949
using namespace CodeGen;

llvm/include/llvm/Support/BranchProbability.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#ifndef LLVM_SUPPORT_BRANCHPROBABILITY_H
1414
#define LLVM_SUPPORT_BRANCHPROBABILITY_H
1515

16-
#include "llvm/Support/CommandLine.h"
1716
#include "llvm/Support/DataTypes.h"
1817
#include <algorithm>
1918
#include <cassert>
@@ -22,9 +21,6 @@
2221

2322
namespace llvm {
2423

25-
extern cl::opt<uint32_t> LikelyBranchWeight;
26-
extern cl::opt<uint32_t> UnlikelyBranchWeight;
27-
2824
class raw_ostream;
2925

3026
// This class represents Branch Probability as a non-negative fraction that is

llvm/include/llvm/Transforms/Scalar/LowerExpectIntrinsic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/IR/Function.h"
1919
#include "llvm/IR/PassManager.h"
20+
#include "llvm/Support/CommandLine.h"
2021

2122
namespace llvm {
2223

@@ -31,6 +32,8 @@ struct LowerExpectIntrinsicPass : PassInfoMixin<LowerExpectIntrinsicPass> {
3132
PreservedAnalyses run(Function &F, FunctionAnalysisManager &);
3233
};
3334

35+
extern cl::opt<uint32_t> LikelyBranchWeight;
36+
extern cl::opt<uint32_t> UnlikelyBranchWeight;
3437
}
3538

3639
#endif

llvm/lib/Support/BranchProbability.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@
1919

2020
using namespace llvm;
2121

22-
// These default values are chosen to represent an extremely skewed outcome for
23-
// a condition, but they leave some room for interpretation by later passes.
24-
//
25-
// If the documentation for __builtin_expect() was made explicit that it should
26-
// only be used in extreme cases, we could make this ratio higher. As it stands,
27-
// programmers may be using __builtin_expect() / llvm.expect to annotate that a
28-
// branch is only mildly likely or unlikely to be taken.
29-
cl::opt<uint32_t> llvm::LikelyBranchWeight(
30-
"likely-branch-weight", cl::Hidden, cl::init(2000),
31-
cl::desc("Weight of the branch likely to be taken (default = 2000)"));
32-
cl::opt<uint32_t> llvm::UnlikelyBranchWeight(
33-
"unlikely-branch-weight", cl::Hidden, cl::init(1),
34-
cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
35-
3622
constexpr uint32_t BranchProbability::D;
3723

3824
raw_ostream &BranchProbability::print(raw_ostream &OS) const {

llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "llvm/IR/Metadata.h"
2525
#include "llvm/InitializePasses.h"
2626
#include "llvm/Pass.h"
27-
#include "llvm/Support/BranchProbability.h"
2827
#include "llvm/Support/Debug.h"
2928
#include "llvm/Transforms/Scalar.h"
3029

@@ -35,6 +34,25 @@ using namespace llvm;
3534
STATISTIC(ExpectIntrinsicsHandled,
3635
"Number of 'expect' intrinsic instructions handled");
3736

37+
// These default values are chosen to represent an extremely skewed outcome for
38+
// a condition, but they leave some room for interpretation by later passes.
39+
//
40+
// If the documentation for __builtin_expect() was made explicit that it should
41+
// only be used in extreme cases, we could make this ratio higher. As it stands,
42+
// programmers may be using __builtin_expect() / llvm.expect to annotate that a
43+
// branch is likely or unlikely to be taken.
44+
//
45+
// There is a known dependency on this ratio in CodeGenPrepare when transforming
46+
// 'select' instructions. It may be worthwhile to hoist these values to some
47+
// shared space, so they can be used directly by other passes.
48+
49+
cl::opt<uint32_t> llvm::LikelyBranchWeight(
50+
"likely-branch-weight", cl::Hidden, cl::init(2000),
51+
cl::desc("Weight of the branch likely to be taken (default = 2000)"));
52+
cl::opt<uint32_t> llvm::UnlikelyBranchWeight(
53+
"unlikely-branch-weight", cl::Hidden, cl::init(1),
54+
cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
55+
3856
static std::tuple<uint32_t, uint32_t>
3957
getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount) {
4058
if (IntrinsicID == Intrinsic::expect) {

0 commit comments

Comments
 (0)