Skip to content

Commit 0cb65b0

Browse files
committed
Revert "[OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique target region info"
This reverts commit 3d0e9ed. Breaking HWASAN buildbot: https://lab.llvm.org/buildbot/#/builders/236/builds/786 Shown by targetted builds breaking at this patch: Built at this patch: https://lab.llvm.org/buildbot/#/builders/236/builds/803 Built at prior patch: https://lab.llvm.org/buildbot/#/builders/236/builds/804
1 parent 5c32742 commit 0cb65b0

File tree

6 files changed

+118
-124
lines changed

6 files changed

+118
-124
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -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 llvm::TargetRegionEntryInfo
1599-
getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
1600-
StringRef ParentName = "") {
1598+
static void getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
1599+
unsigned &DeviceID, unsigned &FileID,
1600+
unsigned &LineNum) {
16011601
SourceManager &SM = C.getSourceManager();
16021602

16031603
// The loc should be always valid and have a file ID (the user cannot use
@@ -1617,8 +1617,9 @@ getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
16171617
<< PLoc.getFilename() << EC.message();
16181618
}
16191619

1620-
return llvm::TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(),
1621-
PLoc.getLine());
1620+
DeviceID = ID.getDevice();
1621+
FileID = ID.getFile();
1622+
LineNum = PLoc.getLine();
16221623
}
16231624

16241625
Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {
@@ -1634,9 +1635,11 @@ Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {
16341635
llvm::raw_svector_ostream OS(PtrName);
16351636
OS << CGM.getMangledName(GlobalDecl(VD));
16361637
if (!VD->isExternallyVisible()) {
1637-
auto EntryInfo = getTargetEntryUniqueInfo(
1638-
CGM.getContext(), VD->getCanonicalDecl()->getBeginLoc());
1639-
OS << llvm::format("_%x", EntryInfo.FileID);
1638+
unsigned DeviceID, FileID, Line;
1639+
getTargetEntryUniqueInfo(CGM.getContext(),
1640+
VD->getCanonicalDecl()->getBeginLoc(),
1641+
DeviceID, FileID, Line);
1642+
OS << llvm::format("_%x", FileID);
16401643
}
16411644
OS << "_decl_tgt_ref_ptr";
16421645
}
@@ -1855,10 +1858,16 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
18551858
// Produce the unique prefix to identify the new target regions. We use
18561859
// the source location of the variable declaration which we know to not
18571860
// conflict with any target region.
1858-
auto EntryInfo =
1859-
getTargetEntryUniqueInfo(CGM.getContext(), Loc, VD->getName());
1861+
unsigned DeviceID;
1862+
unsigned FileID;
1863+
unsigned Line;
1864+
getTargetEntryUniqueInfo(CGM.getContext(), Loc, DeviceID, FileID, Line);
18601865
SmallString<128> Buffer, Out;
1861-
EntryInfo.getTargetRegionEntryFnName(Buffer);
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+
}
18621871

