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