[llvm-dev] Why is printing an Instruction so slow?

Sean Silva via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 5 15:31:48 PDT 2015


On Mon, Oct 5, 2015 at 9:36 AM, Reid Kleckner via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Instruction printing is usually slow because it uses SlotNumbering, which
> is a whole function analysis to determine what numbers to use for unnamed
> values.
>
> If printing is part of your critical path, you can use
> 'Value::print(raw_ostream&, ModuleSlotTracker&)' instead of operator<<. I
> believe it will help you do the analysis once and print many instructions.
>

It is still linear in the number of types in the module. (I recently tried
to reduce llvm-diff's O((module size)^2) complexity by using
ModuleSlotTracker but it still was quadratic even when using
moduleslottracker)

-- Sean Silva


>
> On Mon, Oct 5, 2015 at 8:17 AM, Stephen Thomas via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Hi all,
>>
>> When writing my custom passes, I often emit log messages to llvm::errs()
>> like so:
>>
>> llvm::errs() << "Could not handle instruction: " << *Inst << std::endl;
>>
>> where Inst is a pointer to an Instruction.
>>
>> I've profiled my code and found that this way of printing an Instruction
>> takes a very long time: indeed, it is the bottleneck of my pass.
>>
>> Of course, I could always switch these log messages off for production
>> runs, but during development and debugging, I'd like to have them on to
>> make debugging much easier.
>>
>> Is there a faster way to print an Instruction?
>>
>> Thanks,
>> Steve
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151005/e235038b/attachment-0001.html>


More information about the llvm-dev mailing list