<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hello.<br>
<br>
I am developing a proprietary back end based on LLVM for my employer. As part of debbuging it I use the -debug command line option , and  sometimes insert debug prints such as<br>
<br>
DEBUG( dbgs() << ....)<br>
<br>
which print some intermediate LLVM Values.  <br>
<br>
I have noticed that running with those prints is EXTEREMLY slow, so I decide to take a look at<br>
it and see what the reason is.<br>
<br>
Well using a debugger the problem was obvious, and it appears in lib/IR/AsmWriter.cpp:<br>
<br>
The code of the function Value::print for example has this:<br>
<br>
 
<table class="highlight tab-size-8 js-file-line-container">
<tbody>
<tr>
<td id="LC3117" class="blob-code js-file-line"><span class="pl-k">if</span> (<span class="pl-s">const</span> Instruction *I = dyn_cast<Instruction>(<span class="pl-v">this</span>)) {</td>
</tr>
<tr>
<td id="LC3118" class="blob-code js-file-line">   <span class="pl-s">const</span> Function *F = I-><span class="pl-s3">getParent</span>() ? I-><span class="pl-s3">getParent</span>()-><span class="pl-s3">getParent</span>() :
<span class="pl-v">nullptr</span>;</td>
</tr>
<tr>
<td id="LC3119" class="blob-code js-file-line">   SlotTracker <span class="pl-vo">
SlotTable</span>(F);</td>
</tr>
<tr>
<td id="LC3120" class="blob-code js-file-line">   AssemblyWriter <span class="pl-vo">
W</span>(OS, SlotTable, <span class="pl-s3">getModuleFromVal</span>(I), <span class="pl-v">
nullptr</span>);</td>
</tr>
<tr>
<td id="LC3121" class="blob-code js-file-line">   W.<span class="pl-s3">printInstruction</span>(*I);<br>
}<br>
<br>
<br>
And similar other cases.<br>
The problem is that the    SlotTracker  and AssemblyWriter objects which are<br>
created every time for every Value involves very heavy initialization.<br>
<br>
It can be circumvented quite easily by inserting internal "Caching" of  static<br>
variables for those objects, so that initialization is done automaticaly only in<br>
case the Module or Function was changed since last usage ...<br>
<br>
I did it localy in my tree and it improved performance to reasonable levels, but I work with a dated version of LLVM, so humbly suggest that maybe some of the maintainers of this code do  the same ...
<br>
<br>
<br>
</td>
</tr>
</tbody>
</table>
</div>
<br><br>
This mail was sent via Mail-SeCure system.<br>
<br><br>
 <br> <br>************************************************************************************<br>This footnote confirms that this email message has been scanned by<br>PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses.<br>************************************************************************************<br><br>
</body>
</html>