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