Skip to content

[AMDGPU][NFC] Extend PredicateControl to support True16 predicates. #82245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions llvm/lib/Target/AMDGPU/AMDGPU.td
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
include "llvm/TableGen/SearchableTable.td"
include "llvm/Target/Target.td"
include "AMDGPUFeatures.td"
include "AMDGPUPredicateControl.td"

def p0 : PtrValueType<i64, 0>;
def p1 : PtrValueType<i64, 1>;
Expand Down Expand Up @@ -1895,10 +1896,10 @@ def NotHasTrue16BitInsts : Predicate<"!Subtarget->hasTrue16BitInsts()">;
// True16 instructions as they are defined in the ISA. Fake True16
// instructions have the same encoding as real ones but syntactically
// only allow 32-bit registers in operands and use low halves thereof.
def UseRealTrue16Insts : Predicate<"Subtarget->useRealTrue16Insts()">,
def UseRealTrue16Insts : True16PredicateClass<"Subtarget->useRealTrue16Insts()">,
AssemblerPredicate<(all_of FeatureTrue16BitInsts, FeatureRealTrue16Insts)>;
def UseFakeTrue16Insts : Predicate<"Subtarget->hasTrue16BitInsts() && "
"!Subtarget->useRealTrue16Insts()">;
def UseFakeTrue16Insts : True16PredicateClass<"Subtarget->hasTrue16BitInsts() && "
"!Subtarget->useRealTrue16Insts()">;

def HasVOP3PInsts : Predicate<"Subtarget->hasVOP3PInsts()">,
AssemblerPredicate<(all_of FeatureVOP3P)>;
Expand Down
22 changes: 0 additions & 22 deletions llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,11 @@ class ILFormat<dag outs, dag ins, string asmstr, list<dag> pattern>
let isCodeGenOnly = 1;
}

def TruePredicate : Predicate<"">;

// FIXME: Tablegen should specially supports this
def FalsePredicate : Predicate<"false">;

// Add a predicate to the list if does not already exist to deduplicate it.
class PredConcat<list<Predicate> lst, Predicate pred> {
list<Predicate> ret = !listconcat(lst, !listremove([pred], lst));
}

// Get the union of two Register lists
class RegListUnion<list<Register> lstA, list<Register> lstB> {
list<Register> ret = !listconcat(lstA, !listremove(lstB, lstA));
}

class PredicateControl {
Predicate SubtargetPredicate = TruePredicate;
Predicate AssemblerPredicate = TruePredicate;
Predicate WaveSizePredicate = TruePredicate;
list<Predicate> OtherPredicates = [];
list<Predicate> Predicates = PredConcat<
PredConcat<PredConcat<OtherPredicates,
SubtargetPredicate>.ret,
AssemblerPredicate>.ret,
WaveSizePredicate>.ret;
}

class AMDGPUPat<dag pattern, dag result> : Pat<pattern, result>,
PredicateControl, GISelFlags;

Expand Down
36 changes: 36 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUPredicateControl.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===-- AMDGPUPredicateControl.td --------------------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

def TruePredicate : Predicate<"">;

// FIXME: Tablegen should specially supports this
def FalsePredicate : Predicate<"false">;

// Add a predicate to the list if does not already exist to deduplicate it.
class PredConcat<Predicate pred, list<Predicate> lst> {
list<Predicate> ret = !listconcat(lst, !listremove([pred], lst));
}

// Prevent using other kinds of predicates where True16 predicates are
// expected by giving them their own class.
class True16PredicateClass<string cond> : Predicate<cond>;
def NoTrue16Predicate : True16PredicateClass<"">;

class PredicateControl {
Predicate SubtargetPredicate = TruePredicate;
Predicate AssemblerPredicate = TruePredicate;
Predicate WaveSizePredicate = TruePredicate;
True16PredicateClass True16Predicate = NoTrue16Predicate;
list<Predicate> OtherPredicates = [];
list<Predicate> Predicates =
PredConcat<SubtargetPredicate,
PredConcat<AssemblerPredicate,
PredConcat<WaveSizePredicate,
PredConcat<True16Predicate,
OtherPredicates>.ret>.ret>.ret>.ret;
}
1 change: 1 addition & 0 deletions llvm/lib/Target/AMDGPU/R600.td
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ include "R600Schedule.td"
include "R600Processors.td"
include "R600InstrInfo.td"
include "AMDGPUInstrInfo.td"
include "AMDGPUPredicateControl.td"
include "AMDGPUInstructions.td"
include "R600Instructions.td"
include "R700Instructions.td"
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/VOPInstructions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1484,8 +1484,8 @@ multiclass VOP3_Real_dpp8_with_name<GFXGen Gen, bits<10> op, string opName,
let AsmString = asmName # ps.Pfl.AsmVOP3DPP8,
DecoderNamespace = "DPP8"#Gen.DecoderNamespace#
!if(ps.Pfl.IsRealTrue16, "", "_FAKE16"),
OtherPredicates = !if(ps.Pfl.IsRealTrue16, [UseRealTrue16Insts],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other places in the same file that also need to be taken care of:
VOP3_DPP16_Gen, VOP3_Real_Gen for example.
Do we actually have to introduce True16Predicate?
I think we have already used listconcat to add a new predicate into OtherPredicates list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pasting OtherPredicates could help your particular case, but wouldn't resolve the more general problem of overriding predicates for various groups of instructions and inheriting them from their corresponding pseudos.

The idea is to start using True16Predicate gradually as will seem necessary for future patches.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any examples that we can not use pasting to resolve the overriding issue for OtherPredicates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In real instructions we can paste with OtherPredicates of their pseudos, but there's no way to extend self OtherPredicates of classes and records. So every let OtherPredicates = ... potentially overrides some needed predicates and so having True16Predicate makes it a bit easier to avoid clashes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is Okay to me to introduce True16Predicate if we don't know what is exactly in OtherPredicates when we try to extend it.

[TruePredicate]) in {
True16Predicate = !if(ps.Pfl.IsRealTrue16, UseRealTrue16Insts,
NoTrue16Predicate) in {
defm NAME : VOP3_Real_dpp8_Base<Gen, op, opName>;
}
}
Expand Down