LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_jit.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 32 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             : /* author M.Kersten
      10             :  * This optimizer can be used for JIT optimization and moves
      11             :  * candidate lists into MAL operations where possible.
      12             :  * It should be ran after the candidates optimizer.
      13             :  * Specific snippets to be replaced
      14             :  *       C_1:bat[:oid] := sql.tid(X_0,"sys","t");
      15             :  *       X_4:bat[:int] := sql.bind(X_0,"sys","t","i",0);
      16             :  *       X_13 := algebra.projection(C_1,X_4);
      17             :  * projection can be avoided
      18             :  *
      19             :  * A candidate list can be pushed into the calculations
      20             :  */
      21             : #include "monetdb_config.h"
      22             : #include "mal_builder.h"
      23             : #include "opt_jit.h"
      24             : 
      25             : str
      26           0 : OPTjitImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      27             : {
      28             :         int i, actions = 0;
      29           0 :         int limit = mb->stop, slimit = mb->ssize;
      30           0 :         InstrPtr p, q, *old = mb->stmt;
      31             :         str msg = MAL_SUCCEED;
      32             : 
      33             :         (void) stk;
      34             :         (void) cntxt;
      35             : 
      36           0 :         setVariableScope(mb);
      37           0 :         if ( newMalBlkStmt(mb, mb->ssize) < 0)
      38           0 :                 throw(MAL,"optimizer.jit", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      39             : 
      40             :         /* peephole optimization */
      41           0 :         for (i = 0; i < limit; i++) {
      42           0 :                 p = old[i];
      43             : 
      44           0 :                 if (p->token == ENDsymbol){
      45           0 :                         for(; i<limit; i++)
      46           0 :                                 if (old[i])
      47           0 :                                         pushInstruction(mb,old[i]);
      48             :                         break;
      49             :                 }
      50             :                 /* case 1
      51             :                  * X_527 := algebra.projection(C_353, X_329);
      52             :                  * X_535 := batcalc.-(100:lng, X_527);
      53             :                  */
      54           0 :                 if( getModuleId(p) == batcalcRef && *getFunctionId(p) == '-' && p->argc == 3 && isVarConstant(mb, getArg(p,1)) ){
      55           0 :                         q= getInstrPtr(mb, getVar(mb,getArg(p,2))->updated);
      56           0 :                         if ( q == 0)
      57           0 :                                 q= getInstrPtr(mb, getVar(mb,getArg(p,2))->declared);
      58           0 :                         if( q && getArg(q,0) == getArg(p,2) && getModuleId(q) == algebraRef && getFunctionId(q) == projectionRef ){
      59           0 :                                 getArg(p,2)=  getArg(q,2);
      60           0 :                                 p= addArgument(mb, p, getArg(q,1));
      61           0 :                                 actions++;
      62             :                         }
      63             :                 }
      64           0 :                 pushInstruction(mb,p);
      65             :         }
      66           0 :         for(; i< slimit; i++)
      67           0 :                 if( old[i])
      68           0 :                         pushInstruction(mb, old[i]);
      69             : 
      70           0 :         GDKfree(old);
      71             :         /* Defense line against incorrect plans */
      72           0 :         msg = chkTypes(cntxt->usermodule, mb, FALSE);
      73           0 :         if (!msg)
      74           0 :                 msg = chkFlow(mb);
      75           0 :         if (!msg)
      76           0 :                 msg = chkDeclarations(mb);
      77             :         /* keep actions taken as a fake argument*/
      78           0 :         (void) pushInt(mb, pci, actions);
      79           0 :         return msg;
      80             : }

Generated by: LCOV version 1.14