39 #define DEBUG_TYPE "ssaupdater" 48 : InsertedPHIs(NewPHI) {}
73 assert(ProtoType &&
"Need to initialize SSAUpdater");
75 "All rewritten values must have the same type");
82 if (PHINumValues != ValueMapping.
size())
86 for (
unsigned i = 0, e = PHINumValues; i != e; ++i)
96 Value *Res = GetValueAtEndOfBlockInternal(BB);
109 Value *SingularValue =
nullptr;
114 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
115 for (
unsigned i = 0, e = SomePhi->getNumIncomingValues(); i != e; ++i) {
116 BasicBlock *PredBB = SomePhi->getIncomingBlock(i);
118 PredValues.
push_back(std::make_pair(PredBB, PredVal));
122 SingularValue = PredVal;
123 else if (PredVal != SingularValue)
124 SingularValue =
nullptr;
127 bool isFirstPred =
true;
131 PredValues.
push_back(std::make_pair(PredBB, PredVal));
135 SingularValue = PredVal;
137 }
else if (PredVal != SingularValue)
138 SingularValue =
nullptr;
143 if (PredValues.
empty())
148 return SingularValue;
152 if (isa<PHINode>(BB->
begin())) {
163 ProtoName, &BB->
front());
166 for (
const auto &PredValue : PredValues)
167 InsertedPHI->
addIncoming(PredValue.second, PredValue.first);
180 DL =
I->getDebugLoc();
184 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
194 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
201 if (OldVal != V && OldVal->hasValueHandle())
211 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
241 : PHI(P), idx(PHI->getNumIncomingValues()) {}
244 bool operator==(
const PHI_iterator& x)
const {
return idx == x.idx; }
253 return PHI_iterator(PHI,
true);
263 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
264 Preds->
append(SomePhi->block_begin(), SomePhi->block_end());
282 Updater->ProtoName, &BB->
front());
306 PHINode *PHI = ValueIsPHI(Val, Updater);
326 if (
Value *V = AvailableVals[BB])
340 if (Insts.
empty())
return;
342 const Value *SomeVal;
343 if (
const LoadInst *LI = dyn_cast<LoadInst>(Insts[0]))
346 SomeVal = cast<StoreInst>(Insts[0])->getOperand(0);
348 if (BaseName.
empty())
361 UsesByBlock[
User->getParent()].push_back(
User);
374 if (BlockUses.
empty())
continue;
378 if (BlockUses.
size() == 1) {
391 bool HasStore =
false;
393 if (isa<StoreInst>(
I)) {
414 Value *StoredValue =
nullptr;
416 if (
LoadInst *L = dyn_cast<LoadInst>(&
I)) {
424 L->replaceAllUsesWith(StoredValue);
425 ReplacedLoads[L] = StoredValue;
438 StoredValue =
SI->getOperand(0);
443 assert(StoredValue &&
"Already checked that there is a store in block");
450 for (
LoadInst *ALoad : LiveInLoads) {
457 ReplacedLoads[ALoad] = NewVal;
472 assert(NewVal &&
"not a replaced load?");
478 while (RLI != ReplacedLoads.
end()) {
479 NewVal = RLI->second;
480 RLI = ReplacedLoads.
find(NewVal);
488 User->eraseFromParent();
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
const_iterator end(StringRef path)
Get end iterator over path.
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...
This class represents lattice values for constants.
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 push_back(const T &Elt)
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.
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...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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. ...
Value * FindValueForBlock(BasicBlock *BB) const
Return the value for the specified block if the SSAUpdater has one, otherwise return nullptr...
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.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
SuccIterator< Instruction, BasicBlock > succ_iterator
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.