Skip to content

Commit

Permalink
Merged main:81e3e7e5d455 into amd-gfx:207601c46e4e
Browse files Browse the repository at this point in the history
Local branch amd-gfx 207601c Merged main:d6783c7c98ac into amd-gfx:8de17e533347
Remote branch main 81e3e7e [libc] [search] implement hcreate(_r)/hsearch(_r)/hdestroy(_r) (llvm#73469)
  • Loading branch information
SC llvm team authored and SC llvm team committed Nov 29, 2023
2 parents 207601c + 81e3e7e commit 606d2d4
Show file tree
Hide file tree
Showing 110 changed files with 2,764 additions and 148 deletions.
2 changes: 1 addition & 1 deletion bolt/lib/Core/DIEBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void DIEBuilder::buildTypeUnits(const bool Init) {
true);
}
}
unsigned int CUNum = getCUNum(DwarfContext, IsDWO);
const unsigned int CUNum = getCUNum(DwarfContext, IsDWO);
getState().CloneUnitCtxMap.resize(CUNum);
DWARFContext::unit_iterator_range CU4TURanges =
IsDWO ? DwarfContext->dwo_types_section_units()
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/AttributeCommonInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class AttributeCommonInfo {
IsRegularKeywordAttribute);
}
const IdentifierInfo *getAttrName() const { return AttrName; }
void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; }
SourceLocation getLoc() const { return AttrRange.getBegin(); }
SourceRange getRange() const { return AttrRange; }
void setRange(SourceRange R) { AttrRange = R; }
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9073,6 +9073,7 @@ class AttrImporter {

ToAttr = FromAttr->clone(Importer.getToContext());
ToAttr->setRange(ToRange);
ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
}

// Get the result of the previous import attempt (can be used only once).
Expand Down
13 changes: 11 additions & 2 deletions clang/unittests/AST/ASTImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "clang/AST/RecordLayout.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Testing/CommandLineArgs.h"
#include "llvm/Support/SmallVectorMemoryBuffer.h"

#include "clang/AST/DeclContextInternals.h"
Expand Down Expand Up @@ -7379,11 +7380,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase {
}

template <class DT, class AT>
void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) {
void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr,
TestLanguage Lang = Lang_CXX11) {
static_assert(std::is_base_of<Attr, AT>::value, "AT should be an Attr");
static_assert(std::is_base_of<Decl, DT>::value, "DT should be a Decl");

Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
DT *FromD =
FirstDeclMatcher<DT>().match(FromTU, namedDecl(hasName("test")));
ASSERT_TRUE(FromD);
Expand Down Expand Up @@ -7669,6 +7671,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
checkImportVariadicArg(FromAttr->args(), ToAttr->args());
}

TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
NoThrowAttr *FromAttr, *ToAttr;
importAttr<FunctionDecl>("void test () __attribute__ ((__nothrow__));",
FromAttr, ToAttr, Lang_C99);
checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
}

template <typename T>
auto ExtendWithOptions(const T &Values, const std::vector<std::string> &Args) {
auto Copy = Values;
Expand Down
7 changes: 7 additions & 0 deletions libc/cmake/modules/LLVMLibCFlagRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ endfunction(get_fq_dep_list_without_flag)
# Special flags
set(FMA_OPT_FLAG "FMA_OPT")
set(ROUND_OPT_FLAG "ROUND_OPT")
# SSE2 is the baseline for x86_64, so we add a negative flag to disable it if needed.
set(DISABLE_SSE2_OPT_FLAG "DISABLE_SSE2_OPT")

# Skip FMA_OPT flag for targets that don't support fma.
if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
Expand All @@ -143,3 +145,8 @@ endif()
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")))
set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE)
endif()

# Skip DISABLE_SSE2_OPT flag for targets that don't support SSE2.
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
set(SKIP_FLAG_EXPANSION_DISABLE_SSE2_OPT TRUE)
endif()
14 changes: 14 additions & 0 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ function(_get_common_compile_options output_var flags)
set(ADD_SSE4_2_FLAG TRUE)
endif()

