Bug Summary

File:llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
Warning:line 68, column 23
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name LowerExpectIntrinsic.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-12/lib/clang/12.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/build-llvm/lib/Transforms/Scalar -I /build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/lib/Transforms/Scalar -I /build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/build-llvm/include -I /build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-12/lib/clang/12.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/build-llvm/lib/Transforms/Scalar -fdebug-prefix-map=/build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2020-09-26-161721-17566-1 -x c++ /build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
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
13#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/Statistic.h"
16#include "llvm/ADT/iterator_range.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/IR/Metadata.h"
25#include "llvm/InitializePasses.h"
26#include "llvm/Pass.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Transforms/Scalar.h"
29#include "llvm/Transforms/Utils/MisExpect.h"
30
31using namespace llvm;
32
33#define DEBUG_TYPE"lower-expect-intrinsic" "lower-expect-intrinsic"
34
35STATISTIC(ExpectIntrinsicsHandled,static llvm::Statistic ExpectIntrinsicsHandled = {"lower-expect-intrinsic"
, "ExpectIntrinsicsHandled", "Number of 'expect' intrinsic instructions handled"
}
36 "Number of 'expect' intrinsic instructions handled")static llvm::Statistic ExpectIntrinsicsHandled = {"lower-expect-intrinsic"
, "ExpectIntrinsicsHandled", "Number of 'expect' intrinsic instructions handled"
}
;
37
38// These default values are chosen to represent an extremely skewed outcome for
39// a condition, but they leave some room for interpretation by later passes.
40//
41// If the documentation for __builtin_expect() was made explicit that it should
42// only be used in extreme cases, we could make this ratio higher. As it stands,
43// programmers may be using __builtin_expect() / llvm.expect to annotate that a
44// branch is likely or unlikely to be taken.
45//
46// There is a known dependency on this ratio in CodeGenPrepare when transforming
47// 'select' instructions. It may be worthwhile to hoist these values to some
48// shared space, so they can be used directly by other passes.
49
50cl::opt<uint32_t> llvm::LikelyBranchWeight(
51 "likely-branch-weight", cl::Hidden, cl::init(2000),
52 cl::desc("Weight of the branch likely to be taken (default = 2000)"));
53cl::opt<uint32_t> llvm::UnlikelyBranchWeight(
54 "unlikely-branch-weight", cl::Hidden, cl::init(1),
55 cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
56
57static std::tuple<uint32_t, uint32_t>
58getBranchWeight(Intrinsic::ID IntrinsicID, CallInst *CI, int BranchCount) {
59 if (IntrinsicID == Intrinsic::expect) {
16
Assuming 'IntrinsicID' is not equal to expect
17
Taking false branch
60 // __builtin_expect
61 return std::make_tuple(LikelyBranchWeight.getValue(),
62 UnlikelyBranchWeight.getValue());
63 } else {
64 // __builtin_expect_with_probability
65 assert(CI->getNumOperands() >= 3 &&((CI->getNumOperands() >= 3 && "expect with probability must have 3 arguments"
) ? static_cast<void> (0) : __assert_fail ("CI->getNumOperands() >= 3 && \"expect with probability must have 3 arguments\""
, "/build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp"
, 66, __PRETTY_FUNCTION__))
18
Assuming the condition is true
19
'?' condition is true
66 "expect with probability must have 3 arguments")((CI->getNumOperands() >= 3 && "expect with probability must have 3 arguments"
) ? static_cast<void> (0) : __assert_fail ("CI->getNumOperands() >= 3 && \"expect with probability must have 3 arguments\""
, "/build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp"
, 66, __PRETTY_FUNCTION__))
;
67 ConstantFP *Confidence = dyn_cast<ConstantFP>(CI->getArgOperand(2));
20
Assuming the object is not a 'ConstantFP'
21
'Confidence' initialized to a null pointer value
68 double TrueProb = Confidence->getValueAPF().convertToDouble();
22
Called C++ object pointer is null
69 assert((TrueProb >= 0.0 && TrueProb <= 1.0) &&(((TrueProb >= 0.0 && TrueProb <= 1.0) &&
"probability value must be in the range [0.0, 1.0]") ? static_cast
<void> (0) : __assert_fail ("(TrueProb >= 0.0 && TrueProb <= 1.0) && \"probability value must be in the range [0.0, 1.0]\""
, "/build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp"
, 70, __PRETTY_FUNCTION__))
70 "probability value must be in the range [0.0, 1.0]")(((TrueProb >= 0.0 && TrueProb <= 1.0) &&
"probability value must be in the range [0.0, 1.0]") ? static_cast
<void> (0) : __assert_fail ("(TrueProb >= 0.0 && TrueProb <= 1.0) && \"probability value must be in the range [0.0, 1.0]\""
, "/build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp"
, 70, __PRETTY_FUNCTION__))
;
71 double FalseProb = (1.0 - TrueProb) / (BranchCount - 1);
72 uint32_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX(2147483647) - 1)) + 1.0);
73 uint32_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX(2147483647) - 1)) + 1.0);
74 return std::make_tuple(LikelyBW, UnlikelyBW);
75 }
76}
77
78static bool handleSwitchExpect(SwitchInst &SI) {
79 CallInst *CI = dyn_cast<CallInst>(SI.getCondition());
80 if (!CI)
81 return false;
82
83 Function *Fn = CI->getCalledFunction();
84 if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
85 Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
86 return false;
87
88 Value *ArgValue = CI->getArgOperand(0);
89 ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(CI->getArgOperand(1));
90 if (!ExpectedValue)
91 return false;
92
93 SwitchInst::CaseHandle Case = *SI.findCaseValue(ExpectedValue);
94 unsigned n = SI.getNumCases(); // +1 for default case.
95 uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
96 std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
97 getBranchWeight(Fn->getIntrinsicID(), CI, n + 1);
98
99 SmallVector<uint32_t, 16> Weights(n + 1, UnlikelyBranchWeightVal);
100
101 uint64_t Index = (Case == *SI.case_default()) ? 0 : Case.getCaseIndex() + 1;
102 Weights[Index] = LikelyBranchWeightVal;
103
104 SI.setMetadata(LLVMContext::MD_misexpect,
105 MDBuilder(CI->getContext())
106 .createMisExpect(Index, LikelyBranchWeightVal,
107 UnlikelyBranchWeightVal));
108
109 SI.setCondition(ArgValue);
110 misexpect::checkFrontendInstrumentation(SI);
111
112 SI.setMetadata(LLVMContext::MD_prof,
113 MDBuilder(CI->getContext()).createBranchWeights(Weights));
114
115 return true;
116}
117
118/// Handler for PHINodes that define the value argument to an
119/// @llvm.expect call.
120///
121/// If the operand of the phi has a constant value and it 'contradicts'
122/// with the expected value of phi def, then the corresponding incoming
123/// edge of the phi is unlikely to be taken. Using that information,
124/// the branch probability info for the originating branch can be inferred.
125static void handlePhiDef(CallInst *Expect) {
126 Value &Arg = *Expect->getArgOperand(0);
127 ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(Expect->getArgOperand(1));
128 if (!ExpectedValue)
129 return;
130 const APInt &ExpectedPhiValue = ExpectedValue->getValue();
131
132 // Walk up in backward a list of instructions that
133 // have 'copy' semantics by 'stripping' the copies
134 // until a PHI node or an instruction of unknown kind
135 // is reached. Negation via xor is also handled.
136 //
137 // C = PHI(...);
138 // B = C;
139 // A = B;
140 // D = __builtin_expect(A, 0);
141 //
142 Value *V = &Arg;
143 SmallVector<Instruction *, 4> Operations;
144 while (!isa<PHINode>(V)) {
145 if (ZExtInst *ZExt = dyn_cast<ZExtInst>(V)) {
146 V = ZExt->getOperand(0);
147 Operations.push_back(ZExt);
148 continue;
149 }
150
151 if (SExtInst *SExt = dyn_cast<SExtInst>(V)) {
152 V = SExt->getOperand(0);
153 Operations.push_back(SExt);
154 continue;
155 }
156
157 BinaryOperator *BinOp = dyn_cast<BinaryOperator>(V);
158 if (!BinOp || BinOp->getOpcode() != Instruction::Xor)
159 return;
160
161 ConstantInt *CInt = dyn_cast<ConstantInt>(BinOp->getOperand(1));
162 if (!CInt)
163 return;
164
165 V = BinOp->getOperand(0);
166 Operations.push_back(BinOp);
167 }
168
169 // Executes the recorded operations on input 'Value'.
170 auto ApplyOperations = [&](const APInt &Value) {
171 APInt Result = Value;
172 for (auto Op : llvm::reverse(Operations)) {
173 switch (Op->getOpcode()) {
174 case Instruction::Xor:
175 Result ^= cast<ConstantInt>(Op->getOperand(1))->getValue();
176 break;
177 case Instruction::ZExt:
178 Result = Result.zext(Op->getType()->getIntegerBitWidth());
179 break;
180 case Instruction::SExt:
181 Result = Result.sext(Op->getType()->getIntegerBitWidth());
182 break;
183 default:
184 llvm_unreachable("Unexpected operation")::llvm::llvm_unreachable_internal("Unexpected operation", "/build/llvm-toolchain-snapshot-12~++20200926111128+c6c5629f2fb/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp"
, 184)
;
185 }
186 }
187 return Result;
188 };
189
190 auto *PhiDef = cast<PHINode>(V);
191
192 // Get the first dominating conditional branch of the operand
193 // i's incoming block.
194 auto GetDomConditional = [&](unsigned i) -> BranchInst * {
195 BasicBlock *BB = PhiDef->getIncomingBlock(i);
196 BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator());
197 if (BI && BI->isConditional())
198 return BI;
199 BB = BB->getSinglePredecessor();
200 if (!BB)
201 return nullptr;
202 BI = dyn_cast<BranchInst>(BB->getTerminator());
203 if (!BI || BI->isUnconditional())
204 return nullptr;
205 return BI;
206 };
207
208 // Now walk through all Phi operands to find phi oprerands with values
209 // conflicting with the expected phi output value. Any such operand
210 // indicates the incoming edge to that operand is unlikely.
211 for (unsigned i = 0, e = PhiDef->getNumIncomingValues(); i != e; ++i) {
212
213 Value *PhiOpnd = PhiDef->getIncomingValue(i);
214 ConstantInt *CI = dyn_cast<ConstantInt>(PhiOpnd);
215 if (!CI)
216 continue;
217
218 // Not an interesting case when IsUnlikely is false -- we can not infer
219 // anything useful when the operand value matches the expected phi
220 // output.
221 if (ExpectedPhiValue == ApplyOperations(CI->getValue()))
222 continue;
223
224 BranchInst *BI = GetDomConditional(i);
225 if (!BI)
226 continue;
227
228 MDBuilder MDB(PhiDef->getContext());
229
230 // There are two situations in which an operand of the PhiDef comes
231 // from a given successor of a branch instruction BI.
232 // 1) When the incoming block of the operand is the successor block;
233 // 2) When the incoming block is BI's enclosing block and the
234 // successor is the PhiDef's enclosing block.
235 //
236 // Returns true if the operand which comes from OpndIncomingBB
237 // comes from outgoing edge of BI that leads to Succ block.
238 auto *OpndIncomingBB = PhiDef->getIncomingBlock(i);
239 auto IsOpndComingFromSuccessor = [&](BasicBlock *Succ) {
240 if (OpndIncomingBB == Succ)
241 // If this successor is the incoming block for this
242 // Phi operand, then this successor does lead to the Phi.
243 return true;
244 if (OpndIncomingBB == BI->getParent() && Succ == PhiDef->getParent())
245 // Otherwise, if the edge is directly from the branch
246 // to the Phi, this successor is the one feeding this
247 // Phi operand.
248 return true;
249 return false;
250 };
251 uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
252 std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) = getBranchWeight(
253 Expect->getCalledFunction()->getIntrinsicID(), Expect, 2);
254
255 if (IsOpndComingFromSuccessor(BI->getSuccessor(1)))
256 BI->setMetadata(LLVMContext::MD_prof,
257 MDB.createBranchWeights(LikelyBranchWeightVal,
258 UnlikelyBranchWeightVal));
259 else if (IsOpndComingFromSuccessor(BI->getSuccessor(0)))
260 BI->setMetadata(LLVMContext::MD_prof,
261 MDB.createBranchWeights(UnlikelyBranchWeightVal,
262 LikelyBranchWeightVal));
263 }
264}
265
266// Handle both BranchInst and SelectInst.
267template <class BrSelInst> static bool handleBrSelExpect(BrSelInst &BSI) {
268
269 // Handle non-optimized IR code like:
270 // %expval = call i64 @llvm.expect.i64(i64 %conv1, i64 1)
271 // %tobool = icmp ne i64 %expval, 0
272 // br i1 %tobool, label %if.then, label %if.end
273 //
274 // Or the following simpler case:
275 // %expval = call i1 @llvm.expect.i1(i1 %cmp, i1 1)
276 // br i1 %expval, label %if.then, label %if.end
277
278 CallInst *CI;
279
280 ICmpInst *CmpI = dyn_cast<ICmpInst>(BSI.getCondition());
7
Assuming the object is not a 'ICmpInst'
281 CmpInst::Predicate Predicate;
282 ConstantInt *CmpConstOperand = nullptr;
283 if (!CmpI
7.1
'CmpI' is null
) {
8
Taking true branch
284 CI = dyn_cast<CallInst>(BSI.getCondition());
9
Assuming the object is a 'CallInst'
285 Predicate = CmpInst::ICMP_NE;
286 } else {
287 Predicate = CmpI->getPredicate();
288 if (Predicate != CmpInst::ICMP_NE && Predicate != CmpInst::ICMP_EQ)
289 return false;
290
291 CmpConstOperand = dyn_cast<ConstantInt>(CmpI->getOperand(1));
292 if (!CmpConstOperand)
293 return false;
294 CI = dyn_cast<CallInst>(CmpI->getOperand(0));
295 }
296
297 if (!CI
9.1
'CI' is non-null
)
10
Taking false branch
298 return false;
299
300 uint64_t ValueComparedTo = 0;
301 if (CmpConstOperand
10.1
'CmpConstOperand' is null
) {
11
Taking false branch
302 if (CmpConstOperand->getBitWidth() > 64)
303 return false;
304 ValueComparedTo = CmpConstOperand->getZExtValue();
305 }
306
307 Function *Fn = CI->getCalledFunction();
308 if (!Fn
11.1
'Fn' is non-null
|| (Fn->getIntrinsicID() != Intrinsic::expect &&
12
Assuming the condition is false
309 Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
310 return false;
311
312 Value *ArgValue = CI->getArgOperand(0);
313 ConstantInt *ExpectedValue = dyn_cast<ConstantInt>(CI->getArgOperand(1));
314 if (!ExpectedValue)
13
Assuming 'ExpectedValue' is non-null
14
Taking false branch
315 return false;
316
317 MDBuilder MDB(CI->getContext());
318 MDNode *Node;
319 MDNode *ExpNode;
320
321 uint32_t LikelyBranchWeightVal, UnlikelyBranchWeightVal;
322 std::tie(LikelyBranchWeightVal, UnlikelyBranchWeightVal) =
323 getBranchWeight(Fn->getIntrinsicID(), CI, 2);
15
Calling 'getBranchWeight'
324
325 if ((ExpectedValue->getZExtValue() == ValueComparedTo) ==
326 (Predicate == CmpInst::ICMP_EQ)) {
327 Node =
328 MDB.createBranchWeights(LikelyBranchWeightVal, UnlikelyBranchWeightVal);
329 ExpNode =
330 MDB.createMisExpect(0, LikelyBranchWeightVal, UnlikelyBranchWeightVal);
331 } else {
332 Node =
333 MDB.createBranchWeights(UnlikelyBranchWeightVal, LikelyBranchWeightVal);
334 ExpNode =
335 MDB.createMisExpect(1, LikelyBranchWeightVal, UnlikelyBranchWeightVal);
336 }
337
338 BSI.setMetadata(LLVMContext::MD_misexpect, ExpNode);
339
340 if (CmpI)
341 CmpI->setOperand(0, ArgValue);
342 else
343 BSI.setCondition(ArgValue);
344
345 misexpect::checkFrontendInstrumentation(BSI);
346
347 BSI.setMetadata(LLVMContext::MD_prof, Node);
348
349 return true;
350}
351
352static bool handleBranchExpect(BranchInst &BI) {
353 if (BI.isUnconditional())
5
Taking false branch
354 return false;
355
356 return handleBrSelExpect<BranchInst>(BI);
6
Calling 'handleBrSelExpect<llvm::BranchInst>'
357}
358
359static bool lowerExpectIntrinsic(Function &F) {
360 bool Changed = false;
361
362 for (BasicBlock &BB : F) {
363 // Create "block_weights" metadata.
364 if (BranchInst *BI
2.1
'BI' is non-null
= dyn_cast<BranchInst>(BB.getTerminator())) {
2
Assuming the object is a 'BranchInst'
3
Taking true branch
365 if (handleBranchExpect(*BI))
4
Calling 'handleBranchExpect'
366 ExpectIntrinsicsHandled++;
367 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB.getTerminator())) {
368 if (handleSwitchExpect(*SI))
369 ExpectIntrinsicsHandled++;
370 }
371
372 // Remove llvm.expect intrinsics. Iterate backwards in order
373 // to process select instructions before the intrinsic gets
374 // removed.
375 for (auto BI = BB.rbegin(), BE = BB.rend(); BI != BE;) {
376 Instruction *Inst = &*BI++;
377 CallInst *CI = dyn_cast<CallInst>(Inst);
378 if (!CI) {
379 if (SelectInst *SI = dyn_cast<SelectInst>(Inst)) {
380 if (handleBrSelExpect(*SI))
381 ExpectIntrinsicsHandled++;
382 }
383 continue;
384 }
385
386 Function *Fn = CI->getCalledFunction();
387 if (Fn && (Fn->getIntrinsicID() == Intrinsic::expect ||
388 Fn->getIntrinsicID() == Intrinsic::expect_with_probability)) {
389 // Before erasing the llvm.expect, walk backward to find
390 // phi that define llvm.expect's first arg, and
391 // infer branch probability:
392 handlePhiDef(CI);
393 Value *Exp = CI->getArgOperand(0);
394 CI->replaceAllUsesWith(Exp);
395 CI->eraseFromParent();
396 Changed = true;
397 }
398 }
399 }
400
401 return Changed;
402}
403
404PreservedAnalyses LowerExpectIntrinsicPass::run(Function &F,
405 FunctionAnalysisManager &) {
406 if (lowerExpectIntrinsic(F))
407 return PreservedAnalyses::none();
408
409 return PreservedAnalyses::all();
410}
411
412namespace {
413/// Legacy pass for lowering expect intrinsics out of the IR.
414///
415/// When this pass is run over a function it uses expect intrinsics which feed
416/// branches and switches to provide branch weight metadata for those
417/// terminators. It then removes the expect intrinsics from the IR so the rest
418/// of the optimizer can ignore them.
419class LowerExpectIntrinsic : public FunctionPass {
420public:
421 static char ID;
422 LowerExpectIntrinsic() : FunctionPass(ID) {
423 initializeLowerExpectIntrinsicPass(*PassRegistry::getPassRegistry());
424 }
425
426 bool runOnFunction(Function &F) override { return lowerExpectIntrinsic(F); }
1
Calling 'lowerExpectIntrinsic'
427};
428}
429
430char LowerExpectIntrinsic::ID = 0;
431INITIALIZE_PASS(LowerExpectIntrinsic, "lower-expect",static void *initializeLowerExpectIntrinsicPassOnce(PassRegistry
&Registry) { PassInfo *PI = new PassInfo( "Lower 'expect' Intrinsics"
, "lower-expect", &LowerExpectIntrinsic::ID, PassInfo::NormalCtor_t
(callDefaultCtor<LowerExpectIntrinsic>), false, false);
Registry.registerPass(*PI, true); return PI; } static llvm::
once_flag InitializeLowerExpectIntrinsicPassFlag; void llvm::
initializeLowerExpectIntrinsicPass(PassRegistry &Registry
) { llvm::call_once(InitializeLowerExpectIntrinsicPassFlag, initializeLowerExpectIntrinsicPassOnce
, std::ref(Registry)); }
432 "Lower 'expect' Intrinsics", false, false)static void *initializeLowerExpectIntrinsicPassOnce(PassRegistry
&Registry) { PassInfo *PI = new PassInfo( "Lower 'expect' Intrinsics"
, "lower-expect", &LowerExpectIntrinsic::ID, PassInfo::NormalCtor_t
(callDefaultCtor<LowerExpectIntrinsic>), false, false);
Registry.registerPass(*PI, true); return PI; } static llvm::
once_flag InitializeLowerExpectIntrinsicPassFlag; void llvm::
initializeLowerExpectIntrinsicPass(PassRegistry &Registry
) { llvm::call_once(InitializeLowerExpectIntrinsicPassFlag, initializeLowerExpectIntrinsicPassOnce
, std::ref(Registry)); }
433
434FunctionPass *llvm::createLowerExpectIntrinsicPass() {
435 return new LowerExpectIntrinsic();
436}