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