Skip to content

Commit 923f1fe

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:508a697acd18 into amd-gfx:57bd89831925
Local branch amd-gfx 57bd898 Merged main:747e0d9f0aad into amd-gfx:fdf184dabd64 Remote branch main 508a697 [JITLink] Allow multiple relocations at same offset in EHFrameEdgeFixer (llvm#68252)
2 parents 57bd898 + 508a697 commit 923f1fe

File tree

11 files changed

+97
-39
lines changed

11 files changed

+97
-39
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,8 +4197,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
41974197
if ((Left.is(tok::l_brace) && Left.isNot(BK_Block)) ||
41984198
(Right.is(tok::r_brace) && Right.MatchingParen &&
41994199
Right.MatchingParen->isNot(BK_Block))) {
4200-
return Style.Cpp11BracedListStyle ? Style.SpacesInParensOptions.Other
4201-
: true;
4200+
return !Style.Cpp11BracedListStyle || Style.SpacesInParensOptions.Other;
42024201
}
42034202
if (Left.is(TT_BlockComment)) {
42044203
// No whitespace in x(/*foo=*/1), except for JavaScript.

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 478294
19+
#define LLVM_MAIN_REVISION 478303
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,23 @@ Error EHFrameEdgeFixer::processBlock(ParseContext &PC, Block &B) {
126126
}
127127

128128
// Find the offsets of any existing edges from this block.
129-
BlockEdgeMap BlockEdges;
129+
BlockEdgesInfo BlockEdges;
130130
for (auto &E : B.edges())
131131
if (E.isRelocation()) {
132-
if (BlockEdges.count(E.getOffset()))
133-
return make_error<JITLinkError>(
134-
"Multiple relocations at offset " +
135-
formatv("{0:x16}", E.getOffset()) + " in " + EHFrameSectionName +
136-
" block at address " + formatv("{0:x16}", B.getAddress()));
137-
138-
BlockEdges[E.getOffset()] = EdgeTarget(E);
132+
// Check if we already saw more than one relocation at this offset.
133+
if (BlockEdges.Multiple.contains(E.getOffset()))
134+
continue;
135+
136+
// Otherwise check if we previously had exactly one relocation at this
137+
// offset. If so, we now have a second one and move it from the TargetMap
138+
// into the Multiple set.
139+
auto It = BlockEdges.TargetMap.find(E.getOffset());
140+
if (It != BlockEdges.TargetMap.end()) {
141+
BlockEdges.TargetMap.erase(It);
142+
BlockEdges.Multiple.insert(E.getOffset());
143+
} else {
144+
BlockEdges.TargetMap[E.getOffset()] = EdgeTarget(E);
145+
}
139146
}
140147

141148
BinaryStreamReader BlockReader(
@@ -172,7 +179,7 @@ Error EHFrameEdgeFixer::processBlock(ParseContext &PC, Block &B) {
172179

173180
Error EHFrameEdgeFixer::processCIE(ParseContext &PC, Block &B,
174181
size_t CIEDeltaFieldOffset,
175-
const BlockEdgeMap &BlockEdges) {
182+
const BlockEdgesInfo &BlockEdges) {
176183

177184
LLVM_DEBUG(dbgs() << " Record is CIE\n");
178185

@@ -285,7 +292,7 @@ Error EHFrameEdgeFixer::processCIE(ParseContext &PC, Block &B,
285292
Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
286293
size_t CIEDeltaFieldOffset,
287294
uint32_t CIEDelta,
288-
const BlockEdgeMap &BlockEdges) {
295+
const BlockEdgesInfo &BlockEdges) {
289296
LLVM_DEBUG(dbgs() << " Record is FDE\n");
290297

291298
orc::ExecutorAddr RecordAddress = B.getAddress();
@@ -303,12 +310,17 @@ Error EHFrameEdgeFixer::processFDE(ParseContext &PC, Block &B,
303310

304311
{
305312
// Process the CIE pointer field.
306-
auto CIEEdgeItr = BlockEdges.find(CIEDeltaFieldOffset);
313+
if (BlockEdges.Multiple.contains(CIEDeltaFieldOffset))
314+
return make_error<JITLinkError>(
315+
"CIE pointer field already has multiple edges at " +
316+
formatv("{0:x16}", RecordAddress + CIEDeltaFieldOffset));
317+
318+
auto CIEEdgeItr = BlockEdges.TargetMap.find(CIEDeltaFieldOffset);
307319

308320
orc::ExecutorAddr CIEAddress =
309321
RecordAddress + orc::ExecutorAddrDiff(CIEDeltaFieldOffset) -
310322
orc::ExecutorAddrDiff(CIEDelta);
311-
if (CIEEdgeItr == BlockEdges.end()) {
323+
if (CIEEdgeItr == BlockEdges.TargetMap.end()) {
312324
LLVM_DEBUG({
313325
dbgs() << " Adding edge at "
314326
<< (RecordAddress + CIEDeltaFieldOffset)
@@ -497,7 +509,7 @@ Error EHFrameEdgeFixer::skipEncodedPointer(uint8_t PointerEncoding,
497509
}
498510

499511
Expected<Symbol *> EHFrameEdgeFixer::getOrCreateEncodedPointerEdge(
500-
ParseContext &PC, const BlockEdgeMap &BlockEdges, uint8_t PointerEncoding,
512+
ParseContext &PC, const BlockEdgesInfo &BlockEdges, uint8_t PointerEncoding,
501513
BinaryStreamReader &RecordReader, Block &BlockToFix,
502514
size_t PointerFieldOffset, const char *FieldName) {
503515
using namespace dwarf;
@@ -508,8 +520,8 @@ Expected<Symbol *> EHFrameEdgeFixer::getOrCreateEncodedPointerEdge(
508520
// If there's already an edge here then just skip the encoded pointer and
509521
// return the edge's target.
510522
{
511-
auto EdgeI = BlockEdges.find(PointerFieldOffset);
512-
if (EdgeI != BlockEdges.end()) {
523+
auto EdgeI = BlockEdges.TargetMap.find(PointerFieldOffset);
524+
if (EdgeI != BlockEdges.TargetMap.end()) {
513525
LLVM_DEBUG({
514526
dbgs() << " Existing edge at "
515527
<< (BlockToFix.getAddress() + PointerFieldOffset) << " to "
@@ -522,6 +534,10 @@ Expected<Symbol *> EHFrameEdgeFixer::getOrCreateEncodedPointerEdge(
522534
return std::move(Err);
523535
return EdgeI->second.Target;
524536
}
537+
538+
if (BlockEdges.Multiple.contains(PointerFieldOffset))
539+
return make_error<JITLinkError>("Multiple relocations at offset " +
540+
formatv("{0:x16}", PointerFieldOffset));
525541
}
526542

527543
// Switch absptr to corresponding udata encoding.

llvm/lib/ExecutionEngine/JITLink/EHFrameSupportImpl.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ class EHFrameEdgeFixer {
6060
Edge::AddendT Addend = 0;
6161
};
6262

63-
using BlockEdgeMap = DenseMap<Edge::OffsetT, EdgeTarget>;
63+
struct BlockEdgesInfo {
64+
DenseMap<Edge::OffsetT, EdgeTarget> TargetMap;
65+
DenseSet<Edge::OffsetT> Multiple;
66+
};
67+
6468
using CIEInfosMap = DenseMap<orc::ExecutorAddr, CIEInformation>;
6569

6670
struct ParseContext {
@@ -82,9 +86,9 @@ class EHFrameEdgeFixer {
8286

8387
Error processBlock(ParseContext &PC, Block &B);
8488
Error processCIE(ParseContext &PC, Block &B, size_t CIEDeltaFieldOffset,
85-
const BlockEdgeMap &BlockEdges);
89+
const BlockEdgesInfo &BlockEdges);
8690
Error processFDE(ParseContext &PC, Block &B, size_t CIEDeltaFieldOffset,
87-
uint32_t CIEDelta, const BlockEdgeMap &BlockEdges);
91+
uint32_t CIEDelta, const BlockEdgesInfo &BlockEdges);
8892

8993
Expected<AugmentationInfo>
9094
parseAugmentationString(BinaryStreamReader &RecordReader);
@@ -94,9 +98,9 @@ class EHFrameEdgeFixer {
9498
Error skipEncodedPointer(uint8_t PointerEncoding,
9599
BinaryStreamReader &RecordReader);
96100
Expected<Symbol *> getOrCreateEncodedPointerEdge(
97-
ParseContext &PC, const BlockEdgeMap &BlockEdges, uint8_t PointerEncoding,
98-
BinaryStreamReader &RecordReader, Block &BlockToFix,
99-
size_t PointerFieldOffset, const char *FieldName);
101+
ParseContext &PC, const BlockEdgesInfo &BlockEdges,
102+
uint8_t PointerEncoding, BinaryStreamReader &RecordReader,
103+
Block &BlockToFix, size_t PointerFieldOffset, const char *FieldName);
100104

101105
Expected<Symbol &> getOrCreateSymbol(ParseContext &PC,
102106
orc::ExecutorAddr Addr);

mlir/examples/toy/Ch1/parser/AST.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
#include "toy/AST.h"
1414

15+
#include "llvm/ADT/STLExtras.h"
1516
#include "llvm/ADT/Twine.h"
1617
#include "llvm/ADT/TypeSwitch.h"
18+
#include "llvm/Support/Casting.h"
1719
#include "llvm/Support/raw_ostream.h"
20+
#include <string>
1821

1922
using namespace toy;
2023

mlir/examples/toy/Ch1/toyc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "toy/AST.h"
14+
#include "toy/Lexer.h"
1315
#include "toy/Parser.h"
1416

1517
#include "llvm/ADT/StringRef.h"
1618
#include "llvm/Support/CommandLine.h"
1719
#include "llvm/Support/ErrorOr.h"
1820
#include "llvm/Support/MemoryBuffer.h"
1921
#include "llvm/Support/raw_ostream.h"
22+
#include <memory>
23+
#include <string>
24+
#include <system_error>
2025

2126
using namespace toy;
2227
namespace cl = llvm::cl;

mlir/examples/toy/Ch2/mlir/Dialect.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@
1313

1414
#include "toy/Dialect.h"
1515

16+
#include "mlir/IR/Attributes.h"
1617
#include "mlir/IR/Builders.h"
1718
#include "mlir/IR/BuiltinTypes.h"
1819
#include "mlir/IR/OpImplementation.h"
20+
#include "mlir/IR/Operation.h"
21+
#include "mlir/IR/OperationSupport.h"
22+
#include "mlir/IR/Value.h"
1923
#include "mlir/Interfaces/FunctionImplementation.h"
24+
#include "mlir/Support/LLVM.h"
25+
#include "mlir/Support/LogicalResult.h"
26+
#include "llvm/ADT/ArrayRef.h"
27+
#include "llvm/ADT/STLExtras.h"
28+
#include "llvm/ADT/StringRef.h"
29+
#include "llvm/Support/Casting.h"
30+
#include <algorithm>
31+
#include <string>
2032

2133
using namespace mlir;
2234
using namespace mlir::toy;

mlir/examples/toy/Ch2/mlir/MLIRGen.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,31 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "toy/MLIRGen.h"
15+
#include "mlir/IR/Block.h"
16+
#include "mlir/IR/Diagnostics.h"
17+
#include "mlir/IR/Value.h"
18+
#include "mlir/Support/LogicalResult.h"
1519
#include "toy/AST.h"
1620
#include "toy/Dialect.h"
1721

18-
#include "mlir/IR/Attributes.h"
1922
#include "mlir/IR/Builders.h"
2023
#include "mlir/IR/BuiltinOps.h"
2124
#include "mlir/IR/BuiltinTypes.h"
2225
#include "mlir/IR/MLIRContext.h"
2326
#include "mlir/IR/Verifier.h"
27+
#include "toy/Lexer.h"
2428

2529
#include "llvm/ADT/STLExtras.h"
2630
#include "llvm/ADT/ScopedHashTable.h"
27-
#include "llvm/Support/raw_ostream.h"
31+
#include "llvm/ADT/SmallVector.h"
32+
#include "llvm/ADT/StringRef.h"
33+
#include "llvm/ADT/Twine.h"
34+
#include <cassert>
35+
#include <cstdint>
36+
#include <functional>
2837
#include <numeric>
38+
#include <optional>
39+
#include <vector>
2940

3041
using namespace mlir::toy;
3142
using namespace toy;

mlir/examples/toy/Ch2/parser/AST.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
#include "toy/AST.h"
1414

15+
#include "llvm/ADT/STLExtras.h"
1516
#include "llvm/ADT/Twine.h"
1617
#include "llvm/ADT/TypeSwitch.h"
18+
#include "llvm/Support/Casting.h"
1719
#include "llvm/Support/raw_ostream.h"
20+
#include <string>
1821

1922
using namespace toy;
2023

openmp/libomptarget/DeviceRTL/src/State.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void state::enterDataEnvironment(IdentTy *Ident) {
265265
uint32_t Bytes = sizeof(ThreadStates[0]) * mapping::getMaxTeamThreads();
266266
void *ThreadStatesPtr =
267267
memory::allocGlobal(Bytes, "Thread state array allocation");
268-
memset(ThreadStatesPtr, '0', Bytes);
268+
memset(ThreadStatesPtr, 0, Bytes);
269269
if (!atomic::cas(ThreadStatesBitsPtr, uintptr_t(0),
270270
reinterpret_cast<uintptr_t>(ThreadStatesPtr),
271271
atomic::seq_cst, atomic::seq_cst))
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
1-
// RUN: %libomptarget-compile-run-and-check-generic
1+
// Still broken "without optimizations"
2+
// XUN: %libomptarget-compile-run-and-check-generic
23
// RUN: %libomptarget-compileopt-run-and-check-generic
34

4-
// UNSUPPORTED: amdgcn-amd-amdhsa
5-
65
#include <omp.h>
76
#include <stdio.h>
87

98
int main() {
109
// TODO: Test all ICVs on all levels
11-
int lvl = 333, tid = 666, nt = 999;
12-
#pragma omp target teams map(tofrom : lvl, tid, nt) num_teams(2)
10+
int o_lvl = 111, i_lvl = 222, o_tid = 333, i_tid = 333, o_nt = 444,
11+
i_nt = 555;
12+
#pragma omp target teams map(tofrom : o_lvl, i_lvl, o_tid, i_tid, o_nt, i_nt) \
13+
num_teams(2) thread_limit(2)
1314
{
1415
if (omp_get_team_num() == 0) {
1516
#pragma omp parallel num_threads(128)
16-
if (omp_get_thread_num() == 17) {
17+
if (omp_get_thread_num() == omp_get_num_threads() - 1) {
18+
o_lvl = omp_get_level();
19+
o_tid = omp_get_thread_num();
20+
o_nt = omp_get_num_threads();
1721
#pragma omp parallel num_threads(64)
1822
if (omp_get_thread_num() == omp_get_num_threads() - 1) {
19-
lvl = omp_get_level();
20-
tid = omp_get_thread_num();
21-
nt = omp_get_num_threads();
23+
i_lvl = omp_get_level();
24+
i_tid = omp_get_thread_num();
25+
i_nt = omp_get_num_threads();
2226
}
2327
}
2428
}
2529
}
26-
// TODO: This is wrong, but at least it doesn't crash
27-
// CHECK: lvl: 2, tid: 0, nt: 1
28-
printf("lvl: %i, tid: %i, nt: %i\n", lvl, tid, nt);
30+
// CHECK: outer: lvl: 1, tid: 1, nt: 2
31+
// CHECK: inner: lvl: 2, tid: 0, nt: 1
32+
printf("outer: lvl: %i, tid: %i, nt: %i\n", o_lvl, o_tid, o_nt);
33+
printf("inner: lvl: %i, tid: %i, nt: %i\n", i_lvl, i_tid, i_nt);
2934
return 0;
3035
}

0 commit comments

Comments
 (0)