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 nothrow: 36 @safe: 37 38 /*************************************** 39 * Bit masks for various optimizations. 40 */ 41 42 alias mftype = uint; /* a type big enough for all the flags */ 43 enum 44 { 45 MFdc = 1, // dead code 46 MFda = 2, // dead assignments 47 MFdv = 4, // dead variables 48 MFreg = 8, // register variables 49 MFcse = 0x10, // global common subexpressions 50 MFvbe = 0x20, // very busy expressions 51 MFtime = 0x40, // favor time (speed) over space 52 MFli = 0x80, // loop invariants 53 MFliv = 0x100, // loop induction variables 54 MFcp = 0x200, // copy propagation 55 MFcnp = 0x400, // constant propagation 56 MFloop = 0x800, // loop till no more changes 57 MFtree = 0x1000, // optelem (tree optimization) 58 MFlocal = 0x2000, // localize expressions 59 MFall = 0xFFFF, // do everything 60 } 61 62 /********************************** 63 * Definition elem vector, used for reaching definitions. 64 */ 65 66 struct DefNode 67 { 68 elem *DNelem; // pointer to definition elem 69 block *DNblock; // pointer to block that the elem is in 70 vec_t DNunambig; // vector of unambiguous definitions 71 } 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 public import dmd.backend.var : go; 96 public import dmd.backend.gdag : builddags, boolopt; 97 public import dmd.backend.gflow : flowrd, flowlv, flowvbe, flowcp, flowae, genkillae; 98 public import dmd.backend.glocal : localize; 99 public import dmd.backend.gloop : blockinit, compdom, loopopt, updaterd; 100 public import dmd.backend.gother : constprop, copyprop, rmdeadass, elimass, deadvar, verybusyexp, listrds; 101 public import dmd.backend.gsroa : sliceStructs;