OLD | NEW |
---|---|
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 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
960 UNREACHABLE(); | 960 UNREACHABLE(); |
961 return false; | 961 return false; |
962 } | 962 } |
963 | 963 |
964 virtual Representation RepresentationFromInputs() { | 964 virtual Representation RepresentationFromInputs() { |
965 return representation(); | 965 return representation(); |
966 } | 966 } |
967 Representation RepresentationFromUses(); | 967 Representation RepresentationFromUses(); |
968 Representation RepresentationFromUseRequirements(); | 968 Representation RepresentationFromUseRequirements(); |
969 bool HasNonSmiUse(); | 969 bool HasNonSmiUse(); |
970 bool UsedBy(HValue* value); | |
970 virtual void UpdateRepresentation(Representation new_rep, | 971 virtual void UpdateRepresentation(Representation new_rep, |
971 HInferRepresentationPhase* h_infer, | 972 HInferRepresentationPhase* h_infer, |
972 const char* reason); | 973 const char* reason); |
973 void AddDependantsToWorklist(HInferRepresentationPhase* h_infer); | 974 void AddDependantsToWorklist(HInferRepresentationPhase* h_infer); |
974 | 975 |
975 virtual void RepresentationChanged(Representation to) { } | 976 virtual void RepresentationChanged(Representation to) { } |
976 | 977 |
977 virtual Range* InferRange(Zone* zone); | 978 virtual Range* InferRange(Zone* zone); |
978 virtual void DeleteFromGraph() = 0; | 979 virtual void DeleteFromGraph() = 0; |
979 virtual void InternalSetOperandAt(int index, HValue* value) = 0; | 980 virtual void InternalSetOperandAt(int index, HValue* value) = 0; |
(...skipping 2558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3538 HValue* context() const { return OperandAt(0); } | 3539 HValue* context() const { return OperandAt(0); } |
3539 HValue* left() const { return OperandAt(1); } | 3540 HValue* left() const { return OperandAt(1); } |
3540 HValue* right() const { return OperandAt(2); } | 3541 HValue* right() const { return OperandAt(2); } |
3541 | 3542 |
3542 // True if switching left and right operands likely generates better code. | 3543 // True if switching left and right operands likely generates better code. |
3543 bool AreOperandsBetterSwitched() { | 3544 bool AreOperandsBetterSwitched() { |
3544 if (!IsCommutative()) return false; | 3545 if (!IsCommutative()) return false; |
3545 | 3546 |
3546 // Constant operands are better off on the right, they can be inlined in | 3547 // Constant operands are better off on the right, they can be inlined in |
3547 // many situations on most platforms. | 3548 // many situations on most platforms. |
3548 if (left()->IsConstant()) return true; | 3549 if (left()->IsConstant() && |
3549 if (right()->IsConstant()) return false; | 3550 (!representation().IsDouble() || left()->UseCount() > 1)) { |
3551 return true; | |
3552 } | |
3553 if (right()->IsConstant() && | |
3554 (!representation().IsDouble() || right()->UseCount() > 1)) { | |
3555 return false; | |
3556 } | |
3557 | |
3558 if (left()->IsPhi() && UsedBy(left())) return false; | |
3559 if (right()->IsPhi() && UsedBy(right())) return true; | |
3550 | 3560 |
haitao.feng
2014/05/15 05:56:20
How about writing codes in this way?
- if (left
| |
3551 // Otherwise, if there is only one use of the right operand, it would be | 3561 // Otherwise, if there is only one use of the right operand, it would be |
3552 // better off on the left for platforms that only have 2-arg arithmetic | 3562 // better off on the left for platforms that only have 2-arg arithmetic |
3553 // ops (e.g ia32, x64) that clobber the left operand. | 3563 // ops (e.g ia32, x64) that clobber the left operand. |
3554 return right()->UseCount() == 1; | 3564 return right()->UseCount() == 1; |
3555 } | 3565 } |
3556 | 3566 |
3557 HValue* BetterLeftOperand() { | 3567 HValue* BetterLeftOperand() { |
3558 return AreOperandsBetterSwitched() ? right() : left(); | 3568 return AreOperandsBetterSwitched() ? right() : left(); |
3559 } | 3569 } |
3560 | 3570 |
(...skipping 3393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6954 virtual bool IsDeletable() const V8_OVERRIDE { return true; } | 6964 virtual bool IsDeletable() const V8_OVERRIDE { return true; } |
6955 }; | 6965 }; |
6956 | 6966 |
6957 | 6967 |
6958 #undef DECLARE_INSTRUCTION | 6968 #undef DECLARE_INSTRUCTION |
6959 #undef DECLARE_CONCRETE_INSTRUCTION | 6969 #undef DECLARE_CONCRETE_INSTRUCTION |
6960 | 6970 |
6961 } } // namespace v8::internal | 6971 } } // namespace v8::internal |
6962 | 6972 |
6963 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 6973 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
OLD | NEW |