34 cl::desc(
"The probability of a guard failing is assumed to be the "
35 "reciprocal of this value (default = 1 << 20)"));
38 struct LowerGuardIntrinsicLegacyPass :
public FunctionPass {
55 auto *DeoptBlockTerm =
58 auto *CheckBI = cast<BranchInst>(CheckBB->getTerminator());
62 CheckBI->swapSuccessors();
65 CheckBI->getSuccessor(1)->setName(
"deopt");
75 auto *DeoptCall = B.
CreateCall(DeoptIntrinsic,
Args, {DeoptOB},
"");
80 DeoptCall->
setName(
"deoptcall");
93 if (!GuardDecl || GuardDecl->use_empty())
98 if (
auto *CI = dyn_cast<CallInst>(&
I))
99 if (
auto *F = CI->getCalledFunction())
110 for (
auto *CI : ToLower) {
112 CI->eraseFromParent();
118 bool LowerGuardIntrinsicLegacyPass::runOnFunction(
Function &
F) {
124 "Lower the guard intrinsic to normal control flow",
false,
128 return new LowerGuardIntrinsicLegacyPass();
Pass interface - Implemented by all 'passes'.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents a function call, abstracting a target machine's calling convention.
Type * getReturnType() const
Returns the type of the ret val.
static bool lowerGuardIntrinsic(Function &F)
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void setName(const Twine &Name)
Change the name of the value.
LLVM_NODISCARD bool empty() const
op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
static cl::opt< uint32_t > PredicatePassBranchWeight("guards-predicate-pass-branch-weight", cl::Hidden, cl::init(1<< 20), cl::desc("The probability of a guard failing is assumed to be the ""reciprocal of this value (default = 1 << 20)"))
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
void setCallingConv(CallingConv::ID CC)
initializer< Ty > init(const Ty &Val)
A set of analyses that are preserved following a run of a transformation pass.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
FunctionPass class - This class is used to implement most global optimizations.
op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
static void MakeGuardControlFlowExplicit(Function *DeoptIntrinsic, CallInst *CI)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
LLVMContext & getContext() const
All values hold a context through their type.
Pass * createLowerGuardIntrinsicPass()
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
INITIALIZE_PASS(LowerGuardIntrinsicLegacyPass,"lower-guard-intrinsic","Lower the guard intrinsic to normal control flow", false, false) Pass *llvm
TerminatorInst * SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr)
Split the containing block at the specified instruction - everything before SplitBefore stays in the ...
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Module * getParent()
Get the module that this global value is contained inside of...
A container for an operand bundle being viewed as a set of values rather than a set of uses...
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
const BasicBlock * getParent() const
void initializeLowerGuardIntrinsicLegacyPassPass(PassRegistry &)
bool isVoidTy() const
Return true if this is 'void'.