60#define DEBUG_TYPE "ppc-bool-ret-to-int"
63 "Number of times a bool feeding a RetInst was promoted to an int");
65 "Number of times a bool feeding a CallInst was promoted to an int");
67 "Total number of times a bool was promoted to an int");
75 while (!WorkList.
empty()) {
81 for (
auto &
Op : CurrUser->operands())
90 assert(
V->getType() == Type::getInt1Ty(
V->getContext()) &&
91 "Expect an i1 value");
93 Type *IntTy = ST->isPPC64() ? Type::getInt64Ty(
V->getContext())
102 for (
unsigned I = 0;
I <
P->getNumOperands(); ++
I)
109 IRB.SetInsertPoint(
I->getNextNode());
111 IRB.SetInsertPoint(&Func->getEntryBlock(), Func->getEntryBlock().begin());
112 return IRB.CreateZExt(V, IntTy);
115 typedef SmallPtrSet<const PHINode *, 8> PHINodeSet;
125 static PHINodeSet getPromotablePHINodes(
const Function &
F) {
126 PHINodeSet Promotable;
131 if (
P->getType()->isIntegerTy(1))
132 Promotable.insert(
P);
135 for (
const PHINode *
P : Promotable) {
137 auto IsValidUser = [] (
const Value *
V) ->
bool {
140 auto IsValidOperand = [] (
const Value *
V) ->
bool {
144 const auto &
Users =
P->users();
152 auto IsPromotable = [&Promotable] (
const Value *
V) ->
bool {
154 return !
Phi || Promotable.count(Phi);
158 Promotable.erase(User);
161 for (
const PHINode *
P : Promotable) {
163 const auto &
Users =
P->users();
174 typedef DenseMap<Value *, Value *> B2IMap;
179 PPCBoolRetToInt() : FunctionPass(ID) {}
185 auto *TPC = getAnalysisIfAvailable<TargetPassConfig>();
189 auto &
TM = TPC->getTM<PPCTargetMachine>();
190 ST =
TM.getSubtargetImpl(
F);
193 PHINodeSet PromotablePHINodes = getPromotablePHINodes(
F);
199 if (
F.getReturnType()->isIntegerTy(1))
201 runOnUse(
R->getOperandUse(0), PromotablePHINodes, Bool2IntMap);
204 for (
auto &U : CI->operands())
205 if (
U->getType()->isIntegerTy(1))
206 Changed |= runOnUse(U, PromotablePHINodes, Bool2IntMap);
213 bool runOnUse(Use &U,
const PHINodeSet &PromotablePHINodes,
214 B2IMap &BoolToIntMap) {
215 auto Defs = findAllDefs(U);
224 for (
Value *V : Defs)
229 for (
Value *V : Defs)
231 if (!PromotablePHINodes.count(
P))
235 ++NumBoolRetPromotion;
237 ++NumBoolCallPromotion;
238 ++NumBoolToIntPromotion;
240 for (
Value *V : Defs) {
241 auto [It,
Inserted] = BoolToIntMap.try_emplace(V);
243 It->second = translate(V);
248 for (
auto &Pair : BoolToIntMap) {
251 assert((!
First || Second) &&
"translated from user to non-user!?");
255 for (
unsigned I = 0;
I <
First->getNumOperands(); ++
I)
256 Second->setOperand(
I, BoolToIntMap[
First->getOperand(
I)]);
259 Value *IntRetVal = BoolToIntMap[
U];
260 Type *Int1Ty = Type::getInt1Ty(
U->getContext());
263 new TruncInst(IntRetVal, Int1Ty,
"backToBool",
I->getIterator());
269 void getAnalysisUsage(AnalysisUsage &AU)
const override {
271 FunctionPass::getAnalysisUsage(AU);
275 const PPCSubtarget *ST;
281char PPCBoolRetToInt::ID = 0;
283 "Convert i1 constants to i32/i64 if they are returned",
false,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ReachingDefAnalysis InstSet & ToRemove
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
This defines the Use class.
iv Induction Variable Users
mir Rename Register Operands
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Target-Independent Code Generator Pass Configuration Options pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
FunctionPass class - This class is used to implement most global optimizations.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
NodeAddr< PhiNode * > Phi
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
FunctionPass * createPPCBoolRetToIntPass()