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 66377 : OPTminimalfastImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
59 : InstrPtr pci)
60 : {
61 66377 : str msg = MAL_SUCCEED;
62 66377 : int generator = 0, multiplex = 0, actions = 0;
63 :
64 : /* perform a single scan through the plan to determine which optimizer steps to skip */
65 1422595 : for (int i = 0; i < mb->stop; i++) {
66 1356218 : InstrPtr q = getInstrPtr(mb, i);
67 1356218 : if (getModuleId(q) == generatorRef)
68 0 : generator = 1;
69 1356218 : if (getFunctionId(q) == multiplexRef)
70 0 : multiplex = 1;
71 : }
72 :
73 66377 : optcall(true, OPTinlineImplementation);
74 66555 : optcall(true, OPTremapImplementation);
75 67240 : optcall(true, OPTemptybindImplementation);
76 67272 : optcall(true, OPTdeadcodeImplementation);
77 67180 : optcall(true, OPTforImplementation);
78 67327 : optcall(true, OPTdictImplementation);
79 67285 : optcall(multiplex, OPTmultiplexImplementation);
80 67278 : optcall(generator, OPTgeneratorImplementation);
81 67290 : optcall(profilerStatus, OPTprofilerImplementation);
82 67277 : optcall(profilerStatus, OPTcandidatesImplementation);
83 67277 : optcall(true, OPTgarbageCollectorImplementation);
84 :
85 : /* Defense line against incorrect plans handled by optimizer steps */
86 : /* keep actions taken as a fake argument */
87 66982 : bailout:
88 66982 : (void) pushInt(mb, pci, actions);
89 67173 : return msg;
90 : }
91 :
92 : str
93 31930 : OPTdefaultfastImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
94 : InstrPtr pci)
95 : {
96 31930 : str msg = MAL_SUCCEED;
97 31930 : int generator = 0, multiplex = 0, actions = 0;
98 :
99 : /* perform a single scan through the plan to determine which optimizer steps to skip */
100 1025156 : for (int i = 0; i < mb->stop; i++) {
101 993226 : InstrPtr q = getInstrPtr(mb, i);
102 993226 : if (getModuleId(q) == generatorRef)
103 0 : generator = 1;
104 993226 : if (getFunctionId(q) == multiplexRef)
105 0 : multiplex = 1;
106 : }
107 :
108 31930 : optcall(true, OPTinlineImplementation);
109 31939 : optcall(true, OPTremapImplementation);
110 31984 : optcall(true, OPTcostModelImplementation);
111 31987 : optcall(true, OPTcoercionImplementation);
112 31987 : optcall(true, OPTaliasesImplementation);
113 31983 : optcall(true, OPTevaluateImplementation);
114 31990 : optcall(true, OPTemptybindImplementation);
115 31977 : optcall(true, OPTdeadcodeImplementation);
116 31985 : optcall(true, OPTpushselectImplementation);
117 31973 : optcall(true, OPTaliasesImplementation);
118 31988 : optcall(true, OPTforImplementation);
119 31997 : optcall(true, OPTdictImplementation);
120 31994 : optcall(true, OPTmitosisImplementation);
121 31982 : optcall(true, OPTmergetableImplementation);
122 31982 : optcall(true, OPTaliasesImplementation);
123 31995 : optcall(true, OPTconstantsImplementation);
124 31993 : optcall(true, OPTcommonTermsImplementation);
125 31990 : optcall(true, OPTprojectionpathImplementation);
126 31989 : optcall(true, OPTdeadcodeImplementation);
127 31993 : optcall(true, OPTreorderImplementation);
128 31993 : optcall(true, OPTmatpackImplementation);
129 31996 : optcall(true, OPTdataflowImplementation);
130 31972 : optcall(true, OPTquerylogImplementation);
131 31986 : optcall(multiplex, OPTmultiplexImplementation);
132 31980 : optcall(generator, OPTgeneratorImplementation);
133 31972 : optcall(profilerStatus, OPTprofilerImplementation);
134 31972 : optcall(profilerStatus, OPTcandidatesImplementation);
135 31972 : optcall(true, OPTdeadcodeImplementation);
136 31983 : optcall(true, OPTpostfixImplementation);
137 31980 : optcall(true, OPTgarbageCollectorImplementation);
138 :
139 : /* Defense line against incorrect plans handled by optimizer steps */
140 : /* keep actions taken as a fake argument */
141 31972 : bailout:
142 31972 : (void) pushInt(mb, pci, actions);
143 31958 : return msg;
144 : }
|