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 : /*
14 : * Mark the production and use of candidate lists.
15 : */
16 :
17 : #include "monetdb_config.h"
18 : #include "mal_instruction.h"
19 : #include "opt_candidates.h"
20 :
21 : str
22 508844 : OPTcandidatesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
23 : {
24 508844 : InstrPtr p;
25 508844 : str msg = MAL_SUCCEED;
26 :
27 508844 : if (!(ATOMIC_GET(&GDKdebug) & TESTINGMASK))
28 2032 : goto wrapup;
29 : (void) cntxt;
30 : (void) stk; /* to fool compilers */
31 30966361 : for (int i = 0; i < mb->stop; i++) {
32 30459549 : p = getInstrPtr(mb, i);
33 30459549 : if (p->token == ASSIGNsymbol) {
34 148767 : for (int j = 0; j < p->retc && j + p->retc < p->argc; j++)
35 9564 : if (isVarCList(mb, getArg(p, p->retc + j)))
36 47 : setVarCList(mb, getArg(p, j));
37 : }
38 30459549 : if (getModuleId(p) == sqlRef) {
39 3499106 : if (getFunctionId(p) == tidRef)
40 308655 : setVarCList(mb, getArg(p, 0));
41 3190451 : else if (getFunctionId(p) == subdeltaRef)
42 91661 : setVarCList(mb, getArg(p, 0));
43 26960443 : } else if (getModuleId(p) == algebraRef) {
44 4241176 : if (getFunctionId(p) == selectRef
45 4103328 : || getFunctionId(p) == thetaselectRef)
46 655193 : setVarCList(mb, getArg(p, 0));
47 3585983 : else if (getFunctionId(p) == likeselectRef)
48 13289 : setVarCList(mb, getArg(p, 0));
49 3572694 : else if (getFunctionId(p) == intersectRef
50 3563032 : || getFunctionId(p) == differenceRef)
51 170317 : setVarCList(mb, getArg(p, 0));
52 3402377 : else if (getFunctionId(p) == uniqueRef)
53 74 : setVarCList(mb, getArg(p, 0));
54 3402303 : else if (getFunctionId(p) == firstnRef)
55 1651 : setVarCList(mb, getArg(p, 0));
56 3400652 : else if (getFunctionId(p) == subsliceRef)
57 1300 : setVarCList(mb, getArg(p, 0));
58 3399352 : else if (getFunctionId(p) == projectionRef
59 1944874 : && isVarCList(mb, getArg(p, p->retc + 0))
60 1151200 : && isVarCList(mb, getArg(p, p->retc + 1)))
61 225920 : setVarCList(mb, getArg(p, 0));
62 22719267 : } else if (getModuleId(p) == generatorRef) {
63 475 : if (getFunctionId(p) == selectRef
64 475 : || getFunctionId(p) == thetaselectRef)
65 29 : setVarCList(mb, getArg(p, 0));
66 22718792 : } else if (getModuleId(p) == sampleRef) {
67 21 : if (getFunctionId(p) == subuniformRef)
68 21 : setVarCList(mb, getArg(p, 0));
69 22718771 : } else if (getModuleId(p) == groupRef && p->retc > 1) {
70 90195 : if (getFunctionId(p) == subgroupRef
71 84766 : || getFunctionId(p) == subgroupdoneRef
72 63631 : || getFunctionId(p) == groupRef
73 42677 : || getFunctionId(p) == groupdoneRef)
74 90195 : setVarCList(mb, getArg(p, 1));
75 22628576 : } else if (getModuleId(p) == batRef) {
76 915421 : if (getFunctionId(p) == mergecandRef
77 802067 : || getFunctionId(p) == intersectcandRef
78 802067 : || getFunctionId(p) == diffcandRef
79 802067 : || getFunctionId(p) == mirrorRef)
80 234267 : setVarCList(mb, getArg(p, 0));
81 : }
82 : }
83 :
84 : /* Defense line against incorrect plans */
85 : /* plan remains unaffected */
86 : // msg = chkTypes(cntxt->usermodule, mb, FALSE);
87 : // if( ms== MAL_SUCCEED)
88 : // msg = chkFlow(mb);
89 : // if( ms== MAL_SUCCEED)
90 : // msg = chkDeclarations(mb);
91 : /* keep actions taken as a fake argument */
92 506812 : wrapup:
93 508844 : (void) pushInt(mb, pci, 1);
94 508844 : return msg;
95 : }
|