[PATCH] D124752: [HLSL] clang codeGen for HLSLShaderAttr.
Xiang Li via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon May 30 09:18:13 PDT 2022
python3kgae updated this revision to Diff 432947.
python3kgae marked an inline comment as done.
python3kgae added a comment.
Code cleanup to match comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124752/new/
https://reviews.llvm.org/D124752
Files:
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
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 -fcgl -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/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 AttrBuilder;
+}
namespace clang {
+class FunctionDecl;
+
namespace CodeGen {
class CodeGenModule;
@@ -30,6 +35,9 @@
virtual ~CGHLSLRuntime() {}
void finishCodeGen();
+
+ void addHLSLFunctionAttributes(llvm::AttrBuilder &FuncAttrs,
+ const FunctionDecl *);
};
} // namespace CodeGen
Index: clang/lib/CodeGen/CGHLSLRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -50,3 +50,13 @@
llvm::Module &M = CGM.getModule();
addDxilValVersion(TargetOpts.DxilValidatorVersion, M);
}
+
+void CGHLSLRuntime::addHLSLFunctionAttributes(llvm::AttrBuilder &FuncAttrs,
+ const FunctionDecl *FD) {
+ if (HLSLShaderAttr *ShaderAttr = FD->getAttr<HLSLShaderAttr>()) {
+ const StringRef ShaderAttrKindStr = "dx.shader";
+ FuncAttrs.addAttribute(
+ ShaderAttrKindStr,
+ ShaderAttr->ConvertShaderTypeToStr(ShaderAttr->getType()));
+ }
+}
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -16,6 +16,7 @@
#include "CGBlocks.h"
#include "CGCXXABI.h"
#include "CGCleanup.h"
+#include "CGHLSLRuntime.h"
#include "CGRecordLayout.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
@@ -2601,6 +2602,11 @@
}
assert(ArgNo == FI.arg_size());
+ if (getLangOpts().HLSL && TargetDecl) {
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(TargetDecl))
+ getHLSLRuntime().addHLSLFunctionAttributes(FuncAttrs, FD);
+ }
+
AttrList = llvm::AttributeList::get(
getLLVMContext(), llvm::AttributeSet::get(getLLVMContext(), FuncAttrs),
llvm::AttributeSet::get(getLLVMContext(), RetAttrs), ArgAttrs);
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -3281,7 +3281,7 @@
}
bool FunctionDecl::isInExternCContext() const {
- if (hasAttr<OpenCLKernelAttr>())
+ if (hasAttr<OpenCLKernelAttr>() || hasAttr<HLSLShaderAttr>())
return true;
return getLexicalDeclContext()->isExternCContext();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124752.432947.patch
Type: text/x-patch
Size: 3066 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220530/b1a64f84/attachment-0001.bin>
More information about the cfe-commits
mailing list