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

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

Issue 12315005: Constant fold math and string operations. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 10 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 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 protected: 2362 protected:
2363 virtual bool DataEquals(HValue* other) { return true; } 2363 virtual bool DataEquals(HValue* other) { return true; }
2364 2364
2365 private: 2365 private:
2366 virtual bool IsDeletable() const { return true; } 2366 virtual bool IsDeletable() const { return true; }
2367 }; 2367 };
2368 2368
2369 2369
2370 class HUnaryMathOperation: public HTemplateInstruction<2> { 2370 class HUnaryMathOperation: public HTemplateInstruction<2> {
2371 public: 2371 public:
2372 HUnaryMathOperation(HValue* context, HValue* value, BuiltinFunctionId op) 2372 static HInstruction* New(
2373 : op_(op) { 2373 Zone* zone, HValue* context, HValue* value, BuiltinFunctionId op);
2374 SetOperandAt(0, context);
2375 SetOperandAt(1, value);
2376 switch (op) {
2377 case kMathFloor:
2378 case kMathRound:
2379 case kMathCeil:
2380 set_representation(Representation::Integer32());
2381 break;
2382 case kMathAbs:
2383 // Not setting representation here: it is None intentionally.
2384 SetFlag(kFlexibleRepresentation);
2385 SetGVNFlag(kChangesNewSpacePromotion);
2386 break;
2387 case kMathSqrt:
2388 case kMathPowHalf:
2389 case kMathLog:
2390 case kMathSin:
2391 case kMathCos:
2392 case kMathTan:
2393 set_representation(Representation::Double());
2394 SetGVNFlag(kChangesNewSpacePromotion);
2395 break;
2396 case kMathExp:
2397 set_representation(Representation::Double());
2398 break;
2399 default:
2400 UNREACHABLE();
2401 }
2402 SetFlag(kUseGVN);
2403 }
2404 2374
2405 HValue* context() { return OperandAt(0); } 2375 HValue* context() { return OperandAt(0); }
2406 HValue* value() { return OperandAt(1); } 2376 HValue* value() { return OperandAt(1); }
2407 2377
2408 virtual void PrintDataTo(StringStream* stream); 2378 virtual void PrintDataTo(StringStream* stream);
2409 2379
2410 virtual HType CalculateInferredType(); 2380 virtual HType CalculateInferredType();
2411 2381
2412 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited); 2382 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
2413 2383
2414 virtual Representation RequiredInputRepresentation(int index) { 2384 virtual Representation RequiredInputRepresentation(int index) {
2415 if (index == 0) { 2385 if (index == 0) {
2416 return Representation::Tagged(); 2386 return Representation::Tagged();
2417 } else { 2387 } else {
2418 switch (op_) { 2388 switch (op_) {
2419 case kMathFloor: 2389 case kMathFloor:
2420 case kMathRound: 2390 case kMathRound:
2421 case kMathCeil:
2422 case kMathSqrt: 2391 case kMathSqrt:
2423 case kMathPowHalf: 2392 case kMathPowHalf:
2424 case kMathLog: 2393 case kMathLog:
2425 case kMathExp: 2394 case kMathExp:
2426 case kMathSin: 2395 case kMathSin:
2427 case kMathCos: 2396 case kMathCos:
2428 case kMathTan: 2397 case kMathTan:
2429 return Representation::Double(); 2398 return Representation::Double();
2430 case kMathAbs: 2399 case kMathAbs:
2431 return representation(); 2400 return representation();
(...skipping 11 matching lines...) Expand all
2443 2412
2444 DECLARE_CONCRETE_INSTRUCTION(UnaryMathOperation) 2413 DECLARE_CONCRETE_INSTRUCTION(UnaryMathOperation)
2445 2414
2446 protected: 2415 protected:
2447 virtual bool DataEquals(HValue* other) { 2416 virtual bool DataEquals(HValue* other) {
2448 HUnaryMathOperation* b = HUnaryMathOperation::cast(other); 2417 HUnaryMathOperation* b = HUnaryMathOperation::cast(other);
2449 return op_ == b->op(); 2418 return op_ == b->op();
2450 } 2419 }
2451 2420
2452 private: 2421 private:
2422 HUnaryMathOperation(HValue* context, HValue* value, BuiltinFunctionId op)
2423 : op_(op) {
2424 SetOperandAt(0, context);
2425 SetOperandAt(1, value);
2426 switch (op) {
2427 case kMathFloor:
2428 case kMathRound:
2429 case kMathCeil:
2430 set_representation(Representation::Integer32());
2431 break;
2432 case kMathAbs:
2433 // Not setting representation here: it is None intentionally.
2434 SetFlag(kFlexibleRepresentation);
2435 SetGVNFlag(kChangesNewSpacePromotion);
2436 break;
2437 case kMathSqrt:
2438 case kMathPowHalf:
2439 case kMathLog:
2440 case kMathSin:
2441 case kMathCos:
2442 case kMathTan:
2443 set_representation(Representation::Double());
2444 SetGVNFlag(kChangesNewSpacePromotion);
2445 break;
2446 case kMathExp:
2447 set_representation(Representation::Double());
2448 break;
2449 default:
2450 UNREACHABLE();
2451 }
2452 SetFlag(kUseGVN);
2453 }
2454
2453 virtual bool IsDeletable() const { return true; } 2455 virtual bool IsDeletable() const { return true; }
2454 2456
2455 BuiltinFunctionId op_; 2457 BuiltinFunctionId op_;
2456 }; 2458 };
2457 2459
2458 2460
2459 class HLoadElements: public HTemplateInstruction<2> { 2461 class HLoadElements: public HTemplateInstruction<2> {
2460 public: 2462 public:
2461 HLoadElements(HValue* value, HValue* typecheck) { 2463 HLoadElements(HValue* value, HValue* typecheck) {
2462 SetOperandAt(0, value); 2464 SetOperandAt(0, value);
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
3057 return double_value_; 3059 return double_value_;
3058 } 3060 }
3059 bool HasNumberValue() const { return has_double_value_; } 3061 bool HasNumberValue() const { return has_double_value_; }
3060 int32_t NumberValueAsInteger32() const { 3062 int32_t NumberValueAsInteger32() const {
3061 ASSERT(HasNumberValue()); 3063 ASSERT(HasNumberValue());
3062 // Irrespective of whether a numeric HConstant can be safely 3064 // Irrespective of whether a numeric HConstant can be safely
3063 // represented as an int32, we store the (in some cases lossy) 3065 // represented as an int32, we store the (in some cases lossy)
3064 // representation of the number in int32_value_. 3066 // representation of the number in int32_value_.
3065 return int32_value_; 3067 return int32_value_;
3066 } 3068 }
3069 bool HasStringValue() const {
3070 if (has_double_value_ || has_int32_value_) return false;
3071 ASSERT(!handle_.is_null());
3072 return handle_->IsString();
3073 }
3074 Handle<String> StringValue() const {
3075 ASSERT(HasStringValue());
3076 return Handle<String>::cast(handle_);
3077 }
3067 3078
3068 bool ToBoolean(); 3079 bool ToBoolean();
3069 3080
3070 bool IsUint32() { 3081 bool IsUint32() {
3071 return HasInteger32Value() && (Integer32Value() >= 0); 3082 return HasInteger32Value() && (Integer32Value() >= 0);
3072 } 3083 }
3073 3084
3074 virtual intptr_t Hashcode() { 3085 virtual intptr_t Hashcode() {
3075 ASSERT_ALLOCATION_DISABLED; 3086 ASSERT_ALLOCATION_DISABLED;
3076 intptr_t hash; 3087 intptr_t hash;
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 3888
3878 DECLARE_CONCRETE_INSTRUCTION(InstanceOfKnownGlobal) 3889 DECLARE_CONCRETE_INSTRUCTION(InstanceOfKnownGlobal)
3879 3890
3880 private: 3891 private:
3881 Handle<JSFunction> function_; 3892 Handle<JSFunction> function_;
3882 }; 3893 };
3883 3894
3884 3895
3885 class HPower: public HTemplateInstruction<2> { 3896 class HPower: public HTemplateInstruction<2> {
3886 public: 3897 public:
3887 HPower(HValue* left, HValue* right) { 3898 HPower(HValue* left, HValue* right) {
Jakob Kummerow 2013/02/21 10:14:56 private ctor please
3888 SetOperandAt(0, left); 3899 SetOperandAt(0, left);
3889 SetOperandAt(1, right); 3900 SetOperandAt(1, right);
3890 set_representation(Representation::Double()); 3901 set_representation(Representation::Double());
3891 SetFlag(kUseGVN); 3902 SetFlag(kUseGVN);
3892 SetGVNFlag(kChangesNewSpacePromotion); 3903 SetGVNFlag(kChangesNewSpacePromotion);
3893 } 3904 }
3894 3905
3906 static HInstruction* New(Zone* zone, HValue* left, HValue* right);
3907
3895 HValue* left() { return OperandAt(0); } 3908 HValue* left() { return OperandAt(0); }
3896 HValue* right() const { return OperandAt(1); } 3909 HValue* right() const { return OperandAt(1); }
3897 3910
3898 virtual Representation RequiredInputRepresentation(int index) { 3911 virtual Representation RequiredInputRepresentation(int index) {
3899 return index == 0 3912 return index == 0
3900 ? Representation::Double() 3913 ? Representation::Double()
3901 : Representation::None(); 3914 : Representation::None();
3902 } 3915 }
3903 virtual Representation observed_input_representation(int index) { 3916 virtual Representation observed_input_representation(int index) {
3904 return RequiredInputRepresentation(index); 3917 return RequiredInputRepresentation(index);
(...skipping 26 matching lines...) Expand all
3931 3944
3932 DECLARE_CONCRETE_INSTRUCTION(Random) 3945 DECLARE_CONCRETE_INSTRUCTION(Random)
3933 3946
3934 private: 3947 private:
3935 virtual bool IsDeletable() const { return true; } 3948 virtual bool IsDeletable() const { return true; }
3936 }; 3949 };
3937 3950
3938 3951
3939 class HAdd: public HArithmeticBinaryOperation { 3952 class HAdd: public HArithmeticBinaryOperation {
3940 public: 3953 public:
3941 HAdd(HValue* context, HValue* left, HValue* right) 3954 HAdd(HValue* context, HValue* left, HValue* right)
Jakob Kummerow 2013/02/21 10:14:56 private ctor please
3942 : HArithmeticBinaryOperation(context, left, right) { 3955 : HArithmeticBinaryOperation(context, left, right) {
3943 SetFlag(kCanOverflow); 3956 SetFlag(kCanOverflow);
3944 } 3957 }
3945 3958
3959 static HInstruction* New(
3960 Zone* zone, HValue* context, HValue* left, HValue* right);
3961
3946 // Add is only commutative if two integer values are added and not if two 3962 // Add is only commutative if two integer values are added and not if two
3947 // tagged values are added (because it might be a String concatenation). 3963 // tagged values are added (because it might be a String concatenation).
3948 virtual bool IsCommutative() const { 3964 virtual bool IsCommutative() const {
3949 return !representation().IsTagged(); 3965 return !representation().IsTagged();
3950 } 3966 }
3951 3967
3952 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited); 3968 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
3953 3969
3954 static HInstruction* NewHAdd(Zone* zone,
3955 HValue* context,
3956 HValue* left,
3957 HValue* right);
3958
3959 virtual HType CalculateInferredType(); 3970 virtual HType CalculateInferredType();
3960 3971
3961 virtual HValue* Canonicalize(); 3972 virtual HValue* Canonicalize();
3962 3973
3963 virtual bool IsRelationTrueInternal(NumericRelation relation, HValue* other) { 3974 virtual bool IsRelationTrueInternal(NumericRelation relation, HValue* other) {
3964 HValue* base = NULL; 3975 HValue* base = NULL;
3965 int32_t offset = 0; 3976 int32_t offset = 0;
3966 if (left()->IsInteger32Constant()) { 3977 if (left()->IsInteger32Constant()) {
3967 base = right(); 3978 base = right();
3968 offset = left()->GetInteger32Constant(); 3979 offset = left()->GetInteger32Constant();
(...skipping 12 matching lines...) Expand all
3981 3992
3982 protected: 3993 protected:
3983 virtual bool DataEquals(HValue* other) { return true; } 3994 virtual bool DataEquals(HValue* other) { return true; }
3984 3995
3985 virtual Range* InferRange(Zone* zone); 3996 virtual Range* InferRange(Zone* zone);
3986 }; 3997 };
3987 3998
3988 3999
3989 class HSub: public HArithmeticBinaryOperation { 4000 class HSub: public HArithmeticBinaryOperation {
3990 public: 4001 public:
3991 HSub(HValue* context, HValue* left, HValue* right) 4002 HSub(HValue* context, HValue* left, HValue* right)
Jakob Kummerow 2013/02/21 10:14:56 private ctor please
3992 : HArithmeticBinaryOperation(context, left, right) { 4003 : HArithmeticBinaryOperation(context, left, right) {
3993 SetFlag(kCanOverflow); 4004 SetFlag(kCanOverflow);
3994 } 4005 }
3995 4006
4007 static HInstruction* New(
4008 Zone* zone, HValue* context, HValue* left, HValue* right);
4009
3996 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited); 4010 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
3997 4011
3998 virtual HValue* Canonicalize(); 4012 virtual HValue* Canonicalize();
3999 4013
4000 static HInstruction* NewHSub(Zone* zone,
4001 HValue* context,
4002 HValue* left,
4003 HValue* right);
4004
4005 virtual bool IsRelationTrueInternal(NumericRelation relation, HValue* other) { 4014 virtual bool IsRelationTrueInternal(NumericRelation relation, HValue* other) {
4006 if (right()->IsInteger32Constant()) { 4015 if (right()->IsInteger32Constant()) {
4007 HValue* base = left(); 4016 HValue* base = left();
4008 int32_t offset = right()->GetInteger32Constant(); 4017 int32_t offset = right()->GetInteger32Constant();
4009 return relation.IsExtendable(-offset) 4018 return relation.IsExtendable(-offset)
4010 ? base->IsRelationTrue(relation, other) : false; 4019 ? base->IsRelationTrue(relation, other) : false;
4011 } else { 4020 } else {
4012 return false; 4021 return false;
4013 } 4022 }
4014 } 4023 }
4015 4024
4016 DECLARE_CONCRETE_INSTRUCTION(Sub) 4025 DECLARE_CONCRETE_INSTRUCTION(Sub)
4017 4026
4018 protected: 4027 protected:
4019 virtual bool DataEquals(HValue* other) { return true; } 4028 virtual bool DataEquals(HValue* other) { return true; }
4020 4029
4021 virtual Range* InferRange(Zone* zone); 4030 virtual Range* InferRange(Zone* zone);
4022 }; 4031 };
4023 4032
4024 4033
4025 class HMul: public HArithmeticBinaryOperation { 4034 class HMul: public HArithmeticBinaryOperation {
4026 public: 4035 public:
4027 HMul(HValue* context, HValue* left, HValue* right) 4036 static HInstruction* New(
4028 : HArithmeticBinaryOperation(context, left, right) { 4037 Zone* zone, HValue* context, HValue* left, HValue* right);
4029 SetFlag(kCanOverflow);
4030 }
4031 4038
4032 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited); 4039 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
4033 4040
4034 // Only commutative if it is certain that not two objects are multiplicated. 4041 // Only commutative if it is certain that not two objects are multiplicated.
4035 virtual bool IsCommutative() const { 4042 virtual bool IsCommutative() const {
4036 return !representation().IsTagged(); 4043 return !representation().IsTagged();
4037 } 4044 }
4038 4045
4039 static HInstruction* NewHMul(Zone* zone,
4040 HValue* context,
4041 HValue* left,
4042 HValue* right);
4043
4044 DECLARE_CONCRETE_INSTRUCTION(Mul) 4046 DECLARE_CONCRETE_INSTRUCTION(Mul)
4045 4047
4046 protected: 4048 protected:
4047 virtual bool DataEquals(HValue* other) { return true; } 4049 virtual bool DataEquals(HValue* other) { return true; }
4048 4050
4049 virtual Range* InferRange(Zone* zone); 4051 virtual Range* InferRange(Zone* zone);
4052
4053 private:
4054 HMul(HValue* context, HValue* left, HValue* right)
4055 : HArithmeticBinaryOperation(context, left, right) {
4056 SetFlag(kCanOverflow);
4057 }
4050 }; 4058 };
4051 4059
4052 4060
4053 class HMod: public HArithmeticBinaryOperation { 4061 class HMod: public HArithmeticBinaryOperation {
4054 public: 4062 public:
4055 HMod(HValue* context, HValue* left, HValue* right) 4063 static HInstruction* New(
4056 : HArithmeticBinaryOperation(context, left, right) { 4064 Zone* zone, HValue* context, HValue* left, HValue* right);
4057 SetFlag(kCanBeDivByZero);
4058 }
4059 4065
4060 bool HasPowerOf2Divisor() { 4066 bool HasPowerOf2Divisor() {
4061 if (right()->IsConstant() && 4067 if (right()->IsConstant() &&
4062 HConstant::cast(right())->HasInteger32Value()) { 4068 HConstant::cast(right())->HasInteger32Value()) {
4063 int32_t value = HConstant::cast(right())->Integer32Value(); 4069 int32_t value = HConstant::cast(right())->Integer32Value();
4064 return value != 0 && (IsPowerOf2(value) || IsPowerOf2(-value)); 4070 return value != 0 && (IsPowerOf2(value) || IsPowerOf2(-value));
4065 } 4071 }
4066 4072
4067 return false; 4073 return false;
4068 } 4074 }
4069 4075
4070 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited); 4076 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
4071 4077
4072 static HInstruction* NewHMod(Zone* zone,
4073 HValue* context,
4074 HValue* left,
4075 HValue* right);
4076
4077 DECLARE_CONCRETE_INSTRUCTION(Mod) 4078 DECLARE_CONCRETE_INSTRUCTION(Mod)
4078 4079
4079 protected: 4080 protected:
4080 virtual bool DataEquals(HValue* other) { return true; } 4081 virtual bool DataEquals(HValue* other) { return true; }
4081 4082
4082 virtual Range* InferRange(Zone* zone); 4083 virtual Range* InferRange(Zone* zone);
4084
4085 private:
4086 HMod(HValue* context, HValue* left, HValue* right)
4087 : HArithmeticBinaryOperation(context, left, right) {
4088 SetFlag(kCanBeDivByZero);
4089 }
4083 }; 4090 };
4084 4091
4085 4092
4086 class HDiv: public HArithmeticBinaryOperation { 4093 class HDiv: public HArithmeticBinaryOperation {
4087 public: 4094 public:
4088 HDiv(HValue* context, HValue* left, HValue* right) 4095 static HInstruction* New(
4089 : HArithmeticBinaryOperation(context, left, right) { 4096 Zone* zone, HValue* context, HValue* left, HValue* right);
4090 SetFlag(kCanBeDivByZero);
4091 SetFlag(kCanOverflow);
4092 }
4093 4097
4094 bool HasPowerOf2Divisor() { 4098 bool HasPowerOf2Divisor() {
4095 if (right()->IsConstant() && 4099 if (right()->IsConstant() &&
4096 HConstant::cast(right())->HasInteger32Value()) { 4100 HConstant::cast(right())->HasInteger32Value()) {
4097 int32_t value = HConstant::cast(right())->Integer32Value(); 4101 int32_t value = HConstant::cast(right())->Integer32Value();
4098 return value != 0 && (IsPowerOf2(value) || IsPowerOf2(-value)); 4102 return value != 0 && (IsPowerOf2(value) || IsPowerOf2(-value));
4099 } 4103 }
4100 4104
4101 return false; 4105 return false;
4102 } 4106 }
4103 4107
4104 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited); 4108 virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);
4105 4109
4106 static HInstruction* NewHDiv(Zone* zone,
4107 HValue* context,
4108 HValue* left,
4109 HValue* right);
4110
4111 DECLARE_CONCRETE_INSTRUCTION(Div) 4110 DECLARE_CONCRETE_INSTRUCTION(Div)
4112 4111
4113 protected: 4112 protected:
4114 virtual bool DataEquals(HValue* other) { return true; } 4113 virtual bool DataEquals(HValue* other) { return true; }
4115 4114
4116 virtual Range* InferRange(Zone* zone); 4115 virtual Range* InferRange(Zone* zone);
4116
4117 private:
4118 HDiv(HValue* context, HValue* left, HValue* right)
4119 : HArithmeticBinaryOperation(context, left, right) {
4120 SetFlag(kCanBeDivByZero);
4121 SetFlag(kCanOverflow);
4122 }
4117 }; 4123 };
4118 4124
4119 4125
4120 class HMathMinMax: public HArithmeticBinaryOperation { 4126 class HMathMinMax: public HArithmeticBinaryOperation {
4121 public: 4127 public:
4122 enum Operation { kMathMin, kMathMax }; 4128 enum Operation { kMathMin, kMathMax };
4123 4129
4124 HMathMinMax(HValue* context, HValue* left, HValue* right, Operation op) 4130 static HInstruction* New(
4125 : HArithmeticBinaryOperation(context, left, right), 4131 Zone* zone, HValue* context, HValue* left, HValue* right, Operation op);
4126 operation_(op) { }
4127 4132
4128 virtual Representation RequiredInputRepresentation(int index) { 4133 virtual Representation RequiredInputRepresentation(int index) {
4129 return index == 0 ? Representation::Tagged() 4134 return index == 0 ? Representation::Tagged()
4130 : representation(); 4135 : representation();
4131 } 4136 }
4132 4137
4133 virtual Representation observed_input_representation(int index) { 4138 virtual Representation observed_input_representation(int index) {
4134 return RequiredInputRepresentation(index); 4139 return RequiredInputRepresentation(index);
4135 } 4140 }
4136 4141
(...skipping 17 matching lines...) Expand all
4154 4159
4155 protected: 4160 protected:
4156 virtual bool DataEquals(HValue* other) { 4161 virtual bool DataEquals(HValue* other) {
4157 return other->IsMathMinMax() && 4162 return other->IsMathMinMax() &&
4158 HMathMinMax::cast(other)->operation_ == operation_; 4163 HMathMinMax::cast(other)->operation_ == operation_;
4159 } 4164 }
4160 4165
4161 virtual Range* InferRange(Zone* zone); 4166 virtual Range* InferRange(Zone* zone);
4162 4167
4163 private: 4168 private:
4169 HMathMinMax(HValue* context, HValue* left, HValue* right, Operation op)
4170 : HArithmeticBinaryOperation(context, left, right),
4171 operation_(op) { }
4172
4164 Operation operation_; 4173 Operation operation_;
4165 }; 4174 };
4166 4175
4167 4176
4168 class HBitwise: public HBitwiseBinaryOperation { 4177 class HBitwise: public HBitwiseBinaryOperation {
4169 public: 4178 public:
4170 HBitwise(Token::Value op, HValue* context, HValue* left, HValue* right) 4179 static HInstruction* New(Zone* zone,
4171 : HBitwiseBinaryOperation(context, left, right), op_(op) { 4180 Token::Value op,
4172 ASSERT(op == Token::BIT_AND || 4181 HValue* context,
4173 op == Token::BIT_OR || 4182 HValue* left,
4174 op == Token::BIT_XOR); 4183 HValue* right);
4175 }
4176 4184
4177 Token::Value op() const { return op_; } 4185 Token::Value op() const { return op_; }
4178 4186
4179 virtual bool IsCommutative() const { return true; } 4187 virtual bool IsCommutative() const { return true; }
4180 4188
4181 virtual HValue* Canonicalize(); 4189 virtual HValue* Canonicalize();
4182 4190
4183 static HInstruction* NewHBitwise(Zone* zone,
4184 Token::Value op,
4185 HValue* context,
4186 HValue* left,
4187 HValue* right);
4188
4189 virtual void PrintDataTo(StringStream* stream); 4191 virtual void PrintDataTo(StringStream* stream);
4190 4192
4191 DECLARE_CONCRETE_INSTRUCTION(Bitwise) 4193 DECLARE_CONCRETE_INSTRUCTION(Bitwise)
4192 4194
4193 protected: 4195 protected:
4194 virtual bool DataEquals(HValue* other) { 4196 virtual bool DataEquals(HValue* other) {
4195 return op() == HBitwise::cast(other)->op(); 4197 return op() == HBitwise::cast(other)->op();
4196 } 4198 }
4197 4199
4198 virtual Range* InferRange(Zone* zone); 4200 virtual Range* InferRange(Zone* zone);
4199 4201
4200 private: 4202 private:
4203 HBitwise(Token::Value op, HValue* context, HValue* left, HValue* right)
4204 : HBitwiseBinaryOperation(context, left, right), op_(op) {
4205 ASSERT(op == Token::BIT_AND || op == Token::BIT_OR || op == Token::BIT_XOR);
4206 }
4207
4201 Token::Value op_; 4208 Token::Value op_;
4202 }; 4209 };
4203 4210
4204 4211
4205 class HShl: public HBitwiseBinaryOperation { 4212 class HShl: public HBitwiseBinaryOperation {
4206 public: 4213 public:
4207 HShl(HValue* context, HValue* left, HValue* right) 4214 static HInstruction* New(
4208 : HBitwiseBinaryOperation(context, left, right) { } 4215 Zone* zone, HValue* context, HValue* left, HValue* right);
4209 4216
4210 virtual Range* InferRange(Zone* zone); 4217 virtual Range* InferRange(Zone* zone);
4211 4218
4212 static HInstruction* NewHShl(Zone* zone,
4213 HValue* context,
4214 HValue* left,
4215 HValue* right);
4216
4217 DECLARE_CONCRETE_INSTRUCTION(Shl) 4219 DECLARE_CONCRETE_INSTRUCTION(Shl)
4218 4220
4219 protected: 4221 protected:
4220 virtual bool DataEquals(HValue* other) { return true; } 4222 virtual bool DataEquals(HValue* other) { return true; }
4223
4224 private:
4225 HShl(HValue* context, HValue* left, HValue* right)
4226 : HBitwiseBinaryOperation(context, left, right) { }
4221 }; 4227 };
4222 4228
4223 4229
4224 class HShr: public HBitwiseBinaryOperation { 4230 class HShr: public HBitwiseBinaryOperation {
4225 public: 4231 public:
4226 HShr(HValue* context, HValue* left, HValue* right) 4232 static HInstruction* New(
4227 : HBitwiseBinaryOperation(context, left, right) { } 4233 Zone* zone, HValue* context, HValue* left, HValue* right);
4228 4234
4229 virtual Range* InferRange(Zone* zone); 4235 virtual Range* InferRange(Zone* zone);
4230 4236
4231 static HInstruction* NewHShr(Zone* zone,
4232 HValue* context,
4233 HValue* left,
4234 HValue* right);
4235
4236 DECLARE_CONCRETE_INSTRUCTION(Shr) 4237 DECLARE_CONCRETE_INSTRUCTION(Shr)
4237 4238
4238 protected: 4239 protected:
4239 virtual bool DataEquals(HValue* other) { return true; } 4240 virtual bool DataEquals(HValue* other) { return true; }
4241
4242 private:
4243 HShr(HValue* context, HValue* left, HValue* right)
4244 : HBitwiseBinaryOperation(context, left, right) { }
4240 }; 4245 };
4241 4246
4242 4247
4243 class HSar: public HBitwiseBinaryOperation { 4248 class HSar: public HBitwiseBinaryOperation {
4244 public: 4249 public:
4245 HSar(HValue* context, HValue* left, HValue* right) 4250 static HInstruction* New(
4246 : HBitwiseBinaryOperation(context, left, right) { } 4251 Zone* zone, HValue* context, HValue* left, HValue* right);
4247 4252
4248 virtual Range* InferRange(Zone* zone); 4253 virtual Range* InferRange(Zone* zone);
4249 4254
4250 static HInstruction* NewHSar(Zone* zone,
4251 HValue* context,
4252 HValue* left,
4253 HValue* right);
4254
4255 DECLARE_CONCRETE_INSTRUCTION(Sar) 4255 DECLARE_CONCRETE_INSTRUCTION(Sar)
4256 4256
4257 protected: 4257 protected:
4258 virtual bool DataEquals(HValue* other) { return true; } 4258 virtual bool DataEquals(HValue* other) { return true; }
4259
4260 private:
4261 HSar(HValue* context, HValue* left, HValue* right)
4262 : HBitwiseBinaryOperation(context, left, right) { }
4259 }; 4263 };
4260 4264
4261 4265
4262 class HRor: public HBitwiseBinaryOperation { 4266 class HRor: public HBitwiseBinaryOperation {
4263 public: 4267 public:
4264 HRor(HValue* context, HValue* left, HValue* right) 4268 HRor(HValue* context, HValue* left, HValue* right)
4265 : HBitwiseBinaryOperation(context, left, right) { 4269 : HBitwiseBinaryOperation(context, left, right) {
4266 ChangeRepresentation(Representation::Integer32()); 4270 ChangeRepresentation(Representation::Integer32());
4267 } 4271 }
4268 4272
4269 static HInstruction* NewHRor(Zone* zone,
4270 HValue* context,
4271 HValue* left,
4272 HValue* right);
4273
4274 DECLARE_CONCRETE_INSTRUCTION(Ror) 4273 DECLARE_CONCRETE_INSTRUCTION(Ror)
4275 4274
4276 protected: 4275 protected:
4277 virtual bool DataEquals(HValue* other) { return true; } 4276 virtual bool DataEquals(HValue* other) { return true; }
4278 }; 4277 };
4279 4278
4280 4279
4281 class HOsrEntry: public HTemplateInstruction<0> { 4280 class HOsrEntry: public HTemplateInstruction<0> {
4282 public: 4281 public:
4283 explicit HOsrEntry(BailoutId ast_id) : ast_id_(ast_id) { 4282 explicit HOsrEntry(BailoutId ast_id) : ast_id_(ast_id) {
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
5387 private: 5386 private:
5388 Handle<Map> original_map_; 5387 Handle<Map> original_map_;
5389 Handle<Map> transitioned_map_; 5388 Handle<Map> transitioned_map_;
5390 ElementsKind from_kind_; 5389 ElementsKind from_kind_;
5391 ElementsKind to_kind_; 5390 ElementsKind to_kind_;
5392 }; 5391 };
5393 5392
5394 5393
5395 class HStringAdd: public HBinaryOperation { 5394 class HStringAdd: public HBinaryOperation {
5396 public: 5395 public:
5397 HStringAdd(HValue* context, HValue* left, HValue* right) 5396 static HInstruction* New(
5398 : HBinaryOperation(context, left, right) { 5397 Zone* zone, HValue* context, HValue* left, HValue* right);
5399 set_representation(Representation::Tagged());
5400 SetFlag(kUseGVN);
5401 SetGVNFlag(kDependsOnMaps);
5402 SetGVNFlag(kChangesNewSpacePromotion);
5403 }
5404 5398
5405 virtual Representation RequiredInputRepresentation(int index) { 5399 virtual Representation RequiredInputRepresentation(int index) {
5406 return Representation::Tagged(); 5400 return Representation::Tagged();
5407 } 5401 }
5408 5402
5409 virtual HType CalculateInferredType() { 5403 virtual HType CalculateInferredType() {
5410 return HType::String(); 5404 return HType::String();
5411 } 5405 }
5412 5406
5413 DECLARE_CONCRETE_INSTRUCTION(StringAdd) 5407 DECLARE_CONCRETE_INSTRUCTION(StringAdd)
5414 5408
5415 protected: 5409 protected:
5416 virtual bool DataEquals(HValue* other) { return true; } 5410 virtual bool DataEquals(HValue* other) { return true; }
5417 5411
5412
5413 private:
5414 HStringAdd(HValue* context, HValue* left, HValue* right)
5415 : HBinaryOperation(context, left, right) {
5416 set_representation(Representation::Tagged());
5417 SetFlag(kUseGVN);
5418 SetGVNFlag(kDependsOnMaps);
5419 SetGVNFlag(kChangesNewSpacePromotion);
5420 }
5421
5418 // TODO(svenpanne) Might be safe, but leave it out until we know for sure. 5422 // TODO(svenpanne) Might be safe, but leave it out until we know for sure.
5419 // private:
5420 // virtual bool IsDeletable() const { return true; } 5423 // virtual bool IsDeletable() const { return true; }
5421 }; 5424 };
5422 5425
5423 5426
5424 class HStringCharCodeAt: public HTemplateInstruction<3> { 5427 class HStringCharCodeAt: public HTemplateInstruction<3> {
5425 public: 5428 public:
5426 HStringCharCodeAt(HValue* context, HValue* string, HValue* index) { 5429 HStringCharCodeAt(HValue* context, HValue* string, HValue* index) {
5427 SetOperandAt(0, context); 5430 SetOperandAt(0, context);
5428 SetOperandAt(1, string); 5431 SetOperandAt(1, string);
5429 SetOperandAt(2, index); 5432 SetOperandAt(2, index);
(...skipping 24 matching lines...) Expand all
5454 } 5457 }
5455 5458
5456 // TODO(svenpanne) Might be safe, but leave it out until we know for sure. 5459 // TODO(svenpanne) Might be safe, but leave it out until we know for sure.
5457 // private: 5460 // private:
5458 // virtual bool IsDeletable() const { return true; } 5461 // virtual bool IsDeletable() const { return true; }
5459 }; 5462 };
5460 5463
5461 5464
5462 class HStringCharFromCode: public HTemplateInstruction<2> { 5465 class HStringCharFromCode: public HTemplateInstruction<2> {
5463 public: 5466 public:
5464 HStringCharFromCode(HValue* context, HValue* char_code) { 5467 HStringCharFromCode(HValue* context, HValue* char_code) {
Jakob Kummerow 2013/02/21 10:14:56 private ctor please
5465 SetOperandAt(0, context); 5468 SetOperandAt(0, context);
5466 SetOperandAt(1, char_code); 5469 SetOperandAt(1, char_code);
5467 set_representation(Representation::Tagged()); 5470 set_representation(Representation::Tagged());
5468 SetFlag(kUseGVN); 5471 SetFlag(kUseGVN);
5469 SetGVNFlag(kChangesNewSpacePromotion); 5472 SetGVNFlag(kChangesNewSpacePromotion);
5470 } 5473 }
5471 5474
5475 static HInstruction* New(
5476 Zone* zone, HValue* context, HValue* char_code);
5477
5472 virtual Representation RequiredInputRepresentation(int index) { 5478 virtual Representation RequiredInputRepresentation(int index) {
5473 return index == 0 5479 return index == 0
5474 ? Representation::Tagged() 5480 ? Representation::Tagged()
5475 : Representation::Integer32(); 5481 : Representation::Integer32();
5476 } 5482 }
5477 virtual HType CalculateInferredType(); 5483 virtual HType CalculateInferredType();
5478 5484
5479 HValue* context() { return OperandAt(0); } 5485 HValue* context() { return OperandAt(0); }
5480 HValue* value() { return OperandAt(1); } 5486 HValue* value() { return OperandAt(1); }
5481 5487
5482 virtual bool DataEquals(HValue* other) { return true; } 5488 virtual bool DataEquals(HValue* other) { return true; }
5483 5489
5484 DECLARE_CONCRETE_INSTRUCTION(StringCharFromCode) 5490 DECLARE_CONCRETE_INSTRUCTION(StringCharFromCode)
5485 5491
5486 // TODO(svenpanne) Might be safe, but leave it out until we know for sure. 5492 // TODO(svenpanne) Might be safe, but leave it out until we know for sure.
5487 // private: 5493 // private:
5488 // virtual bool IsDeletable() const { return true; } 5494 // virtual bool IsDeletable() const { return true; }
5489 }; 5495 };
5490 5496
5491 5497
5492 class HStringLength: public HUnaryOperation { 5498 class HStringLength: public HUnaryOperation {
5493 public: 5499 public:
5494 explicit HStringLength(HValue* string) : HUnaryOperation(string) { 5500 explicit HStringLength(HValue* string) : HUnaryOperation(string) {
Jakob Kummerow 2013/02/21 10:14:56 private ctor please
5495 set_representation(Representation::Tagged()); 5501 set_representation(Representation::Tagged());
5496 SetFlag(kUseGVN); 5502 SetFlag(kUseGVN);
5497 SetGVNFlag(kDependsOnMaps); 5503 SetGVNFlag(kDependsOnMaps);
5498 } 5504 }
5499 5505
5506 static HInstruction* New(Zone* zone, HValue* string);
5507
5500 virtual Representation RequiredInputRepresentation(int index) { 5508 virtual Representation RequiredInputRepresentation(int index) {
5501 return Representation::Tagged(); 5509 return Representation::Tagged();
5502 } 5510 }
5503 5511
5504 virtual HType CalculateInferredType() { 5512 virtual HType CalculateInferredType() {
5505 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue); 5513 STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
5506 return HType::Smi(); 5514 return HType::Smi();
5507 } 5515 }
5508 5516
5509 DECLARE_CONCRETE_INSTRUCTION(StringLength) 5517 DECLARE_CONCRETE_INSTRUCTION(StringLength)
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
6032 virtual bool IsDeletable() const { return true; } 6040 virtual bool IsDeletable() const { return true; }
6033 }; 6041 };
6034 6042
6035 6043
6036 #undef DECLARE_INSTRUCTION 6044 #undef DECLARE_INSTRUCTION
6037 #undef DECLARE_CONCRETE_INSTRUCTION 6045 #undef DECLARE_CONCRETE_INSTRUCTION
6038 6046
6039 } } // namespace v8::internal 6047 } } // namespace v8::internal
6040 6048
6041 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ 6049 #endif // V8_HYDROGEN_INSTRUCTIONS_H_
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/hydrogen-instructions.cc » ('j') | src/hydrogen-instructions.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698