| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2017-2021 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
#ifndef _IGA_IR_DUANALYSIS_HPP |
| 10 |
#define _IGA_IR_DUANALYSIS_HPP |
| 11 |
|
| 12 |
#include "../IR/Kernel.hpp" |
| 13 |
#include "../IR/RegSet.hpp" |
| 14 |
|
| 15 |
#include <ostream> |
| 16 |
#include <string> |
| 17 |
#include <vector> |
| 18 |
|
| 19 |
namespace iga { |
| 20 |
// A live range is a path from a definition of some register values to |
| 21 |
// a use. The use may be a read (typical case) or a write (since we need |
| 22 |
// to be able to track WAW dependencies). |
| 23 |
struct Dep { |
| 24 |
// |
| 25 |
// The producer instruction; |
| 26 |
// this can be nullptr if the value is a program input |
| 27 |
Instruction *def = nullptr; |
| 28 |
// |
| 29 |
// The consumer instruction; |
| 30 |
// this can be nullptr if the value is a program output |
| 31 |
Instruction *use = nullptr; |
| 32 |
// |
| 33 |
// The register values that are live in this path |
| 34 |
RegSet values; |
| 35 |
// |
| 36 |
// The minimum number of instructions this path covers |
| 37 |
int minInsts = 0; |
| 38 |
// |
| 39 |
// The minimum number of instructions this path covers in the same |
| 40 |
// pipe as the def pipe (or 0 if there is no def). |
| 41 |
// int minInstsDefPipe = 0; |
| 42 |
// Need to account syncs in between |
| 43 |
// |
| 44 |
// indicates if the dependency crosses a branch (JEU) |
| 45 |
// N.b. this will false for fallthrough since that isn't a branch |
| 46 |
// mov r1 ... |
| 47 |
// (f0.0) jmpi TARGET |
| 48 |
// add ... r1 // crossesBranch = false here |
| 49 |
// TARGET: |
| 50 |
// mul ... r1 // crossesBranch = true here |
| 51 |
bool crossesBranch = false; |
| 52 |
// Similar to the above but includes fallthrough |
| 53 |
bool crossesBlock = false; |
| 54 |
|
| 55 |
// Dep(const Model &m) : values(m) { } |
| 56 |
|
| 57 |
Dep(Instruction *_def, const RegSet &_values, Instruction *_use) |
| 58 |
: def(_def), use(_use), values(_values) {} |
| 59 |
Dep(const Dep &) = default; |
| 60 |
Dep &operator=(const Dep &) = default; |
| 61 |
|
| 62 |
bool operator==(const Dep &p) const; |
| 63 |
bool operator!=(const Dep &p) const { return !(*this == p); } |
| 64 |
|
| 65 |
// for debug |
| 66 |
void str(std::ostream &os) const; |
| 67 |
std::string str() const; |
| 68 |
}; |
| 69 |
|
| 70 |
struct LiveCount { |
| 71 |
unsigned grfBytes = 0; // r* |
| 72 |
unsigned scalarBytes = 0; // s0* |
| 73 |
unsigned flagBytes = 0; // f* |
| 74 |
unsigned accBytes = 0; // acc* |
| 75 |
unsigned indexBytes = 0; // a0* |
| 76 |
}; |
| 77 |
|
| 78 |
struct DepAnalysis { |
| 79 |
// |
| 80 |
// relation of definitions and uses |
| 81 |
std::vector<Dep> deps; |
| 82 |
|
| 83 |
// |
| 84 |
// uses without any definition |
| 85 |
std::vector<Dep> liveIn; |
| 86 |
|
| 87 |
// directly maps instruction ID to the live counts there; |
| 88 |
// the counts are for the live sets *before* the instruction is |
| 89 |
// executed |
| 90 |
std::vector<LiveCount> sums; |
| 91 |
|
| 92 |
// number of iterations until reaching the fixed-point |
| 93 |
int iterations = 0; |
| 94 |
}; |
| 95 |
|
| 96 |
// The primary entry point for the live analysis |
| 97 |
// The counts are counts *going into* this instruction |
| 98 |
DepAnalysis ComputeDepAnalysis(const Kernel *k); |
| 99 |
} // namespace iga |
| 100 |
|
| 101 |
#endif // _IGA_IR_ANALYSIS_HPP |