LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_aliases.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 38 94.7 %
Date: 2021-10-13 02:24:04 Functions: 2 2 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 "mal_instruction.h"
      11             : #include "opt_aliases.h"
      12             : 
      13             : /* an alias is recognized by a simple assignment */
      14             : #define OPTisAlias(X) (X->argc == 2 && X->token == ASSIGNsymbol && X->barrier == 0 )
      15             : 
      16             : void
      17    22499864 : OPTaliasRemap(InstrPtr p, int *alias){
      18             :         int i;
      19    82164268 :         for(i=0; i<p->argc; i++)
      20    59664404 :                 getArg(p,i) = alias[getArg(p,i)];
      21    22499864 : }
      22             : 
      23             : str
      24     1059288 : OPTaliasesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      25             : {
      26             :         int i,j,k=1, limit, actions=0;
      27             :         int *alias = 0;
      28             :         str msg = MAL_SUCCEED;
      29             :         InstrPtr p;
      30             : 
      31             :         (void) stk;
      32             :         (void) cntxt;
      33             : 
      34     1059288 :         limit = mb->stop;
      35    37650194 :         for (i = 1; i < limit; i++){
      36    36965934 :                 p= getInstrPtr(mb,i);
      37    36965934 :                 if (OPTisAlias(p))
      38             :                         break;
      39             :         }
      40     1059288 :         if( i == limit){
      41             :                 // we didn't found a simple assignment that warrants a rewrite
      42      684260 :                 goto wrapup;
      43             :         }
      44             :         k = i;
      45      375028 :         if( i < limit){
      46      375028 :                 alias= (int*) GDKzalloc(sizeof(int)* mb->vtop);
      47      375028 :                 if (alias == NULL)
      48           0 :                         throw(MAL,"optimizer.aliases", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      49      375028 :                 setVariableScope(mb);
      50    44976871 :                 for(j=1; j<mb->vtop; j++) alias[j]=j;
      51             :         }
      52    25423476 :         for (; i < limit; i++){
      53    25048448 :                 p= getInstrPtr(mb,i);
      54    25048448 :                 mb->stmt[k++] = p;
      55    25048448 :                 if (OPTisAlias(p)){
      56     2551286 :                         if( getLastUpdate(mb,getArg(p,0)) == i  &&
      57     2549717 :                                 getBeginScope(mb,getArg(p,0)) == i  &&
      58     2548802 :                                 getLastUpdate(mb,getArg(p,1)) <= i ){
      59     2548582 :                                 alias[getArg(p,0)]= alias[getArg(p,1)];
      60     2548582 :                                 freeInstruction(p);
      61     2548582 :                                 actions++;
      62             :                                 k--;
      63     2548582 :                                 mb->stmt[k]= 0;
      64             :                         } else
      65        2704 :                                 OPTaliasRemap(p,alias);
      66             :                 } else
      67    22497162 :                         OPTaliasRemap(p,alias);
      68             :         }
      69             : 
      70     2923610 :         for(i=k; i<limit; i++)
      71     2548582 :                 mb->stmt[i]= NULL;
      72             : 
      73      375028 :         mb->stop= k;
      74      375028 :         if( alias)
      75      375028 :                 GDKfree(alias);
      76             : 
      77             :         /* Defense line against incorrect plans */
      78             :         /* Plan is unaffected */
      79             :         // msg = chkTypes(cntxt->usermodule, mb, FALSE);
      80             :         // if ( msg == MAL_SUCCEED)
      81             :         //      msg = chkFlow(mb);
      82             :         // if ( msg == MAL_SUCCEED)
      83             :         //      msg = chkDeclarations(mb);
      84           0 : wrapup:
      85             :         /* keep actions taken as a fake argument*/
      86     1059288 :         (void) pushInt(mb, pci, actions);
      87     1059288 :         return msg;
      88             : }

Generated by: LCOV version 1.14