LLVM  10.0.0svn
LowerWidenableCondition.cpp
Go to the documentation of this file.
1 //===- LowerWidenableCondition.cpp - Lower the guard 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 llvm.widenable.condition intrinsic to default value
10 // which is i1 true.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/IR/BasicBlock.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/InstIterator.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/IR/Intrinsics.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/IR/PatternMatch.h"
24 #include "llvm/Pass.h"
25 #include "llvm/Transforms/Scalar.h"
27 
28 using namespace llvm;
29 
30 namespace {
31 struct LowerWidenableConditionLegacyPass : public FunctionPass {
32  static char ID;
33  LowerWidenableConditionLegacyPass() : FunctionPass(ID) {
36  }
37 
38  bool runOnFunction(Function &F) override;
39 };
40 }
41 
43  // Check if we can cheaply rule out the possibility of not having any work to
44  // do.
45  auto *WCDecl = F.getParent()->getFunction(
46  Intrinsic::getName(Intrinsic::experimental_widenable_condition));
47  if (!WCDecl || WCDecl->use_empty())
48  return false;
49 
50  using namespace llvm::PatternMatch;
52  for (auto &I : instructions(F))
53  if (match(&I, m_Intrinsic<Intrinsic::experimental_widenable_condition>()))
54  ToLower.push_back(cast<CallInst>(&I));
55 
56  if (ToLower.empty())
57  return false;
58 
59  for (auto *CI : ToLower) {
60  CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getContext()));
61  CI->eraseFromParent();
62  }
63  return true;
64 }
65 
67  return lowerWidenableCondition(F);
68 }
69 
71 INITIALIZE_PASS(LowerWidenableConditionLegacyPass, "lower-widenable-condition",
72  "Lower the widenable condition to default true value", false,
73  false)
74 
76  return new LowerWidenableConditionLegacyPass();
77 }
78 
82  return PreservedAnalyses::none();
83 
84  return PreservedAnalyses::all();
85 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
F(f)
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:47
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:640
static bool lowerWidenableCondition(Function &F)
void initializeLowerWidenableConditionLegacyPassPass(PassRegistry &)
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:156
static bool runOnFunction(Function &F, bool PostInlining)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Module.h This file contains the declarations for the Module class.
Pass * createLowerWidenableConditionPass()
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:609
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:174
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
#define I(x, y, z)
Definition: MD5.cpp:58
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
inst_range instructions(Function *F)
Definition: InstIterator.h:133
A container for analyses that lazily runs them and caches their results.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
INITIALIZE_PASS(LowerWidenableConditionLegacyPass, "lower-widenable-condition", "Lower the widenable condition to default true value", false, false) Pass *llvm