Skip to content

Commit 5e486d1

Browse files
authored
[TableGen][NFC] Move MacroFusion classes to TargetMacroFusion.td
To make structure clear. Reviewers: dtcxzyw, arsenm Reviewed By: arsenm Pull Request: #85748
1 parent b788e46 commit 5e486d1

File tree

3 files changed

+141
-127
lines changed

3 files changed

+141
-127
lines changed

llvm/include/llvm/Target/Target.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,3 +1877,8 @@ include "llvm/Target/GlobalISel/SelectionDAGCompat.td"
18771877
// Pull in the common support for Pfm Counters generation.
18781878
//
18791879
include "llvm/Target/TargetPfmCounters.td"
1880+
1881+
//===----------------------------------------------------------------------===//
1882+
// Pull in the common support for macro fusion.
1883+
//
1884+
include "llvm/Target/TargetMacroFusion.td"
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//===-- TargetMacroFusion.td - Target Macro Fusion ---------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the TableGen-based macro fusion classes.
10+
11+
// The target instruction that FusionPredicate will be evaluated on.
12+
class FusionTarget;
13+
def first_fusion_target : FusionTarget;
14+
def second_fusion_target : FusionTarget;
15+
def both_fusion_target : FusionTarget;
16+
17+
// Base class of FusionPredicate, etc. The avaliable variables are:
18+
// * const TargetInstrInfo &TII
19+
// * const TargetSubtargetInfo &STI
20+
// * const MachineRegisterInfo &MRI
21+
// * const MachineInstr *FirstMI
22+
// * const MachineInstr &SecondMI
23+
class FusionPredicate<FusionTarget target> {
24+
FusionTarget Target = target;
25+
}
26+
class FirstFusionPredicate: FusionPredicate<first_fusion_target>;
27+
class SecondFusionPredicate: FusionPredicate<second_fusion_target>;
28+
class BothFusionPredicate: FusionPredicate<both_fusion_target>;
29+
30+
// FusionPredicate with raw code predicate.
31+
class FusionPredicateWithCode<code pred> : FusionPredicate<both_fusion_target> {
32+
code Predicate = pred;
33+
}
34+
35+
// FusionPredicate with MCInstPredicate.
36+
class FusionPredicateWithMCInstPredicate<FusionTarget target, MCInstPredicate pred>
37+
: FusionPredicate<target> {
38+
MCInstPredicate Predicate = pred;
39+
}
40+
class FirstFusionPredicateWithMCInstPredicate<MCInstPredicate pred>
41+
: FusionPredicateWithMCInstPredicate<first_fusion_target, pred>;
42+
class SecondFusionPredicateWithMCInstPredicate<MCInstPredicate pred>
43+
: FusionPredicateWithMCInstPredicate<second_fusion_target, pred>;
44+
// The pred will be applied on both firstMI and secondMI.
45+
class BothFusionPredicateWithMCInstPredicate<MCInstPredicate pred>
46+
: FusionPredicateWithMCInstPredicate<both_fusion_target, pred>;
47+
48+
// Tie firstOpIdx and secondOpIdx. The operand of `FirstMI` at position
49+
// `firstOpIdx` should be the same as the operand of `SecondMI` at position
50+
// `secondOpIdx`.
51+
// If the fusion has `IsCommutable` being true and the operand at `secondOpIdx`
52+
// has commutable operand, then the commutable operand will be checked too.
53+
class TieReg<int firstOpIdx, int secondOpIdx> : BothFusionPredicate {
54+
int FirstOpIdx = firstOpIdx;
55+
int SecondOpIdx = secondOpIdx;
56+
}
57+
58+
// The operand of `SecondMI` at position `firstOpIdx` should be the same as the
59+
// operand at position `secondOpIdx`.
60+
// If the fusion has `IsCommutable` being true and the operand at `secondOpIdx`
61+
// has commutable operand, then the commutable operand will be checked too.
62+
class SameReg<int firstOpIdx, int secondOpIdx> : SecondFusionPredicate {
63+
int FirstOpIdx = firstOpIdx;
64+
int SecondOpIdx = secondOpIdx;
65+
}
66+
67+
// A predicate for wildcard. The generated code will be like:
68+
// ```
69+
// if (!FirstMI)
70+
// return ReturnValue;
71+
// ```
72+
class WildcardPred<bit ret> : FirstFusionPredicate {
73+
bit ReturnValue = ret;
74+
}
75+
def WildcardFalse : WildcardPred<0>;
76+
def WildcardTrue : WildcardPred<1>;
77+
78+
// Indicates that the destination register of `FirstMI` should have one use if
79+
// it is a virtual register.
80+
class OneUsePred : FirstFusionPredicate;
81+
def OneUse : OneUsePred;
82+
83+
// Handled by MacroFusionPredicatorEmitter backend.
84+
// The generated predicator will be like:
85+
// ```
86+
// bool isNAME(const TargetInstrInfo &TII,
87+
// const TargetSubtargetInfo &STI,
88+
// const MachineInstr *FirstMI,
89+
// const MachineInstr &SecondMI) {
90+
// auto &MRI = SecondMI.getMF()->getRegInfo();
91+
// /* Predicates */
92+
// return true;
93+
// }
94+
// ```
95+
//
96+
// `IsCommutable` means whether we should handle commutable operands.
97+
class Fusion<string name, string fieldName, string desc, list<FusionPredicate> predicates>
98+
: SubtargetFeature<name, fieldName, "true", desc> {
99+
list<FusionPredicate> Predicates = predicates;
100+
bit IsCommutable = 0;
101+
}
102+
103+
// The generated predicator will be like:
104+
// ```
105+
// bool isNAME(const TargetInstrInfo &TII,
106+
// const TargetSubtargetInfo &STI,
107+
// const MachineInstr *FirstMI,
108+
// const MachineInstr &SecondMI) {
109+
// auto &MRI = SecondMI.getMF()->getRegInfo();
110+
// /* Prolog */
111+
// /* Predicate for `SecondMI` */
112+
// /* Wildcard */
113+
// /* Predicate for `FirstMI` */
114+
// /* Check same registers */
115+
// /* Check One Use */
116+
// /* Tie registers */
117+
// /* Epilog */
118+
// return true;
119+
// }
120+
// ```
121+
class SimpleFusion<string name, string fieldName, string desc,
122+
MCInstPredicate firstPred, MCInstPredicate secondPred,
123+
list<FusionPredicate> prolog = [],
124+
list<FusionPredicate> epilog = []>
125+
: Fusion<name, fieldName, desc,
126+
!listconcat(
127+
prolog,
128+
[
129+
SecondFusionPredicateWithMCInstPredicate<secondPred>,
130+
WildcardTrue,
131+
FirstFusionPredicateWithMCInstPredicate<firstPred>,
132+
SameReg<0, 1>,
133+
OneUse,
134+
TieReg<0, 1>,
135+
],
136+
epilog)>;

