@@ -227,6 +227,12 @@ option specifies "``-``", then the output will also be sent to standard output.
227
227
detect any custom hazards or make any post processing modifications to
228
228
instructions.
229
229
230
+ .. option :: -disable-im
231
+
232
+ Force usage of the generic InstrumentManager rather than using the target
233
+ specific implementation. The generic class creates Instruments that provide
234
+ no extra information, and InstrumentManager never overrides the default
235
+ schedule class for a given instruction.
230
236
231
237
EXIT STATUS
232
238
-----------
@@ -238,9 +244,9 @@ USING MARKERS TO ANALYZE SPECIFIC CODE BLOCKS
238
244
---------------------------------------------
239
245
:program: `llvm-mca ` allows for the optional usage of special code comments to
240
246
mark regions of the assembly code to be analyzed. A comment starting with
241
- substring ``LLVM-MCA-BEGIN `` marks the beginning of a code region. A comment
242
- starting with substring ``LLVM-MCA-END `` marks the end of a code region. For
243
- example:
247
+ substring ``LLVM-MCA-BEGIN `` marks the beginning of an analysis region. A
248
+ comment starting with substring ``LLVM-MCA-END `` marks the end of a region.
249
+ For example:
244
250
245
251
.. code-block :: none
246
252
@@ -251,9 +257,9 @@ example:
251
257
If no user-defined region is specified, then :program: `llvm-mca ` assumes a
252
258
default region which contains every instruction in the input file. Every region
253
259
is analyzed in isolation, and the final performance report is the union of all
254
- the reports generated for every code region.
260
+ the reports generated for every analysis region.
255
261
256
- Code regions can have names. For example:
262
+ Analysis regions can have names. For example:
257
263
258
264
.. code-block :: none
259
265
@@ -315,6 +321,91 @@ assembly is equivalent to the assembly generated in the absence of markers.
315
321
The `Clang options to emit optimization reports <https://clang.llvm.org/docs/UsersManual.html#options-to-emit-optimization-reports >`_
316
322
can also help in detecting missed optimizations.
317
323
324
+ INSTRUMENT REGIONS
325
+ ------------------
326
+
327
+ An InstrumentRegion describes a region of assembly code guarded by
328
+ special LLVM-MCA comment directives.
329
+
330
+ .. code-block :: none
331
+
332
+ # LLVM-MCA-<INSTRUMENT_TYPE> <data>
333
+ ... ## asm
334
+
335
+ where `INSTRUMENT_TYPE ` is a type defined by the target and expects
336
+ to use `data `.
337
+
338
+ A comment starting with substring `LLVM-MCA-<INSTRUMENT_TYPE> `
339
+ brings data into scope for llvm-mca to use in its analysis for
340
+ all following instructions.
341
+
342
+ If a comment with the same `INSTRUMENT_TYPE ` is found later in the
343
+ instruction list, then the original InstrumentRegion will be
344
+ automatically ended, and a new InstrumentRegion will begin.
345
+
346
+ If there are comments containing the different `INSTRUMENT_TYPE `,
347
+ then both data sets remain available. In contrast with an AnalysisRegion,
348
+ an InstrumentRegion does not need a comment to end the region.
349
+
350
+ Comments that are prefixed with `LLVM-MCA- ` but do not correspond to
351
+ a valid `INSTRUMENT_TYPE ` for the target cause an error, except for
352
+ `BEGIN ` and `END `, since those correspond to AnalysisRegions. Comments
353
+ that do not start with `LLVM-MCA- ` are ignored by :program `llvm-mca `.
354
+
355
+ An instruction (a MCInst) is added to an InstrumentRegion R only
356
+ if its location is in range [R.RangeStart, R.RangeEnd].
357
+
358
+ On RISCV targets, vector instructions have different behaviour depending
359
+ on the LMUL. Code can be instrumented with a comment that takes the
360
+ following form:
361
+
362
+ .. code-block :: none
363
+
364
+ # LLVM-MCA-RISCV-LMUL <M1|M2|M4|M8|MF2|MF4|MF8>
365
+
366
+ The RISCV InstrumentManager will override the schedule class for vector
367
+ instructions to use the scheduling behaviour of its pseudo-instruction
368
+ which is LMUL dependent. It makes sense to place RISCV instrument
369
+ comments directly after `vset{i}vl{i} ` instructions, although
370
+ they can be placed anywhere in the program.
371
+
372
+ Example of program with no call to `vset{i}vl{i} `:
373
+
374
+ .. code-block :: none
375
+
376
+ # LLVM-MCA-RISCV-LMUL M2
377
+ vadd.vv v2, v2, v2
378
+
379
+ Example of program with call to `vset{i}vl{i} `:
380
+
381
+ .. code-block :: none
382
+
383
+ vsetvli zero, a0, e8, m1, tu, mu
384
+ # LLVM-MCA-RISCV-LMUL M1
385
+ vadd.vv v2, v2, v2
386
+
387
+ Example of program with multiple calls to `vset{i}vl{i} `:
388
+
389
+ .. code-block :: none
390
+
391
+ vsetvli zero, a0, e8, m1, tu, mu
392
+ # LLVM-MCA-RISCV-LMUL M1
393
+ vadd.vv v2, v2, v2
394
+ vsetvli zero, a0, e8, m8, tu, mu
395
+ # LLVM-MCA-RISCV-LMUL M8
396
+ vadd.vv v2, v2, v2
397
+
398
+ Example of program with call to `vsetvl `:
399
+
400
+ .. code-block :: none
401
+
402
+ vsetvl rd, rs1, rs2
403
+ # LLVM-MCA-RISCV-LMUL M1
404
+ vadd.vv v12, v12, v12
405
+ vsetvl rd, rs1, rs2
406
+ # LLVM-MCA-RISCV-LMUL M4
407
+ vadd.vv v12, v12, v12
408
+
318
409
HOW LLVM-MCA WORKS
319
410
------------------
320
411
@@ -1024,6 +1115,28 @@ already have one, refer to an existing implementation to see how to set it
1024
1115
up. The classes are implemented within the target specific backend (for
1025
1116
example `/llvm/lib/Target/AMDGPU/MCA/ `) so that they can access backend symbols.
1026
1117
1118
+ Instrument Manager
1119
+ """"""""""""""""""""""""""""""""""""
1120
+ On certain architectures, scheduling information for certain instructions
1121
+ do not contain all of the information required to identify the most precise
1122
+ schedule class. For example, data that can have an impact on scheduling can
1123
+ be stored in CSR registers.
1124
+
1125
+ One example of this is on RISCV, where values in registers such as `vtype `
1126
+ and `vl ` change the scheduling behaviour of vector instructions. Since MCA
1127
+ does not keep track of the values in registers, instrument comments can
1128
+ be used to specify these values.
1129
+
1130
+ InstrumentManager's main function is `getSchedClassID() ` which has access
1131
+ to the MCInst and all of the instruments that are active for that MCInst.
1132
+ This function can use the instruments to override the schedule class of
1133
+ the MCInst.
1134
+
1135
+ On RISCV, instrument comments containing LMUL information are used
1136
+ by `getSchedClassID() ` to map a vector instruction and the active
1137
+ LMUL to the scheduling class of the pseudo-instruction that describes
1138
+ that base instruction and the active LMUL.
1139
+
1027
1140
Custom Views
1028
1141
""""""""""""""""""""""""""""""""""""
1029
1142
:program: `llvm-mca ` comes with several Views such as the Timeline View and
0 commit comments