Commit graph

92 commits

Author SHA1 Message Date
Quentin Carbonneaux
626f0b2781 skip preludes for some leaf fns
When rbp is not necessary to compile
a leaf function, we skip saving and
restoring it.
2024-08-23 18:31:53 +02:00
Quentin Carbonneaux
efcb5465e5 align emitted code
Functions are now aligned on 16-byte
boundaries. This mimics gcc and should
help reduce the maximum perf impact of
cosmetic code changes. Previously, any
change in the output of qbe could have
far reaching implications on alignment.

Thanks to Roland Paterson-Jones for
pointing out the variability issue.
2024-08-15 23:11:41 +02:00
Roland Paterson-Jones
cf9f95f521 Optab-driven copy detection 2024-06-09 22:33:38 +02:00
Michael Forney
99169df2ff parse: use dynamically sized hashtable for temporaries
This significantly improves parsing performance for massive functions
with a huge number of temporaries. Parsing the 86MiB IL produced
by cproc during zig bootstrap drops from 17m15s to 2.5s (over 400x
speedup).

The speedup is much smaller for IL produced from normal non-autogenerated
C code. Parsing the sqlite3 amalgamation drops from 0.40s to 0.33s.
2024-04-13 13:31:02 +02:00
Quentin Carbonneaux
8ded7a56a2 add common linkage for data 2024-04-12 11:33:58 +02:00
Quentin Carbonneaux
2d046a0ac6 use mgen in amd64/isel.c 2024-04-09 21:47:16 +02:00
Quentin Carbonneaux
dc3f7d7c4a fix accidentally noop loop
Credit goes to Roland Paterson-Jones
for spotting this bug.
2024-04-04 21:56:50 +02:00
Quentin Carbonneaux
de5ced474d do not parse +N constants
The parsing code for these constants
conflicts with the Tplus token.
2024-04-03 23:30:07 +02:00
Michael Forney
85827e2232 check that data alignment is in range and a power of two
Otherwise, the alignment gets truncated to fit in char, so
`align 256` is handled as no alignment requirement.
2024-03-28 10:35:11 +01:00
Drew DeVault
85287081c4 dbgloc: add column argument
dbgloc line [col]

This is implemented in a backwards-compatible manner.
2024-01-02 12:12:05 +01:00
Quentin Carbonneaux
36946a5142 file,loc become dbgfile,dbgloc 2023-08-18 15:12:56 +02:00
Quentin Carbonneaux
baf11b7175 parseline() tweaks 2023-06-07 10:11:58 +02:00
Thomas Bracht Laumann Jespersen
0d929287d7 implement line number info tracking
Support "file" and "loc" directives. "file" takes a string (a file name)
assigns it a number, sets the current file to that number and records
the string for later. "loc" takes a single number and outputs location
information with a reference to the current file.
2023-06-06 18:44:51 +02:00
Quentin Carbonneaux
28d9ca8eae print prefix for thread-local symbols 2023-04-02 15:20:16 +02:00
Quentin Carbonneaux
5fee3da6ac rename blknew() to newblk()
This is consistent with newtmp()
and newcon().
2023-03-22 11:43:46 +01:00
Quentin Carbonneaux
5e9726946d new UNDEF Ref
Crashing loads of uninitialized memory
proved to be a problem when implementing
unions using qbe.  This patch introduces
a new UNDEF Ref to represent data that is
known to be uninitialized.  Optimization
passes can make use of it to eliminate
some code.  In the last compilation stages,
UNDEF is treated as the constant 0xdeaddead.
2022-12-25 16:37:33 +01:00
Quentin Carbonneaux
26c1c30b7d new blit instruction 2022-12-14 23:18:26 +01:00
Quentin Carbonneaux
c0f25aeae3 new rsval() helper for signed Refs
The .val field is signed in RSlot.
Add a new dedicated function to
fetch it as a signed int.
2022-12-12 22:16:33 +01:00
Quentin Carbonneaux
9126afa2da new hlt block terminator
It is handy to express when
the end of a block cannot be
reached. If a hlt terminator
is executed, it traps the
program.

We don't go the llvm way and
specify execution semantics as
undefined behavior.
2022-11-27 21:48:21 +01:00
Quentin Carbonneaux
cbee74bdb4 use a new struct for symbols
Symbols are a useful abstraction
that occurs in both Con and Alias.
In this patch they get their own
struct. This new struct packages
a symbol name and a type; the type
tells us where the symbol name
must be interpreted (currently, in
gobal memory or in thread-local
storage).

The refactor fixed a bug in
addcon(), proving the value of
packaging symbol names with their
type.
2022-11-22 21:56:21 +01:00
Quentin Carbonneaux
4e90b4210e "rel" fields become "reloc" 2022-10-08 21:48:47 +02:00
Quentin Carbonneaux
00a30954ac add support for thread-local storage
The apple targets are not done yet.
2022-10-08 21:48:42 +02:00
Quentin Carbonneaux
5cea0c20ee flag bad vastart uses 2022-10-03 10:41:30 +02:00
Quentin Carbonneaux
70f297bab7 fix case of Pool constants 2022-10-03 10:41:30 +02:00
Quentin Carbonneaux
0b26cd4f5e parse sb,ub,sh,uh abi types 2022-10-03 10:41:03 +02:00
Ember Sawady
bdaf8d374e Fix parsing of multiple globals in datadef
Eg. data $a = { w $b $c }
2022-09-15 09:09:30 +02:00
Roberto E. Vargas Caballero
c8cd2824ea Reject multiple section definition for a symbol 2022-07-01 13:20:45 +02:00
Roberto E. Vargas Caballero
d9935ac14a Add qbe identifier in error strings
When qbe is used with other tools is a bit hard to identify
what is the tool that is generating the error. Adding an
identifier at the beginning of the line makes much easier
to identify the tool generating the error.
2022-07-01 13:19:33 +02:00
Quentin Carbonneaux
5f4b42abc7 do not leak type fields
Thanks to Daniel Xu for reporting.
2022-04-11 14:36:36 +02:00
Quentin Carbonneaux
9060981c10 flag types defined as unions
The risc-v abi needs to know if a
type is defined as a union or not.

