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

Side by Side Diff: src/hydrogen.h

Issue 14696015: Verify that no-side-effects scope does not add unsafe phis and does not change push-pop balance of … (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add test 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 | « no previous file | src/hydrogen.cc » ('j') | src/hydrogen.cc » ('J')
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 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 int position_; 927 int position_;
928 }; 928 };
929 929
930 930
931 class HGraphBuilder { 931 class HGraphBuilder {
932 public: 932 public:
933 explicit HGraphBuilder(CompilationInfo* info) 933 explicit HGraphBuilder(CompilationInfo* info)
934 : info_(info), 934 : info_(info),
935 graph_(NULL), 935 graph_(NULL),
936 current_block_(NULL), 936 current_block_(NULL),
937 no_side_effects_scope_environment_push_pop_delta_(0),
937 no_side_effects_scope_count_(0) {} 938 no_side_effects_scope_count_(0) {}
938 virtual ~HGraphBuilder() {} 939 virtual ~HGraphBuilder() {}
939 940
940 HBasicBlock* current_block() const { return current_block_; } 941 HBasicBlock* current_block() const { return current_block_; }
941 void set_current_block(HBasicBlock* block) { current_block_ = block; } 942 void set_current_block(HBasicBlock* block) {
943 // Conservatively disalow adding phis by disallowing changing the block
944 // as this class has no other bottlenecks for adding phis.
945 ASSERT(SafeToAddPhiInNoSideEffectsScope());
946 current_block_ = block;
947 }
942 HEnvironment* environment() const { 948 HEnvironment* environment() const {
943 return current_block()->last_environment(); 949 return current_block()->last_environment();
944 } 950 }
945 Zone* zone() const { return info_->zone(); } 951 Zone* zone() const { return info_->zone(); }
946 HGraph* graph() const { return graph_; } 952 HGraph* graph() const { return graph_; }
947 Isolate* isolate() const { return graph_->isolate(); } 953 Isolate* isolate() const { return graph_->isolate(); }
948 954
949 HGraph* CreateGraph(); 955 HGraph* CreateGraph();
950 956
951 // Bailout environment manipulation. 957 // Bailout environment manipulation.
952 void Push(HValue* value) { environment()->Push(value); } 958 void Push(HValue* value) { environment()->Push(value); }
953 HValue* Pop() { return environment()->Pop(); } 959 HValue* Pop() { return environment()->Pop(); }
954 960
955 // Adding instructions. 961 // Adding instructions.
956 HInstruction* AddInstruction(HInstruction* instr); 962 HInstruction* AddInstruction(HInstruction* instr);
957 void AddSimulate(BailoutId id, 963 void AddSimulate(BailoutId id,
958 RemovableSimulate removable = FIXED_SIMULATE); 964 RemovableSimulate removable = FIXED_SIMULATE);
959 HBoundsCheck* AddBoundsCheck( 965 HBoundsCheck* AddBoundsCheck(
960 HValue* index, 966 HValue* index,
961 HValue* length, 967 HValue* length,
962 BoundsCheckKeyMode key_mode = DONT_ALLOW_SMI_KEY, 968 BoundsCheckKeyMode key_mode = DONT_ALLOW_SMI_KEY,
963 Representation r = Representation::None()); 969 Representation r = Representation::None());
964 970
965 HReturn* AddReturn(HValue* value); 971 HReturn* AddReturn(HValue* value);
966 972
967 void IncrementInNoSideEffectsScope() { 973 void IncrementInNoSideEffectsScope() {
974 if (no_side_effects_scope_count_ == 0) {
975 no_side_effects_scope_environment_push_pop_delta_ =
976 environment()->push_count() - environment()->pop_count();
977 }
968 no_side_effects_scope_count_++; 978 no_side_effects_scope_count_++;
969 } 979 }
970 980
971 void DecrementInNoSideEffectsScope() { 981 void DecrementInNoSideEffectsScope() {
972 no_side_effects_scope_count_--; 982 no_side_effects_scope_count_--;
983 if (no_side_effects_scope_count_ == 0) {
984 // No-side-effects scope should not change push-pop delta.
985 ASSERT_EQ(no_side_effects_scope_environment_push_pop_delta_,
986 environment()->push_count() - environment()->pop_count());
987 no_side_effects_scope_environment_push_pop_delta_ = 0;
988 }
989 }
990
991 bool SafeToAddPhiInNoSideEffectsScope() {
992 // Pops and pushes after a simulate are not visible in LChunkBuilder.
993 // If the number of pops is greater than the number pushes then the
994 // environment in HGraphBuilder is shorter then the corresponding
995 // environment in LChunkBuilder. This causes non-observable phis
996 // to be pushed in the environment, which breaks deoptimization.
997 return no_side_effects_scope_count_ == 0 ||
998 no_side_effects_scope_environment_push_pop_delta_ >= 0;
973 } 999 }
974 1000
975 protected: 1001 protected:
976 virtual bool BuildGraph() = 0; 1002 virtual bool BuildGraph() = 0;
977 1003
978 HBasicBlock* CreateBasicBlock(HEnvironment* env); 1004 HBasicBlock* CreateBasicBlock(HEnvironment* env);
979 HBasicBlock* CreateLoopHeaderBlock(); 1005 HBasicBlock* CreateLoopHeaderBlock();
980 1006
981 HValue* BuildCheckNonSmi(HValue* object); 1007 HValue* BuildCheckNonSmi(HValue* object);
982 HValue* BuildCheckMap(HValue* obj, Handle<Map> map); 1008 HValue* BuildCheckMap(HValue* obj, Handle<Map> map);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 HValue* payload); 1351 HValue* payload);
1326 1352
1327 HInstruction* BuildGetNativeContext(HValue* context); 1353 HInstruction* BuildGetNativeContext(HValue* context);
1328 HInstruction* BuildGetArrayFunction(HValue* context); 1354 HInstruction* BuildGetArrayFunction(HValue* context);
1329 1355
1330 private: 1356 private:
1331 HGraphBuilder(); 1357 HGraphBuilder();
1332 CompilationInfo* info_; 1358 CompilationInfo* info_;
1333 HGraph* graph_; 1359 HGraph* graph_;
1334 HBasicBlock* current_block_; 1360 HBasicBlock* current_block_;
1361 int no_side_effects_scope_environment_push_pop_delta_;
1335 int no_side_effects_scope_count_; 1362 int no_side_effects_scope_count_;
1336 }; 1363 };
1337 1364
1338 1365
1339 class HOptimizedGraphBuilder: public HGraphBuilder, public AstVisitor { 1366 class HOptimizedGraphBuilder: public HGraphBuilder, public AstVisitor {
1340 public: 1367 public:
1341 enum BreakType { BREAK, CONTINUE }; 1368 enum BreakType { BREAK, CONTINUE };
1342 enum SwitchType { UNKNOWN_SWITCH, SMI_SWITCH, STRING_SWITCH }; 1369 enum SwitchType { UNKNOWN_SWITCH, SMI_SWITCH, STRING_SWITCH };
1343 1370
1344 // A class encapsulating (lazily-allocated) break and continue blocks for 1371 // A class encapsulating (lazily-allocated) break and continue blocks for
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 EmbeddedVector<char, 64> filename_; 2040 EmbeddedVector<char, 64> filename_;
2014 HeapStringAllocator string_allocator_; 2041 HeapStringAllocator string_allocator_;
2015 StringStream trace_; 2042 StringStream trace_;
2016 int indent_; 2043 int indent_;
2017 }; 2044 };
2018 2045
2019 2046
2020 } } // namespace v8::internal 2047 } } // namespace v8::internal
2021 2048
2022 #endif // V8_HYDROGEN_H_ 2049 #endif // V8_HYDROGEN_H_
OLDNEW
« no previous file with comments | « no previous file | src/hydrogen.cc » ('j') | src/hydrogen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698