LLVM  13.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 
22 #include "llvm/ADT/DenseMapInfo.h"
26 #include "llvm/CodeGen/Register.h"
27 #include <utility>
28 
29 namespace llvm {
30 
31 class ShapeT {
32 public:
34  const MachineRegisterInfo *MRI = nullptr)
35  : Row(Row), Col(Col) {
36  if (MRI)
37  deduceImm(MRI);
38  }
40  : Row(nullptr), Col(nullptr), RowImm(InvalidImmShape),
41  ColImm(InvalidImmShape) {}
42  bool operator==(const ShapeT &Shape) {
43  MachineOperand *R = Shape.Row;
44  MachineOperand *C = Shape.Col;
45  if (!R || !C)
46  return false;
47  if (!Row || !Col)
48  return false;
49  if (Row->getReg() == R->getReg() && Col->getReg() == C->getReg())
50  return true;
51  if ((RowImm != InvalidImmShape) && (ColImm != InvalidImmShape))
52  return RowImm == Shape.getRowImm() && ColImm == Shape.getColImm();
53  return false;
54  }
55 
56  bool operator!=(const ShapeT &Shape) { return !(*this == Shape); }
57 
58  MachineOperand *getRow() const { return Row; }
59 
60  MachineOperand *getCol() const { return Col; }
61 
62  int64_t getRowImm() const { return RowImm; }
63 
64  int64_t getColImm() const { return ColImm; }
65 
66  bool isValid() { return (Row != nullptr) && (Col != nullptr); }
67 
69  // All def must be the same value, otherwise it is invalid MIs.
70  // Find the immediate.
71  // TODO copy propagation.
72  auto GetImm = [&](Register Reg) {
73  int64_t Imm = InvalidImmShape;
74  for (const MachineOperand &DefMO : MRI->def_operands(Reg)) {
75  const auto *MI = DefMO.getParent();
76  if (MI->isMoveImmediate()) {
77  Imm = MI->getOperand(1).getImm();
78  break;
79  }
80  }
81  return Imm;
82  };
83  RowImm = GetImm(Row->getReg());
84  ColImm = GetImm(Col->getReg());
85  }
86 
87 private:
88  static constexpr int64_t InvalidImmShape = -1;
89  MachineOperand *Row;
90  MachineOperand *Col;
91  int64_t RowImm;
92  int64_t ColImm;
93 };
94 
95 } // namespace llvm
96 
97 #endif
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:100
MachineInstr.h
llvm
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::ShapeT::getRow
MachineOperand * getRow() const
Definition: TileShapeInfo.h:58
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::ShapeT
Definition: TileShapeInfo.h:31
llvm::ShapeT::operator!=
bool operator!=(const ShapeT &Shape)
Definition: TileShapeInfo.h:56
MachineRegisterInfo.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ShapeT::operator==
bool operator==(const ShapeT &Shape)
Definition: TileShapeInfo.h:42
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::ShapeT::getCol
MachineOperand * getCol() const
Definition: TileShapeInfo.h:60
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:357
llvm::ShapeT::ShapeT
ShapeT(MachineOperand *Row, MachineOperand *Col, const MachineRegisterInfo *MRI=nullptr)
Definition: TileShapeInfo.h:33
GetImm
static bool GetImm(MachineInstr *MI, unsigned Op, int64_t &Imm)
Definition: MicroMipsSizeReduction.cpp:308
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::ShapeT::ShapeT
ShapeT()
Definition: TileShapeInfo.h:39
llvm::ShapeT::getRowImm
int64_t getRowImm() const
Definition: TileShapeInfo.h:62
llvm::ShapeT::getColImm
int64_t getColImm() const
Definition: TileShapeInfo.h:64
llvm::ShapeT::deduceImm
void deduceImm(const MachineRegisterInfo *MRI)
Definition: TileShapeInfo.h:68
MachineOperand.h
DenseMapInfo.h
Register.h
llvm::ShapeT::isValid
bool isValid()
Definition: TileShapeInfo.h:66