Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
286 commits
Select commit Hold shift + click to select a range
7918c94
improve performance of bsiter()
Jan 5, 2017
f5917c3
attempt to fix cc flags in tests
Jan 5, 2017
260178d
prepare for new c9x infrastructure
Jan 7, 2017
0602ad4
remove styling from generated html
Jan 7, 2017
e38da51
isel fixes for lame apple assembler
Jan 10, 2017
2b4ece6
use a less obtuse api for vnew()
Jan 13, 2017
9fbb276
change 'b' and 'h' ordering in IL doc
Jan 20, 2017
cec21e6
create an instruction index for the IL doc
Jan 20, 2017
4d65638
fix bug in varadd(), thanks Ed Davis
Feb 1, 2017
d4be94b
fix the same bug in varget()
Feb 1, 2017
835b2b4
create an index for the instructions in the IL doc
Jan 20, 2017
7e1c1f9
use uint for block ids
Feb 6, 2017
1a76fd1
robustness fix in fillfron()
Feb 6, 2017
8215b50
fix edge deletion bug in sccp
Feb 6, 2017
c71f44c
update assert() missed in 7e1c1f
Feb 8, 2017
8799dc3
make rsp and rbp globally live
Feb 8, 2017
b99a8b0
support variable argument lists
Feb 8, 2017
d9f1121
tests for variable argument lists
Feb 8, 2017
b698584
update minic for new vararg support
Feb 8, 2017
249af91
minor cleanup in all.h
Feb 14, 2017
a9d8133
add support for closure calls
Feb 16, 2017
28ab26c
comment fix
Feb 16, 2017
2f99913
stricter class constraints for store & vastart
Feb 17, 2017
a940cc8
turn the instruction index into a list
Feb 22, 2017
eebbb69
do not err on address comparisons
Feb 21, 2017
0689986
propagate aliasing information through copies
Feb 23, 2017
5c35f60
add simple idiomatic c test
Feb 23, 2017
fc124dd
update isel comment
Feb 24, 2017
f330102
reenable and fix a bug in memopt
Feb 24, 2017
1bb7652
deduplicate loadsz & storesz
Feb 24, 2017
0699cd2
improve the range of action of load elimination
Feb 24, 2017
5165fca
wrong assumption killsl()
Feb 24, 2017
a35dc8c
fix pretty bad bug in alias analysis
Feb 24, 2017
df61dec
start a new simplification pass
Feb 24, 2017
e46b4e3
cosmetic modifications to emit.c
Feb 24, 2017
2c2db15
do sign/zero extensions removal in copy.c
Feb 25, 2017
da9a30b
cosmetic fixes
Feb 27, 2017
3aecf46
update license years
Feb 27, 2017
e80252a
scrub assembly output
Feb 27, 2017
7432b0a
fix int parsing
Feb 27, 2017
4c3c80e
minor tweaks to simpljmp pass
Feb 27, 2017
f151e42
remove unused parameter from uffind()
Feb 27, 2017
1a31330
add install and uninstall targets to Makefile
Feb 27, 2017
c6f8985
make install/uninstall phonies
Feb 27, 2017
02408ff
add another idiomatic C test (rega does no good)
Mar 1, 2017
81e2fda
improve global registers handling
mpu Mar 29, 2017
9d1c38d
fix bug in union size computation
mpu Apr 9, 2017
49a4593
prepare for multi-target
mpu Apr 9, 2017
9683685
rework storage of types
mpu Apr 9, 2017
61090c7
new arm64 backend, yeepee
mpu Apr 9, 2017
e4bc351
add cross testing for arm64
mpu Apr 9, 2017
f4ddc9e
enable arm64 tests
mpu Apr 9, 2017
5c5aaeb
new abi test for arm64 HFAs
mpu Apr 9, 2017
37064c6
use amd64 instead of x64 in abi doc
mpu Apr 9, 2017
6fd78ec
nits in the documentation
mpu Apr 9, 2017
d6316a9
add instructions to build on windows
mpu Apr 9, 2017
5fde07c
add handy src target to the Makefile
mpu Apr 9, 2017
c52f916
misc fixes for osx
mpu Apr 7, 2017
8241685
always disable pie in tests
mpu Apr 9, 2017
19801b9
simplify slot logic in alias analysis
mpu Apr 10, 2017
dc4cc49
bump the size of the instruction buffer
mpu Apr 10, 2017
669d808
simplify amd64 aggregates classification
mpu Apr 11, 2017
1883ab1
unscrew freebsd tests
mpu Apr 11, 2017
b9c8724
remove html converter
mpu Apr 14, 2017
138b09a
minor changes for env parameter
mpu Apr 16, 2017
0d77e26
documentation update
mpu Apr 17, 2017
51c46ba
Small corrections in documentation
Apr 19, 2017
425a2ed
do not account for interferences in phi classes
mpu May 16, 2017
436d0fc
change the computation of spill costs for phis
mpu May 16, 2017
2d02070
new hinting in the register allocator
mpu May 16, 2017
a3a1451
intern symbol names
mpu May 17, 2017
6628867
free the typ vector at the end of parse()
mpu May 17, 2017
5dcf8c1
fix floating-point division
mpu Jun 6, 2017
9908ae0
isreg() does not need to be inlined
mpu Jun 6, 2017
64c79ed
fix fp subtractions on amd64
mpu Jun 6, 2017
2b64b75
fix dynamic stack allocs for amd64
mpu Jul 27, 2017
ae80e4f
fix bug in jumps simplification
mpu Aug 17, 2017
fedb1fa
mark printf call as variadic in test
mpu Sep 22, 2017
e54f7a0
adjust test.sh for ubuntu
Sep 25, 2017
39b1f46
fix compiler command in testcc
eush77 Oct 6, 2017
e7a3875
Fix compiler warnings.
esg Apr 26, 2018
f1c865f
more compiler warnings...
mpu Apr 26, 2018
316b57e
new spiller heuristic for loops
mpu Feb 5, 2019
834b5cb
fix a bad bug in regalloc boilerplate
mpu Feb 5, 2019
ce0ab53
2 bug fixes in rega
mpu Feb 6, 2019
d9b0d77
soften heuristic of 316b57
mpu Feb 6, 2019
cde5f95
mark phi arguments as escaping
mpu Feb 18, 2019
ccd4154
Fix typo
michaelforney Feb 1, 2019
fcd55bb
doc: Include `align` in data BNF
michaelforney Feb 14, 2019
dad4550
amd64: Fix typo in truncd instruction
michaelforney Feb 14, 2019
44fbc60
Fix assertion failure if temporary was spilled in all predecessors
michaelforney Feb 17, 2019
cf9f2e8
doc: Aggregate types can be nested
michaelforney Feb 20, 2019
a877ba9
fix amd64 addressing mode matcher
mpu Feb 21, 2019
dadf6d6
prefer bigger amd64 addressing
mpu Feb 25, 2019
b2ea8c1
new copy elimination pass
mpu Feb 21, 2019
c043227
Let runtime crash on zero div, don't fold it.
andrewchambers Feb 27, 2019
60804c9
update copyright years
mpu Feb 28, 2019
a85fe6e
skip expensive ssa-building loop when possible
mpu Mar 1, 2019
52392ca
fix in load elimination (vacall is a call)
michaelforney Mar 7, 2019
b15a6d4
use a hash table to parse temporaries
mpu Mar 8, 2019
bcc90d0
make sure phis are temporaries in rega
mpu Mar 9, 2019
ec1b186
add a stress test for phi spilling
mpu Mar 9, 2019
c37347a
emit valid code for mem->mem copies
mpu Mar 12, 2019
fd65f42
improve range-checking macros
mpu Mar 12, 2019
b777cd6
simple heuristic to reuse stack slots
mpu Mar 12, 2019
f622efa
Rearrange the fields in Ins so the bit-fields get packed together
michaelforney Feb 14, 2019
d84f5fc
make sure a spill slot is initialized
mpu Apr 8, 2019
81da1cd
properly detect ssa form
mpu Apr 11, 2019
2a8584c
handle big constants moves to slots
mpu Apr 15, 2019
60142f5
bump NString and NPred
mpu Apr 16, 2019
ff4e5aa
avoid some gcc warnings
mpu Apr 17, 2019
636568d
Fix default config.h for arm64
michaelforney Apr 23, 2019
b4a98c3
cleanup amd64 constant addressing
mpu Apr 25, 2019
82f5ba5
restore some code from b4a98c
mpu Apr 26, 2019
905575d
Allow stack allocations larger than SHRT_MAX * 4 bytes
michaelforney Apr 25, 2019
6592457
amd64/isel: Error if alloc size doesn't fit in Tmp slot type
michaelforney Apr 25, 2019
2a60575
Fix config.h dependency when OBJDIR != obj
michaelforney Apr 25, 2019
dda8727
update conaddr test to catch early segfaults
mpu Apr 26, 2019
47ee853
new large test to evaluate performance
mpu Apr 26, 2019
3a6cc4d
add missing gas prefix
mpu Apr 29, 2019
e2bc0ad
amd64: Use unordered compare for floating points
michaelforney Apr 28, 2019
0384d73
fold: Make sure 32-bit constants get sign extended when necessary
michaelforney Apr 27, 2019
660a8d9
fix folding of unsigned operations
mpu Apr 29, 2019
4b7f02c
isel fix for amd64 memory stores
mpu Apr 30, 2019
2e7d6b2
revert heuristic to reuse stack slots
mpu May 2, 2019
34fee80
detect ubiquitous simple copies
mpu May 2, 2019
84b889c
move fillloop() after fold()
mpu May 2, 2019
c8ffe72
gas: use .balign instead of .align
mpu May 2, 2019
b1063d4
emit only one epilog per function
mpu May 4, 2019
e6c216b
revert last commit
mpu May 5, 2019
7ba69be
fuse epilog deduplication with jump threading
mpu May 5, 2019
6130985
add asm diffing in test script
mpu May 5, 2019
1b1a7f6
fix a bad bug in copy detection
mpu May 14, 2019
72f2e84
drop dead declaration
mpu May 14, 2019
9e7e5bf
Allow specifying literal global names
michaelforney May 14, 2019
359c4eb
arm64: Use 32-bit register name when loading 'b' or 'h' into 'l'
michaelforney May 8, 2019
8655181
arm64: Handle truncd instruction
michaelforney May 8, 2019
7837770
arm64: Handle stack allocations larger than 4095 bytes
michaelforney May 8, 2019
acc3af4
Fix a few uses of gassym missed in 9e7e5bff
michaelforney May 16, 2019
7bf08ff
minic: fix undefined symbol linkage issue
Jul 8, 2019
190263f
copy: Fix use of compound literal outside its scope
michaelforney Nov 20, 2019
9de5726
Use a dynamic array for phi arguments
michaelforney Apr 19, 2020
706d6be
Move NPred in parse.c and decrease it
michaelforney Apr 19, 2020
84f1e29
arm64: Make sure SP stays aligned by 16
michaelforney Apr 19, 2020
9639940
rega: Fix allocation of multiple temporaries to the same register
michaelforney Apr 19, 2020
f059f8b
amd64: Use member class for aggregate parameter temporary
michaelforney Apr 19, 2020
5e5e301
fix a typo in call's BNF
mpu Aug 6, 2020
496c069
fold: zero-initialize padding bits of constants
michaelforney Sep 19, 2020
4756643
docs/llvm: Fix typo jeoparadized -> jeopardized
laumann Feb 15, 2021
2feb742
arm64: handle stack offsets >=4096 in Oaddr
michaelforney Mar 2, 2021
201881d
gas: emit GNU-stack note so that stack is not executable
michaelforney Oct 21, 2020
cdee1d8
silence a gcc10 warning
mpu Mar 2, 2021
83c2108
add data $name = section "section" ...
ddevault Aug 10, 2020
4e81cc2
renaming in gas.c
mpu Mar 2, 2021
99c8f84
fix a couple asan complaints
mpu Mar 2, 2021
be3a67a
arm64: try qemu-system-aarch64
rurban Dec 2, 2020
d3313ad
disable pie for arm64 tests
mpu Mar 2, 2021
9c4e4bc
Arrange debug flag table to match pass order
michaelforney Mar 12, 2021
a2962bb
arm64: fix selcall call data for return of aggregate in memory
michaelforney Mar 12, 2021
0678bee
Revert "arm64: try qemu-system-aarch64"
michaelforney Mar 17, 2021
097dc86
use toolchain to determine aarch64 sysroot path
michaelforney Mar 17, 2021
e0b94a3
spill: use stronger assertion for registers in use at start of function
michaelforney Mar 12, 2021
6d9ee13
amd64: fix conditional jump when compare is swapped and used elsewhere
michaelforney Jun 17, 2021
7f4ab8d
fix amd64 addressing selection bug (afl)
mpu Jul 27, 2021
5a4369d
fix buffer overflow in parser (afl)
mpu Jul 27, 2021
b543ffe
handle fast locals in amd64 shifts (afl)
mpu Jul 27, 2021
98cd2e8
load: handle all cases in cast()
michaelforney Apr 11, 2021
3da3815
err when an address contains a sum $a+$b (afl)
mpu Jul 29, 2021
0437e97
gas: always emit GNU-stack note
ericonr Jul 11, 2021
2bbfcf6
copy: consider identity element for more instructions
michaelforney Jul 7, 2021
f3414a4
parsefields: fix padding calculation
ddevault Aug 17, 2021
2dd269f
test: include exit status in test failure reason
michaelforney Aug 17, 2021
3cbad4d
amd64/emit.c: fix %x =k sub %x, %x
esawady Aug 13, 2021
804921a
amd64/isel: fix floating < and <= result with NaN
michaelforney Aug 17, 2021
7ac88f5
amd64/isel: fix floating point == and != result with NaN
michaelforney Aug 22, 2021
028534d
skip jump arguments in rega
mpu Aug 30, 2021
649a546
test: assign result of print functions to temporary
michaelforney Sep 5, 2021
6a69210
test: use architecture-neutral wrapper for calling vprintf
michaelforney Sep 5, 2021
52c8eb4
skip nx stack annotation on osx
mpu Sep 9, 2021
bb16529
parse: fix loadw when assigned to l temporary
michaelforney Sep 14, 2021
ae23a32
avoid some one last gcc truncation warning
michaelforney Sep 25, 2021
8401139
util: fix typo preventing 4-byte copy in blit()
michaelforney Sep 25, 2021
4309ac5
spill: add some comments describing functions
michaelforney Sep 25, 2021
462e49f
add size suffix to frame setup.
andrewchambers Oct 13, 2021
503c672
amd64/sysv: unbreak env calls
mpu Oct 17, 2021
9858a12
use -static when cross-compiling tests
mpu Oct 17, 2021
fcdef10
make variadic args explicit
mpu Oct 18, 2021
5f994fe
arm64: handle slots
michaelforney May 9, 2019
542825d
arm64: Handle slots in Ocopy operands
michaelforney May 10, 2019
5dbc5dc
arm64: handle copy of constant to slot
michaelforney Mar 25, 2021
5e0ba15
arm64/emit.c: fix move instructions with big immediate values
Jul 11, 2021
fd33b2e
arm64: Add LR to list of registers to save
michaelforney Mar 26, 2021
b2a2521
spill: fix regs assertions
mpu Oct 25, 2021
9dec866
remove trailing whitespace from test/abi7.ssa
michaelforney Oct 26, 2021
900805a
use unified diff format for test output
michaelforney Oct 26, 2021
0d68986
new chacha20 test
mpu Oct 28, 2021
cd095a4
fix for sloppy reg->mem in arm64 abi
mpu Nov 8, 2021
ae8803c
amd64: avoid reading past end of passed struct
michaelforney Sep 25, 2021
6838496
fold: Don't fold invalid addition/subtraction rather than failing
michaelforney Jul 3, 2019
49fb63e
bump NString
mpu Nov 10, 2021
b0f16da
fold: Prevent error when address is used as operand
michaelforney Jun 16, 2019
bf153b3
reuse previous address constants in fold()
michaelforney Nov 18, 2021
367c821
arm64: fix slots with offset >32k
mpu Dec 5, 2021
e91d121
Add a negation instruction
esawady Jan 17, 2022
55a1522
check for fopen() errors for output file
Jan 19, 2022
49654f8
bump copyright year
mpu Jan 23, 2022
b0d27d8
increase token limit to 255
Jan 19, 2022
74d022f
implement unsigned -> float casts
Jan 28, 2022
3964574
implement float -> unsigned casts
Jan 28, 2022
2fd3a95
update token hash params
mpu Jan 28, 2022
8403dcb
fix test/fpcnv (wrong spacing)
mpu Jan 28, 2022
f913cb0
amd64/isel: nits
mpu Jan 28, 2022
a32ecfb
Do not use the asm keyword as a local variable
winspool Jan 28, 2022
20ee522
arm64: handle large slots in Ocopy
mpu Jan 31, 2022
2ca6fb2
shared linkage logic for func/data
mpu Jan 31, 2022
9fc0394
doc: fix name of export linkage flag
p-ouellette Feb 11, 2022
7aceb24
gas: put zero data into .bss by default
michaelforney Feb 10, 2022
e092473
document the automatic use of bss
mpu Feb 11, 2022
630127c
spill: consider jump argument as use of register
michaelforney Feb 12, 2022
3b75357
Revert "skip jump arguments in rega"
michaelforney Feb 12, 2022
2cba9f6
cfg: remove unnecessary check for jump type
michaelforney Feb 12, 2022
8e040d5
test: add c[u]od checks to isel2 and add new integer compare test isel3
michaelforney Feb 12, 2022
4e93eea
add rv64 backend
michaelforney Feb 12, 2022
e7c13e8
fix folding of shifts of word operand by >32
p-ouellette Feb 23, 2022
e04a2cd
doc: minor fixes
p-ouellette Feb 17, 2022
9793857
parse: allow string after first data item
p-ouellette Feb 17, 2022
42cbdc0
improve consistency in arm64 and rv64 abis
mpu Feb 25, 2022
65821c9
disable pie for rv64 tests
mpu Feb 25, 2022
c0cdef2
rv64: cosmetics in isel
mpu Feb 25, 2022
ddd101d
doc: Add missing neg entry to index
Feb 25, 2022
457e568
rv64: formatting and bug fix in epilogue
mpu Feb 27, 2022
3d29434
doc: export function main in hello world example
oldaccountdeadname Mar 6, 2022
349794f
cosmetics
mpu Mar 8, 2022
9060981
flag types defined as unions
mpu Mar 8, 2022
7f7e34c
new abi stress test
mpu Mar 10, 2022
e6debbb
two new tests in abi5.ssa
mpu Mar 10, 2022
a9e4fa9
rv64: plug holes in the abi
mpu Mar 10, 2022
c7842d8
dust off antique .tag
mpu Mar 11, 2022
905e9ce
arm64/abi: fix big aggregates passed on the stack
mpu Mar 14, 2022
7a7a5f4
improve consistency in abis
mpu Mar 14, 2022
6ca9399
output symbol type and size
mpu Mar 14, 2022
329a18a
add rv64/ to README
mpu Mar 14, 2022
c5769f6
dynamic stack allocs for arm64
mpu Mar 14, 2022
c656c48
fix register count in riscv argregs
mpu Mar 15, 2022
01142fa
support env calls on arm64
mpu Mar 15, 2022
da36b21
homogenize riscv and arm abis
mpu Mar 15, 2022
2416d29
new -t? flag to print default target
mpu Mar 15, 2022
cec9855
detect target in tests
mpu Mar 15, 2022
bf2a90e
fix return for big aggregates
mpu Mar 17, 2022
c6b41eb
amd64: restore previous name of amd64_sysv target
michaelforney Mar 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .tag

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
© 2015-2016 Quentin Carbonneaux <quentin@c9x.me>
© 2015-2022 Quentin Carbonneaux <quentin@c9x.me>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
68 changes: 57 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
BIN = qbe
ABI = sysv

