Commit Graph

1444 Commits

Author SHA1 Message Date
Robin Voetter decdedf97d spirv: add names to globals and initializers 2023-09-23 12:36:56 -07:00
Robin Voetter 924235a023 spirv: emit OpLogical(Not)Equal for comparing bools 2023-09-23 12:36:56 -07:00
Robin Voetter c7c0517ac0 spirv: emit OpNot for arithmetic not 2023-09-23 12:36:56 -07:00
Robin Voetter 5141b4e05c spirv: fix store of undef 2023-09-23 12:36:56 -07:00
Robin Voetter f16d1603ab spirv: fix type_map use-after-realloc issues 2023-09-23 12:36:44 -07:00
Robin Voetter 42226fc1b7 spirv: make construct(Struct|Array) use the Function storage class 2023-09-23 12:36:44 -07:00
Robin Voetter 06d9e3b2eb spirv: always emit unsigned integers
This is required for SPIR-V in Kernel mode. The Intel
implementation just didn't care about this fact.
2023-09-23 12:36:44 -07:00
Robin Voetter 18d0909ada spirv: fixes 2023-09-23 12:36:44 -07:00
Robin Voetter 66036e6000 spirv: remove indirect constant lowering
It is stupid and I hate it.
2023-09-23 12:36:44 -07:00
Robin Voetter b30cd67987 spirv: put global var initializers in functions 2023-09-23 12:36:44 -07:00
Robin Voetter 240f9d740d spirv: lower union initialization at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter d06862b759 spirv: lower struct aggregate initialization at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter 001d76a412 spirv: lower array aggregate at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter ae17831cc0 spirv: lower opt constants 2023-09-23 12:36:44 -07:00
Robin Voetter 3e2553c712 spirv: lower ptr constants 2023-09-23 12:36:44 -07:00
Robin Voetter cc13864dfb spirv: lower enum_tag constants 2023-09-23 12:36:44 -07:00
Robin Voetter aeaaa953a0 spirv: assign type names to (error) unions 2023-09-23 12:36:44 -07:00
Robin Voetter ece52640eb spirv: construct error union at runtime 2023-09-23 12:36:44 -07:00
Robin Voetter ced8a2c3a6 spirv: add type_map to map AIR types to SPIR-V types
This will help us both to make the implementation a little
more efficient by caching emission for certain types like structs,
and also allow us to attach extra information about types that we
can use while lowering without performing a search over the entire
type tree for some property.
2023-09-23 12:36:44 -07:00
Robin Voetter 79f7481575 spirv: disable failing tests 2023-09-23 12:36:44 -07:00
Andrew Kelley 747440677d LLVM: fix UAF when lowering debug info for structs
Gotta call the get() function inside the loop if the loop adds anything
to InternPool.
2023-09-21 21:55:41 -07:00
Andrew Kelley 81b5df347a compiler: fix structFieldName crash for tuples
When struct types have no field names, the names are implicitly
understood to be strings corresponding to the field indexes in
declaration order. It used to be the case that a NullTerminatedString
would be stored for each field in this case, however, now, callers must
handle the possibility that there are no names stored at all. This
commit introduces `legacyStructFieldName`, a function to fake the
previous behavior. Probably something better could be done by reworking
all the callsites of this function.
2023-09-21 17:29:34 -07:00
mlugg 1b672e41c5 InternPool,Sema,type,llvm: alignment fixes
This changeset fixes the handling of alignment in several places. The
new rules are:
* `@alignOf(T)` where `T` is a runtime zero-bit type is at least 1,
  maybe greater.
* Zero-bit fields in `extern` structs *do* force alignment, potentially
  offsetting following fields.
* Zero-bit fields *do* have addresses within structs which can be
  observed and are consistent with `@offsetOf`.

