aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm
AgeCommit message (Collapse)Author
2023-04-21cbe: fix issues with atomic floatsJacob Young
Since the Zig language documentation claims support for `.Min` and `.Max` in `@atomicRmw` with floats, allow in Sema and implement for both the llvm and C backends.
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-03-17Merge remote-tracking branch 'origin/master' into llvm16Andrew Kelley
2023-03-17main: add debug option to dump unoptimized llvm irJacob Young
2023-01-26update CPU features to LLVM 16Andrew Kelley
2023-01-25update zig_llvm.cpp and zig_llvm.h to LLVM 16Andrew Kelley
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.