LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_matpack.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 56 70 80.0 %
Date: 2024-12-20 21:24:02 Functions: 1 1 100.0 %

          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             : /*
      14             :  * This simple module unrolls the mat.pack into an incremental sequence.
      15             :  * This could speedup parallel processing and releases resources faster.
      16             :  */
      17             : #include "monetdb_config.h"
      18             : #include "opt_matpack.h"
      19             : 
      20             : str
      21      499064 : OPTmatpackImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
      22             :                                                  InstrPtr pci)
      23             : {
      24      499064 :         int v, i, j, limit, slimit;
      25      499064 :         InstrPtr p, q;
      26      499064 :         int actions = 0;
      27      499064 :         InstrPtr *old = NULL;
      28      499064 :         str msg = MAL_SUCCEED;
      29             : 
      30      499064 :         if (isOptimizerUsed(mb, pci, mergetableRef) <= 0) {
      31       31953 :                 goto wrapup;
      32             :         }
      33             : 
      34             :         (void) cntxt;
      35             :         (void) stk;                                     /* to fool compilers */
      36    22519008 :         for (i = 1; i < mb->stop; i++)
      37    22082980 :                 if (getModuleId(getInstrPtr(mb, i)) == matRef
      38       46570 :                         && getFunctionId(getInstrPtr(mb, i)) == packRef
      39       33498 :                         && isaBatType(getArgType(mb, getInstrPtr(mb, i), 1)))
      40             :                         break;
      41      467160 :         if (i == mb->stop)
      42      436028 :                 goto wrapup;
      43             : 
      44       31132 :         old = mb->stmt;
      45       31132 :         limit = mb->stop;
      46       31132 :         slimit = mb->ssize;
      47       31132 :         if (newMalBlkStmt(mb, mb->stop) < 0)
      48           0 :                 throw(MAL, "optimizer.matpack", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      49             : 
      50     8934256 :         for (i = 0; mb->errors == NULL && i < limit; i++) {
      51     8903124 :                 p = old[i];
      52     8903124 :                 if (getModuleId(p) == matRef && getFunctionId(p) == packRef
      53      160479 :                         && isaBatType(getArgType(mb, p, 1))) {
      54      158351 :                         q = newInstruction(0, matRef, packIncrementRef);
      55      158351 :                         if (q == NULL) {
      56           0 :                                 msg = createException(MAL, "optimizer.matpack",
      57             :                                                                           SQLSTATE(HY013) MAL_MALLOC_FAIL);
      58           0 :                                 break;
      59             :                         }
      60      158351 :                         if (setDestVar(q, newTmpVariable(mb, getArgType(mb, p, 1))) < 0) {
      61           0 :                                 freeInstruction(q);
      62           0 :                                 msg = createException(MAL, "optimizer.matpack",
      63             :                                                                           SQLSTATE(HY013) MAL_MALLOC_FAIL);
      64           0 :                                 break;
      65             :                         }
      66      158351 :                         q = pushArgument(mb, q, getArg(p, 1));
      67      158351 :                         v = getArg(q, 0);
      68      158351 :                         q = pushInt(mb, q, p->argc - p->retc);
      69      158351 :                         pushInstruction(mb, q);
      70      158351 :                         typeChecker(cntxt->usermodule, mb, q, mb->stop - 1, TRUE);
      71             : 
      72     1377236 :                         for (j = 2; j < p->argc; j++) {
      73     1060534 :                                 q = newInstruction(0, matRef, packIncrementRef);
      74     1060534 :                                 if (q == NULL) {
      75           0 :                                         msg = createException(MAL, "optimizer.matpack",
      76             :                                                                                   SQLSTATE(HY013) MAL_MALLOC_FAIL);
      77           0 :                                         break;
      78             :                                 }
      79     1060534 :                                 q = pushArgument(mb, q, v);
      80     1060534 :                                 q = pushArgument(mb, q, getArg(p, j));
      81     1060534 :                                 if (setDestVar(q, newTmpVariable(mb, getVarType(mb, v))) < 0) {
      82           0 :                                         freeInstruction(q);
      83           0 :                                         msg = createException(MAL, "optimizer.matpack",
      84             :                                                                                   SQLSTATE(HY013) MAL_MALLOC_FAIL);
      85           0 :                                         break;
      86             :                                 }
      87     1060534 :                                 v = getArg(q, 0);
      88     1060534 :                                 pushInstruction(mb, q);
      89     1060534 :                                 typeChecker(cntxt->usermodule, mb, q, mb->stop - 1, TRUE);
      90             :                         }
      91           0 :                         if (msg)
      92             :                                 break;
      93      158351 :                         getArg(q, 0) = getArg(p, 0);
      94      158351 :                         freeInstruction(p);
      95      158351 :                         actions++;
      96      158351 :                         continue;
      97             :                 }
      98     8744773 :                 pushInstruction(mb, p);
      99     8744773 :                 old[i] = NULL;
     100             :         }
     101    23432648 :         for (; i < slimit; i++)
     102    23401516 :                 if (old[i])
     103           0 :                         pushInstruction(mb, old[i]);
     104       31132 :         GDKfree(old);
     105             : 
     106             :         /* Defense line against incorrect plans */
     107       31132 :         if (msg == MAL_SUCCEED && actions > 0) {
     108       31132 :                 msg = chkTypes(cntxt->usermodule, mb, FALSE);
     109       31132 :                 if (!msg)
     110       31132 :                         msg = chkFlow(mb);
     111       31132 :                 if (!msg)
     112       31132 :                         msg = chkDeclarations(mb);
     113             :         }
     114           0 :   wrapup:
     115             :         /* keep actions taken as a fake argument */
     116      499113 :         (void) pushInt(mb, pci, actions);
     117      499113 :         return msg;
     118             : }

Generated by: LCOV version 1.14