Commit Graph

641 Commits

Author SHA1 Message Date
Jakub Konka
241e1ac030 cmake: add runaway Coff/Object.zig path 2022-08-30 10:42:21 +02:00
Jakub Konka
90b3599c68 coff: reorganize the linker 2022-08-30 10:42:21 +02:00
Andrew Kelley
532cfb65e0 CI: rework to account for new cmake behavior
* CMakeLists: pass `-Dstrip` for release zig builds
 * pass -target and -mcpu to zig1. works around llvm on freebsd
   incorrectly detecting "freestanding" instead of "freebsd" for the
   native OS.
 * ci.ziglang.org is now responsible for creating aarch64-macos tarballs
   rather than Azure.
2022-08-28 17:07:21 -07:00
Andrew Kelley
aee53e2ffd CMake: add dummy install command
This makes it so that `ninja install` will work as expected.
2022-08-28 17:07:21 -07:00
Andrew Kelley
56129d26eb cmake: build stage3 by default
This is a simplification of the cmake build script which introduces a
new "stage3" target that is built by default, which builds and installs
a stage3 zig.

It greatly simplifies the build instructions for Zig, making it conform
to the regular cmake routine, while still producing a stage3 artifact.
2022-08-28 17:07:21 -07:00
Andrew Kelley
507aae4a1a make self-hosted the default compiler
stage1 is available behind the -fstage1 flag.

closes #89
2022-08-19 16:45:15 -07:00
Meghan Denny
b5861193e0 std: rename std.Target.systemz to .s390x 2022-07-28 23:22:44 -07:00
Andrew Kelley
0527b441ae move zig.h to become an installation file
Now instead of zig.h being baked into the compiler binary, it is a
header file distributed along with all the other header files
distributed with Zig.

Closes #11643
2022-07-27 10:26:45 -07:00
Andrew Kelley
7a09bce232
Merge pull request #12136 from topolarity/llvm-config-rework
CMake: Improve usage of `llvm-config` (esp. for consistent static/shared linking)
2022-07-26 11:41:00 -07:00
Cody Tapscott
3f640ef3d2 CMake: Improve usage of llvm-config, esp. for consistent linking
This commit reworks the LLVM/Clang/LLD discovery process for CMake. The
biggest changes are that:
  1. We search for LLVM from most preferred directory to least, skipping
     any `llvm-config` that is the wrong version, or that doesn't
     support the requested link mode ("static" or "shared").
  2. `ZIG_PREFER_CLANG_CPP_DYLIB` has been renamed to `ZIG_SHARED_LLVM`,
     to better align with `ZIG_STATIC_LLVM`.
  3. We only search for LLVM in the same directory alongside LLVM.
  4. LLVM's link mode is forwarded to Clang, so that we can look for the
     appropriate shared/static libraries.
  5. We use `--link-static` when querying `--system-libs` from llvm-config,
     so that this will include libz and other dependencies for
     statically linking LLD
2022-07-23 08:52:30 -07:00
Jakub Konka
a8bfddfaea
Merge pull request #12140 from ziglang/macho-gc-sections
macho: add support for `-dead_strip` (GC sections) and simplify symbol resolution
2022-07-23 00:01:09 -07:00
Jakub Konka
ca74656685 macho: move GC code into dead_strip.zig module
Implement marking live atoms that reference other live atoms if
required by the compiler (via section attribute).
2022-07-22 16:58:21 +02:00
Andrew Kelley
7d636f0f9d delete the stage1 implementation of autodoc 2022-07-19 19:10:12 -07:00
Cody Tapscott
dd70336f3a CMake: Use NAMES_PER_DIR in all lookups
CMake has a surprising default behavior where looking up a library by
multiple names gives the name order higher priority than the directory
search order.

For example, if your system provides "llvm-config-14" and
CMAKE_PREFIX_PATH includes "llvm-config", CMake will always end up
choosing the system-provided llvm-config-14.

This change add NAMES_PER_DIR to request the more sensible behavior:
directory search order has higher priority than name order, so
CMAKE_PREFIX_PATH always wins over system-provided tools/libraries.
2022-07-14 22:18:10 -04:00
BratishkaErik
b9ed072278 CMakeLists.txt: set LLVM minimal version to 14 2022-07-10 15:43:01 -04:00
Andrew Kelley
41a0b81731 CMake: disable deprecated function warnings
LLVM 14 deprecated a bunch of C API functions in preparation for opaque
pointer changes. However, they did not actually implement opaque pointer
semantics, so the deprecations are largely masturbatory. I have nothing
against masturbation, I am just busy trying to get the self hosted
compiler done for 0.10.0, so we will come back to this later.
2022-07-01 19:17:09 -07:00
Andrew Kelley
6bc6e47b15 stage2: lower float negation explicitly
Rather than lowering float negation as `0.0 - x`.

 * Add AIR instruction for float negation.
 * Add compiler-rt functions for f128, f80 negation

closes #11853
2022-06-30 00:02:00 -07:00
Andrew Kelley
e4092d4442 stage2: rip out multi-compilation-unit compiler-rt
After doing performance testing, it seems that multi-compilation-unit
compiler-rt did not bring the performance improvements that we expected
it to. The idea is that it makes linking faster, however, it incurred a
cost in the frontend that was not offset by any gains in linking.

