Home | History | Annotate | Download | only in crankshaft
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_CRANKSHAFT_HYDROGEN_ALIAS_ANALYSIS_H_
      6 #define V8_CRANKSHAFT_HYDROGEN_ALIAS_ANALYSIS_H_
      7 
      8 #include "src/crankshaft/hydrogen.h"
      9 
     10 namespace v8 {
     11 namespace internal {
     12 
     13 enum HAliasing {
     14   kMustAlias,
     15   kMayAlias,
     16   kNoAlias
     17 };
     18 
     19 
     20 // Defines the interface to alias analysis for the rest of the compiler.
     21 // A simple implementation can use only local reasoning, but a more powerful
     22 // analysis might employ points-to analysis.
     23 class HAliasAnalyzer : public ZoneObject {
     24  public:
     25   // Simple alias analysis distinguishes allocations, parameters,
     26   // and constants using only local reasoning.
     27   HAliasing Query(HValue* a, HValue* b) {
     28     // The same SSA value always references the same object.
     29     if (a == b) return kMustAlias;
     30 
     31     if (a->IsAllocate() || a->IsInnerAllocatedObject()) {
     32       // Two non-identical allocations can never be aliases.
     33       if (b->IsAllocate()) return kNoAlias;
     34       if (b->IsInnerAllocatedObject()) return kNoAlias;
     35       // An allocation can never alias a parameter or a constant.
     36       if (b->IsParameter()) return kNoAlias;
     37       if (b->IsConstant()) return kNoAlias;
     38     }
     39     if (b->IsAllocate() || b->IsInnerAllocatedObject()) {
     40       // An allocation can never alias a parameter or a constant.
     41       if (a->IsParameter()) return kNoAlias;
     42       if (a->IsConstant()) return kNoAlias;
     43     }
     44 
     45     // Constant objects can be distinguished statically.
     46     if (a->IsConstant()) {
     47       return a->Equals(b) ? kMustAlias : kNoAlias;
     48     }
     49     return kMayAlias;
     50   }
     51 
     52   // Checks whether the objects referred to by the given instructions may
     53   // ever be aliases. Note that this is more conservative than checking
     54   // {Query(a, b) == kMayAlias}, since this method considers kMustAlias
     55   // objects to also be may-aliasing.
     56   inline bool MayAlias(HValue* a, HValue* b) {
     57     return Query(a, b) != kNoAlias;
     58   }
     59 
     60   inline bool MustAlias(HValue* a, HValue* b) {
     61     return Query(a, b) == kMustAlias;
     62   }
     63 
     64   inline bool NoAlias(HValue* a, HValue* b) {
     65     return Query(a, b) == kNoAlias;
     66   }
     67 };
     68 
     69 
     70 }  // namespace internal
     71 }  // namespace v8
     72 
     73 #endif  // V8_CRANKSHAFT_HYDROGEN_ALIAS_ANALYSIS_H_
     74