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

Reply via email to