LLVM  14.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 CurrentColumn = 0..NumColumns
29 /// for CurrentRow = 0..NumRows
30 /// for CurrentInner = 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  /// Start row of the current tile to compute.
47 
48  /// Start column of the current tile to compute.
50 
51  /// Current tile offset during the tile computation.
53 
54  /// Header of the outermost loop iterating from 0..NumColumns.
56 
57  /// Header of the second loop iterating from 0..NumRows.
59  /// Latch of the second loop iterating from 0..NumRows.
61  /// Header of the innermost loop iterating from 0..NumInner.
63  /// Latch of the innermost loop iterating from 0..NumInner.
65 
66  TileInfo(unsigned NumRows, unsigned NumColumns, unsigned NumInner,
67  unsigned TileSize)
69  TileSize(TileSize) {}
70 
71  /// Creates an IR loop nests for tiling of the form below. Returns the block
72  /// for the inner loop body and sets {Column,Row,Inner}LoopHeader/Latch
73  /// fields.
74  ///
75  /// for CurrentColumn = 0..NumColumns
76  /// for CurrentRow = 0..NumRows
77  /// for CurrentInner = 0..NumInner
80  LoopInfo &LI);
81 
82 private:
83  /// Creates a new loop with header, body and latch blocks that iterates from
84  /// [0, Bound). Updates \p Preheader to branch to the new header and uses \p
85  /// Exit as exit block. Adds the new loop blocks to \L and applies dominator
86  /// tree updates to \p DTU.
87  static BasicBlock *CreateLoop(BasicBlock *Preheader, BasicBlock *Exit,
88  Value *Bound, Value *Step, StringRef Name,
90  LoopInfo &LI);
91 };
92 } // namespace llvm
93 
94 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::TileInfo::RowLoopLatch
BasicBlock * RowLoopLatch
Latch of the second loop iterating from 0..NumRows.
Definition: MatrixUtils.h:60
llvm::TileInfo::InnerLoopLatch
BasicBlock * InnerLoopLatch
Latch of the innermost loop iterating from 0..NumInner.
Definition: MatrixUtils.h:64
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
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 CurrentColumn = 0...
Definition: MatrixUtils.h:31
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
llvm::TileInfo::TileInfo
TileInfo(unsigned NumRows, unsigned NumColumns, unsigned NumInner, unsigned TileSize)
Definition: MatrixUtils.h:66
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::DomTreeUpdater
Definition: DomTreeUpdater.h:28
llvm::TileInfo::NumRows
unsigned NumRows
Number of rows of the matrix.
Definition: MatrixUtils.h:33
llvm::TileInfo::CurrentCol
Value * CurrentCol
Start column of the current tile to compute.
Definition: MatrixUtils.h:49
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::TileInfo::InnerLoopHeader
BasicBlock * InnerLoopHeader
Header of the innermost loop iterating from 0..NumInner.
Definition: MatrixUtils.h:62
llvm::TileInfo::RowLoopHeader
BasicBlock * RowLoopHeader
Header of the second loop iterating from 0..NumRows.
Definition: MatrixUtils.h:58
llvm::LoopInfo
Definition: LoopInfo.h:1083
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::IRBuilderBase
Common base class shared among various IRBuilders.
Definition: IRBuilder.h:95
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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::CurrentRow
Value * CurrentRow
Start row of the current tile to compute.
Definition: MatrixUtils.h:46
llvm::TileInfo::ColumnLoopHeader
BasicBlock * ColumnLoopHeader
Header of the outermost loop iterating from 0..NumColumns.
Definition: MatrixUtils.h:55
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::TileInfo::CurrentK
Value * CurrentK
Current tile offset during the tile computation.
Definition: MatrixUtils.h:52
llvm::Value
LLVM Value Representation.
Definition: Value.h:74