Furthermore, the single-object compiler-rt (with -ffunction-sections and
--gc-sections) ends up being fewer bytes on disk and so it's actually
the same or faster linking speed than the multi-compilation-unit
version.

So we are planning to keep using single-compilation-unit compiler-rt for
the foreseeable future, but may experiment with this again in the
future, in which case this commit can be reverted.
2022-06-17 18:34:11 -07:00
Andrew Kelley
2064d86298 update CMakeLists.txt source files 2022-06-17 18:24:57 -07:00
Andrew Kelley
b4f3e69342 update CMakeLists.txt source file list 2022-06-17 16:38:59 -07:00
Andrew Kelley
25671f5a97 compiler-rt: move SPARC functions into appropriate compilation units 2022-06-17 16:38:59 -07:00
Andrew Kelley
c99c085d70 compiler-rt: break up functions even more
The purpose of this branch is to switch to using an object file for each
independent function, in order to make linking simpler - instead of
relying on `-ffunction-sections` and `--gc-sections`, which involves the
linker doing the work of linking everything and then undoing work via
garbage collection, this will allow the linker to only include the
compilation units that are depended on in the first place.

This commit makes progress towards that goal.
2022-06-17 16:38:59 -07:00
Jakub Konka
2259d629d3 compiler_rt: use single cache for libcompiler_rt.a static lib 2022-06-17 16:38:59 -07:00
Koakuma
fb0692334e target: Rename sparcv9 -> sparc64
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.

