LLVM (iOS API)
别忘了submodules
只有7.0能在iOS16上使用,不要尝试去用最新版本,能编译无法在iOS16运行。

xcbosa 0d6527c4f3 Move submodules to self host il y a 2 ans
benchmarks 18c6fab107 Pull google/benchmark library to the LLVM tree il y a 7 ans
bindings 732f95ff9a Reapply r374743 with a fix for the ocaml binding il y a 5 ans
cmake d35e5f8dde [CMake] [WinMsvc] Look for includes and libs in ${MSVC_BASE}/atlmfc il y a 5 ans
docs d00dbb86c0 [docs][llvm-ar] Update llvm-ar command guide il y a 5 ans
examples 88e224ab97 [examples] Add a dependency on ExecutionEngine to LLJITWithObjectCache example. il y a 5 ans
frameworks c9f456a78b Edited bootstrap.sh for xcframework generation il y a 5 ans
include 195e132a08 Merge branch 'master' of https://github.com/llvm-mirror/llvm il y a 5 ans
lib 1d90413cd4 Avoid using signal() too much, for cohabitation with other commands il y a 5 ans
libffi @ 45875da4bc a4345c19ad Added Package.swift, il y a 5 ans
projects 195e132a08 Merge branch 'master' of https://github.com/llvm-mirror/llvm il y a 5 ans
resources cb2dfa6478 In MSVC builds embed a VERSIONINFO resource in our exe and DLL files. il y a 10 ans
runtimes 4ead439585 Adding support for overriding LLVM_ENABLE_RUNTIMES for runtimes builds. il y a 5 ans
test 2c4ca6832f [InstCombine] Signed saturation patterns il y a 5 ans
tools 781e843466 Committed changes to lld il y a 5 ans
unittests 672893cf12 [Alignment][NFC] Attributes use Align/MaybeAlign il y a 5 ans
utils 719615b78f gn build: Merge r375483 il y a 5 ans
.arcconfig 0e050ed9a8 [llvm] Set up .arcconfig to point to Diffusion L repository il y a 7 ans
.clang-format 742e43f807 Test commit. il y a 11 ans
.clang-tidy ba3936b0ea Disable tidy checks with too many hits il y a 6 ans
.gitattributes a0ae292f06 Fix the "git modified" issue on the preserve-comments-crlf.s. il y a 6 ans
.gitignore 9ac2d30839 gitignore: Ignore Qt Creator project configuration files. NFC il y a 6 ans
.gitmodules 0d6527c4f3 Move submodules to self host il y a 2 ans
CMakeLists.txt 820be7b079 Add few docs and implementation of strcpy and strcat. il y a 5 ans
CODE_OWNERS.TXT 970d21048e Update email address in CODE_OWNERS il y a 6 ans
CREDITS.TXT 8c5bc90b46 Update email address. il y a 6 ans
LICENSE.TXT 2fea5b324e Fix typos throughout the license files that somehow I and my reviewers il y a 6 ans
LLVMBuild.txt 6b547686c5 Update the file headers across all of the LLVM projects in the monorepo il y a 6 ans
Package.swift c70f694c39 Forgot a , in Package.swift il y a 5 ans
README.txt f44b57907a Edited README for archiving il y a 4 ans
RELEASE_TESTERS.TXT e253500cfc Update the list of platforms & archs il y a 6 ans
bootstrap.sh c9f456a78b Edited bootstrap.sh for xcframework generation il y a 5 ans
configure caeade4234 Remove autoconf support il y a 9 ans
libffi-3.2.1_patch ab55c93099 Patch for automatic compiltion of libffi (don't try to compile armv7) il y a 7 ans
libffi.patch a4345c19ad Added Package.swift, il y a 5 ans
llvm.spec.in 4cfe1aca69 Update structured references to the license to the new license. il y a 6 ans
project.pbxproj 8f278533fc Edited project, now with frameworks il y a 7 ans

README.txt

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain a forked source code
for LLVM, a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.

iOS version specific information
================================

** This repository is now archived. Please move to https://github.com/holzschu/llvm-project for an up-to-date version of LLVM for iOS **

This is a very experimental port. It's is designed to work inside ios_system
(https://github.com/holzschu/ios_system), which itself is supposed to be
embedded inside shell applications such as OpenTerm or Blink:
- https://github.com/louisdh/terminal
- https://github.com/holzschu/blink

Compilation of the entire package takes around 20h (divided by the number of
cores you can give to the compiler). For this reason, even the scripts are
not fully guaranteed to work.

The steps for compilation are:
- get clang and lld as submodules: git submodule update --init --recursive
- get libcxx and libcxxabi as packages
- compile LLVM, clang, lld, libcxx and libcxxabi for OSX
- move libcxx and libcxxabi out of the way
- get libffi and compile it
- make sure ios_system has been compiled, and if not compile it.
- compile LLVM and clang for iOS (that's the long step)

"bootstrap.sh" in this directory takes care of all these steps. Remember,
you have time for a long walk in the woods while it compiles.

Once you have compiled everything, add the binaries you want (at least clang and lli)
to the list of embedded binaries, along with libLLVM.dylib and libclang.dylib.
See `project.pbxproj` in this directory for an example.

Commands in `project.pbxproj`: clang, lli, llvm-link, opt, llvm-nm, llvm-dis

Once you have the binaries inside your app, you need to provide the header files. I copied the ones from the Xcode iPhone SDK into ~/usr/include, and the ones from build_ios/lib/clang/7.0.0/include/ into ~/lib/clang/7.0.0/include/ This will need some thinking.

I welcome all help on this project, including on this README file.

iOS: how to compile a command?
==============================

It's a multi-step process.

1) compile each source file (*.c) using:
clang -S -emit-llvm -I ~/lib/clang/7.0.0/include -I ~/usr/include -Wno-nullability-completeness -D_FORTIFY_SOURCE=0 file.c
(you can place all the options into a config file, and use 'clang --config ~/clang.cfg file.c' instead)

This produces a 'file.ll' file, containing LLVM bitcode for file.c

(if you are compiling packages that use 'configure', you will need to create your own config.h, and add -DHAVE_CONFIG_H)

2) link the files together:
llvm-link -o=executable.bc *.ll

This produces an 'executable.bc' file, containing (binary) LLVM bitcode for all the source files.

3) execute, using the LLVM interpreter:

lli executable.bc

LLI (LLVM Interpreter) can run both a JIT compiler and an interpreter. Currently, the JIT compiler only works if the main application was started by Xcode on your Mac. So the default mode is to run the interpreter (-force-interpreter=true). This is the opposite of the default mode for LLI. If you want to run the JIT compiler, use '-force-interpreter=false'.

The JIT compiler is at least 3 times faster than the interpreter, so it would be great to be able to run it on independent apps.

If it doesn't work:
-------------------

This is a very experimental work. The interpreter, often, does not work. Here are a few of the issues encountered, and how I solved them:

- "Code generator does not support intrinsic function 'llvm.objectsize.i64.pi08'": compile with -D_FORTIFY_SOURCE=0
- crash when running 'bsearch': compile with bsearch.c https://opensource.apple.com/source/xnu/xnu-1228/libsa/bsearch.c
- crash when running 'qsort': compile with qsort.c https://opensource.apple.com/source/xnu/xnu-344/bsd/kern/qsort.c

External functions are called using libFFI, and libFFI has problems with pointer manipulation (that's what happens with bsearch and qsort).

- "Unable to allocate memory for common symbols": (more likely with the JIT) sorry, no ideas.
- "Unknown constant pointer type!": beats me.


LLVM iOS version TODO list:
===========================

X make it easier to add llvm binaries to existing iOS projects, with associated dylibs
X added external functions for exit, print, abort, system, exec... (both interpreter and JIT)
- check that memory is freed when LLVM exits, that all flags are reset
- create a "fake libc" for functions that don't work with FFI (qsort, bsearch,...)
X create static libraries instead of executables
X create frameworks with the static libraries

LLVM iOS version wish list:
===========================

X run lli on a llvm intermediate representation, on an iOS device.
X ...with output on the application screen.
X generate llvm intermediate representation locally on iOS device
X ...and run it using lli
X ...without the need to specify "clang -cc1"
X add libFFI to lli, to load dynamic libraries
X install headers on iOS device, for compilation
- load more dynamic libraries, as needed.

X run lli on binary intermediate representation
X use lli to run a "serious" application (multiple source files, command line
arguments)

- compile libcxx and libcxxabi for iOS as well --> required?