<div dir="ltr"><div>Hi Pietro,</div><div><br></div><div>have a look at the Scheduler unit in llvm-mca (<a href="http://llvm.org/doxygen/Scheduler_8h_source.html">http://llvm.org/doxygen/Scheduler_8h_source.html</a>).</div><div>That's where the issue logic is.</div></div><div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 15 Dec 2020 at 09:05, Pietro D'Ettole <<a href="mailto:progettoiotpolimi2019@gmail.com" target="_blank">progettoiotpolimi2019@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thanks for your detailed response, Andrea! It was exactly what I was looking for.<div><br><div>Do you have any idea of where in llvm-mca instructions get issued? Because I now have to block some kind of instructions as part of my resource strategy.</div><div><br></div><div>Have a nice day!</div></div></div></blockquote><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div dir="auto"></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno dom 13 dic 2020 alle ore 17:02 Andrea Di Biagio <<a href="mailto:andrea.dibiagio@gmail.com" target="_blank">andrea.dibiagio@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi Pietro,</div><div><br></div><div>
llvm-mca internally assigns each processor resource unit to a 64-bit mask value often referred to as `processor resource mask`.<br>This convertion allows llvm-mca to speedup some set operations in the ResourceManager using simple bit manipulation.<br><font color="#000000"><font face="arial, sans-serif"><span style="white-space:pre-wrap"></span></font></font></div><div><br>
</div><div>If I remember correctly, the setCustomStrategy works on processor resource masks. So you need a way to map processor resource ID to mask values.<br>If you want to know how processor resource units are mapped to processor resource masks, then you need to use function 
`computeProcResourceMasks` (defined in llvm/MCA/Support.cpp).<br><br>```</div><div><div>void computeProcResourceMasks(const MCSchedModel &SM,                                                                                                                                                     MutableArrayRef<uint64_t> Masks)<br>```<br></div><div><br></div><div>Array Masks is populated with processor mask values (one per each processor resource unit declared by the scheduling model).<br></div><div><br></div><div>You can visualise the mapping between resource IDs and resource masks using a debug build of llvm-mca by simply passing flag `-debug-only=llvm-mca`. Flag -debug` would work too. However `-debug` is much more verbose as it doesn't filter out disassembler debug prints.<br><br></div><div>Example of processor masks computed by `
computeProcResourceMasks

` for -mcpu=btver2:<br><br></div><div>Command: ` llvm-mca -debug-only=llvm-mca -mcpu=btver2 `<br><br></div><div>```</div><div>Processor resource masks:<br>[ 0]  - 0x00000000000000 - InvalidUnit<br>[ 1]  - 0x00000000000001 - JALU0<br>[ 2]  - 0x00000000000002 - JALU1<br>[ 3]  - 0x00000000004003 - JALU01<br>[ 4]  - 0x00000000000004 - JDiv<br>[ 5]  - 0x00000000000008 - JFPA<br>[ 6]  - 0x00000000000010 - JFPM<br>[ 7]  - 0x00000000000020 - JFPU0<br>[ 8]  - 0x00000000000040 - JFPU1<br>[ 9]  - 0x00000000008060 - JFPU01<br>[10]  - 0x00000000010018 - JFPX<br>[11]  - 0x00000000000080 - JLAGU<br>[12]  - 0x00000000020280 - JLSAGU<br>[13]  - 0x00000000000100 - JMul<br>[14]  - 0x00000000000200 - JSAGU
<br>[15]  - 0x00000000000400 - JSTC<br>[16]  - 0x00000000041800 - JVALU<br>[17]  - 0x00000000000800 - JVALU0<br>[18]  - 0x00000000001000 - JVALU1<br>[19]  - 0x00000000002000 - JVIMUL<br>```</div><div><br></div><div>Here, each entry is a tuple { 
ProcResourceIdx - Mask - 
ProcResourceName }.<br></div><div><br>A simple lookup of that array is enough to obtain the mask values for your custom strategies.<br><br></div><div>I hope this helps.</div><div>-Andrea<br></div><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 13, 2020 at 2:28 PM Pietro D'Ettole via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi everyone,<div><br></div><div>I need to retrieve the ID of a particular ProcResource from the processor SchedModel but I'm having problems with it.</div><div>In detail, I aim to attach a custom strategy to a particular resource and to do so I thought to use the<font color="#000000"><font face="arial, sans-serif"> <span style="white-space:pre-wrap">ResourceManager::</span><span style="white-space:pre-wrap">setCustomStrategy() method.</span></font></font></div><div><font color="#000000"><font face="arial, sans-serif"><span style="white-space:pre-wrap">I've already got to define my CustomStrategy but I can't retrieve the right ResourceID.</span></font></font></div><div><font color="#000000"><font face="arial, sans-serif"><span style="white-space:pre-wrap">I've thought to use the MCProcResourceDesc table inside MCSchedModel, but I'm not sure it'll work.</span></font></font></div><div><font color="#000000"><font face="arial, sans-serif"><span style="white-space:pre-wrap"><br></span></font></font></div><div><font color="#000000"><font face="arial, sans-serif"><span style="white-space:pre-wrap">Is that a good idea? Do you have in mind a better one?</span></font></font></div><div><font color="#000000"><font face="arial, sans-serif"><span style="white-space:pre-wrap"><br></span></font></font></div><div><font color="#000000"><font face="arial, sans-serif"><span style="white-space:pre-wrap">Thanks!</span></font></font></div><div dir="ltr"></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>