llvm.org GIT mirror llvm / 8c0c990
Speculatively revert r97010, "Add an argument to PHITranslateValue to specify the DominatorTree. ...", in hopes of restoring poor old PPC bootstrap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97027 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
4 changed file(s) with 50 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
6565 bool IsPotentiallyPHITranslatable() const;
6666
6767 /// PHITranslateValue - PHI translate the current address up the CFG from
68 /// CurBB to Pred, updating our state to reflect any needed changes. If the
69 /// dominator tree DT is non-null, the translated value must dominate
70 /// PredBB. This returns true on failure and sets Addr to null.
71 bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
72 const DominatorTree *DT);
68 /// CurBB to Pred, updating our state the reflect any needed changes. This
69 /// returns true on failure and sets Addr to null.
70 bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB);
7371
7472 /// PHITranslateWithInsertion - PHI translate this value into the specified
7573 /// predecessor block, inserting a computation of the value if it is
8987 /// returns false.
9088 bool Verify() const;
9189 private:
92 Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB,
93 const DominatorTree *DT);
90 Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB);
91
92
93 /// GetAvailablePHITranslatedSubExpr - Return the value computed by
94 /// PHITranslateSubExpr if it dominates PredBB, otherwise return null.
95 Value *GetAvailablePHITranslatedSubExpr(Value *V,
96 BasicBlock *CurBB, BasicBlock *PredBB,
97 const DominatorTree &DT) const;
9498
9599 /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated
96100 /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
860860 // Get the PHI translated pointer in this predecessor. This can fail if
861861 // not translatable, in which case the getAddr() returns null.
862862 PHITransAddr PredPointer(Pointer);
863 PredPointer.PHITranslateValue(BB, Pred, 0);
863 PredPointer.PHITranslateValue(BB, Pred);
864864
865865 Value *PredPtrVal = PredPointer.getAddr();
866866
133133 }
134134
135135 Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
136 BasicBlock *PredBB,
137 const DominatorTree *DT) {
136 BasicBlock *PredBB) {
138137 // If this is a non-instruction value, it can't require PHI translation.
139138 Instruction *Inst = dyn_cast(V);
140139 if (Inst == 0) return V;
177176 // operands need to be phi translated, and if so, reconstruct it.
178177
179178 if (BitCastInst *BC = dyn_cast(Inst)) {
180 Value *PHIIn = PHITranslateSubExpr(BC->getOperand(0), CurBB, PredBB, DT);
179 Value *PHIIn = PHITranslateSubExpr(BC->getOperand(0), CurBB, PredBB);
181180 if (PHIIn == 0) return 0;
182181 if (PHIIn == BC->getOperand(0))
183182 return BC;
193192 for (Value::use_iterator UI = PHIIn->use_begin(), E = PHIIn->use_end();
194193 UI != E; ++UI) {
195194 if (BitCastInst *BCI = dyn_cast(*UI))
196 if (BCI->getType() == BC->getType() &&
197 (!DT || DT->dominates(BCI->getParent(), PredBB)))
195 if (BCI->getType() == BC->getType())
198196 return BCI;
199197 }
200198 return 0;
205203 SmallVector GEPOps;
206204 bool AnyChanged = false;
207205 for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) {
208 Value *GEPOp = PHITranslateSubExpr(GEP->getOperand(i), CurBB, PredBB, DT);
206 Value *GEPOp = PHITranslateSubExpr(GEP->getOperand(i), CurBB, PredBB);
209207 if (GEPOp == 0) return 0;
210208
211209 AnyChanged |= GEPOp != GEP->getOperand(i);
230228 if (GetElementPtrInst *GEPI = dyn_cast(*UI))
231229 if (GEPI->getType() == GEP->getType() &&
232230 GEPI->getNumOperands() == GEPOps.size() &&
233 GEPI->getParent()->getParent() == CurBB->getParent() &&
234 (!DT || DT->dominates(GEPI->getParent(), PredBB))) {
231 GEPI->getParent()->getParent() == CurBB->getParent()) {
235232 bool Mismatch = false;
236233 for (unsigned i = 0, e = GEPOps.size(); i != e; ++i)
237234 if (GEPI->getOperand(i) != GEPOps[i]) {
253250 bool isNSW = cast(Inst)->hasNoSignedWrap();
254251 bool isNUW = cast(Inst)->hasNoUnsignedWrap();
255252
256 Value *LHS = PHITranslateSubExpr(Inst->getOperand(0), CurBB, PredBB, DT);
253 Value *LHS = PHITranslateSubExpr(Inst->getOperand(0), CurBB, PredBB);
257254 if (LHS == 0) return 0;
258255
259256 // If the PHI translated LHS is an add of a constant, fold the immediates.
289286 if (BinaryOperator *BO = dyn_cast(*UI))
290287 if (BO->getOpcode() == Instruction::Add &&
291288 BO->getOperand(0) == LHS && BO->getOperand(1) == RHS &&
292 BO->getParent()->getParent() == CurBB->getParent() &&
293 (!DT || DT->dominates(BO->getParent(), PredBB)))
289 BO->getParent()->getParent() == CurBB->getParent())
294290 return BO;
295291 }
296292
303299
304300
305301 /// PHITranslateValue - PHI translate the current address up the CFG from
306 /// CurBB to Pred, updating our state to reflect any needed changes. If the
307 /// dominator tree DT is non-null, the translated value must dominate
308 /// PredBB. This returns true on failure and sets Addr to null.
309 bool PHITransAddr::PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
310 const DominatorTree *DT) {
302 /// CurBB to Pred, updating our state the reflect any needed changes. This
303 /// returns true on failure and sets Addr to null.
304 bool PHITransAddr::PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB) {
311305 assert(Verify() && "Invalid PHITransAddr!");
312 Addr = PHITranslateSubExpr(Addr, CurBB, PredBB, DT);
306 Addr = PHITranslateSubExpr(Addr, CurBB, PredBB);
313307 assert(Verify() && "Invalid PHITransAddr!");
314
315 if (DT) {
316 // Make sure the value is live in the predecessor.
317 if (Instruction *Inst = dyn_cast_or_null(Addr))
318 if (!DT->dominates(Inst->getParent(), PredBB))
319 Addr = 0;
320 }
321
322308 return Addr == 0;
323309 }
310
311 /// GetAvailablePHITranslatedSubExpr - Return the value computed by
312 /// PHITranslateSubExpr if it dominates PredBB, otherwise return null.
313 Value *PHITransAddr::
314 GetAvailablePHITranslatedSubExpr(Value *V, BasicBlock *CurBB,BasicBlock *PredBB,
315 const DominatorTree &DT) const {
316 PHITransAddr Tmp(V, TD);
317 Tmp.PHITranslateValue(CurBB, PredBB);
318
319 // See if PHI translation succeeds.
320 V = Tmp.getAddr();
321
322 // Make sure the value is live in the predecessor.
323 if (Instruction *Inst = dyn_cast_or_null(V))
324 if (!DT.dominates(Inst->getParent(), PredBB))
325 return 0;
326 return V;
327 }
328
324329
325330 /// PHITranslateWithInsertion - PHI translate this value into the specified
326331 /// predecessor block, inserting a computation of the value if it is
359364 SmallVectorImpl &NewInsts) {
360365 // See if we have a version of this value already available and dominating
361366 // PredBB. If so, there is no need to insert a new instance of it.
362 PHITransAddr Tmp(InVal, TD);
363 if (!Tmp.PHITranslateValue(CurBB, PredBB, &DT))
364 return Tmp.getAddr();
367 if (Value *Res = GetAvailablePHITranslatedSubExpr(InVal, CurBB, PredBB, DT))
368 return Res;
365369
366370 // If we don't have an available version of this value, it must be an
367371 // instruction.
16321632 LoadPtr = Address.PHITranslateWithInsertion(LoadBB, UnavailablePred,
16331633 *DT, NewInsts);
16341634 } else {
1635 Address.PHITranslateValue(LoadBB, UnavailablePred, DT);
1635 Address.PHITranslateValue(LoadBB, UnavailablePred);
16361636 LoadPtr = Address.getAddr();
1637
1638 // Make sure the value is live in the predecessor.
1639 if (Instruction *Inst = dyn_cast_or_null(LoadPtr))
1640 if (!DT->dominates(Inst->getParent(), UnavailablePred))
1641 LoadPtr = 0;
16371642 }
16381643
16391644 // If we couldn't find or insert a computation of this phi translated value,