LLVM 17.0.0git
LibCallsShrinkWrap.cpp
Go to the documentation of this file.
1//===-- LibCallsShrinkWrap.cpp ----------------------------------*- C++ -*-===//
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 shrink-wraps a call to function if the result is not used.
10// The call can set errno but is otherwise side effect free. For example:
11// sqrt(val);
12// is transformed to
13// if (val < 0)
14// sqrt(val);
15// Even if the result of library call is not being used, the compiler cannot
16// safely delete the call because the function can set errno on error
17// conditions.
18// Note in many functions, the error condition solely depends on the incoming
19// parameter. In this optimization, we can generate the condition can lead to
20// the errno to shrink-wrap the call. Since the chances of hitting the error
21// condition is low, the runtime call is effectively eliminated.
22//
23// These partially dead calls are usually results of C++ abstraction penalty
24// exposed by inlining.
25//
26//===----------------------------------------------------------------------===//
27
30#include "llvm/ADT/Statistic.h"
33#include "llvm/IR/Constants.h"
34#include "llvm/IR/Dominators.h"
35#include "llvm/IR/Function.h"
36#include "llvm/IR/IRBuilder.h"
37#include "llvm/IR/InstVisitor.h"
39#include "llvm/IR/MDBuilder.h"
41#include "llvm/Pass.h"
43
44#include <cmath>
45
46using namespace llvm;
47
48#define DEBUG_TYPE "libcalls-shrinkwrap"
49
50STATISTIC(NumWrappedOneCond, "Number of One-Condition Wrappers Inserted");
51STATISTIC(NumWrappedTwoCond, "Number of Two-Condition Wrappers Inserted");
52
53namespace {
54class LibCallsShrinkWrap : public InstVisitor<LibCallsShrinkWrap> {
55public:
56 LibCallsShrinkWrap(const TargetLibraryInfo &TLI, DominatorTree *DT)
57 : TLI(TLI), DT(DT){};
58 void visitCallInst(CallInst &CI) { checkCandidate(CI); }
59 bool perform() {
60 bool Changed = false;
61 for (auto &CI : WorkList) {
62 LLVM_DEBUG(dbgs() << "CDCE calls: " << CI->getCalledFunction()->getName()
63 << "\n");
64 if (perform(CI)) {
65 Changed = true;
66 LLVM_DEBUG(dbgs() << "Transformed\n");
67 }
68 }
69 return Changed;
70 }
71
72private:
73 bool perform(CallInst *CI);
74 void checkCandidate(CallInst &CI);
75 void shrinkWrapCI(CallInst *CI, Value *Cond);
76 bool performCallDomainErrorOnly(CallInst *CI, const LibFunc &Func);
77 bool performCallErrors(CallInst *CI, const LibFunc &Func);
78 bool performCallRangeErrorOnly(CallInst *CI, const LibFunc &Func);
79 Value *generateOneRangeCond(CallInst *CI, const LibFunc &Func);
80 Value *generateTwoRangeCond(CallInst *CI, const LibFunc &Func);
81 Value *generateCondForPow(CallInst *CI, const LibFunc &Func);
82
83 // Create an OR of two conditions.
84 Value *createOrCond(CallInst *CI, CmpInst::Predicate Cmp, float Val,
85 CmpInst::Predicate Cmp2, float Val2) {
86 IRBuilder<> BBBuilder(CI);
87 Value *Arg = CI->getArgOperand(0);
88 auto Cond2 = createCond(BBBuilder, Arg, Cmp2, Val2);
89 auto Cond1 = createCond(BBBuilder, Arg, Cmp, Val);
90 return BBBuilder.CreateOr(Cond1, Cond2);
91 }
92
93 // Create a single condition using IRBuilder.
94 Value *createCond(IRBuilder<> &BBBuilder, Value *Arg, CmpInst::Predicate Cmp,
95 float Val) {
96 Constant *V = ConstantFP::get(BBBuilder.getContext(), APFloat(Val));
97 if (!Arg->getType()->isFloatTy())
98 V = ConstantExpr::getFPExtend(V, Arg->getType());
99 return BBBuilder.CreateFCmp(Cmp, Arg, V);
100 }
101
102 // Create a single condition.
103 Value *createCond(CallInst *CI, CmpInst::Predicate Cmp, float Val) {
104 IRBuilder<> BBBuilder(CI);
105 Value *Arg = CI->getArgOperand(0);
106 return createCond(BBBuilder, Arg, Cmp, Val);
107 }
108
109 const TargetLibraryInfo &TLI;
110 DominatorTree *DT;
112};
113} // end anonymous namespace
114
115// Perform the transformation to calls with errno set by domain error.
116bool LibCallsShrinkWrap::performCallDomainErrorOnly(CallInst *CI,
117 const LibFunc &Func) {
118 Value *Cond = nullptr;
119
120 switch (Func) {
121 case LibFunc_acos: // DomainError: (x < -1 || x > 1)
122 case LibFunc_acosf: // Same as acos
123 case LibFunc_acosl: // Same as acos
124 case LibFunc_asin: // DomainError: (x < -1 || x > 1)
125 case LibFunc_asinf: // Same as asin
126 case LibFunc_asinl: // Same as asin
127 {
128 ++NumWrappedTwoCond;
129 Cond = createOrCond(CI, CmpInst::FCMP_OLT, -1.0f, CmpInst::FCMP_OGT, 1.0f);
130 break;
131 }
132 case LibFunc_cos: // DomainError: (x == +inf || x == -inf)
133 case LibFunc_cosf: // Same as cos
134 case LibFunc_cosl: // Same as cos
135 case LibFunc_sin: // DomainError: (x == +inf || x == -inf)
136 case LibFunc_sinf: // Same as sin
137 case LibFunc_sinl: // Same as sin
138 {
139 ++NumWrappedTwoCond;
141 -INFINITY);
142 break;
143 }
144 case LibFunc_acosh: // DomainError: (x < 1)
145 case LibFunc_acoshf: // Same as acosh
146 case LibFunc_acoshl: // Same as acosh
147 {
148 ++NumWrappedOneCond;
149 Cond = createCond(CI, CmpInst::FCMP_OLT, 1.0f);
150 break;
151 }
152 case LibFunc_sqrt: // DomainError: (x < 0)
153 case LibFunc_sqrtf: // Same as sqrt
154 case LibFunc_sqrtl: // Same as sqrt
155 {
156 ++NumWrappedOneCond;
157 Cond = createCond(CI, CmpInst::FCMP_OLT, 0.0f);
158 break;
159 }
160 default:
161 return false;
162 }
163 shrinkWrapCI(CI, Cond);
164 return true;
165}
166
167// Perform the transformation to calls with errno set by range error.
168bool LibCallsShrinkWrap::performCallRangeErrorOnly(CallInst *CI,
169 const LibFunc &Func) {
170 Value *Cond = nullptr;
171
172 switch (Func) {
173 case LibFunc_cosh:
174 case LibFunc_coshf:
175 case LibFunc_coshl:
176 case LibFunc_exp:
177 case LibFunc_expf:
178 case LibFunc_expl:
179 case LibFunc_exp10:
180 case LibFunc_exp10f:
181 case LibFunc_exp10l:
182 case LibFunc_exp2:
183 case LibFunc_exp2f:
184 case LibFunc_exp2l:
185 case LibFunc_sinh:
186 case LibFunc_sinhf:
187 case LibFunc_sinhl: {
188 Cond = generateTwoRangeCond(CI, Func);
189 break;
190 }
191 case LibFunc_expm1: // RangeError: (709, inf)
192 case LibFunc_expm1f: // RangeError: (88, inf)
193 case LibFunc_expm1l: // RangeError: (11356, inf)
194 {
195 Cond = generateOneRangeCond(CI, Func);
196 break;
197 }
198 default:
199 return false;
200 }
201 shrinkWrapCI(CI, Cond);
202 return true;
203}
204
205// Perform the transformation to calls with errno set by combination of errors.
206bool LibCallsShrinkWrap::performCallErrors(CallInst *CI,
207 const LibFunc &Func) {
208 Value *Cond = nullptr;
209
210 switch (Func) {
211 case LibFunc_atanh: // DomainError: (x < -1 || x > 1)
212 // PoleError: (x == -1 || x == 1)
213 // Overall Cond: (x <= -1 || x >= 1)
214 case LibFunc_atanhf: // Same as atanh
215 case LibFunc_atanhl: // Same as atanh
216 {
217 ++NumWrappedTwoCond;
218 Cond = createOrCond(CI, CmpInst::FCMP_OLE, -1.0f, CmpInst::FCMP_OGE, 1.0f);
219 break;
220 }
221 case LibFunc_log: // DomainError: (x < 0)
222 // PoleError: (x == 0)
223 // Overall Cond: (x <= 0)
224 case LibFunc_logf: // Same as log
225 case LibFunc_logl: // Same as log
226 case LibFunc_log10: // Same as log
227 case LibFunc_log10f: // Same as log
228 case LibFunc_log10l: // Same as log
229 case LibFunc_log2: // Same as log
230 case LibFunc_log2f: // Same as log
231 case LibFunc_log2l: // Same as log
232 case LibFunc_logb: // Same as log
233 case LibFunc_logbf: // Same as log
234 case LibFunc_logbl: // Same as log
235 {
236 ++NumWrappedOneCond;
237 Cond = createCond(CI, CmpInst::FCMP_OLE, 0.0f);
238 break;
239 }
240 case LibFunc_log1p: // DomainError: (x < -1)
241 // PoleError: (x == -1)
242 // Overall Cond: (x <= -1)
243 case LibFunc_log1pf: // Same as log1p
244 case LibFunc_log1pl: // Same as log1p
245 {
246 ++NumWrappedOneCond;
247 Cond = createCond(CI, CmpInst::FCMP_OLE, -1.0f);
248 break;
249 }
250 case LibFunc_pow: // DomainError: x < 0 and y is noninteger
251 // PoleError: x == 0 and y < 0
252 // RangeError: overflow or underflow
253 case LibFunc_powf:
254 case LibFunc_powl: {
255 Cond = generateCondForPow(CI, Func);
256 if (Cond == nullptr)
257 return false;
258 break;
259 }
260 default:
261 return false;
262 }
263 assert(Cond && "performCallErrors should not see an empty condition");
264 shrinkWrapCI(CI, Cond);
265 return true;
266}
267
268// Checks if CI is a candidate for shrinkwrapping and put it into work list if
269// true.
270void LibCallsShrinkWrap::checkCandidate(CallInst &CI) {
271 if (CI.isNoBuiltin())
272 return;
273 // A possible improvement is to handle the calls with the return value being
274 // used. If there is API for fast libcall implementation without setting
275 // errno, we can use the same framework to direct/wrap the call to the fast
276 // API in the error free path, and leave the original call in the slow path.
277 if (!CI.use_empty())
278 return;
279
282 if (!Callee)
283 return;
284 if (!TLI.getLibFunc(*Callee, Func) || !TLI.has(Func))
285 return;
286
287 if (CI.arg_empty())
288 return;
289 // TODO: Handle long double in other formats.
290 Type *ArgType = CI.getArgOperand(0)->getType();
291 if (!(ArgType->isFloatTy() || ArgType->isDoubleTy() ||
292 ArgType->isX86_FP80Ty()))
293 return;
294
295 WorkList.push_back(&CI);
296}
297
298// Generate the upper bound condition for RangeError.
299Value *LibCallsShrinkWrap::generateOneRangeCond(CallInst *CI,
300 const LibFunc &Func) {
301 float UpperBound;
302 switch (Func) {
303 case LibFunc_expm1: // RangeError: (709, inf)
304 UpperBound = 709.0f;
305 break;
306 case LibFunc_expm1f: // RangeError: (88, inf)
307 UpperBound = 88.0f;
308 break;
309 case LibFunc_expm1l: // RangeError: (11356, inf)
310 UpperBound = 11356.0f;
311 break;
312 default:
313 llvm_unreachable("Unhandled library call!");
314 }
315
316 ++NumWrappedOneCond;
317 return createCond(CI, CmpInst::FCMP_OGT, UpperBound);
318}
319
320// Generate the lower and upper bound condition for RangeError.
321Value *LibCallsShrinkWrap::generateTwoRangeCond(CallInst *CI,
322 const LibFunc &Func) {
323 float UpperBound, LowerBound;
324 switch (Func) {
325 case LibFunc_cosh: // RangeError: (x < -710 || x > 710)
326 case LibFunc_sinh: // Same as cosh
327 LowerBound = -710.0f;
328 UpperBound = 710.0f;
329 break;
330 case LibFunc_coshf: // RangeError: (x < -89 || x > 89)
331 case LibFunc_sinhf: // Same as coshf
332 LowerBound = -89.0f;
333 UpperBound = 89.0f;
334 break;
335 case LibFunc_coshl: // RangeError: (x < -11357 || x > 11357)
336 case LibFunc_sinhl: // Same as coshl
337 LowerBound = -11357.0f;
338 UpperBound = 11357.0f;
339 break;
340 case LibFunc_exp: // RangeError: (x < -745 || x > 709)
341 LowerBound = -745.0f;
342 UpperBound = 709.0f;
343 break;
344 case LibFunc_expf: // RangeError: (x < -103 || x > 88)
345 LowerBound = -103.0f;
346 UpperBound = 88.0f;
347 break;
348 case LibFunc_expl: // RangeError: (x < -11399 || x > 11356)
349 LowerBound = -11399.0f;
350 UpperBound = 11356.0f;
351 break;
352 case LibFunc_exp10: // RangeError: (x < -323 || x > 308)
353 LowerBound = -323.0f;
354 UpperBound = 308.0f;
355 break;
356 case LibFunc_exp10f: // RangeError: (x < -45 || x > 38)
357 LowerBound = -45.0f;
358 UpperBound = 38.0f;
359 break;
360 case LibFunc_exp10l: // RangeError: (x < -4950 || x > 4932)
361 LowerBound = -4950.0f;
362 UpperBound = 4932.0f;
363 break;
364 case LibFunc_exp2: // RangeError: (x < -1074 || x > 1023)
365 LowerBound = -1074.0f;
366 UpperBound = 1023.0f;
367 break;
368 case LibFunc_exp2f: // RangeError: (x < -149 || x > 127)
369 LowerBound = -149.0f;
370 UpperBound = 127.0f;
371 break;
372 case LibFunc_exp2l: // RangeError: (x < -16445 || x > 11383)
373 LowerBound = -16445.0f;
374 UpperBound = 11383.0f;
375 break;
376 default:
377 llvm_unreachable("Unhandled library call!");
378 }
379
380 ++NumWrappedTwoCond;
381 return createOrCond(CI, CmpInst::FCMP_OGT, UpperBound, CmpInst::FCMP_OLT,
382 LowerBound);
383}
384
385// For pow(x,y), We only handle the following cases:
386// (1) x is a constant && (x >= 1) && (x < MaxUInt8)
387// Cond is: (y > 127)
388// (2) x is a value coming from an integer type.
389// (2.1) if x's bit_size == 8
390// Cond: (x <= 0 || y > 128)
391// (2.2) if x's bit_size is 16
392// Cond: (x <= 0 || y > 64)
393// (2.3) if x's bit_size is 32
394// Cond: (x <= 0 || y > 32)
395// Support for powl(x,y) and powf(x,y) are TBD.
396//
397// Note that condition can be more conservative than the actual condition
398// (i.e. we might invoke the calls that will not set the errno.).
399//
400Value *LibCallsShrinkWrap::generateCondForPow(CallInst *CI,
401 const LibFunc &Func) {
402 // FIXME: LibFunc_powf and powl TBD.
403 if (Func != LibFunc_pow) {
404 LLVM_DEBUG(dbgs() << "Not handled powf() and powl()\n");
405 return nullptr;
406 }
407
408 Value *Base = CI->getArgOperand(0);
409 Value *Exp = CI->getArgOperand(1);
410 IRBuilder<> BBBuilder(CI);
411
412 // Constant Base case.
413 if (ConstantFP *CF = dyn_cast<ConstantFP>(Base)) {
414 double D = CF->getValueAPF().convertToDouble();
415 if (D < 1.0f || D > APInt::getMaxValue(8).getZExtValue()) {
416 LLVM_DEBUG(dbgs() << "Not handled pow(): constant base out of range\n");
417 return nullptr;
418 }
419
420 ++NumWrappedOneCond;
421 Constant *V = ConstantFP::get(CI->getContext(), APFloat(127.0f));
422 if (!Exp->getType()->isFloatTy())
423 V = ConstantExpr::getFPExtend(V, Exp->getType());
424 return BBBuilder.CreateFCmp(CmpInst::FCMP_OGT, Exp, V);
425 }
426
427 // If the Base value coming from an integer type.
428 Instruction *I = dyn_cast<Instruction>(Base);
429 if (!I) {
430 LLVM_DEBUG(dbgs() << "Not handled pow(): FP type base\n");
431 return nullptr;
432 }
433 unsigned Opcode = I->getOpcode();
434 if (Opcode == Instruction::UIToFP || Opcode == Instruction::SIToFP) {
435 unsigned BW = I->getOperand(0)->getType()->getPrimitiveSizeInBits();
436 float UpperV = 0.0f;
437 if (BW == 8)
438 UpperV = 128.0f;
439 else if (BW == 16)
440 UpperV = 64.0f;
441 else if (BW == 32)
442 UpperV = 32.0f;
443 else {
444 LLVM_DEBUG(dbgs() << "Not handled pow(): type too wide\n");
445 return nullptr;
446 }
447
448 ++NumWrappedTwoCond;
449 Constant *V = ConstantFP::get(CI->getContext(), APFloat(UpperV));
450 Constant *V0 = ConstantFP::get(CI->getContext(), APFloat(0.0f));
451 if (!Exp->getType()->isFloatTy())
452 V = ConstantExpr::getFPExtend(V, Exp->getType());
453 if (!Base->getType()->isFloatTy())
454 V0 = ConstantExpr::getFPExtend(V0, Exp->getType());
455
456 Value *Cond = BBBuilder.CreateFCmp(CmpInst::FCMP_OGT, Exp, V);
457 Value *Cond0 = BBBuilder.CreateFCmp(CmpInst::FCMP_OLE, Base, V0);
458 return BBBuilder.CreateOr(Cond0, Cond);
459 }
460 LLVM_DEBUG(dbgs() << "Not handled pow(): base not from integer convert\n");
461 return nullptr;
462}
463
464// Wrap conditions that can potentially generate errno to the library call.
465void LibCallsShrinkWrap::shrinkWrapCI(CallInst *CI, Value *Cond) {
466 assert(Cond != nullptr && "ShrinkWrapCI is not expecting an empty call inst");
467 MDNode *BranchWeights =
469
470 Instruction *NewInst =
471 SplitBlockAndInsertIfThen(Cond, CI, false, BranchWeights, DT);
472 BasicBlock *CallBB = NewInst->getParent();
473 CallBB->setName("cdce.call");
474 BasicBlock *SuccBB = CallBB->getSingleSuccessor();
475 assert(SuccBB && "The split block should have a single successor");
476 SuccBB->setName("cdce.end");
477 CI->removeFromParent();
478 CI->insertInto(CallBB, CallBB->getFirstInsertionPt());
479 LLVM_DEBUG(dbgs() << "== Basic Block After ==");
480 LLVM_DEBUG(dbgs() << *CallBB->getSinglePredecessor() << *CallBB
481 << *CallBB->getSingleSuccessor() << "\n");
482}
483
484// Perform the transformation to a single candidate.
485bool LibCallsShrinkWrap::perform(CallInst *CI) {
488 assert(Callee && "perform() should apply to a non-empty callee");
489 TLI.getLibFunc(*Callee, Func);
490 assert(Func && "perform() is not expecting an empty function");
491
492 if (performCallDomainErrorOnly(CI, Func) || performCallRangeErrorOnly(CI, Func))
493 return true;
494 return performCallErrors(CI, Func);
495}
496
497static bool runImpl(Function &F, const TargetLibraryInfo &TLI,
498 DominatorTree *DT) {
499 if (F.hasFnAttribute(Attribute::OptimizeForSize))
500 return false;
501 LibCallsShrinkWrap CCDCE(TLI, DT);
502 CCDCE.visit(F);
503 bool Changed = CCDCE.perform();
504
505// Verify the dominator after we've updated it locally.
506 assert(!DT || DT->verify(DominatorTree::VerificationLevel::Fast));
507 return Changed;
508}
509
512 auto &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
514 if (!runImpl(F, TLI, DT))
515 return PreservedAnalyses::all();
516 auto PA = PreservedAnalyses();
517 PA.preserve<DominatorTreeAnalysis>();
518 return PA;
519}
amdgpu Simplify well known AMD library false FunctionCallee Callee
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
SmallVector< MachineOperand, 4 > Cond
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
#define LLVM_DEBUG(X)
Definition: Debug.h:101
static bool runImpl(Function &F, const TargetLowering &TLI)
This is the interface for a simple mod/ref and alias analysis over globals.
static bool runImpl(Function &F, const TargetLibraryInfo &TLI, DominatorTree *DT)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
FunctionAnalysisManager FAM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:186
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:793
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:254
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:293
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:323
bool arg_empty() const
Definition: InstrTypes.h:1350
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Definition: InstrTypes.h:1868
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1408
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1353
This class represents a function call, abstracting a target machine's calling convention.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:718
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:721
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:724
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:722
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:723
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:725
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2136
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:260
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
Definition: Constants.cpp:927
This is an important base class in LLVM.
Definition: Constant.h:41
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:279
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2256
LLVMContext & getContext() const
Definition: IRBuilder.h:176
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1426
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2564
Base class for instruction visitors.
Definition: InstVisitor.h:78
RetTy visitCallInst(CallInst &I)
Definition: InstVisitor.h:220
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:78
const BasicBlock * getParent() const
Definition: Instruction.h:90
SymbolTableList< Instruction >::iterator insertInto(BasicBlock *ParentBB, SymbolTableList< Instruction >::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
Definition: Instruction.cpp:98
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
Definition: MDBuilder.cpp:37
Metadata node.
Definition: Metadata.h:943
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isX86_FP80Ty() const
Return true if this is x86 long double.
Definition: Type.h:160
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:377
bool use_empty() const
Definition: Value.h:344
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:996
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Instruction * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights, DominatorTree *DT, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
#define INFINITY
Definition: regcomp.c:281