LCOV - code coverage report
Current view: top level - src/crankshaft - hydrogen-alias-analysis.h (source / functions) Hit Total Coverage
Test: app.info Lines: 14 14 100.0 %
Date: 2017-04-26 Functions: 1 1 100.0 %

          Line data    Source code
       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     6368759 :   HAliasing Query(HValue* a, HValue* b) {
      28             :     // The same SSA value always references the same object.
      29     6368759 :     if (a == b) return kMustAlias;
      30             : 
      31    10182760 :     if (a->IsAllocate() || a->IsInnerAllocatedObject()) {
      32             :       // Two non-identical allocations can never be aliases.
      33      311694 :       if (b->IsAllocate()) return kNoAlias;
      34      188009 :       if (b->IsInnerAllocatedObject()) return kNoAlias;
      35             :       // An allocation can never alias a parameter or a constant.
      36      184429 :       if (b->IsParameter()) return kNoAlias;
      37      172015 :       if (b->IsConstant()) return kNoAlias;
      38             :     }
      39     9832975 :     if (b->IsAllocate() || b->IsInnerAllocatedObject()) {
      40             :       // An allocation can never alias a parameter or a constant.
      41      175843 :       if (a->IsParameter()) return kNoAlias;
      42      169095 :       if (a->IsConstant()) return kNoAlias;
      43             :     }
      44             : 
      45             :     // Constant objects can be distinguished statically.
      46     4891439 :     if (a->IsConstant()) {
      47     1912818 :       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      207486 :     return Query(a, b) != kNoAlias;
      58             :   }
      59             : 
      60             :   inline bool MustAlias(HValue* a, HValue* b) {
      61     6161319 :     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_

Generated by: LCOV version 1.10