We cannot use nunion to obtain this
information because the risc-v abi
made the unfortunate decision of
treating

	union { int i; }

differently from

	int i;

So, instead, I introduce a single
bit flag 'isunion'.
2022-03-08 15:57:06 +01:00
Paul Ouellette
979385718b parse: allow string after first data item 2022-02-24 13:11:41 +01:00
Michael Forney
7aceb24c50 gas: put zero data into .bss by default
This allows frontends to use BSS generically, without knowledge of
platform-dependent details.
2022-02-11 08:49:42 +01:00
Quentin Carbonneaux
2ca6fb25a2 shared linkage logic for func/data 2022-02-02 21:09:37 +01:00
Quentin Carbonneaux
2fd3a95d6f update token hash params 2022-01-28 11:07:40 +01:00
Bor Grošelj Simić
b0d27d8a01 increase token limit to 255 2022-01-23 14:19:07 +01:00
Eyal Sawady
e91d121581 Add a negation instruction
Necessary for floating-point negation, because
`%result = sub 0, %operand` doesn't give the correct sign for 0/-0.
2022-01-23 11:43:59 +01:00
Michael Forney
bf153b359e reuse previous address constants in fold()
parseref() has code to reuse address constants, but this is not
done in other passes such as fold or isel. Introduce a new function
newcon() which takes a Con and returns a Ref for that constant, and
use this whenever creating address constants.

This is necessary to fix folding of address constants when one
operand is already folded. For example, in

	%a =l add $x, 1
	%b =l add %a, 2
	%c =w loadw %b

%a and %b were folded to $x+1 and $x+3 respectively, but then the
second add is visited again since it uses %a. This gets folded to
$x+3 as well, but as a new distinct constant. This results in %b
getting labeled as bottom instead of either constant, disabling the
replacement of %b by a constant in subsequent instructions (such
as the loadw).
2021-11-22 18:07:50 +01:00
Quentin Carbonneaux
fcdef10dae make variadic args explicit
Some abis, like the riscv one, treat
arguments differently depending on
whether they are variadic or not.
To prepare for the upcomming riscv
target, we change the variadic call
syntax and give meaning to the
location of the '...' marker.

  # new syntax
  %ret =w call $f(w %regular, ..., w %variadic)

By nature of their abis, the change
is backwards compatible for existing
targets.
2021-10-22 23:53:25 +02:00
Michael Forney
bb16529b34 parse: fix loadw when assigned to l temporary
The documentation states that loadw is syntactic sugar for loadsw,
but it actually got parsed as Oload. If the result is an l temporary,
Oload behaves like Oloadl, not Oloadsw.

To fix this, parse Tloadw as Oloadsw explicitly.
2021-09-20 09:10:10 +02:00
Drew DeVault
f3414a492b parsefields: fix padding calculation
This was causing issues with aggregate types. A simple reproduction is:

type :type.1 = align 8 { 24 }
type :type.2 = align 8 { w 1, :type.1 1 }

The size of type.2 should be 32, adding only 4 bytes of padding between
the first and second field. Prior to this patch, 20 bytes of padding was
added instead, causing the type to have a size of 48.

Signed-off-by: Drew DeVault <sir@cmpwn.com>
2021-08-23 10:03:13 +02:00
Quentin Carbonneaux
5a4369dd27 fix buffer overflow in parser (afl)
Reported by Alessandro Mantovani.
Overly long function names would
trigger out-of-bounds accesses.
2021-07-28 00:53:09 +02:00
Drew DeVault
83c2108341 add data $name = section "section" ...
This allows you to explicitly specify the section to emit the data
directive for, allowing for sections other than .data: for example, .bss
or .init_array.
2021-03-02 10:00:08 +01:00
Michael Forney
706d6beca6 Move NPred in parse.c and decrease it
This now only limits the number of arguments when parsing the input SSA,
which is usually a small fixed size (depending on the frontend).
2020-08-06 10:07:14 +02:00
Michael Forney
9de57265ce Use a dynamic array for phi arguments 2020-08-06 09:51:12 +02:00
Michael Forney
9e7e5bffc4 Allow specifying literal global names 2019-05-15 10:20:12 +02:00
Michael Forney
f622efa05a Rearrange the fields in Ins so the bit-fields get packed together 2019-03-14 10:12:55 +01:00
Quentin Carbonneaux
b15a6d47dc use a hash table to parse temporaries 2019-03-08 22:01:08 +01:00
Quentin Carbonneaux
f1c865f4bc more compiler warnings... 2018-04-26 22:59:30 +02:00
Emil Skoeldberg
e7a3875859 Fix compiler warnings.
Compiler warned about comparison between signed and unsigned values.
2018-04-26 22:49:36 +02:00
Quentin Carbonneaux
66288673cd free the typ vector at the end of parse() 2017-05-17 11:17:17 -04:00