Skip to content

Commit 1830ed2

Browse files
committed
Use BuildBuildins in OpenMPIRBuilder
1 parent b072cab commit 1830ed2

File tree

8 files changed

+24978
-13872
lines changed

8 files changed

+24978
-13872
lines changed

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6740,16 +6740,18 @@ static void emitOMPAtomicCompareExpr(
67406740
R->getType().isVolatileQualified()};
67416741
}
67426742

6743+
llvm::OpenMPIRBuilder::InsertPointTy AllocaIP(
6744+
CGF.AllocaInsertPt->getParent(), CGF.AllocaInsertPt->getIterator());
67436745
if (FailAO == llvm::AtomicOrdering::NotAtomic) {
67446746
// fail clause was not mentioned on the
67456747
// "#pragma omp atomic compare" construct.
6746-
CGF.Builder.restoreIP(OMPBuilder.createAtomicCompare(
6747-
CGF.Builder, XOpVal, VOpVal, ROpVal, EVal, DVal, AO, Op, IsXBinopExpr,
6748-
IsPostfixUpdate, IsFailOnly));
6748+
CGF.Builder.restoreIP(cantFail(OMPBuilder.createAtomicCompare(
6749+
CGF.Builder, AllocaIP, XOpVal, VOpVal, ROpVal, EVal, DVal, AO, Op,
6750+
IsXBinopExpr, IsPostfixUpdate, IsFailOnly)));
67496751
} else
6750-
CGF.Builder.restoreIP(OMPBuilder.createAtomicCompare(
6751-
CGF.Builder, XOpVal, VOpVal, ROpVal, EVal, DVal, AO, Op, IsXBinopExpr,
6752-
IsPostfixUpdate, IsFailOnly, FailAO));
6752+
CGF.Builder.restoreIP(cantFail(OMPBuilder.createAtomicCompare(
6753+
CGF.Builder, AllocaIP, XOpVal, VOpVal, ROpVal, EVal, DVal, AO, Op,
6754+
IsXBinopExpr, IsPostfixUpdate, IsFailOnly, FailAO)));
67536755
}
67546756

67556757
static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,

clang/test/OpenMP/atomic_compare_codegen.cpp

Lines changed: 23272 additions & 12978 deletions
Large diffs are not rendered by default.

flang/test/Integration/OpenMP/atomic-capture-complex.f90

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,43 @@
66
! added to this directory and sub-directories.
77
!===----------------------------------------------------------------------===!
88

9-
!RUN: %if x86-registered-target %{ %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fopenmp %s -o - | FileCheck --check-prefixes=CHECK,X86 %s %}
10-
!RUN: %if aarch64-registerd-target %{ %flang_fc1 -triple aarch64-unknown-linux-gnu -emit-llvm -fopenmp %s -o - | FileCheck --check-prefixes=CHECK,AARCH64 %s %}
9+
!RUN: %if x86-registered-target %{ %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fopenmp -mllvm --disable-llvm %s -o - | FileCheck %s %}
10+
!RUN: %if aarch64-registerd-target %{ %flang_fc1 -triple aarch64-unknown-linux-gnu -emit-llvm -fopenmp -mllvm --disable-llvm %s -o - | FileCheck %s %}
1111

