Skip to content

Commit 56dae59

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merge upstream LLVM into amd-gfx12
2 parents a059f30 + 7ca2375 commit 56dae59

File tree

152 files changed

+3941
-2950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+3941
-2950
lines changed

clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,23 @@ EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
111111
}
112112

113113
RewriteRuleWith<std::string> useNewMlirOpBuilderCheckRule() {
114-
return makeRule(
114+
Stencil message = cat("use 'OpType::create(builder, ...)' instead of "
115+
"'builder.create<OpType>(...)'");
116+
// Match a create call on an OpBuilder.
117+
ast_matchers::internal::Matcher<Stmt> base =
115118
cxxMemberCallExpr(
116119
on(expr(hasType(
117120
cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"))))
118121
.bind("builder")),
119122
callee(cxxMethodDecl(hasTemplateArgument(0, templateArgument()))),
120123
callee(cxxMethodDecl(hasName("create"))))
121-
.bind("call"),
122-
rewrite(node("call"), node("builder"), callArgs("call")),
123-
cat("use 'OpType::create(builder, ...)' instead of "
124-
"'builder.create<OpType>(...)'"));
124+
.bind("call");
125+
return applyFirst(
126+
// Attempt rewrite given an lvalue builder, else just warn.
127+
{makeRule(cxxMemberCallExpr(unless(on(cxxTemporaryObjectExpr())), base),
128+
rewrite(node("call"), node("builder"), callArgs("call")),
129+
message),
130+
makeRule(base, noopEdit(node("call")), message)});
125131
}
126132
} // namespace
127133

clang-tools-extra/test/clang-tidy/checkers/llvm/use-new-mlir-op-builder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ void f() {
6969
// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
7070
// CHECK-FIXES: mlir::ModuleOp::create(ib)
7171
ib.create<mlir::ModuleOp>( );
72+
73+
// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use 'OpType::create(builder, ...)' instead of 'builder.create<OpType>(...)' [llvm-use-new-mlir-op-builder]
74+
// CHECK-FIXES: mlir::OpBuilder().create<mlir::ModuleOp>(builder.getUnknownLoc());
75+
mlir::OpBuilder().create<mlir::ModuleOp>(builder.getUnknownLoc());
7276
}

clang/docs/LanguageExtensions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ It can be used like this:
6868
``__has_builtin`` should not be used to detect support for a builtin macro;
6969
use ``#ifdef`` instead.
7070

71+
When compiling with target offloading, ``__has_builtin`` only considers the
72+
currently active target.
73+
7174
``__has_constexpr_builtin``
7275
---------------------------
7376

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Potentially Breaking Changes
3737
C/C++ Language Potentially Breaking Changes
3838
-------------------------------------------
3939

40+
- The ``__has_builtin`` function now only considers the currently active target when being used with target offloading.
41+
4042
C++ Specific Potentially Breaking Changes
4143
-----------------------------------------
4244
- For C++20 modules, the Reduced BMI mode will be the default option. This may introduce

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ getSystemOffloadArchs(Compilation &C, Action::OffloadKind Kind) {
910910

911911
SmallVector<std::string> GPUArchs;
912912
if (llvm::ErrorOr<std::string> Executable =
913-
llvm::sys::findProgramByName(Program)) {
913+
llvm::sys::findProgramByName(Program, {C.getDriver().Dir})) {
914914
llvm::SmallVector<StringRef> Args{*Executable};
915915
if (Kind == Action::OFK_HIP)
916916
Args.push_back("--only=amdgpu");
@@ -4919,13 +4919,14 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
49194919
}
49204920

49214921
// HIP code in device-only non-RDC mode will bundle the output if it invoked
4922-
// the linker.
4922+
// the linker or if the user explicitly requested it.
49234923
bool ShouldBundleHIP =
4924-
HIPNoRDC && offloadDeviceOnly() &&
49254924
Args.hasFlag(options::OPT_gpu_bundle_output,
4926-
options::OPT_no_gpu_bundle_output, true) &&
4927-
!llvm::any_of(OffloadActions,
4928-
[](Action *A) { return A->getType() != types::TY_Image; });
4925+
options::OPT_no_gpu_bundle_output, false) ||
4926+
(HIPNoRDC && offloadDeviceOnly() &&
4927+
llvm::none_of(OffloadActions, [](Action *A) {
4928+
return A->getType() != types::TY_Image;
4929+
}));
49294930

49304931
// All kinds exit now in device-only mode except for non-RDC mode HIP.
49314932
if (offloadDeviceOnly() && !ShouldBundleHIP)

clang/lib/Driver/ToolChains/HIPSPV.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,17 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
6969

7070
// Link LLVM bitcode.
7171
ArgStringList LinkArgs{};
72+
7273
for (auto Input : Inputs)
7374
LinkArgs.push_back(Input.getFilename());
75+
76+
// Add static device libraries using the common helper function.
77+
// This handles unbundling archives (.a) containing bitcode bundles.
78+
StringRef Arch = getToolChain().getTriple().getArchName();
79+
StringRef Target =
80+
"generic"; // SPIR-V is generic, no specific target ID like -mcpu
81+
tools::AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LinkArgs, Arch,
82+
Target, /*IsBitCodeSDL=*/true);
7483
LinkArgs.append({"-o", TempFile});
7584
const char *LlvmLink =
7685
Args.MakeArgString(getToolChain().GetProgramPath("llvm-link"));

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
17601760
Tok, *this, diag::err_feature_check_malformed);
17611761
if (!II)
17621762
return false;
1763-
else if (II->getBuiltinID() != 0) {
1763+
unsigned BuiltinID = II->getBuiltinID();
1764+
if (BuiltinID != 0) {
17641765
switch (II->getBuiltinID()) {
17651766
case Builtin::BI__builtin_cpu_is:
17661767
return getTargetInfo().supportsCpuIs();
@@ -1774,8 +1775,11 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
17741775
// usual allocation and deallocation functions. Required by libc++
17751776
return 201802;
17761777
default:
1778+
// __has_builtin should return false for aux builtins.
1779+
if (getBuiltinInfo().isAuxBuiltinID(BuiltinID))
1780+
return false;
17771781
return Builtin::evaluateRequiredTargetFeatures(
1778-
getBuiltinInfo().getRequiredFeatures(II->getBuiltinID()),
1782+
getBuiltinInfo().getRequiredFeatures(BuiltinID),
17791783
getTargetInfo().getTargetOpts().FeatureMap);
17801784
}
17811785
return true;

clang/test/CodeGenCUDA/bf16.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ __device__ __bf16 external_func( __bf16 in);
3535
// CHECK: .param .align 2 .b8 _Z9test_callDF16b_param_0[2]
3636
__device__ __bf16 test_call( __bf16 in) {
3737
// CHECK: ld.param.b16 %[[R:rs[0-9]+]], [_Z9test_callDF16b_param_0];
38-
// CHECK: st.param.b16 [param0], %[[R]];
3938
// CHECK: .param .align 2 .b8 retval0[2];
39+
// CHECK: st.param.b16 [param0], %[[R]];
4040
// CHECK: call.uni (retval0), _Z13external_funcDF16b, (param0);
4141
// CHECK: ld.param.b16 %[[RET:rs[0-9]+]], [retval0];
4242
return external_func(in);

clang/test/Driver/hip-binding.hip

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[GFX90a:.+]]"
6262
// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX90a]]"], output: "[[GFX90a_OUT:.+]]"
6363
//
64-
// RUN: not %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-bindings -nogpulib -nogpuinc \
64+
// RUN: not %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-bindings -nogpulib -nogpuinc -emit-llvm \
6565
// RUN: --no-gpu-bundle-output --offload-arch=gfx90a --offload-arch=gfx908 --offload-device-only -c -o %t %s 2>&1 \
6666
// RUN: | FileCheck -check-prefix=MULTI-D-ONLY-NO-BUNDLE-O %s
6767
// MULTI-D-ONLY-NO-BUNDLE-O: error: cannot specify -o when generating multiple output files
@@ -75,6 +75,13 @@
7575
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX90A_OBJ]]"], output: "[[GFX90A:.+]]"
7676
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX908]]", "[[GFX90A]]"], output: "a.out"
7777

