Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -verify -fopenmp %s -verify=expected,omp51 -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp-simd %s -verify=expected,omp51 -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp %s -fopenmp-version=52 -verify=expected,omp5x,omp52 -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp-simd %s -fopenmp-version=52 -verify=expected,omp5x,omp52 -Wuninitialized

// RUN: %clang_cc1 -verify -fopenmp %s -fopenmp-version=51 -verify=expected,omp5x,omp51 -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp-simd %s -fopenmp-version=51 -verify=expected,omp5x,omp51 -Wuninitialized

// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 %s -verify=expected,omp5 -Wuninitialized -DOMP5
// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 %s -verify=expected,omp5 -Wuninitialized -DOMP5
Expand All @@ -15,22 +18,22 @@ T tmain(T argc, S **argv) {
int i;
#pragma omp target teams distribute parallel for simd defaultmap // expected-error {{expected '(' after 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap( // omp51-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap( // omp5x-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap() // omp51-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap() // omp5x-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom // expected-error {{expected ')'}} expected-note {{to match this '('}} omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap (tofrom: // expected-error {{expected ')'}} expected-note {{to match this '('}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap (tofrom: // expected-error {{expected ')'}} expected-note {{to match this '('}} omp52-error {{expected 'scalar', 'aggregate', 'pointer', 'all' in OpenMP clause 'defaultmap'}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom) // omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom scalar) // omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp5-error {{expected ')'}} omp5-note {{to match this '('}} omp51-error {{expected ')'}} omp51-note {{to match this '('}}
#pragma omp target teams distribute parallel for simd defaultmap(tofrom scalar) // omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp5-error {{expected ')'}} omp5-note {{to match this '('}} omp5x-error {{expected ')'}} omp5x-note {{to match this '('}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom, // expected-error {{expected ')'}} omp45-warning {{missing ':' after defaultmap modifier - ignoring}} expected-note {{to match this '('}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap (scalar: // expected-error {{expected ')'}} omp51-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap (scalar: // expected-error {{expected ')'}} omp5x-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp52-error {{expected 'scalar', 'aggregate', 'pointer', 'all' in OpenMP clause 'defaultmap'}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom, scalar // expected-error {{expected ')'}} omp45-warning {{missing ':' after defaultmap modifier - ignoring}} expected-note {{to match this '('}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
Expand All @@ -44,27 +47,27 @@ int main(int argc, char **argv) {
#pragma omp target teams distribute parallel for simd defaultmap // expected-error {{expected '(' after 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap( // omp51-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap( // omp5x-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap() // omp51-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap() // omp5x-error {{'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom // expected-error {{expected ')'}} expected-note {{to match this '('}} omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap (tofrom: // expected-error {{expected ')'}} expected-note {{to match this '('}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap (tofrom: // expected-error {{expected ')'}} expected-note {{to match this '('}} omp52-error {{expected 'scalar', 'aggregate', 'pointer', 'all' in OpenMP clause 'defaultmap'}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom) // omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom scalar) // omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp5-error {{expected ')'}} omp5-note {{to match this '('}} omp51-error {{expected ')'}} omp51-note {{to match this '('}}
#pragma omp target teams distribute parallel for simd defaultmap(tofrom scalar) // omp45-warning {{missing ':' after defaultmap modifier - ignoring}} omp5-error {{expected ')'}} omp5-note {{to match this '('}} omp5x-error {{expected ')'}} omp5x-note {{to match this '('}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom, // expected-error {{expected ')'}} omp45-warning {{missing ':' after defaultmap modifier - ignoring}} expected-note {{to match this '('}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i) foo();
#pragma omp target teams distribute parallel for simd defaultmap (scalar: // expected-error {{expected ')'}} omp51-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
#pragma omp target teams distribute parallel for simd defaultmap (scalar: // expected-error {{expected ')'}} omp5x-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default', 'present' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'alloc', 'from', 'to', 'tofrom', 'firstprivate', 'none', 'default' in OpenMP clause 'defaultmap'}} omp52-error {{expected 'scalar', 'aggregate', 'pointer', 'all' in OpenMP clause 'defaultmap'}} omp51-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} omp5-error {{expected 'scalar', 'aggregate', 'pointer' in OpenMP clause 'defaultmap'}} expected-note {{to match this '('}} omp45-error {{expected 'tofrom' in OpenMP clause 'defaultmap'}}
for (i = 0; i < argc; ++i)
foo();
#pragma omp target teams distribute parallel for simd defaultmap(tofrom, scalar // expected-error {{expected ')'}} omp45-warning {{missing ':' after defaultmap modifier - ignoring}} expected-note {{to match this '('}} omp45-error {{expected 'scalar' in OpenMP clause 'defaultmap'}}
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Sema/attr-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,10 @@ void forward_fixed(const char *fmt, _Bool b, char i, short j, int k, float l, do
a(fmt, b, i, j, k, l, m);
}

// OpenBSD
// same as format(printf(...))...
void a2(const char *a, ...) __attribute__((format(syslog, 1, 2))); // no-error
void b2(const char *a, ...) __attribute__((format(syslog, 1, 1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}
void c2(const char *a, ...) __attribute__((format(syslog, 0, 2))); // expected-error {{'format' attribute parameter 2 is out of bounds}}
void d2(const char *a, int c) __attribute__((format(syslog, 1, 2))); // expected-warning {{GCC requires a function with the 'format' attribute to be variadic}}
void e2(char *str, int c, ...) __attribute__((format(syslog, 2, 3))); // expected-error {{format argument not a string type}}
33 changes: 26 additions & 7 deletions libc/cmake/modules/CheckCompilerFeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ set(
# Making sure ALL_COMPILER_FEATURES is sorted.
list(SORT ALL_COMPILER_FEATURES)

# Compiler features that are unavailable on GPU targets with the in-tree Clang.
set(
CPU_ONLY_COMPILER_FEATURES
"float128"
)

# Function to check whether the compiler supports the provided set of features.
# Usage:
# compiler_supports(
Expand Down Expand Up @@ -67,13 +73,26 @@ foreach(feature IN LISTS ALL_COMPILER_FEATURES)
set(CMAKE_TRY_COMPILE_TARGET_TYPE EXECUTABLE)
endif()

try_compile(
has_feature
${CMAKE_CURRENT_BINARY_DIR}/compiler_features
SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/compiler_features/check_${feature}.cpp
COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${compile_options}
LINK_OPTIONS ${link_options}
)
if(LIBC_TARGET_OS_IS_GPU)
# CUDA shouldn't be required to build the libc, only to test it, so we can't
# try to build CUDA binaries here. Since GPU builds are always compiled with
# the in-tree Clang, we just hardcode which compiler features are available
# when targeting GPUs.
if(feature IN_LIST CPU_ONLY_COMPILER_FEATURES)
set(has_feature FALSE)
else()
set(has_feature TRUE)
endif()
else()
try_compile(
has_feature
${CMAKE_CURRENT_BINARY_DIR}/compiler_features
SOURCES ${LIBC_SOURCE_DIR}/cmake/modules/compiler_features/check_${feature}.cpp
COMPILE_DEFINITIONS -I${LIBC_SOURCE_DIR} ${compile_options}
LINK_OPTIONS ${link_options}
)
endif()

if(has_feature)
list(APPEND AVAILABLE_COMPILER_FEATURES ${feature})
if(${feature} STREQUAL "float16")
Expand Down
6 changes: 4 additions & 2 deletions libc/cmake/modules/LLVMLibCFlagRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
set(SKIP_FLAG_EXPANSION_EXPLICIT_SIMD_OPT TRUE)
endif()

# Skip ROUND_OPT flag for targets that don't support SSE 4.2.
# Skip ROUND_OPT flag for targets that don't support rounding instructions. On
# x86, these are SSE4.1 instructions, but we already had code to check for
# SSE4.2 support.
if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")) OR
LIBC_TARGET_ARCHITECTURE_IS_AARCH64))
LIBC_TARGET_ARCHITECTURE_IS_AARCH64 OR LIBC_TARGET_OS_IS_GPU))
set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE)
endif()
5 changes: 0 additions & 5 deletions libc/config/baremetal/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
"value": false
}
},
"malloc": {
"LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE": {
"value": 102400
}
},
"qsort": {
"LIBC_CONF_QSORT_IMPL": {
"value": "LIBC_QSORT_HEAP_SORT"
Expand Down
6 changes: 0 additions & 6 deletions libc/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@
"doc": "Default number of spins before blocking if a rwlock is in contention (default to 100)."
}
},
"malloc": {
"LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE": {
"value": 1073741824,
"doc": "Default size for the constinit freelist buffer used for the freelist malloc implementation (default 1o 1GB)."
}
},
"unistd": {
"LIBC_CONF_ENABLE_TID_CACHE": {
"value": true,
Expand Down
68 changes: 68 additions & 0 deletions libc/config/gpu/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,74 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.truncf
)

if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
libc.src.math.ceilf16
libc.src.math.copysignf16
libc.src.math.f16add
libc.src.math.f16addf
libc.src.math.f16div
libc.src.math.f16divf
libc.src.math.f16fma
libc.src.math.f16fmaf
libc.src.math.f16mul
libc.src.math.f16mulf
libc.src.math.f16sqrt
libc.src.math.f16sqrtf
libc.src.math.f16sub
libc.src.math.f16subf
libc.src.math.fabsf16
libc.src.math.fdimf16
libc.src.math.floorf16
libc.src.math.fmaxf16
libc.src.math.fmaximum_mag_numf16
libc.src.math.fmaximum_magf16
libc.src.math.fmaximum_numf16
libc.src.math.fmaximumf16
libc.src.math.fminf16
libc.src.math.fminimum_mag_numf16
libc.src.math.fminimum_magf16
libc.src.math.fminimum_numf16
libc.src.math.fminimumf16
libc.src.math.fmodf16
libc.src.math.frexpf16
libc.src.math.fromfpf16
libc.src.math.fromfpxf16
libc.src.math.getpayloadf16
libc.src.math.ilogbf16
libc.src.math.ldexpf16
libc.src.math.llogbf16
libc.src.math.llrintf16
libc.src.math.llroundf16
libc.src.math.logbf16
libc.src.math.lrintf16
libc.src.math.lroundf16
libc.src.math.modff16
libc.src.math.nanf16
libc.src.math.nearbyintf16
libc.src.math.nextafterf16
libc.src.math.nextdownf16
libc.src.math.nexttowardf16
libc.src.math.nextupf16
libc.src.math.remainderf16
libc.src.math.remquof16
libc.src.math.rintf16
libc.src.math.roundevenf16
libc.src.math.roundf16
libc.src.math.scalblnf16
libc.src.math.scalbnf16
libc.src.math.setpayloadf16
libc.src.math.setpayloadsigf16
libc.src.math.totalorderf16
libc.src.math.totalordermagf16
libc.src.math.truncf16
libc.src.math.ufromfpf16
libc.src.math.ufromfpxf16
)
endif()

