Pass Ordering

All,

I have a ModulePass (A) calling a FunctionPass that inturn calls TargetData (a ModulePass). For reasons of code correctness and modularity I cannot reorganize my passes in any other way .

When I use opt to load and run A , it gives the following error.

LLVM ERROR: Bad TargetData ctor used. Tool did not specify a TargetData to use?

I gather from some previous emails that this was not supported. Is it still not supported? and is there any way I can avoid this.

Thanks and Regards

Aparna Kotha

Graduate Student
University of Maryland, College Park

aparna kotha wrote:

All,

I have a ModulePass (A) calling a FunctionPass that inturn calls TargetData (a ModulePass). For reasons of code correctness and modularity I cannot reorganize my passes in any other way .

When I use opt to load and run A , it gives the following error.

LLVM ERROR: Bad TargetData ctor used. Tool did not specify a TargetData to use?

I gather from some previous emails that this was not supported. Is it still not supported? and is there any way I can avoid this.

For some reason, the TargetData pass must use a special constructor method that gives it a reference to the module to be analyzed. This means that declaring it as a dependency in your getAnalysisUsage() methods isn't enough; whatever program is adding your passes to the PassManager must add TargetData explicitly as one of the passes to run.

The opt program does this automatically, so I'm assuming you're writing your own tool that creates a PassManager and tells it to run some passes. You want to add code like the following to your tool:

PassManager Passes; // This line probably exists in your code already

// Explicitly schedule the TargetData pass as the first pass to run; note that M.get() gets a pointer or reference
// to the module to analyze
Passes.add(new TargetData(M.get()));

-- John T.

I am using opt , so i cm confused if i need to do this. On the other hand I modified my functionPass not to call TargetData , and I still get this error. My functionPass still calls Alias Analysis though.

Aparna

aparna kotha wrote:

I am using opt , so i cm confused if i need to do this. On the other hand I modified my functionPass not to call TargetData , and I still get this error. My functionPass still calls Alias Analysis though.

You're correct; you shouldn't need to do that in opt, so I'm confused as to why it didn't work before.

In your function pass with the use of TargetData removed, what does your getAnalysisUsage() method look like? Did you remove the getAnalysis<TargetData>() call in the other methods of your function pass? Both must be removed for your FunctionPass to be totally free of TargetData.

Did you remove TargetData from you ModulePass as well?

-- John T.