26 std::map<Use *, std::vector<std::vector<ConstantExpr *>>> CEPaths;
36 std::map<
Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths,
40 for (
Use &U :
I->operands()) {
43 if (!CEPaths.count(&U))
49 if (
auto *Phi = dyn_cast<PHINode>(
I)) {
57 auto &
Paths = CEPaths[&U];
58 for (
auto &Path :
Paths) {
59 for (
auto *CE : Path) {
63 if (!Visited.
count(CE)) {
67 NI = CE->getAsInstruction(BI);
81 assert(NI &&
"Expected an instruction corresponding to constant "
86 II->replaceUsesOfWith(CE, NI);
93 for (
auto Item : Visited)
94 Item.first->removeDeadConstantUsers();
99 std::map<
Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths) {
100 for (
Use &U :
I->operands()) {
102 auto *CE2 = dyn_cast<ConstantExpr>(U.get());
107 std::vector<std::vector<ConstantExpr *>>
Paths;
110 std::vector<ConstantExpr *> Path{CE2};
111 std::vector<std::vector<ConstantExpr *>> Stack{Path};
112 while (!Stack.empty()) {
113 std::vector<ConstantExpr *> TPath = Stack.back();
115 auto *CE3 = TPath.back();
118 Paths.push_back(TPath);
122 for (
auto &UU : CE3->operands()) {
123 if (
auto *CE4 = dyn_cast<ConstantExpr>(UU.get())) {
124 std::vector<ConstantExpr *> NPath(TPath.begin(), TPath.end());
125 NPath.push_back(CE4);
126 Stack.push_back(NPath);
138 return isa<ConstantExpr>(U) || isa<ConstantAggregate>(U);
142 if (
auto *CE = dyn_cast<ConstantExpr>(
C)) {
143 return CE->getAsInstruction(InsertPt);
144 }
else if (isa<ConstantStruct>(
C) || isa<ConstantArray>(
C)) {
148 return cast<Instruction>(V);
149 }
else if (isa<ConstantVector>(
C)) {
155 return cast<Instruction>(V);
165 for (
User *U :
C->users())
167 Stack.push_back(cast<Constant>(U));
171 while (!Stack.empty()) {
173 if (!ExpandableUsers.
insert(
C))
176 for (
auto *Nested :
C->users())
178 Stack.push_back(cast<Constant>(Nested));
184 for (
User *U :
C->users())
185 if (
auto *
I = dyn_cast<Instruction>(U))
189 bool Changed =
false;
192 for (
Use &U :
I->operands()) {
194 if (
auto *Phi = dyn_cast<PHINode>(
I)) {
197 assert(It != BB->
end() &&
"Unexpected empty basic block");
201 if (
auto *
C = dyn_cast<Constant>(U.get())) {
213 C->removeDeadConstantUsers();
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
InstListType::iterator iterator
Instruction iterators...
A constant value that is initialized with an expression using other constant values.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
This is an important base class in LLVM.
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
InstructionWorklist - This is the worklist management logic for InstCombine and other simplification ...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A vector that has set insertion semantics.
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt32Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
bool convertUsersOfConstantsToInstructions(ArrayRef< Constant * > Consts)
Replace constant expressions users of the given constants with instructions.
static Instruction * expandUser(Instruction *InsertPt, Constant *C)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
static bool isExpandableUser(User *U)
void collectConstantExprPaths(Instruction *I, ConstantExpr *CE, std::map< Use *, std::vector< std::vector< ConstantExpr * > > > &CEPaths)
Given an instruction I which uses given constant expression CE as operand, either directly or nested ...
void convertConstantExprsToInstructions(Instruction *I, ConstantExpr *CE, SmallPtrSetImpl< Instruction * > *Insts=nullptr)
The given instruction I contains given constant expression CE as one of its operands,...