Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
Change-Id: Ibcd11a4bcf026ae9244631b875963ea820f2fff5
  • Loading branch information
Jenkins committed Oct 6, 2024
2 parents 22ff0d6 + 4986510 commit 4632ea4
Show file tree
Hide file tree
Showing 45 changed files with 4,030 additions and 2,178 deletions.
12 changes: 5 additions & 7 deletions clang/lib/AST/ByteCode/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,13 @@ Record *Program::getOrCreateRecord(const RecordDecl *RD) {
if (!RD->isCompleteDefinition())
return nullptr;

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

// We insert nullptr now and replace that later, so recursive calls
// to this function with the same RecordDecl don't run into
// infinite recursion.
Records.insert({RD, nullptr});

// Number of bytes required by fields and base classes.
unsigned BaseSize = 0;
// Number of bytes required by virtual base.
Expand Down
26 changes: 11 additions & 15 deletions clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,10 @@ void CheckerManager::runCheckersOnASTDecl(const Decl *D, AnalysisManager& mgr,
assert(D);

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

unsigned Key = (S->getStmtClass() << 1) | unsigned(isPreVisit);
CachedStmtCheckersMapTy::iterator CCI = CachedStmtCheckersMap.find(Key);
if (CCI != CachedStmtCheckersMap.end())
return CCI->second;

// Find the checkers that should run for this Stmt and cache them.
CachedStmtCheckers &Checkers = CachedStmtCheckersMap[Key];
for (const auto &Info : StmtCheckers)
if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
Checkers.push_back(Info.CheckFn);
auto [CCI, Inserted] = CachedStmtCheckersMap.try_emplace(Key);
CachedStmtCheckers &Checkers = CCI->second;
if (Inserted) {
// Find the checkers that should run for this Stmt and cache them.
for (const auto &Info : StmtCheckers)
if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
Checkers.push_back(Info.CheckFn);
}
return Checkers;
}
2 changes: 1 addition & 1 deletion libc/newhdrgen/yaml/gpu/rpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ functions:
- name: rpc_host_call
standards:
- GPUExtensions
return_type: void
return_type: unsigned long long
arguments:
- type: void *
- type: void *
Expand Down
2 changes: 1 addition & 1 deletion libc/spec/gpu_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def GPUExtensions : StandardSpec<"GPUExtensions"> {
[
FunctionSpec<
"rpc_host_call",
RetValSpec<VoidType>,
RetValSpec<UnsignedLongLongType>,
[ArgSpec<VoidPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
>,
]
Expand Down
9 changes: 7 additions & 2 deletions libc/src/gpu/rpc_host_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ namespace LIBC_NAMESPACE_DECL {

// This calls the associated function pointer on the RPC server with the given
// arguments. We expect that the pointer here is a valid pointer on the server.
LLVM_LIBC_FUNCTION(void, rpc_host_call, (void *fn, void *data, size_t size)) {
LLVM_LIBC_FUNCTION(unsigned long long, rpc_host_call,
(void *fn, void *data, size_t size)) {
rpc::Client::Port port = rpc::client.open<RPC_HOST_CALL>();
port.send_n(data, size);
port.send([=](rpc::Buffer *buffer) {
buffer->data[0] = reinterpret_cast<uintptr_t>(fn);
});
port.recv([](rpc::Buffer *) {});
unsigned long long ret;
port.recv([&](rpc::Buffer *buffer) {
ret = static_cast<unsigned long long>(buffer->data[0]);
});
port.close();
return ret;
}

} // namespace LIBC_NAMESPACE_DECL
2 changes: 1 addition & 1 deletion libc/src/gpu/rpc_host_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace LIBC_NAMESPACE_DECL {

void rpc_host_call(void *fn, void *buffer, size_t size);
unsigned long long rpc_host_call(void *fn, void *buffer, size_t size);

} // namespace LIBC_NAMESPACE_DECL

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/aarch64/inline_memcmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H
#define LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/string/memory_utils/op_aarch64.h"
#include "src/string/memory_utils/op_generic.h"
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/aarch64/inline_memcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMCPY_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMCPY_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/utils.h"

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/aarch64/inline_memmove.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMMOVE_H
#define LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMMOVE_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/string/memory_utils/op_aarch64.h" // aarch64::kNeon
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_generic.h"
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/generic/aligned_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_ALIGNED_ACCESS_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_ALIGNED_ACCESS_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/string/memory_utils/generic/byte_per_byte.h"
#include "src/string/memory_utils/op_generic.h" // generic::splat
#include "src/string/memory_utils/utils.h" // Ptr, CPtr
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/generic/byte_per_byte.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BYTE_PER_BYTE_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BYTE_PER_BYTE_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/optimization.h" // LIBC_LOOP_NOUNROLL
#include "src/string/memory_utils/utils.h" // Ptr, CPtr

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/inline_memcmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCMP_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCMP_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_
#include "src/string/memory_utils/utils.h" // Ptr, CPtr

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/inline_memcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCPY_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCPY_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_
#include "src/string/memory_utils/utils.h" // Ptr, CPtr

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/inline_memset.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMSET_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMSET_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_
#include "src/string/memory_utils/utils.h" // Ptr, CPtr

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/x86_64/inline_memcmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/string/memory_utils/op_generic.h"
#include "src/string/memory_utils/op_x86.h"
Expand Down
1 change: 0 additions & 1 deletion libc/src/string/memory_utils/x86_64/inline_memcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCPY_H

#include "src/__support/macros/attributes.h" // LIBC_INLINE_VAR
#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_x86.h"
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/x86_64/inline_memmove.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMMOVE_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMMOVE_H

#include "src/__support/macros/config.h" // LIBC_INLINE
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_generic.h"
#include "src/string/memory_utils/op_x86.h"
Expand Down
9 changes: 7 additions & 2 deletions libc/utils/gpu/server/rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,18 @@ rpc_status_t handle_server_impl(
}
case RPC_HOST_CALL: {
uint64_t sizes[lane_size] = {0};
unsigned long long results[lane_size] = {0};
void *args[lane_size] = {nullptr};
port->recv_n(args, sizes,
[&](uint64_t size) { return temp_storage.alloc(size); });
port->recv([&](rpc::Buffer *buffer, uint32_t id) {
reinterpret_cast<void (*)(void *)>(buffer->data[0])(args[id]);
using func_ptr_t = unsigned long long (*)(void *);
auto func = reinterpret_cast<func_ptr_t>(buffer->data[0]);
results[id] = func(args[id]);
});
port->send([&](rpc::Buffer *buffer, uint32_t id) {
buffer->data[0] = static_cast<uint64_t>(results[id]);
});
port->send([&](rpc::Buffer *, uint32_t id) {});
break;
}
case RPC_FEOF: {
Expand Down
3 changes: 3 additions & 0 deletions libcxx/test/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ set(BENCHMARK_TESTS
deque_iterator.bench.cpp
exception_ptr.bench.cpp
filesystem.bench.cpp
format/write_double_comparison.bench.cpp
format/write_int_comparison.bench.cpp
format/write_string_comparison.bench.cpp
format_to_n.bench.cpp
format_to.bench.cpp
format.bench.cpp
Expand Down
6 changes: 4 additions & 2 deletions libcxx/test/benchmarks/format.bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ static void BM_format_string(benchmark::State& state) {
size_t size = state.range(0);
std::basic_string<CharT> str(size, CharT('*'));

while (state.KeepRunningBatch(str.size()))
benchmark::DoNotOptimize(std::format(CSTR("{}"), str));
while (state.KeepRunningBatch(str.size())) {
std::basic_string<CharT> s = std::format(CSTR("{}"), str);
benchmark::DoNotOptimize(s);
}

state.SetBytesProcessed(state.iterations() * size * sizeof(CharT));
}
Expand Down
117 changes: 117 additions & 0 deletions libcxx/test/benchmarks/format/write_double_comparison.bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <array>
#include <charconv>
#include <cstdio>
#include <format>
#include <iterator>
#include <list>
#include <random>
#include <vector>

#include "benchmark/benchmark.h"

std::array data = [] {
std::uniform_real_distribution<double> distribution;
std::mt19937 generator;
std::array<double, 1000> result;
std::generate_n(result.begin(), result.size(), [&] { return distribution(generator); });
return result;
}();

static void BM_sprintf(benchmark::State& state) {
std::array<char, 100> output;
while (state.KeepRunningBatch(data.size()))
for (auto value : data) {
sprintf(output.data(), "%f", value);
benchmark::DoNotOptimize(output.data());
}
}

static void BM_to_string(benchmark::State& state) {
while (state.KeepRunningBatch(data.size()))
for (auto value : data) {
std::string s = std::to_string(value);
benchmark::DoNotOptimize(s);
}
}

static void BM_to_chars(benchmark::State& state) {
std::array<char, 100> output;

while (state.KeepRunningBatch(data.size()))
for (auto value : data) {
std::to_chars(output.data(), output.data() + output.size(), value);
benchmark::DoNotOptimize(output.data());
}
}

static void BM_to_chars_as_string(benchmark::State& state) {
std::array<char, 100> output;

while (state.KeepRunningBatch(data.size()))
for (auto value : data) {
char* end = std::to_chars(output.data(), output.data() + output.size(), value).ptr;
std::string s{output.data(), end};
benchmark::DoNotOptimize(s);
}
}

static void BM_format(benchmark::State& state) {
while (state.KeepRunningBatch(data.size()))
for (auto value : data) {
std::string s = std::format("{}", value);
benchmark::DoNotOptimize(s);
}
}

template <class C>
static void BM_format_to_back_inserter(benchmark::State& state) {
while (state.KeepRunningBatch(data.size()))
for (auto value : data) {
C c;
std::format_to(std::back_inserter(c), "{}", value);
benchmark::DoNotOptimize(c);
}
}

template <class F>
static void BM_format_to_iterator(benchmark::State& state, F&& f) {
auto output = f();
while (state.KeepRunningBatch(data.size()))
for (auto value : data) {
std::format_to(std::begin(output), "{}", value);
benchmark::DoNotOptimize(std::begin(output));
}
}

BENCHMARK(BM_sprintf);
BENCHMARK(BM_to_string);
BENCHMARK(BM_to_chars);
BENCHMARK(BM_to_chars_as_string);
BENCHMARK(BM_format);
BENCHMARK_TEMPLATE(BM_format_to_back_inserter, std::string);
BENCHMARK_TEMPLATE(BM_format_to_back_inserter, std::vector<char>);
BENCHMARK_TEMPLATE(BM_format_to_back_inserter, std::list<char>);
BENCHMARK_CAPTURE(BM_format_to_iterator, <std::array>, ([] {
std::array<char, 100> a;
return a;
}));
BENCHMARK_CAPTURE(BM_format_to_iterator, <std::string>, ([] {
std::string s;
s.resize(100);
return s;
}));
BENCHMARK_CAPTURE(BM_format_to_iterator, <std::vector>, ([] {
std::vector<char> v;
v.resize(100);
return v;
}));

BENCHMARK_MAIN();
Loading

0 comments on commit 4632ea4

Please sign in to comment.