From d18bb9e06b6b95ecddcd726c4661f8fa5742975a Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 10 Mar 2016 00:58:20 +0000 Subject: [PATCH] [gvn] Fix more indenting and formatting in regions of code that will need to be changed for porting to the new pass manager. Also sink the comment on the ValueTable class back to that class instead of it dangling on an anonymous namespace. No functionality changed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263084 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVN.cpp | 126 +++++++++++++++++----------------- 1 file changed, 62 insertions(+), 64 deletions(-) diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 859f14ed024..0348401e3c2 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -78,79 +78,78 @@ MaxRecurseDepth("max-recurse-depth", cl::Hidden, cl::init(1000), cl::ZeroOrMore, // ValueTable Class //===----------------------------------------------------------------------===// +namespace { + +struct Expression { + uint32_t opcode; + Type *type; + SmallVector varargs; + + Expression(uint32_t o = ~2U) : opcode(o) {} + + bool operator==(const Expression &other) const { + if (opcode != other.opcode) + return false; + if (opcode == ~0U || opcode == ~1U) + return true; + if (type != other.type) + return false; + if (varargs != other.varargs) + return false; + return true; + } + + friend hash_code hash_value(const Expression &Value) { + return hash_combine( + Value.opcode, Value.type, + hash_combine_range(Value.varargs.begin(), Value.varargs.end())); + } +}; + /// This class holds the mapping between values and value numbers. It is used /// as an efficient mechanism to determine the expression-wise equivalence of /// two values. -namespace { - struct Expression { - uint32_t opcode; - Type *type; - SmallVector varargs; +class ValueTable { + DenseMap valueNumbering; + DenseMap expressionNumbering; + AliasAnalysis *AA; + MemoryDependenceResults *MD; + DominatorTree *DT; - Expression(uint32_t o = ~2U) : opcode(o) { } + uint32_t nextValueNumber; - bool operator==(const Expression &other) const { - if (opcode != other.opcode) - return false; - if (opcode == ~0U || opcode == ~1U) - return true; - if (type != other.type) - return false; - if (varargs != other.varargs) - return false; - return true; - } + Expression create_expression(Instruction *I); + Expression create_cmp_expression(unsigned Opcode, + CmpInst::Predicate Predicate, Value *LHS, + Value *RHS); + Expression create_extractvalue_expression(ExtractValueInst *EI); + uint32_t lookup_or_add_call(CallInst *C); - friend hash_code hash_value(const Expression &Value) { - return hash_combine(Value.opcode, Value.type, - hash_combine_range(Value.varargs.begin(), - Value.varargs.end())); - } - }; +public: + ValueTable() : nextValueNumber(1) {} + uint32_t lookup_or_add(Value *V); + uint32_t lookup(Value *V) const; + uint32_t lookup_or_add_cmp(unsigned Opcode, CmpInst::Predicate Pred, + Value *LHS, Value *RHS); + bool exists(Value *V) const; + void add(Value *V, uint32_t num); + void clear(); + void erase(Value *v); + void setAliasAnalysis(AliasAnalysis *A) { AA = A; } + AliasAnalysis *getAliasAnalysis() const { return AA; } + void setMemDep(MemoryDependenceResults *M) { MD = M; } + void setDomTree(DominatorTree *D) { DT = D; } + uint32_t getNextUnusedValueNumber() { return nextValueNumber; } + void verifyRemoved(const Value *) const; +}; - class ValueTable { - DenseMap valueNumbering; - DenseMap expressionNumbering; - AliasAnalysis *AA; - MemoryDependenceResults *MD; - DominatorTree *DT; - - uint32_t nextValueNumber; - - Expression create_expression(Instruction* I); - Expression create_cmp_expression(unsigned Opcode, - CmpInst::Predicate Predicate, - Value *LHS, Value *RHS); - Expression create_extractvalue_expression(ExtractValueInst* EI); - uint32_t lookup_or_add_call(CallInst* C); - public: - ValueTable() : nextValueNumber(1) { } - uint32_t lookup_or_add(Value *V); - uint32_t lookup(Value *V) const; - uint32_t lookup_or_add_cmp(unsigned Opcode, CmpInst::Predicate Pred, - Value *LHS, Value *RHS); - bool exists(Value *V) const; - void add(Value *V, uint32_t num); - void clear(); - void erase(Value *v); - void setAliasAnalysis(AliasAnalysis* A) { AA = A; } - AliasAnalysis *getAliasAnalysis() const { return AA; } - void setMemDep(MemoryDependenceResults* M) { MD = M; } - void setDomTree(DominatorTree* D) { DT = D; } - uint32_t getNextUnusedValueNumber() { return nextValueNumber; } - void verifyRemoved(const Value *) const; - }; -} +} // End anonymous namespace. namespace llvm { template <> struct DenseMapInfo { - static inline Expression getEmptyKey() { - return ~0U; - } + static inline Expression getEmptyKey() { return ~0U; } - static inline Expression getTombstoneKey() { - return ~1U; - } + static inline Expression getTombstoneKey() { return ~1U; } static unsigned getHashValue(const Expression e) { using llvm::hash_value; @@ -160,8 +159,7 @@ template <> struct DenseMapInfo { return LHS == RHS; } }; - -} +} // End llvm namespace. //===----------------------------------------------------------------------===// // ValueTable Internal Functions