Skip to content

Commit 4632ea4

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: Ibcd11a4bcf026ae9244631b875963ea820f2fff5
2 parents 22ff0d6 + 4986510 commit 4632ea4

Some content is hidden

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

45 files changed

+4030
-2178
lines changed

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,13 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
284284
if (!RD->isCompleteDefinition())
285285
return nullptr;
286286

287-
// Deduplicate records.
288-
if (auto It = Records.find(RD); It != Records.end())
287+
// Return an existing record if available. Otherwise, we insert nullptr now
288+
// and replace that later, so recursive calls to this function with the same
289+
// RecordDecl don't run into infinite recursion.
290+
auto [It, Inserted] = Records.try_emplace(RD);
291+
if (!Inserted)
289292
return It->second;
290293

291-
// We insert nullptr now and replace that later, so recursive calls
292-
// to this function with the same RecordDecl don't run into
293-
// infinite recursion.
294-
Records.insert({RD, nullptr});
295-
296294
// Number of bytes required by fields and base classes.
297295
unsigned BaseSize = 0;
298296
// Number of bytes required by virtual base.

clang/lib/StaticAnalyzer/Core/CheckerManager.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@ void CheckerManager::runCheckersOnASTDecl(const Decl *D, AnalysisManager& mgr,
6666
assert(D);
6767

6868
unsigned DeclKind = D->getKind();
69-
CachedDeclCheckers *checkers = nullptr;
70-
CachedDeclCheckersMapTy::iterator CCI = CachedDeclCheckersMap.find(DeclKind);
71-
if (CCI != CachedDeclCheckersMap.end()) {
72-
checkers = &(CCI->second);
73-
} else {
69+
auto [CCI, Inserted] = CachedDeclCheckersMap.try_emplace(DeclKind);
70+
CachedDeclCheckers *checkers = &(CCI->second);
71+
if (Inserted) {
7472
// Find the checkers that should run for this Decl and cache them.
75-
checkers = &CachedDeclCheckersMap[DeclKind];
7673
for (const auto &info : DeclCheckers)
7774
if (info.IsForDeclFn(D))
7875
checkers->push_back(info.CheckFn);
@@ -896,14 +893,13 @@ CheckerManager::getCachedStmtCheckersFor(const Stmt *S, bool isPreVisit) {
896893
assert(S);
897894

898895
unsigned Key = (S->getStmtClass() << 1) | unsigned(isPreVisit);
899-
CachedStmtCheckersMapTy::iterator CCI = CachedStmtCheckersMap.find(Key);
900-
if (CCI != CachedStmtCheckersMap.end())
901-
return CCI->second;
902-
903-
// Find the checkers that should run for this Stmt and cache them.
904-
CachedStmtCheckers &Checkers = CachedStmtCheckersMap[Key];
905-
for (const auto &Info : StmtCheckers)
906-
if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
907-
Checkers.push_back(Info.CheckFn);
896+
auto [CCI, Inserted] = CachedStmtCheckersMap.try_emplace(Key);
897+
CachedStmtCheckers &Checkers = CCI->second;
898+
if (Inserted) {
899+
// Find the checkers that should run for this Stmt and cache them.
900+
for (const auto &Info : StmtCheckers)
901+
if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
902+
Checkers.push_back(Info.CheckFn);
903+
}
908904
return Checkers;
909905
}

libc/newhdrgen/yaml/gpu/rpc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ functions:
1616
- name: rpc_host_call
1717
standards:
1818
- GPUExtensions
19-
return_type: void
19+
return_type: unsigned long long
2020
arguments:
2121
- type: void *
2222
- type: void *

libc/spec/gpu_ext.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def GPUExtensions : StandardSpec<"GPUExtensions"> {
77
[
88
FunctionSpec<
99
"rpc_host_call",
10-
RetValSpec<VoidType>,
10+
RetValSpec<UnsignedLongLongType>,
1111
[ArgSpec<VoidPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
1212
>,
1313
]

libc/src/gpu/rpc_host_call.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ namespace LIBC_NAMESPACE_DECL {
1717

1818
// This calls the associated function pointer on the RPC server with the given
1919
// arguments. We expect that the pointer here is a valid pointer on the server.
20-
LLVM_LIBC_FUNCTION(void, rpc_host_call, (void *fn, void *data, size_t size)) {
20+
LLVM_LIBC_FUNCTION(unsigned long long, rpc_host_call,
21+
(void *fn, void *data, size_t size)) {
2122
rpc::Client::Port port = rpc::client.open<RPC_HOST_CALL>();
2223
port.send_n(data, size);
2324
port.send([=](rpc::Buffer *buffer) {
2425
buffer->data[0] = reinterpret_cast<uintptr_t>(fn);
2526
});
26-
port.recv([](rpc::Buffer *) {});
27+
unsigned long long ret;
28+
port.recv([&](rpc::Buffer *buffer) {
29+
ret = static_cast<unsigned long long>(buffer->data[0]);
30+
});
2731
port.close();
32+
return ret;
2833
}
2934

3035
} // namespace LIBC_NAMESPACE_DECL

libc/src/gpu/rpc_host_call.h

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

1515
namespace LIBC_NAMESPACE_DECL {
1616

17-
void rpc_host_call(void *fn, void *buffer, size_t size);
17+
unsigned long long rpc_host_call(void *fn, void *buffer, size_t size);
1818

1919
} // namespace LIBC_NAMESPACE_DECL
2020

libc/src/string/memory_utils/aarch64/inline_memcmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H
99
#define LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H
1010

11-
#include "src/__support/macros/config.h" // LIBC_INLINE
11+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1212
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1313
#include "src/string/memory_utils/op_aarch64.h"
1414
#include "src/string/memory_utils/op_generic.h"

libc/src/string/memory_utils/aarch64/inline_memcpy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMCPY_H
99
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMCPY_H
1010

11-
#include "src/__support/macros/config.h" // LIBC_INLINE
11+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1212
#include "src/string/memory_utils/op_builtin.h"
1313
#include "src/string/memory_utils/utils.h"
1414

libc/src/string/memory_utils/aarch64/inline_memmove.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMMOVE_H
99
#define LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMMOVE_H
1010

11-
#include "src/__support/macros/config.h" // LIBC_INLINE
11+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1212
#include "src/string/memory_utils/op_aarch64.h" // aarch64::kNeon
1313
#include "src/string/memory_utils/op_builtin.h"
1414
#include "src/string/memory_utils/op_generic.h"

libc/src/string/memory_utils/generic/aligned_access.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_ALIGNED_ACCESS_H
1414
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_ALIGNED_ACCESS_H
1515

16-
#include "src/__support/macros/config.h" // LIBC_INLINE
16+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1717
#include "src/string/memory_utils/generic/byte_per_byte.h"
1818
#include "src/string/memory_utils/op_generic.h" // generic::splat
1919
#include "src/string/memory_utils/utils.h" // Ptr, CPtr

libc/src/string/memory_utils/generic/byte_per_byte.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BYTE_PER_BYTE_H
1313
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BYTE_PER_BYTE_H
1414

15-
#include "src/__support/macros/config.h" // LIBC_INLINE
15+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1616
#include "src/__support/macros/optimization.h" // LIBC_LOOP_NOUNROLL
1717
#include "src/string/memory_utils/utils.h" // Ptr, CPtr
1818

libc/src/string/memory_utils/inline_memcmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCMP_H
1010
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCMP_H
1111

12-
#include "src/__support/macros/config.h" // LIBC_INLINE
12+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1313
#include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_
1414
#include "src/string/memory_utils/utils.h" // Ptr, CPtr
1515

libc/src/string/memory_utils/inline_memcpy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCPY_H
1010
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCPY_H
1111

12-
#include "src/__support/macros/config.h" // LIBC_INLINE
12+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1313
#include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_
1414
#include "src/string/memory_utils/utils.h" // Ptr, CPtr
1515

libc/src/string/memory_utils/inline_memset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMSET_H
1010
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMSET_H
1111

12-
#include "src/__support/macros/config.h" // LIBC_INLINE
12+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1313
#include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_
1414
#include "src/string/memory_utils/utils.h" // Ptr, CPtr
1515

libc/src/string/memory_utils/x86_64/inline_memcmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H
1010
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H
1111

12-
#include "src/__support/macros/config.h" // LIBC_INLINE
12+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1313
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1414
#include "src/string/memory_utils/op_generic.h"
1515
#include "src/string/memory_utils/op_x86.h"

libc/src/string/memory_utils/x86_64/inline_memcpy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCPY_H
1010

1111
#include "src/__support/macros/attributes.h" // LIBC_INLINE_VAR
12-
#include "src/__support/macros/config.h" // LIBC_INLINE
1312
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1413
#include "src/string/memory_utils/op_builtin.h"
1514
#include "src/string/memory_utils/op_x86.h"

libc/src/string/memory_utils/x86_64/inline_memmove.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMMOVE_H
99
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMMOVE_H
1010

11-
#include "src/__support/macros/config.h" // LIBC_INLINE
11+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1212
#include "src/string/memory_utils/op_builtin.h"
1313
#include "src/string/memory_utils/op_generic.h"
1414
#include "src/string/memory_utils/op_x86.h"

libc/utils/gpu/server/rpc_server.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,18 @@ rpc_status_t handle_server_impl(
319319
}
320320
case RPC_HOST_CALL: {
321321
uint64_t sizes[lane_size] = {0};
322+
unsigned long long results[lane_size] = {0};
322323
void *args[lane_size] = {nullptr};
323324
port->recv_n(args, sizes,
324325
[&](uint64_t size) { return temp_storage.alloc(size); });
325326
port->recv([&](rpc::Buffer *buffer, uint32_t id) {
326-
reinterpret_cast<void (*)(void *)>(buffer->data[0])(args[id]);
327+
using func_ptr_t = unsigned long long (*)(void *);
328+
auto func = reinterpret_cast<func_ptr_t>(buffer->data[0]);
329+
results[id] = func(args[id]);
330+
});
331+
port->send([&](rpc::Buffer *buffer, uint32_t id) {
332+
buffer->data[0] = static_cast<uint64_t>(results[id]);
327333
});
328-
port->send([&](rpc::Buffer *, uint32_t id) {});
329334
break;
330335
}
331336
case RPC_FEOF: {

libcxx/test/benchmarks/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ set(BENCHMARK_TESTS
147147
deque_iterator.bench.cpp
148148
exception_ptr.bench.cpp
149149
filesystem.bench.cpp
150+
format/write_double_comparison.bench.cpp
151+
format/write_int_comparison.bench.cpp
152+
format/write_string_comparison.bench.cpp
150153
format_to_n.bench.cpp
151154
format_to.bench.cpp
152155
format.bench.cpp

libcxx/test/benchmarks/format.bench.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ static void BM_format_string(benchmark::State& state) {
2020
size_t size = state.range(0);
2121
std::basic_string<CharT> str(size, CharT('*'));
2222

23-
while (state.KeepRunningBatch(str.size()))
24-
benchmark::DoNotOptimize(std::format(CSTR("{}"), str));
23+
while (state.KeepRunningBatch(str.size())) {
24+
std::basic_string<CharT> s = std::format(CSTR("{}"), str);
25+
benchmark::DoNotOptimize(s);
26+
}
2527

2628
state.SetBytesProcessed(state.iterations() * size * sizeof(CharT));
2729
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <array>
10+
#include <charconv>
11+
#include <cstdio>
12+
#include <format>
13+
#include <iterator>
14+
#include <list>
15+
#include <random>
16+
#include <vector>
17+
18+
#include "benchmark/benchmark.h"
19+
20+
std::array data = [] {
21+
std::uniform_real_distribution<double> distribution;
22+
std::mt19937 generator;
23+
std::array<double, 1000> result;
24+
std::generate_n(result.begin(), result.size(), [&] { return distribution(generator); });
25+
return result;
26+
}();
27+
28+
static void BM_sprintf(benchmark::State& state) {
29+
std::array<char, 100> output;
30+
while (state.KeepRunningBatch(data.size()))
31+
for (auto value : data) {
32+
sprintf(output.data(), "%f", value);
33+
benchmark::DoNotOptimize(output.data());
34+
}
35+
}
36+
37+
static void BM_to_string(benchmark::State& state) {
38+
while (state.KeepRunningBatch(data.size()))
39+
for (auto value : data) {
40+
std::string s = std::to_string(value);
41+
benchmark::DoNotOptimize(s);
42+
}
43+
}
44+
45+
static void BM_to_chars(benchmark::State& state) {
46+
std::array<char, 100> output;
47+
48+
while (state.KeepRunningBatch(data.size()))
49+
for (auto value : data) {
50+
std::to_chars(output.data(), output.data() + output.size(), value);
51+
benchmark::DoNotOptimize(output.data());
52+
}
53+
}
54+
55+
static void BM_to_chars_as_string(benchmark::State& state) {
56+
std::array<char, 100> output;
57+
58+
while (state.KeepRunningBatch(data.size()))
59+
for (auto value : data) {
60+
char* end = std::to_chars(output.data(), output.data() + output.size(), value).ptr;
61+
std::string s{output.data(), end};
62+
benchmark::DoNotOptimize(s);
63+
}
64+
}
65+
66+
static void BM_format(benchmark::State& state) {
67+
while (state.KeepRunningBatch(data.size()))
68+
for (auto value : data) {
69+
std::string s = std::format("{}", value);
70+
benchmark::DoNotOptimize(s);
71+
}
72+
}
73+
74+
template <class C>
75+
static void BM_format_to_back_inserter(benchmark::State& state) {
76+
while (state.KeepRunningBatch(data.size()))
77+
for (auto value : data) {
78+
C c;
79+
std::format_to(std::back_inserter(c), "{}", value);
80+
benchmark::DoNotOptimize(c);
81+
}
82+
}
83+
84+
template <class F>
85+
static void BM_format_to_iterator(benchmark::State& state, F&& f) {
86+
auto output = f();
87+
while (state.KeepRunningBatch(data.size()))
88+
for (auto value : data) {
89+
std::format_to(std::begin(output), "{}", value);
90+
benchmark::DoNotOptimize(std::begin(output));
91+
}
92+
}
93+
94+
BENCHMARK(BM_sprintf);
95+
BENCHMARK(BM_to_string);
96+
BENCHMARK(BM_to_chars);
97+
BENCHMARK(BM_to_chars_as_string);
98+
BENCHMARK(BM_format);
99+
BENCHMARK_TEMPLATE(BM_format_to_back_inserter, std::string);
100+
BENCHMARK_TEMPLATE(BM_format_to_back_inserter, std::vector<char>);
101+
BENCHMARK_TEMPLATE(BM_format_to_back_inserter, std::list<char>);
102+
BENCHMARK_CAPTURE(BM_format_to_iterator, <std::array>, ([] {
103+
std::array<char, 100> a;
104+
return a;
105+
}));
106+
BENCHMARK_CAPTURE(BM_format_to_iterator, <std::string>, ([] {
107+
std::string s;
108+
s.resize(100);
109+
return s;
110+
}));
111+
BENCHMARK_CAPTURE(BM_format_to_iterator, <std::vector>, ([] {
112+
std::vector<char> v;
113+
v.resize(100);
114+
return v;
115+
}));
116+
117+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)