V = @
OBJDIR = obj

SRC = main.c util.c parse.c mem.c ssa.c copy.c fold.c live.c $(ABI).c isel.c spill.c rega.c emit.c
OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
SRC = main.c util.c parse.c cfg.c mem.c ssa.c alias.c load.c copy.c \
fold.c live.c spill.c rega.c gas.c
AMD64SRC = amd64/targ.c amd64/sysv.c amd64/isel.c amd64/emit.c
ARM64SRC = arm64/targ.c arm64/abi.c arm64/isel.c arm64/emit.c
RV64SRC = rv64/targ.c rv64/abi.c rv64/isel.c rv64/emit.c
SRCALL = $(SRC) $(AMD64SRC) $(ARM64SRC) $(RV64SRC)

AMD64OBJ = $(AMD64SRC:%.c=$(OBJDIR)/%.o)
ARM64OBJ = $(ARM64SRC:%.c=$(OBJDIR)/%.o)
RV64OBJ = $(RV64SRC:%.c=$(OBJDIR)/%.o)
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(AMD64OBJ) $(ARM64OBJ) $(RV64OBJ)

CFLAGS += -Wall -Wextra -std=c99 -g -pedantic

Expand All @@ -19,28 +27,66 @@ $(OBJDIR)/%.o: %.c $(OBJDIR)/timestamp