These are not necessarily all implemented correctly yet (see disabled
test), but this commit fixes all regressions compared to master, and
makes one new test pass.
2023-09-21 14:48:41 -07:00
mlugg ada83fa557 compiler: get codegen of behavior tests working on at least one backend
We're hitting false compile errors, but this is progress!
2023-09-21 14:48:40 -07:00
Andrew Kelley baea62a8ad fix regressions from this branch 2023-09-21 14:48:40 -07:00
Andrew Kelley accd5701c2 compiler: move struct types into InternPool proper
Structs were previously using `SegmentedList` to be given indexes, but
were not actually backed by the InternPool arrays.

After this, the only remaining uses of `SegmentedList` in the compiler
are `Module.Decl` and `Module.Namespace`. Once those last two are
migrated to become backed by InternPool arrays as well, we can introduce
state serialization via writing these arrays to disk all at once.

Unfortunately there are a lot of source code locations that touch the
struct type API, so this commit is still work-in-progress. Once I get it
compiling and passing the test suite, I can provide some interesting
data points such as how it affected the InternPool memory size and
performance comparison against master branch.

I also couldn't resist migrating over a bunch of alignment API over to
use the log2 Alignment type rather than a mismash of u32 and u64 byte
units with 0 meaning something implicitly different and special at every
location. Turns out you can do all the math you need directly on the
log2 representation of alignments.
2023-09-21 14:48:40 -07:00
Jacob Young b1b155feac llvm: update riscv floating-point c abi for LLVM 17 2023-09-19 09:37:32 -07:00
Jacob Young 3506bc61b7 llvm: update data layout computation to LLVM 17 2023-09-19 09:37:32 -07:00
Jacob Young cad594372e llvm: update address space definitions to LLVM 17 2023-09-19 09:37:32 -07:00
Jacob Young 05e01301b0 Builder: further constant select cleanup 2023-09-19 09:37:32 -07:00
Andrew Kelley 6a07b7024a LLVM: update backend to LLVM 17
* LLVMConstSelect is removed (see
   https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179)
 * a couple functions use uint64_t instead of int now which means we
   no longer need `@intCast`.

release/17.x branch, commit 8f4dd44097c9ae25dd203d5ac87f3b48f854bba8
2023-09-19 09:37:31 -07:00
Andrew Kelley 62a12e0631 LLVM 17 std lib updates and fixes
* some manual fixes to generated CPU features code. in the future it
   would be nice to make the script do those automatically. I suspect
   the sm_90a thing is a bug in LLVM.
 * add liteos to various target OS switches. I know nothing about this
   OS; someone will need to work specifically on support for this OS
   when the time comes to support it properly in zig.
 * while waiting for the compiler, I went ahead and made more
   conservative choices about when to use `inline` in std/Target.zig
2023-09-19 09:37:31 -07:00
Andrew Kelley cd8234c3ba update for LLVM 17 new target data
New OSs:
* UEFI
* LiteOS

New ABI:
* OpenHOS

Also update the LLD driver API wrappers.
2023-09-19 09:37:30 -07:00
Andrew Kelley c970dbdfec LLVM: cache LLVM struct field indexes
This is an optimization to avoid O(N) field index lookups. It's also
nicer in terms of DRY; the only tradeoff is memory usage.
2023-09-18 00:09:30 -07:00
Andrew Kelley cb6201715a InternPool: prevent anon struct UAF bugs with type safety
Instead of using actual slices for InternPool.Key.AnonStructType, this
commit changes to use Slice types instead, which store a
long-lived index rather than a pointer.

This is a follow-up to 7ef1eb1c27.
2023-09-12 20:08:56 -04:00
Jacob Young c429bb5d2f llvm/cbe: support slice in @prefetch
Closes #16967
2023-08-28 19:04:53 -07:00
Andrew Kelley ada0010471 compiler: move unions into InternPool
There are a couple concepts here worth understanding:

Key.UnionType - This type is available *before* resolving the union's
fields. The enum tag type, number of fields, and field names, field
types, and field alignments are not available with this.

InternPool.UnionType - This one can be obtained from the above type with
`InternPool.loadUnionType` which asserts that the union's enum tag type
has been resolved. This one has all the information available.

Additionally:

