Skip to content

Commit

Permalink
[libc] Mass replace enclosing namespace (llvm#67032)
Browse files Browse the repository at this point in the history
  • Loading branch information
gchatelet authored Sep 26, 2023
1 parent 7675f54 commit b6bc9d7
Show file tree
Hide file tree
Showing 2,032 changed files with 8,512 additions and 8,336 deletions.
2 changes: 1 addition & 1 deletion libc/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function(add_libc_multi_impl_benchmark name)
get_target_property(entrypoint_object_file ${fq_config_name} "OBJECT_FILE_RAW")
target_link_libraries(${benchmark_name} PUBLIC json ${entrypoint_object_file})
string(TOUPPER ${name} name_upper)
target_compile_definitions(${benchmark_name} PRIVATE "-DLIBC_BENCHMARK_FUNCTION_${name_upper}=__llvm_libc::${name}" "-DLIBC_BENCHMARK_FUNCTION_NAME=\"${fq_config_name}\"")
target_compile_definitions(${benchmark_name} PRIVATE "-DLIBC_BENCHMARK_FUNCTION_${name_upper}=LIBC_NAMESPACE::${name}" "-DLIBC_BENCHMARK_FUNCTION_NAME=\"${fq_config_name}\"")
llvm_update_compile_flags(${benchmark_name})
else()
message(STATUS "Skipping benchmark for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'")
Expand Down
16 changes: 8 additions & 8 deletions libc/benchmarks/LibcDefaultImplementations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "llvm/ADT/ArrayRef.h"
#include <cstddef>

namespace __llvm_libc {
namespace LIBC_NAMESPACE {

extern void *memcpy(void *__restrict, const void *__restrict, size_t);
extern void *memmove(void *, const void *, size_t);
Expand All @@ -11,7 +11,7 @@ extern void bzero(void *, size_t);
extern int memcmp(const void *, const void *, size_t);
extern int bcmp(const void *, const void *, size_t);

} // namespace __llvm_libc
} // namespace LIBC_NAMESPACE

// List of implementations to test.

Expand All @@ -23,31 +23,31 @@ using llvm::libc_benchmarks::MemsetConfiguration;

llvm::ArrayRef<MemcpyConfiguration> getMemcpyConfigurations() {
static constexpr MemcpyConfiguration kMemcpyConfigurations[] = {
{__llvm_libc::memcpy, "__llvm_libc::memcpy"}};
{LIBC_NAMESPACE::memcpy, "LIBC_NAMESPACE::memcpy"}};
return llvm::ArrayRef(kMemcpyConfigurations);
}
llvm::ArrayRef<MemmoveConfiguration> getMemmoveConfigurations() {
static constexpr MemmoveConfiguration kMemmoveConfigurations[] = {
{__llvm_libc::memmove, "__llvm_libc::memmove"}};
{LIBC_NAMESPACE::memmove, "LIBC_NAMESPACE::memmove"}};
return llvm::ArrayRef(kMemmoveConfigurations);
}
llvm::ArrayRef<MemcmpOrBcmpConfiguration> getMemcmpConfigurations() {
static constexpr MemcmpOrBcmpConfiguration kMemcmpConfiguration[] = {
{__llvm_libc::memcmp, "__llvm_libc::memcmp"}};
{LIBC_NAMESPACE::memcmp, "LIBC_NAMESPACE::memcmp"}};
return llvm::ArrayRef(kMemcmpConfiguration);
}
llvm::ArrayRef<MemcmpOrBcmpConfiguration> getBcmpConfigurations() {
static constexpr MemcmpOrBcmpConfiguration kBcmpConfigurations[] = {
{__llvm_libc::bcmp, "__llvm_libc::bcmp"}};
{LIBC_NAMESPACE::bcmp, "LIBC_NAMESPACE::bcmp"}};
return llvm::ArrayRef(kBcmpConfigurations);
}
llvm::ArrayRef<MemsetConfiguration> getMemsetConfigurations() {
static constexpr MemsetConfiguration kMemsetConfigurations[] = {
{__llvm_libc::memset, "__llvm_libc::memset"}};
{LIBC_NAMESPACE::memset, "LIBC_NAMESPACE::memset"}};
return llvm::ArrayRef(kMemsetConfigurations);
}
llvm::ArrayRef<BzeroConfiguration> getBzeroConfigurations() {
static constexpr BzeroConfiguration kBzeroConfigurations[] = {
{__llvm_libc::bzero, "__llvm_libc::bzero"}};
{LIBC_NAMESPACE::bzero, "LIBC_NAMESPACE::bzero"}};
return llvm::ArrayRef(kBzeroConfigurations);
}
2 changes: 1 addition & 1 deletion libc/benchmarks/LibcMemoryBenchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace libc_benchmarks {
struct StudyConfiguration {
// One of 'memcpy', 'memset', 'memcmp'.
// The underlying implementation is always the llvm libc one.
// e.g. 'memcpy' will test '__llvm_libc::memcpy'
// e.g. 'memcpy' will test 'LIBC_NAMESPACE::memcpy'
std::string Function;

// The number of trials to run for this benchmark.
Expand Down
4 changes: 2 additions & 2 deletions libc/benchmarks/LibcMemoryBenchmarkMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <cstring>
#include <unistd.h>

namespace __llvm_libc {
namespace LIBC_NAMESPACE {

extern void *memcpy(void *__restrict, const void *__restrict, size_t);
extern void *memmove(void *, const void *, size_t);
Expand All @@ -30,7 +30,7 @@ extern void bzero(void *, size_t);
extern int memcmp(const void *, const void *, size_t);
extern int bcmp(const void *, const void *, size_t);

} // namespace __llvm_libc
} // namespace LIBC_NAMESPACE

namespace llvm {
namespace libc_benchmarks {
Expand Down
12 changes: 6 additions & 6 deletions libc/benchmarks/automemcpy/lib/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace functions {
// static void memcpy_0xB20D4702493C397E(char *__restrict dst,
// const char *__restrict src,
// size_t size) {
// using namespace __llvm_libc::x86;
// using namespace LIBC_NAMESPACE::x86;
// if(size == 0) return;
// if(size == 1) return copy<_1>(dst, src);
// if(size < 4) return copy<HeadTail<_2>>(dst, src, size);
Expand Down Expand Up @@ -249,7 +249,7 @@ static raw_ostream &operator<<(raw_ostream &Stream,
const auto &Ctx = FI.Ctx;
Stream << "static " << Ctx.FunctionReturnType << ' ' << FI.Name
<< Ctx.FunctionArgs << " {\n";
Stream << kIndent << "using namespace __llvm_libc::" << FI.ElementClass
Stream << kIndent << "using namespace LIBC_NAMESPACE::" << FI.ElementClass
<< ";\n";
for (const auto &I : FI.Individuals)
if (I.Element.Size == 0)
Expand Down Expand Up @@ -428,7 +428,7 @@ namespace configurations {
// ------------------------------------------------------------
// e.g.
// llvm::ArrayRef<MemcpyConfiguration> getMemcpyConfigurations() {
// using namespace __llvm_libc;
// using namespace LIBC_NAMESPACE;
// static constexpr MemcpyConfiguration kConfigurations[] = {
// {Wrap<memcpy_0xE00E29EE73994E2B>, "memcpy_0xE00E29EE73994E2B"},
// {Wrap<memcpy_0x8661D80472487AB5>, "memcpy_0x8661D80472487AB5"},
Expand Down Expand Up @@ -504,7 +504,7 @@ static raw_ostream &operator<<(raw_ostream &Stream, const Configuration &C) {
if (C.Descriptors.empty())
Stream << kIndent << "return {};\n";
else {
Stream << kIndent << "using namespace __llvm_libc;\n";
Stream << kIndent << "using namespace LIBC_NAMESPACE;\n";
Stream << kIndent << "static constexpr " << C.Type
<< " kConfigurations[] = {\n";
Stream << C.Descriptors;
Expand Down Expand Up @@ -542,11 +542,11 @@ static void Serialize(raw_ostream &Stream,
Stream << "using llvm::libc_benchmarks::MemmoveConfiguration;\n";
Stream << "using llvm::libc_benchmarks::MemsetConfiguration;\n";
Stream << "\n";
Stream << "namespace __llvm_libc {\n";
Stream << "namespace LIBC_NAMESPACE {\n";
Stream << "\n";
codegen::functions::Serialize(Stream, Descriptors);
Stream << "\n";
Stream << "} // namespace __llvm_libc\n";
Stream << "} // namespace LIBC_NAMESPACE\n";
Stream << "\n";
Stream << "namespace llvm {\n";
Stream << "namespace automemcpy {\n";
Expand Down
24 changes: 12 additions & 12 deletions libc/benchmarks/automemcpy/unittests/CodeGenTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ using llvm::libc_benchmarks::MemcpyConfiguration;
using llvm::libc_benchmarks::MemmoveConfiguration;
using llvm::libc_benchmarks::MemsetConfiguration;
namespace __llvm_libc {
namespace LIBC_NAMESPACE {
static void memcpy_0xE00E29EE73994E2B(char *__restrict dst, const char *__restrict src, size_t size) {
using namespace __llvm_libc::x86;
using namespace LIBC_NAMESPACE::x86;
return copy<Accelerator>(dst, src, size);
}
static void memcpy_0x7381B60C7BE75EF9(char *__restrict dst, const char *__restrict src, size_t size) {
using namespace __llvm_libc::x86;
using namespace LIBC_NAMESPACE::x86;
if(size == 0) return;
if(size == 1) return copy<_1>(dst, src);
if(size == 2) return copy<_2>(dst, src);
Expand All @@ -84,7 +84,7 @@ static void memcpy_0x7381B60C7BE75EF9(char *__restrict dst, const char *__restri
return copy<Loop<_64>>(dst, src, size);
}
static int memcmp_0x348D7BA6DB0EE033(const char * lhs, const char * rhs, size_t size) {
using namespace __llvm_libc::x86;
using namespace LIBC_NAMESPACE::x86;
if(size == 0) return 0;
if(size == 1) return three_way_compare<_1>(lhs, rhs);
if(size < 4) return three_way_compare<HeadTail<_2>>(lhs, rhs, size);
Expand All @@ -95,7 +95,7 @@ static int memcmp_0x348D7BA6DB0EE033(const char * lhs, const char * rhs, size_t
return three_way_compare<Align<_16,Arg::Lhs>::Then<Loop<_16>>>(lhs, rhs, size);
}
static void memset_0x71E761699B999863(char * dst, int value, size_t size) {
using namespace __llvm_libc::x86;
using namespace LIBC_NAMESPACE::x86;
if(size == 0) return;
if(size == 1) return splat_set<_1>(dst, value);
if(size < 4) return splat_set<HeadTail<_2>>(dst, value, size);
Expand All @@ -108,7 +108,7 @@ static void memset_0x71E761699B999863(char * dst, int value, size_t size) {
return splat_set<Align<_16,Arg::Dst>::Then<Loop<_32>>>(dst, value, size);
}
static void memset_0x3DF0F44E2ED6A50F(char * dst, int value, size_t size) {
using namespace __llvm_libc::x86;
using namespace LIBC_NAMESPACE::x86;
if(size == 0) return;
if(size == 1) return splat_set<_1>(dst, value);
if(size < 4) return splat_set<HeadTail<_2>>(dst, value, size);
Expand All @@ -121,7 +121,7 @@ static void memset_0x3DF0F44E2ED6A50F(char * dst, int value, size_t size) {
return splat_set<Align<_32,Arg::Dst>::Then<Loop<_32>>>(dst, value, size);
}
static void bzero_0x475977492C218AD4(char * dst, size_t size) {
using namespace __llvm_libc::x86;
using namespace LIBC_NAMESPACE::x86;
if(size == 0) return;
if(size == 1) return splat_set<_1>(dst, 0);
if(size == 2) return splat_set<_2>(dst, 0);
Expand All @@ -134,7 +134,7 @@ static void bzero_0x475977492C218AD4(char * dst, size_t size) {
return splat_set<Align<_32,Arg::Dst>::Then<Loop<_32>>>(dst, 0, size);
}
} // namespace __llvm_libc
} // namespace LIBC_NAMESPACE
namespace llvm {
namespace automemcpy {
Expand Down Expand Up @@ -163,7 +163,7 @@ void *Wrap(void *__restrict dst, const void *__restrict src, size_t size) {
return dst;
}
llvm::ArrayRef<MemcpyConfiguration> getMemcpyConfigurations() {
using namespace __llvm_libc;
using namespace LIBC_NAMESPACE;
static constexpr MemcpyConfiguration kConfigurations[] = {
{Wrap<memcpy_0xE00E29EE73994E2B>, "memcpy_0xE00E29EE73994E2B"},
{Wrap<memcpy_0x7381B60C7BE75EF9>, "memcpy_0x7381B60C7BE75EF9"},
Expand All @@ -178,7 +178,7 @@ int Wrap(const void *lhs, const void *rhs, size_t size) {
reinterpret_cast<const char *>(rhs), size);
}
llvm::ArrayRef<MemcmpOrBcmpConfiguration> getMemcmpConfigurations() {
using namespace __llvm_libc;
using namespace LIBC_NAMESPACE;
static constexpr MemcmpOrBcmpConfiguration kConfigurations[] = {
{Wrap<memcmp_0x348D7BA6DB0EE033>, "memcmp_0x348D7BA6DB0EE033"},
};
Expand All @@ -194,7 +194,7 @@ template <MemsetStub Foo> void *Wrap(void *dst, int value, size_t size) {
return dst;
}
llvm::ArrayRef<MemsetConfiguration> getMemsetConfigurations() {
using namespace __llvm_libc;
using namespace LIBC_NAMESPACE;
static constexpr MemsetConfiguration kConfigurations[] = {
{Wrap<memset_0x71E761699B999863>, "memset_0x71E761699B999863"},
{Wrap<memset_0x3DF0F44E2ED6A50F>, "memset_0x3DF0F44E2ED6A50F"},
Expand All @@ -207,7 +207,7 @@ template <BzeroStub Foo> void Wrap(void *dst, size_t size) {
Foo(reinterpret_cast<char *>(dst), size);
}
llvm::ArrayRef<BzeroConfiguration> getBzeroConfigurations() {
using namespace __llvm_libc;
using namespace LIBC_NAMESPACE;
static constexpr BzeroConfiguration kConfigurations[] = {
{Wrap<bzero_0x475977492C218AD4>, "bzero_0x475977492C218AD4"},
};
Expand Down
4 changes: 2 additions & 2 deletions libc/config/linux/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <stdint.h>

namespace __llvm_libc {
namespace LIBC_NAMESPACE {

// Data structure to capture properties of the linux/ELF TLS image.
struct TLSImage {
Expand Down Expand Up @@ -106,6 +106,6 @@ void init_tls(TLSDescriptor &tls);
// Cleanup the TLS area as described in |tls_descriptor|.
void cleanup_tls(uintptr_t tls_addr, uintptr_t tls_size);

} // namespace __llvm_libc
} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_CONFIG_LINUX_APP_H
16 changes: 8 additions & 8 deletions libc/docs/dev/clang_tidy_checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ implementation-in-namespace
---------------------------

It is part of our implementation standards that all implementation pieces live
under the ``__llvm_libc`` namespace. This prevents pollution of the global
under the ``LIBC_NAMESPACE`` namespace. This prevents pollution of the global
namespace. Without a formal check to ensure this, an implementation might
compile and pass unit tests, but not produce a usable libc function.

This check that ensures any function call resolves to a function within the
``__llvm_libc`` namespace.
``LIBC_NAMESPACE`` namespace.

.. code-block:: c++

// Correct: implementation inside the correct namespace.
namespace __llvm_libc {
namespace LIBC_NAMESPACE {
void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
// Namespaces within __llvm_libc namespace are allowed.
// Namespaces within LIBC_NAMESPACE namespace are allowed.
namespace inner{
int localVar = 0;
}
Expand All @@ -67,7 +67,7 @@ creates some uncertainty about which library a call resolves to especially when
a public header with non-namespaced functions like ``string.h`` is included.

This check ensures any function call resolves to a function within the
__llvm_libc namespace.
LIBC_NAMESPACE namespace.

There are exceptions for the following functions:
``__errno_location`` so that ``errno`` can be set;
Expand All @@ -76,10 +76,10 @@ are always external and can be intercepted.

.. code-block:: c++

namespace __llvm_libc {
namespace LIBC_NAMESPACE {

// Allow calls with the fully qualified name.
__llvm_libc::strlen("hello");
LIBC_NAMESPACE::strlen("hello");

// Allow calls to compiler provided functions.
(void)__builtin_abs(-1);
Expand All @@ -93,4 +93,4 @@ are always external and can be intercepted.
// Allow calling into specific global functions (explained above)
::malloc(10);

} // namespace __llvm_libc
} // namespace LIBC_NAMESPACE
2 changes: 1 addition & 1 deletion libc/docs/dev/code_style.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ this:

...

__llvm_libc::AllocChecker ac;
LIBC_NAMESPACE::AllocChecker ac;
auto *obj = new (ac) Type(...);
if (!ac) {
// handle allocator failure.
Expand Down
12 changes: 6 additions & 6 deletions libc/docs/dev/implementation_standard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ example. The ``round`` function will be declared in an internal header file
#ifndef LLVM_LIBC_SRC_MATH_ROUND_ROUND_H
#define LLVM_LIBC_SRC_MATH_ROUND_ROUND_H

namespace __llvm_libc {
namespace LIBC_NAMESPACE {

double round(double);

} // namespace __llvm_libc
} // namespace LIBC_NAMESPACE

#endif LLVM_LIBC_SRC_MATH_ROUND_ROUND_H

Notice that the ``round`` function declaration is nested inside the namespace
``__llvm_libc``. All implementation constructs in LLVM-libc are declared within
the namespace ``__llvm_libc``.
``LIBC_NAMESPACE``. All implementation constructs in LLVM-libc are declared within
the namespace ``LIBC_NAMESPACE``.

``.cpp`` File Structure
-----------------------
Expand All @@ -55,13 +55,13 @@ the entrypoint function should make use of a special macro. For example, the

// --- round.cpp --- //

namespace __llvm_libc {
namespace LIBC_NAMESPACE {

double LLVM_LIBC_ENTRYPOINT(round)(double d) {
// ... implementation goes here.
}

} // namespace __llvm_libc
} // namespace LIBC_NAMESPACE

Notice the use of the macro ``LLVM_LIBC_ENTRYPOINT``. This macro helps us define
an C alias symbol for the C++ implementation. The C alias need not be added by
Expand Down
9 changes: 5 additions & 4 deletions libc/fuzzing/math/Compare.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
#include "src/__support/FPUtil/FPBits.h"

template <typename T>
__llvm_libc::cpp::enable_if_t<__llvm_libc::cpp::is_floating_point_v<T>, bool>
LIBC_NAMESPACE::cpp::enable_if_t<LIBC_NAMESPACE::cpp::is_floating_point_v<T>,
bool>
ValuesEqual(T x1, T x2) {
__llvm_libc::fputil::FPBits<T> bits1(x1);
__llvm_libc::fputil::FPBits<T> bits2(x2);
LIBC_NAMESPACE::fputil::FPBits<T> bits1(x1);
LIBC_NAMESPACE::fputil::FPBits<T> bits2(x2);
// If either is NaN, we want both to be NaN.
if (bits1.is_nan() || bits2.is_nan())
return bits2.is_nan() && bits2.is_nan();
Expand All @@ -26,7 +27,7 @@ ValuesEqual(T x1, T x2) {
}

template <typename T>
__llvm_libc::cpp::enable_if_t<__llvm_libc::cpp::is_integral_v<T>, bool>
LIBC_NAMESPACE::cpp::enable_if_t<LIBC_NAMESPACE::cpp::is_integral_v<T>, bool>
ValuesEqual(T x1, T x2) {
return x1 == x2;
}
Expand Down
4 changes: 2 additions & 2 deletions libc/fuzzing/math/RemQuoDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void RemQuoDiff(RemQuoFunc<T> func1, RemQuoFunc<T> func2, const uint8_t *data,
if ((q1 & 0x7) != (q2 & 0x7))
__builtin_trap();

__llvm_libc::fputil::FPBits<T> bits1(remainder1);
__llvm_libc::fputil::FPBits<T> bits2(remainder2);
LIBC_NAMESPACE::fputil::FPBits<T> bits1(remainder1);
LIBC_NAMESPACE::fputil::FPBits<T> bits2(remainder2);
if (bits1.uintval() != bits2.uintval())
__builtin_trap();
}
Expand Down
Loading

0 comments on commit b6bc9d7

Please sign in to comment.