[LLVMdev] Filename in dynamically loaded function pass
Frits van Bommel
fvbommel at gmail.com
Thu Jul 7 05:32:30 PDT 2011
On 7 July 2011 02:27, Kodakara, Sreekumar V
<sreekumar.v.kodakara at intel.com> wrote:
> 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?
There's Module::getModuleIdentifier(), 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
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
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.
: Doxygen: http://llvm.org/doxygen/classllvm_1_1Module.html#a339f163decf5f2c881937600d1e953fa
More information about the llvm-dev