forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a skeleton librt to provide libc/libm/etc during embedded link…
…ing. (iree-org#6560) The code should be factored out as we start to add things like placeholder functions for querying runtime state/etc but starting simple here to get us bootstrapped. See librt/src/librt.h for some notes. Run librt/build.sh to update the .bc file and then rebuild iree-* so the new version is pulled in.
- Loading branch information
Showing
12 changed files
with
309 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2021 The IREE Authors | ||
# | ||
# Licensed 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 | ||
|
||
load("//build_tools/embed_data:build_defs.bzl", "c_embed_data") | ||
load("//iree:build_defs.oss.bzl", "iree_cmake_extra_content") | ||
|
||
package( | ||
default_visibility = ["//visibility:public"], | ||
features = ["layering_check"], | ||
licenses = ["notice"], # Apache 2.0 | ||
) | ||
|
||
iree_cmake_extra_content( | ||
content = """ | ||
if(NOT "${IREE_TARGET_BACKEND_DYLIB-LLVM-AOT}" AND NOT "${IREE_TARGET_BACKEND_WASM-LLVM-AOT}") | ||
return() | ||
endif() | ||
""", | ||
) | ||
|
||
c_embed_data( | ||
name = "librt", | ||
srcs = ["bin/librt.bc"], | ||
c_file_output = "librt.c", | ||
flatten = True, | ||
h_file_output = "librt.h", | ||
identifier = "iree_compiler_librt", | ||
) |
32 changes: 32 additions & 0 deletions
32
iree/compiler/Dialect/HAL/Target/LLVM/librt/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
################################################################################ | ||
# Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from # | ||
# iree/compiler/Dialect/HAL/Target/LLVM/librt/BUILD # | ||
# # | ||
# Use iree_cmake_extra_content from iree/build_defs.oss.bzl to add arbitrary # | ||
# CMake-only content. # | ||
# # | ||
# To disable autogeneration for this file entirely, delete this header. # | ||
################################################################################ | ||
|
||
if(NOT "${IREE_TARGET_BACKEND_DYLIB-LLVM-AOT}" AND NOT "${IREE_TARGET_BACKEND_WASM-LLVM-AOT}") | ||
return() | ||
endif() | ||
|
||
iree_add_all_subdirs() | ||
|
||
iree_c_embed_data( | ||
NAME | ||
librt | ||
SRCS | ||
"bin/librt.bc" | ||
C_FILE_OUTPUT | ||
"librt.c" | ||
H_FILE_OUTPUT | ||
"librt.h" | ||
IDENTIFIER | ||
"iree_compiler_librt" | ||
FLATTEN | ||
PUBLIC | ||
) | ||
|
||
### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ### |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2021 The IREE Authors | ||
# | ||
# Licensed 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 | ||
|
||
set -e | ||
|
||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
OUT="${SCRIPT_DIR}/bin" | ||
SRC="${SCRIPT_DIR}/src" | ||
LL_FILE="${OUT}/librt.ll" | ||
BC_FILE="${OUT}/librt.bc" | ||
|
||
# Generate an LLVM IR assembly listing so we can easily read the file. | ||
# This is not checked in or used by the compiler. | ||
clang \ | ||
-target wasm32 \ | ||
-std=c17 \ | ||
-O2 \ | ||
-Xclang -disable-llvm-passes \ | ||
-fno-ident \ | ||
-fvisibility=hidden \ | ||
-nostdinc \ | ||
-g0 \ | ||
-S \ | ||
-emit-llvm \ | ||
-fno-verbose-asm \ | ||
-fdiscard-value-names \ | ||
-o "${LL_FILE}" \ | ||
-c \ | ||
"${SRC}/libm.c" | ||
|
||
# Clang adds a bunch of bad attributes and host-specific information that we | ||
# don't want (so we get at least somewhat deterministic builds). | ||
sed -i 's/^;.*$//' ${LL_FILE} | ||
sed -i 's/^source_filename.*$//' ${LL_FILE} | ||
sed -i 's/^target datalayout.*$//' ${LL_FILE} | ||
sed -i 's/^target triple.*$//' ${LL_FILE} | ||
sed -i 's/^\(attributes #[0-9]* = {\).*$/\1 inlinehint }/' ${LL_FILE} | ||
|
||
# Generate a binary bitcode file embedded into the compiler binary. | ||
# NOTE: we do this from stdin so that the filename on the user's system is not | ||
# embedded in the bitcode file (making it non-deterministic). | ||
cat ${LL_FILE} | llvm-as -o=${BC_FILE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2021 The IREE Authors | ||
// | ||
// Licensed 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 "libm.h" | ||
|
||
// https://en.cppreference.com/w/c/numeric/math/fma | ||
LIBRT_EXPORT float fmaf(float x, float y, float z) { | ||
// TODO(*): a real implementation :) | ||
return (x * y) + z; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2021 The IREE Authors | ||
// | ||
// Licensed 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 IREE_COMPILER_DIALECT_HAL_TARGET_LLVM_LIBRT_SRC_LIBM_H_ | ||
#define IREE_COMPILER_DIALECT_HAL_TARGET_LLVM_LIBRT_SRC_LIBM_H_ | ||
|
||
#include "librt.h" | ||
|
||
// https://en.cppreference.com/w/c/numeric/math/fma | ||
LIBRT_EXPORT float fmaf(float x, float y, float z); | ||
|
||
#endif // IREE_COMPILER_DIALECT_HAL_TARGET_LLVM_LIBRT_SRC_LIBM_H_ |
Oops, something went wrong.