[llvm] [RISCV] Use TableGen-based macro fusion (PR #72224)

Wang Pengcheng via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 00:55:15 PST 2023


================
@@ -0,0 +1,208 @@
+//===--- MacroFusionPredicatorEmitter.cpp - Generator for MacroFusion ----===//
----------------
wangpc-pp wrote:

Actually my first version of implementation (unfinished) is like this way:
```
// def fusion1: MacroFusionPat<(FirstInst GPR:$r), (SecondInst GPR:$r)>;
// def fusion2: MacroFusionPat<(FirstInst), (SecondInst GPR:$r)>;
// def fusion3: MacroFusionPat<(FirstInst GPR:$r), (SecondInst)>;
// def fusion4: MacroFusionPat<(FirstInst), (SecondInst)>;
def fusion5: MacroFusionPat<(FirstInst GPR:$r, imm:$imm), (SecondInst _, imm:$imm)>;
```
We define the predicates of first/second and tied register via `dag` expressions. But there are some reasons why I gave it up:
* It's hard to write fusion with multiple opcodes (for example, `lui+addi/addiw`), we need two definitions (`lui+addi` and `lui+addiw`). We can implement it like what we have in `TargetSchedule.td`, aka `instrs` and `instregex`. But it adds too much complexities to the implementation.
* We already have `TargetInstrPredicate.td` to define predicates in SchedModel, which is expressive enough I think.

https://github.com/llvm/llvm-project/pull/72224


More information about the llvm-commits mailing list