Skip to content

Commit 24b497b

Browse files
committed
Define computation of the value computed using major and minor
version Shader Model in a single place to be used both by DXILEmitter and by the lowering pass.
1 parent eea6cf8 commit 24b497b

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

llvm/include/llvm/Support/DXILABI.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,9 @@ enum class ElementType : uint32_t {
9090
} // namespace dxil
9191
} // namespace llvm
9292

93+
// Generate a unique value for given Major, Minor pair of Shader Model
94+
// version. Allows for 100 minor versions for a given major version number.
95+
// To be used uniformly by DXILEmitter backend as well as DXIL Lowering pass.
96+
#define COMPUTE_SM_VERSION_VALUE(MAJ, MIN) ((MAJ * 100) + MIN)
97+
9398
#endif // LLVM_SUPPORT_DXILABI_H

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ include "llvm/IR/Intrinsics.td"
1616
// Abstract class to demarcate minimum Shader model version required
1717
// to support DXIL Op
1818
class DXILShaderModel<int major, int minor> {
19-
int MajorAndMinor = !add(!mul(major, 10), minor);
19+
int Major = major;
20+
int Minor = minor;
2021
}
2122

2223
// Valid minimum Shader model version records
@@ -25,7 +26,7 @@ class DXILShaderModel<int major, int minor> {
2526
foreach i = 0...9 in {
2627
def SM6_#i : DXILShaderModel<6, i>;
2728
}
28-
// Shader Mode 7.x - for now 7.0 is defined. Extend as needed
29+
// Shader Model 7.x - for now 7.0 is defined. Extend as needed
2930
foreach i = 0 in {
3031
def SM7_#i : DXILShaderModel<7, i>;
3132
}

llvm/lib/Target/DirectX/DXILOpLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static SmallVector<Value *> argVectorFlatten(CallInst *Orig,
7373
return NewOperands;
7474
}
7575

76-
static uint32_t getShaderModelVer(Module &M) {
76+
static uint32_t getModuleShaderModelVersion(Module &M) {
7777
std::string TTStr = M.getTargetTriple();
7878
std::string Error;
7979
auto Target = TargetRegistry::lookupTarget(TTStr, Error);
@@ -85,13 +85,13 @@ static uint32_t getShaderModelVer(Module &M) {
8585
auto Major = Triple(TTStr).getOSVersion().getMajor();
8686
auto MinorOrErr = Triple(TTStr).getOSVersion().getMinor();
8787
uint32_t Minor = MinorOrErr.has_value() ? *MinorOrErr : 0;
88-
return ((Major * 10) + Minor);
88+
return COMPUTE_SM_VERSION_VALUE(Major, Minor);
8989
}
9090

9191
static void lowerIntrinsic(dxil::OpCode DXILOp, Function &F, Module &M) {
9292
IRBuilder<> B(M.getContext());
9393
DXILOpBuilder DXILB(M, B);
94-
uint32_t SMVer = getShaderModelVer(M);
94+
uint32_t SMVer = getModuleShaderModelVersion(M);
9595
Type *OverloadTy = DXILB.getOverloadTy(DXILOp, SMVer, F.getFunctionType());
9696
for (User *U : make_early_inc_range(F.users())) {
9797
CallInst *CI = dyn_cast<CallInst>(U);

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,20 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
184184
std::vector<Record *> OverloadTypeRecs =
185185
R->getValueAsListOfDefs("OpOverloadTypes");
186186
// Sort records in ascending order of Shader Model version
187-
std::sort(
188-
OverloadTypeRecs.begin(), OverloadTypeRecs.end(),
189-
[](Record *a, Record *b) {
190-
return (
191-
a->getValueAsDef("ShaderModel")->getValueAsInt("MajorAndMinor") <
192-
b->getValueAsDef("ShaderModel")->getValueAsInt("MajorAndMinor"));
193-
});
187+
std::sort(OverloadTypeRecs.begin(), OverloadTypeRecs.end(),
188+
[](Record *RecA, Record *RecB) {
189+
uint16_t RecAMaj =
190+
RecA->getValueAsDef("ShaderModel")->getValueAsInt("Major");
191+
uint16_t RecAMin =
192+
RecA->getValueAsDef("ShaderModel")->getValueAsInt("Minor");
193+
uint16_t RecBMaj =
194+
RecB->getValueAsDef("ShaderModel")->getValueAsInt("Major");
195+
uint16_t RecBMin =
196+
RecB->getValueAsDef("ShaderModel")->getValueAsInt("Minor");
197+
198+
return (COMPUTE_SM_VERSION_VALUE(RecAMaj, RecAMin) <
199+
COMPUTE_SM_VERSION_VALUE(RecBMaj, RecBMin));
200+
});
194201
unsigned OverloadTypeRecsSize = OverloadTypeRecs.size();
195202
// Populate OpOverloads with
196203
for (unsigned I = 0; I < OverloadTypeRecsSize; I++) {
@@ -255,6 +262,11 @@ static std::string getParameterKindStr(ParameterKind Kind) {
255262
llvm_unreachable("Unknown llvm::dxil::ParameterKind enum");
256263
}
257264

265+
/// Return a string representation of OverloadKind enum that maps to
266+
/// input LLVMType record
267+
/// \param R TableGen def record of class LLVMType
268+
/// \return std::string string representation of OverloadKind
269+
258270
static std::string getOverloadKindStr(const Record *R) {
259271
Record *VTRec = R->getValueAsDef("VT");
260272
switch (getValueType(VTRec)) {
@@ -293,10 +305,12 @@ static std::string getOverloadKindStrs(const SmallVector<Record *> Recs) {
293305
OverloadString.append("{");
294306
for (auto OvRec : Recs) {
295307
OverloadString.append(Prefix).append("{");
296-
OverloadString
297-
.append(std::to_string(OvRec->getValueAsDef("ShaderModel")
298-
->getValueAsInt("MajorAndMinor")))
299-
.append(", ");
308+
uint16_t RecAMaj =
309+
OvRec->getValueAsDef("ShaderModel")->getValueAsInt("Major");
310+
uint16_t RecAMin =
311+
OvRec->getValueAsDef("ShaderModel")->getValueAsInt("Minor");
312+
uint16_t RecMajMin = COMPUTE_SM_VERSION_VALUE(RecAMaj, RecAMin);
313+
OverloadString.append(std::to_string(RecMajMin)).append(", ");
300314
auto OverloadTys = OvRec->getValueAsListOfDefs("OpOverloads");
301315
auto Iter = OverloadTys.begin();
302316
OverloadString.append(getOverloadKindStr(*Iter++));

0 commit comments

Comments
 (0)