LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_matpack.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 46 91.3 %
Date: 2021-10-13 02:24:04 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * This simple module unrolls the mat.pack into an incremental sequence.
      11             :  * This could speedup parallel processing and releases resources faster.
      12             :  */
      13             : #include "monetdb_config.h"
      14             : #include "opt_matpack.h"
      15             : 
      16             : str
      17      353093 : OPTmatpackImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      18             : {
      19             :         int v, i, j, limit, slimit;
      20             :         InstrPtr p,q;
      21             :         int actions = 0;
      22             :         InstrPtr *old = NULL;
      23             :         str msg = MAL_SUCCEED;
      24             : 
      25      353093 :         if( isOptimizerUsed(mb, pci, mergetableRef) <= 0){
      26           0 :                 goto wrapup;
      27             :         }
      28             : 
      29             :         (void) cntxt;
      30             :         (void) stk;             /* to fool compilers */
      31    16628586 :         for( i = 1; i < mb->stop; i++)
      32    16312602 :                 if( getModuleId(getInstrPtr(mb,i)) == matRef  && getFunctionId(getInstrPtr(mb,i)) == packRef && isaBatType(getArgType(mb,getInstrPtr(mb,i),1)))
      33             :                         break;
      34      353093 :         if( i == mb->stop)
      35      315984 :                 goto wrapup;
      36             : 
      37       37109 :         old= mb->stmt;
      38             :         limit= mb->stop;
      39       37109 :         slimit = mb->ssize;
      40       37109 :         if ( newMalBlkStmt(mb,mb->stop) < 0)
      41           0 :                 throw(MAL,"optimizer.matpack", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      42             : 
      43     7978975 :         for (i = 0; i < limit; i++) {
      44     7941866 :                 p = old[i];
      45     7941866 :                 if( getModuleId(p) == matRef  && getFunctionId(p) == packRef && isaBatType(getArgType(mb,p,1))) {
      46      242536 :                         q = newInstruction(0, matRef, packIncrementRef);
      47      242536 :                         setDestVar(q, newTmpVariable(mb, getArgType(mb,p,1)));\
      48      242536 :                         q = addArgument(mb, q, getArg(p,1));
      49      242536 :                         v = getArg(q,0);
      50      242536 :                         q = pushInt(mb,q, p->argc - p->retc);
      51      242536 :                         pushInstruction(mb,q);
      52      242536 :                         typeChecker(cntxt->usermodule,mb,q, mb->stop-1, TRUE);
      53             : 
      54      975588 :                         for ( j = 2; j < p->argc; j++) {
      55      733052 :                                 q = newInstruction(0, matRef, packIncrementRef);
      56      733052 :                                 q = addArgument(mb, q, v);
      57      733052 :                                 q = addArgument(mb, q, getArg(p,j));
      58      733052 :                                 setDestVar(q, newTmpVariable(mb, getVarType(mb,v)));
      59             :                                 v = getArg(q,0);
      60      733052 :                                 pushInstruction(mb,q);
      61      733052 :                                 typeChecker(cntxt->usermodule,mb,q, mb->stop-1, TRUE);
      62             :                         }
      63      242536 :                         getArg(q,0) = getArg(p,0);
      64      242536 :                         freeInstruction(p);
      65      242536 :                         actions++;
      66      242536 :                         continue;
      67             :                 }
      68     7699330 :                 pushInstruction(mb,p);
      69             :         }
      70    18745867 :         for(; i<slimit; i++)
      71    18708758 :                 if (old[i])
      72           0 :                         pushInstruction(mb, old[i]);
      73       37109 :         GDKfree(old);
      74             : 
      75             :         /* Defense line against incorrect plans */
      76       37109 :         if( actions > 0){
      77       37109 :                 msg = chkTypes(cntxt->usermodule, mb, FALSE);
      78       37109 :                 if (!msg)
      79       37109 :                         msg = chkFlow(mb);
      80       37109 :                 if (!msg)
      81       37109 :                         msg = chkDeclarations(mb);
      82             :         }
      83           0 : wrapup:
      84             :         /* keep actions taken as a fake argument*/
      85      353093 :         (void) pushInt(mb, pci, actions);
      86      353093 :         return msg;
      87             : }

Generated by: LCOV version 1.14