LLVM 22.0.0git
TileShapeInfo.h
Go to the documentation of this file.
1//===- llvm/CodeGen/TileShapeInfo.h - ---------------------------*- C++ -*-===//
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/// \file Shape utility for AMX.
10/// AMX hardware requires to config the shape of tile data register before use.
11/// The 2D shape includes row and column. In AMX intrinsics interface the shape
12/// is passed as 1st and 2nd parameter and they are lowered as the 1st and 2nd
13/// machine operand of AMX pseudo instructions. ShapeT class is to facilitate
14/// tile config and register allocator. The row and column are machine operand
15/// of AMX pseudo instructions.
16//
17//===----------------------------------------------------------------------===//
18
19#ifndef LLVM_CODEGEN_TILESHAPEINFO_H
20#define LLVM_CODEGEN_TILESHAPEINFO_H
21
26
27namespace llvm {
28
29class ShapeT {
30public:
32 const MachineRegisterInfo *MRI = nullptr)
33 : Row(Row), Col(Col) {
34 if (MRI)
36 }
38 : Row(nullptr), Col(nullptr), RowImm(InvalidImmShape),
39 ColImm(InvalidImmShape) {}
40 bool operator==(const ShapeT &Shape) const {
41 MachineOperand *R = Shape.Row;
42 MachineOperand *C = Shape.Col;
43 if (!R || !C)
44 return false;
45 if (!Row || !Col)
46 return false;
47 if (Row->getReg() == R->getReg() && Col->getReg() == C->getReg())
48 return true;
49 if ((RowImm != InvalidImmShape) && (ColImm != InvalidImmShape))
50 return RowImm == Shape.getRowImm() && ColImm == Shape.getColImm();
51 return false;
52 }
53
54 bool operator!=(const ShapeT &Shape) const { return !(*this == Shape); }
55
56 MachineOperand *getRow() const { return Row; }
57 MachineOperand *getCol() const { return Col; }
58
59 int64_t getRowImm() const { return RowImm; }
60 int64_t getColImm() const { return ColImm; }
61
62 bool isValid() { return (Row != nullptr) && (Col != nullptr); }
63
65 // All def must be the same value, otherwise it is invalid MIs.
66 // Find the immediate.
67 // TODO copy propagation.
68 auto GetImm = [&](Register Reg) {
69 int64_t Imm = InvalidImmShape;
70 for (const MachineOperand &DefMO : MRI->def_operands(Reg)) {
71 const auto *MI = DefMO.getParent();
72 if (MI->isMoveImmediate()) {
73 if (MI->getOperand(1).isImm()) {
74 Imm = MI->getOperand(1).getImm();
75 } else {
76 assert(MI->getOperand(1).isImplicit() &&
77 "Operand 1 is assumed to be implicit.");
78 // The implicit immediate can vary (MOV32r0, MOV32r1, MOV32r_1,
79 // ...) but in any case, is not a valid shape.
80 }
81 break;
82 }
83 }
84 return Imm;
85 };
86 RowImm = GetImm(Row->getReg());
87 ColImm = GetImm(Col->getReg());
88 }
89
90private:
91 static constexpr int64_t InvalidImmShape = -1;
92 MachineOperand *Row;
93 MachineOperand *Col;
94 int64_t RowImm = -1;
95 int64_t ColImm = -1;
96};
97
98} // namespace llvm
99
100#endif
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
IRTranslator LLVM IR MI
Register Reg
static bool GetImm(MachineInstr *MI, unsigned Op, int64_t &Imm)
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
void deduceImm(const MachineRegisterInfo *MRI)
ShapeT(MachineOperand *Row, MachineOperand *Col, const MachineRegisterInfo *MRI=nullptr)
bool operator!=(const ShapeT &Shape) const
bool operator==(const ShapeT &Shape) const
MachineOperand * getRow() const
int64_t getColImm() const
MachineOperand * getCol() const
int64_t getRowImm() const
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26