aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm
AgeCommit message (Collapse)Author
2023-01-04Sema: implement AVR address spacesMaciej 'vesim' KuliƄski
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2023-01-03add -fopt-bisect-limitGuillaume Wenzek
2022-12-27llvm: cleanup code no longer needed with opaque pointersJacob Young
When using llvm opaque pointers, typed pointers and pointer bitcasts are no longer needed. This also avoids needing packed struct layouts that are nested inside pointers, letting us avoid computing struct layouts in Sema that could cause unnecessary dependency loops.
2022-12-17implement defining C variadic functionsVeikka Tuominen
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-09-21LLVM: remove purposeless const qualifiersAndrew Kelley
These const qualifiers on pointers to opaque types do not serve any purpose. If anything they are misleading since the underlying pointers very likely point to objects that are in fact mutated. This commit does not change any behavior.
2022-09-13properly annotate nullability of ZigLLVMCreateDebugForwardDeclTypeAndrew Kelley
This bug manifested as a segfault in stage1 when calling this function. The C++ code looks like this: ```c++ entry->llvm_di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, ZigLLVMTag_DW_structure_type(), full_name, import ? ZigLLVMFileToScope(import->data.structure.root_struct->di_file) : nullptr, import ? import->data.structure.root_struct->di_file : nullptr, line); ``` There is actually no problem here - what happened is that because cross-language LTO was enabled between zig and c++ code, and because Zig annotated the file parameter (3rd line) as being non-null, the C++ code assumed that parameter could not be null, and eagerly dereferenced `import->...`, causing a segfault, since it was null. I verified that this commit fixed the problem and I also verified this hypothesis by disabling LTO and noticing that it indeed avoided the problem.
2022-08-29Merge remote-tracking branch 'origin/master' into llvm15Andrew Kelley
2022-08-19LLVM: add DLL export attributeAndrew Kelley
This was present in stage1 but missing from self-hosted.
2022-08-10stage2 llvm: implement more C ABIVeikka Tuominen
2022-08-10LLVM: respect linksection for exported variablesAndrew Kelley
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-01stage2: LLVM lowering to opaque pointers APIAndrew Kelley
2022-08-01stage1: LLVM lowering to opaque pointers APIAndrew Kelley
2022-07-31update Target, CPU, OS, ABI, etc. to LLVM 15Andrew Kelley
2022-07-27LLVM: fix lowering byte-aligned packed struct field pointersAndrew Kelley
2022-07-23stage2: implement `@setFloatMode`Veikka Tuominen
2022-07-14LLVM: fix ABI size of optional and error union typesAndrew Kelley
Previously, the Zig ABI size and LLVM ABI size of these types disagreed sometimes. This code also corrects the logging messages to not trigger LLVM assertions.
2022-07-14LLVM: insert debug logging when LLVM ABI size is wrongAndrew Kelley
2022-07-03LLVM: update inline asm to LLVM14 semanticsAndrew Kelley
This is the equivalent of d19290e603833a197bc8bfc8315561ec77291225 applied to stage2 instead of stage1.
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-06-30stage2: lower float negation explicitlyAndrew Kelley
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-11stage2: improve debugging toolsVeikka Tuominen
llvm: dump failed module when -femit-llvm-ir set print_air: * print fully qualified name * use Type.fmt and Value.fmtValue, fmtDebug is useless TypedValue * handle anon structs and tuples * fix bugs
2022-05-31LLVM: add target-cpu and target-features fn attributesAndrew Kelley
2022-05-20LLVM: rework calling convention loweringAndrew Kelley
The previous implementation of calling conventions was hacky and broken. This commit reworks lowerFnParamTy into iterateParamTypes which returns enum tags indicating how to handle each parameter. This is then used in the three places that matter: * lowering a function type to llvm type * converting function parameters to the canonical type representation (with respect to isByRef). * converting canonical type representation to function arguments at callsites (again with respect to isByRef). As a result, we are one step closer to the C ABI tests passing. Before this commit, attempting to build them crashed the compiler. I isolated the broken function and verified that it now is lowered correctly. I will keep working on this one piece at a time until all the C ABI tests pass, and then I will enable all of them in the CI.
2022-05-10Add Visibility field to ExportOptions.Takeshi Yoneda
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2022-05-06LLVM: rework the previous commitAndrew Kelley
Idiomatic Zig, use const instead of var, simplify the logic.
2022-05-04stage2: implement global assemblyAndrew Kelley
So far it's supported by the LLVM backend only. I recommend for the other backends to wait for the resolution of #10761 before adding support for this feature.
2022-05-02LLVM: set module PIC, PIE, and CodeModelAndrew Kelley
Some simple code from stage1 ported over to stage2.
2022-04-27stage2: fix recent LLVM backend codeAndrew Kelley
* std.math.snan: fix compilation error. Also make it and nan inline. * LLVM: use a proper enum type for float op instead of enum literal. Also various cleanups. * LLVM: use LLVMBuildVectorSplat for vector splat AIR instruction. - also the bindings had parameter order wrong * LLVM: additionally handle f16 lowering. For now all targets report OK but I think we will need to add some exceptions to this list.
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-04-15stage2: fix bugs preventing stage2 from building stage3 with LLVMVeikka Tuominen
2022-03-28stage2: LLVM: (WIP) add union fields debug infoJohn Schmidt
2022-03-27LLVM: handle aggregate_init for packed structsAndrew Kelley
2022-03-17stage2: implement `@reduce`Andrew Kelley
Notably, Value.eql and Value.hash are improved to treat NaN as equal to itself, so that Type/Value can be hash map keys. Likewise float hashing normalizes the float value before computing the hash.
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-03-08LLVM: add DISubprogram and DIType lowering; handle dbg_stmtAndrew Kelley
2022-03-08LLVM: add compile unit to debug infoAndrew Kelley
This commit also adds a bunch of bindings for debug info.
2022-03-03LLVM: fix lowering of unions and switchesAndrew Kelley
`Module.Union.getLayout` now additionally returns a `padding` field which tells how many bytes are between the final field end offset and the ending offset of the union. This is used by the LLVM backend to explicitly insert padding. LLVM backend: lowering of unions now inserts additional padding so that LLVM's internals will agree on the ABI size to match what ABI size zig wants unions to be. This is an alternative to calling LLVMABISizeOfType and LLVMABIAlignmentOfType which end up crashing when recursive struct definitions come into play. We no longer ever call these two functions and the bindings are deleted to avoid future footgun firings. LLVM backend: lowering of unions now represents untagged unions consistently. Before it was tripping an assertion. LLVM backend: switch cases call inttoptr on the case items and condition if necessary. Prevents tripping an LLVM assertion. After this commit, we are no longer tripping over any LLVM assertions.
2022-03-02stage2: implement `@extern`Veikka Tuominen
2022-03-01LLVM: add extra padding to structs and tuples sometimesAndrew Kelley
* Sema: resolve type fully when emitting an alloc AIR instruction to avoid tripping assertion for checking struct field alignment. * LLVM backend: keep a reference to the LLVM target data alive during lowering so that we can ask LLVM what it thinks the ABI alignment and size of LLVM types are. We need this in order to lower tuples and structs so that we can put in extra padding bytes when Zig disagrees with LLVM about the size or alignment of something. * LLVM backend: make the LLVM struct type packed that contains the most aligned union field and the padding. This prevents the struct from being too big according to LLVM. In the future, we may want to consider instead emitting unions in a "flat" manner; putting the tag, most aligned union field, and padding all in the same struct field space. * LLVM backend: make structs with 2 or fewer fields return isByRef=false. This results in more efficient codegen. This required lowering of bitcast to sometimes store the struct into an alloca, ptrcast, and then load because LLVM does not allow bitcasting structs. * enable more passing behavior tests.
2022-03-01LLVM: fix tripping assertionsAndrew Kelley
Packed structs were tripping an LLVM assertion due to calling `LLVMConstZExt` from i16 to i16. Solved by using instead `LLVMConstZExtOrBitCast`. Unions were tripping an LLVM assertion due to a typo using the union llvm type to construct an integer value rather than the tag type.
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.