<div dir="auto">Maybe I did not state my use case correctly, I apologise for the confusion.<div dir="auto"><br></div><div dir="auto">I have two different use cases -</div><div dir="auto"><br></div><div dir="auto">1. I have a list of function call instructions from which I can get a list of functions, and subsequently print them out instruction by instruction.</div><div dir="auto"><br></div><div dir="auto">2. I have a list of <llvm::Instructions*> directly (obtained by storing each instruction into a vector as it was executed).</div><div dir="auto"><br></div><div dir="auto">For the second case, the number of instructions is well over 10,000. (Even for the first case, going through each Instruction of each function call, the total number of instructions to be printed is huge).</div><div dir="auto"><br></div><div dir="auto">I have 25-30 such traces, so when I try to print out everything it takes a couple of hours (using llvm::Value::print) so textual representation by way of printing using llvm::Value::print is not practical.</div><div dir="auto"><br></div><div dir="auto">Binary dumps would include a lot of handling (since I need to resolve pointers of all objects I want to dump).</div><div dir="auto"><br></div><div dir="auto">In the best case, it would be nice if I could club together the instructions into some container that I can use the `clang -emit-llvm` method on. I am inclined to think this cannot be an llvm::Module because (as I understand) just a list of instructions cannot be clubbed together to create a valid Module.</div><div dir="auto"><br></div><div dir="auto">Does that offer more clarity for my use case (and why I am disinclined to use llvm::Value::print)?</div><div dir="auto"><br></div><div dir="auto">Thanks!</div><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Tue, 21 Jul, 2020, 1:16 am David Blaikie, <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm not sure that LLVM's bitcode format would natively support just a<br>
handful of Instructions, rather than a whole llvm::Module.<br>
<br>
If you really want just a handful of instructions, maybe text is the<br>
way to go - it sounded like you were serializing whole functions, at<br>
least - which could be copied/cloned/moved into a standalone<br>
llvm::Module and serialized from there. If it's only select<br>
instructions, then maybe text is fine? Or maybe you can summarize the<br>
information you want from the call more succinctly than LLVM's textual<br>
representation.<br>
<br>
On Mon, Jul 20, 2020 at 12:00 PM Yugesh Kothari <<a href="mailto:kothariyugesh@gmail.com" target="_blank" rel="noreferrer">kothariyugesh@gmail.com</a>> wrote:<br>
><br>
> Replicating what clang -emit-llvm does sound like the better way to do it.<br>
><br>
> I was looking under IRPrintingPasses but couldn't find anything specific that would allow me to print out say a std::vector<llvm:: Instruction*>.<br>
><br>
> What do you think would be the easiest way to do this? Can I do some hack where I can get away without writing my own llvm pass? I'm not even sure what the right question to ask is, since this is the first time I'm working with llvm.<br>
><br>
> Thanks!<br>
><br>
> On Mon, 20 Jul, 2020, 10:37 pm David Blaikie, <<a href="mailto:dblaikie@gmail.com" target="_blank" rel="noreferrer">dblaikie@gmail.com</a>> wrote:<br>
>><br>
>> if you're trying to serialize LLVM IR and read it back again later -<br>
>> yeah, probably best to use th binary searialization rather than the<br>
>> textual. If I were doing this I'd try building something using clang<br>
>> with -emit-llvm (that'll produce LLVM IR bitcode in the .o file) and<br>
>> debug that to see which APIs are used to do that.<br>
>><br>
>> On Mon, Jul 20, 2020 at 3:19 AM Yugesh Kothari via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a>> wrote:<br>
>> ><br>
>> > Hi,<br>
>> ><br>
>> > I am working on a project where I need to get a list of llvm Functions that were called during an execution (for futher analysis).<br>
>> > To do this I have maintained a vector<llvm:: Function*> which I print out to a .ll file at the end. However this takes a lot of time since the number of call Instructions is HUGE.<br>
>> > I feel that the bottleneck is the conversion from llvm:: Function to std::string<br>
>> ><br>
>> > How can I speed this up?<br>
>> ><br>
>> > I don't necessarily need it in .ll format, if there is a way to dump the entire llvm::Function object as a byte stream to a .dat file and read it back as objects in a separate script, that would work too. I'm not sure how to do this (tried few things didn't work), any help would be appreciated!<br>
>> ><br>
>> > Thanks!<br>
>> ><br>
>> > _______________________________________________<br>
>> > LLVM Developers mailing list<br>
>> > <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" rel="noreferrer">llvm-dev@lists.llvm.org</a><br>
>> > <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>