| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Test how BOLT handles indirect branch sequence of instructions in | ||
| // AArch64MCPlus builder. | ||
|
|
||
| // clang-format off | ||
|
|
||
| // REQUIRES: system-linux | ||
| // RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o | ||
| // RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q | ||
| // RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg --strict\ | ||
| // RUN: -v=1 2>&1 | FileCheck %s | ||
|
|
||
| // Pattern 1: there is no shift amount after the 'add' instruction. | ||
| // | ||
| // adr x6, 0x219fb0 <sigall_set+0x88> | ||
| // add x6, x6, x14, lsl #2 | ||
| // ldr w7, [x6] | ||
| // add x6, x6, w7, sxtw => no shift amount | ||
| // br x6 | ||
| // | ||
|
|
||
| // Pattern 2: nop/adr pair is used in place of adrp/add | ||
| // | ||
| // nop => nop/adr instead of adrp/add | ||
| // adr x13, 0x215a18 <_nl_value_type_LC_COLLATE+0x50> | ||
| // ldrh w13, [x13, w12, uxtw #1] | ||
| // adr x12, 0x247b30 <__gettextparse+0x5b0> | ||
| // add x13, x12, w13, sxth #2 | ||
| // br x13 | ||
|
|
||
| .section .text | ||
| .align 4 | ||
| .globl _start | ||
| .type _start, %function | ||
| _start: | ||
| bl test1 | ||
| bl test2 | ||
| // mov x0, #4 | ||
| // mov w8, #93 | ||
| // svc #0 | ||
|
|
||
| // Pattern 1 | ||
| // CHECK: BOLT-WARNING: Failed to match indirect branch: ShiftVAL != 2 | ||
| .globl test1 | ||
| .type test1, %function | ||
| test1: | ||
| mov x1, #0 | ||
| adr x3, datatable | ||
| add x3, x3, x1, lsl #2 | ||
| ldr w2, [x3] | ||
| add x3, x3, w2, sxtw | ||
| br x3 | ||
| test1_0: | ||
| ret | ||
| test1_1: | ||
| ret | ||
| test1_2: | ||
| ret | ||
|
|
||
| // Pattern 2 | ||
| // CHECK: BOLT-WARNING: Failed to match indirect branch: nop/adr instead of adrp/add | ||
| .globl test2 | ||
| .type test2, %function | ||
| test2: | ||
| nop | ||
| adr x3, jump_table | ||
| ldrh w3, [x3, x1, lsl #1] | ||
| adr x1, test2_0 | ||
| add x3, x1, w3, sxth #2 | ||
| br x3 | ||
| test2_0: | ||
| ret | ||
| test2_1: | ||
| ret | ||
|
|
||
| .section .rodata,"a",@progbits | ||
| datatable: | ||
| .word test1_0-datatable | ||
| .word test1_1-datatable | ||
| .word test1_2-datatable | ||
|
|
||
| jump_table: | ||
| .hword (test2_0-test2_0)>>2 | ||
| .hword (test2_1-test2_0)>>2 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
|
|
||
| inline int func2(int i); | ||
| int external_call2(int i) { | ||
| // expected-error@+1 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}} | ||
| [[clang::musttail]] return func2(i); | ||
| } | ||
|
|
||
| inline int func2(int i) { | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
|
|
||
| int func2(int i); | ||
| int external_call2(int i) { | ||
| // expected-error@+1 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}} | ||
| [[clang::musttail]] return func2(i); | ||
| } | ||
|
|
||
| __attribute__((weak)) int func2(int i) { | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify=good | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify=good | ||
|
|
||
| int func2(int i); | ||
| int external_call2(int i) { | ||
| // good-no-diagnostics | ||
| [[clang::musttail]] return func2(i); | ||
| } | ||
| int func2(int i) { | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
| // RUN: %clang_cc1 %s -triple powerpc-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
|
|
||
| void name(int *params) { | ||
| auto fn = (void (*)(int *))1; | ||
| // expected-error@+1 {{'musttail' attribute for this call is impossible because indirect calls can not be tail called on PPC}} | ||
| [[clang::musttail]] return fn(params); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
|
|
||
| inline int foo(int x) { | ||
| return x; | ||
| } | ||
|
|
||
| int bar(int x) | ||
| { | ||
| // expected-error@+1 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}} | ||
| [[clang::musttail]] return foo(1); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify | ||
|
|
||
| int foo(int x); | ||
|
|
||
| int bar(int x) | ||
| { | ||
| // expected-error@+1 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}} | ||
| [[clang::musttail]] return foo(x); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64-ibm-aix-xcoff -o /dev/null -emit-llvm -verify=aix | ||
| // RUN: %clang_cc1 %s -triple powerpc-ibm-aix-xcoff -o /dev/null -emit-llvm -verify=aix | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify=linux | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify=linux | ||
|
|
||
| __attribute__((weak)) int func2(int i) { | ||
| return 0; | ||
| } | ||
| int external_call2(int i) { | ||
| // linux-error@+2 {{'musttail' attribute for this call is impossible because external calls can not be tail called on PPC}} | ||
| // aix-error@+1 {{'musttail' attribute is not supported on AIX}} | ||
| [[clang::musttail]] return func2(i); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // RUN: %clang_cc1 %s -triple powerpc64-ibm-aix-xcoff -o /dev/null -emit-llvm -verify=aix | ||
| // RUN: %clang_cc1 %s -triple powerpc-ibm-aix-xcoff -o /dev/null -emit-llvm -verify=aix | ||
| // RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify=good | ||
| // RUN: %clang_cc1 %s -triple powerpc-unknown-linux-gnu -o /dev/null -emit-llvm -verify=good | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify=good | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -target-feature +pcrelative-memops -o /dev/null -emit-llvm -verify=good | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -target-feature +longcall -o /dev/null -emit-llvm -verify=longcall | ||
| // RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -target-feature +pcrelative-memops -target-feature +longcall -o /dev/null -emit-llvm -verify=good | ||
|
|
||
| int foo(int x) { | ||
| return x; | ||
| } | ||
|
|
||
| int bar(int x) | ||
| { | ||
| // good-no-diagnostics | ||
| // longcall-error@+2 {{'musttail' attribute for this call is impossible because long calls can not be tail called on PPC}} | ||
| // aix-error@+1 {{'musttail' attribute is not supported on AIX}} | ||
| [[clang::musttail]] return foo(1); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // RUN: %clang -g -target bpf -S -emit-llvm %s -o - | FileCheck %s | ||
| // | ||
| // When linking BPF object files via bpftool, BTF info is required for | ||
| // every symbol. BTF is generated from debug info. Ensure that debug info | ||
| // is emitted for extern functions referenced via variable initializers. | ||
| // | ||
| // CHECK: !DISubprogram(name: "fn" | ||
| extern void fn(void); | ||
| void (*pfn) (void) = &fn; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // RUN: %clang -g -target bpf -S -emit-llvm %s -o - | FileCheck %s | ||
| // | ||
| // No debug info is produced for unreferenced functions. | ||
| // CHECK-NOT: !DISubprogram | ||
| void unref(void); | ||
| void unref2(typeof(unref)); | ||
|
|
||
| // No debug info for unused extern variables as well. | ||
| // CHECK-NOT: !DiGlobalVariable | ||
| extern int unused; | ||
| extern int unused2[sizeof(unused)]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| //===- AArch64CPUFeatures.inc - AArch64 CPU Features enum -------*- C++ -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the CPUFeatures enum for AArch64 to facilitate better | ||
| // testing of this code between LLVM and compiler-rt, primarily that the files | ||
| // are an exact match. | ||
| // | ||
| // This file has two identical copies. The primary copy lives in LLVM and | ||
| // the other one sits in compiler-rt/lib/builtins/cpu_model directory. To make | ||
| // changes in this file, first modify the primary copy and copy it over to | ||
| // compiler-rt. compiler-rt tests will fail if the two files are not synced up. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef AARCH64_CPU_FEATURS_INC_H | ||
| #define AARCH64_CPU_FEATURS_INC_H | ||
|
|
||
| // Function Multi Versioning CPU features. | ||
| enum CPUFeatures { | ||
| FEAT_RNG, | ||
| FEAT_FLAGM, | ||
| FEAT_FLAGM2, | ||
| FEAT_FP16FML, | ||
| FEAT_DOTPROD, | ||
| FEAT_SM4, | ||
| FEAT_RDM, | ||
| FEAT_LSE, | ||
| FEAT_FP, | ||
| FEAT_SIMD, | ||
| FEAT_CRC, | ||
| FEAT_SHA1, | ||
| FEAT_SHA2, | ||
| FEAT_SHA3, | ||
| FEAT_AES, | ||
| FEAT_PMULL, | ||
| FEAT_FP16, | ||
| FEAT_DIT, | ||
| FEAT_DPB, | ||
| FEAT_DPB2, | ||
| FEAT_JSCVT, | ||
| FEAT_FCMA, | ||
| FEAT_RCPC, | ||
| FEAT_RCPC2, | ||
| FEAT_FRINTTS, | ||
| FEAT_DGH, | ||
| FEAT_I8MM, | ||
| FEAT_BF16, | ||
| FEAT_EBF16, | ||
| FEAT_RPRES, | ||
| FEAT_SVE, | ||
| FEAT_SVE_BF16, | ||
| FEAT_SVE_EBF16, | ||
| FEAT_SVE_I8MM, | ||
| FEAT_SVE_F32MM, | ||
| FEAT_SVE_F64MM, | ||
| FEAT_SVE2, | ||
| FEAT_SVE_AES, | ||
| FEAT_SVE_PMULL128, | ||
| FEAT_SVE_BITPERM, | ||
| FEAT_SVE_SHA3, | ||
| FEAT_SVE_SM4, | ||
| FEAT_SME, | ||
| FEAT_MEMTAG, | ||
| FEAT_MEMTAG2, | ||
| FEAT_MEMTAG3, | ||
| FEAT_SB, | ||
| FEAT_PREDRES, | ||
| FEAT_SSBS, | ||
| FEAT_SSBS2, | ||
| FEAT_BTI, | ||
| FEAT_LS64, | ||
| FEAT_LS64_V, | ||
| FEAT_LS64_ACCDATA, | ||
| FEAT_WFXT, | ||
| FEAT_SME_F64, | ||
| FEAT_SME_I64, | ||
| FEAT_SME2, | ||
| FEAT_RCPC3, | ||
| FEAT_MOPS, | ||
| FEAT_MAX, | ||
| FEAT_EXT = 62, // Reserved to indicate presence of additional features field | ||
| // in __aarch64_cpu_features | ||
| FEAT_INIT // Used as flag of features initialization completion | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ; | ||
| ; NOTE: if this test fails, please make sure the relevant copies are identical | ||
| ; copies of each other. | ||
| ; | ||
| ; RUN: diff %crt_src/lib/builtins/cpu_model/AArch64CPUFeatures.inc %llvm_src/include/llvm/TargetParser/AArch64CPUFeatures.inc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ; | ||
| ; NOTE: if this test fails, please make sure the files are identical | ||
| ; copies of each other. | ||
| ; | ||
| ; RUN: diff %crt_src/include/profile/MIBEntryDef.inc %llvm_src/include/llvm/ProfileData/MIBEntryDef.inc | ||
| ; RUN: diff %crt_src/include/profile/MemProfData.inc %llvm_src/include/llvm/ProfileData/MemProfData.inc | ||
| ; RUN: diff %crt_src/include/profile/InstrProfData.inc %llvm_src/include/llvm/ProfileData/InstrProfData.inc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Definition of macros from limits.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_HDR_LIMITS_MACROS_H | ||
| #define LLVM_LIBC_HDR_LIMITS_MACROS_H | ||
|
|
||
| #ifdef LIBC_FULL_BUILD | ||
|
|
||
| #include "include/llvm-libc-macros/limits-macros.h" | ||
|
|
||
| #else // Overlay mode | ||
|
|
||
| #include <limits.h> | ||
|
|
||
| #endif // LLVM_LIBC_FULL_BUILD | ||
|
|
||
| #endif // LLVM_LIBC_HDR_LIMITS_MACROS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Definition of macros from sys/stat.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_HDR_SYS_STAT_MACROS_H | ||
| #define LLVM_LIBC_HDR_SYS_STAT_MACROS_H | ||
|
|
||
| #ifdef LIBC_FULL_BUILD | ||
|
|
||
| #include "include/llvm-libc-macros/sys-stat-macros.h" | ||
|
|
||
| #else // Overlay mode | ||
|
|
||
| #include <sys/stat.h> | ||
|
|
||
| #endif // LLVM_LIBC_FULL_BUILD | ||
|
|
||
| #endif // LLVM_LIBC_HDR_SYS_STAT_MACROS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Definition of macros from unistd.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_HDR_UNISTD_MACROS_H | ||
| #define LLVM_LIBC_HDR_UNISTD_MACROS_H | ||
|
|
||
| #ifdef LIBC_FULL_BUILD | ||
|
|
||
| #include "include/llvm-libc-macros/unistd-macros.h" | ||
|
|
||
| #else // Overlay mode | ||
|
|
||
| #include <unistd.h> | ||
|
|
||
| #endif // LLVM_LIBC_FULL_BUILD | ||
|
|
||
| #endif // LLVM_LIBC_HDR_UNISTD_MACROS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| //===-- C standard library header dlfcn.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_DLFCN_H | ||
| #define LLVM_LIBC_DLFCN_H | ||
|
|
||
| #include "__llvm-libc-common.h" | ||
| #include "llvm-libc-macros/dlfcn-macros.h" | ||
|
|
||
| %%public_api() | ||
|
|
||
| #endif // LLVM_LIBC_DLFCN_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -277,3 +277,9 @@ add_macro_header( | |
| HDR | ||
| stdckdint-macros.h | ||
| ) | ||
|
|
||
| add_macro_header( | ||
| dlfcn_macros | ||
| HDR | ||
| dlfcn-macros.h | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===-- Definition of macros from dlfcn.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_MACROS_DLFCN_MACROS_H | ||
| #define LLVM_LIBC_MACROS_DLFCN_MACROS_H | ||
|
|
||
| #define RTLD_LAZY 0x00001 | ||
| #define RTLD_NOW 0x00002 | ||
| #define RTLD_GLOBAL 0x00100 | ||
| #define RTLD_LOCAL 0 | ||
|
|
||
| // Non-standard stuff here | ||
| #define RTLD_BINDING_MASK 0x3 | ||
| #define RTLD_NOLOAD 0x00004 | ||
| #define RTLD_DEEPBIND 0x00008 | ||
| #define RTLD_NODELETE 0x01000 | ||
|
|
||
| #endif // LLVM_LIBC_MACROS_DLFCN_MACROS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| add_entrypoint_object( | ||
| dlclose | ||
| SRCS | ||
| dlclose.cpp | ||
| HDRS | ||
| dlclose.h | ||
| ) | ||
|
|
||
| add_entrypoint_object( | ||
| dlerror | ||
| SRCS | ||
| dlerror.cpp | ||
| HDRS | ||
| dlerror.h | ||
| DEPENDS | ||
| libc.include.dlfcn | ||
| libc.src.errno.errno | ||
| ) | ||
|
|
||
| add_entrypoint_object( | ||
| dlopen | ||
| SRCS | ||
| dlopen.cpp | ||
| HDRS | ||
| dlopen.h | ||
| DEPENDS | ||
| libc.include.dlfcn | ||
| libc.src.errno.errno | ||
| ) | ||
|
|
||
| add_entrypoint_object( | ||
| dlsym | ||
| SRCS | ||
| dlsym.cpp | ||
| HDRS | ||
| dlsym.h | ||
| DEPENDS | ||
| libc.include.dlfcn | ||
| libc.src.errno.errno | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation of dlclose -----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "dlclose.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| // TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97917 | ||
| LLVM_LIBC_FUNCTION(int, dlclose, (void *)) { return -1; } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation header of dlclose ------------------------*- C++ -*-===// | ||
| // | ||
| // 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_SRC_DLFCN_DLCLOSE_H | ||
| #define LLVM_LIBC_SRC_DLFCN_DLCLOSE_H | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| int dlclose(void *); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_DLFCN_DLCLOSE_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //===-- Implementation of delerror ----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "dlerror.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| // TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97918 | ||
| LLVM_LIBC_FUNCTION(char *, dlerror, ()) { | ||
| return const_cast<char *>("unsupported"); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation header of dlerror ------------------------*- C++ -*-===// | ||
| // | ||
| // 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_SRC_DLFCN_DLERROR_H | ||
| #define LLVM_LIBC_SRC_DLFCN_DLERROR_H | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| char *dlerror(); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_DLFCN_DLERROR_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation of dlopen -----------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "dlopen.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| // TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97919 | ||
| LLVM_LIBC_FUNCTION(void *, dlopen, (const char *, int)) { return nullptr; } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation header of dlopen -------------------------*- C++ -*-===// | ||
| // | ||
| // 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_SRC_DLFCN_DLOPEN_H | ||
| #define LLVM_LIBC_SRC_DLFCN_DLOPEN_H | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| void *dlopen(const char *, int); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_DLFCN_DLOPEN_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation of dlsym ------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "dlsym.h" | ||
|
|
||
| #include "src/__support/common.h" | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| // TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97920 | ||
| LLVM_LIBC_FUNCTION(void *, dlsym, (void *, const char *)) { return nullptr; } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation header of dlsym --------------------------*- C++ -*-===// | ||
| // | ||
| // 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_SRC_DLFCN_DLSYM_H | ||
| #define LLVM_LIBC_SRC_DLFCN_DLSYM_H | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| void *dlsym(void *, const char *); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_DLFCN_DLSYM_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation header for cospif ------------------------*- C++ -*-===// | ||
| // | ||
| // 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_SRC_MATH_COSPIF_H | ||
| #define LLVM_LIBC_SRC_MATH_COSPIF_H | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| float cospif(float x); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_MATH_COSPIF_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| //===-- Single-precision cospi function -----------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/math/cospif.h" | ||
| #include "sincosf_utils.h" | ||
| #include "src/__support/FPUtil/FEnvImpl.h" | ||
| #include "src/__support/FPUtil/FPBits.h" | ||
| #include "src/__support/FPUtil/multiply_add.h" | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY | ||
| #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(float, cospif, (float x)) { | ||
| using FPBits = typename fputil::FPBits<float>; | ||
|
|
||
| FPBits xbits(x); | ||
| Sign xsign = xbits.sign(); | ||
| xbits.set_sign(Sign::POS); | ||
|
|
||
| uint32_t x_abs = xbits.uintval(); | ||
| double xd = static_cast<double>(xbits.get_val()); | ||
|
|
||
| // Range reduction: | ||
| // For |x| > 1/32, we perform range reduction as follows: | ||
| // Find k and y such that: | ||
| // x = (k + y) * 1/32 | ||
| // k is an integer | ||
| // |y| < 0.5 | ||
| // | ||
| // This is done by performing: | ||
| // k = round(x * 32) | ||
| // y = x * 32 - k | ||
| // | ||
| // Once k and y are computed, we then deduce the answer by the cosine of sum | ||
| // formula: | ||
| // cospi(x) = cos((k + y)*pi/32) | ||
| // = cos(y*pi/32) * cos(k*pi/32) - sin(y*pi/32) * sin(k*pi/32) | ||
| // The values of sin(k*pi/32) and cos(k*pi/32) for k = 0..63 are precomputed | ||
| // and stored using a vector of 32 doubles. Sin(y*pi/32) and cos(y*pi/32) are | ||
| // computed using degree-7 and degree-6 minimax polynomials generated by | ||
| // Sollya respectively. | ||
|
|
||
| // The exhautive test passes for smaller values | ||
| if (LIBC_UNLIKELY(x_abs < 0x38A2'F984U)) { | ||
|
|
||
| #if defined(LIBC_TARGET_CPU_HAS_FMA) | ||
| return fputil::multiply_add(xbits.get_val(), -0x1.0p-25f, 1.0f); | ||
| #else | ||
| return static_cast<float>(fputil::multiply_add(xd, -0x1.0p-25, 1.0)); | ||
| #endif // LIBC_TARGET_CPU_HAS_FMA | ||
| } | ||
|
|
||
| // Numbers greater or equal to 2^23 are always integers or NaN | ||
| if (LIBC_UNLIKELY(x_abs >= 0x4B00'0000)) { | ||
|
|
||
| if (LIBC_UNLIKELY(x_abs < 0x4B80'0000)) { | ||
| return (x_abs & 0x1) ? -1.0f : 1.0f; | ||
| } | ||
|
|
||
| // x is inf or nan. | ||
| if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) { | ||
| if (x_abs == 0x7f80'0000U) { | ||
| fputil::set_errno_if_required(EDOM); | ||
| fputil::raise_except_if_required(FE_INVALID); | ||
| } | ||
| return x + FPBits::quiet_nan().get_val(); | ||
| } | ||
|
|
||
| return 1.0f; | ||
| } | ||
|
|
||
| // Combine the results with the sine of sum formula: | ||
| // cos(pi * x) = cos((k + y)*pi/32) | ||
| // = cos(y*pi/32) * cos(k*pi/32) - sin(y*pi/32) * sin(k*pi/32) | ||
| // = (cosm1_y + 1) * cos_k - sin_y * sin_k | ||
| // = (cosm1_y * cos_k + cos_k) - sin_y * sin_k | ||
| double sin_k, cos_k, sin_y, cosm1_y; | ||
|
|
||
| sincospif_eval(xd, sin_k, cos_k, sin_y, cosm1_y); | ||
|
|
||
| if (LIBC_UNLIKELY(sin_y == 0 && cos_k == 0)) { | ||
| return FPBits::zero(xsign).get_val(); | ||
| } | ||
|
|
||
| return static_cast<float>(fputil::multiply_add( | ||
| sin_y, -sin_k, fputil::multiply_add(cosm1_y, cos_k, cos_k))); | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //===-- Implementation header for fpathconf ---------------------*- C++ -*-===// | ||
| // | ||
| // 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_SRC_UNISTD_FPATHCONF_H | ||
| #define LLVM_LIBC_SRC_UNISTD_FPATHCONF_H | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| long fpathconf(int fd, int name); | ||
|
|
||
| } // namespace LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SRC_UNISTD_FSYNC_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===-- Linux implementation of fpathconf ---------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/unistd/fpathconf.h" | ||
| #include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
| #include "src/__support/common.h" | ||
| #include "src/sys/statvfs/linux/statfs_utils.h" | ||
| #include "src/unistd/linux/pathconf_utils.h" | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(long, fpathconf, (int fd, int name)) { | ||
| if (cpp::optional<statfs_utils::LinuxStatFs> result = | ||
| statfs_utils::linux_fstatfs(fd)) | ||
| return pathconfig(result.value(), name); | ||
| return -1; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //===-- Linux implementation of pathconf ----------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/unistd/pathconf.h" | ||
| #include "src/errno/libc_errno.h" | ||
| #include "src/sys/statvfs/linux/statfs_utils.h" | ||
| #include "src/unistd/linux/pathconf_utils.h" | ||
|
|
||
| namespace LIBC_NAMESPACE { | ||
|
|
||
| LLVM_LIBC_FUNCTION(long, pathconf, (const char *path, int name)) { | ||
| if (cpp::optional<statfs_utils::LinuxStatFs> result = | ||
| statfs_utils::linux_statfs(path)) | ||
| return pathconfig(result.value(), name); | ||
| return -1; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE |