diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 75709740e39ce3..122006f667ed2f 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1595,9 +1595,9 @@ CGOpenMPRuntime::createDispatchNextFunction(unsigned IVSize, bool IVSigned) { /// Obtain information that uniquely identifies a target entry. This /// consists of the file and device IDs as well as line number associated with /// the relevant entry source location. -static void getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc, - unsigned &DeviceID, unsigned &FileID, - unsigned &LineNum) { +static llvm::TargetRegionEntryInfo +getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc, + StringRef ParentName = "") { SourceManager &SM = C.getSourceManager(); // The loc should be always valid and have a file ID (the user cannot use @@ -1617,9 +1617,8 @@ static void getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc, << PLoc.getFilename() << EC.message(); } - DeviceID = ID.getDevice(); - FileID = ID.getFile(); - LineNum = PLoc.getLine(); + return llvm::TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(), + PLoc.getLine()); } Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) { @@ -1635,11 +1634,9 @@ Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) { llvm::raw_svector_ostream OS(PtrName); OS << CGM.getMangledName(GlobalDecl(VD)); if (!VD->isExternallyVisible()) { - unsigned DeviceID, FileID, Line; - getTargetEntryUniqueInfo(CGM.getContext(), - VD->getCanonicalDecl()->getBeginLoc(), - DeviceID, FileID, Line); - OS << llvm::format("_%x", FileID); + auto EntryInfo = getTargetEntryUniqueInfo( + CGM.getContext(), VD->getCanonicalDecl()->getBeginLoc()); + OS << llvm::format("_%x", EntryInfo.FileID); } OS << "_decl_tgt_ref_ptr"; } @@ -1858,16 +1855,10 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD, // Produce the unique prefix to identify the new target regions. We use // the source location of the variable declaration which we know to not // conflict with any target region. - unsigned DeviceID; - unsigned FileID; - unsigned Line; - getTargetEntryUniqueInfo(CGM.getContext(), Loc, DeviceID, FileID, Line); + auto EntryInfo = + getTargetEntryUniqueInfo(CGM.getContext(), Loc, VD->getName()); SmallString<128> Buffer, Out; - { - llvm::raw_svector_ostream OS(Buffer); - OS << "__omp_offloading_" << llvm::format("_%x", DeviceID) - << llvm::format("_%x_", FileID) << VD->getName() << "_l" << Line; - } + EntryInfo.getTargetRegionEntryFnName(Buffer); const Expr *Init = VD->getAnyInitializer(); if (CGM.getLangOpts().CPlusPlus && PerformInit) { @@ -1913,9 +1904,11 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD, // Register the information for the entry associated with the constructor. Out.clear(); + auto CtorEntryInfo = EntryInfo; + CtorEntryInfo.ParentName = Twine(Buffer, "_ctor").toStringRef(Out); OffloadEntriesInfoManager.registerTargetRegionEntryInfo( - DeviceID, FileID, Twine(Buffer, "_ctor").toStringRef(Out), Line, Ctor, - ID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor, + CtorEntryInfo, Ctor, ID, + llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor, CGM.getLangOpts().OpenMPIsDevice); } if (VD->getType().isDestructedType() != QualType::DK_none) { @@ -1961,9 +1954,11 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD, } // Register the information for the entry associated with the destructor. Out.clear(); + auto DtorEntryInfo = EntryInfo; + DtorEntryInfo.ParentName = Twine(Buffer, "_dtor").toStringRef(Out); OffloadEntriesInfoManager.registerTargetRegionEntryInfo( - DeviceID, FileID, Twine(Buffer, "_dtor").toStringRef(Out), Line, Dtor, - ID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryDtor, + DtorEntryInfo, Dtor, ID, + llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryDtor, CGM.getLangOpts().OpenMPIsDevice); } return CGM.getLangOpts().OpenMPIsDevice; @@ -3001,8 +2996,7 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() { auto &&TargetRegionMetadataEmitter = [this, &C, MD, &OrderedEntries, &ParentFunctions, &GetMDInt, &GetMDString]( - unsigned DeviceID, unsigned FileID, StringRef ParentName, - unsigned Line, + const llvm::TargetRegionEntryInfo &EntryInfo, const llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion &E) { // Generate metadata for target regions. Each entry of this metadata @@ -3015,24 +3009,26 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() { // - Entry 4 -> Line in the file where the entry was identified. // - Entry 5 -> Order the entry was created. // The first element of the metadata node is the kind. - llvm::Metadata *Ops[] = {GetMDInt(E.getKind()), GetMDInt(DeviceID), - GetMDInt(FileID), GetMDString(ParentName), - GetMDInt(Line), GetMDInt(E.getOrder())}; + llvm::Metadata *Ops[] = { + GetMDInt(E.getKind()), GetMDInt(EntryInfo.DeviceID), + GetMDInt(EntryInfo.FileID), GetMDString(EntryInfo.ParentName), + GetMDInt(EntryInfo.Line), GetMDInt(E.getOrder())}; SourceLocation Loc; for (auto I = CGM.getContext().getSourceManager().fileinfo_begin(), E = CGM.getContext().getSourceManager().fileinfo_end(); I != E; ++I) { - if (I->getFirst()->getUniqueID().getDevice() == DeviceID && - I->getFirst()->getUniqueID().getFile() == FileID) { + if (I->getFirst()->getUniqueID().getDevice() == EntryInfo.DeviceID && + I->getFirst()->getUniqueID().getFile() == EntryInfo.FileID) { Loc = CGM.getContext().getSourceManager().translateFileLineCol( - I->getFirst(), Line, 1); + I->getFirst(), EntryInfo.Line, 1); break; } } // Save this entry in the right position of the ordered entries array. - OrderedEntries[E.getOrder()] = std::make_tuple(&E, Loc, ParentName); - ParentFunctions[E.getOrder()] = ParentName; + OrderedEntries[E.getOrder()] = + std::make_tuple(&E, Loc, StringRef(EntryInfo.ParentName)); + ParentFunctions[E.getOrder()] = StringRef(EntryInfo.ParentName); // Add metadata to the named metadata node. MD->addOperand(llvm::MDNode::get(C, Ops)); @@ -3195,15 +3191,18 @@ void CGOpenMPRuntime::loadOffloadInfoMetadata() { llvm_unreachable("Unexpected metadata!"); break; case llvm::OffloadEntriesInfoManager::OffloadEntryInfo:: - OffloadingEntryInfoTargetRegion: + OffloadingEntryInfoTargetRegion: { assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is " "only required for the " "device code generation."); + llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3), + /*DeviceID=*/GetMDInt(1), + /*FileID=*/GetMDInt(2), + /*Line=*/GetMDInt(4)); OffloadEntriesInfoManager.initializeTargetRegionEntryInfo( - /*DeviceID=*/GetMDInt(1), /*FileID=*/GetMDInt(2), - /*ParentName=*/GetMDString(3), /*Line=*/GetMDInt(4), - /*Order=*/GetMDInt(5)); + EntryInfo, /*Order=*/GetMDInt(5)); break; + } case llvm::OffloadEntriesInfoManager::OffloadEntryInfo:: OffloadingEntryInfoDeviceGlobalVar: assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is " @@ -6209,7 +6208,7 @@ void CGOpenMPRuntime::emitTargetOutlinedFunction( const OMPExecutableDirective &D, StringRef ParentName, llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID, bool IsOffloadEntry, const RegionCodeGenTy &CodeGen) { - assert(!ParentName.empty() && "Invalid target region parent name!"); + assert(!ParentName.empty() && "Invalid target entry parent name!"); HasEmittedTargetRegion = true; SmallVector, 4> Allocators; for (const auto *C : D.getClausesOfKind()) { @@ -6292,17 +6291,10 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper( const bool BuildOutlinedFn = CGM.getLangOpts().OpenMPIsDevice || !CGM.getLangOpts().OpenMPOffloadMandatory; - unsigned DeviceID; - unsigned FileID; - unsigned Line; - getTargetEntryUniqueInfo(CGM.getContext(), D.getBeginLoc(), DeviceID, FileID, - Line); + auto EntryInfo = + getTargetEntryUniqueInfo(CGM.getContext(), D.getBeginLoc(), ParentName); SmallString<64> EntryFnName; - { - llvm::raw_svector_ostream OS(EntryFnName); - OS << "__omp_offloading" << llvm::format("_%x", DeviceID) - << llvm::format("_%x_", FileID) << ParentName << "_l" << Line; - } + EntryInfo.getTargetRegionEntryFnName(EntryFnName); const CapturedStmt &CS = *D.getCapturedStmt(OMPD_target); @@ -6357,7 +6349,7 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper( // Register the information for the entry associated with this target region. OffloadEntriesInfoManager.registerTargetRegionEntryInfo( - DeviceID, FileID, ParentName, Line, TargetRegionEntryAddr, OutlinedFnID, + EntryInfo, TargetRegionEntryAddr, OutlinedFnID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion, CGM.getLangOpts().OpenMPIsDevice); @@ -10352,16 +10344,12 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S, if (RequiresDeviceCodegen) { const auto &E = *cast(S); - unsigned DeviceID; - unsigned FileID; - unsigned Line; - getTargetEntryUniqueInfo(CGM.getContext(), E.getBeginLoc(), DeviceID, - FileID, Line); + auto EntryInfo = + getTargetEntryUniqueInfo(CGM.getContext(), E.getBeginLoc(), ParentName); // Is this a target region that should not be emitted as an entry point? If // so just signal we are done with this target region. - if (!OffloadEntriesInfoManager.hasTargetRegionEntryInfo(DeviceID, FileID, - ParentName, Line)) + if (!OffloadEntriesInfoManager.hasTargetRegionEntryInfo(EntryInfo)) return; switch (E.getDirectiveKind()) { diff --git a/clang/test/OpenMP/declare_target_codegen.cpp b/clang/test/OpenMP/declare_target_codegen.cpp index e43289e37dfcc9..aa7cf7bd038d42 100644 --- a/clang/test/OpenMP/declare_target_codegen.cpp +++ b/clang/test/OpenMP/declare_target_codegen.cpp @@ -51,7 +51,7 @@ // CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}() // CHECK-DAG: define {{.*}}void @{{.*}}TemplateClass{{.*}}(ptr {{[^,]*}} %{{.*}}) // CHECK-DAG: define {{.*}}i32 @{{.*}}TemplateClass{{.*}}f_method{{.*}}(ptr {{[^,]*}} %{{.*}}) -// CHECK-DAG: define {{.*}}void @__omp_offloading__{{.*}}_globals_l[[@LINE+78]]_ctor() +// CHECK-DAG: define {{.*}}void @__omp_offloading_{{.*}}_globals_l[[@LINE+78]]_ctor() #ifndef HEADER #define HEADER diff --git a/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp b/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp index cb857a6a5d4303..14eabc6c8f48f6 100644 --- a/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp +++ b/clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp @@ -43,8 +43,8 @@ int caz() { return 0; } static int c = foo() + bar() + baz(); #pragma omp declare target (c) -// HOST-DAG: @[[C_CTOR:__omp_offloading__.+_c_l44_ctor]] = private constant i8 0 -// DEVICE-DAG: define weak_odr protected void [[C_CTOR:@__omp_offloading__.+_c_l44_ctor]]() +// HOST-DAG: @[[C_CTOR:__omp_offloading_.+_c_l44_ctor]] = private constant i8 0 +// DEVICE-DAG: define weak_odr protected void [[C_CTOR:@__omp_offloading_.+_c_l44_ctor]]() // DEVICE-DAG: call noundef i32 [[FOO]]() // DEVICE-DAG: call noundef i32 [[BAR]]() // DEVICE-DAG: call noundef i32 [[BAZ]]() @@ -60,15 +60,15 @@ struct S { #pragma omp declare target S cd = doo() + car() + caz() + baz(); #pragma omp end declare target -// HOST-DAG: @[[CD_CTOR:__omp_offloading__.+_cd_l61_ctor]] = private constant i8 0 -// DEVICE-DAG: define weak_odr protected void [[CD_CTOR:@__omp_offloading__.+_cd_l61_ctor]]() +// HOST-DAG: @[[CD_CTOR:__omp_offloading_.+_cd_l61_ctor]] = private constant i8 0 +// DEVICE-DAG: define weak_odr protected void [[CD_CTOR:@__omp_offloading_.+_cd_l61_ctor]]() // DEVICE-DAG: call noundef i32 [[DOO]]() // DEVICE-DAG: call noundef i32 [[CAR]]() // DEVICE-DAG: call noundef i32 [[CAZ]]() // DEVICE-DAG: ret void -// HOST-DAG: @[[CD_DTOR:__omp_offloading__.+_cd_l61_dtor]] = private constant i8 0 -// DEVICE-DAG: define weak_odr protected void [[CD_DTOR:@__omp_offloading__.+_cd_l61_dtor]]() +// HOST-DAG: @[[CD_DTOR:__omp_offloading_.+_cd_l61_dtor]] = private constant i8 0 +// DEVICE-DAG: define weak_odr protected void [[CD_DTOR:@__omp_offloading_.+_cd_l61_dtor]]() // DEVICE-DAG: call void // DEVICE-DAG: ret void diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h index c59adc775dc673..8ba71d55584a2d 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -20,9 +20,11 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/Support/Allocator.h" #include +#include namespace llvm { class CanonicalLoopInfo; +class OffloadEntriesInfoManager; /// Move the instruction after an InsertPoint to the beginning of another /// BasicBlock. @@ -1681,6 +1683,33 @@ class OpenMPIRBuilder { const Twine &Name = {}); }; +/// Data structure to contain the information needed to uniquely identify +/// a target entry. +struct TargetRegionEntryInfo { + std::string ParentName; + unsigned DeviceID; + unsigned FileID; + unsigned Line; + + TargetRegionEntryInfo() : ParentName(""), DeviceID(0), FileID(0), Line(0) {} + TargetRegionEntryInfo(StringRef ParentName, unsigned DeviceID, + unsigned FileID, unsigned Line) + : ParentName(ParentName), DeviceID(DeviceID), FileID(FileID), Line(Line) { + } + + static void getTargetRegionEntryFnName(SmallVectorImpl &Name, + StringRef ParentName, + unsigned DeviceID, unsigned FileID, + unsigned Line); + + void getTargetRegionEntryFnName(SmallVectorImpl &Name); + + bool operator<(const TargetRegionEntryInfo RHS) const { + return std::make_tuple(ParentName, DeviceID, FileID, Line) < + std::make_tuple(RHS.ParentName, RHS.DeviceID, RHS.FileID, RHS.Line); + } +}; + /// Class that manages information about offload code regions and data class OffloadEntriesInfoManager { /// Number of entries registered so far. @@ -1782,22 +1811,19 @@ class OffloadEntriesInfoManager { /// Initialize target region entry. /// This is ONLY needed for DEVICE compilation. - void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, - StringRef ParentName, unsigned LineNum, + void initializeTargetRegionEntryInfo(const TargetRegionEntryInfo &EntryInfo, unsigned Order); /// Register target region entry. - void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, - StringRef ParentName, unsigned LineNum, + void registerTargetRegionEntryInfo(const TargetRegionEntryInfo &EntryInfo, Constant *Addr, Constant *ID, OMPTargetRegionEntryKind Flags, bool IsDevice); /// Return true if a target region entry with the provided information /// exists. - bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID, - StringRef ParentName, unsigned LineNum, + bool hasTargetRegionEntryInfo(const TargetRegionEntryInfo &EntryInfo, bool IgnoreAddressId = false) const; /// brief Applies action \a Action on all registered entries. - typedef function_ref OffloadTargetRegionEntryInfoActTy; void @@ -1868,17 +1894,9 @@ class OffloadEntriesInfoManager { const OffloadDeviceGlobalVarEntryInfoActTy &Action); private: - // Storage for target region entries kind. The storage is to be indexed by - // file ID, device ID, parent function name and line number. - typedef DenseMap - OffloadEntriesTargetRegionPerLine; - typedef StringMap - OffloadEntriesTargetRegionPerParentName; - typedef DenseMap - OffloadEntriesTargetRegionPerFile; - typedef DenseMap - OffloadEntriesTargetRegionPerDevice; - typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy; + // Storage for target region entries kind. + typedef std::map + OffloadEntriesTargetRegionTy; OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion; /// Storage for device global variable entries kind. The storage is to be /// indexed by mangled name. diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp index 91bd2fe0726c5f..6a3700e3adb707 100644 --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -4692,6 +4692,19 @@ void OpenMPIRBuilder::OutlineInfo::collectBlocks( } } +void TargetRegionEntryInfo::getTargetRegionEntryFnName( + SmallVectorImpl &Name, StringRef ParentName, unsigned DeviceID, + unsigned FileID, unsigned Line) { + raw_svector_ostream OS(Name); + OS << "__omp_offloading" << llvm::format("_%x", DeviceID) + << llvm::format("_%x_", FileID) << ParentName << "_l" << Line; +} + +void TargetRegionEntryInfo::getTargetRegionEntryFnName( + SmallVectorImpl &Name) { + getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line); +} + bool OffloadEntriesInfoManager::empty() const { return OffloadEntriesTargetRegion.empty() && OffloadEntriesDeviceGlobalVar.empty(); @@ -4699,60 +4712,47 @@ bool OffloadEntriesInfoManager::empty() const { /// Initialize target region entry. void OffloadEntriesInfoManager::initializeTargetRegionEntryInfo( - unsigned DeviceID, unsigned FileID, StringRef ParentName, unsigned LineNum, - unsigned Order) { - OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum] = + const TargetRegionEntryInfo &EntryInfo, unsigned Order) { + OffloadEntriesTargetRegion[EntryInfo] = OffloadEntryInfoTargetRegion(Order, /*Addr=*/nullptr, /*ID=*/nullptr, OMPTargetRegionEntryTargetRegion); ++OffloadingEntriesNum; } void OffloadEntriesInfoManager::registerTargetRegionEntryInfo( - unsigned DeviceID, unsigned FileID, StringRef ParentName, unsigned LineNum, - Constant *Addr, Constant *ID, OMPTargetRegionEntryKind Flags, - bool IsDevice) { + const TargetRegionEntryInfo &EntryInfo, Constant *Addr, Constant *ID, + OMPTargetRegionEntryKind Flags, bool IsDevice) { // If we are emitting code for a target, the entry is already initialized, // only has to be registered. if (IsDevice) { // This could happen if the device compilation is invoked standalone. - if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum)) + if (!hasTargetRegionEntryInfo(EntryInfo)) { return; - auto &Entry = - OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum]; + } + auto &Entry = OffloadEntriesTargetRegion[EntryInfo]; Entry.setAddress(Addr); Entry.setID(ID); Entry.setFlags(Flags); } else { if (Flags == OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion && - hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum, - /*IgnoreAddressId*/ true)) + hasTargetRegionEntryInfo(EntryInfo, /*IgnoreAddressId*/ true)) return; - assert(!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum) && + assert(!hasTargetRegionEntryInfo(EntryInfo) && "Target region entry already registered!"); OffloadEntryInfoTargetRegion Entry(OffloadingEntriesNum, Addr, ID, Flags); - OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum] = Entry; + OffloadEntriesTargetRegion[EntryInfo] = Entry; ++OffloadingEntriesNum; } } bool OffloadEntriesInfoManager::hasTargetRegionEntryInfo( - unsigned DeviceID, unsigned FileID, StringRef ParentName, unsigned LineNum, - bool IgnoreAddressId) const { - auto PerDevice = OffloadEntriesTargetRegion.find(DeviceID); - if (PerDevice == OffloadEntriesTargetRegion.end()) - return false; - auto PerFile = PerDevice->second.find(FileID); - if (PerFile == PerDevice->second.end()) - return false; - auto PerParentName = PerFile->second.find(ParentName); - if (PerParentName == PerFile->second.end()) - return false; - auto PerLine = PerParentName->second.find(LineNum); - if (PerLine == PerParentName->second.end()) + const TargetRegionEntryInfo &EntryInfo, bool IgnoreAddressId) const { + auto It = OffloadEntriesTargetRegion.find(EntryInfo); + if (It == OffloadEntriesTargetRegion.end()) { return false; + } // Fail if this entry is already registered. - if (!IgnoreAddressId && - (PerLine->second.getAddress() || PerLine->second.getID())) + if (!IgnoreAddressId && (It->second.getAddress() || It->second.getID())) return false; return true; } @@ -4760,11 +4760,9 @@ bool OffloadEntriesInfoManager::hasTargetRegionEntryInfo( void OffloadEntriesInfoManager::actOnTargetRegionEntriesInfo( const OffloadTargetRegionEntryInfoActTy &Action) { // Scan all target region entries and perform the provided action. - for (const auto &D : OffloadEntriesTargetRegion) - for (const auto &F : D.second) - for (const auto &P : F.second) - for (const auto &L : P.second) - Action(D.first, F.first, P.first(), L.first, L.second); + for (const auto &It : OffloadEntriesTargetRegion) { + Action(It.first, It.second); + } } void OffloadEntriesInfoManager::initializeDeviceGlobalVarEntryInfo( diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index 7ae13a51d3a062..b334755c35c8ad 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -5504,16 +5504,17 @@ TEST_F(OpenMPIRBuilderTest, EmitOffloadingArraysArguments) { TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) { OffloadEntriesInfoManager InfoManager; - InfoManager.initializeTargetRegionEntryInfo(1, 2, "parent", 4, 0); + TargetRegionEntryInfo EntryInfo("parent", 1, 2, 4); + InfoManager.initializeTargetRegionEntryInfo(EntryInfo, 0); InfoManager.initializeDeviceGlobalVarEntryInfo( "gvar", OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo, 0); InfoManager.registerTargetRegionEntryInfo( - 1, 2, "parent", 4, nullptr, nullptr, + EntryInfo, nullptr, nullptr, OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion, true); InfoManager.registerDeviceGlobalVarEntryInfo( "gvar", 0x0, 8, OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo, GlobalValue::WeakAnyLinkage, true); - EXPECT_TRUE(InfoManager.hasTargetRegionEntryInfo(1, 2, "parent", 4, true)); + EXPECT_TRUE(InfoManager.hasTargetRegionEntryInfo(EntryInfo, true)); EXPECT_TRUE(InfoManager.hasDeviceGlobalVarEntryInfo("gvar")); } } // namespace