annotate dmd/backend/block.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 63623152e82a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.backend.LIST;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.backend.regm_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.backend.Srcpos;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.backend.code;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.backend.SYMIDX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.backend.vec_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.backend.targ_types;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.backend.con_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 struct block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 union
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 elem* Belem; // pointer to elem tree
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 list_t Blist; // list of expressions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 block* Bnext; // pointer to next block in list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 list_t Bsucc; // linked list of pointers to successors
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 // of this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 list_t Bpred; // and the predecessor list
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 int Bindex; // into created object stack
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 int Bendindex; // index at end of block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 block* Btry; // BCtry,BC_try: enclosing try block, if any
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 // BC???: if in try-block, points to BCtry or BC_try
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 // note that can't have a BCtry and BC_try in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 // the same function.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 union
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 targ_llong *Bswitch; // BCswitch: pointer to switch data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 regm_t usIasmregs; // Registers modified
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 ubyte bIasmrefparam; // References parameters?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 Symbol* catchvar; // __throw() fills in this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Symbol* catchtype; // one type for each catch block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 Symbol* jcatchvar; // __j_throw() fills in this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 int Bscope_index; // index into scope table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 int Blast_index; // enclosing index into scope table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 public alias catchtype Bcatchtype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 Srcpos Bsrcpos; // line number (0 if not known)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 ubyte BC; // exit condition (enum BC)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 // NEW
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 ubyte Balign; // alignment
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 ushort Bflags; // flags (BFLxxxx)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 code* Bcode; // code generated for this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 uint Bweight; // relative number of times this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 // is executed (optimizer and codegen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 uint Bdfoidx; // index of this block in dfo[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 union
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 // CPP
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 SYMIDX symstart; // (symstart <= symnum < symend) Symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 SYMIDX symend; // are declared in this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 block* endscope; // block that forms the end of the
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 // scope for the declared Symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 uint blknum; // position of block from startblock
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 Symbol* Binitvar; // !=NULL points to an auto variable with
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 // an explicit or implicit initializer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 block* gotolist; // BCtry, BCcatch: backward list of try scopes
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 block* gotothread; // BCgoto: threaded list of goto's to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 // unknown labels
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 // OPTIMIZER
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 vec_t Bdom; // mask of dominators for this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 vec_t Binrd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 vec_t Boutrd; // IN and OUT for reaching definitions
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 vec_t Binlv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 vec_t Boutlv; // IN and OUT for live variables
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 vec_t Bin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 vec_t Bout; // IN and OUT for other flow analyses
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 vec_t Bgen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 vec_t Bkill; // pointers to bit vectors used by data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 // flow analysis
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 // BCiftrue can have different vectors for the 2nd successor:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 vec_t Bout2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 vec_t Bgen2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 vec_t Bkill2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 // CODGEN
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 struct
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 targ_size_t Btablesize; // BCswitch, BCjmptab
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 targ_size_t Btableoffset; // BCswitch, BCjmptab
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 targ_size_t Boffset; // code offset of start of this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 targ_size_t Bsize; // code size of this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 con_t Bregcon; // register state at block exit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 targ_size_t Btryoff; // BCtry: offset of try block data
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 enum BFL
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 BFLvisited = 1, // set if block is visited
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 BFLmark = 2, // set if block is visited
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 BFLjmpoptdone = 4, // set when no more jump optimizations
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 // are possible for this block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 BFLnostackopt = 8, // set when stack elimination should not
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 // be done
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 ///version (NTEXCEPTIONS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 BFLehcode = 0x10, // set when we need to load exception code
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 BFLunwind = 0x1000, // do local_unwind following block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 ///version (TARGET_POWERPC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 /// BFLstructret = 0x10, /* Set if a struct return is changed to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 /// block type BCret. This is done to avoid
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 /// error messages */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 BFLnomerg = 0x20, // do not merge with other blocks
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 ///version (TX86) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 BFLprolog = 0x80, // generate function prolog
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 BFLepilog = 0x100, // generate function epilog
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 BFLrefparam = 0x200, // referenced parameter
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 BFLreflocal = 0x400, // referenced local
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 BFLoutsideprolog = 0x800, // outside function prolog/epilog
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 BFLlabel = 0x2000, // block preceded by label
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 ///} else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 /// BFLlooprt = 0x40, // set if looprotate() changes it's Bnext
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 BFLvolatile = 0x4000, // block is volatile
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }