diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -6306,11 +6306,6 @@ if (const auto *C = S.getSingleClause()) Device = EmitScalarExpr(C->getDevice()); - int DependClauseCount = 0; - for (const auto *DC : S.getClausesOfKind()) - DependClauseCount++; - assert(DependClauseCount <= 1 && "Multiple OMPDependClause not supported."); - llvm::Value *NumDependences = nullptr; llvm::Value *DependenceAddress = nullptr; if (const auto *DC = S.getSingleClause()) { @@ -6325,37 +6320,35 @@ DependencePair.second.getPointer(), CGM.Int8PtrTy); } - int HaveNowaitClause = 0; - if (S.getSingleClause()) - HaveNowaitClause = 1; + bool HaveNowaitClause = S.hasClausesOfKind(); if (const auto *C = S.getSingleClause()) { llvm::Value *InteropvarPtr = - (EmitLValue(C->getInteropVar()).getAddress(*this)).getPointer(); - llvm::OMPInteropType InteropType = llvm::OMPInteropType::Unknown; + EmitLValue(C->getInteropVar()).getPointer(*this); + llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown; if (C->getIsTarget()) - InteropType = llvm::OMPInteropType::Target; + InteropType = llvm::omp::OMPInteropType::Target; else if (C->getIsTargetSync()) - InteropType = llvm::OMPInteropType::TargetSync; + InteropType = llvm::omp::OMPInteropType::TargetSync; OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, Device, NumDependences, DependenceAddress, HaveNowaitClause); } else if (const auto *C = S.getSingleClause()) { llvm::Value *InteropvarPtr = - (EmitLValue(C->getInteropVar()).getAddress(*this)).getPointer(); + EmitLValue(C->getInteropVar()).getPointer(*this); OMPBuilder.createOMPInteropDestroy(Builder, InteropvarPtr, Device, NumDependences, DependenceAddress, HaveNowaitClause); } else if (const auto *C = S.getSingleClause()) { llvm::Value *InteropvarPtr = - (EmitLValue(C->getInteropVar()).getAddress(*this)).getPointer(); + EmitLValue(C->getInteropVar()).getPointer(*this); OMPBuilder.createOMPInteropUse(Builder, InteropvarPtr, Device, NumDependences, DependenceAddress, HaveNowaitClause); - } else if (HaveNowaitClause == true) { - llvm_unreachable("Nowait clause is used separately in Interop Directive."); + } else if(HaveNowaitClause == true) { + assert("Nowait clause is used separately in OMPInteropDirective."); } else { - llvm_unreachable("Missing Interop clauses."); + assert("Unhandled or missing clause for OMPInteropDirective "); } } diff --git a/clang/test/OpenMP/interop_irbuilder.cpp b/clang/test/OpenMP/interop_irbuilder.cpp --- a/clang/test/OpenMP/interop_irbuilder.cpp +++ b/clang/test/OpenMP/interop_irbuilder.cpp @@ -1,3 +1,4 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs // RUN: %clang_cc1 -verify -fopenmp -o - %s // expected-no-diagnostics @@ -5,20 +6,20 @@ void test1() { - int device_id = 4; + int device_id = 4; int D0, D1; omp_interop_t interop; - #pragma omp interop init(target: interop) + #pragma omp interop init(target: interop) #pragma omp interop init(targetsync: interop) - + #pragma omp interop init(target: interop) device(device_id) - - #pragma omp interop init(targetsync: interop) device(device_id) - + + #pragma omp interop init(targetsync: interop) device(device_id) + #pragma omp interop use(interop) depend(in:D0, D1) nowait - #pragma omp interop destroy(interop) depend(in:D0, D1) + #pragma omp interop destroy(interop) depend(in:D0, D1) } diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h b/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPConstants.h @@ -128,10 +128,11 @@ LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ ModifierMask) }; -} // end namespace omp - +/// \note This needs to be kept in sync with interop.h enum kmp_interop_type_t.: enum class OMPInteropType { Unknown, Target, TargetSync }; +} // end namespace omp + } // end namespace llvm #endif // LLVM_FRONTEND_OPENMP_OMPCONSTANTS_H diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -791,10 +791,10 @@ /// /// \returns CallInst to the kmpc_interop_init call CallInst * - createOMPInteropInit(const LocationDescription &Loc, llvm::Value *InteropVar, - OMPInteropType InteropType, llvm::Value *Device, - llvm::Value *NumDependences, - llvm::Value *DependenceAddress, int HaveNowaitClause); + createOMPInteropInit(const LocationDescription &Loc, Value *InteropVar, + omp::OMPInteropType InteropType, Value *Device, + Value *NumDependences, + Value *DependenceAddress, bool HaveNowaitClause); /// Create a runtime call for kmpc_interop_destroy /// @@ -807,11 +807,11 @@ /// /// \returns CallInst to the kmpc_interop_destroy call CallInst *createOMPInteropDestroy(const LocationDescription &Loc, - llvm::Value *InteropVar, - llvm::Value *Device, - llvm::Value *NumDependences, - llvm::Value *DependenceAddress, - int HaveNowaitClause); + Value *InteropVar, + Value *Device, + Value *NumDependences, + Value *DependenceAddress, + bool HaveNowaitClause); /// Create a runtime call for kmpc_interop_use /// @@ -824,10 +824,10 @@ /// /// \returns CallInst to the kmpc_interop_use call CallInst *createOMPInteropUse(const LocationDescription &Loc, - llvm::Value *InteropVar, llvm::Value *Device, - llvm::Value *NumDependences, - llvm::Value *DependenceAddress, - int HaveNowaitClause); + Value *InteropVar, Value *Device, + Value *NumDependences, + Value *DependenceAddress, + bool HaveNowaitClause); /// Declarations for LLVM-IR types (simple, array, function and structure) are /// The `omp target` interface diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -2175,11 +2175,11 @@ CallInst *OpenMPIRBuilder::createOMPInteropInit(const LocationDescription &Loc, Value *InteropVar, - OMPInteropType InteropType, - llvm::Value *Device, - llvm::Value *NumDependences, - llvm::Value *DependenceAddress, - int HaveNowaitClause) { + omp::OMPInteropType InteropType, + Value *Device, + Value *NumDependences, + Value *DependenceAddress, + bool HaveNowaitClause) { IRBuilder<>::InsertPointGuard IPG(Builder); Builder.restoreIP(Loc.IP); @@ -2188,12 +2188,12 @@ Value *ThreadId = getOrCreateThreadID(Ident); if (Device == NULL) Device = ConstantInt::get(M.getContext(), APInt(32, -1, true)); - ConstantInt *InteropTypeVal = - ConstantInt::get(M.getContext(), APInt(64, (int)InteropType, true)); + Constant *InteropTypeVal = + ConstantInt::get(Int64, (int)InteropType); if (NumDependences == nullptr) { - NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true)); - PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext()); - DependenceAddress = ConstantPointerNull::get(PointerTy_0); + NumDependences = ConstantInt::get(Int32, 0); + PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext()); + DependenceAddress = ConstantPointerNull::get(PointerTypeVar); } Value *HaveNowaitClauseVal = ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true)); @@ -2207,9 +2207,9 @@ } CallInst *OpenMPIRBuilder::createOMPInteropDestroy( - const LocationDescription &Loc, Value *InteropVar, llvm::Value *Device, - llvm::Value *NumDependences, llvm::Value *DependenceAddress, - int HaveNowaitClause) { + const LocationDescription &Loc, Value *InteropVar, Value *Device, + Value *NumDependences, Value *DependenceAddress, + bool HaveNowaitClause) { IRBuilder<>::InsertPointGuard IPG(Builder); Builder.restoreIP(Loc.IP); @@ -2219,9 +2219,9 @@ if (Device == NULL) Device = ConstantInt::get(M.getContext(), APInt(32, -1, true)); if (NumDependences == nullptr) { - NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true)); - PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext()); - DependenceAddress = ConstantPointerNull::get(PointerTy_0); + NumDependences = ConstantInt::get(Int32, 0); + PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext()); + DependenceAddress = ConstantPointerNull::get(PointerTypeVar); } Value *HaveNowaitClauseVal = ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true)); @@ -2236,10 +2236,10 @@ CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription &Loc, Value *InteropVar, - llvm::Value *Device, - llvm::Value *NumDependences, - llvm::Value *DependenceAddress, - int HaveNowaitClause) { + Value *Device, + Value *NumDependences, + Value *DependenceAddress, + bool HaveNowaitClause) { IRBuilder<>::InsertPointGuard IPG(Builder); Builder.restoreIP(Loc.IP); Constant *SrcLocStr = getOrCreateSrcLocStr(Loc); @@ -2248,9 +2248,9 @@ if (Device == NULL) Device = ConstantInt::get(M.getContext(), APInt(32, -1, true)); if (NumDependences == nullptr) { - NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true)); - PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext()); - DependenceAddress = ConstantPointerNull::get(PointerTy_0); + NumDependences = ConstantInt::get(Int32, 0); + PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext()); + DependenceAddress = ConstantPointerNull::get(PointerTypeVar); } Value *HaveNowaitClauseVal = ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));