llvm/include/llvm/Target/TargetSchedule.td

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -581,130 +581,3 @@ class MemoryQueue<ProcResourceKind PR> {
581581

582582
class LoadQueue<ProcResourceKind LDQueue> : MemoryQueue<LDQueue>;
583583
class StoreQueue<ProcResourceKind STQueue> : MemoryQueue<STQueue>;
584-
585-
// The target instruction that FusionPredicate will be evaluated on.
586-
class FusionTarget;
587-
def first_fusion_target : FusionTarget;
588-
def second_fusion_target : FusionTarget;
589-
def both_fusion_target : FusionTarget;
590-
591-
// Base class of FusionPredicate, etc. The avaliable variables are:
592-
// * const TargetInstrInfo &TII
593-
// * const TargetSubtargetInfo &STI
594-
// * const MachineRegisterInfo &MRI
595-
// * const MachineInstr *FirstMI
596-
// * const MachineInstr &SecondMI
597-
class FusionPredicate<FusionTarget target> {
598-
FusionTarget Target = target;
599-
}
600-
class FirstFusionPredicate: FusionPredicate<first_fusion_target>;
601-
class SecondFusionPredicate: FusionPredicate<second_fusion_target>;
602-
class BothFusionPredicate: FusionPredicate<both_fusion_target>;
603-
604-
// FusionPredicate with raw code predicate.
605-
class FusionPredicateWithCode<code pred> : FusionPredicate<both_fusion_target> {
606-
code Predicate = pred;
607-
}
608-
609-
// FusionPredicate with MCInstPredicate.
610-
class FusionPredicateWithMCInstPredicate<FusionTarget target, MCInstPredicate pred>
611-
: FusionPredicate<target> {
612-
MCInstPredicate Predicate = pred;
613-
}
614-
class FirstFusionPredicateWithMCInstPredicate<MCInstPredicate pred>
615-
: FusionPredicateWithMCInstPredicate<first_fusion_target, pred>;
616-
class SecondFusionPredicateWithMCInstPredicate<MCInstPredicate pred>
617-
: FusionPredicateWithMCInstPredicate<second_fusion_target, pred>;
618-
// The pred will be applied on both firstMI and secondMI.
619-
class BothFusionPredicateWithMCInstPredicate<MCInstPredicate pred>
620-
: FusionPredicateWithMCInstPredicate<both_fusion_target, pred>;
621-
622-
// Tie firstOpIdx and secondOpIdx. The operand of `FirstMI` at position
623-
// `firstOpIdx` should be the same as the operand of `SecondMI` at position
624-
// `secondOpIdx`.
625-
// If the fusion has `IsCommutable` being true and the operand at `secondOpIdx`
626-
// has commutable operand, then the commutable operand will be checked too.
627-
class TieReg<int firstOpIdx, int secondOpIdx> : BothFusionPredicate {
628-
int FirstOpIdx = firstOpIdx;
629-
int SecondOpIdx = secondOpIdx;
630-
}
631-
632-
// The operand of `SecondMI` at position `firstOpIdx` should be the same as the
633-
// operand at position `secondOpIdx`.
634-
// If the fusion has `IsCommutable` being true and the operand at `secondOpIdx`
635-
// has commutable operand, then the commutable operand will be checked too.
636-
class SameReg<int firstOpIdx, int secondOpIdx> : SecondFusionPredicate {
637-
int FirstOpIdx = firstOpIdx;
638-
int SecondOpIdx = secondOpIdx;
639-
}
640-
641-
// A predicate for wildcard. The generated code will be like:
642-
// ```
643-
// if (!FirstMI)
644-
// return ReturnValue;
645-
// ```
646-
class WildcardPred<bit ret> : FirstFusionPredicate {
647-
bit ReturnValue = ret;
648-
}
649-
def WildcardFalse : WildcardPred<0>;
650-
def WildcardTrue : WildcardPred<1>;
651-
652-
// Indicates that the destination register of `FirstMI` should have one use if
653-
// it is a virtual register.
654-
class OneUsePred : FirstFusionPredicate;
655-
def OneUse : OneUsePred;
656-
657-
// Handled by MacroFusionPredicatorEmitter backend.
658-
// The generated predicator will be like:
659-
// ```
660-
// bool isNAME(const TargetInstrInfo &TII,
661-
// const TargetSubtargetInfo &STI,
662-
// const MachineInstr *FirstMI,
663-
// const MachineInstr &SecondMI) {
664-
// auto &MRI = SecondMI.getMF()->getRegInfo();
665-
// /* Predicates */
666-
// return true;
667-
// }
668-
// ```
669-
//
670-
// `IsCommutable` means whether we should handle commutable operands.
671-
class Fusion<string name, string fieldName, string desc, list<FusionPredicate> predicates>
672-
: SubtargetFeature<name, fieldName, "true", desc> {
673-
list<FusionPredicate> Predicates = predicates;
674-
bit IsCommutable = 0;
675-
}
676-
677-
// The generated predicator will be like:
678-
// ```
679-
// bool isNAME(const TargetInstrInfo &TII,
680-
// const TargetSubtargetInfo &STI,
681-
// const MachineInstr *FirstMI,
682-
// const MachineInstr &SecondMI) {
683-
// auto &MRI = SecondMI.getMF()->getRegInfo();
684-
// /* Prolog */
685-
// /* Predicate for `SecondMI` */
686-
// /* Wildcard */
687-
// /* Predicate for `FirstMI` */
688-
// /* Check same registers */
689-
// /* Check One Use */
690-
// /* Tie registers */
691-
// /* Epilog */
692-
// return true;
693-
// }
694-
// ```
695-
class SimpleFusion<string name, string fieldName, string desc,
696-
MCInstPredicate firstPred, MCInstPredicate secondPred,
697-
list<FusionPredicate> prolog = [],
698-
list<FusionPredicate> epilog = []>
699-
: Fusion<name, fieldName, desc,
700-
!listconcat(
701-
prolog,
702-
[
703-
SecondFusionPredicateWithMCInstPredicate<secondPred>,
704-
WildcardTrue,
705-
FirstFusionPredicateWithMCInstPredicate<firstPred>,
706-
SameReg<0, 1>,
707-
OneUse,
708-
TieReg<0, 1>,
709-
],
710-
epilog)>;

0 commit comments

Comments
 (0)