Skip to content

Commit

Permalink
[TBLGEN] Allow to override RC weight
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D74509
  • Loading branch information
rampitec committed Feb 14, 2020
1 parent 2504f14 commit 922197d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 20 deletions.
7 changes: 7 additions & 0 deletions llvm/include/llvm/Target/Target.td
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ class RegisterClass<string namespace, list<ValueType> regTypes, int alignment,
// constrained classes first. The value has to be in the range [0,63].
int AllocationPriority = 0;

// Weight override for register pressure calculation. This is the value
// TargetRegisterClass::getRegClassWeight() will return. The weight is in
// units of pressure for this register class. If unset tablegen will
// calculate a weight based on a number of register units in this register
// class registers. The weight is per register.
int Weight = ?;

// The diagnostic type to present when referencing this operand in a match
// failure error message. If this is empty, the default Match_InvalidOperand
// diagnostic type will be used. If this is "<name>", a Match_<name> enum
Expand Down
10 changes: 0 additions & 10 deletions llvm/lib/Target/AMDGPU/R600RegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

using namespace llvm;

R600RegisterInfo::R600RegisterInfo() : R600GenRegisterInfo(0) {
RCW.RegWeight = 0;
RCW.WeightLimit = 0;
}

#define GET_REGINFO_TARGET_DESC
#include "R600GenRegisterInfo.inc"

Expand Down Expand Up @@ -99,11 +94,6 @@ const TargetRegisterClass * R600RegisterInfo::getCFGStructurizerRegClass(
}
}

const RegClassWeight &R600RegisterInfo::getRegClassWeight(
const TargetRegisterClass *RC) const {
return RCW;
}

bool R600RegisterInfo::isPhysRegLiveAcrossClauses(unsigned Reg) const {
assert(!Register::isVirtualRegister(Reg));

Expand Down
7 changes: 1 addition & 6 deletions llvm/lib/Target/AMDGPU/R600RegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
namespace llvm {

struct R600RegisterInfo final : public R600GenRegisterInfo {
RegClassWeight RCW;

R600RegisterInfo();
R600RegisterInfo() : R600GenRegisterInfo(0) {}

/// \returns the sub reg enum value for the given \p Channel
/// (e.g. getSubRegFromChannel(0) -> R600::sub0)
Expand All @@ -41,9 +39,6 @@ struct R600RegisterInfo final : public R600GenRegisterInfo {
/// CFGStructurizer
const TargetRegisterClass *getCFGStructurizerRegClass(MVT VT) const;

const RegClassWeight &
getRegClassWeight(const TargetRegisterClass *RC) const override;

bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override {
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/AMDGPU/R600RegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,16 @@ def AR_X : R600Reg<"AR.x", 0>;
def INDIRECT_BASE_ADDR : R600Reg <"INDIRECT_BASE_ADDR", 0>;

def R600_ArrayBase : RegisterClass <"AMDGPU", [f32, i32], 32,
(add (sequence "ArrayBase%u", 448, 480))>;
(add (sequence "ArrayBase%u", 448, 480))> {
let Weight = 0;
}
// special registers for ALU src operands
// const buffer reference, SRCx_SEL contains index
def ALU_CONST : R600Reg<"CBuf", 0>;
// interpolation param reference, SRCx_SEL contains index
def ALU_PARAM : R600Reg<"Param", 0>;

let Weight = 0 in {
let isAllocatable = 0 in {

def R600_Addr : RegisterClass <"AMDGPU", [i32], 32, (add (sequence "Addr%u_X", 0, 127))>;
Expand Down Expand Up @@ -251,3 +254,4 @@ def R600_Reg64 : RegisterClass<"AMDGPU", [v2f32, v2i32, i64, f64], 64,
def R600_Reg64Vertical : RegisterClass<"AMDGPU", [v2f32, v2i32], 64,
(add V01_X, V01_Y, V01_Z, V01_W,
V23_X, V23_Y, V23_Z, V23_W)>;
} // End let Weight = 0
24 changes: 24 additions & 0 deletions llvm/test/TableGen/rc-weight-override.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: llvm-tblgen -gen-register-info -I %p/../../include -I %p/Common %s | FileCheck %s

include "reg-with-subregs-common.td"

// CHECK-LABEL: static const RegClassWeight RCWeightTable[] = {
// CHECK: {1, 256}, // GPR32
// CHECK: {2, 256}, // GPR_64

// CHECK: {0, 256}, // GPR_64_W0
def GPR_64_W0 : RegisterClass<"", [v2i32], 64, (add GPR64)> {
let Weight = 0;
}

// CHECK: {1, 256}, // GPR_64_W1
def GPR_64_W1 : RegisterClass<"", [v2i32], 64, (add GPR64)> {
let Weight = 1;
}

// CHECK: {8, 256}, // GPR_64_W8
def GPR_64_W8 : RegisterClass<"", [v2i32], 64, (add GPR64)> {
let Weight = 8;
}

// CHECK: {32, 256}, // GPR_1024
10 changes: 10 additions & 0 deletions llvm/utils/TableGen/CodeGenRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,16 @@ bool CodeGenRegisterClass::contains(const CodeGenRegister *Reg) const {
deref<std::less<>>());
}

unsigned CodeGenRegisterClass::getWeight(const CodeGenRegBank& RegBank) const {
if (TheDef && !TheDef->isValueUnset("Weight"))
return TheDef->getValueAsInt("Weight");

if (Members.empty() || Artificial)
return 0;

return (*Members.begin())->getWeight(RegBank);
}

namespace llvm {

raw_ostream &operator<<(raw_ostream &OS, const CodeGenRegisterClass::Key &K) {
Expand Down
3 changes: 3 additions & 0 deletions llvm/utils/TableGen/CodeGenRegisters.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ namespace llvm {
// Get a bit vector of TopoSigs present in this register class.
const BitVector &getTopoSigs() const { return TopoSigs; }

// Get a weight of this register class.
unsigned getWeight(const CodeGenRegBank&) const;

// Populate a unique sorted list of units from a register set.
void buildRegUnitSet(const CodeGenRegBank &RegBank,
std::vector<unsigned> &RegUnits) const;
Expand Down
6 changes: 3 additions & 3 deletions llvm/utils/TableGen/RegisterInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ EmitRegUnitPressure(raw_ostream &OS, const CodeGenRegBank &RegBank,
<< " static const RegClassWeight RCWeightTable[] = {\n";
for (const auto &RC : RegBank.getRegClasses()) {
const CodeGenRegister::Vec &Regs = RC.getMembers();
OS << " {" << RC.getWeight(RegBank) << ", ";
if (Regs.empty() || RC.Artificial)
OS << " {0, 0";
OS << '0';
else {
std::vector<unsigned> RegUnits;
RC.buildRegUnitSet(RegBank, RegUnits);
OS << " {" << (*Regs.begin())->getWeight(RegBank)
<< ", " << RegBank.getRegUnitSetWeight(RegUnits);
OS << RegBank.getRegUnitSetWeight(RegUnits);
}
OS << "}, \t// " << RC.getName() << "\n";
}
Expand Down

0 comments on commit 922197d

Please sign in to comment.