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.
5 #ifndef V8_HYDROGEN_ALIAS_ANALYSIS_H_
6 #define V8_HYDROGEN_ALIAS_ANALYSIS_H_
8 #include "src/hydrogen.h"
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 {
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;
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;
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;
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;
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.
57 inline bool MayAlias(HValue* a, HValue* b) {
58 return Query(a, b) != kNoAlias;
61 inline bool MustAlias(HValue* a, HValue* b) {
62 return Query(a, b) == kMustAlias;
65 inline bool NoAlias(HValue* a, HValue* b) {
66 return Query(a, b) == kNoAlias;
71 } } // namespace v8::internal
73 #endif // V8_HYDROGEN_ALIAS_ANALYSIS_H_