38#define DEBUG_TYPE "ssaupdater"
47 : InsertedPHIs(NewPHI) {}
59 ProtoName = std::string(
Name);
71 assert(ProtoType &&
"Need to initialize SSAUpdater");
72 assert(ProtoType == V->getType() &&
73 "All rewritten values must have the same type");
79 unsigned PHINumValues =
PHI->getNumIncomingValues();
80 if (PHINumValues != ValueMapping.
size())
84 for (
unsigned i = 0, e = PHINumValues; i != e; ++i)
85 if (ValueMapping[
PHI->getIncomingBlock(i)] !=
86 PHI->getIncomingValue(i)) {
94 Value *Res = GetValueAtEndOfBlockInternal(BB);
107 Value *SingularValue =
nullptr;
112 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
113 for (
unsigned i = 0, e = SomePhi->getNumIncomingValues(); i != e; ++i) {
114 BasicBlock *PredBB = SomePhi->getIncomingBlock(i);
116 PredValues.
push_back(std::make_pair(PredBB, PredVal));
120 SingularValue = PredVal;
121 else if (PredVal != SingularValue)
122 SingularValue =
nullptr;
125 bool isFirstPred =
true;
128 PredValues.
push_back(std::make_pair(PredBB, PredVal));
132 SingularValue = PredVal;
134 }
else if (PredVal != SingularValue)
135 SingularValue =
nullptr;
140 if (PredValues.
empty())
145 return SingularValue;
149 if (isa<PHINode>(BB->
begin())) {
164 for (
const auto &PredValue : PredValues)
165 InsertedPHI->
addIncoming(PredValue.second, PredValue.first);
178 DL =
I->getDebugLoc();
182 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
204 if (
DbgValue->getParent() ==
I->getParent())
221 DbgValue->replaceVariableLocationOp(
I, NewVal);
261 :
PHI(
P), idx(
PHI->getNumIncomingValues()) {}
264 bool operator==(
const PHI_iterator& x)
const {
return idx == x.idx; }
273 return PHI_iterator(
PHI,
true);
308 PHI->addIncoming(Val, Pred);
313 return dyn_cast<PHINode>(Val);
320 if (
PHI &&
PHI->getNumIncomingValues() == 0)
339 if (
Value *V = AvailableVals[BB])
343 return Impl.GetValue(BB);
353 if (Insts.
empty())
return;
355 const Value *SomeVal;
356 if (
const LoadInst *LI = dyn_cast<LoadInst>(Insts[0]))
359 SomeVal = cast<StoreInst>(Insts[0])->getOperand(0);
361 if (BaseName.
empty())
373 UsesByBlock[
User->getParent()].push_back(
User);
386 if (BlockUses.
empty())
continue;
390 if (BlockUses.
size() == 1) {
403 bool HasStore =
false;
405 if (isa<StoreInst>(
I)) {
426 Value *StoredValue =
nullptr;
428 if (
LoadInst *L = dyn_cast<LoadInst>(&
I)) {
436 L->replaceAllUsesWith(StoredValue);
437 ReplacedLoads[L] = StoredValue;
444 if (
StoreInst *SI = dyn_cast<StoreInst>(&
I)) {
450 StoredValue = SI->getOperand(0);
455 assert(StoredValue &&
"Already checked that there is a store in block");
462 for (
LoadInst *ALoad : LiveInLoads) {
468 ALoad->replaceAllUsesWith(NewVal);
469 ReplacedLoads[ALoad] = NewVal;
487 assert(NewVal &&
"not a replaced load?");
493 while (RLI != ReplacedLoads.
end()) {
494 NewVal = RLI->second;
495 RLI = ReplacedLoads.
find(NewVal);
503 User->eraseFromParent();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
static AvailableValsTy & getAvailableVals(void *AV)
DenseMap< MachineBasicBlock *, Register > AvailableValsTy
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static AvailableValsTy & getAvailableVals(void *AV)
static bool IsEquivalentPHI(PHINode *PHI, SmallDenseMap< BasicBlock *, Value *, 8 > &ValueMapping)
This file defines the SmallVector class.
This defines the Use class.
Class recording the (high level) value of a variable.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
This represents the llvm.dbg.value instruction.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
An instruction for reading from memory.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
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...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Value * getIncomingValue()
BasicBlock * getIncomingBlock()
PHI_iterator(PHINode *P, bool)
PHI_iterator & operator++()
bool operator!=(const PHI_iterator &x) const
bool operator==(const PHI_iterator &x) const
static BlkSucc_iterator BlkSucc_end(BlkT *BB)
static BlkSucc_iterator BlkSucc_begin(BlkT *BB)
static void FindPredecessorBlocks(BasicBlock *BB, SmallVectorImpl< BasicBlock * > *Preds)
FindPredecessorBlocks - Put the predecessors of Info->BB into the Preds vector, set Info->NumPreds,...
static Value * CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds, SSAUpdater *Updater)
CreateEmptyPHI - Create a new PHI instruction in the specified block.
static PHINode * ValueIsNewPHI(Value *Val, SSAUpdater *Updater)
ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source operands, i....
static PHI_iterator PHI_begin(PhiT *PHI)
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.
static Value * GetPHIValue(PHINode *PHI)
GetPHIValue - For the specified PHI instruction, return the value that it defines.
static PHI_iterator PHI_end(PhiT *PHI)
static PHINode * ValueIsPHI(Value *Val, SSAUpdater *Updater)
ValueIsPHI - Check if a value is a PHI.
static Value * GetUndefVal(BasicBlock *BB, SSAUpdater *Updater)
GetUndefVal - Get an undefined value of the same type as the value being handled.
Helper class for SSA formation on a set of values defined in multiple blocks.
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
void RewriteUseAfterInsertions(Use &U)
Rewrite a use like RewriteUse but handling in-block definitions.
Value * FindValueForBlock(BasicBlock *BB) const
Return the value for the specified block if the SSAUpdater has one, otherwise return nullptr.
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
Value * GetValueInMiddleOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live in the middle of the specified block.
SSAUpdater(SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
If InsertedPHIs is specified, it will be filled in with all PHI Nodes created by rewriting.
void UpdateDebugValues(Instruction *I)
Rewrite debug value intrinsics to conform to a new SSA form.
bool HasValueForBlock(BasicBlock *BB) const
Return true if the SSAUpdater already has a value for the specified block.
Value * GetValueAtEndOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live at the end of the specified block.
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
The instances of the Type class are immutable: once they are created, they are never changed.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
StringRef getName() const
Return a constant reference to the value's name.
This is an optimization pass for GlobalISel generic memory operations.
Interval::succ_iterator succ_end(Interval *I)
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...
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SuccIterator< Instruction, BasicBlock > succ_iterator
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.