18631872
const Expr *Init = VD->getAnyInitializer();
18641873
if (CGM.getLangOpts().CPlusPlus && PerformInit) {
@@ -1904,12 +1913,9 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
19041913

19051914
// Register the information for the entry associated with the constructor.
19061915
Out.clear();
1907-
auto CtorEntryInfo = EntryInfo;
1908-
CtorEntryInfo.ParentName = Twine(Buffer, "_ctor").toStringRef(Out);
1909-
llvm::errs() << "Registering var ctor: " << Twine(Buffer, "_ctor") << "\n";
19101916
OffloadEntriesInfoManager.registerTargetRegionEntryInfo(
1911-
CtorEntryInfo, Ctor, ID,
1912-
llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor,
1917+
DeviceID, FileID, Twine(Buffer, "_ctor").toStringRef(Out), Line, Ctor,
1918+
ID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor,
19131919
CGM.getLangOpts().OpenMPIsDevice);
19141920
}
19151921
if (VD->getType().isDestructedType() != QualType::DK_none) {
@@ -1955,11 +1961,9 @@ bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
19551961
}
19561962
// Register the information for the entry associated with the destructor.
19571963
Out.clear();
1958-
auto DtorEntryInfo = EntryInfo;
1959-
DtorEntryInfo.ParentName = Twine(Buffer, "_dtor").toStringRef(Out);
19601964
OffloadEntriesInfoManager.registerTargetRegionEntryInfo(
1961-
DtorEntryInfo, Dtor, ID,
1962-
llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryDtor,
1965+
DeviceID, FileID, Twine(Buffer, "_dtor").toStringRef(Out), Line, Dtor,
1966+
ID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryDtor,
19631967
CGM.getLangOpts().OpenMPIsDevice);
19641968
}
19651969
return CGM.getLangOpts().OpenMPIsDevice;
@@ -2997,7 +3001,8 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
29973001
auto &&TargetRegionMetadataEmitter =
29983002
[this, &C, MD, &OrderedEntries, &ParentFunctions, &GetMDInt,
29993003
&GetMDString](
3000-
llvm::TargetRegionEntryInfo EntryInfo,
3004+
unsigned DeviceID, unsigned FileID, StringRef ParentName,
3005+
unsigned Line,
30013006
const llvm::OffloadEntriesInfoManager::OffloadEntryInfoTargetRegion
30023007
&E) {
30033008
// Generate metadata for target regions. Each entry of this metadata
@@ -3010,26 +3015,24 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
30103015
// - Entry 4 -> Line in the file where the entry was identified.
30113016
// - Entry 5 -> Order the entry was created.
30123017
// The first element of the metadata node is the kind.
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())};
3018+
llvm::Metadata *Ops[] = {GetMDInt(E.getKind()), GetMDInt(DeviceID),
3019+
GetMDInt(FileID), GetMDString(ParentName),
3020+
GetMDInt(Line), GetMDInt(E.getOrder())};
30173021

30183022
SourceLocation Loc;
30193023
for (auto I = CGM.getContext().getSourceManager().fileinfo_begin(),
30203024
E = CGM.getContext().getSourceManager().fileinfo_end();
30213025
I != E; ++I) {
3022-
if (I->getFirst()->getUniqueID().getDevice() == EntryInfo.DeviceID &&
3023-
I->getFirst()->getUniqueID().getFile() == EntryInfo.FileID) {
3026+
if (I->getFirst()->getUniqueID().getDevice() == DeviceID &&
3027+
I->getFirst()->getUniqueID().getFile() == FileID) {
30243028
Loc = CGM.getContext().getSourceManager().translateFileLineCol(
3025-
I->getFirst(), EntryInfo.Line, 1);
3029+
I->getFirst(), Line, 1);
30263030
break;
30273031
}
30283032
}
30293033
// Save this entry in the right position of the ordered entries array.
3030-
OrderedEntries[E.getOrder()] =
3031-
std::make_tuple(&E, Loc, StringRef(EntryInfo.ParentName));
3032-
ParentFunctions[E.getOrder()] = StringRef(EntryInfo.ParentName);
3034+
OrderedEntries[E.getOrder()] = std::make_tuple(&E, Loc, ParentName);
3035+
ParentFunctions[E.getOrder()] = ParentName;
30333036

