|
| 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-2017 by Digital Mars, 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.dlist; |
| 29 | +import dmd.backend.dvec; |
| 30 | + |
| 31 | +extern (C++): |
| 32 | + |
| 33 | + |
| 34 | +/*************************************** |
| 35 | + * Bit masks for various optimizations. |
| 36 | + */ |
| 37 | + |
| 38 | +alias mftype = uint; /* a type big enough for all the flags */ |
| 39 | +enum |
| 40 | +{ |
| 41 | + MFdc = 1, // dead code |
| 42 | + MFda = 2, // dead assignments |
| 43 | + MFdv = 4, // dead variables |
| 44 | + MFreg = 8, // register variables |
| 45 | + MFcse = 0x10, // global common subexpressions |
| 46 | + MFvbe = 0x20, // very busy expressions |
| 47 | + MFtime = 0x40, // favor time (speed) over space |
| 48 | + MFli = 0x80, // loop invariants |
| 49 | + MFliv = 0x100, // loop induction variables |
| 50 | + MFcp = 0x200, // copy propagation |
| 51 | + MFcnp = 0x400, // constant propagation |
| 52 | + MFloop = 0x800, // loop till no more changes |
| 53 | + MFtree = 0x1000, // optelem (tree optimization) |
| 54 | + MFlocal = 0x2000, // localize expressions |
| 55 | + MFall = 0xFFFF, // do everything |
| 56 | +} |
| 57 | + |
| 58 | +/********************************** |
| 59 | + * Definition elem vector, used for reaching definitions. |
| 60 | + */ |
| 61 | + |
| 62 | +struct DefNode |
| 63 | +{ |
| 64 | + elem *DNelem; // pointer to definition elem |
| 65 | + block *DNblock; // pointer to block that the elem is in |
| 66 | + vec_t DNunambig; // vector of unambiguous definitions |
| 67 | +} |
| 68 | + |
| 69 | +/* Global Variables */ |
| 70 | +//extern __gshared uint[] optab; |
| 71 | + |
| 72 | +/* Global Optimizer variables |
| 73 | + */ |
| 74 | +struct GlobalOptimizer |
| 75 | +{ |
| 76 | + mftype mfoptim; |
| 77 | + uint changes; // # of optimizations performed |
| 78 | + |
| 79 | + DefNode *defnod; // array of definition elems |
| 80 | + uint deftop; // # of entries in defnod[] |
| 81 | + uint defmax; // capacity of defnod[] |
| 82 | + uint unambigtop; // number of unambiguous defininitions ( <= deftop ) |
| 83 | + |
| 84 | + vec_base_t *dnunambig; // pool to allocate DNunambig vectors from |
| 85 | + uint dnunambigmax; // capacity of dnunambig[] |
| 86 | + |
| 87 | + elem **expnod; // array of expression elems |
| 88 | + uint exptop; // top of expnod[] |
| 89 | + block **expblk; // parallel array of block pointers |
| 90 | + |
| 91 | + vec_t defkill; // vector of AEs killed by an ambiguous definition |
| 92 | + vec_t starkill; // vector of AEs killed by a definition of something that somebody could be |
| 93 | + // pointing to |
| 94 | + vec_t vptrkill; // vector of AEs killed by an access |
| 95 | +} |
| 96 | + |
| 97 | +extern __gshared GlobalOptimizer go; |
| 98 | + |
| 99 | +/* gdag.c */ |
| 100 | +void builddags(); |
| 101 | +void boolopt(); |
| 102 | +void opt_arraybounds(); |
| 103 | + |
| 104 | +/* gflow.c */ |
| 105 | +void flowrd(); |
| 106 | +void flowlv(); |
| 107 | +void flowae(); |
| 108 | +void flowvbe(); |
| 109 | +void flowcp(); |
| 110 | +void flowae(); |
| 111 | +void genkillae(); |
| 112 | +void flowarraybounds(); |
| 113 | +int ae_field_affect(elem *lvalue,elem *e); |
| 114 | + |
| 115 | +/* glocal.c */ |
| 116 | +void localize(); |
| 117 | + |
| 118 | +/* gloop.c */ |
| 119 | +int blockinit(); |
| 120 | +void compdom(); |
| 121 | +void loopopt(); |
| 122 | +void fillInDNunambig(vec_t v, elem *e); |
| 123 | +void updaterd(elem *n,vec_t GEN,vec_t KILL); |
| 124 | + |
| 125 | +/* gother.c */ |
| 126 | +void rd_arraybounds(); |
| 127 | +void rd_free(); |
| 128 | +void constprop(); |
| 129 | +void copyprop(); |
| 130 | +void rmdeadass(); |
| 131 | +void elimass(elem *); |
| 132 | +void deadvar(); |
| 133 | +void verybusyexp(); |
| 134 | +list_t listrds(vec_t, elem *, vec_t); |
| 135 | + |
| 136 | +/* gslice.c */ |
| 137 | +void sliceStructs(); |
| 138 | + |
0 commit comments