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

Side by Side Diff: src/arm/lithium-arm.h

Issue 6880204: Refactor lithium classes to reduce the number of virtual functions. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/arm/lithium-arm.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 V(ConstantI) \ 86 V(ConstantI) \
87 V(ConstantT) \ 87 V(ConstantT) \
88 V(Context) \ 88 V(Context) \
89 V(DeleteProperty) \ 89 V(DeleteProperty) \
90 V(Deoptimize) \ 90 V(Deoptimize) \
91 V(DivI) \ 91 V(DivI) \
92 V(DoubleToI) \ 92 V(DoubleToI) \
93 V(ExternalArrayLength) \ 93 V(ExternalArrayLength) \
94 V(FixedArrayLength) \ 94 V(FixedArrayLength) \
95 V(FunctionLiteral) \ 95 V(FunctionLiteral) \
96 V(Gap) \
97 V(GetCachedArrayIndex) \ 96 V(GetCachedArrayIndex) \
98 V(GlobalObject) \ 97 V(GlobalObject) \
99 V(GlobalReceiver) \ 98 V(GlobalReceiver) \
100 V(Goto) \ 99 V(Goto) \
101 V(HasCachedArrayIndex) \ 100 V(HasCachedArrayIndex) \
102 V(HasCachedArrayIndexAndBranch) \ 101 V(HasCachedArrayIndexAndBranch) \
103 V(HasInstanceType) \ 102 V(HasInstanceType) \
104 V(HasInstanceTypeAndBranch) \ 103 V(HasInstanceTypeAndBranch) \
105 V(InstanceOf) \ 104 V(InstanceOf) \
106 V(InstanceOfAndBranch) \ 105 V(InstanceOfAndBranch) \
107 V(InstanceOfKnownGlobal) \ 106 V(InstanceOfKnownGlobal) \
107 V(InstructionGap) \
108 V(Integer32ToDouble) \ 108 V(Integer32ToDouble) \
109 V(InvokeFunction) \ 109 V(InvokeFunction) \
110 V(IsNull) \ 110 V(IsNull) \
111 V(IsNullAndBranch) \ 111 V(IsNullAndBranch) \
112 V(IsObject) \ 112 V(IsObject) \
113 V(IsObjectAndBranch) \ 113 V(IsObjectAndBranch) \
114 V(IsSmi) \ 114 V(IsSmi) \
115 V(IsSmiAndBranch) \ 115 V(IsSmiAndBranch) \
116 V(JSArrayLength) \ 116 V(JSArrayLength) \
117 V(Label) \ 117 V(Label) \
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 V(Typeof) \ 164 V(Typeof) \
165 V(TypeofIs) \ 165 V(TypeofIs) \
166 V(TypeofIsAndBranch) \ 166 V(TypeofIsAndBranch) \
167 V(IsConstructCall) \ 167 V(IsConstructCall) \
168 V(IsConstructCallAndBranch) \ 168 V(IsConstructCallAndBranch) \
169 V(UnaryMathOperation) \ 169 V(UnaryMathOperation) \
170 V(UnknownOSRValue) \ 170 V(UnknownOSRValue) \
171 V(ValueOf) 171 V(ValueOf)
172 172
173 173
174 #define DECLARE_INSTRUCTION(type) \ 174 #define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \
175 virtual bool Is##type() const { return true; } \ 175 virtual Opcode opcode() const { return LInstruction::k##type; } \
176 static L##type* cast(LInstruction* instr) { \ 176 virtual void CompileToNative(LCodeGen* generator); \
177 ASSERT(instr->Is##type()); \ 177 virtual const char* Mnemonic() const { return mnemonic; } \
178 return reinterpret_cast<L##type*>(instr); \ 178 static L##type* cast(LInstruction* instr) { \
179 ASSERT(instr->Is##type()); \
180 return reinterpret_cast<L##type*>(instr); \
179 } 181 }
180 182
181 183
182 #define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \
183 virtual void CompileToNative(LCodeGen* generator); \
184 virtual const char* Mnemonic() const { return mnemonic; } \
185 DECLARE_INSTRUCTION(type)
186
187
188 #define DECLARE_HYDROGEN_ACCESSOR(type) \ 184 #define DECLARE_HYDROGEN_ACCESSOR(type) \
189 H##type* hydrogen() const { \ 185 H##type* hydrogen() const { \
190 return H##type::cast(hydrogen_value()); \ 186 return H##type::cast(hydrogen_value()); \
191 } 187 }
192 188
193 189
194 class LInstruction: public ZoneObject { 190 class LInstruction: public ZoneObject {
195 public: 191 public:
196 LInstruction() 192 LInstruction()
197 : environment_(NULL), 193 : environment_(NULL),
198 hydrogen_value_(NULL), 194 hydrogen_value_(NULL),
199 is_call_(false), 195 is_call_(false),
200 is_save_doubles_(false) { } 196 is_save_doubles_(false) { }
201 virtual ~LInstruction() { } 197 virtual ~LInstruction() { }
202 198
203 virtual void CompileToNative(LCodeGen* generator) = 0; 199 virtual void CompileToNative(LCodeGen* generator) = 0;
204 virtual const char* Mnemonic() const = 0; 200 virtual const char* Mnemonic() const = 0;
205 virtual void PrintTo(StringStream* stream); 201 virtual void PrintTo(StringStream* stream);
206 virtual void PrintDataTo(StringStream* stream) = 0; 202 virtual void PrintDataTo(StringStream* stream) = 0;
207 virtual void PrintOutputOperandTo(StringStream* stream) = 0; 203 virtual void PrintOutputOperandTo(StringStream* stream) = 0;
208 204
209 // Declare virtual type testers. 205 enum Opcode {
210 #define DECLARE_DO(type) virtual bool Is##type() const { return false; } 206 // Declare a unique enum value for each instruction.
211 LITHIUM_ALL_INSTRUCTION_LIST(DECLARE_DO) 207 #define DECLARE_OPCODE(type) k##type,
212 #undef DECLARE_DO 208 LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_OPCODE)
209 kNumberOfInstructions
210 #undef DECLARE_OPCODE
211 };
212
213 virtual Opcode opcode() const = 0;
214
215 // Declare non-virtual type testers for all leaf IR classes.
216 #define DECLARE_PREDICATE(type) \
217 bool Is##type() const { return opcode() == k##type; }
218 LITHIUM_CONCRETE_INSTRUCTION_LIST(DECLARE_PREDICATE)
219 #undef DECLARE_PREDICATE
220
221 // Declare virtual predicates for instructions that don't have
222 // an opcode.
223 virtual bool IsGap() const { return false; }
213 224
214 virtual bool IsControl() const { return false; } 225 virtual bool IsControl() const { return false; }
215 virtual void SetBranchTargets(int true_block_id, int false_block_id) { } 226 virtual void SetBranchTargets(int true_block_id, int false_block_id) { }
216 227
217 void set_environment(LEnvironment* env) { environment_ = env; } 228 void set_environment(LEnvironment* env) { environment_ = env; }
218 LEnvironment* environment() const { return environment_; } 229 LEnvironment* environment() const { return environment_; }
219 bool HasEnvironment() const { return environment_ != NULL; } 230 bool HasEnvironment() const { return environment_ != NULL; }
220 231
221 void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); } 232 void set_pointer_map(LPointerMap* p) { pointer_map_.set(p); }
222 LPointerMap* pointer_map() const { return pointer_map_.get(); } 233 LPointerMap* pointer_map() const { return pointer_map_.get(); }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 class LGap: public LTemplateInstruction<0, 0, 0> { 340 class LGap: public LTemplateInstruction<0, 0, 0> {
330 public: 341 public:
331 explicit LGap(HBasicBlock* block) 342 explicit LGap(HBasicBlock* block)
332 : block_(block) { 343 : block_(block) {
333 parallel_moves_[BEFORE] = NULL; 344 parallel_moves_[BEFORE] = NULL;
334 parallel_moves_[START] = NULL; 345 parallel_moves_[START] = NULL;
335 parallel_moves_[END] = NULL; 346 parallel_moves_[END] = NULL;
336 parallel_moves_[AFTER] = NULL; 347 parallel_moves_[AFTER] = NULL;
337 } 348 }
338 349
339 DECLARE_CONCRETE_INSTRUCTION(Gap, "gap") 350 // Can't use the DECLARE-macro here because of sub-classes.
340 virtual void PrintDataTo(StringStream* stream) const; 351 virtual bool IsGap() const { return true; }
352 virtual void PrintDataTo(StringStream* stream);
353 static LGap* cast(LInstruction* instr) {
354 ASSERT(instr->IsGap());
355 return reinterpret_cast<LGap*>(instr);
356 }
341 357
342 bool IsRedundant() const; 358 bool IsRedundant() const;
343 359
344 HBasicBlock* block() const { return block_; } 360 HBasicBlock* block() const { return block_; }
345 361
346 enum InnerPosition { 362 enum InnerPosition {
347 BEFORE, 363 BEFORE,
348 START, 364 START,
349 END, 365 END,
350 AFTER, 366 AFTER,
351 FIRST_INNER_POSITION = BEFORE, 367 FIRST_INNER_POSITION = BEFORE,
352 LAST_INNER_POSITION = AFTER 368 LAST_INNER_POSITION = AFTER
353 }; 369 };
354 370
355 LParallelMove* GetOrCreateParallelMove(InnerPosition pos) { 371 LParallelMove* GetOrCreateParallelMove(InnerPosition pos) {
356 if (parallel_moves_[pos] == NULL) parallel_moves_[pos] = new LParallelMove; 372 if (parallel_moves_[pos] == NULL) parallel_moves_[pos] = new LParallelMove;
357 return parallel_moves_[pos]; 373 return parallel_moves_[pos];
358 } 374 }
359 375
360 LParallelMove* GetParallelMove(InnerPosition pos) { 376 LParallelMove* GetParallelMove(InnerPosition pos) {
361 return parallel_moves_[pos]; 377 return parallel_moves_[pos];
362 } 378 }
363 379
364 private: 380 private:
365 LParallelMove* parallel_moves_[LAST_INNER_POSITION + 1]; 381 LParallelMove* parallel_moves_[LAST_INNER_POSITION + 1];
366 HBasicBlock* block_; 382 HBasicBlock* block_;
367 }; 383 };
368 384
369 385
386 class LInstructionGap: public LGap {
387 public:
388 explicit LInstructionGap(HBasicBlock* block) : LGap(block) { }
389
390 DECLARE_CONCRETE_INSTRUCTION(InstructionGap, "gap")
391 };
392
393
370 class LGoto: public LTemplateInstruction<0, 0, 0> { 394 class LGoto: public LTemplateInstruction<0, 0, 0> {
371 public: 395 public:
372 LGoto(int block_id, bool include_stack_check = false) 396 LGoto(int block_id, bool include_stack_check = false)
373 : block_id_(block_id), include_stack_check_(include_stack_check) { } 397 : block_id_(block_id), include_stack_check_(include_stack_check) { }
374 398
375 DECLARE_CONCRETE_INSTRUCTION(Goto, "goto") 399 DECLARE_CONCRETE_INSTRUCTION(Goto, "goto")
376 virtual void PrintDataTo(StringStream* stream); 400 virtual void PrintDataTo(StringStream* stream);
377 virtual bool IsControl() const { return true; } 401 virtual bool IsControl() const { return true; }
378 402
379 int block_id() const { return block_id_; } 403 int block_id() const { return block_id_; }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 472
449 class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> { 473 class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> {
450 public: 474 public:
451 DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value") 475 DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value")
452 }; 476 };
453 477
454 478
455 template<int I, int T> 479 template<int I, int T>
456 class LControlInstruction: public LTemplateInstruction<0, I, T> { 480 class LControlInstruction: public LTemplateInstruction<0, I, T> {
457 public: 481 public:
458 DECLARE_INSTRUCTION(ControlInstruction)
459 virtual bool IsControl() const { return true; } 482 virtual bool IsControl() const { return true; }
460 483
461 int true_block_id() const { return true_block_id_; } 484 int true_block_id() const { return true_block_id_; }
462 int false_block_id() const { return false_block_id_; } 485 int false_block_id() const { return false_block_id_; }
463 void SetBranchTargets(int true_block_id, int false_block_id) { 486 void SetBranchTargets(int true_block_id, int false_block_id) {
464 true_block_id_ = true_block_id; 487 true_block_id_ = true_block_id;
465 false_block_id_ = false_block_id; 488 false_block_id_ = false_block_id;
466 } 489 }
467 490
468 private: 491 private:
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 class LArithmeticD: public LTemplateInstruction<1, 2, 0> { 1122 class LArithmeticD: public LTemplateInstruction<1, 2, 0> {
1100 public: 1123 public:
1101 LArithmeticD(Token::Value op, LOperand* left, LOperand* right) 1124 LArithmeticD(Token::Value op, LOperand* left, LOperand* right)
1102 : op_(op) { 1125 : op_(op) {
1103 inputs_[0] = left; 1126 inputs_[0] = left;
1104 inputs_[1] = right; 1127 inputs_[1] = right;
1105 } 1128 }
1106 1129
1107 Token::Value op() const { return op_; } 1130 Token::Value op() const { return op_; }
1108 1131
1132 virtual Opcode opcode() const { return LInstruction::kArithmeticD; }
1109 virtual void CompileToNative(LCodeGen* generator); 1133 virtual void CompileToNative(LCodeGen* generator);
1110 virtual const char* Mnemonic() const; 1134 virtual const char* Mnemonic() const;
1111 1135
1112 private: 1136 private:
1113 Token::Value op_; 1137 Token::Value op_;
1114 }; 1138 };
1115 1139
1116 1140
1117 class LArithmeticT: public LTemplateInstruction<1, 2, 0> { 1141 class LArithmeticT: public LTemplateInstruction<1, 2, 0> {
1118 public: 1142 public:
1119 LArithmeticT(Token::Value op, LOperand* left, LOperand* right) 1143 LArithmeticT(Token::Value op, LOperand* left, LOperand* right)
1120 : op_(op) { 1144 : op_(op) {
1121 inputs_[0] = left; 1145 inputs_[0] = left;
1122 inputs_[1] = right; 1146 inputs_[1] = right;
1123 } 1147 }
1124 1148
1149 virtual Opcode opcode() const { return LInstruction::kArithmeticT; }
1125 virtual void CompileToNative(LCodeGen* generator); 1150 virtual void CompileToNative(LCodeGen* generator);
1126 virtual const char* Mnemonic() const; 1151 virtual const char* Mnemonic() const;
1127 1152
1128 Token::Value op() const { return op_; } 1153 Token::Value op() const { return op_; }
1129 1154
1130 private: 1155 private:
1131 Token::Value op_; 1156 Token::Value op_;
1132 }; 1157 };
1133 1158
1134 1159
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 int argument_count_; 2227 int argument_count_;
2203 LAllocator* allocator_; 2228 LAllocator* allocator_;
2204 int position_; 2229 int position_;
2205 LInstruction* instruction_pending_deoptimization_environment_; 2230 LInstruction* instruction_pending_deoptimization_environment_;
2206 int pending_deoptimization_ast_id_; 2231 int pending_deoptimization_ast_id_;
2207 2232
2208 DISALLOW_COPY_AND_ASSIGN(LChunkBuilder); 2233 DISALLOW_COPY_AND_ASSIGN(LChunkBuilder);
2209 }; 2234 };
2210 2235
2211 #undef DECLARE_HYDROGEN_ACCESSOR 2236 #undef DECLARE_HYDROGEN_ACCESSOR
2212 #undef DECLARE_INSTRUCTION
2213 #undef DECLARE_CONCRETE_INSTRUCTION 2237 #undef DECLARE_CONCRETE_INSTRUCTION
2214 2238
2215 } } // namespace v8::internal 2239 } } // namespace v8::internal
2216 2240
2217 #endif // V8_ARM_LITHIUM_ARM_H_ 2241 #endif // V8_ARM_LITHIUM_ARM_H_
OLDNEW
« no previous file with comments | « no previous file | src/arm/lithium-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698