Kodakara, Sreekumar V
2011-Jul-07 00:27 UTC
[LLVMdev] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110706/53632a4f/attachment.html>
Frits van Bommel
2011-Jul-07 12:32 UTC
[LLVMdev] Filename in dynamically loaded function pass
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()[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
Kodakara, Sreekumar V
2011-Jul-07 15:41 UTC
[LLVMdev] Filename in dynamically loaded function pass
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()[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
Possibly Parallel Threads
- [LLVMdev] Filename in dynamically loaded function pass
- [LLVMdev] llc is taking a long time at -O1 to convert *.bc to *.s
- [LLVMdev] Accessing the name of the temporary variable in Instruction
- [LLVMdev] Accessing the name of the temporary variable in Instruction
- [LLVMdev] Break operands into multiple instructions