set(TARGET_LLVMLIBC_ENTRYPOINTS
${TARGET_LIBC_ENTRYPOINTS}
${TARGET_LIBM_ENTRYPOINTS}
Expand Down
2 changes: 0 additions & 2 deletions libc/docs/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ to learn about the defaults for your platform and target.
- ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for better debugging experience.
* **"errno" options**
- ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM.
* **"malloc" options**
- ``LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE``: Default size for the constinit freelist buffer used for the freelist malloc implementation (default 1o 1GB).
* **"math" options**
- ``LIBC_CONF_MATH_OPTIMIZATIONS``: Configures optimizations for math functions. Values accepted are LIBC_MATH_SKIP_ACCURATE_PASS, LIBC_MATH_SMALL_TABLES, LIBC_MATH_NO_ERRNO, LIBC_MATH_NO_EXCEPT, and LIBC_MATH_FAST.
* **"printf" options**
Expand Down
73 changes: 32 additions & 41 deletions libc/src/__support/freelist_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

namespace LIBC_NAMESPACE_DECL {

extern "C" cpp::byte _end;
extern "C" cpp::byte __llvm_libc_heap_limit;

using cpp::optional;
using cpp::span;

Expand All @@ -47,18 +50,10 @@ template <size_t NUM_BUCKETS = DEFAULT_BUCKETS.size()> class FreeListHeap {
size_t total_free_calls;
};

FreeListHeap(span<cpp::byte> region)
: FreeListHeap(&*region.begin(), &*region.end(), region.size()) {
auto result = BlockType::init(region);
BlockType *block = *result;
freelist_.add_chunk(block_to_span(block));
}
constexpr FreeListHeap() : begin_(&_end), end_(&__llvm_libc_heap_limit) {}

constexpr FreeListHeap(void *start, cpp::byte *end, size_t total_bytes)
: block_region_start_(start), block_region_end_(end),
freelist_(DEFAULT_BUCKETS), heap_stats_{} {
heap_stats_.total_bytes = total_bytes;
}
constexpr FreeListHeap(span<cpp::byte> region)
: begin_(region.begin()), end_(region.end()) {}

void *allocate(size_t size);
void *aligned_allocate(size_t alignment, size_t size);
Expand All @@ -69,61 +64,57 @@ template <size_t NUM_BUCKETS = DEFAULT_BUCKETS.size()> class FreeListHeap {
void *calloc(size_t num, size_t size);

const HeapStats &heap_stats() const { return heap_stats_; }
void reset_heap_stats() { heap_stats_ = {}; }

void *region_start() const { return block_region_start_; }
size_t region_size() const {
return reinterpret_cast<uintptr_t>(block_region_end_) -
reinterpret_cast<uintptr_t>(block_region_start_);
}
cpp::span<cpp::byte> region() const { return {begin_, end_}; }

protected:
constexpr void set_freelist_node(typename FreeListType::FreeListNode &node,
cpp::span<cpp::byte> chunk) {
freelist_.set_freelist_node(node, chunk);
}
private:
void init();

void *allocate_impl(size_t alignment, size_t size);

private:
span<cpp::byte> block_to_span(BlockType *block) {
return span<cpp::byte>(block->usable_space(), block->inner_size());
}

bool is_valid_ptr(void *ptr) {
return ptr >= block_region_start_ && ptr < block_region_end_;
}
bool is_valid_ptr(void *ptr) { return ptr >= begin_ && ptr < end_; }

void *block_region_start_;
void *block_region_end_;
FreeListType freelist_;
HeapStats heap_stats_;
bool is_initialized_ = false;
cpp::byte *begin_;
cpp::byte *end_;
FreeListType freelist_{DEFAULT_BUCKETS};
HeapStats heap_stats_{};
};

template <size_t BUFF_SIZE, size_t NUM_BUCKETS = DEFAULT_BUCKETS.size()>
struct FreeListHeapBuffer : public FreeListHeap<NUM_BUCKETS> {
class FreeListHeapBuffer : public FreeListHeap<NUM_BUCKETS> {
using parent = FreeListHeap<NUM_BUCKETS>;
using FreeListNode = typename parent::FreeListType::FreeListNode;

public:
constexpr FreeListHeapBuffer()
: FreeListHeap<NUM_BUCKETS>(&block, buffer + sizeof(buffer), BUFF_SIZE),
block(0, BUFF_SIZE), node{}, buffer{} {
block.mark_last();

cpp::span<cpp::byte> chunk(buffer, sizeof(buffer));
parent::set_freelist_node(node, chunk);
}
: FreeListHeap<NUM_BUCKETS>{buffer}, buffer{} {}

typename parent::BlockType block;
FreeListNode node;
cpp::byte buffer[BUFF_SIZE - sizeof(block) - sizeof(node)];
private:
cpp::byte buffer[BUFF_SIZE];
};

template <size_t NUM_BUCKETS> void FreeListHeap<NUM_BUCKETS>::init() {
LIBC_ASSERT(!is_initialized_ && "duplicate initialization");
heap_stats_.total_bytes = region().size();
auto result = BlockType::init(region());
BlockType *block = *result;
freelist_.add_chunk(block_to_span(block));
is_initialized_ = true;
}

template <size_t NUM_BUCKETS>
void *FreeListHeap<NUM_BUCKETS>::allocate_impl(size_t alignment, size_t size) {
if (size == 0)
return nullptr;

if (!is_initialized_)
init();

// Find a chunk in the freelist. Split it if needed, then return.
auto chunk =
freelist_.find_chunk_if([alignment, size](span<cpp::byte> chunk) {
Expand Down
4 changes: 4 additions & 0 deletions libc/src/__support/macros/properties/cpu_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@
#define LIBC_TARGET_CPU_HAS_NEAREST_INT
#endif

#if defined(LIBC_TARGET_ARCH_IS_AARCH64) || defined(LIBC_TARGET_ARCH_IS_GPU)
#define LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS
#endif

#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_CPU_FEATURES_H
14 changes: 7 additions & 7 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.properties.cpu_features
FLAGS
ROUND_OPT
)
Expand Down Expand Up @@ -548,7 +548,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.properties.cpu_features
FLAGS
ROUND_OPT
)
Expand Down Expand Up @@ -617,7 +617,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.properties.cpu_features
FLAGS
ROUND_OPT
)
Expand Down Expand Up @@ -686,7 +686,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.properties.cpu_features
FLAGS
ROUND_OPT
)
Expand Down Expand Up @@ -755,7 +755,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.properties.cpu_features
FLAGS
ROUND_OPT
)
Expand Down Expand Up @@ -948,7 +948,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.properties.architectures
libc.src.__support.macros.properties.cpu_features
FLAGS
ROUND_OPT
)
Expand Down Expand Up @@ -4231,7 +4231,7 @@ add_entrypoint_object(
libc.src.__support.macros.properties.types
libc.src.__support.FPUtil.fma
COMPILE_OPTIONS
-O0 -ggdb3
-O3
)

