<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119177>119177</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[GlobalISel] Improve the debug-ability of the match tables by adding the index as comment in the table
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:globalisel
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
Pierre-vh
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
qcolombet
</td>
</tr>
</table>
<pre>
When looking at the debug output of GlobalISel for the instruction selection phase, one can see something like:
```
10: GIM_SwitchOpcode(MIs[0], [51, 795), Default=357167, JumpTable...) // Got=51
2997: GIM_SwitchType(MIs[0]->getOperand(0), [2, 24), Default=21984, JumpTable...) // Got=s32
3086: Begin try-block
3093: GIM_CheckType(MIs[0]->getOperand(1), TypeID=2)
3096: GIM_CheckType(MIs[0]->getOperand(2), TypeID=2)
```
The number on the left are indices in the match table produced by the TableGen backend.
However, these numbers are not printed as comment in the `.inc` file making it difficult to exactly follow which entry of the table is being executed (you have a proxy information with the `@` comment, but those are sparse.)
The goal of this issue is to improve the debug-ability of the match table by adding the index of the table on each line.
E.g., go from
```
const uint8_t *AArch64InstructionSelector::getMatchTable() const {
constexpr static uint8_t MatchTable0[] = {
GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(51), GIMT_Encode2(795), /*)*//*default:*//*Label 146*/ GIMT_Encode4(357167),
/*TargetOpcode::G_ADD*//*Label 0*/ GIMT_Encode4(2986),
```
To
const uint8_t *AArch64InstructionSelector::getMatchTable() const {
constexpr static uint8_t MatchTable0[] = {
/* 0 */ GIM_SwitchOpcode, /*MI*/0, /*[*/GIMT_Encode2(51), GIMT_Encode2(795), /*)*//*default:*//*Label 146*/ GIMT_Encode4(357167),
/* 10*/ /*TargetOpcode::G_ADD*//*Label 0*/ GIMT_Encode4(2986),
```
In other words something similar to SDISel:
```
static const unsigned char MatcherTable[] = {
/* 0*/ OPC_SwitchOpcode /*448 cases */, 54|128,114|128,1/*31030*/, TARGET_VAL(ISD::EXTRACT_VECTOR_ELT),// ->31036
/* 6*/ OPC_Scope, 103|128,96|128,1/*28775*/, /*->28785*/ // 4 children in Scope
/* 10*/ OPC_MoveChild0,
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVlFvo7oS_jXOy6iRMRDgIQ80aXNztVVX22jvfYuMGYJPDebYJm3-_ZGBNGm7q9U-HOnoVJVixvbnb-ab8ZhbKw8t4pLEt4SxrxKNwZtjTRgj8XrGe1drs_xTaKWbAt2s0OVp-b8aW1BaP8v2ANyBqxFKLPoD6N51vQNdwUbpgqvtEyqotBmWyNY60wsndQsWFY6jruYWCVuBbhEE91MIVjfoag-v5DOSMCc0Jws6_dM8oCTMYbN92D-9SCfqx07oEglLH7aWxLeUxGsPSeLbOPCDJIsJy_xojRXvlSPhOoyTYJF423_7ptvxQuF8PicsA8LuCbuHjfbL4oDQnGVZ8v7E3al7f94NCe8O6B47NLwtCUvpdCKJb5n_ZdEnCizI0uiXDGzICM1Dmi48hVs8yBacOd0USovnYSYLz-RWNYrnX3MLJip-5XbtmXjDALX4TSj2E6hruQjNdzVC2zcFGtDtkA4KKwfc-LwopUALcrQ33IkanI8GdEaXvcASitMwN8Rogy0UXDxjW84Jzf-jX_CIxnNwNdrzMXbAbrWDzsjWYQncgtBNg607H0UWdC5bQRYUKqn80UNKSwelrCopeuXAacBXLpw6QaWV0i_wUktRA7bOnHyme6CRrbRQoAfAVxS9P5Kw9KR7qPkRgXtvXk8g20qbhg_J_yJdfWZCIh-tM0XvTtH72tIWB1dsx43F-RTdMaIHzdXIQVqQ1vYDCadBNp3RR7yU5g0vpJLujfF1lIsT8LL0xMcyLfH1vWO6BeSiBiVb9CG_mx_mnuBBQ2V080FtoVvroJetS_cOCMvz3Ih6EW0v9f80lL82vrLD_IDuwdMZ1CUs9RUwgpDkltAcxi987QxYx50Ub-iXfdTfYPEaSLh-2wY_uCJWY3HlD1vC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