1112 Commits

Author SHA1 Message Date
Robin Voetter
3c5ab4dd3d
spirv: add liveness checks
When a result of a pure instruction is not used, it also does not need to
be generated. The other backends already implement these checks, they were
ignored in SPIR-V up until now. New instructions added in the future should
have these be implemented from the start.
2023-04-09 01:51:49 +02:00
Robin Voetter
39016948f0
spirv: slice types
Implements type lowering for slices.
2023-04-09 01:51:49 +02:00
Robin Voetter
3f92eaceb6
spirv: array, structs, bitcast, call
Implements type lowering for arrays and structs, and implements instruction
lowering for bitcast and call. Bitcast currently naively maps to the OpBitcast
instruction - this is only valid for some primitive types, and should be
improved to work with composites.
2023-04-09 01:51:49 +02:00
Robin Voetter
dae8b4c11f
spirv: emit OpName for some primitive types
OpName instructions assign a debug name to a type. Some basic
types - bool, void, ints, and floats are given a debug name this way.
TODO is to extend this to the other types.
2023-04-09 01:51:49 +02:00
Robin Voetter
3eafe3033e
spirv: improve storage efficiency for integer and float types
In practice there are only a few variations of these types allowed, so it
kind-of makes sense to write them all out. Because the types are hashed this
does not actually save all that many bytes in the long run, though. Perhaps
some of these types should be pre-registered?
2023-04-09 01:51:48 +02:00
Robin Voetter
5826a8a064
spirv: make Type.Ref stronger
Making Type.Ref an unbounded enum rather than a simple integer
ensures that we don't accidently confuse this token for another type.
2023-04-09 01:51:48 +02:00
Robin Voetter
a60308f87c
spirv: enum type
This gives the spir-v backend the power to emit enum types. These
are simply lowered to their backing integer type.
2023-04-09 01:51:48 +02:00
Robin Voetter
df5577c28b
spirv: allow more calling conventions
This allows the Zig calling convention and makes way for a Kernel
calling convention in the future. Any future checks on calling
conventions should be placed in Sema.zig.
2023-04-09 01:51:48 +02:00
Jacob Young
a7f674d6c1
cbe: assert there are no unfreed locals
Also fix the many revealed bugs.
2023-04-07 01:29:20 +01:00
mlugg
1059b57898
Liveness: defer deaths of externally-scoped instructions in loop bodies 2023-04-07 01:29:20 +01:00
Andrew Kelley
f289277599 Merge remote-tracking branch 'origin/master' into llvm16 2023-04-05 22:05:31 -07:00
Jacob Young
243848167b compiler_rt: attempt to fix f16 abi on mac with llvm 16 2023-04-05 22:05:06 -07:00
Jacob Young
f4b411314c Sema: defer stores to inferred allocs
This lets us generate the store with knowledge of the type to be stored.
Therefore, we can avoid generating garbage Air with stores through
pointers to comptime-only types which backends cannot lower.

Closes #13410
Closes #15122
2023-04-02 18:05:44 +03:00
Robin Voetter
3357c59ceb new builtins: @workItemId, @workGroupId, @workGroupSize
* @workItemId returns the index of the work item in a work group for a
  dimension.
* @workGroupId returns the index of the work group in the kernel dispatch for a
  dimension.
* @workGroupSize returns the size of the work group for a dimension.

These builtins are mainly useful for GPU backends. They are currently only
implemented for the AMDGCN LLVM backend.
2023-03-30 12:20:24 +03:00
Tw
11903436a9 llvm/bpf: disable llvm builtins for bpf target
As bpf program has no global section for constant values (especially strings),
so use llvm's builtins (like memcpy, memset, etc) will lead to compilation failure
(something like this: A call to built-in function 'memcpy' is not supported.)

Signed-off-by: Tw <tw19881113@gmail.com>
2023-03-30 12:11:04 +03:00
Jacob Young
0543def52f llvm: fix crashes when loading a struct field
The result of buildStructGEP is not always a GEP (sorry), so we can't
use getGEPResultElementType on it.

Closes #14641
2023-03-30 11:54:24 +03:00
Jacob Young
dd66e0addb Sema: fix empty slice pointer value
We just checked that inst_child_ty was effectively a zero-bit type, so
it is certainly not the non-zero alignment we are looking for.

