Ahmad Nouralizadeh Khorrami via llvm-dev
2018-Nov-11 13:38 UTC
[llvm-dev] Convert Register Names to String
Hi. I want to do a cutomized points-to analysis on IR. Suppose that we have: *%91 = bitcast i8* %90 to %struct.demux_packet*, !dbg !2688* I want to store sth similar to %91 -> target of %90, which records the target of pointer named %91. How can I access the names (Here, %90 and %91)? I know that I can put the whole line for an instruction into a string, using the following code: *string str;* *llvm::raw_string_ostream ss(str);* *inst->print(ss);* But a postprocessing will be needed. I need to parse for parameters which will not be easy in the general case. I appreciate any help. Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181111/b4b2e6ea/attachment.html>
Tim Northover via llvm-dev
2018-Nov-12 09:39 UTC
[llvm-dev] Convert Register Names to String
Hi Ahmad, On Sun, 11 Nov 2018 at 13:39, Ahmad Nouralizadeh Khorrami via llvm-dev <llvm-dev at lists.llvm.org> wrote:> I want to do a cutomized points-to analysis on IR. Suppose that we have: > %91 = bitcast i8* %90 to %struct.demux_packet*, !dbg !2688 > > I want to store sth similar to %91 -> target of %90, which records the target of pointer named %91. How can I access the names (Here, %90 and %91)?Unfortunately it's not trivial. You can see the logic used in AssemblyWriter::printInstruction (in lib/IR/AsmWriter.cpp). It boils down to using Instruction::getName if it exists, otherwise there's a special class called ModuleSlotTracker (the "Machine" instance in that function) that gives each unnamed value a number. You'd have to create one of those yourself; I had a quick look at the header and it actually seems pretty easy to use, which was a pleasant surprise. Cheers. Tim.
Ahmad Nouralizadeh Khorrami via llvm-dev
2018-Nov-12 12:25 UTC
[llvm-dev] Convert Register Names to String
Hi Tim, Thanks for the nice answer. The code that you mentioned, seems to generate the IR. You mean I should reuse the code to extract and output the register names in a file. Next, I should postprocess the file in my own pass? Regards. On Mon, 12 Nov 2018 at 13:09, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Ahmad, > > On Sun, 11 Nov 2018 at 13:39, Ahmad Nouralizadeh Khorrami via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > I want to do a cutomized points-to analysis on IR. Suppose that we have: > > %91 = bitcast i8* %90 to %struct.demux_packet*, !dbg !2688 > > > > I want to store sth similar to %91 -> target of %90, which records the > target of pointer named %91. How can I access the names (Here, %90 and %91)? > > Unfortunately it's not trivial. You can see the logic used in > AssemblyWriter::printInstruction (in lib/IR/AsmWriter.cpp). > > It boils down to using Instruction::getName if it exists, otherwise > there's a special class called ModuleSlotTracker (the "Machine" > instance in that function) that gives each unnamed value a number. > You'd have to create one of those yourself; I had a quick look at the > header and it actually seems pretty easy to use, which was a pleasant > surprise. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181112/e44dfc8c/attachment.html>