forked from OSchip/llvm-project
[OPENMP]Improve diagnostics for not found declare target entries.
We can point to the target region + emit parent functions names/real var names if they were not found in host module during device codegen. llvm-svn: 373620
This commit is contained in:
parent
d1f23bd225
commit
ba643691dd
|
@ -4201,7 +4201,9 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
|
||||||
|
|
||||||
llvm::Module &M = CGM.getModule();
|
llvm::Module &M = CGM.getModule();
|
||||||
llvm::LLVMContext &C = M.getContext();
|
llvm::LLVMContext &C = M.getContext();
|
||||||
SmallVector<const OffloadEntriesInfoManagerTy::OffloadEntryInfo *, 16>
|
SmallVector<std::tuple<const OffloadEntriesInfoManagerTy::OffloadEntryInfo *,
|
||||||
|
SourceLocation, StringRef>,
|
||||||
|
16>
|
||||||
OrderedEntries(OffloadEntriesInfoManager.size());
|
OrderedEntries(OffloadEntriesInfoManager.size());
|
||||||
llvm::SmallVector<StringRef, 16> ParentFunctions(
|
llvm::SmallVector<StringRef, 16> ParentFunctions(
|
||||||
OffloadEntriesInfoManager.size());
|
OffloadEntriesInfoManager.size());
|
||||||
|
@ -4219,7 +4221,8 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
|
||||||
|
|
||||||
// Create function that emits metadata for each target region entry;
|
// Create function that emits metadata for each target region entry;
|
||||||
auto &&TargetRegionMetadataEmitter =
|
auto &&TargetRegionMetadataEmitter =
|
||||||
[&C, MD, &OrderedEntries, &ParentFunctions, &GetMDInt, &GetMDString](
|
[this, &C, MD, &OrderedEntries, &ParentFunctions, &GetMDInt,
|
||||||
|
&GetMDString](
|
||||||
unsigned DeviceID, unsigned FileID, StringRef ParentName,
|
unsigned DeviceID, unsigned FileID, StringRef ParentName,
|
||||||
unsigned Line,
|
unsigned Line,
|
||||||
const OffloadEntriesInfoManagerTy::OffloadEntryInfoTargetRegion &E) {
|
const OffloadEntriesInfoManagerTy::OffloadEntryInfoTargetRegion &E) {
|
||||||
|
@ -4237,8 +4240,19 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
|
||||||
GetMDInt(FileID), GetMDString(ParentName),
|
GetMDInt(FileID), GetMDString(ParentName),
|
||||||
GetMDInt(Line), GetMDInt(E.getOrder())};
|
GetMDInt(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) {
|
||||||
|
Loc = CGM.getContext().getSourceManager().translateFileLineCol(
|
||||||
|
I->getFirst(), Line, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Save this entry in the right position of the ordered entries array.
|
// Save this entry in the right position of the ordered entries array.
|
||||||
OrderedEntries[E.getOrder()] = &E;
|
OrderedEntries[E.getOrder()] = std::make_tuple(&E, Loc, ParentName);
|
||||||
ParentFunctions[E.getOrder()] = ParentName;
|
ParentFunctions[E.getOrder()] = ParentName;
|
||||||
|
|
||||||
// Add metadata to the named metadata node.
|
// Add metadata to the named metadata node.
|
||||||
|
@ -4266,7 +4280,8 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
|
||||||
GetMDInt(E.getFlags()), GetMDInt(E.getOrder())};
|
GetMDInt(E.getFlags()), GetMDInt(E.getOrder())};
|
||||||
|
|
||||||
// Save this entry in the right position of the ordered entries array.
|
// Save this entry in the right position of the ordered entries array.
|
||||||
OrderedEntries[E.getOrder()] = &E;
|
OrderedEntries[E.getOrder()] =
|
||||||
|
std::make_tuple(&E, SourceLocation(), MangledName);
|
||||||
|
|
||||||
// Add metadata to the named metadata node.
|
// Add metadata to the named metadata node.
|
||||||
MD->addOperand(llvm::MDNode::get(C, Ops));
|
MD->addOperand(llvm::MDNode::get(C, Ops));
|
||||||
|
@ -4275,11 +4290,11 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
|
||||||
OffloadEntriesInfoManager.actOnDeviceGlobalVarEntriesInfo(
|
OffloadEntriesInfoManager.actOnDeviceGlobalVarEntriesInfo(
|
||||||
DeviceGlobalVarMetadataEmitter);
|
DeviceGlobalVarMetadataEmitter);
|
||||||
|
|
||||||
for (const auto *E : OrderedEntries) {
|
for (const auto &E : OrderedEntries) {
|
||||||
assert(E && "All ordered entries must exist!");
|
assert(std::get<0>(E) && "All ordered entries must exist!");
|
||||||
if (const auto *CE =
|
if (const auto *CE =
|
||||||
dyn_cast<OffloadEntriesInfoManagerTy::OffloadEntryInfoTargetRegion>(
|
dyn_cast<OffloadEntriesInfoManagerTy::OffloadEntryInfoTargetRegion>(
|
||||||
E)) {
|
std::get<0>(E))) {
|
||||||
if (!CE->getID() || !CE->getAddress()) {
|
if (!CE->getID() || !CE->getAddress()) {
|
||||||
// Do not blame the entry if the parent funtion is not emitted.
|
// Do not blame the entry if the parent funtion is not emitted.
|
||||||
StringRef FnName = ParentFunctions[CE->getOrder()];
|
StringRef FnName = ParentFunctions[CE->getOrder()];
|
||||||
|
@ -4287,16 +4302,16 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
|
||||||
continue;
|
continue;
|
||||||
unsigned DiagID = CGM.getDiags().getCustomDiagID(
|
unsigned DiagID = CGM.getDiags().getCustomDiagID(
|
||||||
DiagnosticsEngine::Error,
|
DiagnosticsEngine::Error,
|
||||||
"Offloading entry for target region is incorrect: either the "
|
"Offloading entry for target region in %0 is incorrect: either the "
|
||||||
"address or the ID is invalid.");
|
"address or the ID is invalid.");
|
||||||
CGM.getDiags().Report(DiagID);
|
CGM.getDiags().Report(std::get<1>(E), DiagID) << FnName;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
createOffloadEntry(CE->getID(), CE->getAddress(), /*Size=*/0,
|
createOffloadEntry(CE->getID(), CE->getAddress(), /*Size=*/0,
|
||||||
CE->getFlags(), llvm::GlobalValue::WeakAnyLinkage);
|
CE->getFlags(), llvm::GlobalValue::WeakAnyLinkage);
|
||||||
} else if (const auto *CE =
|
} else if (const auto *CE = dyn_cast<OffloadEntriesInfoManagerTy::
|
||||||
dyn_cast<OffloadEntriesInfoManagerTy::
|
OffloadEntryInfoDeviceGlobalVar>(
|
||||||
OffloadEntryInfoDeviceGlobalVar>(E)) {
|
std::get<0>(E))) {
|
||||||
OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryKind Flags =
|
OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryKind Flags =
|
||||||
static_cast<OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryKind>(
|
static_cast<OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryKind>(
|
||||||
CE->getFlags());
|
CE->getFlags());
|
||||||
|
@ -4307,10 +4322,10 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
|
||||||
continue;
|
continue;
|
||||||
if (!CE->getAddress()) {
|
if (!CE->getAddress()) {
|
||||||
unsigned DiagID = CGM.getDiags().getCustomDiagID(
|
unsigned DiagID = CGM.getDiags().getCustomDiagID(
|
||||||
DiagnosticsEngine::Error,
|
DiagnosticsEngine::Error, "Offloading entry for declare target "
|
||||||
"Offloading entry for declare target variable is incorrect: the "
|
"variable %0 is incorrect: the "
|
||||||
"address is invalid.");
|
"address is invalid.");
|
||||||
CGM.getDiags().Report(DiagID);
|
CGM.getDiags().Report(std::get<1>(E), DiagID) << std::get<2>(E);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// The vaiable has no definition - no need to add the entry.
|
// The vaiable has no definition - no need to add the entry.
|
||||||
|
|
|
@ -13,14 +13,12 @@
|
||||||
// NO-HOST-BC: The provided host compiler IR file '1111.bc' is required to generate code for OpenMP target regions but cannot be found.
|
// NO-HOST-BC: The provided host compiler IR file '1111.bc' is required to generate code for OpenMP target regions but cannot be found.
|
||||||
|
|
||||||
// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc -DREGION_HOST
|
// RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm-bc %s -o %t-ppc-host.bc -DREGION_HOST
|
||||||
// RUN: not %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -DREGION_DEVICE 2>&1 | FileCheck %s --check-prefix NO-REGION
|
// RUN: not %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -DREGION_DEVICE 2>&1
|
||||||
// NO-REGION: Offloading entry for target region is incorrect: either the address or the ID is invalid.
|
|
||||||
// NO-REGION-NOT: Offloading entry for target region is incorrect: either the address or the ID is invalid.
|
|
||||||
|
|
||||||
#if defined(REGION_HOST) || defined(REGION_DEVICE)
|
#if defined(REGION_HOST) || defined(REGION_DEVICE)
|
||||||
void foo() {
|
void foo() {
|
||||||
#ifdef REGION_HOST
|
#ifdef REGION_HOST
|
||||||
#pragma omp target
|
#pragma omp target // expected-error {{Offloading entry for target region in _Z3foov is incorrect: either the address or the ID is invalid.}}
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
#ifdef REGION_DEVICE
|
#ifdef REGION_DEVICE
|
||||||
|
|
Loading…
Reference in New Issue