Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: src/compiler/linkage.h

Issue 1262343002: [turbofan]: Add better encapsulation to LinkageLocation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Really fix it this time Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/instruction-selector-impl.h ('k') | src/compiler/linkage.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_COMPILER_LINKAGE_H_ 5 #ifndef V8_COMPILER_LINKAGE_H_
6 #define V8_COMPILER_LINKAGE_H_ 6 #define V8_COMPILER_LINKAGE_H_
7 7
8 #include "src/base/flags.h" 8 #include "src/base/flags.h"
9 #include "src/compiler/frame.h" 9 #include "src/compiler/frame.h"
10 #include "src/compiler/machine-type.h" 10 #include "src/compiler/machine-type.h"
11 #include "src/compiler/operator.h" 11 #include "src/compiler/operator.h"
12 #include "src/frames.h" 12 #include "src/frames.h"
13 #include "src/runtime/runtime.h" 13 #include "src/runtime/runtime.h"
14 #include "src/zone.h" 14 #include "src/zone.h"
15 15
16 namespace v8 { 16 namespace v8 {
17 namespace internal { 17 namespace internal {
18 18
19 class CallInterfaceDescriptor; 19 class CallInterfaceDescriptor;
20 20
21 namespace compiler { 21 namespace compiler {
22 22
23 class Node; 23 class Node;
24 class OsrHelper; 24 class OsrHelper;
25 25
26 // Describes the location for a parameter or a return value to a call. 26 // Describes the location for a parameter or a return value to a call.
27 class LinkageLocation { 27 class LinkageLocation {
28 public: 28 public:
29 explicit LinkageLocation(int location) : location_(location) {}
30
31 bool is_register() const {
32 return 0 <= location_ && location_ <= ANY_REGISTER;
33 }
34
35 static const int16_t ANY_REGISTER = 1023;
36 static const int16_t MAX_STACK_SLOT = 32767;
37
38 static LinkageLocation AnyRegister() { return LinkageLocation(ANY_REGISTER); }
39
40 bool operator==(const LinkageLocation& other) const { 29 bool operator==(const LinkageLocation& other) const {
41 return location_ == other.location_; 30 return bit_field_ == other.bit_field_;
42 } 31 }
43 32
44 bool operator!=(const LinkageLocation& other) const { 33 bool operator!=(const LinkageLocation& other) const {
45 return !(*this == other); 34 return !(*this == other);
46 } 35 }
47 36
37 static LinkageLocation ForAnyRegister() {
38 return LinkageLocation(REGISTER, ANY_REGISTER);
39 }
40
41 static LinkageLocation ForRegister(int32_t reg) {
42 DCHECK(reg >= 0);
43 return LinkageLocation(REGISTER, reg);
44 }
45
46 static LinkageLocation ForCallerFrameSlot(int32_t slot) {
47 DCHECK(slot < 0);
48 return LinkageLocation(STACK_SLOT, slot);
49 }
50
51 static LinkageLocation ForCalleeFrameSlot(int32_t slot) {
52 // TODO(titzer): bailout instead of crashing here.
53 DCHECK(slot >= 0 && slot < LinkageLocation::MAX_STACK_SLOT);
54 return LinkageLocation(STACK_SLOT, slot);
55 }
56
48 private: 57 private:
49 friend class CallDescriptor; 58 friend class CallDescriptor;
50 friend class OperandGenerator; 59 friend class OperandGenerator;
51 // location < 0 -> a stack slot on the caller frame 60
52 // 0 <= location < 1023 -> a specific machine register 61 enum LocationType { REGISTER, STACK_SLOT };
53 // 1023 <= location < 1024 -> any machine register 62
54 // 1024 <= location -> a stack slot in the callee frame 63 class TypeField : public BitField<LocationType, 0, 1> {};
55 int16_t location_; 64 class LocationField : public BitField<int32_t, TypeField::kNext, 31> {};
65
66 static const int32_t ANY_REGISTER = -1;
67 static const int32_t MAX_STACK_SLOT = 32767;
68
69 LinkageLocation(LocationType type, int32_t location) {
70 bit_field_ = TypeField::encode(type) |
71 ((location << LocationField::kShift) & LocationField::kMask);
72 }
73
74 int32_t GetLocation() const {
75 return static_cast<int32_t>(bit_field_ & LocationField::kMask) >>
76 LocationField::kShift;
77 }
78
79 bool IsRegister() const { return TypeField::decode(bit_field_) == REGISTER; }
80 bool IsAnyRegister() const {
81 return IsRegister() && GetLocation() == ANY_REGISTER;
82 }
83 bool IsCallerFrameSlot() const { return !IsRegister() && GetLocation() < 0; }
84 bool IsCalleeFrameSlot() const { return !IsRegister() && GetLocation() >= 0; }
85
86 int32_t AsRegister() const {
87 DCHECK(IsRegister());
88 return GetLocation();
89 }
90 int32_t AsCallerFrameSlot() const {
91 DCHECK(IsCallerFrameSlot());
92 return GetLocation();
93 }
94 int32_t AsCalleeFrameSlot() const {
95 DCHECK(IsCalleeFrameSlot());
96 return GetLocation();
97 }
98
99 int32_t bit_field_;
56 }; 100 };
57 101
58 typedef Signature<LinkageLocation> LocationSignature; 102 typedef Signature<LinkageLocation> LocationSignature;
59 103
60 // Describes a call to various parts of the compiler. Every call has the notion 104 // Describes a call to various parts of the compiler. Every call has the notion
61 // of a "target", which is the first input to the call. 105 // of a "target", which is the first input to the call.
62 class CallDescriptor final : public ZoneObject { 106 class CallDescriptor final : public ZoneObject {
63 public: 107 public:
64 // Describes the kind of this call, which determines the target. 108 // Describes the kind of this call, which determines the target.
65 enum Kind { 109 enum Kind {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 CallDescriptor* const incoming_; 333 CallDescriptor* const incoming_;
290 334
291 DISALLOW_COPY_AND_ASSIGN(Linkage); 335 DISALLOW_COPY_AND_ASSIGN(Linkage);
292 }; 336 };
293 337
294 } // namespace compiler 338 } // namespace compiler
295 } // namespace internal 339 } // namespace internal
296 } // namespace v8 340 } // namespace v8
297 341
298 #endif // V8_COMPILER_LINKAGE_H_ 342 #endif // V8_COMPILER_LINKAGE_H_
OLDNEW
« no previous file with comments | « src/compiler/instruction-selector-impl.h ('k') | src/compiler/linkage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698