LLVM: lib/IR/ReplaceConstant.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
18
19using namespace llvm;
20
24
29 Instruction *ConstInst = CE->getAsInstruction();
30 ConstInst->insertBefore(*InsertPt->getParent(), InsertPt);
34 for (auto [Idx, Op] : enumerate(C->operands())) {
37 }
41 for (auto [Idx, Op] : enumerate(C->operands())) {
43 InsertPt);
45 }
46 } else {
48 }
49}
50
53 bool RemoveDeadConstants,
54 bool IncludeSelf) {
55
59 "should not be expanding trivial constant users");
60
61 if (IncludeSelf) {
63 Stack.push_back(C);
64 } else {
68 }
69 }
70
71
73 while (!Stack.empty()) {
74 Constant *C = Stack.pop_back_val();
75 if (!ExpandableUsers.insert(C))
76 continue;
77
78 for (auto *Nested : C->users())
81 }
82
83
85 for (Constant *C : ExpandableUsers)
88 if (!RestrictToFunc || I->getFunction() == RestrictToFunc)
90
91
93
94
95
97 ConstantToInstructionMap;
101 for (Use &U : I->operands()) {
104 BasicBlock *BB = Phi->getIncomingBlock(U);
106 assert(BI != BB->end() && "Unexpected empty basic block");
107 }
108
110 if (ExpandableUsers.contains(C)) {
113 ConstantToInstructionMap[std::make_pair(C, BI->getParent())];
114
115
116
117
118 if (NewInsts.empty() || BI->comesBefore(NewInsts.front()))
120 for (auto *NI : NewInsts)
121 NI->setDebugLoc(Loc);
123 U.set(NewInsts.back());
124 }
125 }
126 }
127 }
128
129 if (RemoveDeadConstants)
131 C->removeDeadConstantUsers();
132
134}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isExpandableUser(User *U)
Definition ReplaceConstant.cpp:21
static void expandUser(BasicBlock::iterator InsertPt, Constant *C, SmallVector< Instruction *, 4 > &NewInsts)
Definition ReplaceConstant.cpp:25
This file implements a set that has insertion order iteration characteristics.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
LLVM_ABI 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...
This is an important base class in LLVM.
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
InstructionWorklist - This is the worklist management logic for InstCombine and other simplification ...
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
static LLVM_ABI 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_arg_type key) const
Check if the SetVector contains the given key.
bool insert(const value_type &X)
Insert a new element into the SetVector.
void push_back(const T &Elt)
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 LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
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.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI bool convertUsersOfConstantsToInstructions(ArrayRef< Constant * > Consts, Function *RestrictToFunc=nullptr, bool RemoveDeadConstants=true, bool IncludeSelf=false)
Replace constant expressions users of the given constants with instructions.
Definition ReplaceConstant.cpp:51
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.