$(OBJDIR)/timestamp:
@mkdir -p $(OBJDIR)
@mkdir -p $(OBJDIR)/amd64
@mkdir -p $(OBJDIR)/arm64
@mkdir -p $(OBJDIR)/rv64
@touch $@

$(OBJ): all.h
obj/main.o: config.h
$(OBJ): all.h ops.h
$(AMD64OBJ): amd64/all.h
$(ARM64OBJ): arm64/all.h
$(RV64OBJ): rv64/all.h
$(OBJDIR)/main.o: config.h

config.h:
@case `uname` in \
*Darwin*) echo "#define Defaultasm Gasmacho" ;; \
*) echo "#define Defaultasm Gaself" ;; \
@case `uname` in \
*Darwin*) \
echo "#define Defasm Gasmacho"; \
echo "#define Deftgt T_amd64_sysv"; \
;; \
*) \
echo "#define Defasm Gaself"; \
case `uname -m` in \
*aarch64*) \
echo "#define Deftgt T_arm64"; \
;; \
*riscv64*) \
echo "#define Deftgt T_rv64"; \
;; \
*) \
echo "#define Deftgt T_amd64_sysv";\
;; \
esac \
;; \
esac > $@

install: $(OBJDIR)/$(BIN)
mkdir -p "$(DESTDIR)/$(PREFIX)/bin/"
cp $< "$(DESTDIR)/$(PREFIX)/bin/"

