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

Side by Side Diff: runtime/vm/intermediate_language.h

Issue 9729015: Compute immediate dominators using SEMI-NCA. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_
6 #define VM_INTERMEDIATE_LANGUAGE_H_ 6 #define VM_INTERMEDIATE_LANGUAGE_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/ast.h" 9 #include "vm/ast.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 virtual void SetSuccessor(Instruction* instr) = 0; 806 virtual void SetSuccessor(Instruction* instr) = 0;
807 807
808 // Discover basic-block structure by performing a recursive depth first 808 // Discover basic-block structure by performing a recursive depth first
809 // traversal of the instruction graph reachable from this instruction. As 809 // traversal of the instruction graph reachable from this instruction. As
810 // a side effect, the block entry instructions in the graph are assigned 810 // a side effect, the block entry instructions in the graph are assigned
811 // numbers in both preorder and postorder. The array 'preorder' maps 811 // numbers in both preorder and postorder. The array 'preorder' maps
812 // preorder block numbers to the block entry instruction with that number 812 // preorder block numbers to the block entry instruction with that number
813 // and analogously for the array 'postorder'. The depth first spanning 813 // and analogously for the array 'postorder'. The depth first spanning
814 // tree is recorded in the array 'parent', which maps preorder block 814 // tree is recorded in the array 'parent', which maps preorder block
815 // numbers to the preorder number of the block's spanning-tree parent. As 815 // numbers to the preorder number of the block's spanning-tree parent. As
816 // a side effect, the set of basic block predecessors (e.g., block entry 816 // a side effect of this function76, the set of basic block predecessors
Kevin Millikin (Google) 2012/03/19 23:25:00 Oops. The stray '76' is deleted.
817 // instructions of predecessor blocks) and also the last instruction in 817 // (e.g., block entry instructions of predecessor blocks) and also the
818 // the block is recorded in each entry instruction. 818 // last instruction in the block is recorded in each entry instruction.
819 virtual void DiscoverBlocks( 819 virtual void DiscoverBlocks(
820 BlockEntryInstr* current_block, 820 BlockEntryInstr* current_block,
821 GrowableArray<BlockEntryInstr*>* preorder, 821 GrowableArray<BlockEntryInstr*>* preorder,
822 GrowableArray<BlockEntryInstr*>* postorder, 822 GrowableArray<BlockEntryInstr*>* postorder,
823 GrowableArray<BlockEntryInstr*>* parent) { 823 GrowableArray<intptr_t>* parent) {
824 // Never called for instructions except block entries and branches. 824 // Never called for instructions except block entries and branches.
825 UNREACHABLE(); 825 UNREACHABLE();
826 } 826 }
827 827
828 #define INSTRUCTION_TYPE_CHECK(type) \ 828 #define INSTRUCTION_TYPE_CHECK(type) \
829 virtual bool Is##type() const { return false; } \ 829 virtual bool Is##type() const { return false; } \
830 virtual type##Instr* As##type() { return NULL; } 830 virtual type##Instr* As##type() { return NULL; }
831 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) 831 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK)
832 #undef INSTRUCTION_TYPE_CHECK 832 #undef INSTRUCTION_TYPE_CHECK
833 833
834 private: 834 private:
835 DISALLOW_COPY_AND_ASSIGN(Instruction); 835 DISALLOW_COPY_AND_ASSIGN(Instruction);
836 }; 836 };
837 837
838 838
839 // Basic block entries are administrative nodes. Joins are the only nodes 839 // Basic block entries are administrative nodes. Joins are the only nodes
840 // with multiple predecessors. Targets are the other basic block entries. 840 // with multiple predecessors. Targets are the other basic block entries.
841 // The types enforce edge-split form---joins are forbidden as the successors 841 // The types enforce edge-split form---joins are forbidden as the successors
842 // of branches. 842 // of branches.
843 class BlockEntryInstr : public Instruction { 843 class BlockEntryInstr : public Instruction {
844 public: 844 public:
845 virtual bool IsBlockEntry() const { return true; } 845 virtual bool IsBlockEntry() const { return true; }
846 846
847 virtual intptr_t PredecessorCount() const = 0;
848 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const = 0;
849
847 intptr_t preorder_number() const { return preorder_number_; } 850 intptr_t preorder_number() const { return preorder_number_; }
848 void set_preorder_number(intptr_t number) { preorder_number_ = number; } 851 void set_preorder_number(intptr_t number) { preorder_number_ = number; }
849 852
850 intptr_t postorder_number() const { return postorder_number_; } 853 intptr_t postorder_number() const { return postorder_number_; }
851 void set_postorder_number(intptr_t number) { postorder_number_ = number; } 854 void set_postorder_number(intptr_t number) { postorder_number_ = number; }
852 855
856 BlockEntryInstr* dominator() const { return dominator_; }
857 void set_dominator(BlockEntryInstr* instr) { dominator_ = instr; }
858
853 Instruction* last_instruction() const { return last_instruction_; } 859 Instruction* last_instruction() const { return last_instruction_; }
854 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; } 860 void set_last_instruction(Instruction* instr) { last_instruction_ = instr; }
855 861
856 protected: 862 protected:
857 BlockEntryInstr() 863 BlockEntryInstr()
858 : preorder_number_(-1), 864 : preorder_number_(-1),
859 postorder_number_(-1), 865 postorder_number_(-1),
866 dominator_(NULL),
860 last_instruction_(NULL) { } 867 last_instruction_(NULL) { }
861 868
862 private: 869 private:
863 intptr_t preorder_number_; 870 intptr_t preorder_number_;
864 intptr_t postorder_number_; 871 intptr_t postorder_number_;
872 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry.
865 Instruction* last_instruction_; 873 Instruction* last_instruction_;
866 874
867 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); 875 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr);
868 }; 876 };
869 877
870 878
871 class JoinEntryInstr : public BlockEntryInstr { 879 class JoinEntryInstr : public BlockEntryInstr {
872 public: 880 public:
873 JoinEntryInstr() 881 JoinEntryInstr()
874 : BlockEntryInstr(), 882 : BlockEntryInstr(),
875 predecessors_(2), // Two is the assumed to be the common case. 883 predecessors_(2), // Two is the assumed to be the common case.
876 successor_(NULL) { } 884 successor_(NULL) { }
877 885
878 DECLARE_INSTRUCTION(JoinEntry) 886 DECLARE_INSTRUCTION(JoinEntry)
879 887
888 virtual intptr_t PredecessorCount() const { return predecessors_.length(); }
889 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const {
890 return predecessors_[index];
891 }
892
880 virtual Instruction* StraightLineSuccessor() const { 893 virtual Instruction* StraightLineSuccessor() const {
881 return successor_; 894 return successor_;
882 } 895 }
883 virtual void SetSuccessor(Instruction* instr) { 896 virtual void SetSuccessor(Instruction* instr) {
884 ASSERT(successor_ == NULL); 897 ASSERT(successor_ == NULL);
885 successor_ = instr; 898 successor_ = instr;
886 } 899 }
887 900
888 virtual void DiscoverBlocks( 901 virtual void DiscoverBlocks(
889 BlockEntryInstr* current_block, 902 BlockEntryInstr* current_block,
890 GrowableArray<BlockEntryInstr*>* preorder, 903 GrowableArray<BlockEntryInstr*>* preorder,
891 GrowableArray<BlockEntryInstr*>* postorder, 904 GrowableArray<BlockEntryInstr*>* postorder,
892 GrowableArray<BlockEntryInstr*>* parent); 905 GrowableArray<intptr_t>* parent);
893 906
894 private: 907 private:
895 ZoneGrowableArray<BlockEntryInstr*> predecessors_; 908 ZoneGrowableArray<BlockEntryInstr*> predecessors_;
896 Instruction* successor_; 909 Instruction* successor_;
897 910
898 DISALLOW_COPY_AND_ASSIGN(JoinEntryInstr); 911 DISALLOW_COPY_AND_ASSIGN(JoinEntryInstr);
899 }; 912 };
900 913
901 914
902 class TargetEntryInstr : public BlockEntryInstr { 915 class TargetEntryInstr : public BlockEntryInstr {
903 public: 916 public:
904 TargetEntryInstr() 917 TargetEntryInstr()
905 : BlockEntryInstr(), predecessor_(NULL), successor_(NULL) { } 918 : BlockEntryInstr(), predecessor_(NULL), successor_(NULL) { }
906 919
907 DECLARE_INSTRUCTION(TargetEntry) 920 DECLARE_INSTRUCTION(TargetEntry)
908 921
922 virtual intptr_t PredecessorCount() const {
923 return (predecessor_ == NULL) ? 0 : 1;
924 }
925 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const {
926 ASSERT((index == 0) && (predecessor_ != NULL));
927 return predecessor_;
928 }
929
909 virtual Instruction* StraightLineSuccessor() const { 930 virtual Instruction* StraightLineSuccessor() const {
910 return successor_; 931 return successor_;
911 } 932 }
912 virtual void SetSuccessor(Instruction* instr) { 933 virtual void SetSuccessor(Instruction* instr) {
913 ASSERT(successor_ == NULL); 934 ASSERT(successor_ == NULL);
914 successor_ = instr; 935 successor_ = instr;
915 } 936 }
916 937
917 virtual void DiscoverBlocks( 938 virtual void DiscoverBlocks(
918 BlockEntryInstr* current_block, 939 BlockEntryInstr* current_block,
919 GrowableArray<BlockEntryInstr*>* preorder, 940 GrowableArray<BlockEntryInstr*>* preorder,
920 GrowableArray<BlockEntryInstr*>* postorder, 941 GrowableArray<BlockEntryInstr*>* postorder,
921 GrowableArray<BlockEntryInstr*>* parent); 942 GrowableArray<intptr_t>* parent);
922 943
923 private: 944 private:
924 BlockEntryInstr* predecessor_; 945 BlockEntryInstr* predecessor_;
925 Instruction* successor_; 946 Instruction* successor_;
926 947
927 DISALLOW_COPY_AND_ASSIGN(TargetEntryInstr); 948 DISALLOW_COPY_AND_ASSIGN(TargetEntryInstr);
928 }; 949 };
929 950
930 951
931 // The non-optimizing compiler assumes that there is exactly one use of 952 // The non-optimizing compiler assumes that there is exactly one use of
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 TargetEntryInstr** true_successor_address() { return &true_successor_; } 1169 TargetEntryInstr** true_successor_address() { return &true_successor_; }
1149 TargetEntryInstr** false_successor_address() { return &false_successor_; } 1170 TargetEntryInstr** false_successor_address() { return &false_successor_; }
1150 1171
1151 virtual Instruction* StraightLineSuccessor() const { return NULL; } 1172 virtual Instruction* StraightLineSuccessor() const { return NULL; }
1152 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } 1173 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); }
1153 1174
1154 virtual void DiscoverBlocks( 1175 virtual void DiscoverBlocks(
1155 BlockEntryInstr* current_block, 1176 BlockEntryInstr* current_block,
1156 GrowableArray<BlockEntryInstr*>* preorder, 1177 GrowableArray<BlockEntryInstr*>* preorder,
1157 GrowableArray<BlockEntryInstr*>* postorder, 1178 GrowableArray<BlockEntryInstr*>* postorder,
1158 GrowableArray<BlockEntryInstr*>* parent); 1179 GrowableArray<intptr_t>* parent);
1159 1180
1160 private: 1181 private:
1161 Value* value_; 1182 Value* value_;
1162 TargetEntryInstr* true_successor_; 1183 TargetEntryInstr* true_successor_;
1163 TargetEntryInstr* false_successor_; 1184 TargetEntryInstr* false_successor_;
1164 1185
1165 DISALLOW_COPY_AND_ASSIGN(BranchInstr); 1186 DISALLOW_COPY_AND_ASSIGN(BranchInstr);
1166 }; 1187 };
1167 1188
1168 #undef DECLARE_INSTRUCTION 1189 #undef DECLARE_INSTRUCTION
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 const GrowableArray<BlockEntryInstr*>& block_order_; 1226 const GrowableArray<BlockEntryInstr*>& block_order_;
1206 1227
1207 private: 1228 private:
1208 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 1229 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
1209 }; 1230 };
1210 1231
1211 1232
1212 } // namespace dart 1233 } // namespace dart
1213 1234
1214 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 1235 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698