OSDN Git Service

[tblgen][llvm-mca] Add the ability to describe move elimination candidates via tablegen.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Fri, 12 Oct 2018 11:23:04 +0000 (11:23 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Fri, 12 Oct 2018 11:23:04 +0000 (11:23 +0000)
commitf39b0d9784b8e8acf20d7046101eb2e229b20a8a
tree52c033a911ad584c147c9904a0fcd41f58be5079
parent0b50ad3f83305d5904d9f0ffa94424134a7b6d82
[tblgen][llvm-mca] Add the ability to describe move elimination candidates via tablegen.

This patch adds the ability to identify instructions that are "move elimination
candidates". It also allows scheduling models to describe processor register
files that allow move elimination.

A move elimination candidate is an instruction that can be eliminated at
register renaming stage.
Each subtarget can specify which instructions are move elimination candidates
with the help of tablegen class "IsOptimizableRegisterMove" (see
llvm/Target/TargetInstrPredicate.td).

For example, on X86, BtVer2 allows both GPR and MMX/SSE moves to be eliminated.
The definition of 'IsOptimizableRegisterMove' for BtVer2 looks like this:

```
def : IsOptimizableRegisterMove<[
  InstructionEquivalenceClass<[
    // GPR variants.
    MOV32rr, MOV64rr,

    // MMX variants.
    MMX_MOVQ64rr,

    // SSE variants.
    MOVAPSrr, MOVUPSrr,
    MOVAPDrr, MOVUPDrr,
    MOVDQArr, MOVDQUrr,

    // AVX variants.
    VMOVAPSrr, VMOVUPSrr,
    VMOVAPDrr, VMOVUPDrr,
    VMOVDQArr, VMOVDQUrr
  ], CheckNot<CheckSameRegOperand<0, 1>> >
]>;
```

Definitions of IsOptimizableRegisterMove from processor models of a same
Target are processed by the SubtargetEmitter to auto-generate a target-specific
override for each of the following predicate methods:

```
bool TargetSubtargetInfo::isOptimizableRegisterMove(const MachineInstr *MI)
const;
bool MCInstrAnalysis::isOptimizableRegisterMove(const MCInst &MI, unsigned
CPUID) const;
```

By default, those methods return false (i.e. conservatively assume that there
are no move elimination candidates).

Tablegen class RegisterFile has been extended with the following information:
 - The set of register classes that allow move elimination.
 - Maxium number of moves that can be eliminated every cycle.
 - Whether move elimination is restricted to moves from registers that are
   known to be zero.

This patch is structured in three part:

A first part (which is mostly boilerplate) adds the new
'isOptimizableRegisterMove' target hooks, and extends existing register file
descriptors in MC by introducing new fields to describe properties related to
move elimination.

A second part, uses the new tablegen constructs to describe move elimination in
the BtVer2 scheduling model.

A third part, teaches llm-mca how to query the new 'isOptimizableRegisterMove'
hook to mark instructions that are candidates for move elimination. It also
teaches class RegisterFile how to describe constraints on move elimination at
PRF granularity.

llvm-mca tests for btver2 show differences before/after this patch.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344334 91177308-0d34-0410-b5e6-96231b3b80d8
16 files changed:
include/llvm/CodeGen/TargetSubtargetInfo.h
include/llvm/MC/MCInstrAnalysis.h
include/llvm/MC/MCSchedule.h
include/llvm/Target/TargetInstrPredicate.td
include/llvm/Target/TargetSchedule.td
lib/Target/X86/X86ScheduleBtVer2.td
test/tools/llvm-mca/X86/BtVer2/reg-move-elimination-1.s
test/tools/llvm-mca/X86/BtVer2/reg-move-elimination-2.s
test/tools/llvm-mca/X86/BtVer2/reg-move-elimination-3.s
test/tools/llvm-mca/X86/BtVer2/reg-move-elimination-4.s
test/tools/llvm-mca/X86/BtVer2/reg-move-elimination-5.s
tools/llvm-mca/lib/HardwareUnits/RegisterFile.cpp
tools/llvm-mca/lib/InstrBuilder.cpp
utils/TableGen/CodeGenSchedule.cpp
utils/TableGen/CodeGenSchedule.h
utils/TableGen/SubtargetEmitter.cpp