Filename in dynamically loaded function pass

Hi All,

I would like to know if there is an API/method that I can use to get the name of the file being processed in a dynamically loaded function pass. In other words, if I invoke a pass as follows

opt -load pass.so -hello src.bc –o src.hello.bc

where pass.so is a functionpass, I would like to get the filename “src.bc”, in the doInitialization/doFinalization method. My intent is to use the name to create another filename (say src.info) and store some other information generated by the pass.

Currently I am getting the filename by using the debug info of an instruction in the function (which actually returns the name of the source file, not the bc file being processed, which is fine for my use case). But sometimes, the instruction may refer to code from a system header file and hence will not return the name of the file that’s currently being processed.

Is there a way to get this info?

Thanks

Sreekumar

There's Module::getModuleIdentifier()[1], which *usually* contains the
file name if the module was loaded from a bitcode file on disk. Since
you're writing a function pass, it should be accessible as
'F.getParent()->getModuleIdentifier()'.
This is not always the case, however. For instance, if the module was
read from standard input it instead contains '<stdin>'. And if the
module was just constructed by a compiler in the same process running
your pass it really depends on what that compiler passed to the Module
constructor.

However, if you're using your pass from opt as you've shown (by
specifying the file on the command line) then it should produce the
name of the input bitcode file.

[1]: Doxygen: http://llvm.org/doxygen/classllvm_1_1Module.html#a339f163decf5f2c881937600d1e953fa

There's Module::getModuleIdentifier()[1], which *usually* contains the
file name if the module was loaded from a bitcode file on disk. Since
you're writing a function pass, it should be accessible as
'F.getParent()->getModuleIdentifier()'.
This is not always the case, however. For instance, if the module was
read from standard input it instead contains '<stdin>'. And if the
module was just constructed by a compiler in the same process running
your pass it really depends on what that compiler passed to the Module
constructor.

However, if you're using your pass from opt as you've shown (by
specifying the file on the command line) then it should produce the
name of the input bitcode file.

[1]: Doxygen: http://llvm.org/doxygen/classllvm_1_1Module.html#a339f163decf5f2c881937600d1e953fa

Thanks for the information. I will try this out and I think this will resolve my issue. Thanks again.

Sreekumar