LLVM 19.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
24using namespace llvm;
25
27 // Check if we can cheaply rule out the possibility of not having any work to
28 // do.
29 auto *WCDecl = F.getParent()->getFunction(
30 Intrinsic::getName(Intrinsic::experimental_widenable_condition));
31 if (!WCDecl || WCDecl->use_empty())
32 return false;
33
34 using namespace llvm::PatternMatch;
36 // Traverse through the users of WCDecl.
37 // This is presumably cheaper than traversing all instructions in the
38 // function.
39 for (auto *U : WCDecl->users())
40 if (auto *CI = dyn_cast<CallInst>(U))
41 if (CI->getFunction() == &F)
42 ToLower.push_back(CI);
43
44 if (ToLower.empty())
45 return false;
46
47 for (auto *CI : ToLower) {
48 CI->replaceAllUsesWith(ConstantInt::getTrue(CI->getContext()));
49 CI->eraseFromParent();
50 }
51 return true;
52}
53
58
60}
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.
This file defines the SmallVector class.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:348
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:849
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
bool empty() const
Definition: SmallVector.h:94
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:1013
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)