scc_xsb.c

00001 /* File:      scc_xsb.c
00002 ** Author(s): Kostis Sagonas
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** 
00007 ** XSB is free software; you can redistribute it and/or modify it under the
00008 ** terms of the GNU Library General Public License as published by the Free
00009 ** Software Foundation; either version 2 of the License, or (at your option)
00010 ** any later version.
00011 ** 
00012 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00013 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00015 ** more details.
00016 ** 
00017 ** You should have received a copy of the GNU Library General Public License
00018 ** along with XSB; if not, write to the Free Software Foundation,
00019 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 **
00021 ** $Id: scc_xsb.c,v 1.7 2005/01/14 18:31:28 ruim Exp $
00022 ** 
00023 */
00024 
00025 
00026 #include "xsb_config.h"
00027 #include "xsb_debug.h"
00028 
00029 #include <stdio.h>
00030 
00031 #include "auxlry.h"
00032 #include "cell_xsb.h"
00033 #include "register.h"
00034 #include "psc_xsb.h"
00035 #include "tries.h"
00036 #include "macro_xsb.h"
00037 #include "context.h"
00038 #include "scc_xsb.h"
00039 
00040 #if (!defined(LOCAL_EVAL))
00041 
00042 /*----------------------------------------------------------------------*/
00043 /*----------------------------------------------------------------------*/
00044 
00045 /* Documentation added 02/02 TLS.
00046 
00047 What does this do?  Well, it wants to break up the ASCC into SCCs.  It
00048 doesnt quite do this exactly, rather it constructs a series of n DFS
00049 visits of the DGT of the ASCC starting with the leader.  Thus, the n
00050 SCCs that constitute the ASCC are traversed, and for each SCC_n, max_u
00051 is set to the oldest subgoal in SCC_n.  The idea is that after all
00052 SCCs are checked, max_u is set to the oldest subgoal in an independant
00053 SCC.
00054 
00055 While there could be several independent SCCs, only the last
00056 independent SCC to be checked will be accessible 
00057 
00058 Also, suppose there are 2 independent SCCs, SCC_1 and SCC_2.  Also
00059 suppose SCC_1 has no loop through negation, but that SCC_2 does.  In
00060 this case Delaying may be prescribed for the ASCC because SCC_2 is
00061 acessible, but SCC_1 is not.  
00062 
00063 The algorithm could be modified by marking compl_visited with a ptr to
00064 the oldest subgoal of the SCC.  In this case, if the first returned
00065 SCC had a loop through negation, the second could be checked, and so
00066 on until an SCC that had no loop through negation was obtained.  
00067 
00068 In addition, such a change would obviate the need for the
00069 find_independent_scc called in wfs_xsb.i
00070 
00071 */
00072 
00073 /* Note that this function does not need to check whether a given
00074    subgoal is completed -- that has already been checked by
00075    add_ascc_edges() in construct_dep_graph() */
00076 
00077 static void DFS_DGT_visit(ComplStackFrame u)
00078 {
00079     EPtr eptr;
00080 
00081     compl_visited(u) = TRUE;
00082     for (eptr=compl_DGT_edges(u); eptr != NULL; eptr=next_edge(eptr)) {
00083       if (!compl_visited(edge_to_node(eptr)))
00084         DFS_DGT_visit(edge_to_node(eptr));
00085     }
00086 }
00087 
00088 ComplStackFrame DFS_DGT(CTXTdeclc ComplStackFrame leader)
00089 {
00090     ComplStackFrame u, max_u = NULL;
00091 
00092     for (u = leader; u >= (ComplStackFrame)openreg; u--)
00093       if (!compl_visited(u)) {
00094         DFS_DGT_visit(u); max_u = u;
00095       }
00096     return max_u;
00097 }
00098 
00099 /*----------------------------------------------------------------------*/
00100 /*  find_independent_scc(ComplStackFrame)                               */
00101 /*      Finds the subgoals in the same SCC as the subgoal that is       */
00102 /*      given as input.  The subgoals are indicated by marking the      */
00103 /*      "visited" field of their completion stack frame.                */
00104 /*----------------------------------------------------------------------*/
00105 
00106 void find_independent_scc(ComplStackFrame u)
00107 {
00108     EPtr eptr;
00109 
00110     compl_visited(u) = TRUE;
00111     for (eptr=compl_DG_edges(u); eptr != NULL; eptr=next_edge(eptr)) {
00112       if (!compl_visited(edge_to_node(eptr)))
00113         find_independent_scc(edge_to_node(eptr));
00114     }
00115 }
00116 
00117 /*----------------------------------------------------------------------*/
00118 
00119 #endif

Generated on Wed Jul 26 13:30:42 2006 for XSB by  doxygen 1.4.5