Skip to content

Commit

Permalink
[DirectX][NFC] Change usage pattern *Dxil* to *DXIL* for uniformity (…
Browse files Browse the repository at this point in the history
…#80778)

Match DXIL TableGen class names with structure names in DXIL Emitter. 
Delete unnecessary Name field.
  • Loading branch information
bharadwajy authored Feb 8, 2024
1 parent 16d1a64 commit 758fd59
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 115 deletions.
89 changes: 43 additions & 46 deletions llvm/lib/Target/DirectX/DXIL.td
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@
include "llvm/IR/Intrinsics.td"

// Abstract representation of the class a DXIL Operation belongs to.
class DxilOpClass<string name> {
class DXILOpClass<string name> {
string Name = name;
}

// Abstract representation of the category a DXIL Operation belongs to
class DxilOpCategory<string name> {
class DXILOpCategory<string name> {
string Name = name;
}

def UnaryClass : DxilOpClass<"Unary">;
def BinaryClass : DxilOpClass<"Binary">;
def FlattenedThreadIdInGroupClass : DxilOpClass<"FlattenedThreadIdInGroup">;
def ThreadIdInGroupClass : DxilOpClass<"ThreadIdInGroup">;
def ThreadIdClass : DxilOpClass<"ThreadId">;
def GroupIdClass : DxilOpClass<"GroupId">;
def UnaryClass : DXILOpClass<"Unary">;
def BinaryClass : DXILOpClass<"Binary">;
def FlattenedThreadIdInGroupClass : DXILOpClass<"FlattenedThreadIdInGroup">;
def ThreadIdInGroupClass : DXILOpClass<"ThreadIdInGroup">;
def ThreadIdClass : DXILOpClass<"ThreadId">;
def GroupIdClass : DXILOpClass<"GroupId">;

def BinaryUintCategory : DxilOpCategory<"Binary uint">;
def UnaryFloatCategory : DxilOpCategory<"Unary float">;
def ComputeIDCategory : DxilOpCategory<"Compute/Mesh/Amplification shader">;
def BinaryUintCategory : DXILOpCategory<"Binary uint">;
def UnaryFloatCategory : DXILOpCategory<"Unary float">;
def ComputeIDCategory : DXILOpCategory<"Compute/Mesh/Amplification shader">;

// The parameter description for a DXIL operation
class DxilOpParameter<int pos, string type, string name, string doc,
class DXILOpParameter<int pos, string type, string name, string doc,
bit isConstant = 0, string enumName = "",
int maxValue = 0> {
int Pos = pos; // Position in parameter list
Expand All @@ -49,16 +49,13 @@ class DxilOpParameter<int pos, string type, string name, string doc,
}

// A representation for a DXIL operation
class DxilOperationDesc<string name> {
// TODO : Appears redundant. OpName should serve the same purpose
string Name = name; // short, unique name

class DXILOperationDesc {
string OpName = ""; // Name of DXIL operation
int OpCode = 0; // Unique non-negative integer associated with the operation
DxilOpClass OpClass; // Class of the operation
DxilOpCategory OpCategory; // Category of the operation
DXILOpClass OpClass; // Class of the operation
DXILOpCategory OpCategory; // Category of the operation
string Doc = ""; // Description of the operation
list<DxilOpParameter> Params = []; // Parameter list of the operation
list<DXILOpParameter> Params = []; // Parameter list of the operation
string OverloadTypes = ""; // Overload types, if applicable
string Attributes = ""; // Attribute shorthands: rn=does not access
// memory,ro=only reads from memory,
Expand All @@ -73,9 +70,9 @@ class DxilOperationDesc<string name> {
list<string> StatsGroup = [];
}

class DxilOperation<string name, int opCode, DxilOpClass opClass, DxilOpCategory opCategory, string doc,
string oloadTypes, string attrs, list<DxilOpParameter> params,
list<string> statsGroup = []> : DxilOperationDesc<name> {
class DXILOperation<string name, int opCode, DXILOpClass opClass, DXILOpCategory opCategory, string doc,
string oloadTypes, string attrs, list<DXILOpParameter> params,
list<string> statsGroup = []> : DXILOperationDesc {
let OpName = name;
let OpCode = opCode;
let Doc = doc;
Expand All @@ -90,56 +87,56 @@ class DxilOperation<string name, int opCode, DxilOpClass opClass, DxilOpCategory
// LLVM intrinsic that DXIL operation maps to.
class LLVMIntrinsic<Intrinsic llvm_intrinsic_> { Intrinsic llvm_intrinsic = llvm_intrinsic_; }

def Sin : DxilOperation<"Sin", 13, UnaryClass, UnaryFloatCategory, "returns sine(theta) for theta in radians.",
def Sin : DXILOperation<"Sin", 13, UnaryClass, UnaryFloatCategory, "returns sine(theta) for theta in radians.",
"half;float;", "rn",
[
DxilOpParameter<0, "$o", "", "operation result">,
DxilOpParameter<1, "i32", "opcode", "DXIL opcode">,
DxilOpParameter<2, "$o", "value", "input value">
DXILOpParameter<0, "$o", "", "operation result">,
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
DXILOpParameter<2, "$o", "value", "input value">
],
["floats"]>,
LLVMIntrinsic<int_sin>;

def UMax : DxilOperation< "UMax", 39, BinaryClass, BinaryUintCategory, "unsigned integer maximum. UMax(a,b) = a > b ? a : b",
def UMax : DXILOperation< "UMax", 39, BinaryClass, BinaryUintCategory, "unsigned integer maximum. UMax(a,b) = a > b ? a : b",
"i16;i32;i64;", "rn",
[
DxilOpParameter<0, "$o", "", "operation result">,
DxilOpParameter<1, "i32", "opcode", "DXIL opcode">,
DxilOpParameter<2, "$o", "a", "input value">,
DxilOpParameter<3, "$o", "b", "input value">
DXILOpParameter<0, "$o", "", "operation result">,
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
DXILOpParameter<2, "$o", "a", "input value">,
DXILOpParameter<3, "$o", "b", "input value">
],
["uints"]>,
LLVMIntrinsic<int_umax>;

def ThreadId : DxilOperation< "ThreadId", 93, ThreadIdClass, ComputeIDCategory, "reads the thread ID", "i32;", "rn",
def ThreadId : DXILOperation< "ThreadId", 93, ThreadIdClass, ComputeIDCategory, "reads the thread ID", "i32;", "rn",
[
DxilOpParameter<0, "i32", "", "thread ID component">,
DxilOpParameter<1, "i32", "opcode", "DXIL opcode">,
DxilOpParameter<2, "i32", "component", "component to read (x,y,z)">
DXILOpParameter<0, "i32", "", "thread ID component">,
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
DXILOpParameter<2, "i32", "component", "component to read (x,y,z)">
]>,
LLVMIntrinsic<int_dx_thread_id>;

def GroupId : DxilOperation< "GroupId", 94, GroupIdClass, ComputeIDCategory, "reads the group ID (SV_GroupID)", "i32;", "rn",
def GroupId : DXILOperation< "GroupId", 94, GroupIdClass, ComputeIDCategory, "reads the group ID (SV_GroupID)", "i32;", "rn",
[
DxilOpParameter<0, "i32", "", "group ID component">,
DxilOpParameter<1, "i32", "opcode", "DXIL opcode">,
DxilOpParameter<2, "i32", "component", "component to read">
DXILOpParameter<0, "i32", "", "group ID component">,
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
DXILOpParameter<2, "i32", "component", "component to read">
]>,
LLVMIntrinsic<int_dx_group_id>;

def ThreadIdInGroup : DxilOperation< "ThreadIdInGroup", 95, ThreadIdInGroupClass, ComputeIDCategory,
def ThreadIdInGroup : DXILOperation< "ThreadIdInGroup", 95, ThreadIdInGroupClass, ComputeIDCategory,
"reads the thread ID within the group (SV_GroupThreadID)", "i32;", "rn",
[
DxilOpParameter<0, "i32", "", "thread ID in group component">,
DxilOpParameter<1, "i32", "opcode", "DXIL opcode">,
DxilOpParameter<2, "i32", "component", "component to read (x,y,z)">
DXILOpParameter<0, "i32", "", "thread ID in group component">,
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">,
DXILOpParameter<2, "i32", "component", "component to read (x,y,z)">
]>,
LLVMIntrinsic<int_dx_thread_id_in_group>;

def FlattenedThreadIdInGroup : DxilOperation< "FlattenedThreadIdInGroup", 96, FlattenedThreadIdInGroupClass, ComputeIDCategory,
def FlattenedThreadIdInGroup : DXILOperation< "FlattenedThreadIdInGroup", 96, FlattenedThreadIdInGroupClass, ComputeIDCategory,
"provides a flattened index for a given thread within a given group (SV_GroupIndex)", "i32;", "rn",
[
DxilOpParameter<0, "i32", "", "result">,
DxilOpParameter<1, "i32", "opcode", "DXIL opcode">
DXILOpParameter<0, "i32", "", "result">,
DXILOpParameter<1, "i32", "opcode", "DXIL opcode">
]>,
LLVMIntrinsic<int_dx_flattened_thread_id_in_group>;
8 changes: 4 additions & 4 deletions llvm/lib/Target/DirectX/DXILMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class EntryMD {
// FIXME: add signature for profile other than CS.
// See https://github.com/llvm/llvm-project/issues/57928.
MDTuple *Signatures = nullptr;
return emitDxilEntryPointTuple(
return emitDXILEntryPointTuple(
&F, F.getName().str(), Signatures, Resources,
Props.emitDXILEntryProps(RawShaderFlag, Ctx, /*IsLib*/ false), Ctx);
}
Expand All @@ -222,7 +222,7 @@ class EntryMD {
// FIXME: add signature for profile other than CS.
// See https://github.com/llvm/llvm-project/issues/57928.
MDTuple *Signatures = nullptr;
return emitDxilEntryPointTuple(
return emitDXILEntryPointTuple(
&F, F.getName().str(), Signatures,
/*entry in lib doesn't need resources metadata*/ nullptr,
Props.emitDXILEntryProps(RawShaderFlag, Ctx, /*IsLib*/ true), Ctx);
Expand All @@ -233,13 +233,13 @@ class EntryMD {
static MDTuple *emitEmptyEntryForLib(MDTuple *Resources,
uint64_t RawShaderFlag,
LLVMContext &Ctx) {
return emitDxilEntryPointTuple(
return emitDXILEntryPointTuple(
nullptr, "", nullptr, Resources,
EntryProps::emitEntryPropsForEmptyEntry(RawShaderFlag, Ctx), Ctx);
}

private:
static MDTuple *emitDxilEntryPointTuple(Function *Fn, const std::string &Name,
static MDTuple *emitDXILEntryPointTuple(Function *Fn, const std::string &Name,
MDTuple *Signatures,
MDTuple *Resources,
MDTuple *Properties,
Expand Down
Loading

0 comments on commit 758fd59

Please sign in to comment.