aboutsummaryrefslogtreecommitdiff
path: root/src/zig_llvm.cpp
AgeCommit message (Collapse)Author
2024-07-24llvm: force `TargetOptions.UseInitArray` to `true`Jacob Young
The `TargetOptions` default constructor initializes all `bool`s to `false`, yet clang defaults to setting this option to `true`. Since recent glibc versions on linux do not appear to support this being set to `false`, just changing the default for now unless a use case for making it configurable is found.
2024-07-23LLVM: more fine-grained sancov emit optionsAndrew Kelley
Exposes sanitizer coverage flags to the target machine emit function. Makes it easier to change sancov options without rebuilding the C++ files. This also enables PCTable = true for sancov which is needed by AFL, and adds the corresponding Clang flag.
2024-07-22ZigLLVMTargetMachineEmitToFile: make sancov enable the optionsAndrew Kelley
2024-07-22initial support for integrated fuzzingAndrew Kelley
* Add the `-ffuzz` and `-fno-fuzz` CLI arguments. * Detect fuzz testing flags from zig cc. * Set the correct clang flags when fuzz testing is requested. It can be combined with TSAN and UBSAN. * Compilation: build fuzzer library when needed which is currently an empty zig file. * Add optforfuzzing to every function in the llvm backend for modules that have requested fuzzing. * In ZigLLVMTargetMachineEmitToFile, add the optimization passes for sanitizer coverage. * std.mem.eql uses a naive implementation optimized for fuzzing when builtin.fuzz is true. Tracked by #20702
2024-05-08update for LLVM 18 new target dataAndrew Kelley
New OSs: * XROS * Serenity * Vulkan Removed OSs: * Ananas * CloudABI * Minix * Contiki New CPUs: * spirv The removed stuff is removed from LLVM but not Zig.
2024-03-03Add comment explaining LLVM bug and linking tracking issueantlilja
2024-03-02LLVM: Add enableBrokenDebugInfoCheck and getBrokenDebugInfoantlilja
These functions allows the caller to find out wether the context encounters broken debug info or not.
2024-02-21LLVM: Remove unused from llvm/bindings.zig and zig_llvm.h/.cppantlilja
2023-10-04comp: add support for -fdata-sectionsJakub Konka
2023-09-19update for LLVM 17 new target dataAndrew Kelley
New OSs: * UEFI * LiteOS New ABI: * OpenHOS Also update the LLD driver API wrappers.
2023-08-08llvm: force strip without libllvm to avoid unimplemented behaviorJacob Young
Also fix deinit bugs.
2023-08-08llvm: finish converting globalsJacob Young
2023-08-08llvm: finish converting instructionsJacob Young
2023-08-08llvm: finish converting intrinsicsJacob Young
2023-08-08llvm: convert vector reduction intrinsicsJacob Young
Scratch that thing I said about one pass. :)
2023-08-08llvm: finish converting attributes to use Builder and the C LLVM APIJacob Young
2023-08-08llvm: convert intrinsics to using `Builder`Jacob Young
2023-08-06Implement bitop intrinsics in new LLVM IR builderantlilja
* llvm.bitreverse * llvm.bswap * llvm.ctpop * llvm.ctlz * llvm.cttz
2023-08-06Implement fp intrinsics in new LLVM IR builderantlilja
Intrinsics implemented * llvm.ceil * llvm.cos * llvm.exp * llvm.exp2 * llvm.fabs * llvm.floor * llvm.log * llvm.log10 * llvm.log2 * llvm.round * llvm.sin * llvm.trunc * llvm.fma
2023-07-23llvm: convert attributes and non-intrinsic callsJacob Young
2023-07-19llvm: convert most instructionsJacob Young
2023-06-23llvm: fixup elem_count argument of ZigLLVMCreateDebugArrayType to be i64kcbanner
The signature is `getOrCreateSubrange(int64_t Lo, int64_t Count)`, so this updates the bindings to match. This fixes a crash in `lowerDebugTypeImpl` when analyzing slices that have a length of 2^32 or larger (up to `2^64 >> 3`, which still crashes, because above that the array size in bits overflows u64).
2023-04-20Expose an option for producing 64-bit DWARF formatDavid Gonzalez Martin
This commit enables producing 64-bit DWARF format for Zig executables that are produced through the LLVM backend. This is achieved by exposing both command-line flags and CompileStep flags. The production of the 64-bit format only affects binaries that use the DWARF format and it is disabled on MacOS due to it being problematic. This commit, despite generating the interface for the Zig user to be able to tell the compile which format is wanted, is just implemented for the LLVM backend, so clang and the self-hosted backends will need this to be implemented in a future commit. This is an effort to work around #7962, since the emission of the 64-bit format automatically produces 64-bit relocations. Further investigation will be needed to make DWARF 32-bit format to emit bigger relocations when needed and not make the linker angry.
2023-04-20llvm: emit metadata for exported global variables (#15349)Tw
* llvm: emit metadata for global variable One use case is to genearte BTF information from global variable's metadata. Signed-off-by: Tw <weii.tan>
2023-04-05Merge remote-tracking branch 'origin/master' into llvm16Andrew Kelley
2023-03-30llvm: fix crashes when loading a struct fieldJacob Young
The result of buildStructGEP is not always a GEP (sorry), so we can't use getGEPResultElementType on it. Closes #14641
2023-01-25update zig_llvm.cpp and zig_llvm.h to LLVM 16Andrew Kelley
2023-01-03add -fopt-bisect-limitGuillaume Wenzek
2022-11-20llvm: add attributes to the arguments of function pointer callsVeikka Tuominen
Closes #13605
2022-11-16llvm: implement arbitrary precision debug enumeratorsVeikka Tuominen
Closes #645
2022-10-12stage2: improve addrspace handlingRobin Voetter
This commit changes the way Zig is intended to deal with variable declaration for exotic targets. Where previously the idea was to enfore local/global variables to be placed into their respective address spaces, depending on the target, this is now fixed to the generic address space. To facilitate this for targets where local variables _must_ be generated into a specific address space (ex. amdgcn where locals must be generated into the private address space), the variable allocations (alloca) are generated into the right address space and then addrspace-casted back to the generic address space. While this could be less efficient in theory, LLVM will hopefull deal with figuring out the actual correct address space for a pointer for us. HIP seems to do the same thing in this regard. Global variables are handled in a similar way.
2022-08-01LLVM backends: work around poorly designed C APIAndrew Kelley
As part of the Opaque Pointers upgrade documentation, LLVM says that the function LLVMGetGEPSourceElementType() can be used to obtain element type information in lieu of LLVMGetElementType(), however, this function actually returns the struct type, not the field type. The GEP instruction does store the information we need, however, this is not exposed in the C API. It seems like they accidentally exposed the wrong field, because one would never need the struct type since one must already pass it directly to the GEP instruction, so one will always have it handy, whereas one will usually not have the field type handy.
2022-08-01stage1: LLVM lowering to opaque pointers APIAndrew Kelley
2022-07-12zig_llvm: include Debug Info Version even for CodeViewAndrew Kelley
I mistakenly thought this was supposed to only be present for Dwarf.
2022-07-07llvm c++ wrapper: fix argument index calculationsAndrew Kelley
2022-07-01LLD: the driver functions now return "false" to mean "error"Andrew Kelley
2022-07-01stage1: update to LLVM 14 APIAndrew Kelley
2022-07-01Merge remote-tracking branch 'origin/master' into llvm14Andrew Kelley
2022-04-27stage2: Manually lower softfloat ops when neededCody Tapscott
Updates stage2 to manually lower softfloat operations for all unary floating point operations and arithmetic. Softfloat support still needs to be added for conversion operators (float<->float and int<->float)
2022-03-16stage2 llvm: keep track of inlined functionsVeikka Tuominen
2022-03-15stage2: add debug info for globals in the LLVM backendWilliam Sengir
LLVM backend: generate DIGlobalVariable's for non-function globals and rename linkage names when exporting functions and globals. zig_llvm.cpp: add some wrappers to convert a handful of DI classes into DINode's since DIGlobalVariable is not a DIScope like the others. zig_llvm.cpp: add some wrappers to allow replacing the LinkageName of DISubprogram and DIGlobalVariable. zig_llvm.cpp: fix DI class mixup causing nonsense reinterpret_cast. The end result is that GDB is now usable since you now no longer need to manually cast every global nor fully qualify every export.
2022-03-13stage2: add debug info for locals in the LLVM backendAndrew Kelley
Adds 2 new AIR instructions: * dbg_var_ptr * dbg_var_val Sema no longer emits dbg_stmt AIR instructions when strip=true. LLVM backend: fixed lowerPtrToVoid when calling ptrAlignment on the element type is problematic. LLVM backend: fixed alloca instructions improperly getting debug location annotated, causing chaotic debug info behavior. zig_llvm.cpp: fixed incorrect bindings for a function that should use unsigned integers for line and column. A bunch of C test cases regressed because the new dbg_var AIR instructions caused their operands to be alive, exposing latent bugs. Mostly it's just a problem that the C backend lowers mutable and const slices to the same C type, so we need to represent that in the C backend instead of printing two duplicate typedefs.
2022-03-08LLVM: no longer store args into alloca instructionsAndrew Kelley
Previously, we did this so that we could insert a debug variable declaration intrinsic on the alloca. But there is a dbg.value intrinsic for declaring variables that are values.
2022-02-03update C API bindings to LLVM 14Andrew Kelley
* zig_clang is fully updated * zig_llvm is fully updated Some initial work on codegen.cpp is in place for upgrading to LLVM's new opaque pointers. However there is much more to be done. A few of zig llvm bindings for deprecated functions have been updated; more need to be updated.
2021-12-28stage2: LLVM backend: fix lowering of union constantsAndrew Kelley
Comment from this commit reproduced here: LLVM does not allow us to change the type of globals. So we must create a new global with the correct type, copy all its attributes, and then update all references to point to the new global, delete the original, and rename the new one to the old one's name. This is necessary because LLVM does not support const bitcasting a struct with padding bytes, which is needed to lower a const union value to LLVM, when a field other than the most-aligned is active. Instead, we must lower to an unnamed struct, and pointer cast at usage sites of the global. Such an unnamed struct is the cause of the global type mismatch, because we don't have the LLVM type until the *value* is created, whereas the global needs to be created based on the type alone, because lowering the value may reference the global as a pointer.
2021-09-30Merge remote-tracking branch 'origin/master' into llvm13Andrew Kelley
2021-09-20Address Spaces: Implement in LLVM codegenRobin Voetter
2021-09-15Merge remote-tracking branch 'origin/master' into llvm13Andrew Kelley
Conflicts: * cmake/Findclang.cmake * cmake/Findlld.cmake * cmake/Findllvm.cmake In master branch, more search paths were added to these files with "12" in the path. In this commit I updated them to "13". * src/stage1/codegen.cpp * src/zig_llvm.cpp * src/zig_llvm.h In master branch, ZigLLVMBuildCmpXchg is improved to add `is_single_threaded`. However, the LLVM 13 C API has this already, and in the llvm13 branch, ZigLLVMBuildCmpXchg is deleted in favor of the C API. In this commit I updated stage2 to use the LLVM 13 C API rather than depending on an improved ZigLLVMBuildCmpXchg. Additionally, src/target.zig largestAtomicBits needed to be updated to include the new m68k ISA.
2021-09-14stage2: implement cmpxchg and improve comptime evalAndrew Kelley
* Implement Sema for `@cmpxchgWeak` and `@cmpxchgStrong`. Both runtime and comptime codepaths are implement. * Implement Codegen for LLVM backend and C backend. * Add LazySrcLoc.node_offset_builtin_call_argX 3...5 * Sema: rework comptime control flow. - `error.ComptimeReturn` is used to signal that a comptime function call has returned a result (stored in the Inlining struct). `analyzeCall` notices this and handles the result. - The ZIR instructions `break_inline`, `block_inline`, `condbr_inline` are now redundant and can be deleted. `break`, `block`, and `condbr` function equivalently inside a comptime scope. - The ZIR instructions `loop` and `repeat` also are modified to directly perform comptime control flow inside a comptime scope, skipping an unnecessary mechanism for analysis of runtime code. This makes Zig perform closer to an interpreter when evaluating comptime code. * Sema: zirRetErrValue looks at Sema.ret_fn_ty rather than sema.func for adding to the inferred error set. This fixes a bug for inlined/comptime function calls. * Implement ZIR printing for cmpxchg. * stage1: make cmpxchg respect --single-threaded - Our LLVM C++ API wrapper failed to expose this boolean flag before. * Fix AIR printing for struct fields showing incorrect liveness data.
2021-09-01saturating arithmetic builtins: add, sub, mul, shl (#9619)travisstaloch
- adds 1 simple behavior tests for each which does integer and vector ops at runtime and comptime - adds bigint_*_sat() methods for each - use CreateIntrinsic() which accepts a variable number of arguments to pass the scale parameter * update langref - added case to test/compile_errors.zig given floats - explain upstream bug in llvm.smul.fix.sat and link to #9643 in langref and commented out test cases * sat-arithmetic: skip mul tests if arch == .wasm32 because ci is erroring with 'LLVM ERROR: Unable to expand fixed point multiplication' when compiling for wasm32