Go to the documentation of this file.
62 #define DEBUG_TYPE "ppc-bool-ret-to-int"
65 "Number of times a bool feeding a RetInst was promoted to an int");
67 "Number of times a bool feeding a CallInst was promoted to an int");
69 "Total number of times a bool was promoted to an int");
75 WorkList.push_back(V);
77 while (!WorkList.empty()) {
79 auto *CurrUser = dyn_cast<User>(Curr);
82 if (CurrUser && !isa<CallInst>(Curr) && !isa<Constant>(Curr))
83 for (
auto &
Op : CurrUser->operands())
85 WorkList.push_back(
Op);
93 "Expect an i1 value");
96 :
Type::getInt32Ty(V->getContext());
98 if (
auto *
C = dyn_cast<Constant>(V))
100 if (
auto *
P = dyn_cast<PHINode>(V)) {
106 for (
unsigned i = 0;
i <
P->getNumOperands(); ++
i)
111 auto *
A = dyn_cast<Argument>(V);
112 auto *
I = dyn_cast<Instruction>(V);
113 assert((A ||
I) &&
"Unknown value type");
116 A ? &*
A->getParent()->getEntryBlock().begin() :
I->getNextNode();
117 return new ZExtInst(V, IntTy,
"", InstPt);
130 static PHINodeSet getPromotablePHINodes(
const Function &
F) {
131 PHINodeSet Promotable;
135 if (
const auto *
P = dyn_cast<PHINode>(&
I))
136 if (
P->getType()->isIntegerTy(1))
140 for (
const PHINode *
P : Promotable) {
142 auto IsValidUser = [] (
const Value *V) ->
bool {
143 return isa<ReturnInst>(V) || isa<CallInst>(V) || isa<PHINode>(V) ||
144 isa<DbgInfoIntrinsic>(V);
146 auto IsValidOperand = [] (
const Value *V) ->
bool {
147 return isa<Constant>(V) || isa<Argument>(V) || isa<CallInst>(V) ||
150 const auto &
Users =
P->users();
158 auto IsPromotable = [&Promotable] (
const Value *V) ->
bool {
159 const auto *Phi = dyn_cast<PHINode>(V);
160 return !Phi || Promotable.count(Phi);
164 Promotable.erase(
User);
167 for (
const PHINode *
P : Promotable) {
169 const auto &
Users =
P->users();
193 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
198 ST =
TM.getSubtargetImpl(
F);
200 PHINodeSet PromotablePHINodes = getPromotablePHINodes(
F);
202 bool Changed =
false;
205 if (
auto *R = dyn_cast<ReturnInst>(&
I))
206 if (
F.getReturnType()->isIntegerTy(1))
208 runOnUse(
R->getOperandUse(0), PromotablePHINodes, Bool2IntMap);
210 if (
auto *CI = dyn_cast<CallInst>(&
I))
211 for (
auto &U : CI->operands())
212 if (U->getType()->isIntegerTy(1))
213 Changed |= runOnUse(U, PromotablePHINodes, Bool2IntMap);
220 bool runOnUse(
Use &U,
const PHINodeSet &PromotablePHINodes,
221 B2IMap &BoolToIntMap) {
222 auto Defs = findAllDefs(U);
231 for (
Value *V : Defs)
232 if (!isa<PHINode>(V) && !isa<Constant>(V) &&
233 !isa<Argument>(V) && !isa<CallInst>(V))
236 for (
Value *V : Defs)
237 if (
const auto *
P = dyn_cast<PHINode>(V))
238 if (!PromotablePHINodes.count(
P))
241 if (isa<ReturnInst>(U.
getUser()))
242 ++NumBoolRetPromotion;
243 if (isa<CallInst>(U.
getUser()))
244 ++NumBoolCallPromotion;
245 ++NumBoolToIntPromotion;
247 for (
Value *V : Defs)
248 if (!BoolToIntMap.count(V))
249 BoolToIntMap[V] = translate(V);
253 for (
auto &Pair : BoolToIntMap) {
254 auto *
First = dyn_cast<User>(Pair.first);
255 auto *Second = dyn_cast<User>(Pair.second);
256 assert((!First || Second) &&
"translated from user to non-user!?");
259 if (First && !isa<CallInst>(First) && !isa<Constant>(First))
260 for (
unsigned i = 0;
i <
First->getNumOperands(); ++
i)
261 Second->setOperand(
i, BoolToIntMap[
First->getOperand(
i)]);
264 Value *IntRetVal = BoolToIntMap[U];
266 auto *
I = cast<Instruction>(U.
getUser());
286 "Convert i1 constants to i32/i64 if they are returned",
false,
This is an optimization pass for GlobalISel generic memory operations.
static IntegerType * getInt1Ty(LLVMContext &C)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
ReachingDefAnalysis InstSet & ToRemove
FunctionPass * createPPCBoolRetToIntPass()
The instances of the Type class are immutable: once they are created, they are never changed.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
LLVM_NODISCARD T pop_back_val()
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
(vector float) vec_cmpeq(*A, *B) C
Represent the analysis usage information of a pass.
into llvm powi allowing the code generator to produce balanced multiplication trees First
Legacy analysis pass which computes a DominatorTree.
STATISTIC(NumFunctions, "Total number of functions")
User * getUser() const
Returns the User that contains this Use.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
mir Rename Register Operands
This class represents a truncation of integer types.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents zero extension of integer types.
Type * getType() const
All values are typed, get the type of this value.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVMContext & getContext() const
All values hold a context through their type.
static bool runOnFunction(Function &F, bool PostInlining)
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
INITIALIZE_PASS(PPCBoolRetToInt, "ppc-bool-ret-to-int", "Convert i1 constants to i32/i64 if they are returned", false, false) FunctionPass *llvm
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
Common code between 32-bit and 64-bit PowerPC targets.
void initializePPCBoolRetToIntPass(PassRegistry &)
iv Induction Variable Users
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const char LLVMTargetMachineRef TM
FunctionPass class - This class is used to implement most global optimizations.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
LLVM Value Representation.
A Use represents the edge between a Value definition and its users.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.