Line data Source code
1 : /*
2 : * SPDX-License-Identifier: MPL-2.0
3 : *
4 : * This Source Code Form is subject to the terms of the Mozilla Public
5 : * License, v. 2.0. If a copy of the MPL was not distributed with this
6 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 : *
8 : * Copyright 2024, 2025 MonetDB Foundation;
9 : * Copyright August 2008 - 2023 MonetDB B.V.;
10 : * Copyright 1997 - July 2008 CWI.
11 : */
12 :
13 : #include "monetdb_config.h"
14 : #include "opt_fastpath.h"
15 : #include "opt_aliases.h"
16 : #include "opt_coercion.h"
17 : #include "opt_commonTerms.h"
18 : #include "opt_candidates.h"
19 : #include "opt_constants.h"
20 : #include "opt_costModel.h"
21 : #include "opt_dataflow.h"
22 : #include "opt_deadcode.h"
23 : #include "opt_dict.h"
24 : #include "opt_for.h"
25 : #include "opt_emptybind.h"
26 : #include "opt_evaluate.h"
27 : #include "opt_garbageCollector.h"
28 : #include "opt_generator.h"
29 : #include "opt_inline.h"
30 : #include "opt_projectionpath.h"
31 : #include "opt_matpack.h"
32 : #include "opt_postfix.h"
33 : #include "opt_mergetable.h"
34 : #include "opt_mitosis.h"
35 : #include "opt_multiplex.h"
36 : #include "opt_profiler.h"
37 : #include "opt_pushselect.h"
38 : #include "opt_querylog.h"
39 : #include "opt_reduce.h"
40 : #include "opt_remap.h"
41 : #include "opt_remoteQueries.h"
42 : #include "opt_reorder.h"
43 : #include "opt_fastpath.h"
44 : #include "optimizer_private.h"
45 : #include "mal_interpreter.h"
46 :
47 : #define optcall(TEST, OPT) \
48 : do { \
49 : if (TEST) { \
50 : if ((msg = OPT(cntxt, mb, stk, pci)) != MAL_SUCCEED) \
51 : goto bailout; \
52 : actions += *(int*)getVarValue(mb, getArg(pci, pci->argc - 1)); \
53 : delArgument(pci, pci->argc - 1); /* keep number of argc low, so 'pci' is not reallocated */ \
54 : } \
55 : } while (0)
56 :
57 : str
58 67317 : OPTminimalfastImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
59 : InstrPtr pci)
60 : {
61 67317 : str msg = MAL_SUCCEED;
62 67317 : int generator = 0, multiplex = 0, actions = 0;
63 :
64 : /* perform a single scan through the plan to determine which optimizer steps to skip */
65 1444529 : for (int i = 0; i < mb->stop; i++) {
66 1377212 : InstrPtr q = getInstrPtr(mb, i);
67 1377212 : if (getModuleId(q) == generatorRef)
68 0 : generator = 1;
69 1377212 : if (getFunctionId(q) == multiplexRef)
70 0 : multiplex = 1;
71 : }
72 :
73 67317 : optcall(true, OPTinlineImplementation);
74 67312 : optcall(true, OPTremapImplementation);
75 67311 : optcall(true, OPTemptybindImplementation);
76 67309 : optcall(true, OPTdeadcodeImplementation);
77 67316 : optcall(true, OPTforImplementation);
78 67313 : optcall(true, OPTdictImplementation);
79 67317 : optcall(multiplex, OPTmultiplexImplementation);
80 67317 : optcall(generator, OPTgeneratorImplementation);
81 67317 : optcall(profilerStatus, OPTprofilerImplementation);
82 67317 : optcall(profilerStatus, OPTcandidatesImplementation);
83 67317 : optcall(true, OPTgarbageCollectorImplementation);
84 :
85 : /* Defense line against incorrect plans handled by optimizer steps */
86 : /* keep actions taken as a fake argument */
87 67313 : bailout:
88 67313 : (void) pushInt(mb, pci, actions);
89 67313 : return msg;
90 : }
91 :
92 : str
93 32001 : OPTdefaultfastImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
94 : InstrPtr pci)
95 : {
96 32001 : str msg = MAL_SUCCEED;
97 32001 : int generator = 0, multiplex = 0, actions = 0;
98 :
99 : /* perform a single scan through the plan to determine which optimizer steps to skip */
100 1009372 : for (int i = 0; i < mb->stop; i++) {
101 977371 : InstrPtr q = getInstrPtr(mb, i);
102 977371 : if (getModuleId(q) == generatorRef)
103 0 : generator = 1;
104 977371 : if (getFunctionId(q) == multiplexRef)
105 0 : multiplex = 1;
106 : }
107 :
108 32001 : optcall(true, OPTinlineImplementation);
109 32001 : optcall(true, OPTremapImplementation);
110 32000 : optcall(true, OPTcostModelImplementation);
111 32000 : optcall(true, OPTcoercionImplementation);
112 32000 : optcall(true, OPTaliasesImplementation);
113 32001 : optcall(true, OPTevaluateImplementation);
114 32000 : optcall(true, OPTemptybindImplementation);
115 32000 : optcall(true, OPTdeadcodeImplementation);
116 32001 : optcall(true, OPTpushselectImplementation);
117 31997 : optcall(true, OPTaliasesImplementation);
118 31999 : optcall(true, OPTforImplementation);
119 31998 : optcall(true, OPTdictImplementation);
120 32000 : optcall(true, OPTmitosisImplementation);
121 31999 : optcall(true, OPTmergetableImplementation);
122 31999 : optcall(true, OPTaliasesImplementation);
123 32001 : optcall(true, OPTconstantsImplementation);
124 32001 : optcall(true, OPTcommonTermsImplementation);
125 32000 : optcall(true, OPTprojectionpathImplementation);
126 32001 : optcall(true, OPTdeadcodeImplementation);
127 32001 : optcall(true, OPTreorderImplementation);
128 31999 : optcall(true, OPTmatpackImplementation);
129 32001 : optcall(true, OPTdataflowImplementation);
130 32001 : optcall(true, OPTquerylogImplementation);
131 32000 : optcall(multiplex, OPTmultiplexImplementation);
132 32000 : optcall(generator, OPTgeneratorImplementation);
133 32000 : optcall(profilerStatus, OPTprofilerImplementation);
134 32000 : optcall(profilerStatus, OPTcandidatesImplementation);
135 32000 : optcall(true, OPTdeadcodeImplementation);
136 32001 : optcall(true, OPTpostfixImplementation);
137 32000 : optcall(true, OPTgarbageCollectorImplementation);
138 :
139 : /* Defense line against incorrect plans handled by optimizer steps */
140 : /* keep actions taken as a fake argument */
141 31999 : bailout:
142 31999 : (void) pushInt(mb, pci, actions);
143 31998 : return msg;
144 : }
|