Skip to content

Commit fd5dbce

Browse files
committed
define DXILProperty for queryable attributes
- define these properties in DXIL.td and DXILConstants.h - emit DXIL definitions as enumerations - emit some helper functions to query OpCodeProp for each property class
1 parent fde0d22 commit fd5dbce

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,18 @@ def ReadOnly : DXILAttribute;
279279
def NoDuplicate : DXILAttribute;
280280
def NoReturn : DXILAttribute;
281281

282+
// A property is simply used to mark a DXIL op belongs to a sub-group of
283+
// DXIL ops, and it is used to query if a particular holds this property.
284+
// This is used for static analysis of DXIL ops.
285+
class DXILProperty;
286+
287+
def IsBarrier : DXILProperty;
288+
def IsDerivative : DXILProperty;
289+
def IsGradient : DXILProperty;
290+
def IsFeedback : DXILProperty;
291+
def IsWave : DXILProperty;
292+
def RequiresUniformInputs : DXILProperty;
293+
282294
class Overloads<Version ver, list<DXILOpParamType> ols> {
283295
Version dxil_version = ver;
284296
list<DXILOpParamType> overload_types = ols;
@@ -376,6 +388,9 @@ class DXILOp<int opcode, DXILOpClass opclass> {
376388

377389
// Versioned attributes of operation
378390
list<Attributes> attributes = [];
391+
392+
// List of properties. Default to no properties.
393+
list<DXILProperty> properties = [];
379394
}
380395

381396
// Concrete definitions of DXIL Operations

llvm/lib/Target/DirectX/DXILConstants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ enum class Attribute : unsigned {
3535
#include "DXILOperation.inc"
3636
};
3737

38+
enum class Property : unsigned {
39+
#define DXIL_PROPERTY(Name) Name,
40+
#include "DXILOperation.inc"
41+
};
42+
3843
} // namespace dxil
3944
} // namespace llvm
4045

llvm/lib/Target/DirectX/DXILOpBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct OpCodeProperty {
159159
llvm::SmallVector<OpOverload> Overloads;
160160
llvm::SmallVector<OpStage> Stages;
161161
llvm::SmallVector<OpAttribute> Attributes;
162+
llvm::SmallVector<dxil::Property> Properties;
162163
int OverloadParamIndex; // parameter index which control the overload.
163164
// When < 0, should be only 1 overload type.
164165
};

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct DXILOperationDesc {
5656
SmallVector<const Record *> OverloadRecs;
5757
SmallVector<const Record *> StageRecs;
5858
SmallVector<const Record *> AttrRecs;
59+
SmallVector<const Record *> PropRecs;
5960
SmallVector<DXILIntrinsicSelect> IntrinsicSelects;
6061
SmallVector<StringRef, 4>
6162
ShaderStages; // shader stages to which this applies, empty for all.
@@ -177,6 +178,13 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
177178
AttrRecs.push_back(CR);
178179
}
179180

181+
Recs = R->getValueAsListOfDefs("properties");
182+
183+
// Get property records
184+
for (const Record *CR : Recs) {
185+
PropRecs.push_back(CR);
186+
}
187+
180188
// Get the operation class
181189
OpClass = R->getValueAsDef("OpClass")->getName();
182190

@@ -348,6 +356,28 @@ static std::string getAttributeListString(ArrayRef<const Record *> Recs) {
348356
return ListString;
349357
}
350358