This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-13 16:43:59 -04:00
Andrew Kelley
ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00
Andrew Kelley
615a983517 cmake: default install prefix to ./stage1 2022-05-01 14:05:01 -07:00
Andrew Kelley
41dd2beaac compiler-rt: math functions reorg
* unify the logic for exporting math functions from compiler-rt,
   with the appropriate suffixes and prefixes.
   - add all missing f128 and f80 exports. Functions with missing
     implementations call other functions and have TODO comments.
   - also add f16 functions
 * move math functions from freestanding libc to compiler-rt (#7265)
 * enable all the f128 and f80 code in the stage2 compiler and behavior
   tests (#11161).
 * update std lib to use builtins rather than `std.math`.
2022-04-27 12:20:44 -07:00
protty
18f3034629
std.Thread: ResetEvent improvements (#11523)
* std: start removing redundant ResetEvents

* src: fix other uses of std.Thread.ResetEvent

* src: add builtin.sanitize_thread for tsan detection

* atomic: add Atomic.fence for proper fencing with tsan

* Thread: remove the other ResetEvent's and rewrite the current one

* Thread: ResetEvent docs

* zig fmt + WaitGroup.reset() fix

* src: fix build issues for ResetEvent + tsan

* Thread: ResetEvent tests

* Thread: ResetEvent module doc

* Atomic: replace llvm *p memory constraint with *m

* panicking: handle spurious wakeups in futex.wait() when waiting for abort()

* zig fmt
2022-04-26 16:48:56 -05:00
kprotty
7284eb22dc treap: initial implementation 2022-04-15 15:26:51 -05:00
Cody Tapscott
b5d5685a4e compiler_rt: Implement floatXiYf/fixXfYi, incl f80
This change:
 - Adds  generic implementation of the float -> integer conversion
   functions floatXiYf, including support for f80
 - Updates the existing implementation of integer -> float conversion
   fixXiYf to support f16 and f80
 - Fixes the handling of the explicit integer bit in `__trunctfxf2`
 - Combines the test cases for fixXfYi/floatXiYf into a single file
 - Renames `fmodl` to `fmodq`, since it operates on 128-bit floats

The new implementation for floatXiYf has been benchmarked, and generally
provides equal or better performance versus the current implementations:

Throughput (MiB/s) - Before
     |    u32   |    i32   |    u64   |    i64   |   u128   |   i128   |
-----|----------|----------|----------|----------|----------|----------|
 f16 |     none |     none |     none |     none |     none |     none |
 f32 |  2231.67 |  2001.19 |  1745.66 |  1405.77 |  2173.99 |  1874.63 |
 f64 |  1407.17 |  1055.83 |  2911.68 |  2437.21 |  1676.05 |  1476.67 |
 f80 |     none |     none |     none |     none |     none |     none |
f128 |   327.56 |   321.25 |   645.92 |   654.52 |  1153.56 |  1096.27 |

Throughput (MiB/s) - After
     |    u32   |    i32   |    u64   |    i64   |   u128   |   i128   |
-----|----------|----------|----------|----------|----------|----------|
 f16 |  1407.61 |  1637.25 |  3555.03 |  2594.56 |  3680.60 |  3063.34 |
 f32 |  2101.36 |  2122.62 |  3225.46 |  3123.86 |  2860.05 |  1985.21 |
 f64 |  1395.57 |  1314.87 |  2409.24 |  2196.30 |  2384.95 |  1908.15 |
 f80 |   475.53 |   457.92 |   884.50 |   812.12 |  1475.27 |  1382.16 |
f128 |   359.60 |   350.91 |   723.08 |   706.80 |  1296.42 |  1198.87 |
2022-04-12 10:25:26 -07:00
viri
c5c6260534
std.math: generalise inf, even simpler isFinite 2022-04-07 02:38:31 -06:00
Andrew Kelley
916a65cb7b
Merge pull request #11224 from koachan/sparc64-codegen
stage2 sparcv9: Add instruction encoder and placeholder codegen impl
2022-03-21 18:21:31 -04:00
William Sengir
9f25c8140c cmake: add missing DWARF files to ZIG_STAGE2_SOURCES 2022-03-20 14:48:37 +01:00
fn ⌃ ⌥
d62b1c932e
translate-c: add missing builtins used by CRuby 2022-03-19 19:08:17 +02:00
Koakuma
93b16de4b4 stage2 sparcv9: Add placeholder files and generate() function
Add placeholder files for Codegen, Emit, and Mir stages, complete with
a placeholder implementation of generate() to make it able to be plugged in
to the frontend. At the moment the implementation just panics, it'll be
worked on incrementally later.

Also, this registers the sparcv9 backend files into CMakeLists.txt.
2022-03-19 06:09:46 +07:00
Jakub Konka
dd55b72949 std: introduce posix_spawn as an alt to fork-exec
Currently, the new API will only be available on macOS with
the intention of adding more POSIX systems to it incrementally
(such as Linux, etc.).

Changes:
* add `posix_spawn` wrappers in a separate container in
  `os/posix_spawn.zig`
* rewrite `ChildProcess.spawnPosix` using `posix_spawn` targeting macOS
  as `ChildProcess.spawnMacos`
* introduce a `posix_spawn` specific `std.c.waitpid` wrapper which
  does return an error in case the child process failed to exec - this
  is required for any process that was spawned using `posix_spawn`
  mechanism as, by definition, the errors returned by `posix_spawn`
  routine cover only the `fork`-equivalent; `pre-exec()` and `exec()`
  steps are covered by a catch-all error `ECHILD` returned by `waitpid`
  on unsuccessful execution, e.g., no such file error, etc.
2022-03-16 19:40:44 +01:00
Jakub Konka
633c4a2a60 macos: add Mach task abstraction
`std.os.darwin.MachTask` wraps `mach_port_t` and can be used to issue
kernel calls tied to the wrapped Mach kernel port/task.
2022-03-13 13:35:39 +01:00
joachimschmidt557
06058ed6f3
stage2 regalloc: replace Register.allocIndex with generic indexOfReg
* callee_preserved_regs and other ABI-specific information have been
moved to the respective abi.zig files
2022-03-11 13:29:16 +01:00
Hadrien Dorio
02902cc099
ci: azure: split build-and-test step (#10853)
replace the .bat script by a pwsh script
2022-02-16 22:33:08 -05:00
Andrew Kelley
d164865308 add missing source file to CMakeLists.txt 2022-02-14 12:26:15 -07:00
Andrew Kelley
1c23321d03 stage1: fix softfloat not getting correct endianness
needed to include platform.h in more places so that LITTLEENDIAN will be
defined appropriately.

closes #10860
2022-02-12 11:18:23 +01:00
Andrew Kelley
44b5fdf326 Revert "ci: azure: split build-and-test step"
This reverts commit 846eb70182.

This did not properly translate the upload portion of the CI script to
powershell which broke our CI pipeline.
2022-02-09 18:26:56 -07:00
Hadrien Dorio
846eb70182 ci: azure: split build-and-test step
replace the .bat script by a pwsh script
2022-02-08 19:47:46 -05:00
Andrew Kelley
fd6c351263 cmake: fix -DZIG_SINGLE_THREADED option
It was still passing --single-threaded instead of -fsingle-threaded.
2022-02-08 17:22:11 -07:00
Veikka Tuominen
a31a749c42 stage1: add f80 type 2022-01-28 11:45:04 -07:00
Jakub Konka
6315bcb32a stage2: rename Isel to Emit for x86_64
Clean up generated errors in Emit.
2022-01-15 18:36:13 +01:00
Jakub Konka
e7ac05e882 stage2: rename Emit to Isel for x86_64 2021-12-31 11:18:23 +01:00
Jan Philipp Hafer
17046674a7 compiler_rt: add __negvsi2, __negvdi2, __negvti2
- neg can only overflow, if a == MIN
- case `-0` is properly handled by hardware, so overflow check by comparing
  `a == MIN` is sufficient
- tests: MIN, MIN+1, MIN+4, -42, -7, -1, 0, 1, 7..

See #1290
2021-12-27 14:35:45 -08:00
Jan Philipp Hafer
405ff911da compiler_rt: add __absvsi2, __absvdi2, __absvti2
- abs can only overflow, if a == MIN
- comparing the sign change from wrapping addition is branchless
- tests: MIN, MIN+1,..MIN+4, -42, -7, -1, 0, 1, 7..

See #1290
2021-12-26 13:21:18 -08:00
Andrew Kelley
3763580e1e add missing files to CMakeLists 2021-12-23 17:48:58 -07:00