30343037
// Add metadata to the named metadata node.
30353038
MD->addOperand(llvm::MDNode::get(C, Ops));
@@ -3192,18 +3195,15 @@ void CGOpenMPRuntime::loadOffloadInfoMetadata() {
31923195
llvm_unreachable("Unexpected metadata!");
31933196
break;
31943197
case llvm::OffloadEntriesInfoManager::OffloadEntryInfo::
3195-
OffloadingEntryInfoTargetRegion: {
3198+
OffloadingEntryInfoTargetRegion:
31963199
assert(CGM.getLangOpts().OpenMPIsDevice && "Initialization of entries is "
31973200
"only required for the "
31983201
"device code generation.");
3199-
llvm::TargetRegionEntryInfo EntryInfo(/*ParentName=*/GetMDString(3),
3200-
/*DeviceID=*/GetMDInt(1),
3201-
/*FileID=*/GetMDInt(2),
3202-
/*Line=*/GetMDInt(4));
32033202
OffloadEntriesInfoManager.initializeTargetRegionEntryInfo(
3204-
EntryInfo, /*Order=*/GetMDInt(5));
3203+
/*DeviceID=*/GetMDInt(1), /*FileID=*/GetMDInt(2),
3204+
/*ParentName=*/GetMDString(3), /*Line=*/GetMDInt(4),
3205+
/*Order=*/GetMDInt(5));
32053206
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 entry parent name!");
6212+
assert(!ParentName.empty() && "Invalid target region parent name!");
62136213
HasEmittedTargetRegion = true;
62146214
SmallVector<std::pair<const Expr *, const Expr *>, 4> Allocators;
62156215
for (const auto *C : D.getClausesOfKind<OMPUsesAllocatorsClause>()) {
@@ -6292,10 +6292,17 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
62926292

62936293
const bool BuildOutlinedFn = CGM.getLangOpts().OpenMPIsDevice ||
62946294
!CGM.getLangOpts().OpenMPOffloadMandatory;
6295-
auto EntryInfo =
6296-
getTargetEntryUniqueInfo(CGM.getContext(), D.getBeginLoc(), ParentName);
6295+
unsigned DeviceID;
6296+
unsigned FileID;
6297+
unsigned Line;
6298+
getTargetEntryUniqueInfo(CGM.getContext(), D.getBeginLoc(), DeviceID, FileID,
6299+
Line);
62976300
SmallString<64> EntryFnName;
6298-
EntryInfo.getTargetRegionEntryFnName(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+
}
62996306

63006307
const CapturedStmt &CS = *D.getCapturedStmt(OMPD_target);
63016308

@@ -6350,7 +6357,7 @@ void CGOpenMPRuntime::emitTargetOutlinedFunctionHelper(
63506357

63516358
// Register the information for the entry associated with this target region.
63526359
OffloadEntriesInfoManager.registerTargetRegionEntryInfo(
6353-
EntryInfo, TargetRegionEntryAddr, OutlinedFnID,
6360+
DeviceID, FileID, ParentName, Line, TargetRegionEntryAddr, OutlinedFnID,
63546361
llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion,
63556362
CGM.getLangOpts().OpenMPIsDevice);
63566363

@@ -10345,12 +10352,16 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,
1034510352

1034610353
if (RequiresDeviceCodegen) {
1034710354
const auto &E = *cast<OMPExecutableDirective>(S);
10348-
auto EntryInfo =
10349-
getTargetEntryUniqueInfo(CGM.getContext(), E.getBeginLoc(), ParentName);
10355+
unsigned DeviceID;
10356+
unsigned FileID;
10357+
unsigned Line;
10358+
getTargetEntryUniqueInfo(CGM.getContext(), E.getBeginLoc(), DeviceID,
10359+
FileID, Line);
1035010360

1035110361
// Is this a target region that should not be emitted as an entry point? If
1035210362
// so just signal we are done with this target region.
10353-
if (!OffloadEntriesInfoManager.hasTargetRegionEntryInfo(EntryInfo))
10363+
if (!OffloadEntriesInfoManager.hasTargetRegionEntryInfo(DeviceID, FileID,
10364+
ParentName, Line))
1035410365
return;
1035510366

1035610367
switch (E.getDirectiveKind()) {

clang/test/OpenMP/declare_target_codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// CHECK-DAG: define {{.*}}i32 @{{.*}}{{foo|bar|baz2|baz3|FA|f_method}}{{.*}}()
5252
// CHECK-DAG: define {{.*}}void @{{.*}}TemplateClass{{.*}}(ptr {{[^,]*}} %{{.*}})
5353
// CHECK-DAG: define {{.*}}i32 @{{.*}}TemplateClass{{.*}}f_method{{.*}}(ptr {{[^,]*}} %{{.*}})
54-
// CHECK-DAG: define {{.*}}void @__omp_offloading_{{.*}}_globals_l[[@LINE+78]]_ctor()
54+
// CHECK-DAG: define {{.*}}void @__omp_offloading__{{.*}}_globals_l[[@LINE+78]]_ctor()
5555

5656
#ifndef HEADER
5757
#define HEADER

clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ int caz() { return 0; }
4343

4444
static int c = foo() + bar() + baz();
4545
#pragma omp declare target (c)
46-
// HOST-DAG: @[[C_CTOR:__omp_offloading_.+_c_l44_ctor]] = private constant i8 0
47-
// DEVICE-DAG: define weak_odr protected void [[C_CTOR:@__omp_offloading_.+_c_l44_ctor]]()
46+
// HOST-DAG: @[[C_CTOR:__omp_offloading__.+_c_l44_ctor]] = private constant i8 0
47+
// DEVICE-DAG: define weak_odr protected void [[C_CTOR:@__omp_offloading__.+_c_l44_ctor]]()
4848
// DEVICE-DAG: call noundef i32 [[FOO]]()
4949
// DEVICE-DAG: call noundef i32 [[BAR]]()
5050
// DEVICE-DAG: call noundef i32 [[BAZ]]()
@@ -60,15 +60,15 @@ struct S {
6060
#pragma omp declare target
6161
S cd = doo() + car() + caz() + baz();
6262
#pragma omp end declare target
63-
// HOST-DAG: @[[CD_CTOR:__omp_offloading_.+_cd_l61_ctor]] = private constant i8 0
64-
// DEVICE-DAG: define weak_odr protected void [[CD_CTOR:@__omp_offloading_.+_cd_l61_ctor]]()
63+
// HOST-DAG: @[[CD_CTOR:__omp_offloading__.+_cd_l61_ctor]] = private constant i8 0
64+
// DEVICE-DAG: define weak_odr protected void [[CD_CTOR:@__omp_offloading__.+_cd_l61_ctor]]()
6565
// DEVICE-DAG: call noundef i32 [[DOO]]()
6666
// DEVICE-DAG: call noundef i32 [[CAR]]()
6767
// DEVICE-DAG: call noundef i32 [[CAZ]]()
6868
// DEVICE-DAG: ret void
6969

70-
// HOST-DAG: @[[CD_DTOR:__omp_offloading_.+_cd_l61_dtor]] = private constant i8 0
71-
// DEVICE-DAG: define weak_odr protected void [[CD_DTOR:@__omp_offloading_.+_cd_l61_dtor]]()
70+
// HOST-DAG: @[[CD_DTOR:__omp_offloading__.+_cd_l61_dtor]] = private constant i8 0
71+
// DEVICE-DAG: define weak_odr protected void [[CD_DTOR:@__omp_offloading__.+_cd_l61_dtor]]()
7272
// DEVICE-DAG: call void
7373
// DEVICE-DAG: ret void
7474

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

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
#include "llvm/IR/IRBuilder.h"
2121
#include "llvm/Support/Allocator.h"
2222
#include <forward_list>
23-
#include <map>
2423

2524
namespace llvm {
2625
class CanonicalLoopInfo;
27-
class OffloadEntriesInfoManager;
2826

2927
/// Move the instruction after an InsertPoint to the beginning of another
3028
/// BasicBlock.
@@ -1683,33 +1681,6 @@ class OpenMPIRBuilder {
16831681
const Twine &Name = {});
16841682
};
16851683

1686-
/// Data structure to contain the information needed to uniquely identify
1687-
/// a target entry.
1688-
struct TargetRegionEntryInfo {
1689-
std::string ParentName;
1690-
unsigned DeviceID;
1691-
unsigned FileID;
1692-
unsigned Line;
1693-
1694-
TargetRegionEntryInfo() : ParentName(""), DeviceID(0), FileID(0), Line(0) {}
1695-
TargetRegionEntryInfo(StringRef ParentName, unsigned DeviceID,
1696-
unsigned FileID, unsigned Line)
1697-
: ParentName(ParentName), DeviceID(DeviceID), FileID(FileID), Line(Line) {
1698-
}
1699-
1700-
static void getTargetRegionEntryFnName(SmallVectorImpl<char> &Name,
1701-
StringRef ParentName,
1702-
unsigned DeviceID, unsigned FileID,
1703-
unsigned Line);
1704-
1705-
void getTargetRegionEntryFnName(SmallVectorImpl<char> &Name);
1706-
1707-
bool operator<(const TargetRegionEntryInfo RHS) const {
1708-
return std::make_tuple(ParentName, DeviceID, FileID, Line) <
1709-
std::make_tuple(RHS.ParentName, RHS.DeviceID, RHS.FileID, RHS.Line);
1710-
}
1711-
};
1712-
17131684
/// Class that manages information about offload code regions and data
17141685
class OffloadEntriesInfoManager {
17151686
/// Number of entries registered so far.
@@ -1811,19 +1782,22 @@ class OffloadEntriesInfoManager {
18111782

18121783
/// Initialize target region entry.
18131784
/// This is ONLY needed for DEVICE compilation.
1814-
void initializeTargetRegionEntryInfo(const TargetRegionEntryInfo &EntryInfo,
1785+
void initializeTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
1786+
StringRef ParentName, unsigned LineNum,
18151787
unsigned Order);
18161788
/// Register target region entry.
1817-
void registerTargetRegionEntryInfo(const TargetRegionEntryInfo &EntryInfo,
1789+
void registerTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
1790+
StringRef ParentName, unsigned LineNum,
18181791
Constant *Addr, Constant *ID,
18191792
OMPTargetRegionEntryKind Flags,
18201793
bool IsDevice);
18211794
/// Return true if a target region entry with the provided information
18221795
/// exists.
1823-
bool hasTargetRegionEntryInfo(const TargetRegionEntryInfo &EntryInfo,
1796+
bool hasTargetRegionEntryInfo(unsigned DeviceID, unsigned FileID,
1797+
StringRef ParentName, unsigned LineNum,
18241798
bool IgnoreAddressId = false) const;
18251799
/// brief Applies action \a Action on all registered entries.
1826-
typedef function_ref<void(const TargetRegionEntryInfo &EntryInfo,
1800+
typedef function_ref<void(unsigned, unsigned, StringRef, unsigned,
18271801
const OffloadEntryInfoTargetRegion &)>
18281802
OffloadTargetRegionEntryInfoActTy;
18291803
void
@@ -1894,9 +1868,17 @@ class OffloadEntriesInfoManager {
18941868
const OffloadDeviceGlobalVarEntryInfoActTy &Action);
18951869

18961870
private:
1897-
// Storage for target region entries kind.
1898-
typedef std::map<TargetRegionEntryInfo, OffloadEntryInfoTargetRegion>
1899-
OffloadEntriesTargetRegionTy;
1871+
// Storage for target region entries kind. The storage is to be indexed by
1872+
// file ID, device ID, parent function name and line number.
1873+
typedef DenseMap<unsigned, OffloadEntryInfoTargetRegion>
1874+
OffloadEntriesTargetRegionPerLine;
1875+
typedef StringMap<OffloadEntriesTargetRegionPerLine>
1876+
OffloadEntriesTargetRegionPerParentName;
1877+
typedef DenseMap<unsigned, OffloadEntriesTargetRegionPerParentName>
1878+
OffloadEntriesTargetRegionPerFile;
1879+
typedef DenseMap<unsigned, OffloadEntriesTargetRegionPerFile>
1880+
OffloadEntriesTargetRegionPerDevice;
1881+
typedef OffloadEntriesTargetRegionPerDevice OffloadEntriesTargetRegionTy;
19001882
OffloadEntriesTargetRegionTy OffloadEntriesTargetRegion;
19011883
/// Storage for device global variable entries kind. The storage is to be
19021884
/// indexed by mangled name.

0 commit comments

Comments
 (0)