This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: prefetch revisited


Hi,
I've digged out one copy of my prefetch.c file.  It should be basically working,
but no guarantees.

It is definitly stupid.  I will try to do some tweaking overnight.

Honza
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.530
diff -c -3 -p -r1.530 toplev.c
*** toplev.c	2001/10/29 11:45:45	1.530
--- toplev.c	2001/10/30 19:36:15
*************** rest_of_compilation (decl)
*** 3271,3276 ****
--- 3271,3277 ----
  
        flow_loops_free (&loops);
      }
+   emit_recursive_prefetch_insns ();
    life_analysis (insns, rtl_dump_file, PROP_FINAL);
    timevar_pop (TV_FLOW);
  
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/Makefile.in,v
retrieving revision 1.760
diff -c -3 -p -r1.760 Makefile.in
*** Makefile.in	2001/10/29 14:34:18	1.760
--- Makefile.in	2001/10/30 19:36:15
*************** OBJS = alias.o bb-reorder.o bitmap.o bui
*** 748,754 ****
   sbitmap.o sched-deps.o sched-ebb.o sched-rgn.o sched-vis.o sdbout.o	\
   sibcall.o simplify-rtx.o splay-tree.o ssa.o ssa-ccp.o ssa-dce.o stmt.o	\
   stor-layout.o stringpool.o timevar.o toplev.o tree.o tree-inline.o 	\
!  unroll.o varasm.o varray.o version.o xcoffout.o			\
   $(GGC) $(out_object_file) $(EXTRA_OBJS)
  
  BACKEND = main.o libbackend.a
--- 748,754 ----
   sbitmap.o sched-deps.o sched-ebb.o sched-rgn.o sched-vis.o sdbout.o	\
   sibcall.o simplify-rtx.o splay-tree.o ssa.o ssa-ccp.o ssa-dce.o stmt.o	\
   stor-layout.o stringpool.o timevar.o toplev.o tree.o tree-inline.o 	\
!  unroll.o varasm.o varray.o version.o xcoffout.o prefetch.o		\
   $(GGC) $(out_object_file) $(EXTRA_OBJS)
  
  BACKEND = main.o libbackend.a
*************** ssa-ccp.o : ssa-ccp.c $(CONFIG_H) system
*** 1483,1488 ****
--- 1483,1490 ----
      $(BASIC_BLOCK_H) ssa.h insn-config.h $(RECOG_H) output.h \
      errors.h $(GGC_H) df.h function.h
  df.o : df.c $(CONFIG_H) system.h $(RTL_H) insn-config.h $(RECOG_H) \
+    function.h $(REGS_H) $(OBSTACK_H) hard-reg-set.h $(BASIC_BLOCK_H) df.h
+ prefetch.o : prefetch.c $(CONFIG_H) system.h $(RTL_H) insn-config.h $(RECOG_H) \
     function.h $(REGS_H) $(OBSTACK_H) hard-reg-set.h $(BASIC_BLOCK_H) df.h
  conflict.o : conflict.c $(CONFIG_H) $(SYSTEM_H) $(OBSTACK_H) $(HASHTAB_H) \
     $(RTL_H) hard-reg-set.h $(BASIC_BLOCK_H)
#include "config.h"
#include "system.h"
#include "rtl.h" 
#include "insn-config.h" 
#include "recog.h" 
#include "function.h" 
#include "regs.h" 
#include "obstack.h" 
#include "hard-reg-set.h"
#include "basic-block.h"
#include "bitmap.h"
#include "df.h"
#include "output.h"
#include "expr.h"

static int find_memref PARAMS ((rtx *xp, void *data));
static void process_ref PARAMS ((struct ref *ref));

struct find_memref_data
{
  rtx reg;
  int offset;
};
static int
find_memref (xp, data)
  rtx *xp;
  void *data;
{
  struct find_memref_data *d = (struct find_memref_data *)data;
  if (GET_CODE (*xp) == MEM
      && XEXP (*xp, 0) == d->reg)
    {
     d->offset = 0;
     return 1;
    }
  if (GET_CODE (*xp) == MEM
      && GET_CODE (XEXP (*xp, 0)) == PLUS
      && XEXP (XEXP (*xp, 0), 0) == d->reg)
    {
      rtx op = XEXP (XEXP (*xp, 0), 1);
 
      if (GET_CODE (op) == CONST_INT)
	d->offset = INTVAL (op);
      else
	d->offset = 0;
      return 1;
    }
  return 0;
}
static void
process_ref (ref)
	struct ref *ref;
{
  bitmap offsets = BITMAP_XMALLOC ();
  struct df_link *link;
  struct find_memref_data d;
  int o;

  d.reg = DF_REF_REG (ref);
  for (link = DF_REF_CHAIN (ref); link; link = link->next)
    {
      rtx insn = DF_REF_INSN (link->ref);

      if (BLOCK_FOR_INSN (insn)
	  == BLOCK_FOR_INSN (DF_REF_INSN (ref)))
	continue;

      if (!for_each_rtx (&PATTERN (insn), find_memref, (void *)&d))
	continue;

      if (rtl_dump_file)
	fprintf (rtl_dump_file, "  Found memref in insn %i offset %i\n",
		 INSN_UID (insn), d.offset);
 
      bitmap_set_bit (offsets, d.offset / 64);
    }

  EXECUTE_IF_SET_IN_BITMAP (offsets, 0, o,
    emit_insn_after (gen_prefetch (gen_rtx_PLUS (Pmode, DF_REF_REG (ref),
			    			 GEN_INT (o * 64)),
				   const0_rtx),
	    	     ref->insn));
  BITMAP_XFREE (offsets);
}
void
emit_recursive_prefetch_insns ()
{
  rtx set;
  struct df *df;
  rtx insn;
 
  df = df_init ();
  df_analyse (df, 0, DF_ALL);
  if (rtl_dump_file)
    df_dump (df, DF_DU_CHAIN, rtl_dump_file);

  for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
    if (INSN_P (insn)
	&& (set = single_set (insn)) != NULL
	&& GET_CODE (SET_SRC (set)) == MEM
	&& GET_CODE (SET_DEST (set)) == REG)
    {
      struct df_link *link = DF_INSN_DEFS (df, insn);

      if (rtl_dump_file)
	fprintf (rtl_dump_file, "Checking load in insn %i\n", INSN_UID (insn));

      while (DF_REF_REG (link->ref) != SET_DEST (set))
	link = link->next;
      process_ref (link->ref);
    }

  df_finish (df);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]