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]
Other format: [Raw text]

RE: Dependency check between instructions?


Hi,

The example code kept crashing because it lacks some context
initialized.  Thus I have to call sched_init/sched_finish pair even I
don't need to run scheduler at all.  This makes me a little
uncomfortable. IMHO, the depedennce analysis should be seperated from
scheduler itself.

  struct sched_info tmp_sched_info;
  current_sched_info = &tmp_sched_info;
  tmp_sched_info.flags = 0;
  sched_init();
  
  /* My own pass */
                                
  sched_finish();

In my pass, I wrote the following code to analyze the dependence between
insn1 and insn2. I feel uncomfortable to directly call
sched_analyze_insn as suggested by Maxim since it is declared as static
function and not supposed to be called externally. And I have to add
init_deps_global call, otherwise, the compiler crashes. 


   init_deps_global ();
   init_deps (&tmp_deps);

   /* Analyze all dependencies between insn1 and insn2.  */
   sched_analyze(&tmp_deps, insn1, insn2);

   /* Remove dependencies from con.  */
   finish_deps_global ();
   free_deps (&tmp_deps);

Is there any better way for dependency analysis?

Cheers,
Bingfeng Mei 
Broadcom UK


-----Original Message-----
From: Maxim Kuvyrkov [mailto:maxim@codesourcery.com] 
Sent: 07 November 2007 14:36
To: Bingfeng Mei
Cc: gcc@gcc.gnu.org
Subject: Re: Dependency check between instructions?

Bingfeng Mei wrote:
> Hello, 
> I am wondering whether there is a simple function/interface in GCC to
> check whether one instruction is dependent on the other (direct and
> indirect). It would be very useful for my target-specific optimizing
> passes, and I could not find in the GCC internal manual and GCC source
> code. Thanks in advance.

IMHO, your best shot is sched-deps.c - infrastructure to calculate 
instruction dependencies for scheduling pass.

Though there is no a user friendly interface to that infrastructure, 
it's not that difficult to write one.

sched-deps.c gathers information about processed instructions into 
dependence context (struct deps) as it analyzes instruction stream one 
insn at a time.
Basically it
1. analyzes the insn
2. creates dependencies for it upon previously analyzed insns
3. and adds information about insn to the context (so that next insn 
will receive proper dependencies too)

A sample function that check if two insns are dependent may look like
this:

bool
insns_dep_p (rtx pro, rtx con)
{
   struct deps _deps, *deps = &_deps;
   bool res;

   /* Initialize context.  */
   init_deps (deps);

   /* Add information about producer to the context.  */
   sched_analyze_insn (deps, pro);

   /* Create dependencies between pro and con.  */
   sched_analyze_insn (deps, con);

   /* Check if con has at least one dep.  */
   res = (get_lists_size (con, ALL_DEPS) != 0);

   /* Remove dependencies from con.  */
   remove_all_deps (con);

   return res;
}

It is not necessary to actually create any dependencies, for an example 
of using sched-deps.c to analyze dependencies between instructions (and 
their LHS and RHS) without creating dependency graph, see sched-deps.c 
in sel-sched-branch.

--
Maxim



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