[llvm] r263250 - [PM] Sink the "Expression" type for GVN into the class as a private

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 08:25:19 PST 2016


Author: chandlerc
Date: Fri Mar 11 10:25:19 2016
New Revision: 263250

URL: http://llvm.org/viewvc/llvm-project?rev=263250&view=rev
Log:
[PM] Sink the "Expression" type for GVN into the class as a private
member type.

Because of how this type is used by the ValueTable, it cannot actually
have hidden visibility. GCC actually nicely warns about this but Clang
just silently ... I don't even know. =/ We should do a better job either
way though.

This should resolve a bunch of the GCC warnings about visibility that
the port of GVN triggered and make the visibility story a bit more
correct.

Modified:
    llvm/trunk/include/llvm/Transforms/Scalar/GVN.h
    llvm/trunk/lib/Transforms/Scalar/GVN.cpp

Modified: llvm/trunk/include/llvm/Transforms/Scalar/GVN.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/GVN.h?rev=263250&r1=263249&r2=263250&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Scalar/GVN.h (original)
+++ llvm/trunk/include/llvm/Transforms/Scalar/GVN.h Fri Mar 11 10:25:19 2016
@@ -34,7 +34,6 @@ namespace llvm {
 namespace gvn LLVM_LIBRARY_VISIBILITY {
 struct AvailableValue;
 struct AvailableValueInBlock;
-struct Expression;
 class GVNLegacyPass;
 }
 
@@ -62,23 +61,26 @@ public:
 private:
   friend class gvn::GVNLegacyPass;
 
+  struct Expression;
+  friend struct DenseMapInfo<Expression>;
+
   /// 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.
   class ValueTable {
     DenseMap<Value *, uint32_t> valueNumbering;
-    DenseMap<gvn::Expression, uint32_t> expressionNumbering;
+    DenseMap<Expression, uint32_t> expressionNumbering;
     AliasAnalysis *AA;
     MemoryDependenceResults *MD;
     DominatorTree *DT;
 
     uint32_t nextValueNumber;
 
-    gvn::Expression create_expression(Instruction *I);
-    gvn::Expression create_cmp_expression(unsigned Opcode,
-                                          CmpInst::Predicate Predicate,
-                                          Value *LHS, Value *RHS);
-    gvn::Expression create_extractvalue_expression(ExtractValueInst *EI);
+    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:

Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=263250&r1=263249&r2=263250&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Fri Mar 11 10:25:19 2016
@@ -75,7 +75,7 @@ static cl::opt<uint32_t>
 MaxRecurseDepth("max-recurse-depth", cl::Hidden, cl::init(1000), cl::ZeroOrMore,
                 cl::desc("Max recurse depth (default = 1000)"));
 
-struct llvm::gvn::Expression {
+struct llvm::GVN::Expression {
   uint32_t opcode;
   Type *type;
   SmallVector<uint32_t, 4> varargs;
@@ -102,16 +102,16 @@ struct llvm::gvn::Expression {
 };
 
 namespace llvm {
-template <> struct DenseMapInfo<Expression> {
-  static inline Expression getEmptyKey() { return ~0U; }
+template <> struct DenseMapInfo<GVN::Expression> {
+  static inline GVN::Expression getEmptyKey() { return ~0U; }
 
-  static inline Expression getTombstoneKey() { return ~1U; }
+  static inline GVN::Expression getTombstoneKey() { return ~1U; }
 
-  static unsigned getHashValue(const Expression e) {
+  static unsigned getHashValue(const GVN::Expression e) {
     using llvm::hash_value;
     return static_cast<unsigned>(hash_value(e));
   }
-  static bool isEqual(const Expression &LHS, const Expression &RHS) {
+  static bool isEqual(const GVN::Expression &LHS, const GVN::Expression &RHS) {
     return LHS == RHS;
   }
 };
@@ -229,7 +229,7 @@ struct llvm::gvn::AvailableValueInBlock
 //                     ValueTable Internal Functions
 //===----------------------------------------------------------------------===//
 
-Expression GVN::ValueTable::create_expression(Instruction *I) {
+GVN::Expression GVN::ValueTable::create_expression(Instruction *I) {
   Expression e;
   e.type = I->getType();
   e.opcode = I->getOpcode();
@@ -263,9 +263,8 @@ Expression GVN::ValueTable::create_expre
   return e;
 }
 
-Expression GVN::ValueTable::create_cmp_expression(unsigned Opcode,
-                                             CmpInst::Predicate Predicate,
-                                             Value *LHS, Value *RHS) {
+GVN::Expression GVN::ValueTable::create_cmp_expression(
+    unsigned Opcode, CmpInst::Predicate Predicate, Value *LHS, Value *RHS) {
   assert((Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) &&
          "Not a comparison!");
   Expression e;
@@ -282,7 +281,8 @@ Expression GVN::ValueTable::create_cmp_e
   return e;
 }
 
-Expression GVN::ValueTable::create_extractvalue_expression(ExtractValueInst *EI) {
+GVN::Expression
+GVN::ValueTable::create_extractvalue_expression(ExtractValueInst *EI) {
   assert(EI && "Not an ExtractValueInst?");
   Expression e;
   e.type = EI->getType();




More information about the llvm-commits mailing list