40 #define DEBUG_TYPE "ssaupdater"
48 : InsertedPHIs(NewPHI) {}
68 assert(ProtoType &&
"Need to initialize SSAUpdater");
70 "All rewritten values must have the same type");
77 if (PHINumValues != ValueMapping.
size())
81 for (
unsigned i = 0, e = PHINumValues; i != e; ++i)
91 Value *Res = GetValueAtEndOfBlockInternal(BB);
104 Value *SingularValue =
nullptr;
109 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
110 for (
unsigned i = 0, e = SomePhi->getNumIncomingValues(); i != e; ++i) {
111 BasicBlock *PredBB = SomePhi->getIncomingBlock(i);
113 PredValues.
push_back(std::make_pair(PredBB, PredVal));
117 SingularValue = PredVal;
118 else if (PredVal != SingularValue)
119 SingularValue =
nullptr;
122 bool isFirstPred =
true;
126 PredValues.
push_back(std::make_pair(PredBB, PredVal));
130 SingularValue = PredVal;
132 }
else if (PredVal != SingularValue)
133 SingularValue =
nullptr;
138 if (PredValues.
empty())
143 return SingularValue;
147 if (isa<PHINode>(BB->
begin())) {
160 ProtoName, &BB->
front());
163 for (
const auto &PredValue : PredValues)
164 InsertedPHI->
addIncoming(PredValue.second, PredValue.first);
177 DL =
I->getDebugLoc();
181 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
183 DEBUG(
dbgs() <<
" Inserted PHI: " << *InsertedPHI <<
"\n");
191 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
198 if (OldVal != V && OldVal->hasValueHandle())
208 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
238 : PHI(P), idx(PHI->getNumIncomingValues()) {}
241 bool operator==(
const PHI_iterator& x)
const {
return idx == x.idx; }
250 return PHI_iterator(PHI,
true);
260 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
261 Preds->
append(SomePhi->block_begin(), SomePhi->block_end());
279 Updater->ProtoName, &BB->
front());
304 PHINode *PHI = ValueIsPHI(Val, Updater);
324 if (
Value *V = AvailableVals[BB])
328 return Impl.GetValue(BB);
338 if (Insts.
empty())
return;
340 const Value *SomeVal;
341 if (
const LoadInst *LI = dyn_cast<LoadInst>(Insts[0]))
344 SomeVal = cast<StoreInst>(Insts[0])->getOperand(0);
346 if (BaseName.
empty())
359 UsesByBlock[
User->getParent()].push_back(
User);
372 if (BlockUses.
empty())
continue;
376 if (BlockUses.
size() == 1) {
389 bool HasStore =
false;
391 if (isa<StoreInst>(
I)) {
412 Value *StoredValue =
nullptr;
422 L->replaceAllUsesWith(StoredValue);
423 ReplacedLoads[
L] = StoredValue;
436 StoredValue =
SI->getOperand(0);
441 assert(StoredValue &&
"Already checked that there is a store in block");
448 for (
LoadInst *ALoad : LiveInLoads) {
455 ReplacedLoads[ALoad] = NewVal;
470 assert(NewVal &&
"not a replaced load?");
476 while (RLI != ReplacedLoads.
end()) {
477 NewVal = RLI->second;
478 RLI = ReplacedLoads.
find(NewVal);
486 User->eraseFromParent();
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
Helper class for SSA formation on a set of values defined in multiple blocks.
static BlkSucc_iterator BlkSucc_end(BlkT *BB)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static void AddPHIOperand(PHINode *PHI, Value *Val, BasicBlock *Pred)
AddPHIOperand - Add the specified value as an operand of the PHI for the specified predecessor block...
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
succ_iterator BlkSucc_iterator
static BlkSucc_iterator BlkSucc_begin(BlkT *BB)
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
static Value * CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds, SSAUpdater *Updater)
CreateEmptyPHI - Create a new PHI instruction in the specified block.
const Instruction & front() const
An instruction for reading from memory.
This defines the Use class.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
static PHINode * InstrIsPHI(Instruction *I)
InstrIsPHI - Check if an instruction is a PHI.
A Use represents the edge between a Value definition and its users.
PHI_iterator(PHINode *P, bool)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
SSAUpdater(SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
If InsertedPHIs is specified, it will be filled in with all PHI Nodes created by rewriting.
static PHI_iterator PHI_begin(PhiT *PHI)
LLVM_NODISCARD bool empty() const
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool operator==(const PHI_iterator &x) const
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static void ValueIsRAUWd(Value *Old, Value *New)
DenseMap< BasicBlock *, Value * > AvailableValsTy
static Value * GetUndefVal(BasicBlock *BB, SSAUpdater *Updater)
GetUndefVal - Get an undefined value of the same type as the value being handled. ...
Interval::succ_iterator succ_end(Interval *I)
unsigned getNumIncomingValues() const
Return the number of incoming edges.
iterator find(const_arg_type_t< KeyT > Val)
Value * GetValueInMiddleOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live in the middle of the specified block...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
void RewriteUseAfterInsertions(Use &U)
Rewrite a use like RewriteUse but handling in-block definitions.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
BasicBlock * getIncomingBlock()
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Interval::pred_iterator pred_end(Interval *I)
bool HasValueForBlock(BasicBlock *BB) const
Return true if the SSAUpdater already has a value for the specified block.
bool empty() const
empty - Check if the array is empty.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static AvailableValsTy & getAvailableVals(void *AV)
static PHINode * ValueIsPHI(Value *Val, SSAUpdater *Updater)
ValueIsPHI - Check if a value is a PHI.
Iterator for intrusive lists based on ilist_node.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
Value * getIncomingValue()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
static void FindPredecessorBlocks(BasicBlock *BB, SmallVectorImpl< BasicBlock * > *Preds)
FindPredecessorBlocks - Put the predecessors of Info->BB into the Preds vector, set Info->NumPreds...
static bool IsEquivalentPHI(PHINode *PHI, SmallDenseMap< BasicBlock *, Value *, 8 > &ValueMapping)
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...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Helper struct that represents how a value is mapped through different register banks.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static PHI_iterator PHI_end(PhiT *PHI)
StringRef - Represent a constant reference to a string, i.e.
bool operator==(uint64_t V1, const APInt &V2)
Value * GetValueAtEndOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live at the end of the specified block...
bool operator!=(const PHI_iterator &x) const
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
static Value * GetPHIValue(PHINode *PHI)
GetPHIValue - For the specified PHI instruction, return the value that it defines.
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
static PHINode * ValueIsNewPHI(Value *Val, SSAUpdater *Updater)
ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source operands, i...
const BasicBlock * getParent() const
PHI_iterator & operator++()
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.