Skip to content

Commit 5e9eb50

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merge upstream LLVM into amd-gfx12
2 parents c9f3a67 + 2b8696b commit 5e9eb50

29 files changed

+897
-639
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CIR_TypedAttr<string name, string attrMnemonic, list<Trait> traits = []>
4242
let assemblyFormat = [{}];
4343
}
4444

45-
class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
45+
class CIR_UnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
4646
: CIR_Attr<name, attrMnemonic, traits> {
4747
let returnType = "bool";
4848
let defaultValue = "false";
@@ -127,7 +127,7 @@ def CIR_BoolAttr : CIR_Attr<"Bool", "bool", [TypedAttrInterface]> {
127127
// ZeroAttr
128128
//===----------------------------------------------------------------------===//
129129

130-
def ZeroAttr : CIR_TypedAttr<"Zero", "zero"> {
130+
def CIR_ZeroAttr : CIR_TypedAttr<"Zero", "zero"> {
131131
let summary = "Attribute to represent zero initialization";
132132
let description = [{
133133
The ZeroAttr is used to indicate zero initialization on structs.
@@ -138,7 +138,7 @@ def ZeroAttr : CIR_TypedAttr<"Zero", "zero"> {
138138
// UndefAttr
139139
//===----------------------------------------------------------------------===//
140140

141-
def UndefAttr : CIR_TypedAttr<"Undef", "undef"> {
141+
def CIR_UndefAttr : CIR_TypedAttr<"Undef", "undef"> {
142142
let summary = "Represent an undef constant";
143143
let description = [{
144144
The UndefAttr represents an undef constant, corresponding to LLVM's notion
@@ -264,7 +264,9 @@ def CIR_FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
264264
// ConstArrayAttr
265265
//===----------------------------------------------------------------------===//
266266

267-
def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [TypedAttrInterface]> {
267+
def CIR_ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [
268+
TypedAttrInterface
269+
]> {
268270
let summary = "A constant array from ArrayAttr or StringRefAttr";
269271
let description = [{
270272
An CIR array attribute is an array of literals of the specified attr types.
@@ -310,8 +312,9 @@ def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [TypedAttrInterface]>
310312
// ConstVectorAttr
311313
//===----------------------------------------------------------------------===//
312314

313-
def ConstVectorAttr : CIR_Attr<"ConstVector", "const_vector",
314-
[TypedAttrInterface]> {
315+
def CIR_ConstVectorAttr : CIR_Attr<"ConstVector", "const_vector", [
316+
TypedAttrInterface
317+
]> {
315318
let summary = "A constant vector from ArrayAttr";
316319
let description = [{
317320
A CIR vector attribute is an array of literals of the specified attribute
@@ -342,7 +345,7 @@ def ConstVectorAttr : CIR_Attr<"ConstVector", "const_vector",
342345
// ConstPtrAttr
343346
//===----------------------------------------------------------------------===//
344347

345-
def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
348+
def CIR_ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
346349
let summary = "Holds a constant pointer value";
347350
let parameters = (ins
348351
AttributeSelfTypeParameter<"", "::cir::PointerType">:$type,
@@ -371,8 +374,9 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
371374
// ConstComplexAttr
372375
//===----------------------------------------------------------------------===//
373376

374-
def ConstComplexAttr : CIR_Attr<"ConstComplex", "const_complex",
375-
[TypedAttrInterface]> {
377+
def CIR_ConstComplexAttr : CIR_Attr<"ConstComplex", "const_complex", [
378+
TypedAttrInterface
379+
]> {
376380
let summary = "An attribute that contains a constant complex value";
377381
let description = [{
378382
The `#cir.const_complex` attribute contains a constant value of complex
@@ -454,7 +458,7 @@ def CIR_VisibilityAttr : CIR_EnumAttr<CIR_VisibilityKind, "visibility"> {
454458
// BitfieldInfoAttr
455459
//===----------------------------------------------------------------------===//
456460

457-
def BitfieldInfoAttr : CIR_Attr<"BitfieldInfo", "bitfield_info"> {
461+
def CIR_BitfieldInfoAttr : CIR_Attr<"BitfieldInfo", "bitfield_info"> {
458462
let summary = "Represents info for a bit-field member";
459463
let description = [{
460464
Holds the following information about bitfields: name, storage type, size
@@ -512,5 +516,4 @@ def BitfieldInfoAttr : CIR_Attr<"BitfieldInfo", "bitfield_info"> {
512516
];
513517
}
514518

515-
516519
#endif // CLANG_CIR_DIALECT_IR_CIRATTRS_TD

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ def CIR_SetBitfieldOp : CIR_Op<"set_bitfield"> {
17471747
let arguments = (ins
17481748
Arg<CIR_PointerType, "the address to store the value", [MemWrite]>:$addr,
17491749
CIR_AnyType:$src,
1750-
BitfieldInfoAttr:$bitfield_info,
1750+
CIR_BitfieldInfoAttr:$bitfield_info,
17511751
DefaultValuedOptionalAttr<I64Attr, "0">:$alignment,
17521752
UnitAttr:$is_volatile
17531753
);
@@ -1834,7 +1834,7 @@ def CIR_GetBitfieldOp : CIR_Op<"get_bitfield"> {
18341834

18351835
let arguments = (ins
18361836
Arg<CIR_PointerType, "the address to load from", [MemRead]>:$addr,
1837-
BitfieldInfoAttr:$bitfield_info,
1837+
CIR_BitfieldInfoAttr:$bitfield_info,
18381838
DefaultValuedOptionalAttr<I64Attr, "0">:$alignment,
18391839
UnitAttr:$is_volatile
18401840
);

compiler-rt/lib/builtins/crtbegin.c

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,33 @@ static void __attribute__((used)) __do_init(void) {
5454
}
5555

5656
#ifdef CRT_HAS_INITFINI_ARRAY
57-
#if __has_feature(ptrauth_init_fini)
57+
# if __has_feature(ptrauth_init_fini)
5858
// TODO: use __ptrauth-qualified pointers when they are supported on clang side
59-
#if __has_feature(ptrauth_init_fini_address_discrimination)
59+
# if __has_feature(ptrauth_init_fini_address_discrimination)
6060
__attribute__((section(".init_array"), used)) static void *__init =
6161
ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
6262
ptrauth_blend_discriminator(
6363
&__init, __ptrauth_init_fini_discriminator));
64-
#else
64+
# else
6565
__attribute__((section(".init_array"), used)) static void *__init =
6666
ptrauth_sign_constant(&__do_init, ptrauth_key_init_fini_pointer,
6767
__ptrauth_init_fini_discriminator);
68-
#endif
69-
#else
68+
# endif
69+
# elif __has_feature(ptrauth_calls)
70+
# ifdef __aarch64__
71+
// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
72+
// pointers in .init_array. Use inline assembly to avoid implicit signing of
73+
// __do_init function pointer with ptrauth_calls enabled.
74+
__asm__(".pushsection .init_array,\"aw\",@init_array\n\t"
75+
".xword __do_init\n\t"
76+
".popsection");
77+
# else
78+
# error "ptrauth_calls is only supported for AArch64"
79+
# endif
80+
# else
7081
__attribute__((section(".init_array"),
7182
used)) static void (*__init)(void) = __do_init;
72-
#endif
83+
# endif
7384
#elif defined(__i386__) || defined(__x86_64__)
7485
__asm__(".pushsection .init,\"ax\",@progbits\n\t"
7586
"call __do_init\n\t"
@@ -125,22 +136,33 @@ static void __attribute__((used)) __do_fini(void) {
125136
}
126137

127138
#ifdef CRT_HAS_INITFINI_ARRAY
128-
#if __has_feature(ptrauth_init_fini)
139+
# if __has_feature(ptrauth_init_fini)
129140
// TODO: use __ptrauth-qualified pointers when they are supported on clang side
130-
#if __has_feature(ptrauth_init_fini_address_discrimination)
141+
# if __has_feature(ptrauth_init_fini_address_discrimination)
131142
__attribute__((section(".fini_array"), used)) static void *__fini =
132143
ptrauth_sign_constant(&__do_fini, ptrauth_key_init_fini_pointer,
133144
ptrauth_blend_discriminator(
134145
&__fini, __ptrauth_init_fini_discriminator));
135-
#else
146+
# else
136147
__attribute__((section(".fini_array"), used)) static void *__fini =
137148
ptrauth_sign_constant(&__do_fini, ptrauth_key_init_fini_pointer,
138149
__ptrauth_init_fini_discriminator);
139-
#endif
140-
#else
150+
# endif
151+
# elif __has_feature(ptrauth_calls)
152+
# ifdef __aarch64__
153+
// If ptrauth_init_fini feature is not present, compiler emits raw unsigned
154+
// pointers in .fini_array. Use inline assembly to avoid implicit signing of
155+
// __do_fini function pointer with ptrauth_calls enabled.
156+
__asm__(".pushsection .fini_array,\"aw\",@fini_array\n\t"
157+
".xword __do_fini\n\t"
158+
".popsection");
159+
# else
160+
# error "ptrauth_calls is only supported for AArch64"
161+
# endif
162+
# else
141163
__attribute__((section(".fini_array"),
142164
used)) static void (*__fini)(void) = __do_fini;
143-
#endif
165+
# endif
144166
#elif defined(__i386__) || defined(__x86_64__)
145167
__asm__(".pushsection .fini,\"ax\",@progbits\n\t"
146168
"call __do_fini\n\t"

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class MCObjectStreamer : public MCStreamer {
5252
DenseMap<const MCSymbol *, SmallVector<PendingAssignment, 1>>
5353
pendingAssignments;
5454

55+
SmallVector<std::unique_ptr<char[]>, 0> FragStorage;
56+
// Available bytes in the current block for trailing data or new fragments.
57+
size_t FragSpace = 0;
58+
5559
void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &);
5660
void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
5761
void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
@@ -84,11 +88,18 @@ class MCObjectStreamer : public MCStreamer {
8488
// Add a fragment with a variable-size tail and start a new empty fragment.
8589
void insert(MCFragment *F);
8690

91+
char *getCurFragEnd() const {
92+
return reinterpret_cast<char *>(CurFrag + 1) + CurFrag->getFixedSize();
93+
}
94+
MCFragment *allocFragSpace(size_t Headroom);
8795
// Add a new fragment to the current section without a variable-size tail.
8896
void newFragment();
8997

98+
void ensureHeadroom(size_t Headroom);
9099
void appendContents(ArrayRef<char> Contents);
91100
void appendContents(size_t Num, char Elt);
101+
// Add a fixup to the current fragment. Call ensureHeadroom beforehand to
102+
// ensure the fixup and appended content apply to the same fragment.
92103
void addFixup(const MCExpr *Value, MCFixupKind Kind);
93104

94105
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;

llvm/include/llvm/MC/MCSection.h

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ class MCFragment {
9393
// Track content and fixups for the fixed-size part as fragments are
9494
// appended to the section. The content remains immutable, except when
9595
// modified by applyFixup.
96-
uint32_t ContentStart = 0;
97-
uint32_t ContentEnd = 0;
96+
uint32_t FixedSize = 0;
9897
uint32_t FixupStart = 0;
9998
uint32_t FixupEnd = 0;
10099

@@ -205,18 +204,6 @@ class MCFragment {
205204
//== Content-related functions manage parent's storage using ContentStart and
206205
// ContentSize.
207206

208-
// Get a SmallVector reference. The caller should call doneAppending to update
209-
// `ContentEnd`.
210-
SmallVectorImpl<char> &getContentsForAppending();
211-
void doneAppending();
212-
void appendContents(ArrayRef<char> Contents) {
213-
getContentsForAppending().append(Contents.begin(), Contents.end());
214-
doneAppending();
215-
}
216-
void appendContents(size_t Num, char Elt) {
217-
getContentsForAppending().append(Num, Elt);
218-
doneAppending();
219-
}
220207
MutableArrayRef<char> getContents();
221208
ArrayRef<char> getContents() const;
222209

@@ -225,10 +212,10 @@ class MCFragment {
225212
MutableArrayRef<char> getVarContents();
226213
ArrayRef<char> getVarContents() const;
227214

228-
size_t getFixedSize() const { return ContentEnd - ContentStart; }
215+
size_t getFixedSize() const { return FixedSize; }
229216
size_t getVarSize() const { return VarContentEnd - VarContentStart; }
230217
size_t getSize() const {
231-
return ContentEnd - ContentStart + (VarContentEnd - VarContentStart);
218+
return FixedSize + (VarContentEnd - VarContentStart);
232219
}
233220

234221
//== Fixup-related functions manage parent's storage using FixupStart and
@@ -651,28 +638,11 @@ class LLVM_ABI MCSection {
651638
bool isBssSection() const { return IsBss; }
652639
};
653640

654-
inline SmallVectorImpl<char> &MCFragment::getContentsForAppending() {
655-
SmallVectorImpl<char> &S = getParent()->ContentStorage;
656-
if (LLVM_UNLIKELY(ContentEnd != S.size())) {
657-
// Move the elements to the end. Reserve space to avoid invalidating
658-
// S.begin()+I for `append`.
659-
auto Size = ContentEnd - ContentStart;
660-
auto I = std::exchange(ContentStart, S.size());
661-
S.reserve(S.size() + Size);
662-
S.append(S.begin() + I, S.begin() + I + Size);
663-
}
664-
return S;
665-
}
666-
inline void MCFragment::doneAppending() {
667-
ContentEnd = getParent()->ContentStorage.size();
668-
}
669641
inline MutableArrayRef<char> MCFragment::getContents() {
670-
return MutableArrayRef(getParent()->ContentStorage)
671-
.slice(ContentStart, ContentEnd - ContentStart);
642+
return {reinterpret_cast<char *>(this + 1), FixedSize};
672643
}
673644
inline ArrayRef<char> MCFragment::getContents() const {
674-
return ArrayRef(getParent()->ContentStorage)
675-
.slice(ContentStart, ContentEnd - ContentStart);
645+
return {reinterpret_cast<const char *>(this + 1), FixedSize};
676646
}
677647

678648
inline MutableArrayRef<char> MCFragment::getVarContents() {

0 commit comments

Comments
 (0)