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. Query(HValue * a,HValue * b)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 // TODO(titzer): DataEquals() is more efficient, but that's protected. 48 return a->Equals(b) ? kMustAlias : kNoAlias; 49 } 50 return kMayAlias; 51 } 52 53 // Checks whether the objects referred to by the given instructions may 54 // ever be aliases. Note that this is more conservative than checking 55 // {Query(a, b) == kMayAlias}, since this method considers kMustAlias 56 // objects to also be may-aliasing. MayAlias(HValue * a,HValue * b)57 inline bool MayAlias(HValue* a, HValue* b) { 58 return Query(a, b) != kNoAlias; 59 } 60 MustAlias(HValue * a,HValue * b)61 inline bool MustAlias(HValue* a, HValue* b) { 62 return Query(a, b) == kMustAlias; 63 } 64 NoAlias(HValue * a,HValue * b)65 inline bool NoAlias(HValue* a, HValue* b) { 66 return Query(a, b) == kNoAlias; 67 } 68 }; 69 70 71 } // namespace internal 72 } // namespace v8 73 74 #endif // V8_CRANKSHAFT_HYDROGEN_ALIAS_ANALYSIS_H_ 75