Skip to content

Commit 0632a35

Browse files
authored
Merge branch 'llvm:main' into main
2 parents dae725e + 5b51d45 commit 0632a35

File tree

9 files changed

+79
-33
lines changed

9 files changed

+79
-33
lines changed

bolt/include/bolt/Profile/BoltAddressTranslation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class BoltAddressTranslation {
111111
/// addresses when aggregating profile
112112
bool enabledFor(llvm::object::ELFObjectFileBase *InputFile) const;
113113

114+
/// Save function and basic block hashes used for metadata dump.
115+
void saveMetadata(BinaryContext &BC);
116+
114117
private:
115118
/// Helper to update \p Map by inserting one or more BAT entries reflecting
116119
/// \p BB for function located at \p FuncAddress. At least one entry will be
@@ -140,6 +143,9 @@ class BoltAddressTranslation {
140143

141144
std::map<uint64_t, MapTy> Maps;
142145

146+
using BBHashMap = std::unordered_map<uint32_t, size_t>;
147+
std::unordered_map<uint64_t, std::pair<size_t, BBHashMap>> FuncHashes;
148+
143149
/// Links outlined cold bocks to their original function
144150
std::map<uint64_t, uint64_t> ColdPartSource;
145151

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,5 +424,20 @@ bool BoltAddressTranslation::enabledFor(
424424
}
425425
return false;
426426
}
427+
428+
void BoltAddressTranslation::saveMetadata(BinaryContext &BC) {
429+
for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
430+
// We don't need a translation table if the body of the function hasn't
431+
// changed
432+
if (BF.isIgnored() || (!BC.HasRelocations && !BF.isSimple()))
433+
continue;
434+
// Prepare function and block hashes
435+
FuncHashes[BF.getAddress()].first = BF.computeHash();
436+
BF.computeBlockHashes();
437+
for (const BinaryBasicBlock &BB : BF)
438+
FuncHashes[BF.getAddress()].second.emplace(BB.getInputOffset(),
439+
BB.getHash());
440+
}
441+
}
427442
} // namespace bolt
428443
} // namespace llvm

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ Error RewriteInstance::run() {
748748

749749
processProfileData();
750750

751+
// Save input binary metadata if BAT section needs to be emitted
752+
if (opts::EnableBAT)
753+
BAT->saveMetadata(*BC);
754+
751755
postProcessFunctions();
752756

753757
processMetadataPostCFG();

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ template <size_t Bits> struct DyadicFloat {
3737
int exponent = 0;
3838
MantissaType mantissa = MantissaType(0);
3939

40-
constexpr DyadicFloat() = default;
40+
LIBC_INLINE constexpr DyadicFloat() = default;
4141

4242
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
43-
DyadicFloat(T x) {
43+
LIBC_INLINE constexpr DyadicFloat(T x) {
4444
static_assert(FPBits<T>::FRACTION_LEN < Bits);
4545
FPBits<T> x_bits(x);
4646
sign = x_bits.sign();
@@ -49,14 +49,14 @@ template <size_t Bits> struct DyadicFloat {
4949
normalize();
5050
}
5151

52-
constexpr DyadicFloat(Sign s, int e, MantissaType m)
52+
LIBC_INLINE constexpr DyadicFloat(Sign s, int e, MantissaType m)
5353
: sign(s), exponent(e), mantissa(m) {
5454
normalize();
5555
}
5656

5757
// Normalizing the mantissa, bringing the leading 1 bit to the most
5858
// significant bit.
59-
constexpr DyadicFloat &normalize() {
59+
LIBC_INLINE constexpr DyadicFloat &normalize() {
6060
if (!mantissa.is_zero()) {
6161
int shift_length = static_cast<int>(mantissa.clz());
6262
exponent -= shift_length;
@@ -66,14 +66,14 @@ template <size_t Bits> struct DyadicFloat {
6666
}
6767

6868
// Used for aligning exponents. Output might not be normalized.
69-
DyadicFloat &shift_left(int shift_length) {
69+
LIBC_INLINE constexpr DyadicFloat &shift_left(int shift_length) {
7070
exponent -= shift_length;
7171
mantissa <<= static_cast<size_t>(shift_length);
7272
return *this;
7373
}
7474

7575
// Used for aligning exponents. Output might not be normalized.
76-
DyadicFloat &shift_right(int shift_length) {
76+
LIBC_INLINE constexpr DyadicFloat &shift_right(int shift_length) {
7777
exponent += shift_length;
7878
mantissa >>= static_cast<size_t>(shift_length);
7979
return *this;
@@ -85,7 +85,7 @@ template <size_t Bits> struct DyadicFloat {
8585
typename = cpp::enable_if_t<cpp::is_floating_point_v<T> &&
8686
(FPBits<T>::FRACTION_LEN < Bits),
8787
void>>
88-
explicit operator T() const {
88+
LIBC_INLINE explicit constexpr operator T() const {
8989
if (LIBC_UNLIKELY(mantissa.is_zero()))
9090
return FPBits<T>::zero(sign).get_val();
9191

@@ -176,7 +176,7 @@ template <size_t Bits> struct DyadicFloat {
176176
return r;
177177
}
178178

179-
explicit operator MantissaType() const {
179+
LIBC_INLINE explicit constexpr operator MantissaType() const {
180180
if (mantissa.is_zero())
181181
return 0;
182182

@@ -208,8 +208,8 @@ template <size_t Bits> struct DyadicFloat {
208208
// don't need to normalize the inputs again in this function. If the inputs are
209209
// not normalized, the results might lose precision significantly.
210210
template <size_t Bits>
211-
constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
212-
DyadicFloat<Bits> b) {
211+
LIBC_INLINE constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
212+
DyadicFloat<Bits> b) {
213213
if (LIBC_UNLIKELY(a.mantissa.is_zero()))
214214
return b;
215215
if (LIBC_UNLIKELY(b.mantissa.is_zero()))
@@ -263,8 +263,8 @@ constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
263263
// don't need to normalize the inputs again in this function. If the inputs are
264264
// not normalized, the results might lose precision significantly.
265265
template <size_t Bits>
266-
constexpr DyadicFloat<Bits> quick_mul(DyadicFloat<Bits> a,
267-
DyadicFloat<Bits> b) {
266+
LIBC_INLINE constexpr DyadicFloat<Bits> quick_mul(DyadicFloat<Bits> a,
267+
DyadicFloat<Bits> b) {
268268
DyadicFloat<Bits> result;
269269
result.sign = (a.sign != b.sign) ? Sign::NEG : Sign::POS;
270270
result.exponent = a.exponent + b.exponent + int(Bits);
@@ -285,16 +285,17 @@ constexpr DyadicFloat<Bits> quick_mul(DyadicFloat<Bits> a,
285285

286286
// Simple polynomial approximation.
287287
template <size_t Bits>
288-
constexpr DyadicFloat<Bits> multiply_add(const DyadicFloat<Bits> &a,
289-
const DyadicFloat<Bits> &b,
290-
const DyadicFloat<Bits> &c) {
288+
LIBC_INLINE constexpr DyadicFloat<Bits>
289+
multiply_add(const DyadicFloat<Bits> &a, const DyadicFloat<Bits> &b,
290+
const DyadicFloat<Bits> &c) {
291291
return quick_add(c, quick_mul(a, b));
292292
}
293293

294294
// Simple exponentiation implementation for printf. Only handles positive
295295
// exponents, since division isn't implemented.
296296
template <size_t Bits>
297-
constexpr DyadicFloat<Bits> pow_n(DyadicFloat<Bits> a, uint32_t power) {
297+
LIBC_INLINE constexpr DyadicFloat<Bits> pow_n(DyadicFloat<Bits> a,
298+
uint32_t power) {
298299
DyadicFloat<Bits> result = 1.0;
299300
DyadicFloat<Bits> cur_power = a;
300301

@@ -309,7 +310,8 @@ constexpr DyadicFloat<Bits> pow_n(DyadicFloat<Bits> a, uint32_t power) {
309310
}
310311

311312
template <size_t Bits>
312-
constexpr DyadicFloat<Bits> mul_pow_2(DyadicFloat<Bits> a, int32_t pow_2) {
313+
LIBC_INLINE constexpr DyadicFloat<Bits> mul_pow_2(DyadicFloat<Bits> a,
314+
int32_t pow_2) {
313315
DyadicFloat<Bits> result = a;
314316
result.exponent += pow_2;
315317
return result;

libc/src/__support/UInt.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ struct BigInt {
157157

158158
LIBC_INLINE constexpr explicit operator bool() const { return !is_zero(); }
159159

160-
LIBC_INLINE BigInt &operator=(const BigInt &other) = default;
160+
LIBC_INLINE constexpr BigInt &operator=(const BigInt &other) = default;
161161

162162
LIBC_INLINE constexpr bool is_zero() const {
163163
for (size_t i = 0; i < WORD_COUNT; ++i) {
@@ -172,7 +172,7 @@ struct BigInt {
172172
LIBC_INLINE constexpr WordType add(const BigInt &x) {
173173
SumCarry<WordType> s{0, 0};
174174
for (size_t i = 0; i < WORD_COUNT; ++i) {
175-
s = add_with_carry_const(val[i], x.val[i], s.carry);
175+
s = add_with_carry(val[i], x.val[i], s.carry);
176176
val[i] = s.sum;
177177
}
178178
return s.carry;
@@ -194,7 +194,7 @@ struct BigInt {
194194
BigInt result;
195195
SumCarry<WordType> s{0, 0};
196196
for (size_t i = 0; i < WORD_COUNT; ++i) {
197-
s = add_with_carry_const(val[i], other.val[i], s.carry);
197+
s = add_with_carry(val[i], other.val[i], s.carry);
198198
result.val[i] = s.sum;
199199
}
200200
return result;
@@ -210,7 +210,7 @@ struct BigInt {
210210
LIBC_INLINE constexpr WordType sub(const BigInt &x) {
211211
DiffBorrow<WordType> d{0, 0};
212212
for (size_t i = 0; i < WORD_COUNT; ++i) {
213-
d = sub_with_borrow_const(val[i], x.val[i], d.borrow);
213+
d = sub_with_borrow(val[i], x.val[i], d.borrow);
214214
val[i] = d.diff;
215215
}
216216
return d.borrow;
@@ -230,7 +230,7 @@ struct BigInt {
230230
BigInt result;
231231
DiffBorrow<WordType> d{0, 0};
232232
for (size_t i = 0; i < WORD_COUNT; ++i) {
233-
d = sub_with_borrow_const(val[i], other.val[i], d.borrow);
233+
d = sub_with_borrow(val[i], other.val[i], d.borrow);
234234
result.val[i] = d.diff;
235235
}
236236
return result;

libc/src/__support/integer_utils.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace LIBC_NAMESPACE {
2121

22-
template <typename T> NumberPair<T> full_mul(T a, T b) {
22+
template <typename T> constexpr NumberPair<T> full_mul(T a, T b) {
2323
NumberPair<T> pa = split(a);
2424
NumberPair<T> pb = split(b);
2525
NumberPair<T> prod;
@@ -43,7 +43,8 @@ template <typename T> NumberPair<T> full_mul(T a, T b) {
4343
}
4444

4545
template <>
46-
LIBC_INLINE NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a, uint32_t b) {
46+
LIBC_INLINE constexpr NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a,
47+
uint32_t b) {
4748
uint64_t prod = uint64_t(a) * uint64_t(b);
4849
NumberPair<uint32_t> result;
4950
result.lo = uint32_t(prod);
@@ -53,7 +54,8 @@ LIBC_INLINE NumberPair<uint32_t> full_mul<uint32_t>(uint32_t a, uint32_t b) {
5354

5455
#ifdef __SIZEOF_INT128__
5556
template <>
56-
LIBC_INLINE NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a, uint64_t b) {
57+
LIBC_INLINE constexpr NumberPair<uint64_t> full_mul<uint64_t>(uint64_t a,
58+
uint64_t b) {
5759
__uint128_t prod = __uint128_t(a) * __uint128_t(b);
5860
NumberPair<uint64_t> result;
5961
result.lo = uint64_t(prod);

libc/src/__support/number_pair.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
namespace LIBC_NAMESPACE {
1717

1818
template <typename T> struct NumberPair {
19-
T lo;
20-
T hi;
19+
T lo = T(0);
20+
T hi = T(0);
2121
};
2222

2323
template <typename T>

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,21 +635,22 @@ static SmallString<128>
635635
getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
636636
Mangler &Mang, const TargetMachine &TM,
637637
unsigned EntrySize, bool UniqueSectionName) {
638-
SmallString<128> Name;
638+
SmallString<128> Name =
639+
getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
639640
if (Kind.isMergeableCString()) {
640641
// We also need alignment here.
641642
// FIXME: this is getting the alignment of the character, not the
642643
// alignment of the global!
643644
Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
644645
cast<GlobalVariable>(GO));
645646

646-
std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
647-
Name = SizeSpec + utostr(Alignment.value());
647+
Name += ".str";
648+
Name += utostr(EntrySize);
649+
Name += ".";
650+
Name += utostr(Alignment.value());
648651
} else if (Kind.isMergeableConst()) {
649-
Name = ".rodata.cst";
652+
Name += ".cst";
650653
Name += utostr(EntrySize);
651-
} else {
652-
Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
653654
}
654655

655656
bool HasPrefix = false;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -large-data-threshold=0 -o %t
2+
; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE
3+
; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -large-data-threshold=99 -o %t
4+
; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL
5+
6+
; LARGE: .lrodata.str4.4 {{.*}} AMSl
7+
; LARGE: .lrodata.cst8 {{.*}} AMl
8+
9+
; SMALL: .rodata.str4.4 {{.*}} AMS
10+
; SMALL: .rodata.cst8 {{.*}} AM
11+
12+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
13+
target triple = "x86_64--linux"
14+
15+
@str = internal unnamed_addr constant [3 x i32] [i32 1, i32 2, i32 0]
16+
@merge = internal unnamed_addr constant i64 2

0 commit comments

Comments
 (0)