uninstall:
rm -f "$(DESTDIR)/$(PREFIX)/bin/$(BIN)"

clean:
rm -fr $(OBJDIR)

clean-gen: clean
rm -f config.h

check: $(OBJDIR)/$(BIN)
tools/unit.sh all
tools/test.sh all

check-arm64: $(OBJDIR)/$(BIN)
TARGET=arm64 tools/test.sh all

check-rv64: $(OBJDIR)/$(BIN)
TARGET=rv64 tools/test.sh all

src:
@echo $(SRCALL)

80:
@for F in $(SRC); \
@for F in $(SRCALL); \
do \
awk "{ \
gsub(/\\t/, \" \"); \
Expand All @@ -49,4 +95,4 @@ check: $(OBJDIR)/$(BIN)
}" < $$F; \
done

.PHONY: clean clean-gen check 80 syndoc
.PHONY: clean clean-gen check check-arm64 src 80 install uninstall
5 changes: 4 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ QBE - Backend Compiler http://c9x.me/compile/
doc/ Documentation.
minic/ An example C frontend for QBE.
tools/ Miscellaneous tools (testing).
test/ Unit tests.
test/ Tests.
amd64/
arm64/
rv64/ Architecture-specific code.

The LICENSE file applies to all files distributed.

Expand Down
169 changes: 169 additions & 0 deletions alias.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#include "all.h"

