LLVM  15.0.0git
LowerExpectIntrinsic.cpp
Go to the documentation of this file.
1 //===- LowerExpectIntrinsic.cpp - Lower expect intrinsic ------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass lowers the 'expect' intrinsic to LLVM metadata.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/Statistic.h"
17 #include "llvm/IR/BasicBlock.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/Intrinsics.h"
22 #include "llvm/IR/LLVMContext.h"
23 #include "llvm/IR/MDBuilder.h"
24 #include "llvm/InitializePasses.h"
25 #include "llvm/Pass.h"
27 #include "llvm/Transforms/Scalar.h"
29 
30 using namespace llvm;
31 
32 #define DEBUG_TYPE "lower-expect-intrinsic"
33 
34 STATISTIC(ExpectIntrinsicsHandled,
35  "Number of 'expect' intrinsic instructions handled");
36 
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 // WARNING: these values are internal implementation detail of the pass.
46 // They should not be exposed to the outside of the pass, front-end codegen
47 // should emit @llvm.expect intrinsics instead of using these weights directly.
48 // Transforms should use TargetTransformInfo's getPredictableBranchThreshold().
50  "likely-branch-weight", cl::Hidden, cl::init(2000),
51  cl::desc("Weight of the branch likely to be taken (default = 2000)"));
53  "unlikely-branch-weight", cl::Hidden, cl::init(1),
54  cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
55 
56 static std::tuple<uint32_t, uint32_t>
57 getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount) {
58  if (IntrinsicID == Intrinsic::expect) {
59  // __builtin_expect
60  return std::make_tuple(LikelyBranchWeight.getValue(),
61  UnlikelyBranchWeight.getValue());
62  } else {
63  // __builtin_expect_with_probability
64  assert(CI->getNumOperands() >= 3 &&
65  "expect with probability must have 3 arguments");
66  auto *Confidence = cast<ConstantFP>(CI->getArgOperand(2));
67  double TrueProb = Confidence->getValueAPF().convertToDouble();
68  assert((TrueProb >= 0.0 && TrueProb <= 1.0) &&
69  "probability value must be in the range [0.0, 1.0]");
70  double FalseProb = (1.0 - TrueProb) / (BranchCount - 1);
71  uint32_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX - 1)) + 1.0);
72  uint32_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX - 1)) + 1.0);
73  return std::make_tuple(LikelyBW, UnlikelyBW);
74  }
75 }
76 
78  CallInst *CI = dyn_cast<CallInst>(SI.getCondition());
79  if (!CI)
80  return false;
81 
82  Function *Fn = CI->getCalledFunction();
83  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
84  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
85  return false;
86 
87  Value *ArgValue = CI->getArgOperand(0);
88  ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(CI->getArgOperand(1));
89  if (!ExpectedValue)
90  return false;
91 
92  SwitchInst::CaseHandle Case = *SI.findCaseValue(ExpectedValue);
93  unsigned n = SI.getNumCases(); // +1 for default case.
94  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
95  std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
96  getBranchWeight(Fn->getIntrinsicID(), CI, n + 1);
97 
98  SmallVector<uint32_t, 16> Weights(n + 1, UnlikelyBranchWeightVal);
99 
100  uint64_t Index = (Case == *SI.case_default()) ? 0 : Case.getCaseIndex() + 1;
101  Weights[Index] = LikelyBranchWeightVal;
102 
103  misexpect::checkExpectAnnotations(SI, Weights, /*IsFrontend=*/true);
104 
105  SI.setCondition(ArgValue);
106 
107  SI.setMetadata(LLVMContext::MD_prof,
108  MDBuilder(CI->getContext()).createBranchWeights(Weights));
109 
110  return true;
111 }
112 
113 /// Handler for PHINodes that define the value argument to an
114 /// @llvm.expect call.
115 ///
116 /// If the operand of the phi has a constant value and it 'contradicts'
117 /// with the expected value of phi def, then the corresponding incoming
118 /// edge of the phi is unlikely to be taken. Using that information,
119 /// the branch probability info for the originating branch can be inferred.
120 static void handlePhiDef(CallInst *Expect) {
121  Value &Arg = *Expect->getArgOperand(0);
122  ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(Expect->getArgOperand(1));
123  if (!ExpectedValue)
124  return;
125  const APInt &ExpectedPhiValue = ExpectedValue->getValue();
126 
127  // Walk up in backward a list of instructions that
128  // have 'copy' semantics by 'stripping' the copies
129  // until a PHI node or an instruction of unknown kind
130  // is reached. Negation via xor is also handled.
131  //
132  // C = PHI(...);
133  // B = C;
134  // A = B;
135  // D = __builtin_expect(A, 0);
136  //
137  Value *V = &Arg;
139  while (!isa<PHINode>(V)) {
140  if (ZExtInst *ZExt = dyn_cast<ZExtInst>(V)) {
141  V = ZExt->getOperand(0);
142  Operations.push_back(ZExt);
143  continue;
144  }
145 
146  if (SExtInst *SExt = dyn_cast<SExtInst>(V)) {
147  V = SExt->getOperand(0);
148  Operations.push_back(SExt);
149  continue;
150  }
151 
152  BinaryOperator *BinOp = dyn_cast<BinaryOperator>(V);
153  if (!BinOp || BinOp->getOpcode() != Instruction::Xor)
154  return;
155 
156  ConstantInt *CInt = dyn_cast<ConstantInt>(BinOp->getOperand(1));
157  if (!CInt)
158  return;
159 
160  V = BinOp->getOperand(0);
161  Operations.push_back(BinOp);
162  }
163 
164  // Executes the recorded operations on input 'Value'.
165  auto ApplyOperations = [&](const APInt &Value) {
166  APInt Result = Value;
167  for (auto Op : llvm::reverse(Operations)) {
168  switch (Op->getOpcode()) {
169  case Instruction::Xor:
170  Result ^= cast<ConstantInt>(Op->getOperand(1))->getValue();
171  break;
172  case Instruction::ZExt:
173  Result = Result.zext(Op->getType()->getIntegerBitWidth());
174  break;
175  case Instruction::SExt:
176  Result = Result.sext(Op->getType()->getIntegerBitWidth());
177  break;
178  default:
179  llvm_unreachable("Unexpected operation");
180  }
181  }
182  return Result;
183  };
184 
185  auto *PhiDef = cast<PHINode>(V);
186 
187  // Get the first dominating conditional branch of the operand
188  // i's incoming block.
189  auto GetDomConditional = [&](unsigned i) -> BranchInst * {
190  BasicBlock *BB = PhiDef->getIncomingBlock(i);
191  BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator());
192  if (BI && BI->isConditional())
193  return BI;
194  BB = BB->getSinglePredecessor();
195  if (!BB)
196  return nullptr;
197  BI = dyn_cast<BranchInst>(BB->getTerminator());
198  if (!BI || BI->isUnconditional())
199  return nullptr;
200  return BI;
201  };
202 
203  // Now walk through all Phi operands to find phi oprerands with values
204  // conflicting with the expected phi output value. Any such operand
205  // indicates the incoming edge to that operand is unlikely.
206  for (unsigned i = 0, e = PhiDef->getNumIncomingValues(); i != e; ++i) {
207 
208  Value *PhiOpnd = PhiDef->getIncomingValue(i);
209  ConstantInt *CI = dyn_cast<ConstantInt>(PhiOpnd);
210  if (!CI)
211  continue;
212 
213  // Not an interesting case when IsUnlikely is false -- we can not infer
214  // anything useful when the operand value matches the expected phi
215  // output.
216  if (ExpectedPhiValue == ApplyOperations(CI->getValue()))
217  continue;
218 
219  BranchInst *BI = GetDomConditional(i);
220  if (!BI)
221  continue;
222 
223  MDBuilder MDB(PhiDef->getContext());
224 
225  // There are two situations in which an operand of the PhiDef comes
226  // from a given successor of a branch instruction BI.
227  // 1) When the incoming block of the operand is the successor block;
228  // 2) When the incoming block is BI's enclosing block and the
229  // successor is the PhiDef's enclosing block.
230  //
231  // Returns true if the operand which comes from OpndIncomingBB
232  // comes from outgoing edge of BI that leads to Succ block.
233  auto *OpndIncomingBB = PhiDef->getIncomingBlock(i);
234  auto IsOpndComingFromSuccessor = [&](BasicBlock *Succ) {
235  if (OpndIncomingBB == Succ)
236  // If this successor is the incoming block for this
237  // Phi operand, then this successor does lead to the Phi.
238  return true;
239  if (OpndIncomingBB == BI->getParent() && Succ == PhiDef->getParent())
240  // Otherwise, if the edge is directly from the branch
241  // to the Phi, this successor is the one feeding this
242  // Phi operand.
243  return true;
244  return false;
245  };
246  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
247  std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) = getBranchWeight(
248  Expect->getCalledFunction()->getIntrinsicID(), Expect, 2);
249 
250  if (IsOpndComingFromSuccessor(BI->getSuccessor(1)))
251  BI->setMetadata(LLVMContext::MD_prof,
252  MDB.createBranchWeights(LikelyBranchWeightVal,
253  UnlikelyBranchWeightVal));
254  else if (IsOpndComingFromSuccessor(BI->getSuccessor(0)))
255  BI->setMetadata(LLVMContext::MD_prof,
256  MDB.createBranchWeights(UnlikelyBranchWeightVal,
257  LikelyBranchWeightVal));
258  }
259 }
260 
261 // Handle both BranchInst and SelectInst.
262 template <class BrSelInst> static bool handleBrSelExpect(BrSelInst &BSI) {
263 
264  // Handle non-optimized IR code like:
265  // %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1)
266  // %tobool = icmp ne i64 %expval, 0
267  // br i1 %tobool, label %if.then, label %if.end
268  //
269  // Or the following simpler case:
270  // %expval = call i1 @llvm.expect.i1(i1 %cmp, i1 1)
271  // br i1 %expval, label %if.then, label %if.end
272 
273  CallInst *CI;
274 
275  ICmpInst *CmpI = dyn_cast<ICmpInst>(BSI.getCondition());
277  ConstantInt *CmpConstOperand = nullptr;
278  if (!CmpI) {
279  CI = dyn_cast<CallInst>(BSI.getCondition());
281  } else {
282  Predicate = CmpI->getPredicate();
284  return false;
285 
286  CmpConstOperand = dyn_cast<ConstantInt>(CmpI->getOperand(1));
287  if (!CmpConstOperand)
288  return false;
289  CI = dyn_cast<CallInst>(CmpI->getOperand(0));
290  }
291 
292  if (!CI)
293  return false;
294 
295  uint64_t ValueComparedTo = 0;
296  if (CmpConstOperand) {
297  if (CmpConstOperand->getBitWidth() > 64)
298  return false;
299  ValueComparedTo = CmpConstOperand->getZExtValue();
300  }
301 
302  Function *Fn = CI->getCalledFunction();
303  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
304  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
305  return false;
306 
307  Value *ArgValue = CI->getArgOperand(0);
308  ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(CI->getArgOperand(1));
309  if (!ExpectedValue)
310  return false;
311 
312  MDBuilder MDB(CI->getContext());
313  MDNode *Node;
314 
315  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
316  std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
317  getBranchWeight(Fn->getIntrinsicID(), CI, 2);
318 
319  SmallVector<uint32_t, 4> ExpectedWeights;
320  if ((ExpectedValue->getZExtValue() == ValueComparedTo) ==
322  Node =
323  MDB.createBranchWeights(LikelyBranchWeightVal, UnlikelyBranchWeightVal);
324  ExpectedWeights = {LikelyBranchWeightVal, UnlikelyBranchWeightVal};
325  } else {
326  Node =
327  MDB.createBranchWeights(UnlikelyBranchWeightVal, LikelyBranchWeightVal);
328  ExpectedWeights = {UnlikelyBranchWeightVal, LikelyBranchWeightVal};
329  }
330 
331  if (CmpI)
332  CmpI->setOperand(0, ArgValue);
333  else
334  BSI.setCondition(ArgValue);
335 
336  misexpect::checkFrontendInstrumentation(BSI, ExpectedWeights);
337 
338  BSI.setMetadata(LLVMContext::MD_prof, Node);
339 
340  return true;
341 }
342 
343 static bool handleBranchExpect(BranchInst &BI) {
344  if (BI.isUnconditional())
345  return false;
346 
347  return handleBrSelExpect<BranchInst>(BI);
348 }
349 
351  bool Changed = false;
352 
353  for (BasicBlock &BB : F) {
354  // Create "block_weights" metadata.
355  if (BranchInst *BI = dyn_cast<BranchInst>(BB.getTerminator())) {
356  if (handleBranchExpect(*BI))
357  ExpectIntrinsicsHandled++;
358  } else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB.getTerminator())) {
359  if (handleSwitchExpect(*SI))
360  ExpectIntrinsicsHandled++;
361  }
362 
363  // Remove llvm.expect intrinsics. Iterate backwards in order
364  // to process select instructions before the intrinsic gets
365  // removed.
367  CallInst *CI = dyn_cast<CallInst>(&Inst);
368  if (!CI) {
369  if (SelectInst *SI = dyn_cast<SelectInst>(&Inst)) {
370  if (handleBrSelExpect(*SI))
371  ExpectIntrinsicsHandled++;
372  }
373  continue;
374  }
375 
376  Function *Fn = CI->getCalledFunction();
377  if (Fn && (Fn->getIntrinsicID() == Intrinsic::expect ||
378  Fn->getIntrinsicID() == Intrinsic::expect_with_probability)) {
379  // Before erasing the llvm.expect, walk backward to find
380  // phi that define llvm.expect's first arg, and
381  // infer branch probability:
382  handlePhiDef(CI);
383  Value *Exp = CI->getArgOperand(0);
384  CI->replaceAllUsesWith(Exp);
385  CI->eraseFromParent();
386  Changed = true;
387  }
388  }
389  }
390 
391  return Changed;
392 }
393 
396  if (lowerExpectIntrinsic(F))
397  return PreservedAnalyses::none();
398 
399  return PreservedAnalyses::all();
400 }
401 
402 namespace {
403 /// Legacy pass for lowering expect intrinsics out of the IR.
404 ///
405 /// When this pass is run over a function it uses expect intrinsics which feed
406 /// branches and switches to provide branch weight metadata for those
407 /// terminators. It then removes the expect intrinsics from the IR so the rest
408 /// of the optimizer can ignore them.
409 class LowerExpectIntrinsic : public FunctionPass {
410 public:
411  static char ID;
412  LowerExpectIntrinsic() : FunctionPass(ID) {
414  }
415 
416  bool runOnFunction(Function &F) override { return lowerExpectIntrinsic(F); }
417 };
418 } // namespace
419 
420 char LowerExpectIntrinsic::ID = 0;
421 INITIALIZE_PASS(LowerExpectIntrinsic, "lower-expect",
422  "Lower 'expect' Intrinsics", false, false)
423 
425  return new LowerExpectIntrinsic();
426 }
i
i
Definition: README.txt:29
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm::misexpect::checkFrontendInstrumentation
void checkFrontendInstrumentation(Instruction &I, const ArrayRef< uint32_t > ExpectedWeights)
checkFrontendInstrumentation - compares PGO counters to the thresholds used for llvm....
Definition: MisExpect.cpp:228
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::LowerExpectIntrinsicPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Run the pass over the function.
Definition: LowerExpectIntrinsic.cpp:394
llvm::CmpInst::ICMP_EQ
@ ICMP_EQ
equal
Definition: InstrTypes.h:740
llvm::CmpInst::Predicate
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:719
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:104
ceil
We have fiadd patterns now but the followings have the same cost and complexity We need a way to specify the later is more profitable def def The FP stackifier should handle simple permutates to reduce number of shuffle e g ceil
Definition: README-FPStack.txt:54
llvm::ConstantInt::getBitWidth
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
Definition: Constants.h:136
Scalar.h
llvm::Function
Definition: Function.h:60
Pass.h
llvm::ConstantInt::getValue
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:133
llvm::SmallVector< uint32_t, 16 >
Statistic.h
llvm::initializeLowerExpectIntrinsicPass
void initializeLowerExpectIntrinsicPass(PassRegistry &)
llvm::CmpInst::ICMP_NE
@ ICMP_NE
not equal
Definition: InstrTypes.h:741
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:139
llvm::PreservedAnalyses::none
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:380
handleSwitchExpect
static bool handleSwitchExpect(SwitchInst &SI)
Definition: LowerExpectIntrinsic.cpp:77
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Instruction::setMetadata
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Definition: Metadata.cpp:1368
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
UnlikelyBranchWeight
static cl::opt< uint32_t > UnlikelyBranchWeight("unlikely-branch-weight", cl::Hidden, cl::init(1), cl::desc("Weight of the branch unlikely to be taken (default = 1)"))
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
CommandLine.h
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition: Constants.h:79
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
Constants.h
Intrinsics.h
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1396
llvm::MDBuilder::createBranchWeights
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
Definition: MDBuilder.cpp:37
llvm::BinaryOperator::getOpcode
BinaryOps getOpcode() const
Definition: InstrTypes.h:392
llvm::Instruction
Definition: Instruction.h:42
MDBuilder.h
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::SwitchInst::CaseHandleImpl::getCaseIndex
unsigned getCaseIndex() const
Returns number of current case.
Definition: Instructions.h:3324
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
handlePhiDef
static void handlePhiDef(CallInst *Expect)
Handler for PHINodes that define the value argument to an @llvm.expect call.
Definition: LowerExpectIntrinsic.cpp:120
BasicBlock.h
llvm::cl::opt
Definition: CommandLine.h:1392
llvm::PPC::Predicate
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Definition: PPCPredicates.h:26
llvm::Instruction::eraseFromParent
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:77
handleBranchExpect
static bool handleBranchExpect(BranchInst &BI)
Definition: LowerExpectIntrinsic.cpp:343
llvm::ICmpInst
This instruction compares its operands according to the predicate given to the constructor.
Definition: Instructions.h:1186
uint64_t
MisExpect.h
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::createLowerExpectIntrinsicPass
FunctionPass * createLowerExpectIntrinsicPass()
handleBrSelExpect
static bool handleBrSelExpect(BrSelInst &BSI)
Definition: LowerExpectIntrinsic.cpp:262
LowerExpectIntrinsic.h
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
llvm::make_early_inc_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:608
lowerExpectIntrinsic
static bool lowerExpectIntrinsic(Function &F)
Definition: LowerExpectIntrinsic.cpp:350
llvm::misexpect::checkExpectAnnotations
void checkExpectAnnotations(Instruction &I, const ArrayRef< uint32_t > ExistingWeights, bool IsFrontend)
checkExpectAnnotations - compares PGO counters to the thresholds used for llvm.expect and warns if th...
Definition: MisExpect.cpp:237
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LikelyBranchWeight
static cl::opt< uint32_t > LikelyBranchWeight("likely-branch-weight", cl::Hidden, cl::init(2000), cl::desc("Weight of the branch likely to be taken (default = 2000)"))
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::SelectInst
This class represents the LLVM 'select' instruction.
Definition: Instructions.h:1737
iterator_range.h
llvm::MDNode
Metadata node.
Definition: Metadata.h:926
llvm::BranchInst::isUnconditional
bool isUnconditional() const
Definition: Instructions.h:3177
llvm::ZExtInst
This class represents zero extension of integer types.
Definition: Instructions.h:4819
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::User::setOperand
void setOperand(unsigned i, Value *Val)
Definition: User.h:174
llvm::Function::getIntrinsicID
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Definition: Function.h:205
llvm::BinaryOperator
Definition: InstrTypes.h:188
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:529
uint32_t
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:991
llvm::SExtInst
This class represents a sign extension of integer types.
Definition: Instructions.h:4858
llvm::ConstantInt::getZExtValue
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:142
INITIALIZE_PASS
INITIALIZE_PASS(LowerExpectIntrinsic, "lower-expect", "Lower 'expect' Intrinsics", false, false) FunctionPass *llvm
Definition: LowerExpectIntrinsic.cpp:421
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:69
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:326
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
Function.h
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::MDBuilder
Definition: MDBuilder.h:35
Instructions.h
llvm::User::getNumOperands
unsigned getNumOperands() const
Definition: User.h:191
SmallVector.h
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1341
llvm::SwitchInst::CaseHandle
Definition: Instructions.h:3343
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:91
llvm::CmpInst::getPredicate
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:809
getBranchWeight
static std::tuple< uint32_t, uint32_t > getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount)
Definition: LowerExpectIntrinsic.cpp:57
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
LLVMContext.h
llvm::SwitchInst
Multiway switch.
Definition: Instructions.h:3243
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::cl::desc
Definition: CommandLine.h:405
llvm::BranchInst
Conditional or Unconditional Branch instruction.
Definition: Instructions.h:3099
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
InitializePasses.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::BranchInst::isConditional
bool isConditional() const
Definition: Instructions.h:3178
llvm::BranchInst::getSuccessor
BasicBlock * getSuccessor(unsigned i) const
Definition: Instructions.h:3192
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37