MemoryDependenceAnalysis

Hello,

I have a code similar to the following:

program test
integer i, j, N
real B(10)

call bar(N, 8)
N = N+1
do i = 1, N
B(i) = (i+5)/(i+3)
enddo

j = N/2
N = N+7

call IMPORTANT_F(B, N, i, j)

end program

and I am trying to use dependence analysis on the second and fourth actual parameters of IMPORTANT_F(). Since it's Fortran, they are really pointers, and the IR of the last block looks like this:

%11 = sdiv i32 %1, 2 ; <i32> [#uses=1]
store i32 %11, i32* %j, align 4
%12 = add i32 %0, 8 ; <i32> [#uses=1]
store i32 %12, i32* %n, align 4
call void (...)* @IMPORTANT_F_([10 x float]* %b, i32* %n, i32* %i, i32* %j) nounwind
ret void

My problem is that if I use getNonLocalPointerDependency() I get the instruction "N=N+1" as a Def for the second parameter, "N", and no Def for the fourth, "j", (only the call to "bar()" as clobber).
If I use getDependency() on the call, I get the instruction "N=N+7" as a clobber.

How can I use MemoryDependenceAnalysis (or any other analysis for that matter) to gather that the instructions
j = N/2 (store i32 %11, i32* %j, align 4)
and
N = N+7 (store i32 %12, i32* %n, align 4)
are the ones that define the parameters "j" and "N" respectively?

thanks,
Anthony

Hello,

I have a code similar to the following:

Hi Anthony,

Can you please attach the .bc file for this?

-Chris

I'm attaching the .bc file. Note that my analysis pass is invoked after "-O1" and that's why the IR I included in the original email is optimized.

simple_loops_F2_4list.bc (6.23 KB)

Try calling MemoryDependenceAnalysis::getDependency? It sounds like
you're misusing getNonLocalPointerDependency.

-Eli

But I'm not interested in the dependencies of the alloca instruction, I'm interested in the definition(s) of the particular use of the pointer.

Anthony

Ah, hmm, it seems like what you really want is
getPointerDependencyFrom... a patch to expose a similar API publicly
might be a good idea.

-Eli

The nonlocal in getNonLocalPointerDependency() means that it does not search the current block.

–Owen

I'm attaching the .bc file. Note that my analysis pass is invoked after "-O1" and that's why the IR I included in the original email is optimized.

Hi Anthony,

Sorry for the delay, things have been crazy lately.

The MemDep API assumes that you will call getDependency() first, and then only call getNonLocalPointerDependency() if it returns non-local. This will return the first instruction that the instruction is dependent on.

As Eli mentioned, MemDep does have some more rich APIs that are private. We could look the export those so that you can query each argument at a time. The problem is that (without more information about language semantics) there is no way to know how much data is accessed off each pointer by the function, nor whether it accesses them through other aliases. For example, "bar" could capture the N pointer, etc.

-Chris

I'm attaching the .bc file. Note that my analysis pass is invoked
after "-O1" and that's why the IR I included in the original email
is optimized.

Hi Anthony,

Sorry for the delay, things have been crazy lately.

The MemDep API assumes that you will call getDependency() first, and
then only call getNonLocalPointerDependency() if it returns non-
local. This will return the first instruction that the instruction is
dependent on.

As Eli mentioned, MemDep does have some more rich APIs that are
private. We could look the export those so that you can query each
argument at a time.

Actually there is no need to export it. I wrote a little ReachingDefinitions pass based on the API from MemDep that gives me the information I want. I should probably send it in, but I'm not sure how to do so. Should I submit it as a patch to the list, or try to commit it in the svn?

Please send it to llvm-commits in patch form, thanks!

-Chris