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

Side by Side Diff: src/hydrogen-instructions.h

Issue 17568015: New array bounds check elimination pass (focused on induction variables and bitwise operations). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Recursive traversal implementation. Created 7 years, 5 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 21 matching lines...) Expand all
32 32
33 #include "allocation.h" 33 #include "allocation.h"
34 #include "code-stubs.h" 34 #include "code-stubs.h"
35 #include "data-flow.h" 35 #include "data-flow.h"
36 #include "small-pointer-list.h" 36 #include "small-pointer-list.h"
37 #include "string-stream.h" 37 #include "string-stream.h"
38 #include "v8conversions.h" 38 #include "v8conversions.h"
39 #include "v8utils.h" 39 #include "v8utils.h"
40 #include "zone.h" 40 #include "zone.h"
41 41
42
titzer 2013/07/18 12:22:58 unnecessary whitespace change
Massi 2013/07/23 07:57:50 Done.
42 namespace v8 { 43 namespace v8 {
43 namespace internal { 44 namespace internal {
44 45
45 // Forward declarations. 46 // Forward declarations.
46 class HBasicBlock; 47 class HBasicBlock;
47 class HEnvironment; 48 class HEnvironment;
48 class HInferRepresentation; 49 class HInferRepresentation;
49 class HInstruction; 50 class HInstruction;
50 class HLoopInformation; 51 class HLoopInformation;
51 class HValue; 52 class HValue;
(...skipping 2991 matching lines...) Expand 10 before | Expand all | Expand 10 after
3043 3044
3044 private: 3045 private:
3045 ZoneList<Handle<JSObject> > prototypes_; 3046 ZoneList<Handle<JSObject> > prototypes_;
3046 ZoneList<Handle<Map> > maps_; 3047 ZoneList<Handle<Map> > maps_;
3047 UniqueValueId first_prototype_unique_id_; 3048 UniqueValueId first_prototype_unique_id_;
3048 UniqueValueId last_prototype_unique_id_; 3049 UniqueValueId last_prototype_unique_id_;
3049 bool can_omit_prototype_maps_; 3050 bool can_omit_prototype_maps_;
3050 }; 3051 };
3051 3052
3052 3053
3054 class InductionVariableData;
3055
3056
3057 struct InductionVariableLimitUpdate {
3058 InductionVariableData* updated_variable;
3059 HValue* limit;
3060 bool limit_is_upper;
3061 bool limit_is_included;
3062
3063 InductionVariableLimitUpdate()
3064 : updated_variable(NULL), limit(NULL),
3065 limit_is_upper(false), limit_is_included(false) {}
3066 };
3067
3068
3069 class HBoundsCheck;
3070 class HPhi;
3071 class HConstant;
3072 class HBitwise;
3073
3074
3075 class InductionVariableData : public ZoneObject {
3076 public:
3077 class InductionVariableCheck : public ZoneObject {
3078 public:
3079 HBoundsCheck* check() { return check_; }
3080 InductionVariableCheck* next() { return next_; }
3081 bool HasUpperLimit() { return upper_limit_ >= 0; }
3082 int32_t upper_limit() {
3083 ASSERT(HasUpperLimit());
3084 return upper_limit_;
3085 }
3086 void set_upper_limit(int32_t upper_limit) {
3087 upper_limit_ = upper_limit;
3088 }
3089
3090 bool processed() { return processed_; }
3091 void set_processed() { processed_ = true; }
3092
3093 InductionVariableCheck(HBoundsCheck* check,
3094 InductionVariableCheck* next,
3095 int32_t upper_limit = kNoLimit)
3096 : check_(check), next_(next), upper_limit_(upper_limit),
3097 processed_(false) {}
3098
3099 private:
3100 HBoundsCheck* check_;
3101 InductionVariableCheck* next_;
3102 int32_t upper_limit_;
3103 bool processed_;
3104 };
3105
3106 class ChecksRelatedToLength : public ZoneObject {
3107 public:
3108 HValue* length() { return length_; }
3109 ChecksRelatedToLength* next() { return next_; }
3110 InductionVariableCheck* checks() { return checks_; }
3111
3112 void AddCheck(HBoundsCheck* check, int32_t upper_limit = kNoLimit);
3113 void CloseCurrentBlock();
3114
3115 ChecksRelatedToLength(HValue* length, ChecksRelatedToLength* next)
3116 : length_(length), next_(next), checks_(NULL),
3117 first_check_in_block_(NULL),
3118 added_index_(NULL),
3119 added_constant_(NULL),
3120 current_and_mask_in_block_(0),
3121 current_or_mask_in_block_(0) {}
3122
3123 private:
3124 void UseNewIndexInCurrentBlock(Token::Value token,
3125 int32_t mask,
3126 HValue* index_base,
3127 HValue* context);
3128
3129 HBoundsCheck* first_check_in_block() { return first_check_in_block_; }
3130 HBitwise* added_index() { return added_index_; }
3131 void set_added_index(HBitwise* index) { added_index_ = index; }
3132 HConstant* added_constant() { return added_constant_; }
3133 void set_added_constant(HConstant* constant) { added_constant_ = constant; }
3134 int32_t current_and_mask_in_block() { return current_and_mask_in_block_; }
3135 int32_t current_or_mask_in_block() { return current_or_mask_in_block_; }
3136 int32_t current_upper_limit() { return current_upper_limit_; }
3137
3138 HValue* length_;
3139 ChecksRelatedToLength* next_;
3140 InductionVariableCheck* checks_;
3141
3142 HBoundsCheck* first_check_in_block_;
3143 HBitwise* added_index_;
3144 HConstant* added_constant_;
3145 int32_t current_and_mask_in_block_;
3146 int32_t current_or_mask_in_block_;
3147 int32_t current_upper_limit_;
3148 };
3149
3150 struct LimitFromPredecessorBlock {
3151 InductionVariableData* variable;
3152 Token::Value token;
3153 HValue* limit;
3154 HBasicBlock* other_target;
3155
3156 bool LimitIsValid() { return token != Token::ILLEGAL; }
3157
3158 bool LimitIsIncluded() {
3159 return Token::IsEqualityOp(token) ||
3160 token == Token::GTE || token == Token::LTE;
3161 }
3162 bool LimitIsUpper() {
3163 return token == Token::LTE || token == Token::LT || token == Token::NE;
3164 }
3165
3166 LimitFromPredecessorBlock()
3167 : variable(NULL),
3168 token(Token::ILLEGAL),
3169 limit(NULL),
3170 other_target(NULL) {}
3171 };
3172
3173 static const int32_t kNoLimit = -1;
3174
3175 static InductionVariableData* ExaminePhi(HPhi* phi);
3176 static void ComputeLimitFromPredecessorBlock(
3177 HBasicBlock* block,
3178 LimitFromPredecessorBlock* result);
3179 static bool ComputeInductionVariableLimit(
3180 HBasicBlock* block,
3181 InductionVariableLimitUpdate* additional_limit);
3182
3183 struct BitwiseDecompositionResult {
3184 HValue* base;
3185 int32_t and_mask;
3186 int32_t or_mask;
3187 HValue* context;
3188
3189 BitwiseDecompositionResult()
3190 : base(NULL), and_mask(0), or_mask(0), context(NULL) {}
3191 };
3192 static void DecomposeBitwise(HValue* value,
3193 BitwiseDecompositionResult* result);
3194
3195 void AddCheck(HBoundsCheck* check, int32_t upper_limit = kNoLimit);
3196
3197 bool CheckIfBranchIsLoopGuard(Token::Value token,
3198 HBasicBlock* current_branch,
3199 HBasicBlock* other_branch);
3200
3201 void UpdateAdditionalLimit(InductionVariableLimitUpdate* update);
3202
3203 HPhi* phi() { return phi_; }
3204 HValue* base() { return base_; }
3205 int32_t increment() { return increment_; }
3206 HValue* limit() { return limit_; }
3207 bool limit_included() { return limit_included_; }
3208 HBasicBlock* limit_validity() { return limit_validity_; }
3209 HBasicBlock* induction_exit_block() { return induction_exit_block_; }
3210 HBasicBlock* induction_exit_target() { return induction_exit_target_; }
3211 ChecksRelatedToLength* checks() { return checks_; }
3212 HValue* additional_upper_limit() { return additional_upper_limit_; }
3213 bool additional_upper_limit_is_included() {
3214 return additional_upper_limit_is_included_;
3215 }
3216 HValue* additional_lower_limit() { return additional_lower_limit_; }
3217 bool additional_lower_limit_is_included() {
3218 return additional_lower_limit_is_included_;
3219 }
3220
3221 bool LowerLimitIsNonNegativeConstant() {
3222 if (base()->IsInteger32Constant() && base()->GetInteger32Constant() >= 0) {
3223 return true;
3224 }
3225 if (additional_lower_limit() != NULL &&
3226 additional_lower_limit()->IsInteger32Constant() &&
3227 additional_lower_limit()->GetInteger32Constant() >= 0) {
3228 // Ignoring the corner case of !additional_lower_limit_is_included()
3229 // is safe, handling it adds unneeded complexity.
3230 return true;
3231 }
3232 return false;
3233 }
3234
3235 int32_t ComputeUpperLimit(int32_t and_mask, int32_t or_mask);
3236
3237 private:
3238 template <class T> void swap(T* a, T* b) {
3239 T c(*a);
3240 *a = *b;
3241 *b = c;
3242 }
3243
3244 InductionVariableData(HPhi* phi, HValue* base, int32_t increment)
3245 : phi_(phi), base_(IgnoreOsrValue(base)), increment_(increment),
3246 limit_(NULL), limit_included_(false), limit_validity_(NULL),
3247 induction_exit_block_(NULL), induction_exit_target_(NULL),
3248 checks_(NULL),
3249 additional_upper_limit_(NULL),
3250 additional_upper_limit_is_included_(false),
3251 additional_lower_limit_(NULL),
3252 additional_lower_limit_is_included_(false) {}
3253
3254 static int32_t ComputeIncrement(HPhi* phi, HValue* phi_operand);
3255
3256 static HValue* IgnoreOsrValue(HValue* v);
3257 static InductionVariableData* GetInductionVariableData(HValue* v);
3258
3259 HPhi* phi_;
3260 HValue* base_;
3261 int32_t increment_;
3262 HValue* limit_;
3263 bool limit_included_;
3264 HBasicBlock* limit_validity_;
3265 HBasicBlock* induction_exit_block_;
3266 HBasicBlock* induction_exit_target_;
3267 ChecksRelatedToLength* checks_;
3268 HValue* additional_upper_limit_;
3269 bool additional_upper_limit_is_included_;
3270 HValue* additional_lower_limit_;
3271 bool additional_lower_limit_is_included_;
3272 };
3273
3274
3053 class HPhi: public HValue { 3275 class HPhi: public HValue {
3054 public: 3276 public:
3055 HPhi(int merged_index, Zone* zone) 3277 HPhi(int merged_index, Zone* zone)
3056 : inputs_(2, zone), 3278 : inputs_(2, zone),
3057 merged_index_(merged_index), 3279 merged_index_(merged_index),
3058 phi_id_(-1) { 3280 phi_id_(-1),
3281 induction_variable_data_(NULL) {
3059 for (int i = 0; i < Representation::kNumRepresentations; i++) { 3282 for (int i = 0; i < Representation::kNumRepresentations; i++) {
3060 non_phi_uses_[i] = 0; 3283 non_phi_uses_[i] = 0;
3061 indirect_uses_[i] = 0; 3284 indirect_uses_[i] = 0;
3062 } 3285 }
3063 ASSERT(merged_index >= 0); 3286 ASSERT(merged_index >= 0);
3064 SetFlag(kFlexibleRepresentation); 3287 SetFlag(kFlexibleRepresentation);
3065 SetFlag(kAllowUndefinedAsNaN); 3288 SetFlag(kAllowUndefinedAsNaN);
3066 } 3289 }
3067 3290
3068 virtual Representation RepresentationFromInputs(); 3291 virtual Representation RepresentationFromInputs();
(...skipping 10 matching lines...) Expand all
3079 virtual int OperandCount() { return inputs_.length(); } 3302 virtual int OperandCount() { return inputs_.length(); }
3080 virtual HValue* OperandAt(int index) const { return inputs_[index]; } 3303 virtual HValue* OperandAt(int index) const { return inputs_[index]; }
3081 HValue* GetRedundantReplacement(); 3304 HValue* GetRedundantReplacement();
3082 void AddInput(HValue* value); 3305 void AddInput(HValue* value);
3083 bool HasRealUses(); 3306 bool HasRealUses();
3084 3307
3085 bool IsReceiver() const { return merged_index_ == 0; } 3308 bool IsReceiver() const { return merged_index_ == 0; }
3086 3309
3087 int merged_index() const { return merged_index_; } 3310 int merged_index() const { return merged_index_; }
3088 3311
3312 InductionVariableData* induction_variable_data() {
3313 return induction_variable_data_;
3314 }
3315 bool IsInductionVariable() {
3316 return induction_variable_data_ != NULL;
3317 }
3318 bool IsLimitedInductionVariable() {
3319 return IsInductionVariable() &&
3320 induction_variable_data_->limit() != NULL;
3321 }
3322 void DetectInductionVariable() {
3323 ASSERT(induction_variable_data_ == NULL);
3324 induction_variable_data_ = InductionVariableData::ExaminePhi(this);
3325 }
3326
3089 virtual void AddInformativeDefinitions(); 3327 virtual void AddInformativeDefinitions();
3090 3328
3091 virtual void PrintTo(StringStream* stream); 3329 virtual void PrintTo(StringStream* stream);
3092 3330
3093 #ifdef DEBUG 3331 #ifdef DEBUG
3094 virtual void Verify(); 3332 virtual void Verify();
3095 #endif 3333 #endif
3096 3334
3097 void InitRealUses(int id); 3335 void InitRealUses(int id);
3098 void AddNonPhiUsesFrom(HPhi* other); 3336 void AddNonPhiUsesFrom(HPhi* other);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3146 int offset = 0, 3384 int offset = 0,
3147 int scale = 0); 3385 int scale = 0);
3148 3386
3149 private: 3387 private:
3150 ZoneList<HValue*> inputs_; 3388 ZoneList<HValue*> inputs_;
3151 int merged_index_; 3389 int merged_index_;
3152 3390
3153 int non_phi_uses_[Representation::kNumRepresentations]; 3391 int non_phi_uses_[Representation::kNumRepresentations];
3154 int indirect_uses_[Representation::kNumRepresentations]; 3392 int indirect_uses_[Representation::kNumRepresentations];
3155 int phi_id_; 3393 int phi_id_;
3394 InductionVariableData* induction_variable_data_;
3156 }; 3395 };
3157 3396
3158 3397
3159 class HInductionVariableAnnotation : public HUnaryOperation { 3398 class HInductionVariableAnnotation : public HUnaryOperation {
3160 public: 3399 public:
3161 static HInductionVariableAnnotation* AddToGraph(HPhi* phi, 3400 static HInductionVariableAnnotation* AddToGraph(HPhi* phi,
3162 NumericRelation relation, 3401 NumericRelation relation,
3163 int operand_index); 3402 int operand_index);
3164 3403
3165 NumericRelation relation() { return relation_; } 3404 NumericRelation relation() { return relation_; }
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
3653 3892
3654 class HBoundsCheck: public HTemplateInstruction<2> { 3893 class HBoundsCheck: public HTemplateInstruction<2> {
3655 public: 3894 public:
3656 // Normally HBoundsCheck should be created using the 3895 // Normally HBoundsCheck should be created using the
3657 // HGraphBuilder::AddBoundsCheck() helper. 3896 // HGraphBuilder::AddBoundsCheck() helper.
3658 // However when building stubs, where we know that the arguments are Int32, 3897 // However when building stubs, where we know that the arguments are Int32,
3659 // it makes sense to invoke this constructor directly. 3898 // it makes sense to invoke this constructor directly.
3660 HBoundsCheck(HValue* index, HValue* length) 3899 HBoundsCheck(HValue* index, HValue* length)
3661 : skip_check_(false), 3900 : skip_check_(false),
3662 base_(NULL), offset_(0), scale_(0), 3901 base_(NULL), offset_(0), scale_(0),
3663 responsibility_direction_(DIRECTION_NONE) { 3902 responsibility_direction_(DIRECTION_NONE),
3903 allow_equality_(false) {
3664 SetOperandAt(0, index); 3904 SetOperandAt(0, index);
3665 SetOperandAt(1, length); 3905 SetOperandAt(1, length);
3666 SetFlag(kFlexibleRepresentation); 3906 SetFlag(kFlexibleRepresentation);
3667 SetFlag(kUseGVN); 3907 SetFlag(kUseGVN);
3668 } 3908 }
3669 3909
3670 bool skip_check() { return skip_check_; } 3910 bool skip_check() const { return skip_check_; }
3671 void set_skip_check(bool skip_check) { skip_check_ = skip_check; } 3911 void set_skip_check() { skip_check_ = true; }
3672 HValue* base() { return base_; } 3912 HValue* base() { return base_; }
3673 int offset() { return offset_; } 3913 int offset() { return offset_; }
3674 int scale() { return scale_; } 3914 int scale() { return scale_; }
3675 bool index_can_increase() { 3915 bool index_can_increase() {
3676 return (responsibility_direction_ & DIRECTION_LOWER) == 0; 3916 return (responsibility_direction_ & DIRECTION_LOWER) == 0;
3677 } 3917 }
3678 bool index_can_decrease() { 3918 bool index_can_decrease() {
3679 return (responsibility_direction_ & DIRECTION_UPPER) == 0; 3919 return (responsibility_direction_ & DIRECTION_UPPER) == 0;
3680 } 3920 }
3681 3921
(...skipping 11 matching lines...) Expand all
3693 base_ = index(); 3933 base_ = index();
3694 offset_ = 0; 3934 offset_ = 0;
3695 scale_ = 0; 3935 scale_ = 0;
3696 return false; 3936 return false;
3697 } 3937 }
3698 } 3938 }
3699 3939
3700 virtual Representation RequiredInputRepresentation(int arg_index) { 3940 virtual Representation RequiredInputRepresentation(int arg_index) {
3701 return representation(); 3941 return representation();
3702 } 3942 }
3943 virtual bool IsDeletable() const {
3944 return skip_check() && !FLAG_debug_code;
3945 }
3703 3946
3704 virtual bool IsRelationTrueInternal(NumericRelation relation, 3947 virtual bool IsRelationTrueInternal(NumericRelation relation,
3705 HValue* related_value, 3948 HValue* related_value,
3706 int offset = 0, 3949 int offset = 0,
3707 int scale = 0); 3950 int scale = 0);
3708 3951
3709 virtual void PrintDataTo(StringStream* stream); 3952 virtual void PrintDataTo(StringStream* stream);
3710 virtual void InferRepresentation(HInferRepresentation* h_infer); 3953 virtual void InferRepresentation(HInferRepresentation* h_infer);
3711 3954
3712 HValue* index() { return OperandAt(0); } 3955 HValue* index() { return OperandAt(0); }
3713 HValue* length() { return OperandAt(1); } 3956 HValue* length() { return OperandAt(1); }
3957 bool allow_equality() { return allow_equality_; }
3958 void set_allow_equality(bool v) { allow_equality_ = v; }
3714 3959
3715 virtual int RedefinedOperandIndex() { return 0; } 3960 virtual int RedefinedOperandIndex() { return 0; }
3716 virtual bool IsPurelyInformativeDefinition() { return skip_check(); } 3961 virtual bool IsPurelyInformativeDefinition() { return skip_check(); }
3717 virtual void AddInformativeDefinitions(); 3962 virtual void AddInformativeDefinitions();
3718 3963
3719 DECLARE_CONCRETE_INSTRUCTION(BoundsCheck) 3964 DECLARE_CONCRETE_INSTRUCTION(BoundsCheck)
3720 3965
3721 protected: 3966 protected:
3722 friend class HBoundsCheckBaseIndexInformation; 3967 friend class HBoundsCheckBaseIndexInformation;
3723 3968
3724 virtual void SetResponsibilityForRange(RangeGuaranteeDirection direction) { 3969 virtual void SetResponsibilityForRange(RangeGuaranteeDirection direction) {
3725 responsibility_direction_ = static_cast<RangeGuaranteeDirection>( 3970 responsibility_direction_ = static_cast<RangeGuaranteeDirection>(
3726 responsibility_direction_ | direction); 3971 responsibility_direction_ | direction);
3727 } 3972 }
3728 3973
3729 virtual bool DataEquals(HValue* other) { return true; } 3974 virtual bool DataEquals(HValue* other) { return true; }
3730 virtual void TryGuaranteeRangeChanging(RangeEvaluationContext* context); 3975 virtual void TryGuaranteeRangeChanging(RangeEvaluationContext* context);
3731 bool skip_check_; 3976 bool skip_check_;
3732 HValue* base_; 3977 HValue* base_;
3733 int offset_; 3978 int offset_;
3734 int scale_; 3979 int scale_;
3735 RangeGuaranteeDirection responsibility_direction_; 3980 RangeGuaranteeDirection responsibility_direction_;
3981 bool allow_equality_;
3736 }; 3982 };
3737 3983
3738 3984
3739 class HBoundsCheckBaseIndexInformation: public HTemplateInstruction<2> { 3985 class HBoundsCheckBaseIndexInformation: public HTemplateInstruction<2> {
3740 public: 3986 public:
3741 explicit HBoundsCheckBaseIndexInformation(HBoundsCheck* check) { 3987 explicit HBoundsCheckBaseIndexInformation(HBoundsCheck* check) {
3742 DecompositionResult decomposition; 3988 DecompositionResult decomposition;
3743 if (check->index()->TryDecompose(&decomposition)) { 3989 if (check->index()->TryDecompose(&decomposition)) {
3744 SetOperandAt(0, decomposition.base()); 3990 SetOperandAt(0, decomposition.base());
3745 SetOperandAt(1, check); 3991 SetOperandAt(1, check);
(...skipping 2855 matching lines...) Expand 10 before | Expand all | Expand 10 after
6601 virtual HType CalculateInferredType() { 6847 virtual HType CalculateInferredType() {
6602 return HType::Tagged(); 6848 return HType::Tagged();
6603 } 6849 }
6604 6850
6605 DECLARE_CONCRETE_INSTRUCTION(LoadFieldByIndex); 6851 DECLARE_CONCRETE_INSTRUCTION(LoadFieldByIndex);
6606 6852
6607 private: 6853 private:
6608 virtual bool IsDeletable() const { return true; } 6854 virtual bool IsDeletable() const { return true; }
6609 }; 6855 };
6610 6856
6611
titzer 2013/07/18 12:22:58 Whitespace change
Massi 2013/07/23 07:57:50 Done.
6612 #undef DECLARE_INSTRUCTION 6857 #undef DECLARE_INSTRUCTION
6613 #undef DECLARE_CONCRETE_INSTRUCTION 6858 #undef DECLARE_CONCRETE_INSTRUCTION
6614 6859
6615 } } // namespace v8::internal 6860 } } // namespace v8::internal
6616 6861
6617 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ 6862 #endif // V8_HYDROGEN_INSTRUCTIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698