static void
getalias(Alias *a, Ref r, Fn *fn)
{
Con *c;

switch (rtype(r)) {
default:
die("unreachable");
case RTmp:
*a = fn->tmp[r.val].alias;
if (astack(a->type))
a->type = a->slot->type;
assert(a->type != ABot);
break;
case RCon:
c = &fn->con[r.val];
if (c->type == CAddr) {
a->type = ASym;
a->label = c->label;
} else
a->type = ACon;
a->offset = c->bits.i;
a->slot = 0;
break;
}
}

int
alias(Ref p, int sp, Ref q, int sq, int *delta, Fn *fn)
{
Alias ap, aq;
int ovlap;

getalias(&ap, p, fn);
getalias(&aq, q, fn);
*delta = ap.offset - aq.offset;
ovlap = ap.offset < aq.offset + sq && aq.offset < ap.offset + sp;

if (astack(ap.type) && astack(aq.type)) {
/* if both are offsets of the same
* stack slot, they alias iif they
* overlap */
if (req(ap.base, aq.base) && ovlap)
return MustAlias;
return NoAlias;
}

if (ap.type == ASym && aq.type == ASym) {
/* they conservatively alias if the
* symbols are different, or they
* alias for sure if they overlap */
if (ap.label != aq.label)
return MayAlias;
if (ovlap)
return MustAlias;
return NoAlias;
}

if ((ap.type == ACon && aq.type == ACon)
|| (ap.type == aq.type && req(ap.base, aq.base))) {
assert(ap.type == ACon || ap.type == AUnk);
/* if they have the same base, we
* can rely on the offsets only */
if (ovlap)
return MustAlias;
return NoAlias;
}

/* if one of the two is unknown
* there may be aliasing unless
* the other is provably local */
if (ap.type == AUnk && aq.type != ALoc)
return MayAlias;
if (aq.type == AUnk && ap.type != ALoc)
return MayAlias;

return NoAlias;
}

