LLVM 23.0.0git
MatrixUtils.h
Go to the documentation of this file.
1//===- MatrixUtils.h - Utilities to lower matrix intrinsics -----*- 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// Utilities for generating tiled loops for matrix operations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TRANSFORMS_UTILS_MATRIXUTILS_H
14#define LLVM_TRANSFORMS_UTILS_MATRIXUTILS_H
15
16#include "llvm/ADT/StringRef.h"
17
18namespace llvm {
19class DomTreeUpdater;
20class BasicBlock;
21class ConstantInt;
22class Value;
23class Loop;
24class LoopInfo;
25class IRBuilderBase;
26
27/// A helper struct to create IR loop nests for tiling in IR of the following
28/// form:
29/// for ColumnLoop.Index = 0..NumColumns
30/// for RowLoop.Index = 0..NumRows
31/// for KLoop.Index = 0..NumInner
32struct TileInfo {
33 /// Number of rows of the matrix.
34 unsigned NumRows;
35
36 /// Number of columns of the matrix.
37 unsigned NumColumns;
38
39 /// Number of columns of the first matrix of a multiply /
40 /// number of rows of the second matrix of a multiply.
41 unsigned NumInner;
42
43 /// Number of rows/columns in a tile.
44 unsigned TileSize = -1;
45
46 /// Properties of a single loop used when generating the tiled loop nest.
47 struct MatrixLoop {
48 /// The index updated on every iteration.
49 Value *Index = nullptr;
50 /// The header and latch of the loop.
51 BasicBlock *Header = nullptr;
52 BasicBlock *Latch = nullptr;
53 };
54
55 /// The loop iterating on the rows.
57 /// The loop iterating on the columns.
59 /// The loop iterating on k (inner dimension).
61
62 TileInfo(unsigned NumRows, unsigned NumColumns, unsigned NumInner,
63 unsigned TileSize)
66
67 /// Creates an IR loop nests for tiling of the form below. Returns the block
68 /// for the inner loop body and sets {Column,Row,Inner}LoopHeader/Latch
69 /// fields.
70 ///
71 /// for ColumnLoop.Index = 0..NumColumns
72 /// for RowLoop.Index = 0..NumRows
73 /// for InnerLoop.Index = 0..NumInner
76 LoopInfo &LI);
77
78private:
79 /// Creates a new loop with header, body and latch blocks that iterates from
80 /// [0, Bound). Updates \p Preheader to branch to the new header and uses \p
81 /// Exit as exit block. Adds the new loop blocks to \L and applies dominator
82 /// tree updates to \p DTU.
83 static BasicBlock *CreateLoop(BasicBlock *Preheader, BasicBlock *Exit,
84 ConstantInt *Bound, ConstantInt *Step,
86 DomTreeUpdater &DTU, Loop *L, LoopInfo &LI);
87};
88} // namespace llvm
89
90#endif
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
LLVM Basic Block Representation.
Definition BasicBlock.h:62
This is the shared class of boolean and integer constants.
Definition Constants.h:87
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
Represents a single loop in the control flow graph.
Definition LoopInfo.h:40
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
Properties of a single loop used when generating the tiled loop nest.
Definition MatrixUtils.h:47
BasicBlock * Header
The header and latch of the loop.
Definition MatrixUtils.h:51
Value * Index
The index updated on every iteration.
Definition MatrixUtils.h:49
unsigned NumInner
Number of columns of the first matrix of a multiply / number of rows of the second matrix of a multip...
Definition MatrixUtils.h:41
MatrixLoop ColumnLoop
The loop iterating on the columns.
Definition MatrixUtils.h:58
MatrixLoop RowLoop
The loop iterating on the rows.
Definition MatrixUtils.h:56
unsigned NumRows
Number of rows of the matrix.
Definition MatrixUtils.h:34
BasicBlock * CreateTiledLoops(BasicBlock *Start, BasicBlock *End, IRBuilderBase &B, DomTreeUpdater &DTU, LoopInfo &LI)
Creates an IR loop nests for tiling of the form below.
unsigned NumColumns
Number of columns of the matrix.
Definition MatrixUtils.h:37
TileInfo(unsigned NumRows, unsigned NumColumns, unsigned NumInner, unsigned TileSize)
Definition MatrixUtils.h:62
unsigned TileSize
Number of rows/columns in a tile.
Definition MatrixUtils.h:44
MatrixLoop KLoop
The loop iterating on k (inner dimension).
Definition MatrixUtils.h:60