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

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

Issue 680313003: Move input/output counts directly into Operators, simplying OperatorProperties. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: yes Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/opcodes.h ('k') | src/compiler/operator.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 2013 the V8 project authors. All rights reserved. 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 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_OPERATOR_H_ 5 #ifndef V8_COMPILER_OPERATOR_H_
6 #define V8_COMPILER_OPERATOR_H_ 6 #define V8_COMPILER_OPERATOR_H_
7 7
8 #include <ostream> // NOLINT(readability/streams) 8 #include <ostream> // NOLINT(readability/streams)
9 9
10 #include "src/base/flags.h" 10 #include "src/base/flags.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 kNoRead = 1 << 4, // Has no scheduling dependency on Effects 42 kNoRead = 1 << 4, // Has no scheduling dependency on Effects
43 kNoWrite = 1 << 5, // Does not modify any Effects and thereby 43 kNoWrite = 1 << 5, // Does not modify any Effects and thereby
44 // create new scheduling dependencies. 44 // create new scheduling dependencies.
45 kNoThrow = 1 << 6, // Can never generate an exception. 45 kNoThrow = 1 << 6, // Can never generate an exception.
46 kFoldable = kNoRead | kNoWrite, 46 kFoldable = kNoRead | kNoWrite,
47 kEliminatable = kNoWrite | kNoThrow, 47 kEliminatable = kNoWrite | kNoThrow,
48 kPure = kNoRead | kNoWrite | kNoThrow | kIdempotent 48 kPure = kNoRead | kNoWrite | kNoThrow | kIdempotent
49 }; 49 };
50 typedef base::Flags<Property, uint8_t> Properties; 50 typedef base::Flags<Property, uint8_t> Properties;
51 51
52 Operator(Opcode opcode, Properties properties, const char* mnemonic) 52 // Constructor.
53 : opcode_(opcode), properties_(properties), mnemonic_(mnemonic) {} 53 Operator(Opcode opcode, Properties properties, const char* mnemonic,
54 virtual ~Operator(); 54 size_t value_in, size_t effect_in, size_t control_in,
55 size_t value_out, size_t effect_out, size_t control_out);
56
57 virtual ~Operator() {}
55 58
56 // A small integer unique to all instances of a particular kind of operator, 59 // A small integer unique to all instances of a particular kind of operator,
57 // useful for quick matching for specific kinds of operators. For fast access 60 // useful for quick matching for specific kinds of operators. For fast access
58 // the opcode is stored directly in the operator object. 61 // the opcode is stored directly in the operator object.
59 Opcode opcode() const { return opcode_; } 62 Opcode opcode() const { return opcode_; }
60 63
61 // Returns a constant string representing the mnemonic of the operator, 64 // Returns a constant string representing the mnemonic of the operator,
62 // without the static parameters. Useful for debugging. 65 // without the static parameters. Useful for debugging.
63 const char* mnemonic() const { return mnemonic_; } 66 const char* mnemonic() const { return mnemonic_; }
64 67
65 // Check if this operator equals another operator. Equivalent operators can 68 // Check if this operator equals another operator. Equivalent operators can
66 // be merged, and nodes with equivalent operators and equivalent inputs 69 // be merged, and nodes with equivalent operators and equivalent inputs
67 // can be merged. 70 // can be merged.
68 virtual bool Equals(const Operator*) const = 0; 71 virtual bool Equals(const Operator* that) const {
72 return this->opcode() == that->opcode();
73 }
69 74
70 // Compute a hashcode to speed up equivalence-set checking. 75 // Compute a hashcode to speed up equivalence-set checking.
71 // Equal operators should always have equal hashcodes, and unequal operators 76 // Equal operators should always have equal hashcodes, and unequal operators
72 // should have unequal hashcodes with high probability. 77 // should have unequal hashcodes with high probability.
73 virtual size_t HashCode() const = 0; 78 virtual size_t HashCode() const { return base::hash<Opcode>()(opcode()); }
74 79
75 // Check whether this operator has the given property. 80 // Check whether this operator has the given property.
76 bool HasProperty(Property property) const { 81 bool HasProperty(Property property) const {
77 return (properties() & property) == property; 82 return (properties() & property) == property;
78 } 83 }
79 84
80 // Number of data inputs to the operator, for verifying graph structure. 85 // Number of data inputs to the operator, for verifying graph structure.
81 virtual int InputCount() const = 0; 86 // TODO(titzer): convert callers to ValueInputCount();
87 int InputCount() const { return ValueInputCount(); }
82 88
83 // Number of data outputs from the operator, for verifying graph structure. 89 // Number of data outputs from the operator, for verifying graph structure.
84 virtual int OutputCount() const = 0; 90 // TODO(titzer): convert callers to ValueOutputCount();
91 int OutputCount() const { return ValueOutputCount(); }
85 92
86 Properties properties() const { return properties_; } 93 Properties properties() const { return properties_; }
87 94
95 // TODO(titzer): convert return values here to size_t.
96 int ValueInputCount() const { return value_in_; }
97 int EffectInputCount() const { return effect_in_; }
98 int ControlInputCount() const { return control_in_; }
99
100 int ValueOutputCount() const { return value_out_; }
101 int EffectOutputCount() const { return effect_out_; }
102 int ControlOutputCount() const { return control_out_; }
103
104 static inline size_t ZeroIfPure(Properties properties) {
105 return (properties & kPure) == kPure ? 0 : 1;
106 }
107
88 // TODO(titzer): API for input and output types, for typechecking graph. 108 // TODO(titzer): API for input and output types, for typechecking graph.
89 protected: 109 protected:
90 // Print the full operator into the given stream, including any 110 // Print the full operator into the given stream, including any
91 // static parameters. Useful for debugging and visualizing the IR. 111 // static parameters. Useful for debugging and visualizing the IR.
92 virtual void PrintTo(std::ostream& os) const = 0; // NOLINT 112 virtual void PrintTo(std::ostream& os) const;
93 friend std::ostream& operator<<(std::ostream& os, const Operator& op); 113 friend std::ostream& operator<<(std::ostream& os, const Operator& op);
94 114
95 private: 115 private:
96 Opcode opcode_; 116 Opcode opcode_;
97 Properties properties_; 117 Properties properties_;
98 const char* mnemonic_; 118 const char* mnemonic_;
119 uint32_t value_in_;
120 uint16_t effect_in_;
121 uint16_t control_in_;
122 uint16_t value_out_;
123 uint8_t effect_out_;
124 uint8_t control_out_;
99 125
100 DISALLOW_COPY_AND_ASSIGN(Operator); 126 DISALLOW_COPY_AND_ASSIGN(Operator);
101 }; 127 };
102 128
103 DEFINE_OPERATORS_FOR_FLAGS(Operator::Properties) 129 DEFINE_OPERATORS_FOR_FLAGS(Operator::Properties)
104 130
105 std::ostream& operator<<(std::ostream& os, const Operator& op); 131 std::ostream& operator<<(std::ostream& os, const Operator& op);
106 132
107 133
108 // An implementation of Operator that has no static parameters. Such operators
109 // have just a name, an opcode, and a fixed number of inputs and outputs.
110 // They can represented by singletons and shared globally.
111 class SimpleOperator : public Operator {
112 public:
113 SimpleOperator(Opcode opcode, Properties properties, size_t input_count,
114 size_t output_count, const char* mnemonic);
115 ~SimpleOperator();
116
117 virtual bool Equals(const Operator* that) const FINAL;
118 virtual size_t HashCode() const FINAL;
119 virtual int InputCount() const FINAL;
120 virtual int OutputCount() const FINAL;
121
122 private:
123 virtual void PrintTo(std::ostream& os) const FINAL;
124
125 uint8_t input_count_;
126 uint8_t output_count_;
127
128 DISALLOW_COPY_AND_ASSIGN(SimpleOperator);
129 };
130
131
132 // A templatized implementation of Operator that has one static parameter of 134 // A templatized implementation of Operator that has one static parameter of
133 // type {T}. 135 // type {T}.
134 template <typename T, typename Pred = std::equal_to<T>, 136 template <typename T, typename Pred = std::equal_to<T>,
135 typename Hash = base::hash<T>> 137 typename Hash = base::hash<T>>
136 class Operator1 : public Operator { 138 class Operator1 : public Operator {
137 public: 139 public:
138 Operator1(Opcode opcode, Properties properties, int input_count, 140 Operator1(Opcode opcode, Properties properties, const char* mnemonic,
139 int output_count, const char* mnemonic, T parameter, 141 size_t value_in, size_t effect_in, size_t control_in,
140 Pred const& pred = Pred(), Hash const& hash = Hash()) 142 size_t value_out, size_t effect_out, size_t control_out,
141 : Operator(opcode, properties, mnemonic), 143 T parameter, Pred const& pred = Pred(), Hash const& hash = Hash())
142 input_count_(input_count), 144 : Operator(opcode, properties, mnemonic, value_in, effect_in, control_in,
143 output_count_(output_count), 145 value_out, effect_out, control_out),
144 parameter_(parameter), 146 parameter_(parameter),
145 pred_(pred), 147 pred_(pred),
146 hash_(hash) {} 148 hash_(hash) {}
147 149
148 T const& parameter() const { return parameter_; } 150 T const& parameter() const { return parameter_; }
149 151
150 virtual bool Equals(const Operator* other) const FINAL { 152 virtual bool Equals(const Operator* other) const FINAL {
151 if (opcode() != other->opcode()) return false; 153 if (opcode() != other->opcode()) return false;
152 const Operator1<T>* that = static_cast<const Operator1<T>*>(other); 154 const Operator1<T>* that = static_cast<const Operator1<T>*>(other);
153 return this->pred_(this->parameter(), that->parameter()); 155 return this->pred_(this->parameter(), that->parameter());
154 } 156 }
155 virtual size_t HashCode() const FINAL { 157 virtual size_t HashCode() const FINAL {
156 return base::hash_combine(this->opcode(), this->hash_(this->parameter())); 158 return base::hash_combine(this->opcode(), this->hash_(this->parameter()));
157 } 159 }
158 virtual int InputCount() const FINAL { return input_count_; }
159 virtual int OutputCount() const FINAL { return output_count_; }
160 virtual void PrintParameter(std::ostream& os) const { 160 virtual void PrintParameter(std::ostream& os) const {
161 os << "[" << this->parameter() << "]"; 161 os << "[" << this->parameter() << "]";
162 } 162 }
163 163
164 protected: 164 protected:
165 virtual void PrintTo(std::ostream& os) const FINAL { 165 virtual void PrintTo(std::ostream& os) const FINAL {
166 os << mnemonic(); 166 os << mnemonic();
167 PrintParameter(os); 167 PrintParameter(os);
168 } 168 }
169 169
170 private: 170 private:
171 int const input_count_;
172 int const output_count_;
173 T const parameter_; 171 T const parameter_;
174 Pred const pred_; 172 Pred const pred_;
175 Hash const hash_; 173 Hash const hash_;
176 }; 174 };
177 175
178 176
179 // Helper to extract parameters from Operator1<*> operator. 177 // Helper to extract parameters from Operator1<*> operator.
180 template <typename T> 178 template <typename T>
181 inline T const& OpParameter(const Operator* op) { 179 inline T const& OpParameter(const Operator* op) {
182 return static_cast<const Operator1<T>*>(op)->parameter(); 180 return static_cast<const Operator1<T>*>(op)->parameter();
183 } 181 }
184 182
185 } // namespace compiler 183 } // namespace compiler
186 } // namespace internal 184 } // namespace internal
187 } // namespace v8 185 } // namespace v8
188 186
189 #endif // V8_COMPILER_OPERATOR_H_ 187 #endif // V8_COMPILER_OPERATOR_H_
OLDNEW
« no previous file with comments | « src/compiler/opcodes.h ('k') | src/compiler/operator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698