[MC][Tablegen] Allow the definition of processor register files in the scheduling...
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 3 Apr 2018 13:36:24 +0000 (13:36 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Tue, 3 Apr 2018 13:36:24 +0000 (13:36 +0000)
commit9da4d6db33689aa95fc5f7c8802b766c890111da
treefc3970f467276f532910ab2e416dc4dc54f178a7
parentd96a363855f9ce7b9d2d8182206c74f3bb9d11ab
[MC][Tablegen] Allow the definition of processor register files in the scheduling model for llvm-mca

This patch allows the description of register files in processor scheduling
models. This addresses PR36662.

A new tablegen class named 'RegisterFile' has been added to TargetSchedule.td.
Targets can optionally describe register files for their processors using that
class. In particular, class RegisterFile allows to specify:
 - The total number of physical registers.
 - Which target registers are accessible through the register file.
 - The cost of allocating a register at register renaming stage.

Example (from this patch - see file X86/X86ScheduleBtVer2.td)

  def FpuPRF : RegisterFile<72, [VR64, VR128, VR256], [1, 1, 2]>

Here, FpuPRF describes a register file for MMX/XMM/YMM registers. On Jaguar
(btver2), a YMM register definition consumes 2 physical registers, while MMX/XMM
register definitions only cost 1 physical register.

The syntax allows to specify an empty set of register classes.  An empty set of
register classes means: this register file models all the registers specified by
the Target.  For each register class, users can specify an optional register
cost. By default, register costs default to 1.  A value of 0 for the number of
physical registers means: "this register file has an unbounded number of
physical registers".

This patch is structured in two parts.

* Part 1 - MC/Tablegen *

A first part adds the tablegen definition of RegisterFile, and teaches the
SubtargetEmitter how to emit information related to register files.

Information about register files is accessible through an instance of
MCExtraProcessorInfo.
The idea behind this design is to logically partition the processor description
which is only used by external tools (like llvm-mca) from the processor
information used by the llvm machine schedulers.
I think that this design would make easier for targets to get rid of the extra
processor information if they don't want it.

* Part 2 - llvm-mca related *

The second part of this patch is related to changes to llvm-mca.

The main differences are:
 1) class RegisterFile now needs to take into account the "cost of a register"
when allocating physical registers at register renaming stage.
 2) Point 1. triggered a minor refactoring which lef to the removal of the
"maximum 32 register files" restriction.
 3) The BackendStatistics view has been updated so that we can print out extra
details related to each register file implemented by the processor.

The effect of point 3. is also visible in tests register-files-[1..5].s.

Differential Revision: https://reviews.llvm.org/D44980

llvm-svn: 329067
16 files changed:
llvm/include/llvm/MC/MCSchedule.h
llvm/include/llvm/Target/TargetSchedule.td
llvm/lib/Target/X86/X86ScheduleBtVer2.td
llvm/test/tools/llvm-mca/X86/BtVer2/register-files-1.s
llvm/test/tools/llvm-mca/X86/BtVer2/register-files-2.s
llvm/test/tools/llvm-mca/X86/BtVer2/register-files-3.s
llvm/test/tools/llvm-mca/X86/BtVer2/register-files-4.s [new file with mode: 0644]
llvm/test/tools/llvm-mca/X86/BtVer2/register-files-5.s [new file with mode: 0644]
llvm/tools/llvm-mca/Backend.h
llvm/tools/llvm-mca/BackendStatistics.cpp
llvm/tools/llvm-mca/BackendStatistics.h
llvm/tools/llvm-mca/Dispatch.cpp
llvm/tools/llvm-mca/Dispatch.h
llvm/utils/TableGen/CodeGenSchedule.cpp
llvm/utils/TableGen/CodeGenSchedule.h
llvm/utils/TableGen/SubtargetEmitter.cpp