Skip to content

Commit 084cdd0

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 9a27517 commit 084cdd0

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;
@@ -322,6 +334,9 @@ class DXILOp<int opcode, DXILOpClass opclass> {
322334

323335
// Versioned attributes of operation
324336
list<Attributes> attributes = [];
337+
338+
// List of properties. Default to no properties.
339+
list<DXILProperty> properties = [];
325340
}
326341

327342
// 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
@@ -42,6 +42,7 @@ struct DXILOperationDesc {
4242
SmallVector<const Record *> OverloadRecs;
4343
SmallVector<const Record *> StageRecs;
4444
SmallVector<const Record *> AttrRecs;
45+
SmallVector<const Record *> PropRecs;
4546
StringRef Intrinsic; // The llvm intrinsic map to OpName. Default is "" which
4647
// means no map exists
4748
SmallVector<StringRef, 4>
@@ -149,6 +150,13 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
149150
AttrRecs.push_back(CR);
150151
}
151152

153+
Recs = R->getValueAsListOfDefs("properties");
154+
155+
// Get property records
156+
for (const Record *CR : Recs) {
157+
PropRecs.push_back(CR);
158+
}
159+
152160
// Get the operation class
153161
OpClass = R->getValueAsDef("OpClass")->getName();
154162

@@ -318,6 +326,28 @@ static std::string getAttributeListString(ArrayRef<const Record *> Recs) {
318326
return ListString;
319327
}
320328

329+
/// Return a string representation of valid property information denoted
330+
// by input records
331+
//
332+
/// \param Recs A vector of records of TableGen Property records
333+
/// \return std::string string representation of properties list string
334+
// {Attr1, Attr2, ...}
335+
static std::string getPropertyListString(ArrayRef<const Record *> Recs) {
336+
std::string ListString = "";
337+
std::string Prefix = "";
338+
ListString.append("{");
339+
340+
std::string CommaPrefix = "";
341+
for (const auto *Rec : Recs) {
342+
ListString.append(CommaPrefix)
343+
.append("dxil::Property::")
344+
.append(Rec->getName());
345+
CommaPrefix = ", ";
346+
}
347+
ListString.append("}");
348+
return ListString;
349+
}
350+
321351
/// Emit a mapping of DXIL opcode to opname
322352
static void emitDXILOpCodes(ArrayRef<DXILOperationDesc> Ops, raw_ostream &OS) {
323353
OS << "#ifdef DXIL_OPCODE\n";
@@ -356,6 +386,30 @@ static void emitDXILAttributes(const RecordKeeper &Records, raw_ostream &OS) {
356386
OS << "#endif\n\n";
357387
}
358388

389+
/// Emit a list of DXIL op properties and their query functions
390+
static void emitDXILProperties(const RecordKeeper &Records, raw_ostream &OS) {
391+
// Generate their definitions
392+
OS << "#ifdef DXIL_PROPERTY\n";
393+
for (const Record *Prop: Records.getAllDerivedDefinitions("DXILProperty"))
394+
OS << "DXIL_PROPERTY(" << Prop->getName() << ")\n";
395+
OS << "#undef DXIL_PROPERTY\n";
396+
OS << "#endif\n\n";
397+
}
398+
399+
static void emitDXILPropertyHelpers(const RecordKeeper &Records, raw_ostream &OS) {
400+
// Generate their helper functions
401+
for (const Record *Prop: Records.getAllDerivedDefinitions("DXILProperty")) {
402+
OS << "[[maybe_unused]]\n";
403+
OS << "static bool has" << Prop->getName() << "(dxil::OpCode Op) {\n";
404+
OS << " auto *OpCodeProp = getOpCodeProperty(Op);\n";
405+
OS << " for (auto Prop : OpCodeProp->Properties)\n";
406+
OS << " if (Prop == dxil::Property::" << Prop->getName() << ")\n";
407+
OS << " return true;\n";
408+
OS << " return false;\n";
409+
OS << "}\n\n";
410+
}
411+
}
412+
359413
/// Emit a list of DXIL op function types
360414
static void emitDXILOpFunctionTypes(ArrayRef<DXILOperationDesc> Ops,
361415
raw_ostream &OS) {
@@ -426,7 +480,8 @@ static void emitDXILOperationTable(ArrayRef<DXILOperationDesc> Ops,
426480
<< OpClassStrings.get(Op.OpClass.data()) << ", "
427481
<< getOverloadMaskString(Op.OverloadRecs) << ", "
428482
<< getStageMaskString(Op.StageRecs) << ", "
429-
<< getAttributeListString(Op.AttrRecs) << ", " << Op.OverloadParamIndex
483+
<< getAttributeListString(Op.AttrRecs) << ", "
484+
<< getPropertyListString(Op.PropRecs) << ", " << Op.OverloadParamIndex
430485
<< " }";
431486
Prefix = ",\n";
432487
}
@@ -532,11 +587,13 @@ static void emitDxilOperation(const RecordKeeper &Records, raw_ostream &OS) {
532587
emitDXILOpClasses(Records, OS);
533588
emitDXILOpParamTypes(Records, OS);
534589
emitDXILAttributes(Records, OS);
590+
emitDXILProperties(Records, OS);
535591
emitDXILOpFunctionTypes(DXILOps, OS);
536592
emitDXILIntrinsicMap(DXILOps, OS);
537593
OS << "#ifdef DXIL_OP_OPERATION_TABLE\n\n";
538594
emitDXILOperationTableDataStructs(Records, OS);
539595
emitDXILOperationTable(DXILOps, OS);
596+
emitDXILPropertyHelpers(Records, OS);
540597
OS << "#undef DXIL_OP_OPERATION_TABLE\n";
541598
OS << "#endif\n\n";
542599
}

0 commit comments

Comments
 (0)