12-
!CHECK: %[[X_NEW_VAL:.*]] = alloca { float, float }, align 8
13-
!CHECK: %[[VAL_1:.*]] = alloca { float, float }, i64 1, align 8
14-
!CHECK: %[[ORIG_VAL:.*]] = alloca { float, float }, i64 1, align 8
15-
!CHECK: store { float, float } { float 2.000000e+00, float 2.000000e+00 }, ptr %[[ORIG_VAL]], align 4
16-
!CHECK: br label %entry
17-
18-
!CHECK: entry:
19-
!CHECK: %[[ATOMIC_TEMP_LOAD:.*]] = alloca { float, float }, align 8
20-
!CHECK: call void @__atomic_load(i64 8, ptr %[[ORIG_VAL]], ptr %[[ATOMIC_TEMP_LOAD]], i32 0)
21-
!CHECK: %[[PHI_NODE_ENTRY_1:.*]] = load { float, float }, ptr %[[ATOMIC_TEMP_LOAD]], align 8
22-
!CHECK: br label %.atomic.cont
23-
24-
!CHECK: .atomic.cont
25-
!CHECK: %[[VAL_4:.*]] = phi { float, float } [ %[[PHI_NODE_ENTRY_1]], %entry ], [ %{{.*}}, %.atomic.cont ]
26-
!CHECK: %[[VAL_5:.*]] = extractvalue { float, float } %[[VAL_4]], 0
27-
!CHECK: %[[VAL_6:.*]] = extractvalue { float, float } %[[VAL_4]], 1
28-
!CHECK: %[[VAL_7:.*]] = fadd contract float %[[VAL_5]], 1.000000e+00
29-
!CHECK: %[[VAL_8:.*]] = fadd contract float %[[VAL_6]], 1.000000e+00
30-
!CHECK: %[[VAL_9:.*]] = insertvalue { float, float } undef, float %[[VAL_7]], 0
31-
!CHECK: %[[VAL_10:.*]] = insertvalue { float, float } %[[VAL_9]], float %[[VAL_8]], 1
32-
!CHECK: store { float, float } %[[VAL_10]], ptr %[[X_NEW_VAL]], align 4
33-
!CHECK: %[[VAL_11:.*]] = call i1 @__atomic_compare_exchange(i64 8, ptr %[[ORIG_VAL]], ptr %[[ATOMIC_TEMP_LOAD]], ptr %[[X_NEW_VAL]],
34-
!i32 2, i32 2)
35-
!CHECK: %[[VAL_12:.*]] = load { float, float }, ptr %[[ATOMIC_TEMP_LOAD]], align 4
36-
!CHECK: br i1 %[[VAL_11]], label %.atomic.exit, label %.atomic.cont
37-
38-
!CHECK: .atomic.exit
39-
!AARCH64: %[[LCSSA:.*]] = phi { float, float } [ %[[VAL_10]], %.atomic.cont ]
40-
!AARCH64: store { float, float } %[[LCSSA]], ptr %[[VAL_1]], align 4
41-
!X86: store { float, float } %[[VAL_10]], ptr %[[VAL_1]], align 4
12+
! CHECK-LABEL: define {{.*}}@_QQmain(
13+
! CHECK-NEXT: %[[DOTATOMIC_ORIG_PTR:.+]] = alloca { float, float }, align 8
14+
! CHECK-NEXT: %[[DOTATOMIC_UPD_PTR:.+]] = alloca { float, float }, align 8
15+
! CHECK-NEXT: %[[TMP1:.+]] = alloca { float, float }, i64 1, align 8
16+
! CHECK-NEXT: %[[TMP2:.+]] = alloca { float, float }, i64 1, align 8
17+
! CHECK-NEXT: store { float, float } { float 2.000000e+00, float 2.000000e+00 }, ptr %[[TMP2]], align 4
18+
! CHECK-NEXT: br label %[[ENTRY:.+]]
19+
! CHECK-EMPTY:
20+
! CHECK-NEXT: [[ENTRY]]:
21+
! CHECK-NEXT: %[[DOTATOMIC_LOAD:.+]] = load atomic i64, ptr %[[TMP2]] monotonic, align 8
22+
! CHECK-NEXT: store i64 %[[DOTATOMIC_LOAD]], ptr %[[DOTATOMIC_ORIG_PTR]], align 8
23+
! CHECK-NEXT: br label %[[DOTATOMIC_RETRY:.+]]
24+
! CHECK-EMPTY:
25+
! CHECK-NEXT: [[DOTATOMIC_RETRY]]:
26+
! CHECK-NEXT: %[[DOTATOMIC_ORIG:.+]] = load { float, float }, ptr %[[DOTATOMIC_ORIG_PTR]], align 4
27+
! CHECK-NEXT: %[[TMP3:.+]] = extractvalue { float, float } %[[DOTATOMIC_ORIG]], 0
28+
! CHECK-NEXT: %[[TMP4:.+]] = extractvalue { float, float } %[[DOTATOMIC_ORIG]], 1
29+
! CHECK-NEXT: %[[TMP5:.+]] = fadd contract float %[[TMP3]], 1.000000e+00
30+
! CHECK-NEXT: %[[TMP6:.+]] = fadd contract float %[[TMP4]], 1.000000e+00
31+
! CHECK-NEXT: %[[TMP7:.+]] = insertvalue { float, float } undef, float %[[TMP5]], 0
32+
! CHECK-NEXT: %[[TMP8:.+]] = insertvalue { float, float } %[[TMP7]], float %[[TMP6]], 1
33+
! CHECK-NEXT: store { float, float } %[[TMP8]], ptr %[[DOTATOMIC_UPD_PTR]], align 4
34+
! CHECK-NEXT: %[[DOTCMPXCHG_EXPECTED:.+]] = load i64, ptr %[[DOTATOMIC_ORIG_PTR]], align 8
35+
! CHECK-NEXT: %[[DOTCMPXCHG_DESIRED:.+]] = load i64, ptr %[[DOTATOMIC_UPD_PTR]], align 8
36+
! CHECK-NEXT: %[[DOTCMPXCHG_PAIR:.+]] = cmpxchg weak ptr %[[TMP2]], i64 %[[DOTCMPXCHG_EXPECTED]], i64 %[[DOTCMPXCHG_DESIRED]] monotonic monotonic, align 8
37+
! CHECK-NEXT: %[[DOTCMPXCHG_PREV:.+]] = extractvalue { i64, i1 } %[[DOTCMPXCHG_PAIR]], 0
38+
! CHECK-NEXT: store i64 %[[DOTCMPXCHG_PREV]], ptr %[[DOTATOMIC_ORIG_PTR]], align 8
39+
! CHECK-NEXT: %[[DOTCMPXCHG_SUCCESS:.+]] = extractvalue { i64, i1 } %[[DOTCMPXCHG_PAIR]], 1
40+
! CHECK-NEXT: br i1 %[[DOTCMPXCHG_SUCCESS]], label %[[DOTATOMIC_DONE:.+]], label %[[DOTATOMIC_RETRY]]
41+
! CHECK-EMPTY:
42+
! CHECK-NEXT: [[DOTATOMIC_DONE]]:
43+
! CHECK-NEXT: store { float, float } %[[TMP8]], ptr %[[TMP1]], align 4
44+
! CHECK-NEXT: ret void
45+
! CHECK-NEXT: }
4246

