Skip to content

Commit de938df

Browse files
committed
[NFC] review comments:
- update nit from review comments - fix some typos in comments - add additional comments for clarity
1 parent e988056 commit de938df

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,18 @@ def removed : DXILShaderStage;
270270
// DXIL Op attributes
271271

272272
// A function attribute denotes that there is a corresponding LLVM function
273-
// attribute that will be set when building the DXIL op. The mapping for
274-
// non-trivial cases is defined by setDXILAttribute in DXILOpBuilder.cpp
273+
// attribute that will be set when building the DXIL op. The mapping is defined
274+
// by setDXILAttributes in DXILOpBuilder.cpp
275275
class DXILAttribute;
276276

277277
def ReadNone : DXILAttribute;
278278
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.
282+
// A property is simply used to mark that a DXIL op belongs to a sub-group of
283+
// DXIL ops, and it is used to query if a particular op holds this property.
284+
// This is used for the static analysis of DXIL ops.
285285
class DXILProperty;
286286

287287
def IsBarrier : DXILProperty;
@@ -797,6 +797,9 @@ def CreateHandle : DXILOp<57, createHandle> {
797797
let arguments = [Int8Ty, Int32Ty, Int32Ty, Int1Ty];
798798
let result = HandleTy;
799799
let stages = [Stages<DXIL1_0, [all_stages]>, Stages<DXIL1_6, [removed]>];
800+
// NOTE: The ReadOnly attribute was set for consistency with DXC. However, it
801+
// seems like ReadNone may more appropiately describe it. So noted to
802+
// consider a change in the future
800803
let attributes = [Attributes<DXIL1_0, [ReadOnly]>];
801804
}
802805

llvm/lib/Target/DirectX/DXILOpBuilder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,20 @@ static std::optional<size_t> getPropIndex(ArrayRef<T> PropList,
361361
return std::nullopt;
362362
}
363363

364+
// Helper function to pack an OpCode and VersionTuple into a uint64_t for use
365+
// in a switch statement
364366
constexpr static uint64_t computeSwitchEnum(dxil::OpCode OpCode,
365367
uint16_t VersionMajor,
366368
uint16_t VersionMinor) {
367369
uint64_t OpCodePack = (uint64_t)OpCode;
368370
return (OpCodePack << 32) | (VersionMajor << 16) | VersionMinor;
369371
}
370372

373+
// Retreive all the set attributes for a DXIL OpCode given the targeted
374+
// DXILVersion
371375
static dxil::Attributes getDXILAttributes(dxil::OpCode OpCode,
372376
VersionTuple DXILVersion) {
377+
// Instantiate all versions to iterate through
373378
SmallVector<Version> Versions = {
374379
#define DXIL_VERSION(MAJOR, MINOR) {MAJOR, MINOR},
375380
#include "DXILOperation.inc"
@@ -379,6 +384,9 @@ static dxil::Attributes getDXILAttributes(dxil::OpCode OpCode,
379384
for (auto Version : Versions) {
380385
if (DXILVersion < VersionTuple(Version.Major, Version.Minor))
381386
continue;
387+
388+
// Switch through and match an OpCode with the specific version and set the
389+
// corresponding flag(s) if available
382390
switch (computeSwitchEnum(OpCode, Version.Major, Version.Minor)) {
383391
#define DXIL_OP_ATTRIBUTES(OpCode, VersionMajor, VersionMinor, ...) \
384392
case computeSwitchEnum(OpCode, VersionMajor, VersionMinor): { \
@@ -392,6 +400,8 @@ static dxil::Attributes getDXILAttributes(dxil::OpCode OpCode,
392400
return Attributes;
393401
}
394402

403+
// Retreive the set of DXIL Attributes given the version and map them to an
404+
// llvm function attribute that is set onto the instruction
395405
static void setDXILAttributes(CallInst *CI, dxil::OpCode OpCode,
396406
VersionTuple DXILVersion) {
397407
dxil::Attributes Attributes = getDXILAttributes(OpCode, DXILVersion);

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
181181
Recs = R->getValueAsListOfDefs("properties");
182182

183183
// Get property records
184-
for (const Record *CR : Recs) {
184+
for (const Record *CR : Recs)
185185
PropRecs.push_back(CR);
186-
}
187186

188187
// Get the operation class
189188
OpClass = R->getValueAsDef("OpClass")->getName();
@@ -371,7 +370,8 @@ static void emitDXILAttributes(const RecordKeeper &Records, raw_ostream &OS) {
371370
OS << "#endif\n\n";
372371
}
373372

374-
// Determine which function attributes are set for a dxil version
373+
// Helper function to determine if the given Attr is defined in the vector
374+
// Attrs, by comparing the names
375375
static bool attrIsDefined(std::vector<const Record *> Attrs,
376376
const Record *Attr) {
377377
for (auto CurAttr : Attrs)
@@ -384,6 +384,13 @@ static bool attrIsDefined(std::vector<const Record *> Attrs,
384384
static void emitDXILOpAttributes(const RecordKeeper &Records,
385385
ArrayRef<DXILOperationDesc> Ops,
386386
raw_ostream &OS) {
387+
// A DXIL op can have multiple function attributes that are specific to a
388+
// specific DXIL version and higher. AttrRecs models this by grouping the
389+
// attributes by the versions. So we will output a macro for each version
390+
// number with a table of bools in the following format:
391+
//
392+
// OpName, VersionMajor, VersionMinor, FnAttr1, FnAttr2, ...
393+
// Eg) Abs, 1, 0, true, false, ...
387394
OS << "#ifdef DXIL_OP_ATTRIBUTES\n";
388395
for (const auto &Op : Ops) {
389396
for (const auto *Rec : Op.AttrRecs) {
@@ -393,7 +400,11 @@ static void emitDXILOpAttributes(const RecordKeeper &Records,
393400
Rec->getValueAsDef("dxil_version")->getValueAsInt("Minor");
394401
OS << "DXIL_OP_ATTRIBUTES(dxil::OpCode::" << Op.OpName << ", ";
395402
OS << std::to_string(Major) << ", " << std::to_string(Minor);
403+
// These Attrs are the ones set for above DXIL version
396404
auto Attrs = Rec->getValueAsListOfDefs("fn_attrs");
405+
// We will then iteratre through all possible attributes and mark the
406+
// present ones as 'true' and all the others as 'false' to create the
407+
// boolean table, eg) true, false, false, false
397408
for (const Record *Attr :
398409
Records.getAllDerivedDefinitions("DXILAttribute")) {
399410
std::string HasAttr = ", false";
@@ -408,7 +419,7 @@ static void emitDXILOpAttributes(const RecordKeeper &Records,
408419
OS << "#endif\n\n";
409420
}
410421

411-
/// Emit a list of DXIL op properties and their query functions
422+
/// Emit a list of DXIL op properties
412423
static void emitDXILProperties(const RecordKeeper &Records, raw_ostream &OS) {
413424
OS << "#ifdef DXIL_PROPERTY\n";
414425
for (const Record *Prop : Records.getAllDerivedDefinitions("DXILProperty"))

0 commit comments

Comments
 (0)