Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/CompileCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ llvm::ArrayRef<ArgStripper::Rule> ArgStripper::rulesFor(llvm::StringRef Arg) {
dlog(" {0} #={1} *={2} Mode={3}", R.Text, R.ExactArgs, R.PrefixArgs,
int(R.Modes));
}
dlog("Table spellings={0} rules={1} string-bytes={2}", Result->size(),
RuleCount, Result->getAllocator().getBytesAllocated());
dlog("Table spellings={0} rules={1} allocator-bytes={2}", Result->size(),
RuleCount, Result->getAllocator().getTotalMemory());
#endif
// The static table will never be destroyed.
return Result.release();
Expand Down
11 changes: 7 additions & 4 deletions clang/unittests/Lex/PPMemoryAllocationsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ TEST_F(PPMemoryAllocationsTest, PPMacroDefinesAllocations) {

PP.LexTokensUntilEOF();

size_t NumAllocated = PP.getPreprocessorAllocator().getBytesAllocated();
float BytesPerDefine = float(NumAllocated) / float(NumMacros);
llvm::errs() << "Num preprocessor allocations for " << NumMacros
<< " #define: " << NumAllocated << "\n";
// Use the total slab memory held by the preprocessor's allocator as a proxy.
// Over a million #defines the per-allocation slab overhead is negligible, so
// this closely tracks the bytes requested for storing the macro information.
size_t TotalMemory = PP.getPreprocessorAllocator().getTotalMemory();
float BytesPerDefine = float(TotalMemory) / float(NumMacros);
llvm::errs() << "Preprocessor allocator memory for " << NumMacros
<< " #define: " << TotalMemory << "\n";
llvm::errs() << "Bytes per #define: " << BytesPerDefine << "\n";
// On arm64-apple-macos, we get around 120 bytes per define.
// Assume a reasonable upper bound based on that number that we don't want
Expand Down
1 change: 1 addition & 0 deletions libc/shared/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "builtins/addtf3.h"
#include "builtins/divtf3.h"
#include "builtins/multf3.h"
#include "builtins/subdf3.h"
#include "builtins/subtf3.h"

#endif // LLVM_LIBC_SHARED_BUILTINS_H
29 changes: 29 additions & 0 deletions libc/shared/builtins/subdf3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This header exposes LLVM-libc's __subdf3 implementation as shared::subdf3 so
/// that it can be reused by compiler-rt's builtins.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SHARED_BUILTINS_SUBDF3_H
#define LLVM_LIBC_SHARED_BUILTINS_SUBDF3_H

#include "shared/libc_common.h"
#include "src/__support/builtins/subdf3.h"

namespace LIBC_NAMESPACE_DECL {
namespace shared {

using builtins::subdf3;

} // namespace shared
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SHARED_BUILTINS_SUBDF3_H
9 changes: 9 additions & 0 deletions libc/src/__support/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ add_header_library(
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)

add_header_library(
subdf3
HDRS
subdf3.h
DEPENDS
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)
32 changes: 32 additions & 0 deletions libc/src/__support/builtins/subdf3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This header exposes LLVM-libc's __subdf3 implementation as builtins::subdf3
/// so that it can be reused by compiler-rt's builtins.
///
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBDF3_H
#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBDF3_H

#include "src/__support/FPUtil/generic/add_sub.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {
namespace builtins {

// Subtraction at double precision; mirrors compiler-rt's __subdf3.
LIBC_INLINE double subdf3(double x, double y) {
return fputil::generic::sub<double>(x, y);
}

} // namespace builtins
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBDF3_H
1 change: 1 addition & 0 deletions libc/test/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ add_fp_unittest(
libc.src.__support.builtins.addtf3
libc.src.__support.builtins.divtf3
libc.src.__support.builtins.multf3
libc.src.__support.builtins.subdf3
libc.src.__support.builtins.subtf3
)

Expand Down
1 change: 1 addition & 0 deletions libc/test/shared/shared_builtins_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {

TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::adddf3(1.0, 2.0));
EXPECT_FP_EQ(2.0, LIBC_NAMESPACE::shared::subdf3(5.0, 3.0));
}

#ifdef LIBC_TYPES_HAS_FLOAT128
Expand Down
3 changes: 0 additions & 3 deletions lldb/include/lldb/Utility/ConstString.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,7 @@ class ConstString {

struct MemoryStats {
size_t GetBytesTotal() const { return bytes_total; }
size_t GetBytesUsed() const { return bytes_used; }
size_t GetBytesUnused() const { return bytes_total - bytes_used; }
size_t bytes_total = 0;
size_t bytes_used = 0;
};

static MemoryStats GetMemoryStats();
Expand Down
2 changes: 0 additions & 2 deletions lldb/source/Target/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ json::Value ModuleStats::ToJSON() const {
llvm::json::Value ConstStringStats::ToJSON() const {
json::Object obj;
obj.try_emplace<int64_t>("bytesTotal", stats.GetBytesTotal());
obj.try_emplace<int64_t>("bytesUsed", stats.GetBytesUsed());
obj.try_emplace<int64_t>("bytesUnused", stats.GetBytesUnused());
return obj;
}

Expand Down
1 change: 0 additions & 1 deletion lldb/source/Utility/ConstString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ class Pool {
std::shared_lock<PoolMutex> lock(pool.m_mutex);
const Allocator &alloc = pool.m_string_map.getAllocator();
stats.bytes_total += alloc.getTotalMemory();
stats.bytes_used += alloc.getBytesAllocated();
}
return stats;
}
Expand Down
2 changes: 0 additions & 2 deletions lldb/test/API/commands/statistics/basic/TestStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ def test_memory(self):
strings = memory["strings"]
strings_keys = [
"bytesTotal",
"bytesUsed",
"bytesUnused",
]
self.verify_keys(strings, '"strings"', strings_keys, None)

Expand Down
47 changes: 19 additions & 28 deletions llvm/include/llvm/Support/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define LLVM_SUPPORT_ALLOCATOR_H

#include "llvm/ADT/SmallVector.h"
#include "llvm/Config/abi-breaking.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/AllocatorBase.h"
#include "llvm/Support/Compiler.h"
Expand All @@ -36,9 +37,7 @@ namespace detail {

// We call out to an external function to actually print the message as the
// printing code uses Allocator.h in its implementation.
LLVM_ABI void printBumpPtrAllocatorStats(unsigned NumSlabs,
size_t BytesAllocated,
size_t TotalMemory);
LLVM_ABI void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t TotalMemory);

} // end namespace detail

Expand Down Expand Up @@ -96,11 +95,12 @@ class BumpPtrAllocatorImpl
BumpPtrAllocatorImpl(BumpPtrAllocatorImpl &&Old)
: AllocTy(std::move(Old.getAllocator())), CurPtr(Old.CurPtr),
EndSentinel(Old.EndSentinel), Slabs(std::move(Old.Slabs)),
CustomSizedSlabs(std::move(Old.CustomSizedSlabs)),
BytesAllocated(Old.BytesAllocated), RedZoneSize(Old.RedZoneSize) {
CustomSizedSlabs(std::move(Old.CustomSizedSlabs)) {
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
RedZoneSize = Old.RedZoneSize;
#endif
Old.CurPtr = nullptr;
Old.EndSentinel = 0;
Old.BytesAllocated = 0;
Old.Slabs.clear();
Old.CustomSizedSlabs.clear();
}
Expand All @@ -116,15 +116,15 @@ class BumpPtrAllocatorImpl

CurPtr = RHS.CurPtr;
EndSentinel = RHS.EndSentinel;
BytesAllocated = RHS.BytesAllocated;
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
RedZoneSize = RHS.RedZoneSize;
#endif
Slabs = std::move(RHS.Slabs);
CustomSizedSlabs = std::move(RHS.CustomSizedSlabs);
AllocTy::operator=(std::move(RHS.getAllocator()));

RHS.CurPtr = nullptr;
RHS.EndSentinel = 0;
RHS.BytesAllocated = 0;
RHS.Slabs.clear();
RHS.CustomSizedSlabs.clear();
return *this;
Expand All @@ -141,7 +141,6 @@ class BumpPtrAllocatorImpl
return;

// Reset the state.
BytesAllocated = 0;
CurPtr = (char *)Slabs.front();
EndSentinel = uintptr_t(CurPtr) + SlabSize + 1;

Expand All @@ -158,12 +157,10 @@ class BumpPtrAllocatorImpl
// Allocate(0, N) is valid, it returns a non-null pointer (which should not
// be dereferenced).
LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, Align Alignment) {
// Keep track of how many bytes we've allocated.
BytesAllocated += Size;

size_t SizeToAllocate = Size;
#if LLVM_ADDRESS_SANITIZER_BUILD
// Add trailing bytes as a "red zone" under ASan.
#if LLVM_ADDRESS_SANITIZER_BUILD && LLVM_ENABLE_ABI_BREAKING_CHECKS
// Add trailing bytes as a "red zone" under ASan. RedZoneSize only exists
// when both conditions are true.
SizeToAllocate += RedZoneSize;
#endif
SizeToAllocate = alignToPowerOf2(SizeToAllocate, MinAlign);
Expand Down Expand Up @@ -308,15 +305,14 @@ class BumpPtrAllocatorImpl
return TotalMemory;
}

size_t getBytesAllocated() const { return BytesAllocated; }

void setRedZoneSize(size_t NewSize) {
void setRedZoneSize([[maybe_unused]] size_t NewSize) {
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
RedZoneSize = NewSize;
#endif
}

void PrintStats() const {
detail::printBumpPtrAllocatorStats(Slabs.size(), BytesAllocated,
getTotalMemory());
detail::printBumpPtrAllocatorStats(Slabs.size(), getTotalMemory());
}

private:
Expand All @@ -335,14 +331,11 @@ class BumpPtrAllocatorImpl
/// Custom-sized slabs allocated for too-large allocation requests.
SmallVector<std::pair<void *, size_t>, 0> CustomSizedSlabs;

/// How many bytes we've allocated.
///
/// Used so that we can compute how much space was wasted.
size_t BytesAllocated = 0;

/// The number of bytes to put between allocations when running under
/// a sanitizer.
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
/// The number of bytes to put between allocations when running under a
/// sanitizer.
size_t RedZoneSize = 1;
#endif

static size_t computeSlabSize(unsigned SlabIdx) {
// Scale the actual allocated slab size based on the number of slabs
Expand Down Expand Up @@ -472,8 +465,6 @@ template <typename T> class SpecificBumpPtrAllocator {
std::optional<int64_t> identifyObject(const void *Ptr) {
return Allocator.identifyObject(Ptr);
}

size_t getBytesAllocated() const { return Allocator.getBytesAllocated(); }
};

} // end namespace llvm
Expand Down
10 changes: 0 additions & 10 deletions llvm/include/llvm/Support/PerThreadBumpPtrAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ class PerThreadAllocator
return TotalMemory;
}

/// Return allocated size by all allocators.
size_t getBytesAllocated() const {
size_t BytesAllocated = 0;

for (size_t Idx = 0; Idx < getNumberOfAllocators(); Idx++)
BytesAllocated += Allocators[Idx].getBytesAllocated();

return BytesAllocated;
}

/// Set red zone for all allocators.
void setRedZoneSize(size_t NewSize) {
for (size_t Idx = 0; Idx < getNumberOfAllocators(); Idx++)
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/Support/WithColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class WithColor {
/// @param Bold Bold/brighter text, default false
/// @param BG If true, change the background, default: change foreground
/// @param Mode Enable, disable or compute whether to use colors.
///
/// FIXME: If Color == SAVEDCOLOR, Bold == false is currently ignored.
LLVM_CTOR_NODISCARD WithColor(
raw_ostream &OS, raw_ostream::Colors Color = raw_ostream::SAVEDCOLOR,
bool Bold = false, bool BG = false, ColorMode Mode = ColorMode::Auto)
Expand Down Expand Up @@ -117,6 +119,8 @@ class WithColor {
/// change only the bold attribute, and keep colors untouched
/// @param Bold Bold/brighter text, default false
/// @param BG If true, change the background, default: change foreground
///
/// FIXME: If Color == SAVEDCOLOR, Bold == false is currently ignored.
LLVM_ABI WithColor &changeColor(raw_ostream::Colors Color, bool Bold = false,
bool BG = false);

Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/Support/raw_ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ class LLVM_ABI raw_ostream {
/// @param Bold bold/brighter text, default false
/// @param BG if true change the background, default: change foreground
/// @returns itself so it can be used within << invocations
///
/// FIXME: If Color == SAVEDCOLOR, Bold == false is currently ignored.
virtual raw_ostream &changeColor(enum Colors Color, bool Bold = false,
bool BG = false);

Expand Down
5 changes: 1 addition & 4 deletions llvm/lib/Support/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ namespace llvm {

namespace detail {

void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t BytesAllocated,
size_t TotalMemory) {
void printBumpPtrAllocatorStats(unsigned NumSlabs, size_t TotalMemory) {
errs() << "\nNumber of memory regions: " << NumSlabs << '\n'
<< "Bytes used: " << BytesAllocated << '\n'
<< "Bytes allocated: " << TotalMemory << '\n'
<< "Bytes wasted: " << (TotalMemory - BytesAllocated)
<< " (includes alignment, etc)\n";
}

Expand Down
1 change: 0 additions & 1 deletion llvm/lib/TableGen/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ void detail::RecordKeeperImpl::dumpAllocationStats(raw_ostream &OS) const {
OS << "TheVarBitInitPool size = " << TheVarBitInitPool.size() << '\n';
OS << "TheVarDefInitPool size = " << TheVarDefInitPool.size() << '\n';
OS << "TheFieldInitPool size = " << TheFieldInitPool.size() << '\n';
OS << "Bytes allocated = " << Allocator.getBytesAllocated() << '\n';
OS << "Total allocator memory = " << Allocator.getTotalMemory() << "\n\n";

OS << "Number of records instantiated = " << LastRecordID << '\n';
Expand Down
Loading
Loading