LLVM 18.0.0git
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
16#include "llvm/IR/Function.h"
19#include "llvm/IR/Intrinsics.h"
20#include "llvm/IR/Module.h"
23#include "llvm/Pass.h"
25
26using namespace llvm;
27
28namespace {
29struct LowerWidenableConditionLegacyPass : public FunctionPass {
30 static char ID;
31 LowerWidenableConditionLegacyPass() : FunctionPass(ID) {
34 }
35
36 bool runOnFunction(Function &F) override;
37};
38}
39
41 // Check if we can cheaply rule out the possibility of not having any work to
42 // do.
43 auto *WCDecl = F.getParent()->getFunction(
44 Intrinsic::getName(Intrinsic::experimental_widenable_condition));
45 if (!WCDecl || WCDecl->use_empty())
46 return false;
47
48 using namespace llvm::PatternMatch;
50 // Traverse through the users of WCDecl.
51 // This is presumably cheaper than traversing all instructions in the
52 // function.
53 for (auto *U : WCDecl->users())
54 if (auto *CI = dyn_cast<CallInst>(U))
55 if (CI->getFunction() == &F)
56 ToLower.push_back(CI);
57
58 if (ToLower.empty())
59 return false;
60
61 for (auto *CI : ToLower) {
62 CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getContext()));
63 CI->eraseFromParent();
64 }
65 return true;
66}
67
68bool LowerWidenableConditionLegacyPass::runOnFunction(Function &F) {
70}
71
72char LowerWidenableConditionLegacyPass::ID = 0;
73INITIALIZE_PASS(LowerWidenableConditionLegacyPass, "lower-widenable-condition",
74 "Lower the widenable condition to default true value", false,
75 false)
76
78 return new LowerWidenableConditionLegacyPass();
79}
80
85
87}
static bool lowerWidenableCondition(Function &F)
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
This file defines the SmallVector class.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:833
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
bool empty() const
Definition: SmallVector.h:94
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:988
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeLowerWidenableConditionLegacyPassPass(PassRegistry &)
Pass * createLowerWidenableConditionPass()
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)