diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -6796,61 +6796,6 @@ // code for that information. class MappableExprsHandler { public: - /// Values for bit flags used to specify the mapping type for - /// offloading. - enum OpenMPOffloadMappingFlags : uint64_t { - /// No flags - OMP_MAP_NONE = 0x0, - /// Allocate memory on the device and move data from host to device. - OMP_MAP_TO = 0x01, - /// Allocate memory on the device and move data from device to host. - OMP_MAP_FROM = 0x02, - /// Always perform the requested mapping action on the element, even - /// if it was already mapped before. - OMP_MAP_ALWAYS = 0x04, - /// Delete the element from the device environment, ignoring the - /// current reference count associated with the element. - OMP_MAP_DELETE = 0x08, - /// The element being mapped is a pointer-pointee pair; both the - /// pointer and the pointee should be mapped. - OMP_MAP_PTR_AND_OBJ = 0x10, - /// This flags signals that the base address of an entry should be - /// passed to the target kernel as an argument. - OMP_MAP_TARGET_PARAM = 0x20, - /// Signal that the runtime library has to return the device pointer - /// in the current position for the data being mapped. Used when we have the - /// use_device_ptr or use_device_addr clause. - OMP_MAP_RETURN_PARAM = 0x40, - /// This flag signals that the reference being passed is a pointer to - /// private data. - OMP_MAP_PRIVATE = 0x80, - /// Pass the element to the device by value. - OMP_MAP_LITERAL = 0x100, - /// Implicit map - OMP_MAP_IMPLICIT = 0x200, - /// Close is a hint to the runtime to allocate memory close to - /// the target device. - OMP_MAP_CLOSE = 0x400, - /// 0x800 is reserved for compatibility with XLC. - /// Produce a runtime error if the data is not already allocated. - OMP_MAP_PRESENT = 0x1000, - // Increment and decrement a separate reference counter so that the data - // cannot be unmapped within the associated region. Thus, this flag is - // intended to be used on 'target' and 'target data' directives because they - // are inherently structured. It is not intended to be used on 'target - // enter data' and 'target exit data' directives because they are inherently - // dynamic. - // This is an OpenMP extension for the sake of OpenACC support. - OMP_MAP_OMPX_HOLD = 0x2000, - /// Signal that the runtime library should use args as an array of - /// descriptor_dim pointers and use args_size as dims. Used when we have - /// non-contiguous list items in target update directive - OMP_MAP_NON_CONTIG = 0x100000000000, - /// The 16 MSBs of the flags indicate whether the entry is member of some - /// struct/class. - OMP_MAP_MEMBER_OF = 0xffff000000000000, - LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF), - }; /// Get the offset of the OMP_MAP_MEMBER_OF field. static unsigned getFlagMemberOffset() { @@ -7977,7 +7922,7 @@ /// Return the adjusted map modifiers if the declaration a capture refers to /// appears in a first-private clause. This is expected to be used only with /// directives that start with 'target'. - MappableExprsHandler::OpenMPOffloadMappingFlags + OpenMPOffloadMappingFlags getMapModifiersForPrivateClauses(const CapturedStmt::Capture &Cap) const { assert(Cap.capturesVariable() && "Expected capture by reference only!"); @@ -7986,10 +7931,8 @@ // declaration is known as first-private in this handler. if (FirstPrivateDecls.count(Cap.getCapturedVar())) { if (Cap.getCapturedVar()->getType()->isAnyPointerType()) - return MappableExprsHandler::OMP_MAP_TO | - MappableExprsHandler::OMP_MAP_PTR_AND_OBJ; - return MappableExprsHandler::OMP_MAP_PRIVATE | - MappableExprsHandler::OMP_MAP_TO; + return OMP_MAP_TO | OMP_MAP_PTR_AND_OBJ; + return OMP_MAP_PRIVATE | OMP_MAP_TO; } auto I = LambdasMap.find(Cap.getCapturedVar()->getCanonicalDecl()); if (I != LambdasMap.end()) @@ -8000,8 +7943,7 @@ /*AddPtrFlag=*/false, /*AddIsTargetParamFlag=*/false, /*isNonContiguous=*/false); - return MappableExprsHandler::OMP_MAP_TO | - MappableExprsHandler::OMP_MAP_FROM; + return OMP_MAP_TO | OMP_MAP_FROM; } static OpenMPOffloadMappingFlags getMemberOfFlag(unsigned Position) { @@ -9147,8 +9089,7 @@ for (unsigned I = 0, E = CombinedInfo.Sizes.size(); I < E; ++I) { if (auto *CI = dyn_cast(CombinedInfo.Sizes[I])) { if (!isa(CI) && !isa(CI)) { - if (IsNonContiguous && (CombinedInfo.Types[I] & - MappableExprsHandler::OMP_MAP_NON_CONTIG)) + if (IsNonContiguous && (CombinedInfo.Types[I] & OMP_MAP_NON_CONTIG)) ConstSizes[I] = llvm::ConstantInt::get( CGF.Int64Ty, CombinedInfo.NonContigInfo.Dims[I]); else @@ -9226,8 +9167,8 @@ if (Info.separateBeginEndCalls()) { bool EndMapTypesDiffer = false; for (uint64_t &Type : Mapping) { - if (Type & MappableExprsHandler::OMP_MAP_PRESENT) { - Type &= ~MappableExprsHandler::OMP_MAP_PRESENT; + if (Type & OMP_MAP_PRESENT) { + Type &= ~OMP_MAP_PRESENT; EndMapTypesDiffer = true; } } @@ -9592,9 +9533,7 @@ // from | alloc | alloc | from | from | release | delete // tofrom | alloc | to | from | tofrom | release | delete llvm::Value *LeftToFrom = MapperCGF.Builder.CreateAnd( - MapType, - MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_TO | - MappableExprsHandler::OMP_MAP_FROM)); + MapType, MapperCGF.Builder.getInt64(OMP_MAP_TO | OMP_MAP_FROM)); llvm::BasicBlock *AllocBB = MapperCGF.createBasicBlock("omp.type.alloc"); llvm::BasicBlock *AllocElseBB = MapperCGF.createBasicBlock("omp.type.alloc.else"); @@ -9608,30 +9547,25 @@ MapperCGF.EmitBlock(AllocBB); llvm::Value *AllocMapType = MapperCGF.Builder.CreateAnd( MemberMapType, - MapperCGF.Builder.getInt64(~(MappableExprsHandler::OMP_MAP_TO | - MappableExprsHandler::OMP_MAP_FROM))); + MapperCGF.Builder.getInt64(~(OMP_MAP_TO | OMP_MAP_FROM))); MapperCGF.Builder.CreateBr(EndBB); MapperCGF.EmitBlock(AllocElseBB); llvm::Value *IsTo = MapperCGF.Builder.CreateICmpEQ( - LeftToFrom, - MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_TO)); + LeftToFrom, MapperCGF.Builder.getInt64(OMP_MAP_TO)); MapperCGF.Builder.CreateCondBr(IsTo, ToBB, ToElseBB); // In case of to, clear OMP_MAP_FROM. MapperCGF.EmitBlock(ToBB); llvm::Value *ToMapType = MapperCGF.Builder.CreateAnd( - MemberMapType, - MapperCGF.Builder.getInt64(~MappableExprsHandler::OMP_MAP_FROM)); + MemberMapType, MapperCGF.Builder.getInt64(~OMP_MAP_FROM)); MapperCGF.Builder.CreateBr(EndBB); MapperCGF.EmitBlock(ToElseBB); llvm::Value *IsFrom = MapperCGF.Builder.CreateICmpEQ( - LeftToFrom, - MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_FROM)); + LeftToFrom, MapperCGF.Builder.getInt64(OMP_MAP_FROM)); MapperCGF.Builder.CreateCondBr(IsFrom, FromBB, EndBB); // In case of from, clear OMP_MAP_TO. MapperCGF.EmitBlock(FromBB); llvm::Value *FromMapType = MapperCGF.Builder.CreateAnd( - MemberMapType, - MapperCGF.Builder.getInt64(~MappableExprsHandler::OMP_MAP_TO)); + MemberMapType, MapperCGF.Builder.getInt64(~OMP_MAP_TO)); // In case of tofrom, do nothing. MapperCGF.EmitBlock(EndBB); LastBB = EndBB; @@ -9705,8 +9639,7 @@ llvm::Value *IsArray = MapperCGF.Builder.CreateICmpSGT( Size, MapperCGF.Builder.getInt64(1), "omp.arrayinit.isarray"); llvm::Value *DeleteBit = MapperCGF.Builder.CreateAnd( - MapType, - MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_DELETE)); + MapType, MapperCGF.Builder.getInt64(OMP_MAP_DELETE)); llvm::Value *DeleteCond; llvm::Value *Cond; if (IsInit) { @@ -9714,8 +9647,7 @@ llvm::Value *BaseIsBegin = MapperCGF.Builder.CreateICmpNE(Base, Begin); // IsPtrAndObj? llvm::Value *PtrAndObjBit = MapperCGF.Builder.CreateAnd( - MapType, - MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_PTR_AND_OBJ)); + MapType, MapperCGF.Builder.getInt64(OMP_MAP_PTR_AND_OBJ)); PtrAndObjBit = MapperCGF.Builder.CreateIsNotNull(PtrAndObjBit); BaseIsBegin = MapperCGF.Builder.CreateAnd(BaseIsBegin, PtrAndObjBit); Cond = MapperCGF.Builder.CreateOr(IsArray, BaseIsBegin); @@ -9737,12 +9669,9 @@ // Remove OMP_MAP_TO and OMP_MAP_FROM from the map type, so that it achieves // memory allocation/deletion purpose only. llvm::Value *MapTypeArg = MapperCGF.Builder.CreateAnd( - MapType, - MapperCGF.Builder.getInt64(~(MappableExprsHandler::OMP_MAP_TO | - MappableExprsHandler::OMP_MAP_FROM))); + MapType, MapperCGF.Builder.getInt64(~(OMP_MAP_TO | OMP_MAP_FROM))); MapTypeArg = MapperCGF.Builder.CreateOr( - MapTypeArg, - MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_IMPLICIT)); + MapTypeArg, MapperCGF.Builder.getInt64(OMP_MAP_IMPLICIT)); // Call the runtime API __tgt_push_mapper_component to fill up the runtime // data structure. @@ -9968,9 +9897,8 @@ CurInfo.Sizes.push_back(CGF.Builder.CreateIntCast( CGF.getTypeSize(RI->getType()), CGF.Int64Ty, /*isSigned=*/true)); // Copy to the device as an argument. No need to retrieve it. - CurInfo.Types.push_back(MappableExprsHandler::OMP_MAP_LITERAL | - MappableExprsHandler::OMP_MAP_TARGET_PARAM | - MappableExprsHandler::OMP_MAP_IMPLICIT); + CurInfo.Types.push_back(OMP_MAP_LITERAL | OMP_MAP_TARGET_PARAM | + OMP_MAP_IMPLICIT); CurInfo.Mappers.push_back(nullptr); } else { // If we have any information in the map clause, we use it, otherwise we 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 @@ -189,8 +189,63 @@ OMP_TGT_EXEC_MODE_GENERIC = 1 << 0, OMP_TGT_EXEC_MODE_SPMD = 1 << 1, OMP_TGT_EXEC_MODE_GENERIC_SPMD = - OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD, - LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD) + OMP_TGT_EXEC_MODE_GENERIC | OMP_TGT_EXEC_MODE_SPMD +}; + +/// Values for bit flags used to specify the mapping type for +/// offloading. +enum OpenMPOffloadMappingFlags : uint64_t { + /// No flags + OMP_MAP_NONE = 0x0, + /// Allocate memory on the device and move data from host to device. + OMP_MAP_TO = 0x01, + /// Allocate memory on the device and move data from device to host. + OMP_MAP_FROM = 0x02, + /// Always perform the requested mapping action on the element, even + /// if it was already mapped before. + OMP_MAP_ALWAYS = 0x04, + /// Delete the element from the device environment, ignoring the + /// current reference count associated with the element. + OMP_MAP_DELETE = 0x08, + /// The element being mapped is a pointer-pointee pair; both the + /// pointer and the pointee should be mapped. + OMP_MAP_PTR_AND_OBJ = 0x10, + /// This flags signals that the base address of an entry should be + /// passed to the target kernel as an argument. + OMP_MAP_TARGET_PARAM = 0x20, + /// Signal that the runtime library has to return the device pointer + /// in the current position for the data being mapped. Used when we have the + /// use_device_ptr or use_device_addr clause. + OMP_MAP_RETURN_PARAM = 0x40, + /// This flag signals that the reference being passed is a pointer to + /// private data. + OMP_MAP_PRIVATE = 0x80, + /// Pass the element to the device by value. + OMP_MAP_LITERAL = 0x100, + /// Implicit map + OMP_MAP_IMPLICIT = 0x200, + /// Close is a hint to the runtime to allocate memory close to + /// the target device. + OMP_MAP_CLOSE = 0x400, + /// 0x800 is reserved for compatibility with XLC. + /// Produce a runtime error if the data is not already allocated. + OMP_MAP_PRESENT = 0x1000, + // Increment and decrement a separate reference counter so that the data + // cannot be unmapped within the associated region. Thus, this flag is + // intended to be used on 'target' and 'target data' directives because they + // are inherently structured. It is not intended to be used on 'target + // enter data' and 'target exit data' directives because they are inherently + // dynamic. + // This is an OpenMP extension for the sake of OpenACC support. + OMP_MAP_OMPX_HOLD = 0x2000, + /// Signal that the runtime library should use args as an array of + /// descriptor_dim pointers and use args_size as dims. Used when we have + /// non-contiguous list items in target update directive + OMP_MAP_NON_CONTIG = 0x100000000000, + /// The 16 MSBs of the flags indicate whether the entry is member of some + /// struct/class. + OMP_MAP_MEMBER_OF = 0xffff000000000000, + LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF) }; enum class AddressSpace : unsigned {