list(FIND flags ${DISABLE_SSE2_OPT_FLAG} no_sse2)
if(${no_sse2} LESS 0)
list(FIND flags "${DISABLE_SSE2_OPT_FLAG}__ONLY" no_sse2)
endif()
if((${no_sse2} GREATER -1) AND (LIBC_CPU_FEATURES MATCHES "SSE2"))
set(DISABLE_SSE2_FLAG TRUE)
endif()

set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN})
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND compile_options "-fpie")
Expand Down Expand Up @@ -58,12 +66,18 @@ function(_get_common_compile_options output_var flags)
if(ADD_SSE4_2_FLAG)
list(APPEND compile_options "-msse4.2")
endif()
if(DISABLE_SSE2_FLAG)
list(APPEND compile_options "-mno-sse2")
endif()
elseif(MSVC)
list(APPEND compile_options "/EHs-c-")
list(APPEND compile_options "/GR-")
if(ADD_FMA_FLAG)
list(APPEND compile_options "/arch:AVX2")
endif()
if(DISABLE_SSE2_FLAG)
list(APPEND compile_options "/arch:SSE")
endif()
endif()
if (LIBC_TARGET_ARCHITECTURE_IS_GPU)
list(APPEND compile_options "-nogpulib")
Expand Down
8 changes: 8 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ set(TARGET_LIBC_ENTRYPOINTS
#libc.src.stdio.scanf
#libc.src.stdio.fscanf

# search.h entrypoints
libc.src.search.hcreate
libc.src.search.hcreate_r
libc.src.search.hsearch
libc.src.search.hsearch_r
libc.src.search.hdestroy
libc.src.search.hdestroy_r

# sys/mman.h entrypoints
libc.src.sys.mman.madvise
libc.src.sys.mman.mmap
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.stdlib
libc.include.string
libc.include.strings
libc.include.search
libc.include.sys_mman
libc.include.sys_socket
libc.include.sys_syscall
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,7 @@ def TermiosAPI : PublicAPI<"termios.h"> {
def SetJmpAPI : PublicAPI<"setjmp.h"> {
let Types = ["jmp_buf"];
}

def SearchAPI : PublicAPI<"search.h"> {
let Types = ["ACTION", "ENTRY", "struct hsearch_data"];
}
8 changes: 8 additions & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdlib.strtoul
libc.src.stdlib.strtoull

# search.h entrypoints
libc.src.search.hcreate
libc.src.search.hcreate_r
libc.src.search.hsearch
libc.src.search.hsearch_r
libc.src.search.hdestroy
libc.src.search.hdestroy_r

# sys/mman.h entrypoints
libc.src.sys.mman.mmap
libc.src.sys.mman.munmap
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ set(TARGET_PUBLIC_HEADERS
libc.include.stdlib
libc.include.string
libc.include.strings
libc.include.search
)
8 changes: 8 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.scanf
libc.src.stdio.fscanf

# search.h entrypoints
libc.src.search.hcreate
libc.src.search.hcreate_r
libc.src.search.hsearch
libc.src.search.hsearch_r
libc.src.search.hdestroy
libc.src.search.hdestroy_r

# sys/mman.h entrypoints
libc.src.sys.mman.madvise
libc.src.sys.mman.mmap
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.stdlib
libc.include.string
libc.include.strings
libc.include.search
libc.include.termios
libc.include.threads
libc.include.time
Expand Down
8 changes: 8 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,14 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.spawn.posix_spawn_file_actions_destroy
libc.src.spawn.posix_spawn_file_actions_init

# search.h entrypoints
libc.src.search.hcreate
libc.src.search.hcreate_r
libc.src.search.hsearch
libc.src.search.hsearch_r
libc.src.search.hdestroy
libc.src.search.hdestroy_r

# threads.h entrypoints
libc.src.threads.call_once
libc.src.threads.cnd_broadcast
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.stdlib
libc.include.string
libc.include.strings
libc.include.search
libc.include.termios
libc.include.threads
libc.include.time
Expand Down
12 changes: 12 additions & 0 deletions libc/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ add_gen_header(
.llvm-libc-types.size_t
)

add_gen_header(
search
DEF_FILE search.h.def
GEN_HDR search.h
DEPENDS
.llvm_libc_common_h
.llvm-libc-types.ACTION
.llvm-libc-types.ENTRY
.llvm-libc-types.struct_hsearch_data
.llvm-libc-types.size_t
)

add_gen_header(
time
DEF_FILE time.h.def
Expand Down
14 changes: 14 additions & 0 deletions libc/include/llvm-libc-types/ACTION.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//===-- Definition of ACTION type -----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef __LLVM_LIBC_TYPES_ACTION_H__
#define __LLVM_LIBC_TYPES_ACTION_H__

typedef enum { FIND, ENTER } ACTION;

#endif // __LLVM_LIBC_TYPES_ACTION_H__
3 changes: 3 additions & 0 deletions libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ add_header(wint_t HDR wint_t.h)
add_header(sa_family_t HDR sa_family_t.h)
add_header(struct_sockaddr HDR struct_sockaddr.h)
add_header(rpc_opcodes_t HDR rpc_opcodes_t.h)
add_header(ACTION HDR ACTION.h)
add_header(ENTRY HDR ENTRY.h)
add_header(struct_hsearch_data HDR struct_hsearch_data.h)
17 changes: 17 additions & 0 deletions libc/include/llvm-libc-types/ENTRY.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Definition of ENTRY type ------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef __LLVM_LIBC_TYPES_ENTRY_H__
#define __LLVM_LIBC_TYPES_ENTRY_H__

typedef struct {
char *key;
void *data;
} ENTRY;

#endif // __LLVM_LIBC_TYPES_ENTRY_H__
17 changes: 17 additions & 0 deletions libc/include/llvm-libc-types/struct_hsearch_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//===-- Definition of type struct hsearch_data ----------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef __LLVM_LIBC_TYPES_STRUCT_HSEARCH_DATA_H__
#define __LLVM_LIBC_TYPES_STRUCT_HSEARCH_DATA_H__

struct hsearch_data {
void *__opaque;
unsigned int __unused[2];
};

#endif // __LLVM_LIBC_TYPES_STRUCT_HSEARCH_DATA_H__
18 changes: 18 additions & 0 deletions libc/include/search.h.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- POSIX header search.h ---------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SEARCH_H
#define LLVM_LIBC_SEARCH_H

#include <__llvm-libc-common.h>
#define __need_size_t
#include <stddef.h>

%%public_api()

#endif // LLVM_LIBC_SEARCH_H
40 changes: 39 additions & 1 deletion libc/spec/gnu_ext.td
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ def CpuSetPtr : PtrType<CpuSetT>;
def ConstCpuSetPtr : ConstType<CpuSetPtr>;

def QSortRCompareT : NamedType<"__qsortrcompare_t">;
def StructHsearchData : NamedType<"struct hsearch_data">;
def StructHsearchDataPtr : PtrType<StructHsearchData>;

def GnuExtensions : StandardSpec<"GNUExtensions"> {
NamedType CookieIOFunctionsT = NamedType<"cookie_io_functions_t">;
Expand Down Expand Up @@ -54,7 +56,6 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
>,
]
>;

HeaderSpec String = HeaderSpec<
"string.h",
[], // Macros
Expand Down Expand Up @@ -89,6 +90,42 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
]
>;

HeaderSpec Search = HeaderSpec<
"search.h",
[], // Macros
[
StructHsearchData
],
[], // Enumerations
[
FunctionSpec<
"hcreate_r",
RetValSpec<IntType>,
[
ArgSpec<SizeTType>,
ArgSpec<StructHsearchDataPtr>
]
>,
FunctionSpec<
"hdestroy_r",
RetValSpec<VoidType>,
[
ArgSpec<StructHsearchDataPtr>
]
>,
FunctionSpec<
"hsearch_r",
RetValSpec<IntType>,
[
ArgSpec<EntryType>,
ArgSpec<ActionType>,
ArgSpec<EntryTypePtrPtr>,
ArgSpec<StructHsearchDataPtr>
]
>,
]
>;

HeaderSpec FEnv = HeaderSpec<
"fenv.h",
[], // Macros
Expand Down Expand Up @@ -243,6 +280,7 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
StdIO,
StdLib,
String,
Search,
UniStd,
];
}
Loading

0 comments on commit 606d2d4

Please sign in to comment.