| 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_REGSET_HPP |
| 10 |
#define _IGA_IR_REGSET_HPP |
| 11 |
|
| 12 |
// Future replacement for RegDeps(.cpp/.hpp) |
| 13 |
// Need to decouple machine state logic from the dependency set. |
| 14 |
|
| 15 |
#include "BitSet.hpp" |
| 16 |
#include "Instruction.hpp" |
| 17 |
#include "Kernel.hpp" |
| 18 |
|
| 19 |
#include <ostream> |
| 20 |
#include <string> |
| 21 |
|
| 22 |
namespace iga { |
| 23 |
// A register set represent all the storage in the register files |
| 24 |
// at a certain granularity (currently typically byte). |
| 25 |
// |
| 26 |
class RegSet { |
| 27 |
public: |
| 28 |
using Bits = BitSet<>; |
| 29 |
// TODO: |
| 30 |
// using Bits = FlexibleBitSet |
| 31 |
private: |
| 32 |
Bits *bitSetForPtr(RegName rn); |
| 33 |
|
| 34 |
public: |
| 35 |
Bits &bitSetFor(RegName rn); |
| 36 |
const Bits &bitSetFor(RegName rn) const; |
| 37 |
|
| 38 |
private: |
| 39 |
size_t offsetOf(RegName rn, int reg) const; |
| 40 |
size_t offsetOf(RegName rn, RegRef rr, size_t typeSize) const; |
| 41 |
size_t offsetOf(RegName rn, RegRef rr, Type t) const; |
| 42 |
bool isTrackedReg(RegName rn) const; |
| 43 |
|
| 44 |
public: |
| 45 |
~RegSet() = default; |
| 46 |
RegSet(const Model &m); |
| 47 |
RegSet(const RegSet &rs); |
| 48 |
RegSet &operator=(const RegSet &); |
| 49 |
|
| 50 |
const Model &getModel() const { return model; } |
| 51 |
|
| 52 |
bool operator==(const RegSet &rs) const; |
| 53 |
bool operator!=(const RegSet &rs) const { return !(*this == rs); } |
| 54 |
|
| 55 |
/////////////////////////////////////////////////////////////////////// |
| 56 |
// set operations |
| 57 |
bool empty() const; |
| 58 |
void reset(); |
| 59 |
bool intersects(const RegSet &rhs) const; |
| 60 |
// bool containsAll(const RegSet &rhs) const; |
| 61 |
bool destructiveUnion(const RegSet &inp); |
| 62 |
bool destructiveSubtract(const RegSet &rhs); |
| 63 |
bool intersectInto(const RegSet &rhs, RegSet &into) const; |
| 64 |
|
| 65 |
/////////////////////////////////////////////////////////////////////// |
| 66 |
// generic add functions |
| 67 |
bool addReg(RegName rn, int reg); |
| 68 |
bool addRegs(RegName rn, int reg, int n = 1); |
| 69 |
bool add(RegName rn, size_t regFileOffBits, size_t numBits); |
| 70 |
bool add(RegName rn, RegRef r, Type t); |
| 71 |
|
| 72 |
// for pred or condmod |
| 73 |
bool addFlagRegArf(RegRef fr, ExecSize es, ChannelOffset co); |
| 74 |
|
| 75 |
/////////////////////////////////////////////////////////////////////// |
| 76 |
// specialized add functions for full instructions |
| 77 |
// |
| 78 |
// all the source inputs (including implicit acc), excluding predicate |
| 79 |
bool addSourceInputs(const Instruction &i); |
| 80 |
// |
| 81 |
// just the predicate |
| 82 |
bool addPredicationInputs(const Instruction &i); |
| 83 |
// |
| 84 |
// just operand 'srcIx' |
| 85 |
bool addSourceOperandInput(const Instruction &i, int srcIx); |
| 86 |
// |
| 87 |
// implicit sources such as acc or flag register in a select |
| 88 |
bool addSourceImplicit(const Instruction &i); |
| 89 |
// |
| 90 |
// just send descriptor inputs |
| 91 |
bool addSourceDescriptorInputs(const Instruction &i); |
| 92 |
// |
| 93 |
// just uses of a0 as part of an indirect register access |
| 94 |
bool addDestinationInputs(const Instruction &i); // register indirect |
| 95 |
// |
| 96 |
////////////////////// |
| 97 |
// destination outputs including acc, but excluding predicate (flagmod) |
| 98 |
bool addDestinationOutputs(const Instruction &i); |
| 99 |
// |
| 100 |
// just the destination operand omitting acc |
| 101 |
bool addExplicitDestinationOutputs(const Instruction &i); |
| 102 |
// |
| 103 |
// just the conditional modifier |
| 104 |
bool addFlagModifierOutputs(const Instruction &i); |
| 105 |
// |
| 106 |
// implicit destinations such as acc |
| 107 |
bool addDestinationImplicit(const Instruction &i); |
| 108 |
|
| 109 |
////////////////////////////////////// |
| 110 |
// both source and destination can cover to this |
| 111 |
bool addImplicitAccumulatorAccess(const Instruction &i, bool isDst); |
| 112 |
|
| 113 |
// both predicates and flag modifiers can cover to this |
| 114 |
bool addFlagAccess(const Instruction &i); |
| 115 |
|
| 116 |
/////////////////////////////////////// |
| 117 |
// helpers for operand regions |
| 118 |
bool setDstRegion(RegName rn, RegRef rr, Region r, size_t execSize, |
| 119 |
size_t typeSizeBits); |
| 120 |
bool setSrcRegion(RegName rn, RegRef rr, Region r, size_t execSize, |
| 121 |
size_t typeSizeBits); |
| 122 |
|
| 123 |
void str(std::ostream &os) const; |
| 124 |
std::string str() const; |
| 125 |
|
| 126 |
static std::string str(const Model &m, RegName rn, const RegSet::Bits &bs); |
| 127 |
|
| 128 |
static RegSet unionOf(const RegSet &r1, const RegSet &r2) { |
| 129 |
RegSet r12(r1.model); |
| 130 |
(void)r12.destructiveUnion(r1); |
| 131 |
(void)r12.destructiveUnion(r2); |
| 132 |
return r12; |
| 133 |
} |
| 134 |
static RegSet::Bits emptyPredSet(const Model &model); |
| 135 |
static RegSet intersection(const RegSet &rs1, const RegSet &rs2) { |
| 136 |
IGA_ASSERT(&rs1.model == &rs2.model, "model mismatch"); |
| 137 |
RegSet rsI(rs1.model); |
| 138 |
rs1.intersectInto(rs2, rsI); |
| 139 |
return rsI; |
| 140 |
} |
| 141 |
|
| 142 |
private: |
| 143 |
bool addSendOperand(const Instruction &i, int srcIx); |
| 144 |
bool addDpasOperand(const Instruction &i, int srcIx); |
| 145 |
|
| 146 |
private: |
| 147 |
const Model &model; |
| 148 |
Bits bitsR; |
| 149 |
Bits bitsA; |
| 150 |
Bits bitsAcc; |
| 151 |
Bits bitsF; |
| 152 |
Bits bitsS; |
| 153 |
}; |
| 154 |
|
| 155 |
struct InstSrcs { |
| 156 |
RegSet predication; |
| 157 |
RegSet sources; |
| 158 |
InstSrcs(const Model &m) : predication(m), sources(m) {} |
| 159 |
|
| 160 |
RegSet unionOf() const { return RegSet::unionOf(predication, sources); } |
| 161 |
bool empty() const { return predication.empty() && sources.empty(); } |
| 162 |
std::string str() const { return unionOf().str(); } |
| 163 |
|
| 164 |
static InstSrcs compute(const Instruction &i); |
| 165 |
}; |
| 166 |
struct InstDsts { |
| 167 |
RegSet flagModifier; |
| 168 |
RegSet destinations; |
| 169 |
|
| 170 |
InstDsts(const Model &m) : flagModifier(m), destinations(m) {} |
| 171 |
|
| 172 |
RegSet unionOf() const { return RegSet::unionOf(flagModifier, destinations); } |
| 173 |
bool subtractFrom(RegSet &rs) const { |
| 174 |
bool changed = false; |
| 175 |
changed |= rs.destructiveSubtract(flagModifier); |
| 176 |
changed |= rs.destructiveSubtract(destinations); |
| 177 |
return changed; |
| 178 |
} |
| 179 |
bool empty() const { return flagModifier.empty() && destinations.empty(); } |
| 180 |
std::string str() const { return unionOf().str(); } |
| 181 |
|
| 182 |
static InstDsts compute(const Instruction &i); |
| 183 |
}; |
| 184 |
|
| 185 |
inline InstSrcs InstSrcs::compute(const Instruction &i) { |
| 186 |
InstSrcs iss(Model::LookupModelRef(i.platform())); |
| 187 |
iss.predication.addPredicationInputs(i); |
| 188 |
iss.sources.addSourceInputs(i); |
| 189 |
return iss; |
| 190 |
} |
| 191 |
inline InstDsts InstDsts::compute(const Instruction &i) { |
| 192 |
InstDsts ids(Model::LookupModelRef(i.platform())); |
| 193 |
ids.destinations.reset(); |
| 194 |
ids.flagModifier.addFlagModifierOutputs(i); |
| 195 |
ids.destinations.addDestinationOutputs(i); |
| 196 |
return ids; |
| 197 |
} |
| 198 |
} // namespace iga |
| 199 |
|
| 200 |
#endif // _IGA_IR_REGSET_HPP |