Skip to content

Commit b92bab3

Browse files
authored
[HLSL] Appropriately set function attribute optnone (#125937)
When optimization is disabled, set `optnone` attribute all module entry functions. Updated test in accordance with the change. Closes #124796
1 parent 42538ca commit b92bab3

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
345345
WaveSizeAttr->getPreferred());
346346
Fn->addFnAttr(WaveSizeKindStr, WaveSizeStr);
347347
}
348+
// HLSL entry functions are materialized for module functions with
349+
// HLSLShaderAttr attribute. SetLLVMFunctionAttributesForDefinition called
350+
// later in the compiler-flow for such module functions is not aware of and
351+
// hence not able to set attributes of the newly materialized entry functions.
352+
// So, set attributes of entry function here, as appropriate.
353+
if (CGM.getCodeGenOpts().OptimizationLevel == 0)
354+
Fn->addFnAttr(llvm::Attribute::OptimizeNone);
348355
Fn->addFnAttr(llvm::Attribute::NoInline);
349356
}
350357

clang/test/CodeGenHLSL/inline-functions.hlsl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
2-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE
3-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE,OPT_ATTR
2+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,OPT_ATTR
3+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,NOOPT_ATTR
44
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
5-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE
6-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE
5+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,OPT_ATTR
6+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,NOOPT_ATTR
77

88
// Tests that user functions will always be inlined.
99
// This includes exported functions and mangled entry point implementation functions.
@@ -71,7 +71,8 @@ RWBuffer<unsigned> Indices;
7171
// NOINLINE: ret void
7272

7373
// The unmangled version is not inlined, EntryAttr reflects that
74-
// CHECK: Function Attrs: {{.*}}noinline
74+
// OPT_ATTR: Function Attrs: {{.*}}optnone
75+
// NOOPT_ATTR-NOT: Function Attrs: {{.*}}optnone
7576
// CHECK: define void @main() {{[a-z_ ]*}}[[EntryAttr:\#[0-9]+]]
7677
// Make sure function calls are inlined when AlwaysInline is run
7778
// This only leaves calls to llvm. intrinsics
@@ -98,7 +99,8 @@ void main(unsigned int GI : SV_GroupIndex) {
9899
// NOINLINE: ret void
99100

100101
// The unmangled version is not inlined, EntryAttr reflects that
101-
// CHECK: Function Attrs: {{.*}}noinline
102+
// OPT_ATTR: Function Attrs: {{.*}}optnone
103+
// NOOPT_ATTR-NOT: Function Attrs: {{.*}}optnone
102104
// CHECK: define void @main10() {{[a-z_ ]*}}[[EntryAttr]]
103105
// Make sure function calls are inlined when AlwaysInline is run
104106
// This only leaves calls to llvm. intrinsics

0 commit comments

Comments
 (0)