v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hydrogen-alias-analysis.h
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_HYDROGEN_ALIAS_ANALYSIS_H_
29 #define V8_HYDROGEN_ALIAS_ANALYSIS_H_
30 
31 #include "hydrogen.h"
32 
33 namespace v8 {
34 namespace internal {
35 
36 enum HAliasing {
40 };
41 
42 
43 // Defines the interface to alias analysis for the rest of the compiler.
44 // A simple implementation can use only local reasoning, but a more powerful
45 // analysis might employ points-to analysis.
46 class HAliasAnalyzer : public ZoneObject {
47  public:
48  // Simple alias analysis distinguishes allocations, parameters,
49  // and constants using only local reasoning.
51  // The same SSA value always references the same object.
52  if (a == b) return kMustAlias;
53 
54  if (a->IsAllocate() || a->IsInnerAllocatedObject()) {
55  // Two non-identical allocations can never be aliases.
56  if (b->IsAllocate()) return kNoAlias;
57  if (b->IsInnerAllocatedObject()) return kNoAlias;
58  // An allocation can never alias a parameter or a constant.
59  if (b->IsParameter()) return kNoAlias;
60  if (b->IsConstant()) return kNoAlias;
61  }
62  if (b->IsAllocate() || b->IsInnerAllocatedObject()) {
63  // An allocation can never alias a parameter or a constant.
64  if (a->IsParameter()) return kNoAlias;
65  if (a->IsConstant()) return kNoAlias;
66  }
67 
68  // Constant objects can be distinguished statically.
69  if (a->IsConstant()) {
70  // TODO(titzer): DataEquals() is more efficient, but that's protected.
71  return a->Equals(b) ? kMustAlias : kNoAlias;
72  }
73  return kMayAlias;
74  }
75 
76  // Checks whether the objects referred to by the given instructions may
77  // ever be aliases. Note that this is more conservative than checking
78  // {Query(a, b) == kMayAlias}, since this method considers kMustAlias
79  // objects to also be may-aliasing.
80  inline bool MayAlias(HValue* a, HValue* b) {
81  return Query(a, b) != kNoAlias;
82  }
83 
84  inline bool MustAlias(HValue* a, HValue* b) {
85  return Query(a, b) == kMustAlias;
86  }
87 
88  inline bool NoAlias(HValue* a, HValue* b) {
89  return Query(a, b) == kNoAlias;
90  }
91 };
92 
93 
94 } } // namespace v8::internal
95 
96 #endif // V8_HYDROGEN_ALIAS_ANALYSIS_H_
bool NoAlias(HValue *a, HValue *b)
bool MayAlias(HValue *a, HValue *b)
bool Equals(HValue *other)
HAliasing Query(HValue *a, HValue *b)
bool MustAlias(HValue *a, HValue *b)