Skip to content

Commit 8653b74

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: I583f3124faab024cb9f199f7b3c840d8a68b7cd4
2 parents 01eeefd + 38a44bd commit 8653b74

File tree

153 files changed

+2111
-2106
lines changed

Some content is hidden

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

153 files changed

+2111
-2106
lines changed

clang/lib/Format/FormatInternal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#ifndef LLVM_CLANG_LIB_FORMAT_FORMATINTERNAL_H
1616
#define LLVM_CLANG_LIB_FORMAT_FORMATINTERNAL_H
1717

18+
#include "clang/Basic/LLVM.h"
19+
#include "clang/Format/Format.h"
20+
#include "clang/Tooling/Core/Replacement.h"
21+
#include <utility>
22+
1823
namespace clang {
1924
namespace format {
2025
namespace internal {

clang/lib/Sema/SemaChecking.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5189,6 +5189,7 @@ static bool isPPC_64Builtin(unsigned BuiltinID) {
51895189
case PPC::BI__builtin_ppc_fetch_and_andlp:
51905190
case PPC::BI__builtin_ppc_fetch_and_orlp:
51915191
case PPC::BI__builtin_ppc_fetch_and_swaplp:
5192+
case PPC::BI__builtin_ppc_rldimi:
51925193
return true;
51935194
}
51945195
return false;
@@ -5290,8 +5291,10 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID,
52905291
case PPC::BI__builtin_ppc_rlwnm:
52915292
return SemaValueIsRunOfOnes(TheCall, 2);
52925293
case PPC::BI__builtin_ppc_rlwimi:
5294+
return SemaBuiltinConstantArgRange(TheCall, 2, 0, 31) ||
5295+
SemaValueIsRunOfOnes(TheCall, 3);
52935296
case PPC::BI__builtin_ppc_rldimi:
5294-
return SemaBuiltinConstantArg(TheCall, 2, Result) ||
5297+
return SemaBuiltinConstantArgRange(TheCall, 2, 0, 63) ||
52955298
SemaValueIsRunOfOnes(TheCall, 3);
52965299
case PPC::BI__builtin_ppc_addex: {
52975300
if (SemaBuiltinConstantArgRange(TheCall, 2, 0, 3))

clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-error.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ void test_trap(void) {
2424
__tw(ia, ib, 0); //expected-error {{argument value 0 is outside the valid range [1, 31]}}
2525
}
2626

27+
#ifdef __PPC64__
2728
void test_builtin_ppc_rldimi() {
2829
unsigned int shift;
2930
unsigned long long mask;
3031
unsigned long long res = __builtin_ppc_rldimi(ull, ull, shift, 7); // expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
3132
res = __builtin_ppc_rldimi(ull, ull, 63, mask); // expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
3233
res = __builtin_ppc_rldimi(ull, ull, 63, 0xFFFF000000000F00); // expected-error {{argument 3 value should represent a contiguous bit field}}
34+
res = __builtin_ppc_rldimi(ull, ull, 64, 0xFFFF000000000000); // expected-error {{argument value 64 is outside the valid range [0, 63]}}
3335
}
36+
#endif
3437

3538
void test_builtin_ppc_rlwimi() {
3639
unsigned int shift;
@@ -83,6 +86,10 @@ void testalignx(const void *pointer, unsigned int alignment) {
8386
}
8487

8588
#ifndef __PPC64__
89+
unsigned long long testrldimi32() {
90+
return __rldimi(ull, ui, 3, 0x7ffff8ULL); //expected-error {{this builtin is only available on 64-bit targets}}
91+
}
92+
8693
long long testbpermd(long long bit_selector, long long source) {
8794
return __bpermd(bit_selector, source); //expected-error {{this builtin is only available on 64-bit targets}}
8895
}

clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// REQUIRES: powerpc-registered-target
22
// RUN: %clang_cc1 -triple powerpc64-unknown-linux-gnu \
3-
// RUN: -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
3+
// RUN: -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s \
4+
// RUN: -check-prefixes=PPC64,CHECK
45
// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu \
5-
// RUN: -emit-llvm %s -o - -target-cpu pwr8 | FileCheck %s
6+
// RUN: -emit-llvm %s -o - -target-cpu pwr8 | FileCheck %s \
7+
// RUN: -check-prefixes=PPC64,CHECK
68
// RUN: %clang_cc1 -triple powerpc-unknown-aix \
79
// RUN: -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
810
// RUN: %clang_cc1 -triple powerpc64-unknown-aix \
@@ -11,18 +13,20 @@
1113
extern unsigned int ui;
1214
extern unsigned long long ull;
1315

16+
#ifdef __PPC64__
1417
void test_builtin_ppc_rldimi() {
15-
// CHECK-LABEL: test_builtin_ppc_rldimi
16-
// CHECK: %res = alloca i64, align 8
17-
// CHECK-NEXT: [[RA:%[0-9]+]] = load i64, ptr @ull, align 8
18-
// CHECK-NEXT: [[RB:%[0-9]+]] = load i64, ptr @ull, align 8
19-
// CHECK-NEXT: [[RC:%[0-9]+]] = call i64 @llvm.ppc.rldimi(i64 [[RA]], i64 [[RB]], i32 63, i64 72057593769492480)
20-
// CHECK-NEXT: store i64 [[RC]], ptr %res, align 8
21-
// CHECK-NEXT: ret void
18+
// PPC64-LABEL: test_builtin_ppc_rldimi
19+
// PPC64: %res = alloca i64, align 8
20+
// PPC64-NEXT: [[RA:%[0-9]+]] = load i64, ptr @ull, align 8
21+
// PPC64-NEXT: [[RB:%[0-9]+]] = load i64, ptr @ull, align 8
22+
// PPC64-NEXT: [[RC:%[0-9]+]] = call i64 @llvm.ppc.rldimi(i64 [[RA]], i64 [[RB]], i32 63, i64 72057593769492480)
23+
// PPC64-NEXT: store i64 [[RC]], ptr %res, align 8
24+
// PPC64-NEXT: ret void
2225

2326
/*shift = 63, mask = 0x00FFFFFFF0000000 = 72057593769492480, ~mask = 0xFF0000000FFFFFFF = -72057593769492481*/
2427
unsigned long long res = __builtin_ppc_rldimi(ull, ull, 63, 0x00FFFFFFF0000000);
2528
}
29+
#endif
2630

2731
void test_builtin_ppc_rlwimi() {
2832
// CHECK-LABEL: test_builtin_ppc_rlwimi

clang/unittests/Format/FormatTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11475,10 +11475,10 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
1147511475
"void new (link p);\n"
1147611476
"void delete (link p);");
1147711477

11478-
verifyFormat("{ p->delete(); }\n"
11479-
"{ p->new(); }",
11480-
"{ p->delete (); }\n"
11481-
"{ p->new (); }");
11478+
verifyFormat("p->new();\n"
11479+
"p->delete();",
11480+
"p->new ();\n"
11481+
"p->delete ();");
1148211482

1148311483
FormatStyle AfterPlacementOperator = getLLVMStyle();
1148411484
AfterPlacementOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom;

flang/lib/Lower/Bridge.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
748748

749749
void copyVar(mlir::Location loc, mlir::Value dst,
750750
mlir::Value src) override final {
751-
copyVarHLFIR(loc, dst, src);
751+
copyVarHLFIR(loc, Fortran::lower::SymbolBox::Intrinsic{dst},
752+
Fortran::lower::SymbolBox::Intrinsic{src});
752753
}
753754

754755
void copyHostAssociateVar(
@@ -1009,10 +1010,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10091010
// `omp.private`'s `alloc` block. If this is the case, we return this
10101011
// `SymbolBox::Intrinsic` value.
10111012
if (Fortran::lower::SymbolBox v = symMap->lookupSymbol(sym))
1012-
return v.match(
1013-
[&](const Fortran::lower::SymbolBox::Intrinsic &)
1014-
-> Fortran::lower::SymbolBox { return v; },
1015-
[](const auto &) -> Fortran::lower::SymbolBox { return {}; });
1013+
return v;
10161014

10171015
return {};
10181016
}
@@ -1060,15 +1058,16 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10601058
const Fortran::lower::SymbolBox &rhs_sb) {
10611059
mlir::Location loc = genLocation(sym.name());
10621060
if (lowerToHighLevelFIR())
1063-
copyVarHLFIR(loc, lhs_sb.getAddr(), rhs_sb.getAddr());
1061+
copyVarHLFIR(loc, lhs_sb, rhs_sb);
10641062
else
10651063
copyVarFIR(loc, sym, lhs_sb, rhs_sb);
10661064
}
10671065

1068-
void copyVarHLFIR(mlir::Location loc, mlir::Value dst, mlir::Value src) {
1066+
void copyVarHLFIR(mlir::Location loc, Fortran::lower::SymbolBox dst,
1067+
Fortran::lower::SymbolBox src) {
10691068
assert(lowerToHighLevelFIR());
1070-
hlfir::Entity lhs{dst};
1071-
hlfir::Entity rhs{src};
1069+
hlfir::Entity lhs{dst.getAddr()};
1070+
hlfir::Entity rhs{src.getAddr()};
10721071
// Temporary_lhs is set to true in hlfir.assign below to avoid user
10731072
// assignment to be used and finalization to be called on the LHS.
10741073
// This may or may not be correct but mimics the current behaviour
@@ -1082,7 +1081,22 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10821081
/*keepLhsLengthInAllocatableAssignment=*/false,
10831082
/*temporary_lhs=*/true);
10841083
};
1085-
if (lhs.isAllocatable()) {
1084+
1085+
bool isBoxAllocatable = dst.match(
1086+
[](const fir::MutableBoxValue &box) { return box.isAllocatable(); },
1087+
[](const fir::FortranVariableOpInterface &box) {
1088+
return fir::FortranVariableOpInterface(box).isAllocatable();
1089+
},
1090+
[](const auto &box) { return false; });
1091+
1092+
bool isBoxPointer = dst.match(
1093+
[](const fir::MutableBoxValue &box) { return box.isPointer(); },
1094+
[](const fir::FortranVariableOpInterface &box) {
1095+
return fir::FortranVariableOpInterface(box).isPointer();
1096+
},
1097+
[](const auto &box) { return false; });
1098+
1099+
if (isBoxAllocatable) {
10861100
// Deep copy allocatable if it is allocated.
10871101
// Note that when allocated, the RHS is already allocated with the LHS
10881102
// shape for copy on entry in createHostAssociateVarClone.
@@ -1097,7 +1111,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
10971111
copyData(lhs, rhs);
10981112
})
10991113
.end();
1100-
} else if (lhs.isPointer()) {
1114+
} else if (isBoxPointer) {
11011115
// Set LHS target to the target of RHS (do not copy the RHS
11021116
// target data into the LHS target storage).
11031117
auto loadVal = builder->create<fir::LoadOp>(loc, rhs);

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void DataSharingProcessor::processStep2(mlir::Operation *op, bool isLoop) {
5050
}
5151

5252
void DataSharingProcessor::insertDeallocs() {
53+
// TODO Extend delayed privatization to include a `dealloc` region.
5354
for (const Fortran::semantics::Symbol *sym : privatizedSymbols)
5455
if (Fortran::semantics::IsAllocatable(sym->GetUltimate())) {
5556
converter.createHostAssociateVarCloneDealloc(*sym);
@@ -367,6 +368,7 @@ void DataSharingProcessor::doPrivatize(const Fortran::semantics::Symbol *sym) {
367368
symLoc, uniquePrivatizerName, symType,
368369
isFirstPrivate ? mlir::omp::DataSharingClauseType::FirstPrivate
369370
: mlir::omp::DataSharingClauseType::Private);
371+
fir::ExtendedValue symExV = converter.getSymbolExtendedValue(*sym);
370372

371373
symTable->pushScope();
372374

@@ -377,7 +379,8 @@ void DataSharingProcessor::doPrivatize(const Fortran::semantics::Symbol *sym) {
377379
&allocRegion, /*insertPt=*/{}, symType, symLoc);
378380

379381
firOpBuilder.setInsertionPointToEnd(allocEntryBlock);
380-
symTable->addSymbol(*sym, allocRegion.getArgument(0));
382+
symTable->addSymbol(*sym,
383+
fir::substBase(symExV, allocRegion.getArgument(0)));
381384
symTable->pushScope();
382385
cloneSymbol(sym);
383386
firOpBuilder.create<mlir::omp::YieldOp>(
@@ -394,10 +397,12 @@ void DataSharingProcessor::doPrivatize(const Fortran::semantics::Symbol *sym) {
394397
mlir::Block *copyEntryBlock = firOpBuilder.createBlock(
395398
&copyRegion, /*insertPt=*/{}, {symType, symType}, {symLoc, symLoc});
396399
firOpBuilder.setInsertionPointToEnd(copyEntryBlock);
397-
symTable->addSymbol(*sym, copyRegion.getArgument(0),
400+
symTable->addSymbol(*sym,
401+
fir::substBase(symExV, copyRegion.getArgument(0)),
398402
/*force=*/true);
399403
symTable->pushScope();
400-
symTable->addSymbol(*sym, copyRegion.getArgument(1));
404+
symTable->addSymbol(*sym,
405+
fir::substBase(symExV, copyRegion.getArgument(1)));
401406
auto ip = firOpBuilder.saveInsertionPoint();
402407
copyFirstPrivateSymbol(sym, &ip);
403408

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
! Test delayed privatization for allocatables: `firstprivate`.
2+
3+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization \
4+
! RUN: -o - %s 2>&1 | FileCheck %s
5+
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %s 2>&1 |\
6+
! RUN: FileCheck %s
7+
8+
subroutine delayed_privatization_allocatable
9+
implicit none
10+
integer, allocatable :: var1
11+
12+
!$omp parallel firstprivate(var1)
13+
var1 = 10
14+
!$omp end parallel
15+
end subroutine
16+
17+
! CHECK-LABEL: omp.private {type = firstprivate}
18+
! CHECK-SAME: @[[PRIVATIZER_SYM:.*]] : [[TYPE:!fir.ref<!fir.box<!fir.heap<i32>>>]] alloc {
19+
20+
! CHECK-NEXT: ^bb0(%[[PRIV_ARG:.*]]: [[TYPE]]):
21+
22+
! CHECK: } copy {
23+
! CHECK: ^bb0(%[[PRIV_ORIG_ARG:.*]]: [[TYPE]], %[[PRIV_PRIV_ARG:.*]]: [[TYPE]]):
24+
25+
! CHECK-NEXT: %[[PRIV_BASE_VAL:.*]] = fir.load %[[PRIV_PRIV_ARG]]
26+
! CHECK-NEXT: %[[PRIV_BASE_BOX:.*]] = fir.box_addr %[[PRIV_BASE_VAL]]
27+
! CHECK-NEXT: %[[PRIV_BASE_ADDR:.*]] = fir.convert %[[PRIV_BASE_BOX]]
28+
! CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : i64
29+
! CHECK-NEXT: %[[COPY_COND:.*]] = arith.cmpi ne, %[[PRIV_BASE_ADDR]], %[[C0]] : i64
30+
31+
! CHECK-NEXT: fir.if %[[COPY_COND]] {
32+
! CHECK-NEXT: %[[ORIG_BASE_VAL:.*]] = fir.load %[[PRIV_ORIG_ARG]]
33+
! CHECK-NEXT: %[[ORIG_BASE_ADDR:.*]] = fir.box_addr %[[ORIG_BASE_VAL]]
34+
! CHECK-NEXT: %[[ORIG_BASE_LD:.*]] = fir.load %[[ORIG_BASE_ADDR]]
35+
! CHECK-NEXT: hlfir.assign %[[ORIG_BASE_LD]] to %[[PRIV_BASE_BOX]] temporary_lhs
36+
! CHECK-NEXT: }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
! Test delayed privatization for allocatables: `private`.
2+
3+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization \
4+
! RUN: -o - %s 2>&1 | FileCheck %s
5+
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %s 2>&1 |\
6+
! RUN: FileCheck %s
7+
8+
subroutine delayed_privatization_allocatable
9+
implicit none
10+
integer, allocatable :: var1
11+
12+
!$omp parallel private(var1)
13+
var1 = 10
14+
!$omp end parallel
15+
end subroutine
16+
17+
! CHECK-LABEL: omp.private {type = private}
18+
! CHECK-SAME: @[[PRIVATIZER_SYM:.*]] : [[TYPE:!fir.ref<!fir.box<!fir.heap<i32>>>]] alloc {
19+
20+
! CHECK-NEXT: ^bb0(%[[PRIV_ARG:.*]]: [[TYPE]]):
21+
22+
! CHECK-NEXT: %[[PRIV_ALLOC:.*]] = fir.alloca !fir.box<!fir.heap<i32>> {bindc_name = "var1", pinned, uniq_name = "_QFdelayed_privatization_allocatableEvar1"}
23+
24+
! CHECK-NEXT: %[[PRIV_ARG_VAL:.*]] = fir.load %[[PRIV_ARG]] : !fir.ref<!fir.box<!fir.heap<i32>>>
25+
! CHECK-NEXT: %[[PRIV_ARG_BOX:.*]] = fir.box_addr %[[PRIV_ARG_VAL]] : (!fir.box<!fir.heap<i32>>) -> !fir.heap<i32>
26+
! CHECK-NEXT: %[[PRIV_ARG_ADDR:.*]] = fir.convert %[[PRIV_ARG_BOX]] : (!fir.heap<i32>) -> i64
27+
! CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : i64
28+
! CHECK-NEXT: %[[ALLOC_COND:.*]] = arith.cmpi ne, %[[PRIV_ARG_ADDR]], %[[C0]] : i64
29+
30+
! CHECK-NEXT: fir.if %[[ALLOC_COND]] {
31+
! CHECK-NEXT: %[[PRIV_ALLOCMEM:.*]] = fir.allocmem i32 {fir.must_be_heap = true, uniq_name = "_QFdelayed_privatization_allocatableEvar1.alloc"}
32+
! CHECK-NEXT: %[[PRIV_ALLOCMEM_BOX:.*]] = fir.embox %[[PRIV_ALLOCMEM]] : (!fir.heap<i32>) -> !fir.box<!fir.heap<i32>>
33+
! CHECK-NEXT: fir.store %[[PRIV_ALLOCMEM_BOX]] to %[[PRIV_ALLOC]] : !fir.ref<!fir.box<!fir.heap<i32>>>
34+
! CHECK-NEXT: } else {
35+
! CHECK-NEXT: %[[ZERO_BITS:.*]] = fir.zero_bits !fir.heap<i32>
36+
! CHECK-NEXT: %[[ZERO_BOX:.*]] = fir.embox %[[ZERO_BITS]] : (!fir.heap<i32>) -> !fir.box<!fir.heap<i32>>
37+
! CHECK-NEXT: fir.store %[[ZERO_BOX]] to %[[PRIV_ALLOC]] : !fir.ref<!fir.box<!fir.heap<i32>>>
38+
! CHECK-NEXT: }
39+
40+
! CHECK-NEXT: %[[PRIV_DECL:.*]]:2 = hlfir.declare %[[PRIV_ALLOC]]
41+
! CHECK-NEXT: omp.yield(%[[PRIV_DECL]]#0 : [[TYPE]])
42+
43+
! CHECK-NEXT: }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
! Test delayed privatization for pointers: `private`.
2+
3+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization \
4+
! RUN: -o - %s 2>&1 | FileCheck %s
5+
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization -o - %s 2>&1 |\
6+
! RUN: FileCheck %s
7+
8+
subroutine delayed_privatization_pointer
9+
implicit none
10+
integer, pointer :: var1
11+
12+
!$omp parallel firstprivate(var1)
13+
var1 = 10
14+
!$omp end parallel
15+
end subroutine
16+
17+
! CHECK-LABEL: omp.private {type = firstprivate}
18+
! CHECK-SAME: @[[PRIVATIZER_SYM:.*]] : [[TYPE:!fir.ref<!fir.box<!fir.ptr<i32>>>]] alloc {
19+
20+
! CHECK-NEXT: ^bb0(%[[PRIV_ARG:.*]]: [[TYPE]]):
21+
22+
! CHECK-NEXT: %[[PRIV_ALLOC:.*]] = fir.alloca !fir.box<!fir.ptr<i32>> {bindc_name = "var1", pinned, uniq_name = "_QFdelayed_privatization_pointerEvar1"}
23+
! CHECK-NEXT: %[[PRIV_DECL:.*]]:2 = hlfir.declare %[[PRIV_ALLOC]]
24+
! CHECK-NEXT: omp.yield(%[[PRIV_DECL]]#0 : [[TYPE]])
25+
26+
! CHECK-NEXT: } copy {
27+
! CHECK: ^bb0(%[[PRIV_ORIG_ARG:.*]]: [[TYPE]], %[[PRIV_PRIV_ARG:.*]]: [[TYPE]]):
28+
! CHECK-NEXT: %[[ORIG_BASE_VAL:.*]] = fir.load %[[PRIV_ORIG_ARG]]
29+
! CHECK-NEXT: fir.store %[[ORIG_BASE_VAL]] to %[[PRIV_PRIV_ARG]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
30+
! CHECK-NEXT: omp.yield(%[[PRIV_PRIV_ARG]] : [[TYPE]])
31+
! CHECK-NEXT: }

0 commit comments

Comments
 (0)