@@ -1595,9 +1595,9 @@ CGOpenMPRuntime::createDispatchNextFunction(unsigned IVSize, bool IVSigned) {
15951595/// Obtain information that uniquely identifies a target entry. This
15961596/// consists of the file and device IDs as well as line number associated with
15971597/// the relevant entry source location.
1598- static void getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
1599- unsigned &DeviceID, unsigned &FileID ,
1600- unsigned &LineNum ) {
1598+ static llvm::TargetRegionEntryInfo
1599+ getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc ,
1600+ StringRef ParentName = "" ) {
16011601 SourceManager &SM = C.getSourceManager();
16021602
16031603 // 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,
16171617 << PLoc.getFilename() << EC.message();
16181618 }
16191619
1620- DeviceID = ID.getDevice();
1621- FileID = ID.getFile();
1622- LineNum = PLoc.getLine();
1620+ return llvm::TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(),
1621+ PLoc.getLine());
16231622}
16241623
16251624Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {
@@ -1635,11 +1634,9 @@ Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {
16351634 llvm::raw_svector_ostream OS(PtrName);
16361635 OS << CGM.getMangledName(GlobalDecl(VD));
16371636 if (!VD->isExternallyVisible()) {
1638- unsigned DeviceID, FileID, Line;
1639- getTargetEntryUniqueInfo(CGM.getContext(),
1640- VD->getCanonicalDecl()->getBeginLoc(),
1641- DeviceID, FileID, Line);
1642- OS << llvm::format("_%x", FileID);
1637+ auto EntryInfo = getTargetEntryUniqueInfo(
1638+ CGM.getContext(), VD->getCanonicalDecl()->getBeginLoc());
1639+ OS << llvm::format("_%x", EntryInfo.FileID);
16431640 }
16441641 OS << "_decl_tgt_ref_ptr";
16451642 }
@@ -1858,16 +1855,10 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
18581855 // Produce the unique prefix to identify the new target regions. We use
18591856 // the source location of the variable declaration which we know to not
18601857 // conflict with any target region.
1861- unsigned DeviceID;
1862- unsigned FileID;
1863- unsigned Line;
1864- getTargetEntryUniqueInfo(CGM.getContext(), Loc, DeviceID, FileID, Line);
1858+ auto EntryInfo =
1859+ getTargetEntryUniqueInfo(CGM.getContext(), Loc, VD->getName());
18651860 SmallString<128> Buffer, Out;
1866- {
1867- llvm::raw_svector_ostream OS(Buffer);
1868- OS << "__omp_offloading_" << llvm::format("_%x", DeviceID)
1869- << llvm::format("_%x_", FileID) << VD->getName() << "_l" << Line;
1870- }
1861+ EntryInfo.getTargetRegionEntryFnName(Buffer);
18711862
18721863 const Expr *Init = VD->getAnyInitializer();
18731864 if (CGM.getLangOpts().CPlusPlus && PerformInit) {
@@ -1913,9 +1904,12 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
19131904
19141905 // Register the information for the entry associated with the constructor.
19151906 Out.clear();
1907+ auto CtorEntryInfo = EntryInfo;
1908+ CtorEntryInfo.ParentName = Twine(Buffer, "_ctor").toStringRef(Out);
1909+ llvm::errs() << "Registering var ctor: " << Twine(Buffer, "_ctor") << "\n";
19161910 OffloadEntriesInfoManager.registerTargetRegionEntryInfo(
1917- DeviceID, FileID, Twine(Buffer, "_ctor").toStringRef(Out), Line, Ctor ,
1918- ID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor,
1911+ CtorEntryInfo, Ctor, ID ,
1912+ llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor,
19191913 CGM.getLangOpts().OpenMPIsDevice);
19201914 }
19211915 if (VD->getType().isDestructedType() != QualType::DK_none) {
@@ -1961,9 +1955,11 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
19611955 }
19621956 // Register the information for the entry associated with the destructor.
19631957 Out.clear();
1958+ auto DtorEntryInfo = EntryInfo;
1959+ DtorEntryInfo.ParentName = Twine(Buffer, "_dtor").toStringRef(Out);
19641960 OffloadEntriesInfoManager.registerTargetRegionEntryInfo(
1965- DeviceID, FileID, Twine(Buffer, "_dtor").toStringRef(Out), Line, Dtor ,
1966- ID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryDtor,
1961+ DtorEntryInfo, Dtor, ID ,
1962+ llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryDtor,
19671963 CGM.getLangOpts().OpenMPIsDevice);
19681964 }
19691965 return CGM.getLangOpts().OpenMPIsDevice;
@@ -3001,8 +2997,7 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
30012997 auto &&TargetRegionMetadataEmitter =
30022998 [this, &C, MD, &OrderedEntries, &ParentFunctions, &GetMDInt,
30032999 &GetMDString](
3004- unsigned DeviceID, unsigned FileID, StringRef ParentName,
3005- unsigned Line,
3000+ llvm::TargetRegionEntryInfo EntryInfo,
30063001 const llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion
30073002 &E) {
30083003 // Generate metadata for target regions. Each entry of this metadata
@@ -3015,24 +3010,26 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
30153010 // - Entry 4 -> Line in the file where the entry was identified.
30163011 // - Entry 5 -> Order the entry was created.
30173012 // The first element of the metadata node is the kind.
3018- llvm::Metadata *Ops[] = {GetMDInt(E.getKind()), GetMDInt(DeviceID),
3019- GetMDInt(FileID), GetMDString(ParentName),
3020- GetMDInt(Line), GetMDInt(E.getOrder())};
3013+ llvm::Metadata *Ops[] = {
3014+ GetMDInt(E.getKind()), GetMDInt(EntryInfo.DeviceID),
3015+ GetMDInt(EntryInfo.FileID), GetMDString(EntryInfo.ParentName),
3016+ GetMDInt(EntryInfo.Line), GetMDInt(E.getOrder())};
30213017
30223018 SourceLocation Loc;
30233019 for (auto I = CGM.getContext().getSourceManager().fileinfo_begin(),
30243020 E = CGM.getContext().getSourceManager().fileinfo_end();
30253021 I != E; ++I) {
3026- if (I->getFirst()->getUniqueID().getDevice() == DeviceID &&
3027- I->getFirst()->getUniqueID().getFile() == FileID) {
3022+ if (I->getFirst()->getUniqueID().getDevice() == EntryInfo. DeviceID &&
3023+ I->getFirst()->getUniqueID().getFile() == EntryInfo. FileID) {
30283024 Loc = CGM.getContext().getSourceManager().translateFileLineCol(
3029- I->getFirst(), Line, 1);
3025+ I->getFirst(), EntryInfo. Line, 1);
30303026 break;
30313027 }
30323028 }
30333029 // Save this entry in the right position of the ordered entries array.
3034- OrderedEntries[E.getOrder()] = std::make_tuple(&E, Loc, ParentName);
3035- ParentFunctions[E.getOrder()] = ParentName;
3030+ OrderedEntries[E.getOrder()] =
3031+ std::make_tuple(&E, Loc, StringRef(EntryInfo.ParentName));
3032+ ParentFunctions[E.getOrder()] = StringRef(EntryInfo.ParentName);
30363033
30373034 // Add metadata to the named metadata node.
30383035 MD->addOperand(llvm::MDNode::get(C, Ops));
@@ -3195,15 +3192,18 @@ void CGOpenMPRuntime::loadOffloadInfoMetadata() {
31953192 llvm_unreachable("Unexpected metadata!");
31963193 break;
31973194 case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
3198- OffloadingEntryInfoTargetRegion:
3195+ OffloadingEntryInfoTargetRegion: {
31993196 assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
32003197 "only required for the "
32013198 "device code generation.");
3199+ llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
3200+ /*DeviceID=*/GetMDInt(1),
3201+ /*FileID=*/GetMDInt(2),
3202+ /*Line=*/GetMDInt(4));
32023203 OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
3203- /*DeviceID=*/GetMDInt(1), /*FileID=*/GetMDInt(2),
3204- /*ParentName=*/GetMDString(3), /*Line=*/GetMDInt(4),
3205- /*Order=*/GetMDInt(5));
3204+ EntryInfo, /*Order=*/GetMDInt(5));
32063205 break;
3206+ }
32073207 case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
32083208 OffloadingEntryInfoDeviceGlobalVar:
32093209 assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
@@ -6209,7 +6209,7 @@ void CGOpenMPRuntime::emitTargetOutlinedFunction(
62096209 const OMPExecutableDirective &D, StringRef ParentName,
62106210 llvm::Function *&OutlinedFn, llvm::Constant *&OutlinedFnID,
62116211 bool IsOffloadEntry, const RegionCodeGenTy &CodeGen) {
6212- assert(!ParentName.empty() && "Invalid target region parent name!");
6212+ assert(!ParentName.empty() && "Invalid target entry parent name!");
62136213 HasEmittedTargetRegion = true;
62146214 SmallVector<std::pair<const Expr *, const Expr *>, 4> Allocators;
62156215 for (const auto *C : D.getClausesOfKind<OMPUsesAllocatorsClause>()) {
@@ -6292,17 +6292,10 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
62926292
62936293 const bool BuildOutlinedFn = CGM.getLangOpts().OpenMPIsDevice ||
62946294 !CGM.getLangOpts().OpenMPOffloadMandatory;
6295- unsigned DeviceID;
6296- unsigned FileID;
6297- unsigned Line;
6298- getTargetEntryUniqueInfo(CGM.getContext(), D.getBeginLoc(), DeviceID, FileID,
6299- Line);
6295+ auto EntryInfo =
6296+ getTargetEntryUniqueInfo(CGM.getContext(), D.getBeginLoc(), ParentName);
63006297 SmallString<64> EntryFnName;
6301- {
6302- llvm::raw_svector_ostream OS(EntryFnName);
6303- OS << "__omp_offloading" << llvm::format("_%x", DeviceID)
6304- << llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
6305- }
6298+ EntryInfo.getTargetRegionEntryFnName(EntryFnName);
63066299
63076300 const CapturedStmt &CS = *D.getCapturedStmt(OMPD_target);
63086301
@@ -6357,7 +6350,7 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
63576350
63586351 // Register the information for the entry associated with this target region.
63596352 OffloadEntriesInfoManager.registerTargetRegionEntryInfo(
6360- DeviceID, FileID, ParentName, Line , TargetRegionEntryAddr, OutlinedFnID,
6353+ EntryInfo , TargetRegionEntryAddr, OutlinedFnID,
63616354 llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion,
63626355 CGM.getLangOpts().OpenMPIsDevice);
63636356
@@ -10352,16 +10345,12 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,
1035210345
1035310346 if (RequiresDeviceCodegen) {
1035410347 const auto &E = *cast<OMPExecutableDirective>(S);
10355- unsigned DeviceID;
10356- unsigned FileID;
10357- unsigned Line;
10358- getTargetEntryUniqueInfo(CGM.getContext(), E.getBeginLoc(), DeviceID,
10359- FileID, Line);
10348+ auto EntryInfo =
10349+ getTargetEntryUniqueInfo(CGM.getContext(), E.getBeginLoc(), ParentName);
1036010350
1036110351 // Is this a target region that should not be emitted as an entry point? If
1036210352 // so just signal we are done with this target region.
10363- if (!OffloadEntriesInfoManager.hasTargetRegionEntryInfo(DeviceID, FileID,
10364- ParentName, Line))
10353+ if (!OffloadEntriesInfoManager.hasTargetRegionEntryInfo(EntryInfo))
1036510354 return;
1036610355
1036710356 switch (E.getDirectiveKind()) {
0 commit comments