* ZIR: Turn an unused bit into `any_aligned_fields` flag to help
  semantic analysis know whether a union has explicit alignment on any
  fields (usually not).
* Sema: delete `resolveTypeRequiresComptime` which had the same type
  signature and near-duplicate logic to `typeRequiresComptime`.
  - Make opaque types not report comptime-only (this was inconsistent
    between the two implementations of this function).
* Implement accepted proposal #12556 which is a breaking change.
2023-08-22 13:54:14 -07:00
Jacob Young 4ac20f69ac Revert "llvm: fix bootstrap"
This reverts commit ea72fea1a4.
2023-08-20 12:40:34 -07:00
mlugg 7a85ad151d cbe: elide block result allocation for 0-bit types
This logic already existed for the void type, but is also necessary for
other 0-bit types. Without it, we try to alloc a local for a 0-bit type
which gets translated to a local of type `void` which C doesn't like.
2023-08-20 11:58:14 -07:00
Lewis Gaul 387b0ac4f1 Make NaNs quiet by default and other NaN tidy-up (#16826)
* Generalise NaN handling and make std.math.nan() give quiet NaNs

* Address uses of std.math.qnan_* and std.math.nan_* consts

* Comment out failing test due to issues with signalling NaN

* Fix issue in c_builtins.zig where we need qnan_u32
2023-08-18 02:07:49 -04:00
Andrew Kelley 7ef1eb1c27 InternPool: safer enum API
The key changes in this commit are:

```diff
-        names: []const NullTerminatedString,
+        names: NullTerminatedString.Slice,
-        values: []const Index,
+        values: Index.Slice,
```

Which eliminates the slices from `InternPool.Key.EnumType` and replaces
them with structs that contain `start` and `len` indexes. This makes the
lifetime of `EnumType` change from expiring with updates to InternPool,
to expiring when the InternPool is garbage-collected, which is currently
never.

This is gearing up for a larger change I started working on locally
which moves union types into InternPool.

As a bonus, I fixed some unnecessary instances of `@as`.
2023-08-17 18:16:03 -07:00
mlugg 083ee8e0e2 InternPool: preserve indices of builtin types when resolved
Some builtin types have a special InternPool index (e.g.
`.type_info_type`) so that AstGen can refer to them before semantic
analysis. Unfortunately, this previously led to a second index existing
to refer to the type once it was resolved, complicating Sema by having
the concept of an "unresolved" type index.

This change makes Sema modify these InternPool indices in-place to
contain the expanded representation when resolved. The analysis of the
corresponding decls is caught in `Module.semaDecl`, and a field is set
on Sema telling it which index to place struct/union/enum types at. This
system could break if `std.builtin` contained complex decls which
evaluate multiple struct types, but this will be caught by the
assertions in `InternPool.resolveBuiltinType`.

The AstGen result types which were disabled in 6917a8c have been
re-enabled.

Resolves: #16603
2023-08-15 11:45:23 +01:00
Jacob Young 1c5c3f499a cmake: fix auto-detection of various host targets
Closes #16800
2023-08-13 11:26:10 -07:00
Jacob Young c4848694d2 llvm: enable even without libllvm linked 2023-08-09 05:47:13 -04:00
Jacob Young 3e1dd93bb2 llvm: force strip without libllvm to avoid unimplemented behavior
Also fix deinit bugs.
2023-08-08 23:32:40 -04:00
Jacob Young 53bea0f7e4 llvm: remove dependence on llvm data layout alignment
by just using the zig alignment and letting llvm promote it as desired
2023-08-08 22:09:44 -04:00
Jacob Young 35cd56a369 llvm: fix alias issues 2023-08-08 21:32:50 -04:00
Jacob Young 2bdd180c6f llvm: finish converting globals 2023-08-08 21:32:50 -04:00
Jacob Young 2499d8fb73 Builder: fix enough bugs to pass the behavior tests
without using any information from the LLVM API
2023-08-08 21:32:50 -04:00
Jacob Young a66cd54f94 llvm: cleanup even more unused LLVM API bindings 2023-08-08 21:32:50 -04:00