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

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 10905233: Whenever possible use length passed to the List constructor for bounds checks instead of loading it… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address Srdjan's comments Created 8 years, 3 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 | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/intermediate_language.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_ 6 #define VM_INTERMEDIATE_LANGUAGE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 M(SmiToDouble) \ 236 M(SmiToDouble) \
237 M(CheckClass) \ 237 M(CheckClass) \
238 M(CheckSmi) \ 238 M(CheckSmi) \
239 M(Constant) \ 239 M(Constant) \
240 M(CheckEitherNonSmi) \ 240 M(CheckEitherNonSmi) \
241 M(UnboxedDoubleBinaryOp) \ 241 M(UnboxedDoubleBinaryOp) \
242 M(MathSqrt) \ 242 M(MathSqrt) \
243 M(UnboxDouble) \ 243 M(UnboxDouble) \
244 M(BoxDouble) \ 244 M(BoxDouble) \
245 M(CheckArrayBound) \ 245 M(CheckArrayBound) \
246 246 M(CheckBound) \
247 247
248 #define FORWARD_DECLARATION(type) class type##Instr; 248 #define FORWARD_DECLARATION(type) class type##Instr;
249 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) 249 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION)
250 #undef FORWARD_DECLARATION 250 #undef FORWARD_DECLARATION
251 251
252 252
253 // Functions required in all concrete instruction classes. 253 // Functions required in all concrete instruction classes.
254 #define DECLARE_INSTRUCTION(type) \ 254 #define DECLARE_INSTRUCTION(type) \
255 virtual Tag tag() const { return k##type; } \ 255 virtual Tag tag() const { return k##type; } \
256 virtual void Accept(FlowGraphVisitor* visitor); \ 256 virtual void Accept(FlowGraphVisitor* visitor); \
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 private: 438 private:
439 friend class Definition; // Needed for InsertBefore, InsertAfter. 439 friend class Definition; // Needed for InsertBefore, InsertAfter.
440 440
441 // Classes that set deopt_id_. 441 // Classes that set deopt_id_.
442 friend class UnboxDoubleInstr; 442 friend class UnboxDoubleInstr;
443 friend class UnboxedDoubleBinaryOpInstr; 443 friend class UnboxedDoubleBinaryOpInstr;
444 friend class MathSqrtInstr; 444 friend class MathSqrtInstr;
445 friend class CheckClassInstr; 445 friend class CheckClassInstr;
446 friend class CheckSmiInstr; 446 friend class CheckSmiInstr;
447 friend class CheckArrayBoundInstr; 447 friend class CheckArrayBoundInstr;
448 friend class CheckBoundInstr;
448 friend class CheckEitherNonSmiInstr; 449 friend class CheckEitherNonSmiInstr;
449 friend class LICM; 450 friend class LICM;
450 451
451 intptr_t deopt_id_; 452 intptr_t deopt_id_;
452 intptr_t lifetime_position_; // Position used by register allocator. 453 intptr_t lifetime_position_; // Position used by register allocator.
453 Instruction* previous_; 454 Instruction* previous_;
454 Instruction* next_; 455 Instruction* next_;
455 Environment* env_; 456 Environment* env_;
456 DISALLOW_COPY_AND_ASSIGN(Instruction); 457 DISALLOW_COPY_AND_ASSIGN(Instruction);
457 }; 458 };
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 class StaticCallInstr : public TemplateDefinition<0> { 1990 class StaticCallInstr : public TemplateDefinition<0> {
1990 public: 1991 public:
1991 StaticCallInstr(intptr_t token_pos, 1992 StaticCallInstr(intptr_t token_pos,
1992 const Function& function, 1993 const Function& function,
1993 const Array& argument_names, 1994 const Array& argument_names,
1994 ZoneGrowableArray<PushArgumentInstr*>* arguments) 1995 ZoneGrowableArray<PushArgumentInstr*>* arguments)
1995 : token_pos_(token_pos), 1996 : token_pos_(token_pos),
1996 function_(function), 1997 function_(function),
1997 argument_names_(argument_names), 1998 argument_names_(argument_names),
1998 arguments_(arguments), 1999 arguments_(arguments),
1999 result_cid_(kDynamicCid) { 2000 result_cid_(kDynamicCid),
2001 is_known_constructor_(false) {
2000 ASSERT(function.IsZoneHandle()); 2002 ASSERT(function.IsZoneHandle());
2001 ASSERT(argument_names.IsZoneHandle()); 2003 ASSERT(argument_names.IsZoneHandle());
2002 } 2004 }
2003 2005
2004 DECLARE_INSTRUCTION(StaticCall) 2006 DECLARE_INSTRUCTION(StaticCall)
2005 virtual RawAbstractType* CompileType() const; 2007 virtual RawAbstractType* CompileType() const;
2006 2008
2007 // Accessors forwarded to the AST node. 2009 // Accessors forwarded to the AST node.
2008 const Function& function() const { return function_; } 2010 const Function& function() const { return function_; }
2009 const Array& argument_names() const { return argument_names_; } 2011 const Array& argument_names() const { return argument_names_; }
2010 intptr_t token_pos() const { return token_pos_; } 2012 intptr_t token_pos() const { return token_pos_; }
2011 2013
2012 virtual intptr_t ArgumentCount() const { return arguments_->length(); } 2014 virtual intptr_t ArgumentCount() const { return arguments_->length(); }
2013 PushArgumentInstr* ArgumentAt(intptr_t index) const { 2015 PushArgumentInstr* ArgumentAt(intptr_t index) const {
2014 return (*arguments_)[index]; 2016 return (*arguments_)[index];
2015 } 2017 }
2016 2018
2017 virtual void PrintOperandsTo(BufferFormatter* f) const; 2019 virtual void PrintOperandsTo(BufferFormatter* f) const;
2018 2020
2019 virtual bool CanDeoptimize() const { return true; } 2021 virtual bool CanDeoptimize() const { return true; }
2020 virtual intptr_t ResultCid() const { return result_cid_; } 2022 virtual intptr_t ResultCid() const { return result_cid_; }
2021 void set_result_cid(intptr_t value) { result_cid_ = value; } 2023 void set_result_cid(intptr_t value) { result_cid_ = value; }
2022 2024
2025 bool is_known_constructor() const { return is_known_constructor_; }
2026 void set_is_known_constructor(bool is_known_constructor) {
2027 is_known_constructor_ = is_known_constructor;
2028 }
2029
2023 private: 2030 private:
2024 const intptr_t token_pos_; 2031 const intptr_t token_pos_;
2025 const Function& function_; 2032 const Function& function_;
2026 const Array& argument_names_; 2033 const Array& argument_names_;
2027 ZoneGrowableArray<PushArgumentInstr*>* arguments_; 2034 ZoneGrowableArray<PushArgumentInstr*>* arguments_;
2028 intptr_t result_cid_; // For some library functions we know the result. 2035 intptr_t result_cid_; // For some library functions we know the result.
2029 2036
2037 // Some library constructors have known semantics.
2038 bool is_known_constructor_;
2039
2030 DISALLOW_COPY_AND_ASSIGN(StaticCallInstr); 2040 DISALLOW_COPY_AND_ASSIGN(StaticCallInstr);
2031 }; 2041 };
2032 2042
2033 2043
2034 class LoadLocalInstr : public TemplateDefinition<0> { 2044 class LoadLocalInstr : public TemplateDefinition<0> {
2035 public: 2045 public:
2036 LoadLocalInstr(const LocalVariable& local, intptr_t context_level) 2046 LoadLocalInstr(const LocalVariable& local, intptr_t context_level)
2037 : local_(local), 2047 : local_(local),
2038 context_level_(context_level) { } 2048 context_level_(context_level) { }
2039 2049
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2861 public: 2871 public:
2862 MathSqrtInstr(Value* value, StaticCallInstr* instance_call) { 2872 MathSqrtInstr(Value* value, StaticCallInstr* instance_call) {
2863 ASSERT(value != NULL); 2873 ASSERT(value != NULL);
2864 inputs_[0] = value; 2874 inputs_[0] = value;
2865 deopt_id_ = instance_call->deopt_id(); 2875 deopt_id_ = instance_call->deopt_id();
2866 } 2876 }
2867 2877
2868 Value* value() const { return inputs_[0]; } 2878 Value* value() const { return inputs_[0]; }
2869 2879
2870 virtual bool CanDeoptimize() const { return false; } 2880 virtual bool CanDeoptimize() const { return false; }
2871 virtual bool HasSideEffect() const { return false; } 2881 virtual bool AffectedBySideEffect() const { return false; }
2872 2882
2873 virtual bool AttributesEqual(Definition* other) const { 2883 virtual bool AttributesEqual(Definition* other) const {
2874 return true; 2884 return true;
2875 } 2885 }
2876 2886
2877 // The output is not an instance but when it is boxed it becomes double. 2887 // The output is not an instance but when it is boxed it becomes double.
2878 virtual intptr_t ResultCid() const { return kDoubleCid; } 2888 virtual intptr_t ResultCid() const { return kDoubleCid; }
2879 2889
2880 virtual Representation representation() const { 2890 virtual Representation representation() const {
2881 return kUnboxedDouble; 2891 return kUnboxedDouble;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
3249 3259
3250 virtual bool AttributesEqual(Definition* other) const; 3260 virtual bool AttributesEqual(Definition* other) const;
3251 3261
3252 virtual bool AffectedBySideEffect() const { return false; } 3262 virtual bool AffectedBySideEffect() const { return false; }
3253 3263
3254 Value* array() const { return inputs_[0]; } 3264 Value* array() const { return inputs_[0]; }
3255 Value* index() const { return inputs_[1]; } 3265 Value* index() const { return inputs_[1]; }
3256 3266
3257 intptr_t array_type() const { return array_type_; } 3267 intptr_t array_type() const { return array_type_; }
3258 3268
3269 virtual Definition* Canonicalize();
3270
3259 private: 3271 private:
3260 intptr_t array_type_; 3272 intptr_t array_type_;
3261 3273
3262 DISALLOW_COPY_AND_ASSIGN(CheckArrayBoundInstr); 3274 DISALLOW_COPY_AND_ASSIGN(CheckArrayBoundInstr);
3263 }; 3275 };
3264 3276
3265 3277
3278 class CheckBoundInstr : public TemplateDefinition<2> {
3279 public:
3280 CheckBoundInstr(Value* length,
3281 Value* index,
3282 intptr_t deopt_id) {
3283 ASSERT(length != NULL);
3284 ASSERT(index != NULL);
3285 inputs_[0] = length;
3286 inputs_[1] = index;
3287 deopt_id_ = deopt_id;
3288 }
3289
3290 DECLARE_INSTRUCTION(CheckBound)
3291 virtual RawAbstractType* CompileType() const;
3292
3293 virtual bool CanDeoptimize() const { return true; }
3294 virtual intptr_t ResultCid() const { return kIllegalCid; }
3295
3296 virtual bool AttributesEqual(Definition* other) const {
3297 return true;
3298 }
3299
3300 virtual bool AffectedBySideEffect() const { return false; }
3301
3302 Value* length() const { return inputs_[0]; }
3303 Value* index() const { return inputs_[1]; }
3304
3305 private:
3306 DISALLOW_COPY_AND_ASSIGN(CheckBoundInstr);
3307 };
3308
3309
3266 #undef DECLARE_INSTRUCTION 3310 #undef DECLARE_INSTRUCTION
3267 3311
3268 class Environment : public ZoneAllocated { 3312 class Environment : public ZoneAllocated {
3269 public: 3313 public:
3270 // Iterate the non-NULL values in the innermost level of an environment. 3314 // Iterate the non-NULL values in the innermost level of an environment.
3271 class ShallowIterator : public ValueObject { 3315 class ShallowIterator : public ValueObject {
3272 public: 3316 public:
3273 explicit ShallowIterator(Environment* environment) 3317 explicit ShallowIterator(Environment* environment)
3274 : environment_(environment), index_(0) { } 3318 : environment_(environment), index_(0) { }
3275 3319
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 ForwardInstructionIterator* current_iterator_; 3488 ForwardInstructionIterator* current_iterator_;
3445 3489
3446 private: 3490 private:
3447 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 3491 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
3448 }; 3492 };
3449 3493
3450 3494
3451 } // namespace dart 3495 } // namespace dart
3452 3496
3453 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 3497 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698