LLVM  16.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 
29 #include "llvm/ADT/SmallVector.h"
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"
38 #include "llvm/IR/Instructions.h"
39 #include "llvm/IR/MDBuilder.h"
40 #include "llvm/InitializePasses.h"
41 #include "llvm/Pass.h"
43 
44 #include <cmath>
45 
46 using namespace llvm;
47 
48 #define DEBUG_TYPE "libcalls-shrinkwrap"
49 
50 STATISTIC(NumWrappedOneCond, "Number of One-Condition Wrappers Inserted");
51 STATISTIC(NumWrappedTwoCond, "Number of Two-Condition Wrappers Inserted");
52 
53 namespace {
54 class LibCallsShrinkWrapLegacyPass : public FunctionPass {
55 public:
56  static char ID; // Pass identification, replacement for typeid
57  explicit LibCallsShrinkWrapLegacyPass() : FunctionPass(ID) {
60  }
61  void getAnalysisUsage(AnalysisUsage &AU) const override;
62  bool runOnFunction(Function &F) override;
63 };
64 }
65 
67 INITIALIZE_PASS_BEGIN(LibCallsShrinkWrapLegacyPass, "libcalls-shrinkwrap",
68  "Conditionally eliminate dead library calls", false,
69  false)
71 INITIALIZE_PASS_END(LibCallsShrinkWrapLegacyPass, "libcalls-shrinkwrap",
72  "Conditionally eliminate dead library calls", false, false)
73 
74 namespace {
75 class LibCallsShrinkWrap : public InstVisitor<LibCallsShrinkWrap> {
76 public:
78  : TLI(TLI), DT(DT){};
79  void visitCallInst(CallInst &CI) { checkCandidate(CI); }
80  bool perform() {
81  bool Changed = false;
82  for (auto &CI : WorkList) {
83  LLVM_DEBUG(dbgs() << "CDCE calls: " << CI->getCalledFunction()->getName()
84  << "\n");
85  if (perform(CI)) {
86  Changed = true;
87  LLVM_DEBUG(dbgs() << "Transformed\n");
88  }
89  }
90  return Changed;
91  }
92 
93 private:
94  bool perform(CallInst *CI);
95  void checkCandidate(CallInst &CI);
96  void shrinkWrapCI(CallInst *CI, Value *Cond);
97  bool performCallDomainErrorOnly(CallInst *CI, const LibFunc &Func);
98  bool performCallErrors(CallInst *CI, const LibFunc &Func);
99  bool performCallRangeErrorOnly(CallInst *CI, const LibFunc &Func);
100  Value *generateOneRangeCond(CallInst *CI, const LibFunc &Func);
101  Value *generateTwoRangeCond(CallInst *CI, const LibFunc &Func);
102  Value *generateCondForPow(CallInst *CI, const LibFunc &Func);
103 
104  // Create an OR of two conditions.
105  Value *createOrCond(CallInst *CI, CmpInst::Predicate Cmp, float Val,
106  CmpInst::Predicate Cmp2, float Val2) {
107  IRBuilder<> BBBuilder(CI);
108  Value *Arg = CI->getArgOperand(0);
109  auto Cond2 = createCond(BBBuilder, Arg, Cmp2, Val2);
110  auto Cond1 = createCond(BBBuilder, Arg, Cmp, Val);
111  return BBBuilder.CreateOr(Cond1, Cond2);
112  }
113 
114  // Create a single condition using IRBuilder.
115  Value *createCond(IRBuilder<> &BBBuilder, Value *Arg, CmpInst::Predicate Cmp,
116  float Val) {
117  Constant *V = ConstantFP::get(BBBuilder.getContext(), APFloat(Val));
118  if (!Arg->getType()->isFloatTy())
119  V = ConstantExpr::getFPExtend(V, Arg->getType());
120  return BBBuilder.CreateFCmp(Cmp, Arg, V);
121  }
122 
123  // Create a single condition.
124  Value *createCond(CallInst *CI, CmpInst::Predicate Cmp, float Val) {
125  IRBuilder<> BBBuilder(CI);
126  Value *Arg = CI->getArgOperand(0);
127  return createCond(BBBuilder, Arg, Cmp, Val);
128  }
129 
130  const TargetLibraryInfo &TLI;
131  DominatorTree *DT;
133 };
134 } // end anonymous namespace
135 
136 // Perform the transformation to calls with errno set by domain error.
137 bool LibCallsShrinkWrap::performCallDomainErrorOnly(CallInst *CI,
138  const LibFunc &Func) {
139  Value *Cond = nullptr;
140 
141  switch (Func) {
142  case LibFunc_acos: // DomainError: (x < -1 || x > 1)
143  case LibFunc_acosf: // Same as acos
144  case LibFunc_acosl: // Same as acos
145  case LibFunc_asin: // DomainError: (x < -1 || x > 1)
146  case LibFunc_asinf: // Same as asin
147  case LibFunc_asinl: // Same as asin
148  {
149  ++NumWrappedTwoCond;
150  Cond = createOrCond(CI, CmpInst::FCMP_OLT, -1.0f, CmpInst::FCMP_OGT, 1.0f);
151  break;
152  }
153  case LibFunc_cos: // DomainError: (x == +inf || x == -inf)
154  case LibFunc_cosf: // Same as cos
155  case LibFunc_cosl: // Same as cos
156  case LibFunc_sin: // DomainError: (x == +inf || x == -inf)
157  case LibFunc_sinf: // Same as sin
158  case LibFunc_sinl: // Same as sin
159  {
160  ++NumWrappedTwoCond;
161  Cond = createOrCond(CI, CmpInst::FCMP_OEQ, INFINITY, CmpInst::FCMP_OEQ,
162  -INFINITY);
163  break;
164  }
165  case LibFunc_acosh: // DomainError: (x < 1)
166  case LibFunc_acoshf: // Same as acosh
167  case LibFunc_acoshl: // Same as acosh
168  {
169  ++NumWrappedOneCond;
170  Cond = createCond(CI, CmpInst::FCMP_OLT, 1.0f);
171  break;
172  }
173  case LibFunc_sqrt: // DomainError: (x < 0)
174  case LibFunc_sqrtf: // Same as sqrt
175  case LibFunc_sqrtl: // Same as sqrt
176  {
177  ++NumWrappedOneCond;
178  Cond = createCond(CI, CmpInst::FCMP_OLT, 0.0f);
179  break;
180  }
181  default:
182  return false;
183  }
184  shrinkWrapCI(CI, Cond);
185  return true;
186 }
187 
188 // Perform the transformation to calls with errno set by range error.
189 bool LibCallsShrinkWrap::performCallRangeErrorOnly(CallInst *CI,
190  const LibFunc &Func) {
191  Value *Cond = nullptr;
192 
193  switch (Func) {
194  case LibFunc_cosh:
195  case LibFunc_coshf:
196  case LibFunc_coshl:
197  case LibFunc_exp:
198  case LibFunc_expf:
199  case LibFunc_expl:
200  case LibFunc_exp10:
201  case LibFunc_exp10f:
202  case LibFunc_exp10l:
203  case LibFunc_exp2:
204  case LibFunc_exp2f:
205  case LibFunc_exp2l:
206  case LibFunc_sinh:
207  case LibFunc_sinhf:
208  case LibFunc_sinhl: {
209  Cond = generateTwoRangeCond(CI, Func);
210  break;
211  }
212  case LibFunc_expm1: // RangeError: (709, inf)
213  case LibFunc_expm1f: // RangeError: (88, inf)
214  case LibFunc_expm1l: // RangeError: (11356, inf)
215  {
216  Cond = generateOneRangeCond(CI, Func);
217  break;
218  }
219  default:
220  return false;
221  }
222  shrinkWrapCI(CI, Cond);
223  return true;
224 }
225 
226 // Perform the transformation to calls with errno set by combination of errors.
227 bool LibCallsShrinkWrap::performCallErrors(CallInst *CI,
228  const LibFunc &Func) {
229  Value *Cond = nullptr;
230 
231  switch (Func) {
232  case LibFunc_atanh: // DomainError: (x < -1 || x > 1)
233  // PoleError: (x == -1 || x == 1)
234  // Overall Cond: (x <= -1 || x >= 1)
235  case LibFunc_atanhf: // Same as atanh
236  case LibFunc_atanhl: // Same as atanh
237  {
238  ++NumWrappedTwoCond;
239  Cond = createOrCond(CI, CmpInst::FCMP_OLE, -1.0f, CmpInst::FCMP_OGE, 1.0f);
240  break;
241  }
242  case LibFunc_log: // DomainError: (x < 0)
243  // PoleError: (x == 0)
244  // Overall Cond: (x <= 0)
245  case LibFunc_logf: // Same as log
246  case LibFunc_logl: // Same as log
247  case LibFunc_log10: // Same as log
248  case LibFunc_log10f: // Same as log
249  case LibFunc_log10l: // Same as log
250  case LibFunc_log2: // Same as log
251  case LibFunc_log2f: // Same as log
252  case LibFunc_log2l: // Same as log
253  case LibFunc_logb: // Same as log
254  case LibFunc_logbf: // Same as log
255  case LibFunc_logbl: // Same as log
256  {
257  ++NumWrappedOneCond;
258  Cond = createCond(CI, CmpInst::FCMP_OLE, 0.0f);
259  break;
260  }
261  case LibFunc_log1p: // DomainError: (x < -1)
262  // PoleError: (x == -1)
263  // Overall Cond: (x <= -1)
264  case LibFunc_log1pf: // Same as log1p
265  case LibFunc_log1pl: // Same as log1p
266  {
267  ++NumWrappedOneCond;
268  Cond = createCond(CI, CmpInst::FCMP_OLE, -1.0f);
269  break;
270  }
271  case LibFunc_pow: // DomainError: x < 0 and y is noninteger
272  // PoleError: x == 0 and y < 0
273  // RangeError: overflow or underflow
274  case LibFunc_powf:
275  case LibFunc_powl: {
276  Cond = generateCondForPow(CI, Func);
277  if (Cond == nullptr)
278  return false;
279  break;
280  }
281  default:
282  return false;
283  }
284  assert(Cond && "performCallErrors should not see an empty condition");
285  shrinkWrapCI(CI, Cond);
286  return true;
287 }
288 
289 // Checks if CI is a candidate for shrinkwrapping and put it into work list if
290 // true.
291 void LibCallsShrinkWrap::checkCandidate(CallInst &CI) {
292  if (CI.isNoBuiltin())
293  return;
294  // A possible improvement is to handle the calls with the return value being
295  // used. If there is API for fast libcall implementation without setting
296  // errno, we can use the same framework to direct/wrap the call to the fast
297  // API in the error free path, and leave the original call in the slow path.
298  if (!CI.use_empty())
299  return;
300 
301  LibFunc Func;
303  if (!Callee)
304  return;
305  if (!TLI.getLibFunc(*Callee, Func) || !TLI.has(Func))
306  return;
307 
308  if (CI.arg_empty())
309  return;
310  // TODO: Handle long double in other formats.
311  Type *ArgType = CI.getArgOperand(0)->getType();
312  if (!(ArgType->isFloatTy() || ArgType->isDoubleTy() ||
313  ArgType->isX86_FP80Ty()))
314  return;
315 
316  WorkList.push_back(&CI);
317 }
318 
319 // Generate the upper bound condition for RangeError.
320 Value *LibCallsShrinkWrap::generateOneRangeCond(CallInst *CI,
321  const LibFunc &Func) {
322  float UpperBound;
323  switch (Func) {
324  case LibFunc_expm1: // RangeError: (709, inf)
325  UpperBound = 709.0f;
326  break;
327  case LibFunc_expm1f: // RangeError: (88, inf)
328  UpperBound = 88.0f;
329  break;
330  case LibFunc_expm1l: // RangeError: (11356, inf)
331  UpperBound = 11356.0f;
332  break;
333  default:
334  llvm_unreachable("Unhandled library call!");
335  }
336 
337  ++NumWrappedOneCond;
338  return createCond(CI, CmpInst::FCMP_OGT, UpperBound);
339 }
340 
341 // Generate the lower and upper bound condition for RangeError.
342 Value *LibCallsShrinkWrap::generateTwoRangeCond(CallInst *CI,
343  const LibFunc &Func) {
344  float UpperBound, LowerBound;
345  switch (Func) {
346  case LibFunc_cosh: // RangeError: (x < -710 || x > 710)
347  case LibFunc_sinh: // Same as cosh
348  LowerBound = -710.0f;
349  UpperBound = 710.0f;
350  break;
351  case LibFunc_coshf: // RangeError: (x < -89 || x > 89)
352  case LibFunc_sinhf: // Same as coshf
353  LowerBound = -89.0f;
354  UpperBound = 89.0f;
355  break;
356  case LibFunc_coshl: // RangeError: (x < -11357 || x > 11357)
357  case LibFunc_sinhl: // Same as coshl
358  LowerBound = -11357.0f;
359  UpperBound = 11357.0f;
360  break;
361  case LibFunc_exp: // RangeError: (x < -745 || x > 709)
362  LowerBound = -745.0f;
363  UpperBound = 709.0f;
364  break;
365  case LibFunc_expf: // RangeError: (x < -103 || x > 88)
366  LowerBound = -103.0f;
367  UpperBound = 88.0f;
368  break;
369  case LibFunc_expl: // RangeError: (x < -11399 || x > 11356)
370  LowerBound = -11399.0f;
371  UpperBound = 11356.0f;
372  break;
373  case LibFunc_exp10: // RangeError: (x < -323 || x > 308)
374  LowerBound = -323.0f;
375  UpperBound = 308.0f;
376  break;
377  case LibFunc_exp10f: // RangeError: (x < -45 || x > 38)
378  LowerBound = -45.0f;
379  UpperBound = 38.0f;
380  break;
381  case LibFunc_exp10l: // RangeError: (x < -4950 || x > 4932)
382  LowerBound = -4950.0f;
383  UpperBound = 4932.0f;
384  break;
385  case LibFunc_exp2: // RangeError: (x < -1074 || x > 1023)
386  LowerBound = -1074.0f;
387  UpperBound = 1023.0f;
388  break;
389  case LibFunc_exp2f: // RangeError: (x < -149 || x > 127)
390  LowerBound = -149.0f;
391  UpperBound = 127.0f;
392  break;
393  case LibFunc_exp2l: // RangeError: (x < -16445 || x > 11383)
394  LowerBound = -16445.0f;
395  UpperBound = 11383.0f;
396  break;
397  default:
398  llvm_unreachable("Unhandled library call!");
399  }
400 
401  ++NumWrappedTwoCond;
402  return createOrCond(CI, CmpInst::FCMP_OGT, UpperBound, CmpInst::FCMP_OLT,
403  LowerBound);
404 }
405 
406 // For pow(x,y), We only handle the following cases:
407 // (1) x is a constant && (x >= 1) && (x < MaxUInt8)
408 // Cond is: (y > 127)
409 // (2) x is a value coming from an integer type.
410 // (2.1) if x's bit_size == 8
411 // Cond: (x <= 0 || y > 128)
412 // (2.2) if x's bit_size is 16
413 // Cond: (x <= 0 || y > 64)
414 // (2.3) if x's bit_size is 32
415 // Cond: (x <= 0 || y > 32)
416 // Support for powl(x,y) and powf(x,y) are TBD.
417 //
418 // Note that condition can be more conservative than the actual condition
419 // (i.e. we might invoke the calls that will not set the errno.).
420 //
421 Value *LibCallsShrinkWrap::generateCondForPow(CallInst *CI,
422  const LibFunc &Func) {
423  // FIXME: LibFunc_powf and powl TBD.
424  if (Func != LibFunc_pow) {
425  LLVM_DEBUG(dbgs() << "Not handled powf() and powl()\n");
426  return nullptr;
427  }
428 
429  Value *Base = CI->getArgOperand(0);
430  Value *Exp = CI->getArgOperand(1);
431  IRBuilder<> BBBuilder(CI);
432 
433  // Constant Base case.
434  if (ConstantFP *CF = dyn_cast<ConstantFP>(Base)) {
435  double D = CF->getValueAPF().convertToDouble();
436  if (D < 1.0f || D > APInt::getMaxValue(8).getZExtValue()) {
437  LLVM_DEBUG(dbgs() << "Not handled pow(): constant base out of range\n");
438  return nullptr;
439  }
440 
441  ++NumWrappedOneCond;
442  Constant *V = ConstantFP::get(CI->getContext(), APFloat(127.0f));
443  if (!Exp->getType()->isFloatTy())
444  V = ConstantExpr::getFPExtend(V, Exp->getType());
445  return BBBuilder.CreateFCmp(CmpInst::FCMP_OGT, Exp, V);
446  }
447 
448  // If the Base value coming from an integer type.
449  Instruction *I = dyn_cast<Instruction>(Base);
450  if (!I) {
451  LLVM_DEBUG(dbgs() << "Not handled pow(): FP type base\n");
452  return nullptr;
453  }
454  unsigned Opcode = I->getOpcode();
455  if (Opcode == Instruction::UIToFP || Opcode == Instruction::SIToFP) {
456  unsigned BW = I->getOperand(0)->getType()->getPrimitiveSizeInBits();
457  float UpperV = 0.0f;
458  if (BW == 8)
459  UpperV = 128.0f;
460  else if (BW == 16)
461  UpperV = 64.0f;
462  else if (BW == 32)
463  UpperV = 32.0f;
464  else {
465  LLVM_DEBUG(dbgs() << "Not handled pow(): type too wide\n");
466  return nullptr;
467  }
468 
469  ++NumWrappedTwoCond;
470  Constant *V = ConstantFP::get(CI->getContext(), APFloat(UpperV));
471  Constant *V0 = ConstantFP::get(CI->getContext(), APFloat(0.0f));
472  if (!Exp->getType()->isFloatTy())
473  V = ConstantExpr::getFPExtend(V, Exp->getType());
474  if (!Base->getType()->isFloatTy())
475  V0 = ConstantExpr::getFPExtend(V0, Exp->getType());
476 
477  Value *Cond = BBBuilder.CreateFCmp(CmpInst::FCMP_OGT, Exp, V);
478  Value *Cond0 = BBBuilder.CreateFCmp(CmpInst::FCMP_OLE, Base, V0);
479  return BBBuilder.CreateOr(Cond0, Cond);
480  }
481  LLVM_DEBUG(dbgs() << "Not handled pow(): base not from integer convert\n");
482  return nullptr;
483 }
484 
485 // Wrap conditions that can potentially generate errno to the library call.
486 void LibCallsShrinkWrap::shrinkWrapCI(CallInst *CI, Value *Cond) {
487  assert(Cond != nullptr && "ShrinkWrapCI is not expecting an empty call inst");
488  MDNode *BranchWeights =
489  MDBuilder(CI->getContext()).createBranchWeights(1, 2000);
490 
491  Instruction *NewInst =
492  SplitBlockAndInsertIfThen(Cond, CI, false, BranchWeights, DT);
493  BasicBlock *CallBB = NewInst->getParent();
494  CallBB->setName("cdce.call");
495  BasicBlock *SuccBB = CallBB->getSingleSuccessor();
496  assert(SuccBB && "The split block should have a single successor");
497  SuccBB->setName("cdce.end");
498  CI->removeFromParent();
499  CallBB->getInstList().insert(CallBB->getFirstInsertionPt(), CI);
500  LLVM_DEBUG(dbgs() << "== Basic Block After ==");
501  LLVM_DEBUG(dbgs() << *CallBB->getSinglePredecessor() << *CallBB
502  << *CallBB->getSingleSuccessor() << "\n");
503 }
504 
505 // Perform the transformation to a single candidate.
506 bool LibCallsShrinkWrap::perform(CallInst *CI) {
507  LibFunc Func;
509  assert(Callee && "perform() should apply to a non-empty callee");
510  TLI.getLibFunc(*Callee, Func);
511  assert(Func && "perform() is not expecting an empty function");
512 
513  if (performCallDomainErrorOnly(CI, Func) || performCallRangeErrorOnly(CI, Func))
514  return true;
515  return performCallErrors(CI, Func);
516 }
517 
518 void LibCallsShrinkWrapLegacyPass::getAnalysisUsage(AnalysisUsage &AU) const {
522 }
523 
524 static bool runImpl(Function &F, const TargetLibraryInfo &TLI,
525  DominatorTree *DT) {
526  if (F.hasFnAttribute(Attribute::OptimizeForSize))
527  return false;
528  LibCallsShrinkWrap CCDCE(TLI, DT);
529  CCDCE.visit(F);
530  bool Changed = CCDCE.perform();
531 
532 // Verify the dominator after we've updated it locally.
534  return Changed;
535 }
536 
538  auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
539  auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
540  auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
541  return runImpl(F, TLI, DT);
542 }
543 
544 namespace llvm {
546 
547 // Public interface to LibCallsShrinkWrap pass.
549  return new LibCallsShrinkWrapLegacyPass();
550 }
551 
554  auto &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
556  if (!runImpl(F, TLI, DT))
557  return PreservedAnalyses::all();
558  auto PA = PreservedAnalyses();
559  PA.preserve<DominatorTreeAnalysis>();
560  return PA;
561 }
562 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
libcalls
partially inline libcalls
Definition: PartiallyInlineLibCalls.cpp:212
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::CallBase::isNoBuiltin
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Definition: InstrTypes.h:1839
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::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
llvm::Function
Definition: Function.h:60
Pass.h
llvm::SmallVector< CallInst *, 16 >
Statistic.h
false::LibCallsShrinkWrap::LibCallsShrinkWrap
LibCallsShrinkWrap(const TargetLibraryInfo &TLI, DominatorTree *DT)
Definition: LibCallsShrinkWrap.cpp:77
llvm::APInt::getMaxValue
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
Definition: APInt.h:186
llvm::IRBuilder<>
llvm::IRBuilderBase::CreateOr
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1403
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
GlobalsModRef.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::BasicBlock::getSingleSuccessor
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:315
llvm::Type::isX86_FP80Ty
bool isX86_FP80Ty() const
Return true if this is x86 long double.
Definition: Type.h:159
llvm::BasicBlock::getSinglePredecessor
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:285
llvm::Sched::Fast
@ Fast
Definition: TargetLowering.h:104
llvm::CmpInst::FCMP_OGT
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:723
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
library
Itanium Name Demangler i e convert the string _Z1fv into and both[sub] projects need to demangle but neither can depend on each other *libcxxabi needs the demangler to implement which is part of the itanium ABI spec *LLVM needs a copy for a bunch of and cannot rely on the system s __cxa_demangle because it a might not be and b may not be up to date on the latest language features The copy of the demangler in LLVM has some extra stuff that aren t needed in which depend on the shared generic components Despite these we want to keep the core generic demangling library identical between both copies to simplify development and testing If you re working on the generic library
Definition: README.txt:36
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:187
shrinkwrap
libcalls shrinkwrap
Definition: LibCallsShrinkWrap.cpp:71
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:24
Constants.h
f
Itanium Name Demangler i e convert the string _Z1fv into f()". You can also use the CRTP base ManglingParser to perform some simple analysis on the mangled name
llvm::LibFunc
LibFunc
Definition: TargetLibraryInfo.h:36
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::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
TargetLibraryInfo.h
llvm::BasicBlock::getFirstInsertionPt
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:246
false
Definition: StackSlotColoring.cpp:141
llvm::createLibCallsShrinkWrapPass
FunctionPass * createLibCallsShrinkWrapPass()
Definition: LibCallsShrinkWrap.cpp:548
llvm::Instruction
Definition: Instruction.h:42
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:302
MDBuilder.h
llvm::IRBuilderBase::getContext
LLVMContext & getContext() const
Definition: IRBuilder.h:175
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:257
false::LibCallsShrinkWrap::perform
bool perform()
Definition: LibCallsShrinkWrap.cpp:80
llvm::Value::setName
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:375
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(LibCallsShrinkWrapLegacyPass, "libcalls-shrinkwrap", "Conditionally eliminate dead library calls", false, false) INITIALIZE_PASS_END(LibCallsShrinkWrapLegacyPass
llvm::IRBuilderBase::CreateFCmp
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2219
llvm::CmpInst::FCMP_OEQ
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition: InstrTypes.h:722
llvm::CmpInst::FCMP_OLT
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:725
llvm::Instruction::removeFromParent
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
Definition: Instruction.cpp:77
false::LibCallsShrinkWrap
Definition: LibCallsShrinkWrap.cpp:75
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:344
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
INFINITY
#define INFINITY
Definition: regcomp.c:281
llvm::APFloat
Definition: APFloat.h:716
false::LibCallsShrinkWrap::visitCallInst
void visitCallInst(CallInst &CI)
Definition: LibCallsShrinkWrap.cpp:79
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:475
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
I
#define I(x, y, z)
Definition: MD5.cpp:58
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::CmpInst::FCMP_OGE
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition: InstrTypes.h:724
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
calls
libcalls Conditionally eliminate dead library calls
Definition: LibCallsShrinkWrap.cpp:72
LibCallsShrinkWrap.h
Cond
SmallVector< MachineOperand, 4 > Cond
Definition: BasicBlockSections.cpp:138
InstVisitor.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::AnalysisUsage::addPreserved
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Definition: PassAnalysisSupport.h:98
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
llvm::InstVisitor
Base class for instruction visitors.
Definition: InstVisitor.h:78
runImpl
static bool runImpl(Function &F, const TargetLibraryInfo &TLI, DominatorTree *DT)
Definition: LibCallsShrinkWrap.cpp:524
llvm::ifs::IFSSymbolType::Func
@ Func
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:187
llvm::initializeLibCallsShrinkWrapLegacyPassPass
void initializeLibCallsShrinkWrapLegacyPassPass(PassRegistry &)
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:85
llvm::Type::isFloatTy
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:153
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
llvm::ConstantFP::get
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:926
llvm::AnalysisManager::getCachedResult
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:793
Function.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:226
llvm::Type::isDoubleTy
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:156
llvm::CallBase::arg_empty
bool arg_empty() const
Definition: InstrTypes.h:1338
llvm::MDBuilder
Definition: MDBuilder.h:36
llvm::DominatorTreeAnalysis
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:267
llvm::BasicBlock::getInstList
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:373
Instructions.h
SmallVector.h
llvm::ConstantExpr::getFPExtend
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2118
Dominators.h
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1341
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:91
llvm::GlobalsAAWrapperPass
Legacy wrapper pass to provide the GlobalsAAResult object.
Definition: GlobalsModRef.h:142
llvm::DominatorTreeBase::verify
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
Definition: GenericDomTree.h:802
llvm::codeview::CompileSym3Flags::Exp
@ Exp
llvm::CmpInst::FCMP_OLE
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition: InstrTypes.h:726
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
llvm::LibCallsShrinkWrapPass::run
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
Definition: LibCallsShrinkWrap.cpp:552
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::SplitBlockAndInsertIfThen
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 ...
Definition: BasicBlockUtils.cpp:1525
BasicBlockUtils.h
InitializePasses.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::TargetLibraryAnalysis
Analysis pass providing the TargetLibraryInfo.
Definition: TargetLibraryInfo.h:450
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::LibCallsShrinkWrapPassID
char & LibCallsShrinkWrapPassID
Definition: LibCallsShrinkWrap.cpp:545