Skip to content

Commit 7ef0f9a

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#2974)
2 parents 6f87e58 + bdbaa96 commit 7ef0f9a

File tree

41 files changed

+415
-343
lines changed

Some content is hidden

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

41 files changed

+415
-343
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
15641564
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
15651565
DynamicAllocator::Form::Operator);
15661566
assert(B);
1567-
S.Stk.push<Pointer>(Pointer(B).atIndex(0));
1567+
S.Stk.push<Pointer>(Pointer(B).atIndex(0).narrow());
15681568
return true;
15691569
}
15701570

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,10 @@ class LineJoiner {
986986
void join(AnnotatedLine &A, const AnnotatedLine &B) {
987987
assert(!A.Last->Next);
988988
assert(!B.First->Previous);
989-
if (B.Affected)
989+
if (B.Affected || B.LeadingEmptyLinesAffected) {
990+
assert(B.Affected || A.Last->Children.empty());
990991
A.Affected = true;
992+
}
991993
A.Last->Next = B.First;
992994
B.First->Previous = A.Last;
993995
B.First->CanBreakBefore = true;

clang/unittests/Format/FormatTestSelective.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ TEST_F(FormatTestSelective, RemovesTrailingWhitespaceOfFormattedLine) {
4141
EXPECT_EQ("int a;", format("int a; ", 0, 0));
4242
EXPECT_EQ("int a;\n", format("int a; \n \n \n ", 0, 0));
4343
EXPECT_EQ("int a;\nint b; ", format("int a; \nint b; ", 0, 0));
44+
45+
EXPECT_EQ("void f() {}", format("void f() {\n"
46+
" \n"
47+
"}",
48+
11, 0));
4449
}
4550

4651
TEST_F(FormatTestSelective, FormatsCorrectRegionForLeadingWhitespace) {

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ class MCAssembler {
113113
bool fragmentNeedsRelaxation(const MCRelaxableFragment &) const;
114114

115115
void layoutSection(MCSection &Sec);
116-
/// Perform one layout iteration and return true if any offsets
117-
/// were adjusted.
118-
bool relaxOnce();
116+
/// Perform one layout iteration and return the index of the first stable
117+
/// section for subsequent optimization.
118+
unsigned relaxOnce(unsigned FirstStable);
119119

120120
/// Perform relaxation on a single fragment.
121121
bool relaxFragment(MCFragment &F);

llvm/include/llvm/MC/MCFixup.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace llvm {
1818
class MCExpr;
1919

2020
/// Extensible enumeration to represent the type of a fixup.
21-
enum MCFixupKind : uint16_t {
21+
using MCFixupKind = uint16_t;
22+
enum {
2223
// [0, FirstLiteralRelocationKind) encodes raw relocation types.
2324

2425
// [FirstLiteralRelocationKind, FK_NONE) encodes raw relocation types coming
@@ -67,7 +68,7 @@ class MCFixup {
6768

6869
/// The target dependent kind of fixup item this is. The kind is used to
6970
/// determine how the operand value should be encoded into the instruction.
70-
uint16_t Kind = FK_NONE;
71+
MCFixupKind Kind = FK_NONE;
7172

7273
/// True if this is a PC-relative fixup. The relocatable expression is
7374
/// typically resolved When SymB is nullptr and SymA is a local symbol defined
@@ -81,7 +82,7 @@ class MCFixup {
8182
/// Consider bit fields if we need more flags.
8283

8384
public:
84-
static MCFixup create(uint32_t Offset, const MCExpr *Value, uint16_t Kind,
85+
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind,
8586
bool PCRel = false) {
8687
MCFixup FI;
8788
FI.Value = Value;
@@ -90,13 +91,8 @@ class MCFixup {
9091
FI.PCRel = PCRel;
9192
return FI;
9293
}
93-
static MCFixup create(uint32_t Offset, const MCExpr *Value,
94-
MCFixupKind Kind) {
95-
return create(Offset, Value, unsigned(Kind));
96-
}
97-
98-
MCFixupKind getKind() const { return MCFixupKind(Kind); }
9994

95+
MCFixupKind getKind() const { return Kind; }
10096
unsigned getTargetKind() const { return Kind; }
10197

10298
uint32_t getOffset() const { return Offset; }

llvm/include/llvm/MC/MCSection.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ class MCFragment {
5252

5353
public:
5454
enum FragmentType : uint8_t {
55-
FT_Align,
5655
FT_Data,
56+
FT_Relaxable,
57+
FT_Align,
5758
FT_Fill,
59+
FT_LEB,
5860
FT_Nops,
59-
FT_Relaxable,
6061
FT_Org,
6162
FT_Dwarf,
6263
FT_DwarfFrame,
63-
FT_LEB,
6464
FT_BoundaryAlign,
6565
FT_SymbolId,
6666
FT_CVInlineLines,

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ bool IRTranslator::translateGetElementPtr(const User &U,
16811681
auto OffsetMIB =
16821682
MIRBuilder.buildConstant(OffsetTy, Offset);
16831683

1684-
if (int64_t(Offset) >= 0 && cast<GEPOperator>(U).isInBounds())
1684+
if (Offset >= 0 && cast<GEPOperator>(U).isInBounds())
16851685
Flags |= MachineInstr::MIFlag::NoUWrap;
16861686

16871687
MIRBuilder.buildPtrAdd(getOrCreateVReg(U), BaseReg, OffsetMIB.getReg(0),

llvm/lib/MC/MCAssembler.cpp

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,14 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
196196
assert(getBackendPtr() && "Requires assembler backend");
197197
switch (F.getKind()) {
198198
case MCFragment::FT_Data:
199-
return cast<MCDataFragment>(F).getContents().size();
200199
case MCFragment::FT_Relaxable:
201-
return cast<MCRelaxableFragment>(F).getContents().size();
200+
case MCFragment::FT_LEB:
201+
case MCFragment::FT_Dwarf:
202+
case MCFragment::FT_DwarfFrame:
203+
case MCFragment::FT_CVInlineLines:
204+
case MCFragment::FT_CVDefRange:
205+
case MCFragment::FT_PseudoProbe:
206+
return cast<MCEncodedFragment>(F).getContents().size();
202207
case MCFragment::FT_Fill: {
203208
auto &FF = cast<MCFillFragment>(F);
204209
int64_t NumValues = 0;
@@ -217,9 +222,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
217222
case MCFragment::FT_Nops:
218223
return cast<MCNopsFragment>(F).getNumBytes();
219224

220-
case MCFragment::FT_LEB:
221-
return cast<MCLEBFragment>(F).getContents().size();
222-
223225
case MCFragment::FT_BoundaryAlign:
224226
return cast<MCBoundaryAlignFragment>(F).getSize();
225227

@@ -275,17 +277,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
275277
}
276278
return Size;
277279
}
278-
279-
case MCFragment::FT_Dwarf:
280-
return cast<MCDwarfLineAddrFragment>(F).getContents().size();
281-
case MCFragment::FT_DwarfFrame:
282-
return cast<MCDwarfCallFrameFragment>(F).getContents().size();
283-
case MCFragment::FT_CVInlineLines:
284-
return cast<MCCVInlineLineTableFragment>(F).getContents().size();
285-
case MCFragment::FT_CVDefRange:
286-
return cast<MCCVDefRangeFragment>(F).getContents().size();
287-
case MCFragment::FT_PseudoProbe:
288-
return cast<MCPseudoProbeAddrFragment>(F).getContents().size();
289280
}
290281

291282
llvm_unreachable("invalid fragment kind");
@@ -543,6 +534,22 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
543534
++stats::EmittedFragments;
544535

545536
switch (F.getKind()) {
537+
case MCFragment::FT_Data:
538+
case MCFragment::FT_Relaxable:
539+
case MCFragment::FT_LEB:
540+
case MCFragment::FT_Dwarf:
541+
case MCFragment::FT_DwarfFrame:
542+
case MCFragment::FT_CVInlineLines:
543+
case MCFragment::FT_CVDefRange:
544+
case MCFragment::FT_PseudoProbe: {
545+
if (F.getKind() == MCFragment::FT_Data)
546+
++stats::EmittedDataFragments;
547+
else if (F.getKind() == MCFragment::FT_Relaxable)
548+
++stats::EmittedRelaxableFragments;
549+
const auto &EF = cast<MCEncodedFragment>(F);
550+
OS << StringRef(EF.getContents().data(), EF.getContents().size());
551+
break;
552+
}
546553
case MCFragment::FT_Align: {
547554
++stats::EmittedAlignFragments;
548555
const MCAlignFragment &AF = cast<MCAlignFragment>(F);
@@ -589,18 +596,6 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
589596
break;
590597
}
591598

592-
case MCFragment::FT_Data:
593-
++stats::EmittedDataFragments;
594-
OS << StringRef(cast<MCDataFragment>(F).getContents().data(),
595-
cast<MCDataFragment>(F).getContents().size());
596-
break;
597-
598-
case MCFragment::FT_Relaxable:
599-
++stats::EmittedRelaxableFragments;
600-
OS << StringRef(cast<MCRelaxableFragment>(F).getContents().data(),
601-
cast<MCRelaxableFragment>(F).getContents().size());
602-
break;
603-
604599
case MCFragment::FT_Fill: {
605600
++stats::EmittedFillFragments;
606601
const MCFillFragment &FF = cast<MCFillFragment>(F);
@@ -676,12 +671,6 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
676671
break;
677672
}
678673

679-
case MCFragment::FT_LEB: {
680-
const MCLEBFragment &LF = cast<MCLEBFragment>(F);
681-
OS << StringRef(LF.getContents().data(), LF.getContents().size());
682-
break;
683-
}
684-
685674
case MCFragment::FT_BoundaryAlign: {
686675
const MCBoundaryAlignFragment &BF = cast<MCBoundaryAlignFragment>(F);
687676
if (!Asm.getBackend().writeNopData(OS, FragmentSize, BF.getSubtargetInfo()))
@@ -706,31 +695,6 @@ static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
706695
break;
707696
}
708697

709-
case MCFragment::FT_Dwarf: {
710-
const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
711-
OS << StringRef(OF.getContents().data(), OF.getContents().size());
712-
break;
713-
}
714-
case MCFragment::FT_DwarfFrame: {
715-
const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F);
716-
OS << StringRef(CF.getContents().data(), CF.getContents().size());
717-
break;
718-
}
719-
case MCFragment::FT_CVInlineLines: {
720-
const auto &OF = cast<MCCVInlineLineTableFragment>(F);
721-
OS << StringRef(OF.getContents().data(), OF.getContents().size());
722-
break;
723-
}
724-
case MCFragment::FT_CVDefRange: {
725-
const auto &DRF = cast<MCCVDefRangeFragment>(F);
726-
OS << StringRef(DRF.getContents().data(), DRF.getContents().size());
727-
break;
728-
}
729-
case MCFragment::FT_PseudoProbe: {
730-
const MCPseudoProbeAddrFragment &PF = cast<MCPseudoProbeAddrFragment>(F);
731-
OS << StringRef(PF.getContents().data(), PF.getContents().size());
732-
break;
733-
}
734698
}
735699

736700
assert(OS.tell() - Start == FragmentSize &&
@@ -831,7 +795,8 @@ void MCAssembler::layout() {
831795
this->HasLayout = true;
832796
for (MCSection &Sec : *this)
833797
layoutSection(Sec);
834-
while (relaxOnce())
798+
unsigned FirstStable = Sections.size();
799+
while ((FirstStable = relaxOnce(FirstStable)) > 0)
835800
if (getContext().hadError())
836801
return;
837802

@@ -1163,31 +1128,36 @@ void MCAssembler::layoutSection(MCSection &Sec) {
11631128
}
11641129
}
11651130

1166-
bool MCAssembler::relaxOnce() {
1131+
unsigned MCAssembler::relaxOnce(unsigned FirstStable) {
11671132
++stats::RelaxationSteps;
11681133
PendingErrors.clear();
11691134

1170-
// Size of fragments in one section can depend on the size of fragments in
1171-
// another. If any fragment has changed size, we have to re-layout (and
1172-
// as a result possibly further relax) all sections.
1173-
bool ChangedAny = false;
1174-
for (MCSection &Sec : *this) {
1135+
unsigned Res = 0;
1136+
for (unsigned I = 0; I != FirstStable; ++I) {
11751137
// Assume each iteration finalizes at least one extra fragment. If the
11761138
// layout does not converge after N+1 iterations, bail out.
1139+
auto &Sec = *Sections[I];
11771140
auto MaxIter = Sec.curFragList()->Tail->getLayoutOrder() + 1;
11781141
for (;;) {
11791142
bool Changed = false;
11801143
for (MCFragment &F : Sec)
11811144
if (relaxFragment(F))
11821145
Changed = true;
11831146

1184-
ChangedAny |= Changed;
1185-
if (!Changed || --MaxIter == 0)
1147+
if (!Changed)
1148+
break;
1149+
// If any fragment changed size, it might impact the layout of subsequent
1150+
// sections. Therefore, we must re-evaluate all sections.
1151+
FirstStable = Sections.size();
1152+
Res = I;
1153+
if (--MaxIter == 0)
11861154
break;
11871155
layoutSection(Sec);
11881156
}
11891157
}
1190-
return ChangedAny;
1158+
// The subsequent relaxOnce call only needs to visit Sections [0,Res) if no
1159+
// change occurred.
1160+
return Res;
11911161
}
11921162

11931163
void MCAssembler::reportError(SMLoc L, const Twine &Msg) const {

llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AArch64AsmBackend : public MCAsmBackend {
6767
// Fixup kinds from raw relocation types and .reloc directives force
6868
// relocations and do not need these fields.
6969
if (mc::isRelocation(Kind))
70-
return MCAsmBackend::getFixupKindInfo(FK_NONE);
70+
return {};
7171

7272
if (Kind < FirstTargetFixupKind)
7373
return MCAsmBackend::getFixupKindInfo(Kind);

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ AArch64MCCodeEmitter::getAddSubImmOpValue(const MCInst &MI, unsigned OpIdx,
303303
const MCExpr *Expr = MO.getExpr();
304304

305305
// Encode the 12 bits of the fixup.
306-
MCFixupKind Kind = MCFixupKind(AArch64::fixup_aarch64_add_imm12);
306+
MCFixupKind Kind = AArch64::fixup_aarch64_add_imm12;
307307
addFixup(Fixups, 0, Expr, Kind);
308308

309309
++MCNumFixups;
@@ -413,8 +413,8 @@ AArch64MCCodeEmitter::getMoveWideImmOpValue(const MCInst &MI, unsigned OpIdx,
413413
return MO.getImm();
414414
assert(MO.isExpr() && "Unexpected movz/movk immediate");
415415

416-
Fixups.push_back(MCFixup::create(0, MO.getExpr(),
417-
MCFixupKind(AArch64::fixup_aarch64_movw)));
416+
Fixups.push_back(
417+
MCFixup::create(0, MO.getExpr(), AArch64::fixup_aarch64_movw));
418418

419419
++MCNumFixups;
420420

0 commit comments

Comments
 (0)