14 #define DEBUG_TYPE "ssaupdater"
39 : AV(0), ProtoType(0), ProtoName(), InsertedPHIs(NewPHI) {}
59 assert(ProtoType != 0 &&
"Need to initialize SSAUpdater");
60 assert(ProtoType == V->
getType() &&
61 "All rewritten values must have the same type");
68 if (PHINumValues != ValueMapping.
size())
72 for (
unsigned i = 0, e = PHINumValues; i != e; ++i)
82 Value *Res = GetValueAtEndOfBlockInternal(BB);
95 Value *SingularValue = 0;
100 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
101 for (
unsigned i = 0, e = SomePhi->getNumIncomingValues(); i != e; ++i) {
102 BasicBlock *PredBB = SomePhi->getIncomingBlock(i);
104 PredValues.
push_back(std::make_pair(PredBB, PredVal));
108 SingularValue = PredVal;
109 else if (PredVal != SingularValue)
113 bool isFirstPred =
true;
117 PredValues.
push_back(std::make_pair(PredBB, PredVal));
121 SingularValue = PredVal;
123 }
else if (PredVal != SingularValue)
129 if (PredValues.
empty())
133 if (SingularValue != 0)
134 return SingularValue;
138 if (isa<PHINode>(BB->
begin())) {
151 ProtoName, &BB->
front());
154 for (
unsigned i = 0, e = PredValues.
size(); i != e; ++i)
155 InsertedPHI->
addIncoming(PredValues[i].second, PredValues[i].first);
167 DL =
I->getDebugLoc();
171 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
173 DEBUG(
dbgs() <<
" Inserted PHI: " << *InsertedPHI <<
"\n");
181 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
188 if (OldVal != V && OldVal->hasValueHandle())
198 if (
PHINode *UserPN = dyn_cast<PHINode>(User))
227 :
PHI(P), idx(
PHI->getNumIncomingValues()) {}
230 bool operator==(
const PHI_iterator& x)
const {
return idx == x.idx; }
238 return PHI_iterator(PHI,
true);
248 if (
PHINode *SomePhi = dyn_cast<PHINode>(BB->
begin())) {
249 for (
unsigned PI = 0, E = SomePhi->getNumIncomingValues(); PI != E; ++PI)
250 Preds->
push_back(SomePhi->getIncomingBlock(PI));
268 Updater->ProtoName, &BB->
front());
313 if (
Value *V = AvailableVals[BB])
317 return Impl.GetValue(BB);
327 if (Insts.
empty())
return;
330 if (
LoadInst *
LI = dyn_cast<LoadInst>(Insts[0]))
333 SomeVal = cast<StoreInst>(Insts[0])->getOperand(0);
335 if (BaseName.
empty())
349 for (
unsigned i = 0, e = Insts.
size(); i != e; ++i) {
351 UsesByBlock[User->
getParent()].push_back(User);
360 for (
unsigned i = 0, e = Insts.
size(); i != e; ++i) {
366 if (BlockUses.
empty())
continue;
370 if (BlockUses.
size() == 1) {
372 if (
StoreInst *SI = dyn_cast<StoreInst>(User)) {
377 LiveInLoads.
push_back(cast<LoadInst>(User));
383 bool HasStore =
false;
384 for (
unsigned i = 0, e = BlockUses.
size(); i != e; ++i) {
385 if (isa<StoreInst>(BlockUses[i])) {
395 for (
unsigned i = 0, e = BlockUses.
size(); i != e; ++i)
396 LiveInLoads.
push_back(cast<LoadInst>(BlockUses[i]));
406 Value *StoredValue = 0;
408 if (
LoadInst *L = dyn_cast<LoadInst>(II)) {
416 L->replaceAllUsesWith(StoredValue);
417 ReplacedLoads[L] = StoredValue;
424 if (
StoreInst *SI = dyn_cast<StoreInst>(II)) {
430 StoredValue = SI->getOperand(0);
435 assert(StoredValue &&
"Already checked that there is a store in block");
442 for (
unsigned i = 0, e = LiveInLoads.
size(); i != e; ++i) {
450 ReplacedLoads[ALoad] = NewVal;
458 for (
unsigned i = 0, e = Insts.
size(); i != e; ++i) {
466 Value *NewVal = ReplacedLoads[User];
467 assert(NewVal &&
"not a replaced load?");
473 while (RLI != ReplacedLoads.
end()) {
474 NewVal = RLI->second;
475 RLI = ReplacedLoads.
find(NewVal);
491 return std::find(Insts.
begin(), Insts.
end(),
I) != Insts.
end();
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)
static void AddPHIOperand(PHINode *PHI, Value *Val, BasicBlock *Pred)
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)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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)
const Instruction & front() const
void setDebugLoc(const DebugLoc &Loc)
setDebugLoc - Set the debug location information for this instruction.
LoopInfoBase< BlockT, LoopT > * LI
StringRef getName() const
static PHINode * InstrIsPHI(Instruction *I)
PHI_iterator(PHINode *P, bool)
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static PHI_iterator PHI_begin(PhiT *PHI)
Interval::succ_iterator succ_begin(Interval *I)
bool operator==(const PHI_iterator &x) const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
void replaceAllUsesWith(Value *V)
static void ValueIsRAUWd(Value *Old, Value *New)
DenseMap< BasicBlock *, Value * > AvailableValsTy
static Value * GetUndefVal(BasicBlock *BB, SSAUpdater *Updater)
Interval::succ_iterator succ_end(Interval *I)
unsigned getNumIncomingValues() const
Value * GetValueInMiddleOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live in the middle of the specified block...
LLVM Basic Block Representation.
void RewriteUseAfterInsertions(Use &U)
Rewrite a use like RewriteUse but handling in-block definitions.
Interval::pred_iterator pred_begin(Interval *I)
BasicBlock * getIncomingBlock()
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
BasicBlock * getIncomingBlock(unsigned i) const
SSAUpdater(SmallVectorImpl< PHINode * > *InsertedPHIs=0)
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 count(const KeyT &Val) const
count - Return true if the specified key is in the map.
static UndefValue * get(Type *T)
Value * SimplifyInstruction(Instruction *I, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
static AvailableValsTy & getAvailableVals(void *AV)
static PHINode * ValueIsPHI(Value *Val, SSAUpdater *Updater)
Value * getIncomingValue(unsigned i) const
Value * getIncomingValue()
static void FindPredecessorBlocks(BasicBlock *BB, SmallVectorImpl< BasicBlock * > *Preds)
static bool IsEquivalentPHI(PHINode *PHI, SmallDenseMap< BasicBlock *, Value *, 8 > &ValueMapping)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
LLVM Value Representation.
static PHI_iterator PHI_end(PhiT *PHI)
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
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
iterator find(const KeyT &Val)
static Value * GetPHIValue(PHINode *PHI)
static PHINode * ValueIsNewPHI(Value *Val, SSAUpdater *Updater)
const BasicBlock * getParent() const
bool empty() const
empty - Check if the string is empty.
PHI_iterator & operator++()