4347
program main
4448
complex*8 ia, ib

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,7 +3215,6 @@ class OpenMPIRBuilder {
32153215

32163216
/// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
32173217
/// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
3218-
/// Only Scalar data types.
32193218
///
32203219
/// \param AllocaIP The insertion point to be used for alloca
32213220
/// instructions.
@@ -3236,7 +3235,7 @@ class OpenMPIRBuilder {
32363235
/// (e.g. true for X = X BinOp Expr)
32373236
///
32383237
/// \returns A pair of the old value of X before the update, and the value
3239-
/// used for the update.
3238+
/// after the update.
32403239
Expected<std::pair<Value *, Value *>>
32413240
emitAtomicUpdate(InsertPointTy AllocaIP, Value *X, Type *XElemTy, Value *Expr,
32423241
AtomicOrdering AO, AtomicRMWInst::BinOp RMWOp,
@@ -3258,7 +3257,7 @@ class OpenMPIRBuilder {
32583257
bool IsVolatile = false;
32593258
};
32603259

3261-
/// Emit atomic Read for : V = X --- Only Scalar data types.
3260+
/// Emit atomic Read for : V = X.
32623261
///
32633262
/// \param Loc The insert and source location description.
32643263
/// \param X The target pointer to be atomically read
@@ -3268,9 +3267,9 @@ class OpenMPIRBuilder {
32683267
/// instructions.
32693268
///
32703269
/// \return Insertion point after generated atomic read IR.
3271-
InsertPointTy createAtomicRead(const LocationDescription &Loc,
3272-
AtomicOpValue &X, AtomicOpValue &V,
3273-
AtomicOrdering AO);
3270+
InsertPointOrErrorTy createAtomicRead(const LocationDescription &Loc,
3271+
AtomicOpValue &X, AtomicOpValue &V,
3272+
AtomicOrdering AO);
32743273

32753274
/// Emit atomic write for : X = Expr --- Only Scalar data types.
32763275
///
@@ -3281,9 +3280,10 @@ class OpenMPIRBuilder {
32813280
/// instructions.
32823281
///
32833282
/// \return Insertion point after generated atomic Write IR.
3284-
InsertPointTy createAtomicWrite(const LocationDescription &Loc,
3285-
AtomicOpValue &X, Value *Expr,
3286-
AtomicOrdering AO);
3283+
InsertPointOrErrorTy createAtomicWrite(const LocationDescription &Loc,
3284+
InsertPointTy AllocaIP,
3285+
AtomicOpValue &X, Value *Expr,
3286+
AtomicOrdering AO);
32873287

32883288
/// Emit atomic update for constructs: X = X BinOp Expr ,or X = Expr BinOp X
32893289
/// For complex Operations: X = UpdateOp(X) => CmpExch X, old_X, UpdateOp(X)
@@ -3392,18 +3392,17 @@ class OpenMPIRBuilder {
33923392
/// the case the comparison is '=='.
33933393
///
33943394
/// \return Insertion point after generated atomic capture IR.
3395-
InsertPointTy
3396-
createAtomicCompare(const LocationDescription &Loc, AtomicOpValue &X,
3397-
AtomicOpValue &V, AtomicOpValue &R, Value *E, Value *D,
3398-
AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
3399-
bool IsXBinopExpr, bool IsPostfixUpdate, bool IsFailOnly);
3400-
InsertPointTy createAtomicCompare(const LocationDescription &Loc,
3401-
AtomicOpValue &X, AtomicOpValue &V,
3402-
AtomicOpValue &R, Value *E, Value *D,
3403-
AtomicOrdering AO,
3404-
omp::OMPAtomicCompareOp Op,
3405-
bool IsXBinopExpr, bool IsPostfixUpdate,
3406-
bool IsFailOnly, AtomicOrdering Failure);
3395+
InsertPointOrErrorTy
3396+
createAtomicCompare(const LocationDescription &Loc, InsertPointTy AllocaIP,
3397+
AtomicOpValue &X, AtomicOpValue &V, AtomicOpValue &R,
3398+
Value *E, Value *D, AtomicOrdering AO,
3399+
omp::OMPAtomicCompareOp Op, bool IsXBinopExpr,
3400+
bool IsPostfixUpdate, bool IsFailOnly);
3401+
InsertPointOrErrorTy createAtomicCompare(
3402+
const LocationDescription &Loc, InsertPointTy AllocaIP, AtomicOpValue &X,
3403+
AtomicOpValue &V, AtomicOpValue &R, Value *E, Value *D, AtomicOrdering AO,
3404+
omp::OMPAtomicCompareOp Op, bool IsXBinopExpr, bool IsPostfixUpdate,
3405+
bool IsFailOnly, AtomicOrdering Failure);
34073406

34083407
/// Create the control flow structure of a canonical OpenMP loop.
34093408
///

0 commit comments

Comments
 (0)