Closes #15085
2023-03-28 23:12:19 +03:00
Xavier Bouchoux
898e4473e8 CBE: implement aggregateInit() for array of array case.
fixes `error(compilation): clang failed with stderr: error: array type 'uint32_t[10]' (aka 'unsigned int[10]') is not assignable`
2023-03-21 14:56:04 +02:00
Veikka Tuominen
773b1c4c5c llvm: fix lowering packed union initiated to zero-bit value
Closes #14980
2023-03-21 00:34:12 +02:00
Andrew Kelley
5c4bbd0657 Merge remote-tracking branch 'origin/master' into llvm16 2023-03-17 14:55:22 -07:00
Jacob Young
cfcd6698cd main: add debug option to dump unoptimized llvm ir 2023-03-17 01:57:14 -04:00
Andrew Kelley
1ed569e0b2 Merge remote-tracking branch 'origin/master' into llvm16 2023-03-16 17:33:24 -07:00
Jacob Young
77d06012c2 CBE: implement unsigned big int div and mod 2023-03-07 03:03:35 -05:00
Andrew Kelley
48e72960a4 llvm: fix lowering of @trap
It needed an unreachable instruction after it.
2023-03-05 17:23:09 -07:00
Andrew Kelley
2641feb9b9
Merge pull request #14789 from jacobly0/ditype
llvm: fix use after free with pointers to optional slices
2023-03-05 16:32:51 -05:00
Jacob Young
1efd36cd5c CBE: fix reduce of emulated integers 2023-03-05 06:32:55 -05:00
Jacob Young
33fa25ba44 CBE: ensure uniqueness of more internal identifiers 2023-03-05 02:59:02 -05:00
Jacob Young
0b0298aff2 CBE: implement select and shuffle 2023-03-05 02:59:02 -05:00
Jacob Young
aac4707902 CBE: implement splat 2023-03-05 02:59:02 -05:00
Jacob Young
ba69ee488b CBE: implement vector truncate 2023-03-05 02:59:02 -05:00
Jacob Young
8f6da78fb1 CBE: implement vector element pointers 2023-03-05 02:59:02 -05:00
Jacob Young
c478c7609e CBE: implement vector operations
Also, bigint add and sub which is all I was actually trying to do.
2023-03-05 02:59:02 -05:00
Jacob Young
9e3a5ecd39 CBE: fix behavior test failures on msvc 2023-03-05 02:59:02 -05:00
Jacob Young
93d696e84e CBE: implement some big integer and vector unary operations 2023-03-05 02:59:01 -05:00
Jacob Young
a8f4ac2b94 CBE: implement big integer and vector comparisons 2023-03-05 02:59:01 -05:00
Jacob Young
874ae81f1b CBE: implement big integer literals 2023-03-05 02:59:01 -05:00
Jacob Young
2cf27c5718 llvm: fix incorrectly annotated DIType
Closes #14715
Closes #14783
2023-03-04 13:52:47 -07:00
r00ster91
65368683ad add @trap builtin
This introduces a new builtin function that compiles down to something that results in an illegal instruction exception/interrupt.
It can be used to exit a program abnormally.

This implements the builtin for all backends.
2023-03-04 12:08:19 +01:00
Andrew Kelley
df4cfc2ecf Merge remote-tracking branch 'origin/master' into llvm16 2023-03-03 12:08:18 -07:00
Andrew Kelley
d399f8a489 Merge remote-tracking branch 'origin/master' into llvm16 2023-02-27 16:10:48 -07:00
Jacob Young
9e51972701 llvm: fix untagged struct names in debug info for llvm (again)
At least lldb misbehaves with all these same-named unions, so just
generate a unique name.
2023-02-27 05:18:47 -05:00
Jacob Young
477be90c0c CBE: replace locals list with a hash map
Replace `ArrayList` with `ArrayHashMap` since we want to be able to
remove by element.
2023-02-25 00:27:07 -05:00
Jacob Young
1453a595aa CBE: reuse locals with the same CType instead of Type
Many `Type`s can correspond to the same `CType`, so this reduces the
number of used locals by 27760 when compiling only-c.

Also, disabled some tests that were only passing by accident and
shouldn't really be considered working.
2023-02-24 23:41:54 -05:00
Jacob Young
f8aecef670 CBE: implement the future
Turns out f(...) will be supported one day.
2023-02-23 21:25:29 -05:00
Jacob Young
1f3d9f79c1 CBE: apply some maybe payload cleanups 2023-02-23 20:30:59 -05:00
Jacob Young
c0671a92c7 CBE: simplify always_tail call logic
It should be Sema's job to check this anyway.
2023-02-23 20:30:59 -05:00
Jacob Young
3a1cb62317 CBE: delete stage1 hacks 2023-02-23 20:30:59 -05:00
Jacob Young
8ccdc74949 CType: cleanup 2023-02-23 20:30:59 -05:00
Jacob Young
9d24d0354f CBE: fix MSVC diagnostics generated by the behavior tests
After this, the last MSVC warnings are in behavior/bugs/529.zig:
behavior.c(37971): warning C4133: 'function': incompatible types - from 'A__8479 *' to 'A__8474 *'
behavior.c(37974): warning C4133: 'function': incompatible types - from 'A__8480 *' to 'A__8474 *'
2023-02-23 20:30:59 -05:00
Jacob Young
a0d7fd162b CBE: support call attributes
* Support always_tail and never_tail/never_inline with a comptime callee using clang
 * Support never_inline using gcc
 * Support never_inline using msvc

Unfortunately, can't enable behavior tests because of the conditional support.
2023-02-23 10:54:26 -05:00