359+
/// Return a string representation of valid property information denoted
360+
// by input records
361+
//
362+
/// \param Recs A vector of records of TableGen Property records
363+
/// \return std::string string representation of properties list string
364+
// {Attr1, Attr2, ...}
365+
static std::string getPropertyListString(ArrayRef<const Record *> Recs) {
366+
std::string ListString = "";
367+
std::string Prefix = "";
368+
ListString.append("{");
369+
370+
std::string CommaPrefix = "";
371+
for (const auto *Rec : Recs) {
372+
ListString.append(CommaPrefix)
373+
.append("dxil::Property::")
374+
.append(Rec->getName());
375+
CommaPrefix = ", ";
376+
}
377+
ListString.append("}");
378+
return ListString;
379+
}
380+
351381
/// Emit a mapping of DXIL opcode to opname
352382
static void emitDXILOpCodes(ArrayRef<DXILOperationDesc> Ops, raw_ostream &OS) {
353383
OS << "#ifdef DXIL_OPCODE\n";
@@ -386,6 +416,30 @@ static void emitDXILAttributes(const RecordKeeper &Records, raw_ostream &OS) {
386416
OS << "#endif\n\n";
387417
}
388418

419+
/// Emit a list of DXIL op properties and their query functions
420+
static void emitDXILProperties(const RecordKeeper &Records, raw_ostream &OS) {
421+
// Generate their definitions
422+
OS << "#ifdef DXIL_PROPERTY\n";
423+
for (const Record *Prop: Records.getAllDerivedDefinitions("DXILProperty"))
424+
OS << "DXIL_PROPERTY(" << Prop->getName() << ")\n";
425+
OS << "#undef DXIL_PROPERTY\n";
426+
OS << "#endif\n\n";
427+
}
428+
429+
static void emitDXILPropertyHelpers(const RecordKeeper &Records, raw_ostream &OS) {
430+
// Generate their helper functions
431+
for (const Record *Prop: Records.getAllDerivedDefinitions("DXILProperty")) {
432+
OS << "[[maybe_unused]]\n";
433+
OS << "static bool has" << Prop->getName() << "(dxil::OpCode Op) {\n";
434+
OS << " auto *OpCodeProp = getOpCodeProperty(Op);\n";
435+
OS << " for (auto Prop : OpCodeProp->Properties)\n";
436+
OS << " if (Prop == dxil::Property::" << Prop->getName() << ")\n";
437+
OS << " return true;\n";
438+
OS << " return false;\n";
439+
OS << "}\n\n";
440+
}
441+
}
442+
389443
/// Emit a list of DXIL op function types
390444
static void emitDXILOpFunctionTypes(ArrayRef<DXILOperationDesc> Ops,
391445
raw_ostream &OS) {
@@ -482,7 +536,8 @@ static void emitDXILOperationTable(ArrayRef<DXILOperationDesc> Ops,
482536
<< OpClassStrings.get(Op.OpClass.data()) << ", "
483537
<< getOverloadMaskString(Op.OverloadRecs) << ", "
484538
<< getStageMaskString(Op.StageRecs) << ", "
485-
<< getAttributeListString(Op.AttrRecs) << ", " << Op.OverloadParamIndex
539+
<< getAttributeListString(Op.AttrRecs) << ", "
540+
<< getPropertyListString(Op.PropRecs) << ", " << Op.OverloadParamIndex
486541
<< " }";
487542
Prefix = ",\n";
488543
}
@@ -588,12 +643,14 @@ static void emitDxilOperation(const RecordKeeper &Records, raw_ostream &OS) {
588643
emitDXILOpClasses(Records, OS);
589644
emitDXILOpParamTypes(Records, OS);
590645
emitDXILAttributes(Records, OS);
646+
emitDXILProperties(Records, OS);
591647
emitDXILOpFunctionTypes(DXILOps, OS);
592648
emitDXILIntrinsicArgSelectTypes(Records, OS);
593649
emitDXILIntrinsicMap(DXILOps, OS);
594650
OS << "#ifdef DXIL_OP_OPERATION_TABLE\n\n";
595651
emitDXILOperationTableDataStructs(Records, OS);
596652
emitDXILOperationTable(DXILOps, OS);
653+
emitDXILPropertyHelpers(Records, OS);
597654
OS << "#undef DXIL_OP_OPERATION_TABLE\n";
598655
OS << "#endif\n\n";
599656
}

0 commit comments

Comments
 (0)