LLVM  16.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 #include <cmath>
31 
32 using namespace llvm;
33 
34 #define DEBUG_TYPE "lower-expect-intrinsic"
35 
36 STATISTIC(ExpectIntrinsicsHandled,
37  "Number of 'expect' intrinsic instructions handled");
38 
39 // These default values are chosen to represent an extremely skewed outcome for
40 // a condition, but they leave some room for interpretation by later passes.
41 //
42 // If the documentation for __builtin_expect() was made explicit that it should
43 // only be used in extreme cases, we could make this ratio higher. As it stands,
44 // programmers may be using __builtin_expect() / llvm.expect to annotate that a
45 // branch is likely or unlikely to be taken.
46 
47 // WARNING: these values are internal implementation detail of the pass.
48 // They should not be exposed to the outside of the pass, front-end codegen
49 // should emit @llvm.expect intrinsics instead of using these weights directly.
50 // Transforms should use TargetTransformInfo's getPredictableBranchThreshold().
52  "likely-branch-weight", cl::Hidden, cl::init(2000),
53  cl::desc("Weight of the branch likely to be taken (default = 2000)"));
55  "unlikely-branch-weight", cl::Hidden, cl::init(1),
56  cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
57 
58 static std::tuple<uint32_t, uint32_t>
59 getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount) {
60  if (IntrinsicID == Intrinsic::expect) {
61  // __builtin_expect
62  return std::make_tuple(LikelyBranchWeight.getValue(),
63  UnlikelyBranchWeight.getValue());
64  } else {
65  // __builtin_expect_with_probability
66  assert(CI->getNumOperands() >= 3 &&
67  "expect with probability must have 3 arguments");
68  auto *Confidence = cast<ConstantFP>(CI->getArgOperand(2));
69  double TrueProb = Confidence->getValueAPF().convertToDouble();
70  assert((TrueProb >= 0.0 && TrueProb <= 1.0) &&
71  "probability value must be in the range [0.0, 1.0]");
72  double FalseProb = (1.0 - TrueProb) / (BranchCount - 1);
73  uint32_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX - 1)) + 1.0);
74  uint32_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX - 1)) + 1.0);
75  return std::make_tuple(LikelyBW, UnlikelyBW);
76  }
77 }
78 
80  CallInst *CI = dyn_cast<CallInst>(SI.getCondition());
81  if (!CI)
82  return false;
83 
84  Function *Fn = CI->getCalledFunction();
85  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
86  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
87  return false;
88 
89  Value *ArgValue = CI->getArgOperand(0);
90  ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(CI->getArgOperand(1));
91  if (!ExpectedValue)
92  return false;
93 
94  SwitchInst::CaseHandle Case = *SI.findCaseValue(ExpectedValue);
95  unsigned n = SI.getNumCases(); // +1 for default case.
96  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
97  std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
98  getBranchWeight(Fn->getIntrinsicID(), CI, n + 1);
99 
100  SmallVector<uint32_t, 16> Weights(n + 1, UnlikelyBranchWeightVal);
101 
102  uint64_t Index = (Case == *SI.case_default()) ? 0 : Case.getCaseIndex() + 1;
103  Weights[Index] = LikelyBranchWeightVal;
104 
105  misexpect::checkExpectAnnotations(SI, Weights, /*IsFrontend=*/true);
106 
107  SI.setCondition(ArgValue);
108 
109  SI.setMetadata(LLVMContext::MD_prof,
110  MDBuilder(CI->getContext()).createBranchWeights(Weights));
111 
112  return true;
113 }
114 
115 /// Handler for PHINodes that define the value argument to an
116 /// @llvm.expect call.
117 ///
118 /// If the operand of the phi has a constant value and it 'contradicts'
119 /// with the expected value of phi def, then the corresponding incoming
120 /// edge of the phi is unlikely to be taken. Using that information,
121 /// the branch probability info for the originating branch can be inferred.
122 static void handlePhiDef(CallInst *Expect) {
123  Value &Arg = *Expect->getArgOperand(0);
124  ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(Expect->getArgOperand(1));
125  if (!ExpectedValue)
126  return;
127  const APInt &ExpectedPhiValue = ExpectedValue->getValue();
128 
129  // Walk up in backward a list of instructions that
130  // have 'copy' semantics by 'stripping' the copies
131  // until a PHI node or an instruction of unknown kind
132  // is reached. Negation via xor is also handled.
133  //
134  // C = PHI(...);
135  // B = C;
136  // A = B;
137  // D = __builtin_expect(A, 0);
138  //
139  Value *V = &Arg;
141  while (!isa<PHINode>(V)) {
142  if (ZExtInst *ZExt = dyn_cast<ZExtInst>(V)) {
143  V = ZExt->getOperand(0);
144  Operations.push_back(ZExt);
145  continue;
146  }
147 
148  if (SExtInst *SExt = dyn_cast<SExtInst>(V)) {
149  V = SExt->getOperand(0);
150  Operations.push_back(SExt);
151  continue;
152  }
153 
154  BinaryOperator *BinOp = dyn_cast<BinaryOperator>(V);
155  if (!BinOp || BinOp->getOpcode() != Instruction::Xor)
156  return;
157 
158  ConstantInt *CInt = dyn_cast<ConstantInt>(BinOp->getOperand(1));
159  if (!CInt)
160  return;
161 
162  V = BinOp->getOperand(0);
163  Operations.push_back(BinOp);
164  }
165 
166  // Executes the recorded operations on input 'Value'.
167  auto ApplyOperations = [&](const APInt &Value) {
168  APInt Result = Value;
169  for (auto *Op : llvm::reverse(Operations)) {
170  switch (Op->getOpcode()) {
171  case Instruction::Xor:
172  Result ^= cast<ConstantInt>(Op->getOperand(1))->getValue();
173  break;
174  case Instruction::ZExt:
175  Result = Result.zext(Op->getType()->getIntegerBitWidth());
176  break;
177  case Instruction::SExt:
178  Result = Result.sext(Op->getType()->getIntegerBitWidth());
179  break;
180  default:
181  llvm_unreachable("Unexpected operation");
182  }
183  }
184  return Result;
185  };
186 
187  auto *PhiDef = cast<PHINode>(V);
188 
189  // Get the first dominating conditional branch of the operand
190  // i's incoming block.
191  auto GetDomConditional = [&](unsigned i) -> BranchInst * {
192  BasicBlock *BB = PhiDef->getIncomingBlock(i);
193  BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator());
194  if (BI && BI->isConditional())
195  return BI;
196  BB = BB->getSinglePredecessor();
197  if (!BB)
198  return nullptr;
199  BI = dyn_cast<BranchInst>(BB->getTerminator());
200  if (!BI || BI->isUnconditional())
201  return nullptr;
202  return BI;
203  };
204 
205  // Now walk through all Phi operands to find phi oprerands with values
206  // conflicting with the expected phi output value. Any such operand
207  // indicates the incoming edge to that operand is unlikely.
208  for (unsigned i = 0, e = PhiDef->getNumIncomingValues(); i != e; ++i) {
209 
210  Value *PhiOpnd = PhiDef->getIncomingValue(i);
211  ConstantInt *CI = dyn_cast<ConstantInt>(PhiOpnd);
212  if (!CI)
213  continue;
214 
215  // Not an interesting case when IsUnlikely is false -- we can not infer
216  // anything useful when the operand value matches the expected phi
217  // output.
218  if (ExpectedPhiValue == ApplyOperations(CI->getValue()))
219  continue;
220 
221  BranchInst *BI = GetDomConditional(i);
222  if (!BI)
223  continue;
224 
225  MDBuilder MDB(PhiDef->getContext());
226 
227  // There are two situations in which an operand of the PhiDef comes
228  // from a given successor of a branch instruction BI.
229  // 1) When the incoming block of the operand is the successor block;
230  // 2) When the incoming block is BI's enclosing block and the
231  // successor is the PhiDef's enclosing block.
232  //
233  // Returns true if the operand which comes from OpndIncomingBB
234  // comes from outgoing edge of BI that leads to Succ block.
235  auto *OpndIncomingBB = PhiDef->getIncomingBlock(i);
236  auto IsOpndComingFromSuccessor = [&](BasicBlock *Succ) {
237  if (OpndIncomingBB == Succ)
238  // If this successor is the incoming block for this
239  // Phi operand, then this successor does lead to the Phi.
240  return true;
241  if (OpndIncomingBB == BI->getParent() && Succ == PhiDef->getParent())
242  // Otherwise, if the edge is directly from the branch
243  // to the Phi, this successor is the one feeding this
244  // Phi operand.
245  return true;
246  return false;
247  };
248  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
249  std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) = getBranchWeight(
250  Expect->getCalledFunction()->getIntrinsicID(), Expect, 2);
251 
252  if (IsOpndComingFromSuccessor(BI->getSuccessor(1)))
253  BI->setMetadata(LLVMContext::MD_prof,
254  MDB.createBranchWeights(LikelyBranchWeightVal,
255  UnlikelyBranchWeightVal));
256  else if (IsOpndComingFromSuccessor(BI->getSuccessor(0)))
257  BI->setMetadata(LLVMContext::MD_prof,
258  MDB.createBranchWeights(UnlikelyBranchWeightVal,
259  LikelyBranchWeightVal));
260  }
261 }
262 
263 // Handle both BranchInst and SelectInst.
264 template <class BrSelInst> static bool handleBrSelExpect(BrSelInst &BSI) {
265 
266  // Handle non-optimized IR code like:
267  // %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1)
268  // %tobool = icmp ne i64 %expval, 0
269  // br i1 %tobool, label %if.then, label %if.end
270  //
271  // Or the following simpler case:
272  // %expval = call i1 @llvm.expect.i1(i1 %cmp, i1 1)
273  // br i1 %expval, label %if.then, label %if.end
274 
275  CallInst *CI;
276 
277  ICmpInst *CmpI = dyn_cast<ICmpInst>(BSI.getCondition());
279  ConstantInt *CmpConstOperand = nullptr;
280  if (!CmpI) {
281  CI = dyn_cast<CallInst>(BSI.getCondition());
283  } else {
284  Predicate = CmpI->getPredicate();
286  return false;
287 
288  CmpConstOperand = dyn_cast<ConstantInt>(CmpI->getOperand(1));
289  if (!CmpConstOperand)
290  return false;
291  CI = dyn_cast<CallInst>(CmpI->getOperand(0));
292  }
293 
294  if (!CI)
295  return false;
296 
297  uint64_t ValueComparedTo = 0;
298  if (CmpConstOperand) {
299  if (CmpConstOperand->getBitWidth() > 64)
300  return false;
301  ValueComparedTo = CmpConstOperand->getZExtValue();
302  }
303 
304  Function *Fn = CI->getCalledFunction();
305  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
306  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
307  return false;
308 
309  Value *ArgValue = CI->getArgOperand(0);
310  ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(CI->getArgOperand(1));
311  if (!ExpectedValue)
312  return false;
313 
314  MDBuilder MDB(CI->getContext());
315  MDNode *Node;
316 
317  uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
318  std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
319  getBranchWeight(Fn->getIntrinsicID(), CI, 2);
320 
321  SmallVector<uint32_t, 4> ExpectedWeights;
322  if ((ExpectedValue->getZExtValue() == ValueComparedTo) ==
324  Node =
325  MDB.createBranchWeights(LikelyBranchWeightVal, UnlikelyBranchWeightVal);
326  ExpectedWeights = {LikelyBranchWeightVal, UnlikelyBranchWeightVal};
327  } else {
328  Node =
329  MDB.createBranchWeights(UnlikelyBranchWeightVal, LikelyBranchWeightVal);
330  ExpectedWeights = {UnlikelyBranchWeightVal, LikelyBranchWeightVal};
331  }
332 
333  if (CmpI)
334  CmpI->setOperand(0, ArgValue);
335  else
336  BSI.setCondition(ArgValue);
337 
338  misexpect::checkFrontendInstrumentation(BSI, ExpectedWeights);
339 
340  BSI.setMetadata(LLVMContext::MD_prof, Node);
341 
342  return true;
343 }
344 
345 static bool handleBranchExpect(BranchInst &BI) {
346  if (BI.isUnconditional())
347  return false;
348 
349  return handleBrSelExpect<BranchInst>(BI);
350 }
351 
353  bool Changed = false;
354 
355  for (BasicBlock &BB : F) {
356  // Create "block_weights" metadata.
357  if (BranchInst *BI = dyn_cast<BranchInst>(BB.getTerminator())) {
358  if (handleBranchExpect(*BI))
359  ExpectIntrinsicsHandled++;
360  } else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB.getTerminator())) {
361  if (handleSwitchExpect(*SI))
362  ExpectIntrinsicsHandled++;
363  }
364 
365  // Remove llvm.expect intrinsics. Iterate backwards in order
366  // to process select instructions before the intrinsic gets
367  // removed.
369  CallInst *CI = dyn_cast<CallInst>(&Inst);
370  if (!CI) {
371  if (SelectInst *SI = dyn_cast<SelectInst>(&Inst)) {
372  if (handleBrSelExpect(*SI))
373  ExpectIntrinsicsHandled++;
374  }
375  continue;
376  }
377 
378  Function *Fn = CI->getCalledFunction();
379  if (Fn && (Fn->getIntrinsicID() == Intrinsic::expect ||
380  Fn->getIntrinsicID() == Intrinsic::expect_with_probability)) {
381  // Before erasing the llvm.expect, walk backward to find
382  // phi that define llvm.expect's first arg, and
383  // infer branch probability:
384  handlePhiDef(CI);
385  Value *Exp = CI->getArgOperand(0);
386  CI->replaceAllUsesWith(Exp);
387  CI->eraseFromParent();
388  Changed = true;
389  }
390  }
391  }
392 
393  return Changed;
394 }
395 
398  if (lowerExpectIntrinsic(F))
399  return PreservedAnalyses::none();
400 
401  return PreservedAnalyses::all();
402 }
403 
404 namespace {
405 /// Legacy pass for lowering expect intrinsics out of the IR.
406 ///
407 /// When this pass is run over a function it uses expect intrinsics which feed
408 /// branches and switches to provide branch weight metadata for those
409 /// terminators. It then removes the expect intrinsics from the IR so the rest
410 /// of the optimizer can ignore them.
411 class LowerExpectIntrinsic : public FunctionPass {
412 public:
413  static char ID;
414  LowerExpectIntrinsic() : FunctionPass(ID) {
416  }
417 
418  bool runOnFunction(Function &F) override { return lowerExpectIntrinsic(F); }
419 };
420 } // namespace
421 
422 char LowerExpectIntrinsic::ID = 0;
423 INITIALIZE_PASS(LowerExpectIntrinsic, "lower-expect",
424  "Lower 'expect' Intrinsics", false, false)
425 
427  return new LowerExpectIntrinsic();
428 }
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:194
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::LowerExpectIntrinsicPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Run the pass over the function.
Definition: LowerExpectIntrinsic.cpp:396
llvm::CmpInst::ICMP_EQ
@ ICMP_EQ
equal
Definition: InstrTypes.h:740
llvm::AArch64PACKey::ID
ID
Definition: AArch64BaseInfo.h:818
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:140
llvm::PreservedAnalyses::none
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
handleSwitchExpect
static bool handleSwitchExpect(SwitchInst &SI)
Definition: LowerExpectIntrinsic.cpp:79
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:1456
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:187
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:24
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
SI
@ SI
Definition: SIInstrInfo.cpp:7882
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
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:3358
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:122
BasicBlock.h
llvm::cl::opt
Definition: CommandLine.h:1412
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:81
handleBranchExpect
static bool handleBranchExpect(BranchInst &BI)
Definition: LowerExpectIntrinsic.cpp:345
llvm::ICmpInst
This instruction compares its operands according to the predicate given to the constructor.
Definition: Instructions.h:1185
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
uint64_t
MisExpect.h
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:53
llvm::createLowerExpectIntrinsicPass
FunctionPass * createLowerExpectIntrinsicPass()
handleBrSelExpect
static bool handleBrSelExpect(BrSelInst &BSI)
Definition: LowerExpectIntrinsic.cpp:264
LowerExpectIntrinsic.h
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:447
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:716
lowerExpectIntrinsic
static bool lowerExpectIntrinsic(Function &F)
Definition: LowerExpectIntrinsic.cpp:352
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:202
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)"))
llvm::SelectInst
This class represents the LLVM 'select' instruction.
Definition: Instructions.h:1736
iterator_range.h
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::BranchInst::isUnconditional
bool isUnconditional() const
Definition: Instructions.h:3211
llvm::ZExtInst
This class represents zero extension of integer types.
Definition: Instructions.h:4849
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:532
uint32_t
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
llvm::SExtInst
This class represents a sign extension of integer types.
Definition: Instructions.h:4888
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:423
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:85
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
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:36
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:3377
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
llvm::reverse
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:485
getBranchWeight
static std::tuple< uint32_t, uint32_t > getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount)
Definition: LowerExpectIntrinsic.cpp:59
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:1473
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:3277
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::cl::desc
Definition: CommandLine.h:413
llvm::BranchInst
Conditional or Unconditional Branch instruction.
Definition: Instructions.h:3133
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:3212
llvm::BranchInst::getSuccessor
BasicBlock * getSuccessor(unsigned i) const
Definition: Instructions.h:3226
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38