add_entrypoint_object(
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/ceilf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/cpu_features.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, ceilf16, (float16 x)) {
#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
defined(LIBC_TARGET_ARCH_IS_AARCH64)
defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
return static_cast<float16>(__builtin_ceilf(x));
#else
return fputil::ceil(x);
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/floorf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/cpu_features.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, floorf16, (float16 x)) {
#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
defined(LIBC_TARGET_ARCH_IS_AARCH64)
defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
return static_cast<float16>(__builtin_floorf(x));
#else
return fputil::floor(x);
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/rintf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/cpu_features.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, rintf16, (float16 x)) {
#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
defined(LIBC_TARGET_ARCH_IS_AARCH64)
defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
return static_cast<float16>(__builtin_rintf(x));
#else
return fputil::round_using_current_rounding_mode(x);
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/roundevenf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/cpu_features.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, roundevenf16, (float16 x)) {
#if defined(__LIBC_USE_BUILTIN_ROUNDEVEN) && \
defined(LIBC_TARGET_ARCH_IS_AARCH64)
defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
return static_cast<float16>(__builtin_roundevenf(x));
#else
return fputil::round_using_specific_rounding_mode(x, FP_INT_TONEAREST);
Expand Down
5 changes: 3 additions & 2 deletions libc/src/math/generic/roundf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/cpu_features.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, roundf16, (float16 x)) {
#if defined(__LIBC_USE_BUILTIN_ROUND) && defined(LIBC_TARGET_ARCH_IS_AARCH64)
#if defined(__LIBC_USE_BUILTIN_ROUND) && \
defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
return static_cast<float16>(__builtin_roundf(x));
#else
return fputil::round(x);
Expand Down
4 changes: 2 additions & 2 deletions libc/src/math/generic/truncf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/architectures.h"
#include "src/__support/macros/properties/cpu_features.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(float16, truncf16, (float16 x)) {
#if defined(__LIBC_USE_BUILTIN_CEIL_FLOOR_RINT_TRUNC) && \
defined(LIBC_TARGET_ARCH_IS_AARCH64)
defined(LIBC_TARGET_CPU_HAS_FAST_FLOAT16_OPS)
return static_cast<float16>(__builtin_truncf(x));
#else
return fputil::trunc(x);
Expand Down
2 changes: 0 additions & 2 deletions libc/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,6 @@ if(NOT LIBC_TARGET_OS_IS_GPU)
malloc.h
DEPENDS
libc.src.__support.freelist_heap
COMPILE_OPTIONS
-DLIBC_FREELIST_MALLOC_SIZE=${LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE}
)
get_target_property(freelist_malloc_is_skipped libc.src.stdlib.freelist_malloc "SKIPPED")
if(LIBC_TARGET_OS_IS_BAREMETAL AND NOT freelist_malloc_is_skipped)
Expand Down
13 changes: 2 additions & 11 deletions libc/src/stdlib/freelist_malloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,8 @@

namespace LIBC_NAMESPACE_DECL {

namespace {
#ifdef LIBC_FREELIST_MALLOC_SIZE
// This is set via the LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE configuration.
constexpr size_t SIZE = LIBC_FREELIST_MALLOC_SIZE;
#else
#error "LIBC_FREELIST_MALLOC_SIZE was not defined for this build."
#endif
LIBC_CONSTINIT FreeListHeapBuffer<SIZE> freelist_heap_buffer;
} // namespace

FreeListHeap<> *freelist_heap = &freelist_heap_buffer;
static LIBC_CONSTINIT FreeListHeap<> freelist_heap_symbols;
FreeListHeap<> *freelist_heap = &freelist_heap_symbols;

LLVM_LIBC_FUNCTION(void *, malloc, (size_t size)) {
return freelist_heap->allocate(size);
Expand Down
1 change: 1 addition & 0 deletions libc/test/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if(LLVM_LIBC_FULL_BUILD)
SUITE
libc-support-tests
SRCS
fake_heap.s
freelist_heap_test.cpp
freelist_malloc_test.cpp
DEPENDS
Expand Down
15 changes: 15 additions & 0 deletions libc/test/src/__support/fake_heap.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//===-- Test fake definition for heap symbols -----------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

.globl _end, __llvm_libc_heap_limit

.bss
_end:
.fill 1024
__llvm_libc_heap_limit:

7 changes: 6 additions & 1 deletion libc/test/src/__support/freelist_heap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ using LIBC_NAMESPACE::freelist_heap;
#define TEST_FOR_EACH_ALLOCATOR(TestCase, BufferSize) \
class LlvmLibcFreeListHeapTest##TestCase : public testing::Test { \
public: \
FreeListHeapBuffer<BufferSize> fake_global_buffer; \
void SetUp() override { \
freelist_heap = \
new (&fake_global_buffer) FreeListHeapBuffer<BufferSize>; \
} \
void RunTest(FreeListHeap<> &allocator, [[maybe_unused]] size_t N); \
}; \
TEST_F(LlvmLibcFreeListHeapTest##TestCase, TestCase) { \
alignas(FreeListHeap<>::BlockType) \
cpp::byte buf[BufferSize] = {cpp::byte(0)}; \
FreeListHeap<> allocator(buf); \
RunTest(allocator, BufferSize); \
RunTest(*freelist_heap, freelist_heap->region_size()); \
RunTest(*freelist_heap, freelist_heap->region().size()); \
} \
void LlvmLibcFreeListHeapTest##TestCase::RunTest(FreeListHeap<> &allocator, \
size_t N)
Expand Down
4 changes: 1 addition & 3 deletions libc/test/src/__support/freelist_malloc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
#include "test/UnitTest/Test.h"

using LIBC_NAMESPACE::freelist_heap;
using LIBC_NAMESPACE::FreeListHeapBuffer;

