39 #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())) {
158 ProtoName, &BB->
front());
161 for (
const auto &PredValue : PredValues)
162 InsertedPHI->
addIncoming(PredValue.second, PredValue.first);
175 DL =
I->getDebugLoc();
179 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
189 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
196 if (OldVal != V && OldVal->hasValueHandle())
206 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
236 : PHI(P), idx(PHI->getNumIncomingValues()) {}
239 bool operator==(
const PHI_iterator& x)
const {
return idx == x.idx; }
248 return PHI_iterator(PHI,
true);
258 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
259 Preds->
append(SomePhi->block_begin(), SomePhi->block_end());
277 Updater->ProtoName, &BB->
front());
301 PHINode *PHI = ValueIsPHI(Val, Updater);
321 if (
Value *V = AvailableVals[BB])
335 if (Insts.
empty())
return;
337 const Value *SomeVal;
338 if (
const LoadInst *LI = dyn_cast<LoadInst>(Insts[0]))
341 SomeVal = cast<StoreInst>(Insts[0])->getOperand(0);
343 if (BaseName.
empty())
356 UsesByBlock[
User->getParent()].push_back(
User);
369 if (BlockUses.
empty())
continue;
373 if (BlockUses.
size() == 1) {
386 bool HasStore =
false;
388 if (isa<StoreInst>(
I)) {
409 Value *StoredValue =
nullptr;
411 if (
LoadInst *L = dyn_cast<LoadInst>(&
I)) {
419 L->replaceAllUsesWith(StoredValue);
420 ReplacedLoads[L] = StoredValue;
433 StoredValue =
SI->getOperand(0);
438 assert(StoredValue &&
"Already checked that there is a store in block");
445 for (
LoadInst *ALoad : LiveInLoads) {
452 ReplacedLoads[ALoad] = NewVal;
467 assert(NewVal &&
"not a replaced load?");
473 while (RLI != ReplacedLoads.
end()) {
474 NewVal = RLI->second;
475 RLI = ReplacedLoads.
find(NewVal);
483 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.
DenseMap< BasicBlock *, Value * > AvailableValsTy
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...
Compute iterated dominance frontiers using a linear time algorithm.
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
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.
ValT GetValue(BlkT *BB)
GetValue - Check to see if AvailableVals has an entry for the specified BB and if so...
An instruction for reading from memory.
TerminatorInst::SuccIterator< TerminatorInst *, BasicBlock > succ_iterator
This defines the Use class.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
iterator begin()
Instruction iterator methods.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
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...
static PHI_iterator PHI_begin(PhiT *PHI)
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...
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
Type * getType() const
All values are typed, get the type of this value.
bool operator==(const PHI_iterator &x) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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)
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)
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...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
SSAUpdater(SmallVectorImpl< PHINode *> *InsertedPHIs=nullptr)
If InsertedPHIs is specified, it will be filled in with all PHI Nodes created by rewriting.
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()
Interval::pred_iterator pred_end(Interval *I)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static AvailableValsTy & getAvailableVals(void *AV)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
static PHINode * ValueIsPHI(Value *Val, SSAUpdater *Updater)
ValueIsPHI - Check if a value is a PHI.
static void FindPredecessorBlocks(BasicBlock *BB, SmallVectorImpl< BasicBlock *> *Preds)
FindPredecessorBlocks - Put the predecessors of Info->BB into the Preds vector, set Info->NumPreds...
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.
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...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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)
bool operator!=(const PHI_iterator &x) const
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...
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...
bool empty() const
empty - Check if the array is empty.
const BasicBlock * getParent() const
bool HasValueForBlock(BasicBlock *BB) const
Return true if the SSAUpdater already has a value for the specified block.
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.