LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_mask.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 53 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 1 0.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             : /* (c) Martin Kersten
      10             :  * This optimizer injects the MSK operations to reduce footprint
      11             :  */
      12             : #include "monetdb_config.h"
      13             : #include "opt_mask.h"
      14             : 
      15             : str
      16           0 : OPTmaskImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      17             : {
      18             :         int i, j, k, limit, slimit;
      19             :         InstrPtr p=0, q=0, r=0, *old= NULL;
      20             :         int actions = 0;
      21             :         int *varused=0;
      22             :         str msg= MAL_SUCCEED;
      23             : 
      24             :         (void) cntxt;
      25             :         (void) stk;             /* to fool compilers */
      26             : 
      27           0 :         if ( mb->inlineProp )
      28           0 :                 goto wrapup;
      29             : 
      30           0 :         varused = GDKzalloc(2 * mb->vtop * sizeof(int));
      31           0 :         if (varused == NULL)
      32           0 :                 goto wrapup;
      33             : 
      34           0 :         limit = mb->stop;
      35           0 :         slimit = mb->ssize;
      36           0 :         old = mb->stmt;
      37           0 :         if (newMalBlkStmt(mb, mb->ssize) < 0) {
      38           0 :                 GDKfree(varused);
      39           0 :                 throw(MAL,"optimizer.deadcode", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      40             :         }
      41             : 
      42             :         // Consolidate the actual need for variables
      43           0 :         for (i = 0; i < limit; i++) {
      44           0 :                 p = old[i];
      45           0 :                 if( p == 0)
      46           0 :                         continue; //left behind by others?
      47           0 :                 for(j=0; j< p->retc; j++){
      48           0 :                         k =  getArg(p,j);
      49           0 :                         if( isaBatType(getArgType(mb, p,j)) && getBatType(getArgType(mb, p, j)) == TYPE_msk){
      50             :                                 // remember we have encountered a mask producing function
      51           0 :                                 varused[k] = k;
      52             :                         }
      53             :                 }
      54           0 :                 for(j=p->retc; j< p->argc; j++){
      55           0 :                         k =  getArg(p,j);
      56           0 :                         if(varused[k]) {
      57             :                                 // we should actually postpone its reconstruction to JIT
      58           0 :                                 r = newInstruction(mb, maskRef, umaskRef);
      59           0 :                                 getArg(r,0) = k;
      60           0 :                                 r= pushArgument(mb, r, varused[k]);
      61           0 :                                 pushInstruction(mb,r);
      62           0 :                                 varused[k] = 0;
      63             :                         }
      64             :                 }
      65           0 :                 pushInstruction(mb, p);
      66             : 
      67           0 :                 if ( getModuleId(p) == algebraRef && (getFunctionId(p) == selectRef || getFunctionId(p) == thetaselectRef)){
      68           0 :                         k=  getArg(p,0);
      69           0 :                         setDestVar(p, newTmpVariable(mb, newBatType(TYPE_oid)));
      70           0 :                         setVarFixed(mb,getArg(p,0));
      71             : 
      72             :                         // Inject a dummy pair, just based on :oid for now and later to be switched to :msk
      73           0 :                         q = newInstruction(mb, maskRef, maskRef);
      74           0 :                         setDestVar(q, newTmpVariable(mb, newBatType(TYPE_msk)));
      75           0 :                         setVarFixed(mb,getArg(q,0));
      76           0 :                         q= pushArgument(mb, q, getArg(p,0));
      77           0 :                         pushInstruction(mb,q);
      78           0 :                         varused[k] = getArg(q,0);
      79           0 :                         actions++;      
      80             :                 } 
      81             :         }
      82             : 
      83           0 :         for(; i<slimit; i++)
      84           0 :                 if( old[i])
      85           0 :                         pushInstruction(mb, old[i]);
      86             :         /* Defense line against incorrect plans */
      87           0 :         if( actions > 0){
      88           0 :                 msg = chkTypes(cntxt->usermodule, mb, FALSE);
      89           0 :                 if (!msg)
      90           0 :                         msg = chkFlow(mb);
      91           0 :                 if (!msg)
      92           0 :                         msg = chkDeclarations(mb);
      93             :         }
      94             :         /* keep all actions taken as a post block comment */
      95           0 : wrapup:
      96             :         /* keep actions taken as a fake argument*/
      97           0 :         (void) pushInt(mb, pci, actions);
      98             : 
      99           0 :         if(old) GDKfree(old);
     100           0 :         if(varused) GDKfree(varused);
     101             :         return msg;
     102             : }

Generated by: LCOV version 1.14