78+
// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-bindings -nogpulib -nogpuinc -emit-llvm \
79+
// RUN: --gpu-bundle-output --offload-arch=gfx90a --offload-arch=gfx908 --offload-device-only -c -o a.out %s 2>&1 \
80+
// RUN: | FileCheck -check-prefix=MULTI-D-ONLY-BC %s
81+
// MULTI-D-ONLY-BC: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[GFX908_BC:.+]]"
82+
// MULTI-D-ONLY-BC-NEXT: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[GFX90A_BC:.+]]"
83+
// MULTI-D-ONLY-BC-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX908_BC]]", "[[GFX90A_BC]]"], output: "a.out"
84+
7885
//
7986
// Check to ensure that we can use '-fsyntax-only' for HIP output with the new
8087
// driver.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test HIPSPV static device library linking
2+
// REQUIRES: system-linux
3+
// UNSUPPORTED: system-windows
4+
5+
// Create a dummy archive to test SDL linking
6+
// RUN: rm -rf %t && mkdir %t
7+
// RUN: touch %t/dummy.bc
8+
// RUN: llvm-ar cr %t/libSDL.a %t/dummy.bc
9+
10+
// Test that -l options are passed to llvm-link for --offload=spirv64
11+
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
12+
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
13+
// RUN: -L%t -lSDL \
14+
// RUN: 2>&1 | FileCheck -check-prefix=SDL-LINK %s
15+
16+
// Test that .a files are properly unbundled and passed to llvm-link
17+
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
18+
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
19+
// RUN: %t/libSDL.a \
20+
// RUN: 2>&1 | FileCheck -check-prefix=SDL-ARCHIVE %s
21+
22+
// Verify that the input files are added before the SDL files in llvm-link command
23+
// This tests the ordering fix to match HIPAMD behavior
24+
// SDL-LINK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libSDL.a" "-targets=hip-spirv64-unknown-unknown-unknown-generic" "-output=[[SDL_A:.*\.a]]" "-allow-missing-bundles"
25+
// SDL-LINK: "{{.*}}llvm-link" "{{.*}}.bc" "[[SDL_A]]" "-o"
26+
27+
// SDL-ARCHIVE: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libSDL.a" "-targets=hip-spirv64-unknown-unknown-unknown-generic" "-output=[[SDL_A:.*\.a]]" "-allow-missing-bundles"
28+
// SDL-ARCHIVE: "{{.*}}llvm-link" "{{.*}}.bc" "[[SDL_A]]" "-o"

0 commit comments

Comments
 (0)