aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm/Builder.zig
AgeCommit message (Collapse)Author
2025-02-27Move the compiler's LLVM bitcode builder to std.zig.llvm.Alex Rønne Petersen
2025-02-22llvm: Use inline variants of memcpy/memset intrinsics when using -fno-builtin.Alex Rønne Petersen
This is a correctness issue: When -fno-builtin is used, we must assume that we could be compiling the memcpy/memset implementations, so generating calls to them is problematic.
2025-02-22llvm.Builder: Update some intrinsic definitions for LLVM 19.Alex Rønne Petersen
2025-02-03compiler,std: implement ZON supportMason Remaley
This commit allows using ZON (Zig Object Notation) in a few ways. * `@import` can be used to load ZON at comptime and convert it to a normal Zig value. In this case, `@import` must have a result type. * `std.zon.parse` can be used to parse ZON at runtime, akin to the parsing logic in `std.json`. * `std.zon.stringify` can be used to convert arbitrary data structures to ZON at runtime, again akin to `std.json`.
2025-01-16all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renamesmlugg
2024-12-27llvm: fix UB in metadata printerDavid Rubin
2024-11-03Merge pull request #21599 from alexrp/thumb-portingAlex Rønne Petersen
2024-11-03llvm: Update the list of address spaces for LLVM 19.Alex Rønne Petersen
Mainly affects amdgcn.
2024-11-02llvm: Remove extraneous commas for branch hint metadata in textual IR output.Alex Rønne Petersen
2024-10-23Merge pull request #21758 from kcbanner/dll_storage_classAndrew Kelley
Add `is_dll_import` to @extern, to support `__declspec(dllimport)` with the MSVC ABI
2024-10-22Cause a compilation error to occur if using @extern with is_dll_import in a ↵kcbanner
comptime scope. Add a note about thread local / dll import being the cause.
2024-10-19compiler: introduce new `CallingConvention`mlugg
This commit begins implementing accepted proposal #21209 by making `std.builtin.CallingConvention` a tagged union. The stage1 dance here is a little convoluted. This commit introduces the new type as `NewCallingConvention`, keeping the old `CallingConvention` around. The compiler uses `std.builtin.NewCallingConvention` exclusively, but when fetching the type from `std` when running the compiler (e.g. with `getBuiltinType`), the name `CallingConvention` is used. This allows a prior build of Zig to be used to build this commit. The next commit will update `zig1.wasm`, and then the compiler and standard library can be updated to completely replace `CallingConvention` with `NewCallingConvention`. The second half of #21209 is to remove `@setAlignStack`, which will be implemented in another commit after updating `zig1.wasm`.
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-09-04Merge pull request #21257 from mlugg/computed-goto-3Andrew Kelley
compiler: implement labeled switch/continue
2024-09-01Builder: add `indirectbr` llvm instructionJacob Young
2024-09-01LLVM: Emit module flags through Builder instead of LLVM APIantlilja
2024-08-28llvm.Builder: revert adding !nosanitize APIAndrew Kelley
It's not actually useful after all.
2024-08-28llvm.Builder: add !nosanitize APIAndrew Kelley
see #20992 Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-27compiler: implement `@branchHint`, replacing `@setCold`mlugg
Implements the accepted proposal to introduce `@branchHint`. This builtin is permitted as the first statement of a block if that block is the direct body of any of the following: * a function (*not* a `test`) * either branch of an `if` * the RHS of a `catch` or `orelse` * a `switch` prong * an `or` or `and` expression It lowers to the ZIR instruction `extended(branch_hint(...))`. When Sema encounters this instruction, it sets `sema.branch_hint` appropriately, and `zirCondBr` etc are expected to reset this value as necessary. The state is on `Sema` rather than `Block` to make it automatically propagate up non-conditional blocks without special handling. If `@panic` is reached, the branch hint is set to `.cold` if none was already set; similarly, error branches get a hint of `.unlikely` if no hint is explicitly provided. If a condition is comptime-known, `cold` hints from the taken branch are allowed to propagate up, but other hints are discarded. This is because a `likely`/`unlikely` hint just indicates the direction this branch is likely to go, which is redundant information when the branch is known at comptime; but `cold` hints indicate that control flow is unlikely to ever reach this branch, meaning if the branch is always taken from its parent, then the parent is also unlikely to ever be reached. This branch information is stored in AIR `cond_br` and `switch_br`. In addition, `try` and `try_ptr` instructions have variants `try_cold` and `try_ptr_cold` which indicate that the error case is cold (rather than just unlikely); this is reachable through e.g. `errdefer unreachable` or `errdefer @panic("")`. A new API `unwrapSwitch` is introduced to `Air` to make it more convenient to access `switch_br` instructions. In time, I plan to update all AIR instructions to be accessed via an `unwrap` method which returns a convenient tagged union a la `InternPool.indexToKey`. The LLVM backend lowers branch hints for conditional branches and switches as follows: * If any branch is marked `unpredictable`, the instruction is marked `!unpredictable`. * Any branch which is marked as `cold` gets a `llvm.assume(i1 true) [ "cold"() ]` call to mark the code path cold. * If any branch is marked `likely` or `unlikely`, branch weight metadata is attached with `!prof`. Likely branches get a weight of 2000, and unlikely branches a weight of 1. In `switch` statements, un-annotated branches get a weight of 1000 as a "middle ground" hint, since there could be likely *and* unlikely *and* un-annotated branches. For functions, a `cold` hint corresponds to the `cold` function attribute, and other hints are currently ignored -- as far as I can tell LLVM doesn't really have a way to lower them. (Ideally, we would want the branch hint given in the function to propagate to call sites.) The compiler and standard library do not yet use this new builtin. Resolves: #21148
2024-08-27llvm.Builder: add support for more instruction metadataAndrew Kelley
mlugg: this is cherry-picked from Andrew's nosanitize branch (with Jacob's fixes squashed in) since I needed this for `unpredictable` and `prof` metadata. The nosanitize-specific changes are reverted in the next commit. Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
2024-08-13nvptx: add implementations for GPU builtinsRobin Voetter
2024-07-21Revert "Merge pull request #20380 from tau-dev/master"Andrew Kelley
This reverts commit 397be0c9cc8156d38d1487a4c80210007033cbd0, reversing changes made to 18d412ab2fb7bda92f7bfbdf732849bbcd066c33. Caused test failures in master branch.
2024-07-19llvm: add pass-by-reference info to debug typesTau
Without this data, debugger expressions try to pass structs by-value, which mostly just crashes. Also: mark enums as enum classes to prevent the enumerators from shadowing other identifiers.
2024-07-19llvm: Do not generate static member definitionsTau
They were not helping LLDB and actively throwing off GDB. Also: clean up some llvm.Builder and llvm.ir definitions that are no longer necessary.
2024-07-19llvm: encode variables as DW_TAG_imported_declarationTau
Now we get working global variable lookup in GDB! LLDB still re-mangles, and it looks like we can't do much about that for now. Also: translate non-owning type declarations into typedefs.
2024-07-19llvm: set precise scopes on namespace types and variablesTau
This will allow accessing non-local declarations from debuggers, which, AFAICT, was impossible before. Getting scopes right already works for type declarations and functions, but will need some fiddling for variables: For those, I tried imitating what Clang does for static member variables, but LLDB tries to re-mangle those and then fails at lookup, while GDB outright crashes. Hopefully I can find some other dwarven incantation to do the right thing.
2024-07-13Builder: fix llvm ir syntaxJacob Young
2024-07-03LLVM Builder: Pass correct argument to ensureUnusedMetadataCapacityantlilja
The trail_len was being multiplied by the size of the type before
2024-04-25LLVM: Remove deprecated or soon to be deprecated constant expressionsantlilja
2024-04-06Builder: fix encoding big integers in bitcodeJacob Young
Closes #19543
2024-04-06LLVM Builder: Emit binary op optional flags for exact and no wrapantlilja
2024-03-17LLVM: Use fast math when requestedantlilja
2024-03-17LLVM: Fix incorrect fast constant in FastMath packed structantlilja
2024-03-17LLVM: Fix reaching unreachable code when emitting fast callantlilja
2024-03-11std.builtin: make atomic order fields lowercaseTristan Ross
2024-02-29LLVM Builder: Fix emission of enum debug enumerator info bitcodeantlilja
2024-02-28Builder: Implement StrtabString and use it for Global namesantlilja
2024-02-28LLVM: Implement more efficient blob writingantlilja
2024-02-26Merge pull request #19083 from antlilja/llvm-blockinfoAndrew Kelley
LLVM reduce size of emitted bitcode
2024-02-26Builder: Reduce size of DebugLoc abbrevantlilja
2024-02-26Builder: Use BlockInfo block to reduce size of bitcodeantlilja
2024-02-25llvm: free llvm data before running llvm optimizationsJacob Young
This reduces the max memory usage.
2024-02-25llvm: implement per-module strippingJacob Young
This avoids llvm module verification errors when the strip option is different across modules.
2024-02-25Merge pull request #19074 from antlilja/llvm-debug-locJacob Young
Rework LLVM debug locations to not emit them twice
2024-02-25llvm: remork memory management in emitJacob Young
2024-02-25Builder: Fix llvm ir debug location outputantlilja
2024-02-25Builder: Improve debug location systemantlilja
Debug locations are no longer emitted twice every time
2024-02-24BitcodeWriter: cleanup type widthsJacob Young
2024-02-24Builder: fix bitcode widthsJacob Young