TEST(LlvmLibcFreeListMalloc, MallocStats) {
constexpr size_t kAllocSize = 256;
constexpr size_t kCallocNum = 4;
constexpr size_t kCallocSize = 64;

freelist_heap->reset_heap_stats(); // Do this because other tests might've
// called the same global allocator.

void *ptr1 = LIBC_NAMESPACE::malloc(kAllocSize);

const auto &freelist_heap_stats = freelist_heap->heap_stats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void test_nonexistent() {
TEST_VALIDATE_EXCEPTION(
std::chrono::nonexistent_local_time,
[&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-03-30 02:30:00.000000000 is in a gap between
1986-03-30 02:00:00 CET and
1986-03-30 03:00:00 CEST which are both equivalent to
Expand All @@ -103,7 +103,7 @@ static void test_nonexistent() {
TEST_VALIDATE_EXCEPTION(
std::chrono::nonexistent_local_time,
[&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-03-30 02:30:00.000000 is in a gap between
1986-03-30 02:00:00 CET and
1986-03-30 03:00:00 CEST which are both equivalent to
Expand All @@ -117,7 +117,7 @@ static void test_nonexistent() {
TEST_VALIDATE_EXCEPTION(
std::chrono::nonexistent_local_time,
[&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-03-30 02:30:00.000 is in a gap between
1986-03-30 02:00:00 CET and
1986-03-30 03:00:00 CEST which are both equivalent to
Expand All @@ -131,7 +131,7 @@ static void test_nonexistent() {
TEST_VALIDATE_EXCEPTION(
std::chrono::nonexistent_local_time,
[&]([[maybe_unused]] const std::chrono::nonexistent_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-03-30 02:30:00 is in a gap between
1986-03-30 02:00:00 CET and
1986-03-30 03:00:00 CEST which are both equivalent to
Expand Down Expand Up @@ -173,7 +173,7 @@ static void test_ambiguous() {
TEST_VALIDATE_EXCEPTION(
std::chrono::ambiguous_local_time,
[&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-09-28 02:30:00.000000000 is ambiguous. It could be
1986-09-28 02:30:00.000000000 CEST == 1986-09-28 00:30:00.000000000 UTC or
1986-09-28 02:30:00.000000000 CET == 1986-09-28 01:30:00.000000000 UTC)";
Expand All @@ -186,7 +186,7 @@ static void test_ambiguous() {
TEST_VALIDATE_EXCEPTION(
std::chrono::ambiguous_local_time,
[&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-09-28 02:30:00.000000 is ambiguous. It could be
1986-09-28 02:30:00.000000 CEST == 1986-09-28 00:30:00.000000 UTC or
1986-09-28 02:30:00.000000 CET == 1986-09-28 01:30:00.000000 UTC)";
Expand All @@ -199,7 +199,7 @@ static void test_ambiguous() {
TEST_VALIDATE_EXCEPTION(
std::chrono::ambiguous_local_time,
[&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-09-28 02:30:00.000 is ambiguous. It could be
1986-09-28 02:30:00.000 CEST == 1986-09-28 00:30:00.000 UTC or
1986-09-28 02:30:00.000 CET == 1986-09-28 01:30:00.000 UTC)";
Expand All @@ -212,7 +212,7 @@ static void test_ambiguous() {
TEST_VALIDATE_EXCEPTION(
std::chrono::ambiguous_local_time,
[&]([[maybe_unused]] const std::chrono::ambiguous_local_time& e) {
std::string_view what =
[[maybe_unused]] std::string_view what =
R"(1986-09-28 02:30:00 is ambiguous. It could be
1986-09-28 02:30:00 CEST == 1986-09-28 00:30:00 UTC or
1986-09-28 02:30:00 CET == 1986-09-28 01:30:00 UTC)";
Expand Down
26 changes: 8 additions & 18 deletions lld/ELF/ScriptLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
// in various corner cases. We do not care much about efficiency because
// the time spent in parsing linker scripts is usually negligible.
//
// Our grammar of the linker script is LL(1).
//
// Overall, this lexer works fine for most linker scripts. There might
// be room for improving compatibility, but that's probably not at the
// top of our todo list.
Expand All @@ -38,6 +36,8 @@ using namespace llvm;
using namespace lld;
using namespace lld::elf;

ScriptLexer::ScriptLexer(MemoryBufferRef mb) : curBuf(mb), mbs(1, mb) {}

// Returns a whole line containing the current token.
StringRef ScriptLexer::getLine() {
StringRef s = getCurrentMB().getBuffer();
Expand Down Expand Up @@ -84,12 +84,6 @@ std::string ScriptLexer::getCurrentLocation() {
return (filename + ":" + Twine(getLineNumber())).str();
}

ScriptLexer::ScriptLexer(MemoryBufferRef mb) {
curBuf.s = mb.getBuffer();
curBuf.filename = mb.getBufferIdentifier();
mbs.push_back(mb);
}

// We don't want to record cascading errors. Keep only the first one.
void ScriptLexer::setError(const Twine &msg) {
if (errorCount())
Expand All @@ -103,12 +97,9 @@ void ScriptLexer::setError(const Twine &msg) {
}

void ScriptLexer::lex() {
std::vector<StringRef> vec;
StringRef begin = curBuf.s;

for (;;) {
StringRef &s = curBuf.s;
s = skipSpace(curBuf.s);
s = skipSpace(s);
if (s.empty()) {
// If this buffer is from an INCLUDE command, switch to the "return
// value"; otherwise, mark EOF.
Expand All @@ -128,7 +119,8 @@ void ScriptLexer::lex() {
if (s.starts_with("\"")) {
size_t e = s.find("\"", 1);
if (e == StringRef::npos) {
size_t lineno = begin.substr(0, s.data() - begin.data()).count('\n');
size_t lineno =
StringRef(curBuf.begin, s.data() - curBuf.begin).count('\n');
error(curBuf.filename + ":" + Twine(lineno + 1) + ": unclosed quote");
return;
}
Expand All @@ -144,8 +136,7 @@ void ScriptLexer::lex() {
s = s.substr(3);
return;
}
if (s.size() > 1 && ((s[1] == '=' && strchr("*/+-!<>&^|", s[0])) ||
(s[0] == s[1] && strchr("<>&|", s[0])))) {
if (s.size() > 1 && (s[1] == '=' && strchr("+-*/!&^|", s[0]))) {
curTok = s.substr(0, 2);
s = s.substr(2);
return;
Expand All @@ -160,7 +151,8 @@ void ScriptLexer::lex() {
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789_.$");
if (pos == 0 && s.size() >= 2 &&
is_contained({"==", "!=", "<=", ">=", "<<", ">>"}, s.substr(0, 2)))
((s[0] == s[1] && strchr("<>&|", s[0])) ||
is_contained({"==", "!=", "<=", ">=", "<<", ">>"}, s.substr(0, 2))))
pos = 2;
} else {
pos = s.find_first_not_of(
Expand Down Expand Up @@ -206,8 +198,6 @@ StringRef ScriptLexer::skipSpace(StringRef s) {
bool ScriptLexer::atEOF() { return eof || errorCount(); }

StringRef ScriptLexer::next() {
if (errorCount())
return "";
prevTok = peek();
return std::exchange(curTok, StringRef(curBuf.s.data(), 0));
}
Expand Down
5 changes: 5 additions & 0 deletions lld/ELF/ScriptLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class ScriptLexer {
struct Buffer {
// The remaining content to parse and the filename.
StringRef s, filename;
const char *begin = nullptr;
Buffer() = default;
Buffer(MemoryBufferRef mb)
: s(mb.getBuffer()), filename(mb.getBufferIdentifier()),
begin(mb.getBufferStart()) {}
};
// The current buffer and parent buffers due to INCLUDE.
Buffer curBuf;
Expand Down
13 changes: 7 additions & 6 deletions lld/ELF/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ void ScriptParser::readDynamicList() {
std::tie(locals, globals) = readSymbols();
expect(";");

if (peek() != "") {
setError("EOF expected, but got " + next());
StringRef tok = peek();
if (tok.size()) {
setError("EOF expected, but got " + tok);
return;
}
if (!locals.empty()) {
Expand All @@ -215,8 +216,9 @@ void ScriptParser::readDynamicList() {

void ScriptParser::readVersionScript() {
readVersionScriptCommand();
if (peek().size())
setError("EOF expected, but got " + next());
StringRef tok = peek();
if (tok.size())
setError("EOF expected, but got " + tok);
}

void ScriptParser::readVersionScriptCommand() {
Expand Down Expand Up @@ -415,8 +417,7 @@ void ScriptParser::readInclude() {
if (std::optional<std::string> path = searchScript(tok)) {
if (std::optional<MemoryBufferRef> mb = readFile(*path)) {
buffers.push_back(curBuf);
curBuf.s = mb->getBuffer();
curBuf.filename = mb->getBufferIdentifier();
curBuf = Buffer(*mb);
mbs.push_back(*mb);
}
return;
Expand Down
49 changes: 49 additions & 0 deletions lld/test/ELF/linkerscript/diag.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# REQUIRES: x86
# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o 0.o

#--- 1.lds
SECTIONS {
.text + { *(.text) }
.keep : { *(.keep) } /*
comment line 1
comment line 2 */
.temp : { *(.temp) }
}

# RUN: not ld.lld -shared 0.o -T 1.lds 2>&1 | FileCheck %s --check-prefix=CHECK1 --match-full-lines --strict-whitespace
# CHECK1:{{.*}}:2: malformed number: +
# CHECK1-NEXT:>>> .text + { *(.text) }
# CHECK1-NEXT:>>> ^

#--- 2.lds

UNKNOWN_TAG {
.text : { *(.text) }
.keep : { *(.keep) }
.temp : { *(.temp) }
}

# RUN: not ld.lld -shared 0.o -T 2.lds 2>&1 | FileCheck %s --check-prefix=CHECK2 --match-full-lines --strict-whitespace
# CHECK2:{{.*}}:2: unknown directive: UNKNOWN_TAG
# CHECK2-NEXT:>>> UNKNOWN_TAG {
# CHECK2-NEXT:>>> ^

#--- 3.lds
SECTIONS {
.text : { *(.text) }
.keep : { *(.keep) }
boom ^temp : { *(.temp) }
}
#--- 3a.lds
INCLUDE "3.lds"
#--- 3b.lds
foo = 3;
INCLUDE "3a.lds"

# RUN: not ld.lld -shared 0.o -T 3.lds 2>&1 | FileCheck %s --check-prefix=CHECK3 --match-full-lines --strict-whitespace
# RUN: not ld.lld -shared 0.o -T 3a.lds 2>&1 | FileCheck %s --check-prefix=CHECK3 --match-full-lines --strict-whitespace
# RUN: not ld.lld -shared 0.o -T 3b.lds 2>&1 | FileCheck %s --check-prefix=CHECK3 --match-full-lines --strict-whitespace
# CHECK3:{{.*}}3.lds:4: malformed number: ^
# CHECK3-NEXT:>>> boom ^temp : { *(.temp) }
# CHECK3-NEXT:>>> ^
15 changes: 0 additions & 15 deletions lld/test/ELF/linkerscript/diag1.test

This file was deleted.

13 changes: 0 additions & 13 deletions lld/test/ELF/linkerscript/diag2.test

This file was deleted.

13 changes: 0 additions & 13 deletions lld/test/ELF/linkerscript/diag3.test

This file was deleted.

14 changes: 0 additions & 14 deletions lld/test/ELF/linkerscript/diag4.test

This file was deleted.

14 changes: 0 additions & 14 deletions lld/test/ELF/linkerscript/diag5.test

This file was deleted.

7 changes: 0 additions & 7 deletions lld/test/ELF/linkerscript/diag6.test

This file was deleted.

File renamed without changes.
25 changes: 25 additions & 0 deletions lld/test/ELF/linkerscript/unquoted.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# REQUIRES: x86
# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o 0.o

#--- empty.lds
#--- 1.lds

SECTIONS /*
#--- 1a.lds
foo = 3;
INCLUDE "empty.lds"
INCLUDE "1.lds"

# RUN: not ld.lld -shared 0.o -T 1.lds 2>&1 | FileCheck %s --check-prefix=CHECK1 --match-full-lines --strict-whitespace
# RUN: not ld.lld -shared 0.o -T 1a.lds 2>&1 | FileCheck %s --check-prefix=CHECK1 --match-full-lines --strict-whitespace
# CHECK1:{{.*}}error: 1.lds:2: unclosed comment in a linker script
# CHECK1-NEXT:>>> SECTIONS /*
# CHECK1-NEXT:>>> ^

#--- 2.lds
INCLUDE "empty.lds"
"
# RUN: not ld.lld -shared 0.o -T 2.lds 2>&1 | FileCheck %s --check-prefix=CHECK2 --match-full-lines --strict-whitespace
# CHECK2:{{.*}}error: 2.lds:2: unclosed quote
# CHECK2-NOT:{{.}}
2 changes: 1 addition & 1 deletion lld/test/MachO/filelist.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## This test verifies that the paths in -filelist get processed in command-line
## order.

# RUN: rm -rf %t; split-file %s %t
# RUN: rm -rf %t; split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/first.s -o %t/first.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/second.s -o %t/second.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
Expand Down
20 changes: 0 additions & 20 deletions lldb/include/lldb/Core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define LLDB_CORE_PLUGINMANAGER_H

#include "lldb/Core/Architecture.h"
#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Utility/CompletionRequest.h"
#include "lldb/Utility/FileSpec.h"
Expand Down Expand Up @@ -488,25 +487,6 @@ class PluginManager {

static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();

// Scripted Interface
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
ScriptedInterfaceCreateInstance create_callback,
lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages);

static bool UnregisterPlugin(ScriptedInterfaceCreateInstance create_callback);

static uint32_t GetNumScriptedInterfaces();

static llvm::StringRef GetScriptedInterfaceNameAtIndex(uint32_t idx);

static llvm::StringRef GetScriptedInterfaceDescriptionAtIndex(uint32_t idx);

static lldb::ScriptLanguage GetScriptedInterfaceLanguageAtIndex(uint32_t idx);

static ScriptedInterfaceUsages
GetScriptedInterfaceUsagesAtIndex(uint32_t idx);

// REPL
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
REPLCreateInstance create_callback,
Expand Down
7 changes: 0 additions & 7 deletions lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#ifndef LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
#define LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H

#include "ScriptedInterfaceUsages.h"

#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
Expand Down Expand Up @@ -70,11 +68,6 @@ class ScriptedInterface {
return true;
}

static bool CreateInstance(lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages) {
return false;
}

protected:
StructuredData::GenericSP m_object_instance_sp;
};
Expand Down
43 changes: 0 additions & 43 deletions lldb/include/lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h

This file was deleted.

3 changes: 0 additions & 3 deletions lldb/include/lldb/lldb-private-interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Value;
} // namespace llvm

namespace lldb_private {
class ScriptedInterfaceUsages;
typedef lldb::ABISP (*ABICreateInstance)(lldb::ProcessSP process_sp,
const ArchSpec &arch);
typedef std::unique_ptr<Architecture> (*ArchitectureCreateInstance)(
Expand Down Expand Up @@ -125,8 +124,6 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error,
lldb::LanguageType language,
Debugger *debugger, Target *target,
const char *repl_options);
typedef bool (*ScriptedInterfaceCreateInstance)(lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages);
typedef int (*ComparisonFunction)(const void *, const void *);
typedef void (*DebuggerInitializeCallback)(Debugger &debugger);
/// Trace
Expand Down
126 changes: 2 additions & 124 deletions lldb/source/Commands/CommandObjectScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

#include "CommandObjectScripting.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandOptionArgumentTable.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Utility/Args.h"
Expand Down Expand Up @@ -129,126 +127,9 @@ class CommandObjectScriptingRun : public CommandObjectRaw {
CommandOptions m_options;
};

#define LLDB_OPTIONS_scripting_template_list
#include "CommandOptions.inc"

class CommandObjectScriptingTemplateList : public CommandObjectParsed {
public:
CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
: CommandObjectParsed(
interpreter, "scripting template list",
"List all the available scripting extension templates. ",
"scripting template list [--language <scripting-language> --]") {}

~CommandObjectScriptingTemplateList() override = default;

Options *GetOptions() override { return &m_options; }

class CommandOptions : public Options {
public:
CommandOptions() = default;
~CommandOptions() override = default;
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) override {
Status error;
const int short_option = m_getopt_table[option_idx].val;
#pragma mark CommandObjectMultiwordScripting

switch (short_option) {
case 'l':
m_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
option_arg, GetDefinitions()[option_idx].enum_values,
eScriptLanguageNone, error);
if (!error.Success())
error.SetErrorStringWithFormatv(
"unrecognized value for language '{0}'", option_arg);
break;
default:
llvm_unreachable("Unimplemented option");
}

return error;
}

void OptionParsingStarting(ExecutionContext *execution_context) override {
m_language = lldb::eScriptLanguageDefault;
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::ArrayRef(g_scripting_template_list_options);
}

lldb::ScriptLanguage m_language = lldb::eScriptLanguageDefault;
};

protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Stream &s = result.GetOutputStream();
s.Printf("Available scripted extension templates:");

auto print_field = [&s](llvm::StringRef key, llvm::StringRef value) {
if (!value.empty()) {
s.IndentMore();
s.Indent();
s << key << ": " << value << '\n';
s.IndentLess();
}
};

size_t num_listed_interface = 0;
size_t num_templates = PluginManager::GetNumScriptedInterfaces();
for (size_t i = 0; i < num_templates; i++) {
llvm::StringRef plugin_name =
PluginManager::GetScriptedInterfaceNameAtIndex(i);
if (plugin_name.empty())
break;

lldb::ScriptLanguage lang =
PluginManager::GetScriptedInterfaceLanguageAtIndex(i);
if (lang != m_options.m_language)
continue;

if (!num_listed_interface)
s.EOL();

num_listed_interface++;

llvm::StringRef desc =
PluginManager::GetScriptedInterfaceDescriptionAtIndex(i);
ScriptedInterfaceUsages usages =
PluginManager::GetScriptedInterfaceUsagesAtIndex(i);

print_field("Name", plugin_name);
print_field("Language", ScriptInterpreter::LanguageToString(lang));
print_field("Description", desc);
usages.Dump(s, ScriptedInterfaceUsages::UsageKind::API);
usages.Dump(s, ScriptedInterfaceUsages::UsageKind::CommandInterpreter);

if (i != num_templates - 1)
s.EOL();
}

if (!num_listed_interface)
s << " None\n";
}

private:
CommandOptions m_options;
};

class CommandObjectMultiwordScriptingTemplate : public CommandObjectMultiword {
public:
CommandObjectMultiwordScriptingTemplate(CommandInterpreter &interpreter)
: CommandObjectMultiword(
interpreter, "scripting template",
"Commands for operating on the scripting templates.",
"scripting template [<subcommand-options>]") {
LoadSubCommand(
"list",
CommandObjectSP(new CommandObjectScriptingTemplateList(interpreter)));
}

~CommandObjectMultiwordScriptingTemplate() override = default;
};
// CommandObjectMultiwordScripting

CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
CommandInterpreter &interpreter)
Expand All @@ -258,9 +139,6 @@ CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
"scripting <subcommand> [<subcommand-options>]") {
LoadSubCommand("run",
CommandObjectSP(new CommandObjectScriptingRun(interpreter)));
LoadSubCommand("template",
CommandObjectSP(
new CommandObjectMultiwordScriptingTemplate(interpreter)));
}

CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting() = default;
6 changes: 0 additions & 6 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -841,12 +841,6 @@ let Command = "scripting run" in {
" language. If none is specific the default scripting language is used.">;
}

let Command = "scripting template list" in {
def scripting_template_list_language : Option<"language", "l">,
EnumArg<"ScriptLang">, Desc<"Specify the scripting "
" language. If none is specified the default scripting language is used.">;
}

let Command = "source info" in {
def source_info_count : Option<"count", "c">, Arg<"Count">,
Desc<"The number of line entries to display.">;
Expand Down
65 changes: 0 additions & 65 deletions lldb/source/Core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,70 +1505,6 @@ LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
return all;
}

#pragma mark ScriptedInterfaces

struct ScriptedInterfaceInstance
: public PluginInstance<ScriptedInterfaceCreateInstance> {
ScriptedInterfaceInstance(llvm::StringRef name, llvm::StringRef description,
ScriptedInterfaceCreateInstance create_callback,
lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages)
: PluginInstance<ScriptedInterfaceCreateInstance>(name, description,
create_callback),
language(language), usages(usages) {}

lldb::ScriptLanguage language;
ScriptedInterfaceUsages usages;
};

typedef PluginInstances<ScriptedInterfaceInstance> ScriptedInterfaceInstances;

static ScriptedInterfaceInstances &GetScriptedInterfaceInstances() {
static ScriptedInterfaceInstances g_instances;
return g_instances;
}

bool PluginManager::RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
ScriptedInterfaceCreateInstance create_callback,
lldb::ScriptLanguage language, ScriptedInterfaceUsages usages) {
return GetScriptedInterfaceInstances().RegisterPlugin(
name, description, create_callback, language, usages);
}

bool PluginManager::UnregisterPlugin(
ScriptedInterfaceCreateInstance create_callback) {
return GetScriptedInterfaceInstances().UnregisterPlugin(create_callback);
}

uint32_t PluginManager::GetNumScriptedInterfaces() {
return GetScriptedInterfaceInstances().GetInstances().size();
}

llvm::StringRef PluginManager::GetScriptedInterfaceNameAtIndex(uint32_t index) {
return GetScriptedInterfaceInstances().GetNameAtIndex(index);
}

llvm::StringRef
PluginManager::GetScriptedInterfaceDescriptionAtIndex(uint32_t index) {
return GetScriptedInterfaceInstances().GetDescriptionAtIndex(index);
}

lldb::ScriptLanguage
PluginManager::GetScriptedInterfaceLanguageAtIndex(uint32_t idx) {
const auto &instances = GetScriptedInterfaceInstances().GetInstances();
return idx < instances.size() ? instances[idx].language
: ScriptLanguage::eScriptLanguageNone;
}

ScriptedInterfaceUsages
PluginManager::GetScriptedInterfaceUsagesAtIndex(uint32_t idx) {
const auto &instances = GetScriptedInterfaceInstances().GetInstances();
if (idx >= instances.size())
return {};
return instances[idx].usages;
}

#pragma mark REPL

struct REPLInstance : public PluginInstance<REPLCreateInstance> {
Expand Down Expand Up @@ -1629,7 +1565,6 @@ void PluginManager::DebuggerInitialize(Debugger &debugger) {
GetOperatingSystemInstances().PerformDebuggerCallback(debugger);
GetStructuredDataPluginInstances().PerformDebuggerCallback(debugger);
GetTracePluginInstances().PerformDebuggerCallback(debugger);
GetScriptedInterfaceInstances().PerformDebuggerCallback(debugger);
}

// This is the preferred new way to register plugin specific settings. e.g.
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ lldb_tablegen(InterpreterPropertiesEnum.inc -gen-lldb-property-enum-defs
SOURCE InterpreterProperties.td
TARGET LLDBInterpreterPropertiesEnumGen)

add_subdirectory(Interfaces)

add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
CommandAlias.cpp
CommandHistory.cpp
Expand Down Expand Up @@ -56,7 +54,6 @@ add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
ScriptInterpreter.cpp

LINK_LIBS
lldbInterpreterInterfaces
lldbCommands
lldbCore
lldbDataFormatters
Expand All @@ -69,7 +66,6 @@ add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
)

add_dependencies(lldbInterpreter
lldbInterpreterInterfaces
LLDBInterpreterPropertiesGen
LLDBInterpreterPropertiesEnumGen)

10 changes: 0 additions & 10 deletions lldb/source/Interpreter/Interfaces/CMakeLists.txt

This file was deleted.

37 changes: 0 additions & 37 deletions lldb/source/Interpreter/Interfaces/ScriptedInterfaceUsages.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ if (LLDB_ENABLE_LIBEDIT)
endif()

add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
OperatingSystemPythonInterface.cpp
ScriptedPythonInterface.cpp
ScriptedProcessPythonInterface.cpp
ScriptedThreadPythonInterface.cpp
ScriptedThreadPlanPythonInterface.cpp
ScriptedPlatformPythonInterface.cpp

LINK_LIBS
lldbCore
Expand All @@ -34,9 +38,3 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
LINK_COMPONENTS
Support
)

add_subdirectory(OperatingSystemPythonInterface)
add_subdirectory(ScriptedPlatformPythonInterface)
add_subdirectory(ScriptedProcessPythonInterface)
add_subdirectory(ScriptedThreadPlanPythonInterface)

Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,25 @@
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/Log.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#include "../lldb-python.h"

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "OperatingSystemPythonInterface.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;
using Locker = ScriptInterpreterPythonImpl::Locker;

LLDB_PLUGIN_DEFINE_ADV(OperatingSystemPythonInterface, ScriptInterpreterPythonOperatingSystemPythonInterface)

OperatingSystemPythonInterface::OperatingSystemPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {}
Expand Down Expand Up @@ -84,18 +79,4 @@ OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
return obj->GetAsString()->GetValue().str();
}

void OperatingSystemPythonInterface::Initialize() {
const std::vector<llvm::StringRef> ci_usages = {
"settings set target.process.python-os-plugin-path <script-path>",
"settings set process.experimental.os-plugin-reports-all-threads [0/1]"};
const std::vector<llvm::StringRef> api_usages = {};
PluginManager::RegisterPlugin(
GetPluginNameStatic(), llvm::StringRef("Mock thread state"),
CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
}

void OperatingSystemPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,18 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/OperatingSystemInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedThreadPythonInterface.h"

#include "ScriptedThreadPythonInterface.h"
#include "lldb/Interpreter/Interfaces/OperatingSystemInterface.h"
#include <optional>

namespace lldb_private {
class OperatingSystemPythonInterface
: virtual public OperatingSystemInterface,
virtual public ScriptedThreadPythonInterface,
public PluginInterface {
virtual public ScriptedThreadPythonInterface {
public:
OperatingSystemPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand All @@ -51,16 +41,6 @@ class OperatingSystemPythonInterface
StructuredData::DictionarySP GetRegisterInfo() override;

std::optional<std::string> GetRegisterContextForTID(lldb::tid_t tid) override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "OperatingSystemPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
} // namespace lldb_private

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,27 @@
//
//===----------------------------------------------------------------------===//

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on

#endif

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
// LLDB Python header must be included first
#include "../lldb-python.h"

#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedPlatformPythonInterface.h"

#include "lldb/Target/ExecutionContext.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;
using Locker = ScriptInterpreterPythonImpl::Locker;

LLDB_PLUGIN_DEFINE_ADV(ScriptedPlatformPythonInterface, ScriptInterpreterPythonScriptedPlatformPythonInterface)

ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
Expand Down Expand Up @@ -101,14 +93,4 @@ Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) {
return GetStatusFromMethod("kill_process", pid);
}

void ScriptedPlatformPythonInterface::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), "Mock platform and interact with its processes.",
CreateInstance, eScriptLanguagePython, {});
}

void ScriptedPlatformPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif // LLDB_ENABLE_PYTHON
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPLATFORMPYTHONINTERFACE_H

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedPythonInterface.h"
#include "ScriptedPythonInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h"

namespace lldb_private {
class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
public ScriptedPythonInterface,
public PluginInterface {
public ScriptedPythonInterface {
public:
ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand All @@ -44,16 +43,6 @@ class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) override;

Status KillProcess(lldb::pid_t pid) override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "ScriptedPlatformPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
} // namespace lldb_private

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,29 @@
//
//===----------------------------------------------------------------------===//

#include "lldb/Host/Config.h"
#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#include "../lldb-python.h"
#endif

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
#include "../ScriptedThreadPythonInterface.h"
#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedProcessPythonInterface.h"

#include "ScriptedThreadPythonInterface.h"
#include <optional>

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;
using Locker = ScriptInterpreterPythonImpl::Locker;

LLDB_PLUGIN_DEFINE_ADV(ScriptedProcessPythonInterface, ScriptInterpreterPythonScriptedProcessPythonInterface)

ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedProcessInterface(), ScriptedPythonInterface(interpreter) {}
Expand Down Expand Up @@ -216,24 +208,4 @@ StructuredData::DictionarySP ScriptedProcessPythonInterface::GetMetadata() {
return dict;
}

void ScriptedProcessPythonInterface::Initialize() {
const std::vector<llvm::StringRef> ci_usages = {
"process attach -C <script-name> [-k key -v value ...]",
"process launch -C <script-name> [-k key -v value ...]"};
const std::vector<llvm::StringRef> api_usages = {
"SBAttachInfo.SetScriptedProcessClassName",
"SBAttachInfo.SetScriptedProcessDictionary",
"SBTarget.Attach",
"SBLaunchInfo.SetScriptedProcessClassName",
"SBLaunchInfo.SetScriptedProcessDictionary",
"SBTarget.Launch"};
PluginManager::RegisterPlugin(
GetPluginNameStatic(), llvm::StringRef("Mock process state"),
CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
}

void ScriptedProcessPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPROCESSPYTHONINTERFACE_H

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedPythonInterface.h"

#include "ScriptedPythonInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h"
#include <optional>

namespace lldb_private {
class ScriptedProcessPythonInterface : public ScriptedProcessInterface,
public ScriptedPythonInterface,
public PluginInterface {
public ScriptedPythonInterface {
public:
ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand Down Expand Up @@ -69,16 +67,6 @@ class ScriptedProcessPythonInterface : public ScriptedProcessInterface,

StructuredData::DictionarySP GetMetadata() override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "ScriptedProcessPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }

private:
lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override;
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Utility/Log.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#include "../lldb-python.h"

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedThreadPlanPythonInterface.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;

LLDB_PLUGIN_DEFINE_ADV(ScriptedThreadPlanPythonInterface, ScriptInterpreterPythonScriptedThreadPlanPythonInterface)

ScriptedThreadPlanPythonInterface::ScriptedThreadPlanPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedThreadPlanInterface(), ScriptedPythonInterface(interpreter) {}
Expand Down Expand Up @@ -107,19 +102,4 @@ ScriptedThreadPlanPythonInterface::GetStopDescription(lldb::StreamSP &stream) {
return llvm::Error::success();
}

void ScriptedThreadPlanPythonInterface::Initialize() {
const std::vector<llvm::StringRef> ci_usages = {
"thread step-scripted -C <script-name> [-k key -v value ...]"};
const std::vector<llvm::StringRef> api_usages = {
"SBThread.StepUsingScriptedThreadPlan"};
PluginManager::RegisterPlugin(
GetPluginNameStatic(),
llvm::StringRef("Alter thread stepping logic and stop reason"),
CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
}

void ScriptedThreadPlanPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,17 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPLANPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPLANPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on

#endif

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedPythonInterface.h"

#include "ScriptedPythonInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h"
#include <optional>

namespace lldb_private {
class ScriptedThreadPlanPythonInterface : public ScriptedThreadPlanInterface,
public ScriptedPythonInterface,
public PluginInterface {
public ScriptedPythonInterface {
public:
ScriptedThreadPlanPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand All @@ -52,16 +41,6 @@ class ScriptedThreadPlanPythonInterface : public ScriptedThreadPlanInterface,
lldb::StateType GetRunState() override;

llvm::Error GetStopDescription(lldb::StreamSP &stream) override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "ScriptedThreadPlanPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
} // namespace lldb_private

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// LLDB Python header must be included first
#include "lldb-python.h"

#include "Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.h"
#include "Interfaces/ScriptedPlatformPythonInterface/ScriptedPlatformPythonInterface.h"
#include "Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h"
#include "Interfaces/ScriptedThreadPlanPythonInterface/ScriptedThreadPlanPythonInterface.h"
#include "Interfaces/OperatingSystemPythonInterface.h"
#include "Interfaces/ScriptedPlatformPythonInterface.h"
#include "Interfaces/ScriptedProcessPythonInterface.h"
#include "Interfaces/ScriptedThreadPlanPythonInterface.h"
#include "Interfaces/ScriptedThreadPythonInterface.h"
#include "PythonDataObjects.h"
#include "PythonReadline.h"
Expand Down
80 changes: 49 additions & 31 deletions llvm/include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ class DenseMapBase : public DebugEpochBase {

/// Return true if the specified key is in the map, false otherwise.
bool contains(const_arg_type_t<KeyT> Val) const {
const BucketT *TheBucket;
return LookupBucketFor(Val, TheBucket);
return doFind(Val) != nullptr;
}

/// Return 1 if the specified key is in the map, 0 otherwise.
Expand All @@ -153,21 +152,17 @@ class DenseMapBase : public DebugEpochBase {
}

iterator find(const_arg_type_t<KeyT> Val) {
BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
return makeIterator(TheBucket,
shouldReverseIterate<KeyT>() ? getBuckets()
: getBucketsEnd(),
*this, true);
if (BucketT *Bucket = doFind(Val))
return makeIterator(
Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
*this, true);
return end();
}
const_iterator find(const_arg_type_t<KeyT> Val) const {
const BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
return makeConstIterator(TheBucket,
shouldReverseIterate<KeyT>() ? getBuckets()
: getBucketsEnd(),
*this, true);
if (const BucketT *Bucket = doFind(Val))
return makeConstIterator(
Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
*this, true);
return end();
}

Expand All @@ -178,31 +173,26 @@ class DenseMapBase : public DebugEpochBase {
/// type used.
template<class LookupKeyT>
iterator find_as(const LookupKeyT &Val) {
BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
return makeIterator(TheBucket,
shouldReverseIterate<KeyT>() ? getBuckets()
: getBucketsEnd(),
*this, true);
if (BucketT *Bucket = doFind(Val))
return makeIterator(
Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
*this, true);
return end();
}
template<class LookupKeyT>
const_iterator find_as(const LookupKeyT &Val) const {
const BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
return makeConstIterator(TheBucket,
shouldReverseIterate<KeyT>() ? getBuckets()
: getBucketsEnd(),
*this, true);
if (const BucketT *Bucket = doFind(Val))
return makeConstIterator(
Bucket, shouldReverseIterate<KeyT>() ? getBuckets() : getBucketsEnd(),
*this, true);
return end();
}

/// lookup - Return the entry for the specified key, or a default
/// constructed value if no such entry exists.
ValueT lookup(const_arg_type_t<KeyT> Val) const {
const BucketT *TheBucket;
if (LookupBucketFor(Val, TheBucket))
return TheBucket->getSecond();
if (const BucketT *Bucket = doFind(Val))
return Bucket->getSecond();
return ValueT();
}

Expand Down Expand Up @@ -343,8 +333,8 @@ class DenseMapBase : public DebugEpochBase {
}

bool erase(const KeyT &Val) {
BucketT *TheBucket;
if (!LookupBucketFor(Val, TheBucket))
BucketT *TheBucket = doFind(Val);
if (!TheBucket)
return false; // not in map.

TheBucket->getSecond().~ValueT();
Expand Down Expand Up @@ -643,6 +633,34 @@ class DenseMapBase : public DebugEpochBase {
return TheBucket;
}

template <typename LookupKeyT> BucketT *doFind(const LookupKeyT &Val) {
BucketT *BucketsPtr = getBuckets();
const unsigned NumBuckets = getNumBuckets();
if (NumBuckets == 0)
return nullptr;

const KeyT EmptyKey = getEmptyKey();
unsigned BucketNo = getHashValue(Val) & (NumBuckets - 1);
unsigned ProbeAmt = 1;
while (true) {
BucketT *Bucket = BucketsPtr + BucketNo;
if (LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
return Bucket;
if (LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
return nullptr;

// Otherwise, it's a hash collision or a tombstone, continue quadratic
// probing.
BucketNo += ProbeAmt++;
BucketNo &= NumBuckets - 1;
}
}

template <typename LookupKeyT>
const BucketT *doFind(const LookupKeyT &Val) const {
return const_cast<DenseMapBase *>(this)->doFind(Val); // NOLINT
}

/// LookupBucketFor - Lookup the appropriate bucket for Val, returning it in
/// FoundBucket. If the bucket contains the key and a value, this returns
/// true, otherwise it returns a bucket with an empty marker or tombstone and
Expand Down
88 changes: 41 additions & 47 deletions llvm/include/llvm/Analysis/DXILResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ class MDTuple;

namespace dxil {

struct ResourceBinding {
uint32_t Space;
uint32_t LowerBound;
uint32_t Size;

bool operator==(const ResourceBinding &RHS) const {
return std::tie(Space, LowerBound, Size) ==
std::tie(RHS.Space, RHS.LowerBound, RHS.Size);
}
bool operator!=(const ResourceBinding &RHS) const { return !(*this == RHS); }
};

class ResourceInfo {
struct ResourceBinding {
uint32_t UniqueID;
uint32_t Space;
uint32_t LowerBound;
uint32_t Size;

bool operator==(const ResourceBinding &RHS) const {
return std::tie(UniqueID, Space, LowerBound, Size) ==
std::tie(RHS.UniqueID, RHS.Space, RHS.LowerBound, RHS.Size);
}
bool operator!=(const ResourceBinding &RHS) const {
return !(*this == RHS);
}
};

struct UAVInfo {
bool GloballyCoherent;
bool HasCounter;
Expand Down Expand Up @@ -81,12 +84,11 @@ class ResourceInfo {
Value *Symbol;
StringRef Name;

ResourceBinding Binding;
uint32_t UniqueID;

dxil::ResourceClass RC;
dxil::ResourceKind Kind;

ResourceBinding Binding = {};

// Resource class dependent properties.
// CBuffer, Sampler, and RawBuffer end here.
union {
Expand Down Expand Up @@ -114,70 +116,62 @@ class ResourceInfo {
bool isMultiSample() const;

ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
StringRef Name, ResourceBinding Binding, uint32_t UniqueID)
: Symbol(Symbol), Name(Name), Binding(Binding), UniqueID(UniqueID),
RC(RC), Kind(Kind) {}
StringRef Name)
: Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}

public:
static ResourceInfo SRV(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy, uint32_t ElementCount,
dxil::ResourceKind Kind);
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID);
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID, uint32_t Stride,
Align Alignment);
uint32_t Stride, Align Alignment);
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount);
static ResourceInfo
Texture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
uint32_t UniqueID, dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount);
static ResourceInfo Texture2DMSArray(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount);

static ResourceInfo UAV(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy, uint32_t ElementCount,
bool GloballyCoherent, bool IsROV,
dxil::ResourceKind Kind);
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
bool GloballyCoherent, bool IsROV);
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID, uint32_t Stride,
uint32_t Stride,
Align Alignment, bool GloballyCoherent,
bool IsROV, bool HasCounter);
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount,
bool GloballyCoherent);
static ResourceInfo
RWTexture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
uint32_t UniqueID, dxil::ElementType ElementTy,
uint32_t ElementCount, uint32_t SampleCount,
bool GloballyCoherent);
static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy,
uint32_t ElementCount,
uint32_t SampleCount,
bool GloballyCoherent);
static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name,
ResourceBinding Binding,
uint32_t UniqueID,
dxil::SamplerFeedbackType FeedbackTy);
static ResourceInfo
FeedbackTexture2DArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
uint32_t UniqueID,
FeedbackTexture2DArray(Value *Symbol, StringRef Name,
dxil::SamplerFeedbackType FeedbackTy);

static ResourceInfo CBuffer(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
uint32_t Size);
static ResourceInfo CBuffer(Value *Symbol, StringRef Name, uint32_t Size);

static ResourceInfo Sampler(Value *Symbol, StringRef Name,
ResourceBinding Binding, uint32_t UniqueID,
dxil::SamplerType SamplerTy);

void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
uint32_t Size) {
Binding.UniqueID = UniqueID;
Binding.Space = Space;
Binding.LowerBound = LowerBound;
Binding.Size = Size;
}

bool operator==(const ResourceInfo &RHS) const;

MDTuple *getAsMetadata(LLVMContext &Ctx) const;
Expand Down
20 changes: 18 additions & 2 deletions llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,8 @@ class OpenMPIRBuilder {
/// The total number of pointers passed to the runtime library.
unsigned NumberOfPtrs = 0u;

bool EmitDebug = false;

explicit TargetDataInfo() {}
explicit TargetDataInfo(bool RequiresDevicePointerInfo,
bool SeparateBeginEndCalls)
Expand Down Expand Up @@ -2349,7 +2351,6 @@ class OpenMPIRBuilder {
void emitOffloadingArraysArgument(IRBuilderBase &Builder,
OpenMPIRBuilder::TargetDataRTArgs &RTArgs,
OpenMPIRBuilder::TargetDataInfo &Info,
bool EmitDebug = false,
bool ForEndCall = false);

/// Emit an array of struct descriptors to be assigned to the offload args.
Expand All @@ -2360,13 +2361,28 @@ class OpenMPIRBuilder {

/// Emit the arrays used to pass the captures and map information to the
/// offloading runtime library. If there is no map or capture information,
/// return nullptr by reference.
/// return nullptr by reference. Accepts a reference to a MapInfosTy object
/// that contains information generated for mappable clauses,
/// including base pointers, pointers, sizes, map types, user-defined mappers.
void emitOffloadingArrays(
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, MapInfosTy &CombinedInfo,
TargetDataInfo &Info, bool IsNonContiguous = false,
function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr,
function_ref<Value *(unsigned int)> CustomMapperCB = nullptr);

/// Allocates memory for and populates the arrays required for offloading
/// (offload_{baseptrs|ptrs|mappers|sizes|maptypes|mapnames}). Then, it
/// emits their base addresses as arguments to be passed to the runtime
/// library. In essence, this function is a combination of
/// emitOffloadingArrays and emitOffloadingArraysArgument and should arguably
/// be preferred by clients of OpenMPIRBuilder.
void emitOffloadingArraysAndArgs(
InsertPointTy AllocaIP, InsertPointTy CodeGenIP, TargetDataInfo &Info,
TargetDataRTArgs &RTArgs, MapInfosTy &CombinedInfo,
bool IsNonContiguous = false, bool ForEndCall = false,
function_ref<void(unsigned int, Value *)> DeviceAddrCB = nullptr,
function_ref<Value *(unsigned int)> CustomMapperCB = nullptr);

/// Creates offloading entry for the provided entry ID \a ID, address \a
/// Addr, size \a Size, and flags \a Flags.
void createOffloadEntry(Constant *ID, Constant *Addr, uint64_t Size,
Expand Down
2 changes: 0 additions & 2 deletions llvm/include/llvm/MC/MCPseudoProbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,6 @@ class MCDecodedPseudoProbeInlineTree
MCDecodedPseudoProbeInlineTree> {
public:
InlineSite ISite;
// Used for decoding
uint32_t ChildrenToProcess = 0;

MCDecodedPseudoProbeInlineTree() = default;
MCDecodedPseudoProbeInlineTree(const InlineSite &Site) : ISite(Site){};
Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/Support/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,13 @@ template <typename T> class SpecificBumpPtrAllocator {

/// Allocate space for an array of objects without constructing them.
T *Allocate(size_t num = 1) { return Allocator.Allocate<T>(num); }

/// \return An index uniquely and reproducibly identifying
/// an input pointer \p Ptr in the given allocator.
/// Returns an empty optional if the pointer is not found in the allocator.
std::optional<int64_t> identifyObject(const void *Ptr) {
return Allocator.identifyObject(Ptr);
}
};

} // end namespace llvm
Expand Down
Loading