Problem with MemoryDependenceAnalysis

Dear all,

I am having a problem adding a MemoryDependenceAnalysis pass to a Module Pass i created, it gives me the following error when i add (Info.addRequired<MemoryDependenceAnalysis>():wink: it in the getAnalysisUsage(AnalysisUsage &Info) function.

adding callgraph pass ... done
opt: /net/home/yehia/llvm/llvm-2.4/include/llvm/Target/TargetData.h:114: llvm::TargetData::TargetData(): Assertion `0 && "ERROR: Bad TargetData ctor used. " "Tool did not specify a TargetData to use?"' failed.
adding DependenceFlowGraph_FunctionAnalaysis_Pass ... doneopt[0x75627f]
/lib64/libc.so.6[0x3880a30070]
/lib64/libc.so.6(gsignal+0x35)[0x3880a30015]
/lib64/libc.so.6(abort+0x110)[0x3880a31980]
/lib64/libc.so.6(__assert_fail+0xf6)[0x3880a29726]
opt[0x6709bd]
opt(_ZN4llvm17PMTopLevelManager12schedulePassEPNS_4PassE+0x125)[0x6efa75]
opt(_ZN4llvm17PMTopLevelManager12schedulePassEPNS_4PassE+0x190)[0x6efae0]
opt(_ZN4llvm13MPPassManager25addLowerLevelRequiredPassEPNS_4PassES2_+0xcc)[0x6f1dfc]
opt(_ZN4llvm13PMDataManager3addEPNS_4PassEb+0x2a7)[0x6f4237]
opt(main+0x348)[0x485ac8]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x3880a1d8a4]
opt(sinh+0x39)[0x47b1f9]

i tried a work around by creating another function pass and adding the MemoryDependenceAnalysis pass to it (i didn't try to get the analysis). it doesn't give errors if i only call the function pass i created alone, but if i add this function pass to the module pass it gives the same error.

so here is a brief:
adding MemoryDependenceAnalysis to a module pass -> fail
adding MemoryDependenceAnalysis to function pass -> success
adding a function pass that contains MemoryDependenceAnalysis to a module pass -> fail
adding the same function pass without containing MemoryDependenceAnalysis to the module pass -> success

Dear all,

I am having a problem adding a MemoryDependenceAnalysis pass to a Module
Pass i created, it gives me the following error when i add
(Info.addRequired<MemoryDependenceAnalysis>():wink: it in the
getAnalysisUsage(AnalysisUsage &Info) function.

If MemoryDependenceAnalysis requires any module level analysis then it won't work.

adding callgraph pass ... done
opt: /net/home/yehia/llvm/llvm-2.4/include/llvm/Target/TargetData.h:114:
llvm::TargetData::TargetData(): Assertion `0 && "ERROR: Bad TargetData
ctor used. " "Tool did not specify a TargetData to use?"' failed.

Can you send entire list of passes you're using on 'opt' command line?

Devang Patel wrote:

Dear all,

I am having a problem adding a MemoryDependenceAnalysis pass to a Module
Pass i created, it gives me the following error when i add
(Info.addRequired<MemoryDependenceAnalysis>():wink: it in the
getAnalysisUsage(AnalysisUsage &Info) function.

If MemoryDependenceAnalysis requires any module level analysis then it won't work.
  
Does that mean i can't call it from a Module pass?

adding callgraph pass ... done
opt: /net/home/yehia/llvm/llvm-2.4/include/llvm/Target/TargetData.h: 114:
llvm::TargetData::TargetData(): Assertion `0 && "ERROR: Bad TargetData
ctor used. " "Tool did not specify a TargetData to use?"' failed.
    
Can you send entire list of passes you're using on 'opt' command line?
  

I am loading the CallGraph pass before it from my module
Info.addRequired<CallGraph>();
Info.addPreserved<CallGraph>();
and from opt i tried first to call my module only and then tried to call -memdep before calling my module, but both gave the same errors
opt $OPT_OPTIONS -load ${LLVM_PATH}/Release/lib/.libs/libDFGMODULEPASS.so -DFGModulePass < $2.bc
and
opt $OPT_OPTIONS -load ${LLVM_PATH}/Release/lib/.libs/libDFGMODULEPASS.so -memdep -DFGModulePass < $2.bc

by the way ... i found another mail addressing the same problem as i have in the mailing list archive but i couldn't find a reply
the message was sent by jeffhao on Thu, 26 Feb 2009 17:39:32 -0500

thank you.

Aha, so you're actually invoking function pass from a CG pass. See if my suggestion from
  http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-February/020109.html
helps.

no .. i am calling a function pass from a module pass, adding other function passes to my module pass works, but when i try to add MemoryDependenceAnalysis it gives error

I want to report a bug but i don't know if this is a real bug or i am doing something wrong, knowing that i am adding other function passe to my module pass and it works fine.

the error i get:

adding callgraph pass ... done
opt: /net/home/yehia/llvm/llvm-2.4/include/llvm/Target/TargetData.h:114: llvm::TargetData::TargetData(): Assertion `0 && "ERROR: Bad TargetData ctor used. " "Tool did not specify a TargetData to use?"' failed.
adding DependenceFlowGraph_FunctionAnalaysis_Pass ... doneopt[0x75627f]
/lib64/libc.so.6[0x3880a30070]
/lib64/libc.so.6(gsignal+0x35)[0x3880a30015]
/lib64/libc.so.6(abort+0x110)[0x3880a31980]
/lib64/libc.so.6(__assert_fail+0xf6)[0x3880a29726]
opt[0x6709bd]
opt(_ZN4llvm17PMTopLevelManager12schedulePassEPNS_4PassE+0x125)[0x6efa75]
opt(_ZN4llvm17PMTopLevelManager12schedulePassEPNS_4PassE+0x190)[0x6efae0]
opt(_ZN4llvm13MPPassManager25addLowerLevelRequiredPassEPNS_4PassES2_+0xcc)[0x6f1dfc]
opt(_ZN4llvm13PMDataManager3addEPNS_4PassEb+0x2a7)[0x6f4237]
opt(main+0x348)[0x485ac8]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x3880a1d8a4]
opt(sinh+0x39)[0x47b1f9]

Devang Patel wrote:

Amr Yehia wrote:

no .. i am calling a function pass from a module pass, adding other function passes to my module pass works, but when i try to add MemoryDependenceAnalysis it gives error
  

I'm going to assume that you're running your passes via a specially built tool and not as a set of passes loaded into the opt program. If this assumption is wrong, please let me know.

Looking at the assertion, you're creating a TargetData pass without passing in either a string describing the target or an LLVM Module * from which TargetData can look up the relevant architecture information.

For example, in the hand-written SAFECode tool, the following code should cause the same error:

PassManager Passes;
Passes.add (new TargetData());
...
Passes.run (*M.get());

However, the following will fix the problem:

PassManager Passes;
std::auto_ptr<Module> M;
.... <code that reads an LLVM Module into M from a bitcode file>...
Passes.add (new TargetData (M.get()));
...
Passes.run (*M.get());

The comments for the constructors in llvm/include/llvm/Target/TargetData.h will help clarify this.

-- John T.

actually i only created a new Module pass and tried to getAnalysis of MemoryDependenceAnalysis from it, i didn't use TargetData directly

to regenerate the error i am attaching a c file containing an example code to regenerate the error. with its Makefile
the command line i used is:
opt -time-passes -analyze -load ${LLVM_PATH}/Release/lib/.libs/libMYMODULEPASS.so -MyModulePass < test.bc

i tried the same but from a function pass and it worked.

John Criswell wrote:

Makefile (390 Bytes)

regenerateMDAError.cpp (604 Bytes)

Amr Yehia wrote:

actually i only created a new Module pass and tried to getAnalysis of
MemoryDependenceAnalysis from it, i didn't use TargetData directly
  

Interesting. The opt tool creates a TargetData pass correctly, but the
PassManager is trying to create a new TargetData pass anyway.

You might be able to work around the problem by writing your own tool
that creates a TargetData pass explictly and then adds it to the
PassManger. You can use the pa tool from the Pool Allocation project
(code attached) as a template.

The fact that your pass doesn't work when loaded through opt appears to
be a bug to me. It seems that the PassManger is not finding the already
"run" TargetData pass and is trying to create a new one with the default
constructor (which hits the assertion). Without investigating further,
I'd recommend filing a bug report.

-- John T.

pa.cpp (5.09 KB)