From f5c592905e6e1ef4b78337d76c8215e543607b8d Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Mon, 17 Aug 2026 03:16:26 +0800 Subject: [RISCV][GlobalISel] Generate conditional branch selection --- .../lib/Target/RISCV/RISCVGISelControlFlow.rccdesc | 252 +++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 backend/lib/Target/RISCV/RISCVGISelControlFlow.rccdesc (limited to 'backend/lib/Target/RISCV/RISCVGISelControlFlow.rccdesc') diff --git a/backend/lib/Target/RISCV/RISCVGISelControlFlow.rccdesc b/backend/lib/Target/RISCV/RISCVGISelControlFlow.rccdesc new file mode 100644 index 0000000..c58135f --- /dev/null +++ b/backend/lib/Target/RISCV/RISCVGISelControlFlow.rccdesc @@ -0,0 +1,252 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +selection_rules: + - + id: select_g_br + priority: 100 + match: + opcode: G_BR + apply: + instructions: + - opcode: PseudoBR + root: true + operands: [{ operand: 0 }] + - + id: select_g_brcond_sgt_minus_one + priority: 600 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: sgt } + captures: + - { id: lhs, operand: 2 } + operand_def_constants: + - index: 3 + ranges: [{ min: -1, max: -1 }] + apply: + instructions: + - opcode: BGE + root: true + operands: + - { captured_operand: lhs } + - { physical_register: X0, flags: [use] } + - { operand: 1 } + erase_operand_definitions: [0] + - + id: select_g_brcond_slt_one + priority: 600 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: slt } + captures: + - { id: lhs, operand: 2 } + operand_def_constants: + - index: 3 + ranges: [{ min: 1, max: 1 }] + apply: + instructions: + - opcode: BGE + root: true + operands: + - { physical_register: X0, flags: [use] } + - { captured_operand: lhs } + - { operand: 1 } + erase_operand_definitions: [0] + - + id: select_g_brcond_eq + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: eq } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BEQ + root: true + operands: [{ captured_operand: lhs }, { captured_operand: rhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_ne + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: ne } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BNE + root: true + operands: [{ captured_operand: lhs }, { captured_operand: rhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_slt + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: slt } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BLT + root: true + operands: [{ captured_operand: lhs }, { captured_operand: rhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_sge + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: sge } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BGE + root: true + operands: [{ captured_operand: lhs }, { captured_operand: rhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_ult + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: ult } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BLTU + root: true + operands: [{ captured_operand: lhs }, { captured_operand: rhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_uge + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: uge } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BGEU + root: true + operands: [{ captured_operand: lhs }, { captured_operand: rhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_sgt + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: sgt } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BLT + root: true + operands: [{ captured_operand: rhs }, { captured_operand: lhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_sle + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: sle } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BGE + root: true + operands: [{ captured_operand: rhs }, { captured_operand: lhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_ugt + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: ugt } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BLTU + root: true + operands: [{ captured_operand: rhs }, { captured_operand: lhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond_ule + priority: 400 + match: + opcode: G_BRCOND + def_use: + - operand: 0 + opcode: G_ICMP + integer_predicate: { index: 1, value: ule } + captures: + - { id: lhs, operand: 2 } + - { id: rhs, operand: 3 } + apply: + instructions: + - opcode: BGEU + root: true + operands: [{ captured_operand: rhs }, { captured_operand: lhs }, { operand: 1 }] + erase_operand_definitions: [0] + - + id: select_g_brcond + priority: 100 + match: + opcode: G_BRCOND + apply: + instructions: + - opcode: BNE + root: true + operands: + - { operand: 0 } + - { physical_register: X0, flags: [use] } + - { operand: 1 } -- cgit v1.2.3