From: Daniel Berlin Date: Mon, 26 Dec 2016 20:06:58 +0000 (+0000) Subject: clang-format NewGVN files X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7870484ec88275ad1a8d51dfce28459edbf25b28;p=llvm clang-format NewGVN files git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290551 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Transforms/Scalar/GVNExpression.h b/include/llvm/Transforms/Scalar/GVNExpression.h index 2b5d1719fd1..9d1df02fe40 100644 --- a/include/llvm/Transforms/Scalar/GVNExpression.h +++ b/include/llvm/Transforms/Scalar/GVNExpression.h @@ -68,8 +68,7 @@ public: // Compare the expression type for anything but load and store. // For load and store we set the opcode to zero. // This is needed for load coercion. - if (getExpressionType() != ET_Load && - getExpressionType() != ET_Store && + if (getExpressionType() != ET_Load && getExpressionType() != ET_Store && getExpressionType() != Other.getExpressionType()) return false; @@ -190,7 +189,7 @@ public: const auto &OE = cast(Other); return getType() == OE.getType() && NumOperands == OE.NumOperands && - std::equal(op_begin(), op_end(), OE.op_begin()); + std::equal(op_begin(), op_end(), OE.op_begin()); } virtual hash_code getHashValue() const override { @@ -220,6 +219,7 @@ class op_inserter private: typedef BasicExpression Container; Container *BE; + public: explicit op_inserter(BasicExpression &E) : BE(&E) {} explicit op_inserter(BasicExpression *E) : BE(E) {} @@ -233,7 +233,6 @@ public: op_inserter &operator++(int) { return *this; } }; - class CallExpression final : public BasicExpression { private: CallInst *Call; @@ -245,8 +244,7 @@ public: } CallExpression(unsigned NumOperands, CallInst *C, MemoryAccess *DA) - : BasicExpression(NumOperands, ET_Call), Call(C), - DefiningAccess(DA) {} + : BasicExpression(NumOperands, ET_Call), Call(C), DefiningAccess(DA) {} void operator=(const CallExpression &) = delete; CallExpression(const CallExpression &) = delete; CallExpression() = delete; @@ -287,8 +285,8 @@ public: LoadExpression(unsigned NumOperands, LoadInst *L, MemoryAccess *DA) : LoadExpression(ET_Load, NumOperands, L, DA) {} - LoadExpression(enum ExpressionType EType, unsigned NumOperands, - LoadInst *L, MemoryAccess *DA) + LoadExpression(enum ExpressionType EType, unsigned NumOperands, LoadInst *L, + MemoryAccess *DA) : BasicExpression(NumOperands, EType), Load(L), DefiningAccess(DA) { Alignment = L ? L->getAlignment() : 0; } @@ -335,8 +333,7 @@ public: } StoreExpression(unsigned NumOperands, StoreInst *S, MemoryAccess *DA) - : BasicExpression(NumOperands, ET_Store), Store(S), - DefiningAccess(DA) {} + : BasicExpression(NumOperands, ET_Store), Store(S), DefiningAccess(DA) {} void operator=(const StoreExpression &) = delete; StoreExpression(const StoreExpression &) = delete; StoreExpression() = delete; @@ -374,8 +371,7 @@ public: return EB->getExpressionType() == ET_AggregateValue; } - AggregateValueExpression(unsigned NumOperands, - unsigned NumIntOperands) + AggregateValueExpression(unsigned NumOperands, unsigned NumIntOperands) : BasicExpression(NumOperands, ET_AggregateValue), MaxIntOperands(NumIntOperands), NumIntOperands(0), IntOperands(nullptr) {} @@ -413,7 +409,7 @@ public: return false; const AggregateValueExpression &OE = cast(Other); return NumIntOperands == OE.NumIntOperands && - std::equal(int_op_begin(), int_op_end(), OE.int_op_begin()); + std::equal(int_op_begin(), int_op_end(), OE.int_op_begin()); } virtual hash_code getHashValue() const override { @@ -453,7 +449,6 @@ public: int_op_inserter &operator++(int) { return *this; } }; - class PHIExpression final : public BasicExpression { private: BasicBlock *BB; @@ -501,8 +496,7 @@ public: return EB->getExpressionType() == ET_Variable; } - VariableExpression(Value *V) - : Expression(ET_Variable), VariableValue(V) {} + VariableExpression(Value *V) : Expression(ET_Variable), VariableValue(V) {} void operator=(const VariableExpression &) = delete; VariableExpression(const VariableExpression &) = delete; VariableExpression() = delete; @@ -539,8 +533,7 @@ public: return EB->getExpressionType() == ET_Constant; } - ConstantExpression() - : Expression(ET_Constant), ConstantValue(NULL) {} + ConstantExpression() : Expression(ET_Constant), ConstantValue(NULL) {} ConstantExpression(Constant *constantValue) : Expression(ET_Constant), ConstantValue(constantValue) {} void operator=(const ConstantExpression &) = delete; diff --git a/lib/Transforms/Scalar/NewGVN.cpp b/lib/Transforms/Scalar/NewGVN.cpp index 32a47db4f45..096a4ae4162 100644 --- a/lib/Transforms/Scalar/NewGVN.cpp +++ b/lib/Transforms/Scalar/NewGVN.cpp @@ -87,13 +87,13 @@ STATISTIC(NumGVNPhisAllSame, "Number of PHIs whos arguments are all the same"); // Anchor methods. namespace llvm { namespace GVNExpression { - Expression::~Expression() = default; - BasicExpression::~BasicExpression() = default; - CallExpression::~CallExpression() = default; - LoadExpression::~LoadExpression() = default; - StoreExpression::~StoreExpression() = default; - AggregateValueExpression::~AggregateValueExpression() = default; - PHIExpression::~PHIExpression() = default; +Expression::~Expression() = default; +BasicExpression::~BasicExpression() = default; +CallExpression::~CallExpression() = default; +LoadExpression::~LoadExpression() = default; +StoreExpression::~StoreExpression() = default; +AggregateValueExpression::~AggregateValueExpression() = default; +PHIExpression::~PHIExpression() = default; } } @@ -140,29 +140,29 @@ struct CongruenceClass { }; namespace llvm { - template <> struct DenseMapInfo { - static const Expression *getEmptyKey() { - uintptr_t Val = static_cast(-1); - Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; - return reinterpret_cast(Val); - } - static const Expression *getTombstoneKey() { - uintptr_t Val = static_cast(~1U); - Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; - return reinterpret_cast(Val); - } - static unsigned getHashValue(const Expression *V) { - return static_cast(V->getHashValue()); - } - static bool isEqual(const Expression *LHS, const Expression *RHS) { - if (LHS == RHS) - return true; - if (LHS == getTombstoneKey() || RHS == getTombstoneKey() || - LHS == getEmptyKey() || RHS == getEmptyKey()) - return false; - return *LHS == *RHS; - } - }; +template <> struct DenseMapInfo { + static const Expression *getEmptyKey() { + uintptr_t Val = static_cast(-1); + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + return reinterpret_cast(Val); + } + static const Expression *getTombstoneKey() { + uintptr_t Val = static_cast(~1U); + Val <<= PointerLikeTypeTraits::NumLowBitsAvailable; + return reinterpret_cast(Val); + } + static unsigned getHashValue(const Expression *V) { + return static_cast(V->getHashValue()); + } + static bool isEqual(const Expression *LHS, const Expression *RHS) { + if (LHS == RHS) + return true; + if (LHS == getTombstoneKey() || RHS == getTombstoneKey() || + LHS == getEmptyKey() || RHS == getEmptyKey()) + return false; + return *LHS == *RHS; + } +}; } // end namespace llvm class NewGVN : public FunctionPass { @@ -240,8 +240,7 @@ public: bool runOnFunction(Function &F) override; bool runGVN(Function &F, DominatorTree *DT, AssumptionCache *AC, - TargetLibraryInfo *TLI, AliasAnalysis *AA, - MemorySSA *MSSA); + TargetLibraryInfo *TLI, AliasAnalysis *AA, MemorySSA *MSSA); private: // This transformation requires dominator postdominator info. @@ -632,8 +631,7 @@ NewGVN::createAggregateValueExpression(Instruction *I, const BasicBlock *B) { llvm_unreachable("Unhandled type of aggregate value operation"); } -const VariableExpression * -NewGVN::createVariableExpression(Value *V) { +const VariableExpression *NewGVN::createVariableExpression(Value *V) { VariableExpression *E = new (ExpressionAllocator) VariableExpression(V); E->setOpcode(V->getValueID()); return E; @@ -647,8 +645,7 @@ const Expression *NewGVN::createVariableOrConstant(Value *V, return createVariableExpression(Leader); } -const ConstantExpression * -NewGVN::createConstantExpression(Constant *C) { +const ConstantExpression *NewGVN::createConstantExpression(Constant *C) { ConstantExpression *E = new (ExpressionAllocator) ConstantExpression(C); E->setOpcode(C->getValueID()); return E; @@ -667,8 +664,7 @@ const CallExpression *NewGVN::createCallExpression(CallInst *CI, // See if we have a congruence class and leader for this operand, and if so, // return it. Otherwise, return the operand itself. template -Value *NewGVN::lookupOperandLeader(Value *V, const User *U, - const T &B) const { +Value *NewGVN::lookupOperandLeader(Value *V, const User *U, const T &B) const { CongruenceClass *CC = ValueToClass.lookup(V); if (CC && (CC != InitialClass)) return CC->RepLeader; @@ -747,8 +743,7 @@ const Expression *NewGVN::performSymbolicLoadEvaluation(Instruction *I, if (!LI->isSimple()) return nullptr; - Value *LoadAddressLeader = - lookupOperandLeader(LI->getPointerOperand(), I, B); + Value *LoadAddressLeader = lookupOperandLeader(LI->getPointerOperand(), I, B); // Load of undef is undef. if (isa(LoadAddressLeader)) return createConstantExpression(UndefValue::get(LI->getType())); @@ -778,10 +773,8 @@ const Expression *NewGVN::performSymbolicCallEvaluation(Instruction *I, return createCallExpression(CI, nullptr, B); else if (AA->onlyReadsMemory(CI)) { MemoryAccess *DefiningAccess = MSSAWalker->getClobberingMemoryAccess(CI); - return createCallExpression(CI, lookupMemoryAccessEquiv(DefiningAccess), - B); - } - else + return createCallExpression(CI, lookupMemoryAccessEquiv(DefiningAccess), B); + } else return nullptr; } @@ -1219,7 +1212,8 @@ void NewGVN::processOutgoingEdges(TerminatorInst *TI, BasicBlock *B) { } } -// The algorithm initially places the values of the routine in the INITIAL congruence +// The algorithm initially places the values of the routine in the INITIAL +// congruence // class. The leader of INITIAL is the undetermined value `TOP`. // When the algorithm has finished, values still in INITIAL are unreachable. void NewGVN::initializeCongruenceClasses(Function &F) { @@ -1357,10 +1351,10 @@ void NewGVN::valueNumberInstruction(Instruction *I) { } } -// This is the main transformation entry point. +// This is the main transformation entry point. bool NewGVN::runGVN(Function &F, DominatorTree *_DT, AssumptionCache *_AC, - TargetLibraryInfo *_TLI, AliasAnalysis *_AA, - MemorySSA *_MSSA) { + TargetLibraryInfo *_TLI, AliasAnalysis *_AA, + MemorySSA *_MSSA) { bool Changed = false; DT = _DT; AC = _AC; @@ -1472,12 +1466,13 @@ bool NewGVN::runGVN(Function &F, DominatorTree *_DT, AssumptionCache *_AC, } // Delete all unreachable blocks. - auto UnreachableBlockPred = - [&](const BasicBlock &BB) { return !ReachableBlocks.count(&BB); }; + auto UnreachableBlockPred = [&](const BasicBlock &BB) { + return !ReachableBlocks.count(&BB); + }; for (auto &BB : make_filter_range(F, UnreachableBlockPred)) { DEBUG(dbgs() << "We believe block " << getBlockName(&BB) - << " is unreachable\n"); + << " is unreachable\n"); deleteInstructionsInBlock(&BB); Changed = true; } @@ -1496,8 +1491,7 @@ bool NewGVN::runOnFunction(Function &F) { &getAnalysis().getMSSA()); } -PreservedAnalyses NewGVNPass::run(Function &F, - AnalysisManager &AM) { +PreservedAnalyses NewGVNPass::run(Function &F, AnalysisManager &AM) { NewGVN Impl; // Apparently the order in which we get these results matter for @@ -1539,8 +1533,7 @@ struct NewGVN::ValueDFS { // Only one of these will be set. Value *Val; Use *U; - ValueDFS() - : DFSIn(0), DFSOut(0), LocalNum(0), Val(nullptr), U(nullptr) {} + ValueDFS() : DFSIn(0), DFSOut(0), LocalNum(0), Val(nullptr), U(nullptr) {} bool operator<(const ValueDFS &Other) const { // It's not enough that any given field be less than - we have sets @@ -1557,25 +1550,28 @@ struct NewGVN::ValueDFS { // Each LLVM instruction only produces one value, and thus the lowest-level // differentiator that really matters for the stack (and what we use as as a // replacement) is the local dfs number. - // Everything else in the structure is instruction level, and only affects the - // order in which we will replace operands of a given instruction. + // Everything else in the structure is instruction level, and only affects + // the order in which we will replace operands of a given instruction. // // For a given instruction (IE things with equal dfsin, dfsout, localnum), // the order of replacement of uses does not matter. // IE given, // a = 5 // b = a + a - // When you hit b, you will have two valuedfs with the same dfsin, out, and localnum. + // When you hit b, you will have two valuedfs with the same dfsin, out, and + // localnum. // The .val will be the same as well. // The .u's will be different. - // You will replace both, and it does not matter what order you replace them in - // (IE whether you replace operand 2, then operand 1, or operand 1, then operand 2). - // Similarly for the case of same dfsin, dfsout, localnum, but different .val's + // You will replace both, and it does not matter what order you replace them + // in (IE whether you replace operand 2, then operand 1, or operand 1, then + // operand 2). + // Similarly for the case of same dfsin, dfsout, localnum, but different + // .val's // a = 5 // b = 6 // c = a + b - // in c, we will a valuedfs for a, and one for b,with everything the same but - // .val and .u. + // in c, we will a valuedfs for a, and one for b,with everything the same + // but .val and .u. // It does not matter what order we replace these operands in. // You will always end up with the same IR, and this is guaranteed. return std::tie(DFSIn, DFSOut, LocalNum, Val, U) < @@ -1768,7 +1764,6 @@ bool NewGVN::eliminateInstructions(Function &F) { // overlapping ranges while sorting, as we will never eliminate anything // with those members, as they don't dominate anything else in our set. - bool AnythingReplaced = false; // Since we are going to walk the domtree anyway, and we can't guarantee the @@ -1924,8 +1919,7 @@ bool NewGVN::eliminateInstructions(Function &F) { // If we replaced something in an instruction, handle the patching of // metadata. - if (auto *ReplacedInst = - dyn_cast(MemberUse->get())) + if (auto *ReplacedInst = dyn_cast(MemberUse->get())) patchReplacementInstruction(ReplacedInst, Result); assert(isa(MemberUse->getUser())); @@ -1960,4 +1954,3 @@ bool NewGVN::eliminateInstructions(Function &F) { return AnythingReplaced; } -