[llvm] [DXIL] Add DXIL version-specific TableGen specification and implementation of DXIL Ops (PR #97593)
Chris B via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 14:30:10 PDT 2024
================
@@ -249,17 +309,95 @@ static FunctionType *getDXILOpFunctionType(const OpCodeProperty *Prop,
ArgTys[0], ArrayRef<Type *>(&ArgTys[1], ArgTys.size() - 1), false);
}
+/// Get index of the property from PropList valid for the most recent
+/// DXIL version not greater than DXILVer.
+/// PropList is expected to be sorted in ascending order of DXIL version.
+template <typename T>
+static int getPropIndex(const std::vector<T> PropList,
+ const VersionTuple DXILVer) {
+ auto Size = PropList.size();
+ for (int I = Size - 1; I >= 0; I--) {
+ auto OL = PropList[I];
+ if (VersionTuple(OL.DXILVersion.Major, OL.DXILVersion.Minor) <= DXILVer) {
+ return I;
+ }
+ }
+ report_fatal_error(Twine(DXILVer.getAsString()) + ": Unknown DXIL Version",
+ /*gen_crash_diag*/ false);
+
+ return -1;
+}
+
namespace llvm {
namespace dxil {
+// No extra checks on TargetTripleStr need be performed to verify that the
+// Triple is well-formed or that the target is supported since these checks
+// would have been done at the time the module M is constructed in the earlier
+// stages of compilation.
+DXILOpBuilder::DXILOpBuilder(Module &M, IRBuilderBase &B)
+ : M(M), B(B), TargetTripleStr(M.getTargetTriple()) {}
+
CallInst *DXILOpBuilder::createDXILOpCall(dxil::OpCode OpCode, Type *ReturnTy,
Type *OverloadTy,
SmallVector<Value *> Args) {
+
+ auto Major = Triple(TargetTripleStr).getDXILVersion().getMajor();
+ auto MinorOrErr = Triple(TargetTripleStr).getDXILVersion().getMinor();
+ uint32_t Minor = MinorOrErr.has_value() ? *MinorOrErr : 0;
+ VersionTuple DXILVer(Major, Minor);
----------------
llvm-beanz wrote:
```suggestion
VersionTuple DXILVer = Triple(TargetTripleStr).getDXILVersion();
```
https://github.com/llvm/llvm-project/pull/97593
More information about the llvm-commits
mailing list