Skip to content

Commit 82c6cc1

Browse files
committed
Manually merged main:d37ced88809cb4d2df57ec80887b3f8801ca719b into amd-gfx:bbaefb59377a
Local branch amd-gfx bbaefb5 Manually merged main:3c423722cfd75bf293e42001145fe9ebad53c522 into amd-gfx:52eb0adfd010 Remote branch main d37ced8 AMDGPU: refactor phi lowering from SILowerI1Copies (NFCI) (llvm#75349)
2 parents bbaefb5 + d37ced8 commit 82c6cc1

File tree

756 files changed

+56097
-32116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

756 files changed

+56097
-32116
lines changed

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace llvm {
3333

3434
namespace bolt {
3535
class DIEStreamer;
36+
class DebugStrOffsetsWriter;
3637

3738
class DIEBuilder {
3839
friend DIEStreamer;
@@ -266,7 +267,8 @@ class DIEBuilder {
266267
ProcessingType getCurrentProcessingState() { return getState().Type; }
267268

268269
/// Constructs IR for Type Units.
269-
void buildTypeUnits(const bool Init = true);
270+
void buildTypeUnits(DebugStrOffsetsWriter *StrOffsetWriter = nullptr,
271+
const bool Init = true);
270272
/// Constructs IR for all the CUs.
271273
void buildCompileUnits(const bool Init = true);
272274
/// Constructs IR for CUs in a vector.

bolt/include/bolt/Core/DebugData.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,6 @@ class DebugStrOffsetsWriter {
436436
StrOffsetsStream = std::make_unique<raw_svector_ostream>(*StrOffsetsBuffer);
437437
}
438438

439-
/// Initializes Buffer and Stream.
440-
void initialize(const DWARFSection &StrOffsetsSection,
441-
const std::optional<StrOffsetsContributionDescriptor> Contr);
442-
443439
/// Update Str offset in .debug_str in .debug_str_offsets.
444440
void updateAddressMap(uint32_t Index, uint32_t Address);
445441

@@ -455,9 +451,13 @@ class DebugStrOffsetsWriter {
455451
}
456452

457453
private:
454+
/// Initializes Buffer and Stream.
455+
void initialize(DWARFUnit &Unit);
456+
458457
std::unique_ptr<DebugStrOffsetsBufferVector> StrOffsetsBuffer;
459458
std::unique_ptr<raw_svector_ostream> StrOffsetsStream;
460459
std::map<uint32_t, uint32_t> IndexToAddressMap;
460+
std::vector<uint32_t> StrOffsets;
461461
std::unordered_map<uint64_t, uint64_t> ProcessedBaseOffsets;
462462
bool StrOffsetSectionWasModified = false;
463463
};

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ static unsigned int getCUNum(DWARFContext *DwarfContext, bool IsDWO) {
189189
return CUNum;
190190
}
191191

192-
void DIEBuilder::buildTypeUnits(const bool Init) {
192+
void DIEBuilder::buildTypeUnits(DebugStrOffsetsWriter *StrOffsetWriter,
193+
const bool Init) {
193194
if (Init)
194195
BuilderState.reset(new State());
195196

@@ -229,8 +230,11 @@ void DIEBuilder::buildTypeUnits(const bool Init) {
229230
registerUnit(*DU.get(), false);
230231
}
231232

232-
for (DWARFUnit *DU : getState().DWARF5TUVector)
233+
for (DWARFUnit *DU : getState().DWARF5TUVector) {
233234
constructFromUnit(*DU);
235+
if (StrOffsetWriter)
236+
StrOffsetWriter->finalizeSection(*DU, *this);
237+
}
234238
}
235239

236240
void DIEBuilder::buildCompileUnits(const bool Init) {
@@ -280,7 +284,7 @@ void DIEBuilder::buildCompileUnits(const std::vector<DWARFUnit *> &CUs) {
280284
void DIEBuilder::buildDWOUnit(DWARFUnit &U) {
281285
BuilderState.release();
282286
BuilderState = std::make_unique<State>();
283-
buildTypeUnits(false);
287+
buildTypeUnits(nullptr, false);
284288
getState().Type = ProcessingType::CUs;
285289
registerUnit(U, false);
286290
constructFromUnit(U);

bolt/lib/Core/DebugData.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -851,35 +851,34 @@ std::string SimpleBinaryPatcher::patchBinary(StringRef BinaryContents) {
851851
return BinaryContentsStr;
852852
}
853853

854-
void DebugStrOffsetsWriter::initialize(
855-
const DWARFSection &StrOffsetsSection,
856-
const std::optional<StrOffsetsContributionDescriptor> Contr) {
854+
void DebugStrOffsetsWriter::initialize(DWARFUnit &Unit) {
855+
if (Unit.getVersion() < 5)
856+
return;
857+
const DWARFSection &StrOffsetsSection = Unit.getStringOffsetSection();
858+
const std::optional<StrOffsetsContributionDescriptor> &Contr =
859+
Unit.getStringOffsetsTableContribution();
857860
if (!Contr)
858861
return;
859-
860862
const uint8_t DwarfOffsetByteSize = Contr->getDwarfOffsetByteSize();
861863
assert(DwarfOffsetByteSize == 4 &&
862864
"Dwarf String Offsets Byte Size is not supported.");
863-
uint32_t Index = 0;
865+
StrOffsets.reserve(Contr->Size);
864866
for (uint64_t Offset = 0; Offset < Contr->Size; Offset += DwarfOffsetByteSize)
865-
IndexToAddressMap[Index++] = support::endian::read32le(
866-
StrOffsetsSection.Data.data() + Contr->Base + Offset);
867+
StrOffsets.push_back(support::endian::read32le(
868+
StrOffsetsSection.Data.data() + Contr->Base + Offset));
867869
}
868870

869871
void DebugStrOffsetsWriter::updateAddressMap(uint32_t Index, uint32_t Address) {
870-
assert(IndexToAddressMap.count(Index) > 0 && "Index is not found.");
871872
IndexToAddressMap[Index] = Address;
872873
StrOffsetSectionWasModified = true;
873874
}
874875

875876
void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
876877
DIEBuilder &DIEBldr) {
877-
if (IndexToAddressMap.empty())
878-
return;
879-
880878
std::optional<AttrInfo> AttrVal =
881879
findAttributeInfo(Unit.getUnitDIE(), dwarf::DW_AT_str_offsets_base);
882-
assert(AttrVal && "DW_AT_str_offsets_base not present.");
880+
if (!AttrVal)
881+
return;
883882
std::optional<uint64_t> Val = AttrVal->V.getAsSectionOffset();
884883
assert(Val && "DW_AT_str_offsets_base Value not present.");
885884
DIE &Die = *DIEBldr.getUnitDIEbyUnit(Unit);
@@ -888,11 +887,14 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
888887
auto RetVal = ProcessedBaseOffsets.find(*Val);
889888
// Handling re-use of str-offsets section.
890889
if (RetVal == ProcessedBaseOffsets.end() || StrOffsetSectionWasModified) {
890+
initialize(Unit);
891+
// Update String Offsets that were modified.
892+
for (const auto &Entry : IndexToAddressMap)
893+
StrOffsets[Entry.first] = Entry.second;
891894
// Writing out the header for each section.
892-
support::endian::write(
893-
*StrOffsetsStream,
894-
static_cast<uint32_t>(IndexToAddressMap.size() * 4 + 4),
895-
llvm::endianness::little);
895+
support::endian::write(*StrOffsetsStream,
896+
static_cast<uint32_t>(StrOffsets.size() * 4 + 4),
897+
llvm::endianness::little);
896898
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(5),
897899
llvm::endianness::little);
898900
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(0),
@@ -904,8 +906,8 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
904906
DIEBldr.replaceValue(&Die, dwarf::DW_AT_str_offsets_base,
905907
StrListBaseAttrInfo.getForm(),
906908
DIEInteger(BaseOffset));
907-
for (const auto &Entry : IndexToAddressMap)
908-
support::endian::write(*StrOffsetsStream, Entry.second,
909+
for (const uint32_t Offset : StrOffsets)
910+
support::endian::write(*StrOffsetsStream, Offset,
909911
llvm::endianness::little);
910912
} else {
911913
DIEBldr.replaceValue(&Die, dwarf::DW_AT_str_offsets_base,
@@ -915,6 +917,7 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
915917

916918
StrOffsetSectionWasModified = false;
917919
IndexToAddressMap.clear();
920+
StrOffsets.clear();
918921
}
919922

920923
void DebugStrWriter::create() {

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ void DWARFRewriter::addStringHelper(DIEBuilder &DIEBldr, DIE &Die,
554554
const DWARFUnit &Unit,
555555
DIEValue &DIEAttrInfo, StringRef Str) {
556556
uint32_t NewOffset = StrWriter->addString(Str);
557-
if (Unit.getVersion() == 5) {
557+
if (Unit.getVersion() >= 5) {
558558
StrOffstsWriter->updateAddressMap(DIEAttrInfo.getDIEInteger().getValue(),
559559
NewOffset);
560560
return;
@@ -696,9 +696,6 @@ void DWARFRewriter::updateDebugInfo() {
696696
std::optional<DWARFUnit *> SplitCU;
697697
std::optional<uint64_t> RangesBase;
698698
std::optional<uint64_t> DWOId = Unit->getDWOId();
699-
if (Unit->getVersion() >= 5)
700-
StrOffstsWriter->initialize(Unit->getStringOffsetSection(),
701-
Unit->getStringOffsetsTableContribution());
702699
if (DWOId)
703700
SplitCU = BC.getDWOCU(*DWOId);
704701
DebugLocWriter *DebugLocWriter = createRangeLocList(*Unit);
@@ -753,7 +750,7 @@ void DWARFRewriter::updateDebugInfo() {
753750
};
754751

755752
DIEBuilder DIEBlder(BC.DwCtx.get());
756-
DIEBlder.buildTypeUnits();
753+
DIEBlder.buildTypeUnits(StrOffstsWriter.get());
757754
SmallVector<char, 20> OutBuffer;
758755
std::unique_ptr<raw_svector_ostream> ObjOS =
759756
std::make_unique<raw_svector_ostream>(OutBuffer);

bolt/test/RISCV/call-annotations.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ f:
1616

1717
// CHECK-LABEL: Binary Function "_start" after building cfg {
1818
// CHECK: auipc ra, f
19-
// CHECK-NEXT: jalr ra, -4(ra) # Offset: 4
19+
// CHECK-NEXT: jalr ra, -0x4(ra) # Offset: 4
2020
// CHECK-NEXT: jal ra, f # Offset: 8
2121
// CHECK-NEXT: jal zero, f # TAILCALL # Offset: 12
2222

2323
// CHECK-LABEL: Binary Function "long_tail" after building cfg {
2424
// CHECK: auipc t1, f
25-
// CHECK-NEXT: jalr zero, -24(t1) # TAILCALL # Offset: 8
25+
// CHECK-NEXT: jalr zero, -0x18(t1) # TAILCALL # Offset: 8
2626

2727
// CHECK-LABEL: Binary Function "compressed_tail" after building cfg {
2828
// CHECK: jr a0 # TAILCALL # Offset: 0

bolt/test/RISCV/relax.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// CHECK: Binary Function "_start" after building cfg {
88
// CHECK: jal ra, near_f
99
// CHECK-NEXT: auipc ra, far_f@plt
10-
// CHECK-NEXT: jalr ra, 12(ra)
10+
// CHECK-NEXT: jalr ra, 0xc(ra)
1111
// CHECK-NEXT: j near_f
1212

1313
// CHECK: Binary Function "_start" after fix-riscv-calls {
@@ -17,8 +17,8 @@
1717

1818
// OBJDUMP: 0000000000600000 <_start>:
1919
// OBJDUMP-NEXT: jal 0x600040 <near_f>
20-
// OBJDUMP-NEXT: auipc ra, 512
21-
// OBJDUMP-NEXT: jalr 124(ra)
20+
// OBJDUMP-NEXT: auipc ra, 0x200
21+
// OBJDUMP-NEXT: jalr 0x7c(ra)
2222
// OBJDUMP-NEXT: j 0x600040 <near_f>
2323
// OBJDUMP: 0000000000600040 <near_f>:
2424
// OBJDUMP: 0000000000800080 <far_f>:

bolt/test/RISCV/reloc-tls.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// RUN: | FileCheck %s
55

66
// CHECK-LABEL: Binary Function "tls_le{{.*}}" after building cfg {
7-
// CHECK: lui a5, 0
7+
// CHECK: lui a5, 0x0
88
// CHECK-NEXT: add a5, a5, tp
9-
// CHECK-NEXT: lw t0, 0(a5)
10-
// CHECK-NEXT: sw t0, 0(a5)
9+
// CHECK-NEXT: lw t0, 0x0(a5)
10+
// CHECK-NEXT: sw t0, 0x0(a5)
1111

1212
// CHECK-LABEL: Binary Function "tls_ie" after building cfg {
1313
// CHECK-LABEL: .LBB01

bolt/test/RISCV/reorder-blocks-reverse.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ _start:
2323
// CHECK-NEXT: {{.*}}00: beq t0, t1, {{.*}} <_start+0x10>
2424
// CHECK-NEXT: {{.*}}04: j {{.*}} <_start+0x16>
2525
// CHECK-NEXT: {{.*}}08: ret
26-
// CHECK-NEXT: {{.*}}0a: li a0, 6
26+
// CHECK-NEXT: {{.*}}0a: li a0, 0x6
2727
// CHECK-NEXT: {{.*}}0c: j {{.*}} <_start+0x8>
28-
// CHECK-NEXT: {{.*}}10: li a0, 5
28+
// CHECK-NEXT: {{.*}}10: li a0, 0x5
2929
// CHECK-NEXT: {{.*}}12: j {{.*}} <_start+0x8>
3030
// CHECK-NEXT: {{.*}}16: beq t0, t2, {{.*}} <_start+0xa>
3131
// CHECK-NEXT: {{.*}}1a: j {{.*}} <_start+0x10>

bolt/test/RISCV/tls-le-gnu-ld.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
// RUN: | FileCheck %s
88

99
// CHECK: Binary Function "_start" after building cfg {
10-
// CHECK: lw t0, 0(tp)
11-
// CHECK-NEXT: sw t0, 0(tp)
10+
// CHECK: lw t0, 0x0(tp)
11+
// CHECK-NEXT: sw t0, 0x0(tp)

0 commit comments

Comments
 (0)