40#define DEBUG_TYPE "lower-is-constant-intrinsic"
43 "Number of 'is.constant' intrinsic calls handled");
45 "Number of 'objectsize' intrinsic calls handled");
48 if (
auto *
C = dyn_cast<Constant>(II->
getOperand(0)))
49 if (
C->isManifestConstant())
57 bool HasDeadBlocks =
false;
65 UnsimplifiedUsers.
end());
67 for (
auto &VH : Worklist) {
68 BranchInst *BI = dyn_cast_or_null<BranchInst>(VH);
87 Other->removePredecessor(Source);
101 std::optional<DomTreeUpdater> DTU;
103 DTU.emplace(DT, DomTreeUpdater::UpdateStrategy::Lazy);
105 bool HasDeadBlocks =
false;
106 const auto &
DL =
F.getParent()->getDataLayout();
118 case Intrinsic::is_constant:
119 case Intrinsic::objectsize:
138 case Intrinsic::is_constant:
140 LLVM_DEBUG(
dbgs() <<
"Folding " << *II <<
" to " << *NewValue <<
"\n");
141 IsConstantIntrinsicsHandled++;
143 case Intrinsic::objectsize:
145 LLVM_DEBUG(
dbgs() <<
"Folding " << *II <<
" to " << *NewValue <<
"\n");
146 ObjectSizeIntrinsicsHandled++;
150 II, NewValue, DTU ? &*DTU :
nullptr);
154 return !Worklist.
empty();
184 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
186 if (
auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
187 DT = &DTWP->getDomTree();
199char LowerConstantIntrinsics::ID = 0;
201 "Lower constant intrinsics",
false,
false)
208 return new LowerConstantIntrinsics();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::optional< std::vector< StOtherPiece > > Other
static bool runOnFunction(Function &F, bool PostInlining)
expand Expand reduction intrinsics
This is the interface for a simple mod/ref and alias analysis over globals.
static bool lowerConstantIntrinsics(Function &F, const TargetLibraryInfo &TLI, DominatorTree *DT)
static bool replaceConditionalBranchesOnConstant(Instruction *II, Value *NewValue, DomTreeUpdater *DTU)
static Value * lowerIsConstantIntrinsic(IntrinsicInst *II)
The header file for the LowerConstantIntrinsics pass as used by the new pass manager.
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
This file implements a set that has insertion order iteration characteristics.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A container for analyses that lazily runs them and caches their results.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
BasicBlock * getSuccessor(unsigned i) const
bool isUnconditional() const
static ConstantInt * getTrue(LLVMContext &Context)
static ConstantInt * getFalse(LLVMContext &Context)
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
Analysis pass which computes a DominatorTree.
Legacy analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionPass class - This class is used to implement most global optimizations.
Legacy wrapper pass to provide the GlobalsAAResult object.
const BasicBlock * getParent() const
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserve()
Mark an analysis as preserved.
iterator end()
Get an iterator to the end of the SetVector.
iterator begin()
Get an iterator to the beginning of the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
Target - Wrapper for Target specific information.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
Value handle that is nullable, but tries to track the Value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
bool match(Val *V, const Pattern &P)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
This is an optimization pass for GlobalISel generic memory operations.
Value * lowerObjectSizeCall(IntrinsicInst *ObjectSize, const DataLayout &DL, const TargetLibraryInfo *TLI, bool MustSucceed)
Try to turn a call to @llvm.objectsize into an integer value of the given Type.
void initializeLowerConstantIntrinsicsPass(PassRegistry &)
bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, SmallSetVector< Instruction *, 8 > *UnsimplifiedUsers=nullptr)
Replace all uses of 'I' with 'SimpleV' and simplify the uses recursively.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createLowerConstantIntrinsicsPass()
bool pred_empty(const BasicBlock *BB)
bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Run the pass over the function.