python3kgae created this revision. python3kgae added reviewers: dblaikie, MaskRay, hoy, lebedev.ri. Herald added subscribers: Anastasia, StephenFan. Herald added a project: All. python3kgae requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Translate HLSLShaderAttr to IR level. 1. Skip mangle for hlsl entry functions. 2. Add function attribute for hlsl entry functions. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D124752 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/CodeGen/CodeGenModule.cpp clang/test/CodeGenHLSL/entry.hlsl clang/test/CodeGenHLSL/shader_type_attr.hlsl
Index: clang/test/CodeGenHLSL/shader_type_attr.hlsl =================================================================== --- /dev/null +++ clang/test/CodeGenHLSL/shader_type_attr.hlsl @@ -0,0 +1,11 @@ +// RUN: %clang --driver-mode=dxc -Tlib_6_x -Fo - %s | FileCheck %s + +// Make sure not mangle entry. +// CHECK:define void @foo() +// Make sure add function attribute. +// CHECK:"dx.shader"="compute" +[shader("compute")] +[numthreads(1,1,1)] +void foo() { + +} Index: clang/test/CodeGenHLSL/entry.hlsl =================================================================== --- /dev/null +++ clang/test/CodeGenHLSL/entry.hlsl @@ -0,0 +1,10 @@ +// RUN: %clang --driver-mode=dxc -Tcs_6_1 -Efoo -Fo - %s | FileCheck %s + +// Make sure not mangle entry. +// CHECK:define void @foo() +// Make sure add function attribute. +// CHECK:"dx.shader"="compute" +[numthreads(1,1,1)] +void foo() { + +} Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -1650,6 +1650,10 @@ /*AttrOnCallSite=*/false, IsThunk); F->setAttributes(PAL); F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv)); + if (getLangOpts().HLSL) { + if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(GD.getDecl())) + getHLSLRuntime().setHLSLFnuctionAttributes(F, FD); + } } static void removeImageAccessQualifier(std::string& TyName) { Index: clang/lib/CodeGen/CGHLSLRuntime.h =================================================================== --- clang/lib/CodeGen/CGHLSLRuntime.h +++ clang/lib/CodeGen/CGHLSLRuntime.h @@ -15,8 +15,13 @@ #ifndef LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H #define LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H +namespace llvm { +class Function; +} namespace clang { +class FunctionDecl; + namespace CodeGen { class CodeGenModule; @@ -30,6 +35,8 @@ virtual ~CGHLSLRuntime() {} void finishCodeGen(); + + void setHLSLFnuctionAttributes(llvm::Function *, const FunctionDecl *); }; } // namespace CodeGen Index: clang/lib/CodeGen/CGHLSLRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGHLSLRuntime.cpp +++ clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -50,3 +50,12 @@ llvm::Module &M = CGM.getModule(); addDxilValVersion(TargetOpts.DxilValidatorVersion, M); } + +void clang::CodeGen::CGHLSLRuntime::setHLSLFnuctionAttributes( + llvm::Function *F, const FunctionDecl *FD) { + if (HLSLShaderAttr *ShaderAttr = FD->getAttr<HLSLShaderAttr>()) { + const StringRef ShaderAttrKindStr = "dx.shader"; + F->addFnAttr(ShaderAttrKindStr, + ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType())); + } +} Index: clang/lib/AST/Mangle.cpp =================================================================== --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -135,6 +135,10 @@ if (isa<MSGuidDecl>(D)) return true; + // HLSL shader entry function never need to be mangled. + if (getASTContext().getLangOpts().HLSL && D->hasAttr<HLSLShaderAttr>()) + return false; + return shouldMangleCXXName(D); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits