diff --git a/llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h b/llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h --- a/llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h +++ b/llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h @@ -208,11 +208,11 @@ MemDepResult Result; public: - NonLocalDepEntry(BasicBlock *bb, MemDepResult result) - : BB(bb), Result(result) {} + NonLocalDepEntry(BasicBlock *BB, MemDepResult Result) + : BB(BB), Result(Result) {} // This is used for searches. - NonLocalDepEntry(BasicBlock *bb) : BB(bb) {} + NonLocalDepEntry(BasicBlock *BB) : BB(BB) {} // BB is the sort key, it can't be changed. BasicBlock *getBB() const { return BB; } @@ -233,8 +233,8 @@ Value *Address; public: - NonLocalDepResult(BasicBlock *bb, MemDepResult result, Value *address) - : Entry(bb, result), Address(address) {} + NonLocalDepResult(BasicBlock *BB, MemDepResult Result, Value *Address) + : Entry(BB, Result), Address(Address) {} // BB is the sort key, it can't be changed. BasicBlock *getBB() const { return Entry.getBB(); } diff --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h --- a/llvm/include/llvm/Analysis/MemorySSA.h +++ b/llvm/include/llvm/Analysis/MemorySSA.h @@ -1272,8 +1272,8 @@ const_cast(Location.Ptr), OriginalAccess->getBlock()->getModule()->getDataLayout(), nullptr); - if (!Translator.PHITranslateValue(OriginalAccess->getBlock(), - DefIterator.getPhiArgBlock(), DT, true)) + if (!Translator.translateValue(OriginalAccess->getBlock(), + DefIterator.getPhiArgBlock(), DT, true)) if (Translator.getAddr() != CurrentPair.second.Ptr) CurrentPair.second = CurrentPair.second.getWithNewPtr(Translator.getAddr()); diff --git a/llvm/include/llvm/Analysis/PHITransAddr.h b/llvm/include/llvm/Analysis/PHITransAddr.h --- a/llvm/include/llvm/Analysis/PHITransAddr.h +++ b/llvm/include/llvm/Analysis/PHITransAddr.h @@ -17,10 +17,10 @@ #include "llvm/IR/Instruction.h" namespace llvm { - class AssumptionCache; - class DominatorTree; - class DataLayout; - class TargetLibraryInfo; +class AssumptionCache; +class DominatorTree; +class DataLayout; +class TargetLibraryInfo; /// PHITransAddr - An address value which tracks and handles phi translation. /// As we walk "up" the CFG through predecessors, we need to ensure that the @@ -49,8 +49,8 @@ SmallVector InstInputs; public: - PHITransAddr(Value *addr, const DataLayout &DL, AssumptionCache *AC) - : Addr(addr), DL(DL), AC(AC) { + PHITransAddr(Value *Addr, const DataLayout &DL, AssumptionCache *AC) + : Addr(Addr), DL(DL), AC(AC) { // If the address is an instruction, the whole thing is considered an input. if (Instruction *I = dyn_cast(Addr)) InstInputs.push_back(I); @@ -58,9 +58,9 @@ Value *getAddr() const { return Addr; } - /// NeedsPHITranslationFromBlock - Return true if moving from the specified + /// needsPHITranslationFromBlock - Return true if moving from the specified /// BasicBlock to its predecessors requires PHI translation. - bool NeedsPHITranslationFromBlock(BasicBlock *BB) const { + bool needsPHITranslationFromBlock(BasicBlock *BB) const { // We do need translation if one of our input instructions is defined in // this block. for (unsigned i = 0, e = InstInputs.size(); i != e; ++i) @@ -69,51 +69,51 @@ return false; } - /// IsPotentiallyPHITranslatable - If this needs PHI translation, return true + /// isPotentiallyPHITranslatable - If this needs PHI translation, return true /// if we have some hope of doing it. This should be used as a filter to /// avoid calling PHITranslateValue in hopeless situations. - bool IsPotentiallyPHITranslatable() const; + bool isPotentiallyPHITranslatable() const; - /// PHITranslateValue - PHI translate the current address up the CFG from + /// translateValue - PHI translate the current address up the CFG from /// CurBB to Pred, updating our state to reflect any needed changes. If /// 'MustDominate' is true, the translated value must dominate /// PredBB. This returns true on failure and sets Addr to null. - bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, - const DominatorTree *DT, bool MustDominate); + bool translateValue(BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree *DT, bool MustDominate); - /// PHITranslateWithInsertion - PHI translate this value into the specified + /// translateWithInsertion - PHI translate this value into the specified /// predecessor block, inserting a computation of the value if it is /// unavailable. /// /// All newly created instructions are added to the NewInsts list. This /// returns null on failure. /// - Value *PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, - const DominatorTree &DT, - SmallVectorImpl &NewInsts); + Value *translateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree &DT, + SmallVectorImpl &NewInsts); void dump() const; - /// Verify - Check internal consistency of this data structure. If the + /// verify - Check internal consistency of this data structure. If the /// structure is valid, it returns true. If invalid, it prints errors and /// returns false. - bool Verify() const; + bool verify() const; private: - Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB, - const DominatorTree *DT); + Value *translateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree *DT); - /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated + /// insertTranslatedSubExpr - Insert a computation of the PHI translated /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB /// block. All newly created instructions are added to the NewInsts list. /// This returns null on failure. /// - Value *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB, - BasicBlock *PredBB, const DominatorTree &DT, - SmallVectorImpl &NewInsts); + Value *insertTranslatedSubExpr(Value *InVal, BasicBlock *CurBB, + BasicBlock *PredBB, const DominatorTree &DT, + SmallVectorImpl &NewInsts); - /// AddAsInput - If the specified value is an instruction, add it as an input. - Value *AddAsInput(Value *V) { + /// addAsInput - If the specified value is an instruction, add it as an input. + Value *addAsInput(Value *V) { // If V is an instruction, it is now an input. if (Instruction *VI = dyn_cast(V)) InstInputs.push_back(VI); diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -1238,7 +1238,7 @@ // phi translation to change it into a value live in the predecessor block. // If not, we just add the predecessors to the worklist and scan them with // the same Pointer. - if (!Pointer.NeedsPHITranslationFromBlock(BB)) { + if (!Pointer.needsPHITranslationFromBlock(BB)) { SkipFirstBlock = false; SmallVector NewBlocks; for (BasicBlock *Pred : PredCache.get(BB)) { @@ -1277,7 +1277,7 @@ // We do need to do phi translation, if we know ahead of time we can't phi // translate this value, don't even try. - if (!Pointer.IsPotentiallyPHITranslatable()) + if (!Pointer.isPotentiallyPHITranslatable()) goto PredTranslationFailure; // We may have added values to the cache list before this PHI translation. @@ -1298,7 +1298,7 @@ // Get the PHI translated pointer in this predecessor. This can fail if // not translatable, in which case the getAddr() returns null. PHITransAddr &PredPointer = PredList.back().second; - PredPointer.PHITranslateValue(BB, Pred, &DT, /*MustDominate=*/false); + PredPointer.translateValue(BB, Pred, &DT, /*MustDominate=*/false); Value *PredPtrVal = PredPointer.getAddr(); // Check to see if we have already visited this pred block with another diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp --- a/llvm/lib/Analysis/PHITransAddr.cpp +++ b/llvm/lib/Analysis/PHITransAddr.cpp @@ -25,7 +25,7 @@ "gvn-add-phi-translation", cl::init(false), cl::Hidden, cl::desc("Enable phi-translation of add instructions")); -static bool CanPHITrans(Instruction *Inst) { +static bool canPHITrans(Instruction *Inst) { if (isa(Inst) || isa(Inst)) return true; @@ -53,9 +53,8 @@ } #endif - -static bool VerifySubExpr(Value *Expr, - SmallVectorImpl &InstInputs) { +static bool verifySubExpr(Value *Expr, + SmallVectorImpl &InstInputs) { // If this is a non-instruction value, there is nothing to do. Instruction *I = dyn_cast(Expr); if (!I) return true; @@ -70,30 +69,30 @@ // If it isn't in the InstInputs list it is a subexpr incorporated into the // address. Validate that it is phi translatable. - if (!CanPHITrans(I)) { + if (!canPHITrans(I)) { errs() << "Instruction in PHITransAddr is not phi-translatable:\n"; errs() << *I << '\n'; llvm_unreachable("Either something is missing from InstInputs or " - "CanPHITrans is wrong."); + "canPHITrans is wrong."); } // Validate the operands of the instruction. for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) - if (!VerifySubExpr(I->getOperand(i), InstInputs)) + if (!verifySubExpr(I->getOperand(i), InstInputs)) return false; return true; } -/// Verify - Check internal consistency of this data structure. If the +/// verify - Check internal consistency of this data structure. If the /// structure is valid, it returns true. If invalid, it prints errors and /// returns false. -bool PHITransAddr::Verify() const { +bool PHITransAddr::verify() const { if (!Addr) return true; SmallVector Tmp(InstInputs.begin(), InstInputs.end()); - if (!VerifySubExpr(Addr, Tmp)) + if (!verifySubExpr(Addr, Tmp)) return false; if (!Tmp.empty()) { @@ -107,18 +106,16 @@ return true; } - -/// IsPotentiallyPHITranslatable - If this needs PHI translation, return true +/// isPotentiallyPHITranslatable - If this needs PHI translation, return true /// if we have some hope of doing it. This should be used as a filter to /// avoid calling PHITranslateValue in hopeless situations. -bool PHITransAddr::IsPotentiallyPHITranslatable() const { +bool PHITransAddr::isPotentiallyPHITranslatable() const { // If the input value is not an instruction, or if it is not defined in CurBB, // then we don't need to phi translate it. Instruction *Inst = dyn_cast(Addr); - return !Inst || CanPHITrans(Inst); + return !Inst || canPHITrans(Inst); } - static void RemoveInstInputs(Value *V, SmallVectorImpl &InstInputs) { Instruction *I = dyn_cast(V); @@ -140,9 +137,9 @@ } } -Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB, - BasicBlock *PredBB, - const DominatorTree *DT) { +Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock *CurBB, + BasicBlock *PredBB, + const DominatorTree *DT) { // If this is a non-instruction value, it can't require PHI translation. Instruction *Inst = dyn_cast(V); if (!Inst) return V; @@ -166,11 +163,11 @@ // If this is a PHI, go ahead and translate it. if (PHINode *PN = dyn_cast(Inst)) - return AddAsInput(PN->getIncomingValueForBlock(PredBB)); + return addAsInput(PN->getIncomingValueForBlock(PredBB)); // If this is a non-phi value, and it is analyzable, we can incorporate it // into the expression by making all instruction operands be inputs. - if (!CanPHITrans(Inst)) + if (!canPHITrans(Inst)) return nullptr; // All instruction operands are now inputs (and of course, they may also be @@ -186,7 +183,7 @@ if (CastInst *Cast = dyn_cast(Inst)) { if (!isSafeToSpeculativelyExecute(Cast)) return nullptr; - Value *PHIIn = PHITranslateSubExpr(Cast->getOperand(0), CurBB, PredBB, DT); + Value *PHIIn = translateSubExpr(Cast->getOperand(0), CurBB, PredBB, DT); if (!PHIIn) return nullptr; if (PHIIn == Cast->getOperand(0)) return Cast; @@ -195,8 +192,8 @@ // Constants are trivial to find. if (Constant *C = dyn_cast(PHIIn)) - return AddAsInput(ConstantExpr::getCast(Cast->getOpcode(), - C, Cast->getType())); + return addAsInput( + ConstantExpr::getCast(Cast->getOpcode(), C, Cast->getType())); // Otherwise we have to see if a casted version of the incoming pointer // is available. If so, we can use it, otherwise we have to fail. @@ -215,7 +212,7 @@ SmallVector GEPOps; bool AnyChanged = false; for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) { - Value *GEPOp = PHITranslateSubExpr(GEP->getOperand(i), CurBB, PredBB, DT); + Value *GEPOp = translateSubExpr(GEP->getOperand(i), CurBB, PredBB, DT); if (!GEPOp) return nullptr; AnyChanged |= GEPOp != GEP->getOperand(i); @@ -232,7 +229,7 @@ for (unsigned i = 0, e = GEPOps.size(); i != e; ++i) RemoveInstInputs(GEPOps[i], InstInputs); - return AddAsInput(V); + return addAsInput(V); } // Scan to see if we have this GEP available. @@ -259,7 +256,7 @@ bool isNSW = cast(Inst)->hasNoSignedWrap(); bool isNUW = cast(Inst)->hasNoUnsignedWrap(); - Value *LHS = PHITranslateSubExpr(Inst->getOperand(0), CurBB, PredBB, DT); + Value *LHS = translateSubExpr(Inst->getOperand(0), CurBB, PredBB, DT); if (!LHS) return nullptr; // If the PHI translated LHS is an add of a constant, fold the immediates. @@ -273,7 +270,7 @@ // If the old 'LHS' was an input, add the new 'LHS' as an input. if (is_contained(InstInputs, BOp)) { RemoveInstInputs(BOp, InstInputs); - AddAsInput(LHS); + addAsInput(LHS); } } @@ -282,7 +279,7 @@ // If we simplified the operands, the LHS is no longer an input, but Res // is. RemoveInstInputs(LHS, InstInputs); - return AddAsInput(Res); + return addAsInput(Res); } // If we didn't modify the add, just return it. @@ -306,21 +303,19 @@ return nullptr; } - /// PHITranslateValue - PHI translate the current address up the CFG from /// CurBB to Pred, updating our state to reflect any needed changes. If /// 'MustDominate' is true, the translated value must dominate /// PredBB. This returns true on failure and sets Addr to null. -bool PHITransAddr::PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, - const DominatorTree *DT, - bool MustDominate) { +bool PHITransAddr::translateValue(BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree *DT, bool MustDominate) { assert(DT || !MustDominate); - assert(Verify() && "Invalid PHITransAddr!"); + assert(verify() && "Invalid PHITransAddr!"); if (DT && DT->isReachableFromEntry(PredBB)) - Addr = PHITranslateSubExpr(Addr, CurBB, PredBB, DT); + Addr = translateSubExpr(Addr, CurBB, PredBB, DT); else Addr = nullptr; - assert(Verify() && "Invalid PHITransAddr!"); + assert(verify() && "Invalid PHITransAddr!"); if (MustDominate) // Make sure the value is live in the predecessor. @@ -338,14 +333,14 @@ /// All newly created instructions are added to the NewInsts list. This /// returns null on failure. /// -Value *PHITransAddr:: -PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, - const DominatorTree &DT, - SmallVectorImpl &NewInsts) { +Value * +PHITransAddr::translateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree &DT, + SmallVectorImpl &NewInsts) { unsigned NISize = NewInsts.size(); // Attempt to PHI translate with insertion. - Addr = InsertPHITranslatedSubExpr(Addr, CurBB, PredBB, DT, NewInsts); + Addr = insertTranslatedSubExpr(Addr, CurBB, PredBB, DT, NewInsts); // If successful, return the new value. if (Addr) return Addr; @@ -356,20 +351,18 @@ return nullptr; } - -/// InsertPHITranslatedPointer - Insert a computation of the PHI translated +/// insertTranslatedSubExpr - Insert a computation of the PHI translated /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB /// block. All newly created instructions are added to the NewInsts list. /// This returns null on failure. /// -Value *PHITransAddr:: -InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB, - BasicBlock *PredBB, const DominatorTree &DT, - SmallVectorImpl &NewInsts) { +Value *PHITransAddr::insertTranslatedSubExpr( + Value *InVal, BasicBlock *CurBB, BasicBlock *PredBB, + const DominatorTree &DT, SmallVectorImpl &NewInsts) { // See if we have a version of this value already available and dominating // PredBB. If so, there is no need to insert a new instance of it. PHITransAddr Tmp(InVal, DL, AC); - if (!Tmp.PHITranslateValue(CurBB, PredBB, &DT, /*MustDominate=*/true)) + if (!Tmp.translateValue(CurBB, PredBB, &DT, /*MustDominate=*/true)) return Tmp.getAddr(); // We don't need to PHI translate values which aren't instructions. @@ -380,8 +373,8 @@ // Handle cast of PHI translatable value. if (CastInst *Cast = dyn_cast(Inst)) { if (!isSafeToSpeculativelyExecute(Cast)) return nullptr; - Value *OpVal = InsertPHITranslatedSubExpr(Cast->getOperand(0), - CurBB, PredBB, DT, NewInsts); + Value *OpVal = insertTranslatedSubExpr(Cast->getOperand(0), CurBB, PredBB, + DT, NewInsts); if (!OpVal) return nullptr; // Otherwise insert a cast at the end of PredBB. @@ -398,8 +391,8 @@ SmallVector GEPOps; BasicBlock *CurBB = GEP->getParent(); for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) { - Value *OpVal = InsertPHITranslatedSubExpr(GEP->getOperand(i), - CurBB, PredBB, DT, NewInsts); + Value *OpVal = insertTranslatedSubExpr(GEP->getOperand(i), CurBB, PredBB, + DT, NewInsts); if (!OpVal) return nullptr; GEPOps.push_back(OpVal); } @@ -422,8 +415,8 @@ // This needs to be evaluated carefully to consider its cost trade offs. // PHI translate the LHS. - Value *OpVal = InsertPHITranslatedSubExpr(Inst->getOperand(0), - CurBB, PredBB, DT, NewInsts); + Value *OpVal = insertTranslatedSubExpr(Inst->getOperand(0), CurBB, PredBB, + DT, NewInsts); if (OpVal == nullptr) return nullptr; diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -462,10 +462,10 @@ "Should not hit the entry block because SI must be dominated by LI"); for (BasicBlock *Pred : predecessors(B)) { PHITransAddr PredAddr = Addr; - if (PredAddr.NeedsPHITranslationFromBlock(B)) { - if (!PredAddr.IsPotentiallyPHITranslatable()) + if (PredAddr.needsPHITranslationFromBlock(B)) { + if (!PredAddr.isPotentiallyPHITranslatable()) return false; - if (PredAddr.PHITranslateValue(B, Pred, DT, false)) + if (PredAddr.translateValue(B, Pred, DT, false)) return false; } Value *TranslatedPtr = PredAddr.getAddr(); diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1556,8 +1556,8 @@ BasicBlock *Cur = Load->getParent(); while (Cur != LoadBB) { PHITransAddr Address(LoadPtr, DL, AC); - LoadPtr = Address.PHITranslateWithInsertion( - Cur, Cur->getSinglePredecessor(), *DT, NewInsts); + LoadPtr = Address.translateWithInsertion(Cur, Cur->getSinglePredecessor(), + *DT, NewInsts); if (!LoadPtr) { CanDoPRE = false; break; @@ -1567,8 +1567,8 @@ if (LoadPtr) { PHITransAddr Address(LoadPtr, DL, AC); - LoadPtr = Address.PHITranslateWithInsertion(LoadBB, UnavailablePred, *DT, - NewInsts); + LoadPtr = Address.translateWithInsertion(LoadBB, UnavailablePred, *DT, + NewInsts); } // If we couldn't find or insert a computation of this phi translated value, // we fail PRE.