1 /**
2  * Compiler implementation of the
3  * $(LINK2 http://www.dlang.org, D programming language).
4  *
5  * Copyright:   Copyright (C) 1986-1998 by Symantec
6  *              Copyright (C) 2000-2020 by The D Language Foundation, All Rights Reserved
7  * Authors:     $(LINK2 http://www.digitalmars.com, Walter Bright)
8  * License:     Distributed under the Boost Software License, Version 1.0.
9  *              http://www.boost.org/LICENSE_1_0.txt
10  * Source:      https://github.com/dlang/dmd/blob/master/src/dmd/backend/goh.d
11  */
12 
13 module dmd.backend.goh;
14 
15 import core.stdc.stdio;
16 import core.stdc.stdlib;
17 import core.stdc.string;
18 import core.stdc.time;
19 
20 import dmd.backend.cc;
21 import dmd.backend.cdef;
22 import dmd.backend.oper;
23 import dmd.backend.global;
24 import dmd.backend.el;
25 import dmd.backend.ty;
26 import dmd.backend.type;
27 
28 import dmd.backend.barray;
29 import dmd.backend.dlist;
30 import dmd.backend.dvec;
31 
32 extern (C++):
33 nothrow:
34 
35 /***************************************
36  * Bit masks for various optimizations.
37  */
38 
39 alias mftype = uint;        /* a type big enough for all the flags  */
40 enum
41 {
42     MFdc    = 1,               // dead code
43     MFda    = 2,               // dead assignments
44     MFdv    = 4,               // dead variables
45     MFreg   = 8,               // register variables
46     MFcse   = 0x10,            // global common subexpressions
47     MFvbe   = 0x20,            // very busy expressions
48     MFtime  = 0x40,            // favor time (speed) over space
49     MFli    = 0x80,            // loop invariants
50     MFliv   = 0x100,           // loop induction variables
51     MFcp    = 0x200,           // copy propagation
52     MFcnp   = 0x400,           // constant propagation
53     MFloop  = 0x800,           // loop till no more changes
54     MFtree  = 0x1000,          // optelem (tree optimization)
55     MFlocal = 0x2000,          // localize expressions
56     MFall   = 0xFFFF,          // do everything
57 }
58 
59 /**********************************
60  * Definition elem vector, used for reaching definitions.
61  */
62 
63 struct DefNode
64 {
65     elem    *DNelem;        // pointer to definition elem
66     block   *DNblock;       // pointer to block that the elem is in
67     vec_t    DNunambig;     // vector of unambiguous definitions
68 }
69 
70 /* Global Variables */
71 //extern __gshared uint[] optab;
72 
73 /* Global Optimizer variables
74  */
75 struct GlobalOptimizer
76 {
77     mftype mfoptim;
78     uint changes;       // # of optimizations performed
79 
80     Barray!DefNode defnod;    // array of definition elems
81     uint unambigtop;    // number of unambiguous defininitions ( <= deftop )
82 
83     Barray!(vec_base_t) dnunambig;  // pool to allocate DNunambig vectors from
84 
85     Barray!(elem*) expnod;      // array of expression elems
86     uint exptop;        // top of expnod[]
87     Barray!(block*) expblk;     // parallel array of block pointers
88 
89     vec_t defkill;      // vector of AEs killed by an ambiguous definition
90     vec_t starkill;     // vector of AEs killed by a definition of something that somebody could be
91                         // pointing to
92     vec_t vptrkill;     // vector of AEs killed by an access
93 }
94 
95 extern __gshared GlobalOptimizer go;
96 
97 /* gdag.c */
98 void builddags();
99 void boolopt();
100 void opt_arraybounds();
101 
102 /* gflow.c */
103 void flowrd();
104 void flowlv();
105 void flowvbe();
106 void flowcp();
107 void flowae();
108 void genkillae();
109 void flowarraybounds();
110 int ae_field_affect(elem *lvalue,elem *e);
111 
112 /* glocal.c */
113 void localize();
114 
115 /* gloop.c */
116 int blockinit();
117 void compdom();
118 void loopopt();
119 extern (C) void fillInDNunambig(vec_t v, elem *e);
120 extern (C) void updaterd(elem *n,vec_t GEN,vec_t KILL);
121 
122 /* gother.c */
123 void rd_arraybounds();
124 void rd_free();
125 void constprop();
126 void copyprop();
127 void rmdeadass();
128 void elimass(elem *);
129 void deadvar();
130 void verybusyexp();
131 extern (C) list_t listrds(vec_t, elem *, vec_t);
132 
133 /* gslice.c */
134 void sliceStructs(symtab_t* symtab, block* startblock);
135