int
escapes(Ref r, Fn *fn)
{
Alias *a;

if (rtype(r) != RTmp)
return 1;
a = &fn->tmp[r.val].alias;
return !astack(a->type) || a->slot->type == AEsc;
}

static void
esc(Ref r, Fn *fn)
{
Alias *a;

assert(rtype(r) <= RType);
if (rtype(r) == RTmp) {
a = &fn->tmp[r.val].alias;
if (astack(a->type))
a->slot->type = AEsc;
}
}

void
fillalias(Fn *fn)
{
uint n, m;
Blk *b;
Phi *p;
Ins *i;
Alias *a, a0, a1;

for (n=0; n<fn->nblk; ++n) {
b = fn->rpo[n];
for (p=b->phi; p; p=p->link) {
for (m=0; m<p->narg; m++)
esc(p->arg[m], fn);
assert(rtype(p->to) == RTmp);
a = &fn->tmp[p->to.val].alias;
assert(a->type == ABot);
a->type = AUnk;
a->base = p->to;
a->offset = 0;
a->slot = 0;
}
for (i=b->ins; i<&b->ins[b->nins]; ++i) {
a = 0;
if (!req(i->to, R)) {
assert(rtype(i->to) == RTmp);
a = &fn->tmp[i->to.val].alias;
assert(a->type == ABot);
if (Oalloc <= i->op && i->op <= Oalloc1) {
a->type = ALoc;
a->slot = a;
} else {
a->type = AUnk;
a->slot = 0;
}
a->base = i->to;
a->offset = 0;
}
if (i->op == Ocopy) {
assert(a);
getalias(a, i->arg[0], fn);
}
if (i->op == Oadd) {
getalias(&a0, i->arg[0], fn);
getalias(&a1, i->arg[1], fn);
if (a0.type == ACon) {
*a = a1;
a->offset += a0.offset;
}
else if (a1.type == ACon) {
*a = a0;
a->offset += a1.offset;
}
}
if (req(i->to, R) || a->type == AUnk) {
if (!isload(i->op))
esc(i->arg[0], fn);
if (!isstore(i->op))
esc(i->arg[1], fn);
}
}
esc(b->jmp.arg, fn);
}
}
Loading