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

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

Issue 14676011: Improve dead code elimination by transitively marking live code and removing all dead code. Replace… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rename CanBeEliminated -> CannotBeEliminated, implement IsDeletable() for HPhi. Created 7 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 | « src/hydrogen.cc ('k') | src/hydrogen-instructions.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 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 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 // Track instructions that are dominating side effects. If an instruction 787 // Track instructions that are dominating side effects. If an instruction
788 // sets this flag, it must implement SetSideEffectDominator() and should 788 // sets this flag, it must implement SetSideEffectDominator() and should
789 // indicate which side effects to track by setting GVN flags. 789 // indicate which side effects to track by setting GVN flags.
790 kTrackSideEffectDominators, 790 kTrackSideEffectDominators,
791 kCanOverflow, 791 kCanOverflow,
792 kBailoutOnMinusZero, 792 kBailoutOnMinusZero,
793 kCanBeDivByZero, 793 kCanBeDivByZero,
794 kDeoptimizeOnUndefined, 794 kDeoptimizeOnUndefined,
795 kIsArguments, 795 kIsArguments,
796 kTruncatingToInt32, 796 kTruncatingToInt32,
797 // Set after an instruction is killed.
797 kIsDead, 798 kIsDead,
798 // Instructions that are allowed to produce full range unsigned integer 799 // Instructions that are allowed to produce full range unsigned integer
799 // values are marked with kUint32 flag. If arithmetic shift or a load from 800 // values are marked with kUint32 flag. If arithmetic shift or a load from
800 // EXTERNAL_UNSIGNED_INT_ELEMENTS array is not marked with this flag 801 // EXTERNAL_UNSIGNED_INT_ELEMENTS array is not marked with this flag
801 // it will deoptimize if result does not fit into signed integer range. 802 // it will deoptimize if result does not fit into signed integer range.
802 // HGraph::ComputeSafeUint32Operations is responsible for setting this 803 // HGraph::ComputeSafeUint32Operations is responsible for setting this
803 // flag. 804 // flag.
804 kUint32, 805 kUint32,
805 // If a phi is involved in the evaluation of a numeric constraint the 806 // If a phi is involved in the evaluation of a numeric constraint the
806 // recursion can cause an endless cycle: we use this flag to exit the loop. 807 // recursion can cause an endless cycle: we use this flag to exit the loop.
807 kNumericConstraintEvaluationInProgress, 808 kNumericConstraintEvaluationInProgress,
808 // This flag is set to true after the SetupInformativeDefinitions() pass 809 // This flag is set to true after the SetupInformativeDefinitions() pass
809 // has processed this instruction. 810 // has processed this instruction.
810 kIDefsProcessingDone, 811 kIDefsProcessingDone,
811 kHasNoObservableSideEffects, 812 kHasNoObservableSideEffects,
813 // Indicates the instruction is live during dead code elimination.
814 kIsLive,
812 kLastFlag = kIDefsProcessingDone 815 kLastFlag = kIDefsProcessingDone
813 }; 816 };
814 817
815 STATIC_ASSERT(kLastFlag < kBitsPerInt); 818 STATIC_ASSERT(kLastFlag < kBitsPerInt);
816 819
817 static const int kChangesToDependsFlagsLeftShift = 1; 820 static const int kChangesToDependsFlagsLeftShift = 1;
818 821
819 static GVNFlag ChangesFlagFromInt(int x) { 822 static GVNFlag ChangesFlagFromInt(int x) {
820 return static_cast<GVNFlag>(x * 2); 823 return static_cast<GVNFlag>(x * 2);
821 } 824 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 1067
1065 virtual HType CalculateInferredType(); 1068 virtual HType CalculateInferredType();
1066 1069
1067 // This function must be overridden for instructions which have the 1070 // This function must be overridden for instructions which have the
1068 // kTrackSideEffectDominators flag set, to track instructions that are 1071 // kTrackSideEffectDominators flag set, to track instructions that are
1069 // dominating side effects. 1072 // dominating side effects.
1070 virtual void SetSideEffectDominator(GVNFlag side_effect, HValue* dominator) { 1073 virtual void SetSideEffectDominator(GVNFlag side_effect, HValue* dominator) {
1071 UNREACHABLE(); 1074 UNREACHABLE();
1072 } 1075 }
1073 1076
1074 bool IsDead() const { 1077 // Check if this instruction has some reason that prevents elimination.
1075 return HasNoUses() && !HasObservableSideEffects() && IsDeletable(); 1078 bool CannotBeEliminated() const {
1079 return HasObservableSideEffects() || !IsDeletable();
1076 } 1080 }
1077 1081
1078 #ifdef DEBUG 1082 #ifdef DEBUG
1079 virtual void Verify() = 0; 1083 virtual void Verify() = 0;
1080 #endif 1084 #endif
1081 1085
1082 bool IsRelationTrue(NumericRelation relation, 1086 bool IsRelationTrue(NumericRelation relation,
1083 HValue* other, 1087 HValue* other,
1084 int offset = 0, 1088 int offset = 0,
1085 int scale = 0); 1089 int scale = 0);
(...skipping 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after
2962 virtual bool DataEquals(HValue* other) { return true; } 2966 virtual bool DataEquals(HValue* other) { return true; }
2963 }; 2967 };
2964 2968
2965 2969
2966 class HPhi: public HValue { 2970 class HPhi: public HValue {
2967 public: 2971 public:
2968 HPhi(int merged_index, Zone* zone) 2972 HPhi(int merged_index, Zone* zone)
2969 : inputs_(2, zone), 2973 : inputs_(2, zone),
2970 merged_index_(merged_index), 2974 merged_index_(merged_index),
2971 phi_id_(-1), 2975 phi_id_(-1),
2972 is_live_(false),
2973 is_convertible_to_integer_(true) { 2976 is_convertible_to_integer_(true) {
2974 for (int i = 0; i < Representation::kNumRepresentations; i++) { 2977 for (int i = 0; i < Representation::kNumRepresentations; i++) {
2975 non_phi_uses_[i] = 0; 2978 non_phi_uses_[i] = 0;
2976 indirect_uses_[i] = 0; 2979 indirect_uses_[i] = 0;
2977 } 2980 }
2978 ASSERT(merged_index >= 0); 2981 ASSERT(merged_index >= 0);
2979 SetFlag(kFlexibleRepresentation); 2982 SetFlag(kFlexibleRepresentation);
2980 } 2983 }
2981 2984
2982 virtual Representation RepresentationFromInputs(); 2985 virtual Representation RepresentationFromInputs();
2983 2986
2984 virtual Range* InferRange(Zone* zone); 2987 virtual Range* InferRange(Zone* zone);
2985 virtual void InferRepresentation(HInferRepresentation* h_infer); 2988 virtual void InferRepresentation(HInferRepresentation* h_infer);
2986 Representation RepresentationFromUseRequirements(); 2989 Representation RepresentationFromUseRequirements();
2987 virtual Representation RequiredInputRepresentation(int index) { 2990 virtual Representation RequiredInputRepresentation(int index) {
2988 return representation(); 2991 return representation();
2989 } 2992 }
2990 virtual HType CalculateInferredType(); 2993 virtual HType CalculateInferredType();
2991 virtual int OperandCount() { return inputs_.length(); } 2994 virtual int OperandCount() { return inputs_.length(); }
2992 virtual HValue* OperandAt(int index) const { return inputs_[index]; } 2995 virtual HValue* OperandAt(int index) const { return inputs_[index]; }
2993 HValue* GetRedundantReplacement(); 2996 HValue* GetRedundantReplacement();
2994 void AddInput(HValue* value); 2997 void AddInput(HValue* value);
2995 bool HasRealUses(); 2998 bool HasRealUses();
2996 2999
2997 bool IsReceiver() { return merged_index_ == 0; } 3000 bool IsReceiver() const { return merged_index_ == 0; }
2998 3001
2999 int merged_index() const { return merged_index_; } 3002 int merged_index() const { return merged_index_; }
3000 3003
3001 virtual void AddInformativeDefinitions(); 3004 virtual void AddInformativeDefinitions();
3002 3005
3003 virtual void PrintTo(StringStream* stream); 3006 virtual void PrintTo(StringStream* stream);
3004 3007
3005 #ifdef DEBUG 3008 #ifdef DEBUG
3006 virtual void Verify(); 3009 virtual void Verify();
3007 #endif 3010 #endif
(...skipping 14 matching lines...) Expand all
3022 int tagged_indirect_uses() const { 3025 int tagged_indirect_uses() const {
3023 return indirect_uses_[Representation::kTagged]; 3026 return indirect_uses_[Representation::kTagged];
3024 } 3027 }
3025 int int32_indirect_uses() const { 3028 int int32_indirect_uses() const {
3026 return indirect_uses_[Representation::kInteger32]; 3029 return indirect_uses_[Representation::kInteger32];
3027 } 3030 }
3028 int double_indirect_uses() const { 3031 int double_indirect_uses() const {
3029 return indirect_uses_[Representation::kDouble]; 3032 return indirect_uses_[Representation::kDouble];
3030 } 3033 }
3031 int phi_id() { return phi_id_; } 3034 int phi_id() { return phi_id_; }
3032 bool is_live() { return is_live_; }
3033 void set_is_live(bool b) { is_live_ = b; }
3034 3035
3035 static HPhi* cast(HValue* value) { 3036 static HPhi* cast(HValue* value) {
3036 ASSERT(value->IsPhi()); 3037 ASSERT(value->IsPhi());
3037 return reinterpret_cast<HPhi*>(value); 3038 return reinterpret_cast<HPhi*>(value);
3038 } 3039 }
3039 virtual Opcode opcode() const { return HValue::kPhi; } 3040 virtual Opcode opcode() const { return HValue::kPhi; }
3040 3041
3041 virtual bool IsConvertibleToInteger() const { 3042 virtual bool IsConvertibleToInteger() const {
3042 return is_convertible_to_integer_; 3043 return is_convertible_to_integer_;
3043 } 3044 }
(...skipping 11 matching lines...) Expand all
3055 id(), Mnemonic(), input->id(), input->Mnemonic(), i); 3056 id(), Mnemonic(), input->id(), input->Mnemonic(), i);
3056 } 3057 }
3057 return false; 3058 return false;
3058 } 3059 }
3059 } 3060 }
3060 return true; 3061 return true;
3061 } 3062 }
3062 3063
3063 void SimplifyConstantInputs(); 3064 void SimplifyConstantInputs();
3064 3065
3066 // TODO(titzer): we can't eliminate the receiver for generating backtraces
3067 virtual bool IsDeletable() const { return !IsReceiver(); }
3068
3065 protected: 3069 protected:
3066 virtual void DeleteFromGraph(); 3070 virtual void DeleteFromGraph();
3067 virtual void InternalSetOperandAt(int index, HValue* value) { 3071 virtual void InternalSetOperandAt(int index, HValue* value) {
3068 inputs_[index] = value; 3072 inputs_[index] = value;
3069 } 3073 }
3070 3074
3071 virtual bool IsRelationTrueInternal(NumericRelation relation, 3075 virtual bool IsRelationTrueInternal(NumericRelation relation,
3072 HValue* other, 3076 HValue* other,
3073 int offset = 0, 3077 int offset = 0,
3074 int scale = 0); 3078 int scale = 0);
3075 3079
3076 private: 3080 private:
3077 ZoneList<HValue*> inputs_; 3081 ZoneList<HValue*> inputs_;
3078 int merged_index_; 3082 int merged_index_;
3079 3083
3080 int non_phi_uses_[Representation::kNumRepresentations]; 3084 int non_phi_uses_[Representation::kNumRepresentations];
3081 int indirect_uses_[Representation::kNumRepresentations]; 3085 int indirect_uses_[Representation::kNumRepresentations];
3082 int phi_id_; 3086 int phi_id_;
3083 bool is_live_;
3084 bool is_convertible_to_integer_; 3087 bool is_convertible_to_integer_;
3085 }; 3088 };
3086 3089
3087 3090
3088 class HInductionVariableAnnotation : public HUnaryOperation { 3091 class HInductionVariableAnnotation : public HUnaryOperation {
3089 public: 3092 public:
3090 static HInductionVariableAnnotation* AddToGraph(HPhi* phi, 3093 static HInductionVariableAnnotation* AddToGraph(HPhi* phi,
3091 NumericRelation relation, 3094 NumericRelation relation,
3092 int operand_index); 3095 int operand_index);
3093 3096
(...skipping 3368 matching lines...) Expand 10 before | Expand all | Expand 10 after
6462 virtual bool IsDeletable() const { return true; } 6465 virtual bool IsDeletable() const { return true; }
6463 }; 6466 };
6464 6467
6465 6468
6466 #undef DECLARE_INSTRUCTION 6469 #undef DECLARE_INSTRUCTION
6467 #undef DECLARE_CONCRETE_INSTRUCTION 6470 #undef DECLARE_CONCRETE_INSTRUCTION
6468 6471
6469 } } // namespace v8::internal 6472 } } // namespace v8::internal
6470 6473
6471 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ 6474 #endif // V8_HYDROGEN_INSTRUCTIONS_H_
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/hydrogen-instructions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698