From 3dd396dbdafff66dc208690b224cce1ecd0fc47a Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 15 Aug 2024 00:27:50 +0300 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?= =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.5-bogner [skip ci] --- llvm/lib/Target/DirectX/DXIL.td | 18 +++++++++++------- llvm/lib/Target/DirectX/DXILOpBuilder.cpp | 11 +++++------ llvm/lib/Target/DirectX/DXILOpBuilder.h | 14 +------------- llvm/lib/Target/DirectX/DXILResourceAnalysis.h | 4 ++++ 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/llvm/lib/Target/DirectX/DXIL.td b/llvm/lib/Target/DirectX/DXIL.td index 67015cff78a79..60185c20606b2 100644 --- a/llvm/lib/Target/DirectX/DXIL.td +++ b/llvm/lib/Target/DirectX/DXIL.td @@ -671,8 +671,9 @@ def Dot4 : DXILOp<56, dot4> { def ThreadId : DXILOp<93, threadId> { let Doc = "Reads the thread ID"; let LLVMIntrinsic = int_dx_thread_id; - let arguments = [i32Ty]; - let result = i32Ty; + let arguments = [overloadTy]; + let result = overloadTy; + let overloads = [Overloads]; let stages = [Stages]; let attributes = [Attributes]; } @@ -680,8 +681,9 @@ def ThreadId : DXILOp<93, threadId> { def GroupId : DXILOp<94, groupId> { let Doc = "Reads the group ID (SV_GroupID)"; let LLVMIntrinsic = int_dx_group_id; - let arguments = [i32Ty]; - let result = i32Ty; + let arguments = [overloadTy]; + let result = overloadTy; + let overloads = [Overloads]; let stages = [Stages]; let attributes = [Attributes]; } @@ -689,8 +691,9 @@ def GroupId : DXILOp<94, groupId> { def ThreadIdInGroup : DXILOp<95, threadIdInGroup> { let Doc = "Reads the thread ID within the group (SV_GroupThreadID)"; let LLVMIntrinsic = int_dx_thread_id_in_group; - let arguments = [i32Ty]; - let result = i32Ty; + let arguments = [overloadTy]; + let result = overloadTy; + let overloads = [Overloads]; let stages = [Stages]; let attributes = [Attributes]; } @@ -699,7 +702,8 @@ def FlattenedThreadIdInGroup : DXILOp<96, flattenedThreadIdInGroup> { let Doc = "Provides a flattened index for a given thread within a given " "group (SV_GroupIndex)"; let LLVMIntrinsic = int_dx_flattened_thread_id_in_group; - let result = i32Ty; + let result = overloadTy; + let overloads = [Overloads]; let stages = [Stages]; let attributes = [Attributes]; } diff --git a/llvm/lib/Target/DirectX/DXILOpBuilder.cpp b/llvm/lib/Target/DirectX/DXILOpBuilder.cpp index 42df7c90cb337..0e2b4601112b5 100644 --- a/llvm/lib/Target/DirectX/DXILOpBuilder.cpp +++ b/llvm/lib/Target/DirectX/DXILOpBuilder.cpp @@ -87,6 +87,9 @@ static const char *getOverloadTypeName(OverloadKind Kind) { } static OverloadKind getOverloadKind(Type *Ty) { + if (!Ty) + return OverloadKind::VOID; + Type::TypeID T = Ty->getTypeID(); switch (T) { case Type::VoidTyID: @@ -379,11 +382,7 @@ Expected DXILOpBuilder::tryCreateOp(dxil::OpCode OpCode, uint16_t ValidTyMask = Prop->Overloads[*OlIndexOrErr].ValidTys; - // If we don't have an overload type, use the function's return type. This is - // a bit of a hack, but it's necessary to get the type suffix on unoverloaded - // DXIL ops correct, like `dx.op.threadId.i32`. - OverloadKind Kind = - getOverloadKind(OverloadTy ? OverloadTy : DXILOpFT->getReturnType()); + OverloadKind Kind = getOverloadKind(OverloadTy); // Check if the operation supports overload types and OverloadTy is valid // per the specified types for the operation @@ -424,7 +423,7 @@ Expected DXILOpBuilder::tryCreateOp(dxil::OpCode OpCode, return B.CreateCall(DXILFn, OpArgs); } -CallInst *DXILOpBuilder::createOp(dxil::OpCode OpCode, ArrayRef &Args, +CallInst *DXILOpBuilder::createOp(dxil::OpCode OpCode, ArrayRef Args, Type *RetTy) { Expected Result = tryCreateOp(OpCode, Args, RetTy); if (Error E = Result.takeError()) diff --git a/llvm/lib/Target/DirectX/DXILOpBuilder.h b/llvm/lib/Target/DirectX/DXILOpBuilder.h index ff66f39a3ceb3..5d83357f7a2e9 100644 --- a/llvm/lib/Target/DirectX/DXILOpBuilder.h +++ b/llvm/lib/Target/DirectX/DXILOpBuilder.h @@ -33,25 +33,13 @@ class DXILOpBuilder { /// Create a call instruction for the given DXIL op. The arguments /// must be valid for an overload of the operation. - CallInst *createOp(dxil::OpCode Op, ArrayRef &Args, + CallInst *createOp(dxil::OpCode Op, ArrayRef Args, Type *RetTy = nullptr); -#define DXIL_OPCODE(Op, Name) \ - CallInst *create##Name##Op(ArrayRef &Args, Type *RetTy = nullptr) { \ - return createOp(dxil::OpCode(Op), Args, RetTy); \ - } -#include "DXILOperation.inc" - /// Try to create a call instruction for the given DXIL op. Fails if the /// overload is invalid. Expected tryCreateOp(dxil::OpCode Op, ArrayRef Args, Type *RetTy = nullptr); -#define DXIL_OPCODE(Op, Name) \ - Expected tryCreate##Name##Op(ArrayRef &Args, \ - Type *RetTy = nullptr) { \ - return tryCreateOp(dxil::OpCode(Op), Args, RetTy); \ - } -#include "DXILOperation.inc" /// Return the name of the given opcode. static const char *getOpCodeName(dxil::OpCode DXILOp); diff --git a/llvm/lib/Target/DirectX/DXILResourceAnalysis.h b/llvm/lib/Target/DirectX/DXILResourceAnalysis.h index 3a2b8a9fd39d5..26d9237d51b49 100644 --- a/llvm/lib/Target/DirectX/DXILResourceAnalysis.h +++ b/llvm/lib/Target/DirectX/DXILResourceAnalysis.h @@ -57,6 +57,10 @@ class DXILResourceMDWrapper : public ModulePass { /// Calculate the DXILResource for the module. bool runOnModule(Module &M) override; + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.setPreservesAll(); + } + void print(raw_ostream &O, const Module *M = nullptr) const override; }; } // namespace llvm