Use hidden visibility to reduce the sizes of some .o files. This chops 60K off a...
[oota-llvm.git] / lib / VMCore / ConstantFold.cpp
index f12a041df0492a86ce7a64971c6932f119df23a8..e5ca2b37bcaec52ab9b18728567b321ecee54bef 100644 (file)
 #include "llvm/Function.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/Visibility.h"
 #include <limits>
 #include <cmath>
 using namespace llvm;
 
 namespace {
-  struct ConstRules {
+  struct VISIBILITY_HIDDEN ConstRules {
     ConstRules() {}
     virtual ~ConstRules() {}
 
@@ -86,8 +87,9 @@ namespace {
 // This class also provides subclasses with typesafe implementations of methods
 // so that don't have to do type casting.
 //
+namespace {
 template<class ArgType, class SubClassName>
-class TemplateRules : public ConstRules {
+class VISIBILITY_HIDDEN TemplateRules : public ConstRules {
 
 
   //===--------------------------------------------------------------------===//
@@ -210,7 +212,7 @@ class TemplateRules : public ConstRules {
 public:
   virtual ~TemplateRules() {}
 };
-
+}  // end anonymous namespace
 
 
 //===----------------------------------------------------------------------===//
@@ -219,12 +221,15 @@ public:
 //
 // EmptyRules provides a concrete base class of ConstRules that does nothing
 //
-struct EmptyRules : public TemplateRules<Constant, EmptyRules> {
+namespace {
+struct VISIBILITY_HIDDEN EmptyRules
+  : public TemplateRules<Constant, EmptyRules> {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
     if (V1 == V2) return ConstantBool::True;
     return 0;
   }
 };
+}  // end anonymous namespace
 
 
 
@@ -234,7 +239,9 @@ struct EmptyRules : public TemplateRules<Constant, EmptyRules> {
 //
 // BoolRules provides a concrete base class of ConstRules for the 'bool' type.
 //
-struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
+namespace {
+struct VISIBILITY_HIDDEN BoolRules
+  : public TemplateRules<ConstantBool, BoolRules> {
 
   static Constant *LessThan(const ConstantBool *V1, const ConstantBool *V2) {
     return ConstantBool::get(V1->getValue() < V2->getValue());
@@ -275,6 +282,7 @@ struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
   DEF_CAST(Double, ConstantFP  , double)
 #undef DEF_CAST
 };
+}  // end anonymous namespace
 
 
 //===----------------------------------------------------------------------===//
@@ -284,8 +292,9 @@ struct BoolRules : public TemplateRules<ConstantBool, BoolRules> {
 // NullPointerRules provides a concrete base class of ConstRules for null
 // pointers.
 //
-struct NullPointerRules : public TemplateRules<ConstantPointerNull,
-                                               NullPointerRules> {
+namespace {
+struct VISIBILITY_HIDDEN NullPointerRules
+  : public TemplateRules<ConstantPointerNull, NullPointerRules> {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
     return ConstantBool::True;  // Null pointers are always equal
   }
@@ -328,6 +337,7 @@ struct NullPointerRules : public TemplateRules<ConstantPointerNull,
     return ConstantPointerNull::get(PTy);
   }
 };
+}  // end anonymous namespace
 
 //===----------------------------------------------------------------------===//
 //                          ConstantPackedRules Class
@@ -349,7 +359,8 @@ static Constant *EvalVectorOp(const ConstantPacked *V1,
 /// PackedTypeRules provides a concrete base class of ConstRules for
 /// ConstantPacked operands.
 ///
-struct ConstantPackedRules
+namespace {
+struct VISIBILITY_HIDDEN ConstantPackedRules
   : public TemplateRules<ConstantPacked, ConstantPackedRules> {
   
   static Constant *Add(const ConstantPacked *V1, const ConstantPacked *V2) {
@@ -397,6 +408,7 @@ struct ConstantPackedRules
     return 0;
   }
 };
+}  // end anonymous namespace
 
 
 //===----------------------------------------------------------------------===//
@@ -407,8 +419,11 @@ struct ConstantPackedRules
 /// PackedType operands, where both operands are not ConstantPacked.  The usual
 /// cause for this is that one operand is a ConstantAggregateZero.
 ///
-struct GeneralPackedRules : public TemplateRules<Constant, GeneralPackedRules> {
+namespace {
+struct VISIBILITY_HIDDEN GeneralPackedRules
+  : public TemplateRules<Constant, GeneralPackedRules> {
 };
+}  // end anonymous namespace
 
 
 //===----------------------------------------------------------------------===//
@@ -419,8 +434,10 @@ struct GeneralPackedRules : public TemplateRules<Constant, GeneralPackedRules> {
 // different types.  This allows the C++ compiler to automatically generate our
 // constant handling operations in a typesafe and accurate manner.
 //
+namespace {
 template<class ConstantClass, class BuiltinType, Type **Ty, class SuperClass>
-struct DirectRules : public TemplateRules<ConstantClass, SuperClass> {
+struct VISIBILITY_HIDDEN DirectRules
+  : public TemplateRules<ConstantClass, SuperClass> {
   static Constant *Add(const ConstantClass *V1, const ConstantClass *V2) {
     BuiltinType R = (BuiltinType)V1->getValue() + (BuiltinType)V2->getValue();
     return ConstantClass::get(*Ty, R);
@@ -478,6 +495,7 @@ struct DirectRules : public TemplateRules<ConstantClass, SuperClass> {
   DEF_CAST(Double, ConstantFP  , double)
 #undef DEF_CAST
 };
+}  // end anonymous namespace
 
 
 //===----------------------------------------------------------------------===//
@@ -487,8 +505,9 @@ struct DirectRules : public TemplateRules<ConstantClass, SuperClass> {
 // DirectIntRules provides implementations of functions that are valid on
 // integer types, but not all types in general.
 //
+namespace {
 template <class ConstantClass, class BuiltinType, Type **Ty>
-struct DirectIntRules
+struct VISIBILITY_HIDDEN DirectIntRules
   : public DirectRules<ConstantClass, BuiltinType, Ty,
                        DirectIntRules<ConstantClass, BuiltinType, Ty> > {
 
@@ -534,6 +553,7 @@ struct DirectIntRules
     return ConstantClass::get(*Ty, R);
   }
 };
+}  // end anonymous namespace
 
 
 //===----------------------------------------------------------------------===//
@@ -543,8 +563,9 @@ struct DirectIntRules
 /// DirectFPRules provides implementations of functions that are valid on
 /// floating point types, but not all types in general.
 ///
+namespace {
 template <class ConstantClass, class BuiltinType, Type **Ty>
-struct DirectFPRules
+struct VISIBILITY_HIDDEN DirectFPRules
   : public DirectRules<ConstantClass, BuiltinType, Ty,
                        DirectFPRules<ConstantClass, BuiltinType, Ty> > {
   static Constant *Rem(const ConstantClass *V1, const ConstantClass *V2) {
@@ -561,6 +582,7 @@ struct DirectFPRules
     return ConstantClass::get(*Ty, R);
   }
 };
+}  // end anonymous namespace
 
 
 /// ConstRules::get - This method returns the constant rules implementation that
@@ -1455,7 +1477,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
           dyn_cast<PointerType>(CE->getOperand(0)->getType()))
         if (const ArrayType *SAT = dyn_cast<ArrayType>(SPT->getElementType()))
           if (const ArrayType *CAT =
-              dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
+        dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
             if (CAT->getElementType() == SAT->getElementType())
               return ConstantExpr::getGetElementPtr(
                       (Constant*)CE->getOperand(0), IdxList);