LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_inline.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 32 32 100.0 %
Date: 2021-10-13 02:24:04 Functions: 3 3 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             : #include "monetdb_config.h"
      10             : #include "opt_inline.h"
      11             : 
      12             : static bool
      13         263 : isCorrectInline(MalBlkPtr mb){
      14             :         /* make sure we have a simple inline function with a singe return */
      15             :         InstrPtr p;
      16             :         int i, retseen=0;
      17             : 
      18       12733 :         for( i= 1; i < mb->stop; i++){
      19       12470 :                 p= getInstrPtr(mb,i);
      20       12470 :                 if ( p->token == RETURNsymbol || p->token == YIELDsymbol ||
      21       12470 :                          p->barrier == RETURNsymbol || p->barrier == YIELDsymbol)
      22         261 :                         retseen++;
      23             :         }
      24         263 :         return retseen <= 1;
      25             : }
      26             : 
      27             : 
      28             : static bool
      29      139651 : OPTinlineMultiplex(MalBlkPtr mb, InstrPtr p)
      30             : {
      31             :         Symbol s;
      32             :         str mod,fcn;
      33             : 
      34      139651 :         mod = VALget(&getVar(mb, getArg(p, p->retc+0))->value);
      35      139651 :         fcn = VALget(&getVar(mb, getArg(p, p->retc+1))->value);
      36      139651 :         if ((s = findSymbolInModule(getModule(putName(mod)), putName(fcn))) == 0)
      37             :                 return false;
      38      139634 :         return s->def->inlineProp;
      39             : }
      40             : 
      41             : 
      42             : str
      43      356725 : OPTinlineImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      44             : {
      45             :         int i;
      46             :         InstrPtr q, sig;
      47             :         int actions = 0;
      48             :         str msg = MAL_SUCCEED;
      49             : 
      50             :         (void)stk;
      51             : 
      52    22492171 :         for (i = 1; i < mb->stop; i++) {
      53    22135448 :                 q = getInstrPtr(mb, i);
      54    22135448 :                 if( q->blk ){
      55    19440516 :                         sig = getInstrPtr(q->blk,0);
      56             :                         /*
      57             :                          * Time for inlining functions that are used in multiplex operations.
      58             :                          * They are produced by SQL compiler.
      59             :                          */
      60    19440516 :                         if (isMultiplex(q)) {
      61      139651 :                                  OPTinlineMultiplex(mb,q);
      62             :                         } else
      63             :                         /*
      64             :                          * Check if the function definition is tagged as being inlined.
      65             :                          */
      66    19300863 :                         if (sig->token == FUNCTIONsymbol && q->blk->inlineProp &&
      67         263 :                                 isCorrectInline(q->blk) ) {
      68         263 :                                 (void) inlineMALblock(mb,i,q->blk);
      69         263 :                                 i--;
      70         263 :                                 actions++;
      71             :                         }
      72             :                 }
      73             :         }
      74             : 
      75             :         //mnstr_printf(cntxt->fdout,"inline limit %d ssize %d vtop %d vsize %d\n", mb->stop, (int)(mb->ssize), mb->vtop, (int)(mb->vsize));
      76             :         /* Defense line against incorrect plans */
      77      356723 :         if( actions > 0){
      78         217 :                 msg = chkTypes(cntxt->usermodule, mb, FALSE);
      79         217 :                 if (!msg)
      80         217 :                         msg = chkFlow(mb);
      81         217 :                 if (!msg)
      82         217 :                         msg = chkDeclarations(mb);
      83             :         }
      84             :         /* keep actions taken as a fake argument*/
      85      356723 :         (void) pushInt(mb, pci, actions);
      86      356724 :         return msg;
      87             : }

Generated by: LCOV version 1.14