aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/lower.go
AgeCommit message (Collapse)Author
2021-03-04cmd/compile: implement simple register resultsDavid Chase
at least for ints and strings includes simple test For #40724. Change-Id: Ib8484e5b957b08f961574a67cfd93d3d26551558 Reviewed-on: https://go-review.googlesource.com/c/go/+/295309 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-03cmd/compile: retrieve Args from registersDavid Chase
in progress; doesn't fully work until they are also passed on register on the caller side. For #40724. Change-Id: I29a6680e60bdbe9d132782530214f2a2b51fb8f6 Reviewed-on: https://go-review.googlesource.com/c/go/+/293394 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-02-26cmd/compile: change StaticCall to return a "Results"David Chase
StaticLECall (multiple value in +mem, multiple value result +mem) -> StaticCall (multiple ergister value in +mem, multiple register-sized-value result +mem) -> ARCH CallStatic (multiple ergister value in +mem, multiple register-sized-value result +mem) But the architecture-dependent stuff is indifferent to whether it is mem->mem or (mem)->(mem) until Prog generation. Deal with OpSelectN -> Prog in ssagen/ssa.go, others, as they appear. For #40724. Change-Id: I1d0436f6371054f1881862641d8e7e418e4a6a16 Reviewed-on: https://go-review.googlesource.com/c/go/+/293391 Trust: David Chase <drchase@google.com> Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-08-27cmd/compile: invalidate zero-use values during rewriteKeith Randall
This helps remove uses that aren't needed any more. That in turn helps other rules with Uses==1 conditions fire. Update #39918 Change-Id: I68635b675472f1d59e59604e4d34b949a0016533 Reviewed-on: https://go-review.googlesource.com/c/go/+/249463 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2018-12-28cmd/compile,runtime: redo mid-stack inlining tracebacksKeith Randall
Work involved in getting a stack trace is divided between runtime.Callers and runtime.CallersFrames. Before this CL, runtime.Callers returns a pc per runtime frame. runtime.CallersFrames is responsible for expanding a runtime frame into potentially multiple user frames. After this CL, runtime.Callers returns a pc per user frame. runtime.CallersFrames just maps those to user frame info. Entries in the result of runtime.Callers are now pcs of the calls (or of the inline marks), not of the instruction just after the call. Fixes #29007 Fixes #28640 Update #26320 Change-Id: I1c9567596ff73dc73271311005097a9188c3406f Reviewed-on: https://go-review.googlesource.com/c/152537 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2018-04-20cmd/compile: don't lower OpConvertAustin Clements
Currently, each architecture lowers OpConvert to an arch-specific OpXXXconvert. This is silly because OpConvert means the same thing on all architectures and is logically a no-op that exists only to keep track of conversions to and from unsafe.Pointer. Furthermore, lowering it makes it harder to recognize in other analyses, particularly liveness analysis. This CL eliminates the lowering of OpConvert, leaving it as the generic op until code generation time. The main complexity here is that we still need to register-allocate OpConvert operations. Currently, each arch's lowered OpConvert specifies all GP registers in its register mask. Ideally, OpConvert wouldn't affect value homing at all, and we could just copy the home of OpConvert's source, but this can potentially home an OpConvert in a LocalSlot, which neither regalloc nor stackalloc expect. Rather than try to disentangle this assumption from regalloc and stackalloc, we continue to register-allocate OpConvert, but teach regalloc that OpConvert can be allocated to any allocatable GP register. For #24543. Change-Id: I795a6aee5fd94d4444a7bafac3838a400c9f7bb6 Reviewed-on: https://go-review.googlesource.com/108496 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2016-09-14cmd/compile: make ssa compilation unconditionalKeith Randall
Rip out the code that allows SSA to be used conditionally. No longer exists: ssa=0 flag GOSSAHASH GOSSAPKG SSATEST GOSSAFUNC now only controls the printing of the IR/html. Still need to rip out all of the old backend. It should no longer be callable after this CL. Update #16357 Change-Id: Ib30cc18fba6ca52232c41689ba610b0a94aa74f5 Reviewed-on: https://go-review.googlesource.com/29155 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2016-08-15[dev.ssa] cmd/compile: PPC64, FP to/from int conversions.dev.ssaDavid Chase
Passes ssa_test. Requires a few new instructions and some scratchpad memory to move data between G and F registers. Also fixed comparisons to be correct in case of NaN. Added missing instructions for run.bash. Removed some FP registers that are apparently "reserved" (but that are also apparently also unused except for a gratuitous multiplication by two when y = x+x would work just as well). Currently failing stack splits. Updates #16010. Change-Id: I73b161bfff54445d72bd7b813b1479f89fc72602 Reviewed-on: https://go-review.googlesource.com/26813 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2016-07-18[dev.ssa] cmd/compile: clean up tuple types and selectsKeith Randall
Make tuple types and their SelectX ops fully generic. These ops no longer need to be lowered. Regalloc understands them and their tuple-generating arguments. We can now have opcodes returning arbitrary pairs of results. (And it would be easy to move to >2 results if needed.) Update arm implementation to the new standard. Implement just enough in 386 port to do 64-bit add. Change-Id: I370ed5aacce219c82e1954c61d1f63af76c16f79 Reviewed-on: https://go-review.googlesource.com/24976 Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-06-15[dev.ssa] cmd/compile: handle GetG on ARMCherry Zhang
Use hardware g register (R10) for GetG, allow g to appear at LHS of some ops. Progress on SSA backend for ARM. Now everything compiles and runs. Updates #15365. Change-Id: Icdf93585579faa86cc29b1e17ab7c90f0119fc4e Reviewed-on: https://go-review.googlesource.com/23952 Reviewed-by: David Chase <drchase@google.com>
2016-05-18cmd/compile: keep pointer input arguments live throughout functionKeith Randall
Introduce a KeepAlive op which makes sure that its argument is kept live until the KeepAlive. Use KeepAlive to mark pointer input arguments as live after each function call and at each return. We do this change only for pointer arguments. Those are the critical ones to handle because they might have finalizers. Doing compound arguments (slices, structs, ...) is more complicated because we would need to track field liveness individually (we do that for auto variables now, but inputs requires extra trickery). Turn off the automatic marking of args as live. That way, when args are explicitly nulled, plive will know that the original argument is dead. The KeepAlive op will be the eventual implementation of runtime.KeepAlive. Fixes #15277 Change-Id: I5f223e65d99c9f8342c03fbb1512c4d363e903e5 Reviewed-on: https://go-review.googlesource.com/22365 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2016-01-19[dev.ssa] Merge remote-tracking branch 'origin/master' into mergebranchKeith Randall
Semi-regular merge from tip to dev.ssa. Conflicts: src/runtime/sys_windows_amd64.s Change-Id: I5f733130049c810e6ceacd46dad85faebca52b29
2016-01-13[dev.ssa] cmd/compile: clean up comparisonsKeith Randall
Add new constant-flags opcodes. These can be generated from comparisons that we know the result of, like x&31 < 32. Constant-fold the constant-flags opcodes into all flag users. Reorder some CMPxconst args so they read in the comparison direction. Reorg deadcode removal a bit - it needs to remove the OpCopy ops it generates when strength-reducing Phi ops. So it needs to splice out all the dead blocks and do a copy elimination before it computes live values. Change-Id: Ie922602033592ad8212efe4345394973d3b94d9f Reviewed-on: https://go-review.googlesource.com/18267 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com>
2015-11-03[dev.ssa] cmd/compile: start arguments as spilledKeith Randall
Declare a function's arguments as having already been spilled so their use just requires a restore. Allow spill locations to be portions of larger objects the stack. Required to load portions of compound input arguments. Rename the memory input to InputMem. Use Arg for the pre-spilled argument values. Change-Id: I8fe2a03ffbba1022d98bfae2052b376b96d32dda Reviewed-on: https://go-review.googlesource.com/16536 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
2015-09-05[dev.ssa] cmd/runtime: generate gc bitmaps for SSA-compiled codeKeith Randall
This change is all about leveraging the gc bitmap generation that is already done by the current compiler. We rearrange how stack allocation is done so that we generate a variable declaration for each spill. We also reorganize how args/locals are recorded during SSA. Then we can use the existing allocauto/defframe to allocate the stack frame and liveness to make the gc bitmaps. With this change, stack copying works correctly and we no longer need hacks in runtime/stack*.go to make tests work. GC is close to working, it just needs write barriers. Change-Id: I990fb4e3fbe98850c6be35c3185a1c85d9e1a6ba Reviewed-on: https://go-review.googlesource.com/13894 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-24[dev.ssa] cmd/compile: streamline unimplemented stringsJosh Bleecher Snyder
This aids in making sense of the aggregate set of work outstanding. Interest in the details of any particular implementation failure is better handled locally anyway. In my local tree, running make.bash after this CL yields: 14.85% 1811 SSA unimplemented: unhandled expr SLICEARR 13.84% 1687 SSA unimplemented: unhandled expr CALLINTER 11.84% 1444 SSA unimplemented: unhandled stmt RETJMP 10.24% 1249 SSA unimplemented: unhandled expr EFACE 8.52% 1039 SSA unimplemented: unhandled expr SLICE 4.92% 600 SSA unimplemented: local variable with class PAUTO,heap unimplemented 4.90% 598 SSA unimplemented: unhandled expr SLICESTR 3.91% 477 SSA unimplemented: local variable with class PFUNC unimplemented 3.45% 421 SSA unimplemented: not lowered: IMake INTER PTR64 PTR64 3.42% 417 SSA unimplemented: unhandled expr APPEND 3.21% 391 SSA unimplemented: unhandled expr CLOSUREVAR 3.06% 373 SSA unimplemented: unhandled stmt DEFER 3.04% 371 SSA unimplemented: unhandled stmt AS2DOTTYPE 1.61% 196 SSA unimplemented: unhandled expr DOTTYPE 1.56% 190 SSA unimplemented: not lowered: Load STRUCT PTR64 mem 0.79% 96 SSA unimplemented: not lowered: StringMake STRING PTR64 UINTPTR 0.69% 84 SSA unimplemented: unhandled binary op NE FLOAT64 0.53% 65 SSA unimplemented: unhandled expr STRUCTLIT 0.50% 61 SSA unimplemented: not lowered: SliceMake ARRAY PTR64 UINTPTR UINTPTR 0.45% 55 SSA unimplemented: zero for type float64 not implemented 0.44% 54 SSA unimplemented: unhandled addr CLOSUREVAR 0.38% 46 SSA unimplemented: unhandled binary op EQ FLOAT64 0.35% 43 SSA unimplemented: unhandled binary op LT FLOAT64 0.34% 42 SSA unimplemented: unhandled len(map) 0.33% 40 SSA unimplemented: unhandled stmt FALL 0.23% 28 SSA unimplemented: CONVNOP closure 0.21% 25 SSA unimplemented: local variable with class PPARAM,heap unimplemented 0.21% 25 SSA unimplemented: unhandled binary op GT FLOAT64 0.18% 22 SSA unimplemented: unhandled OCONV FLOAT32 -> FLOAT64 0.18% 22 SSA unimplemented: unhandled expr REAL 0.16% 20 SSA unimplemented: unhandled stmt PROC 0.16% 19 SSA unimplemented: unhandled closure arg 0.15% 18 SSA unimplemented: unhandled OCONV INT64 -> FLOAT64 0.12% 15 SSA unimplemented: unhandled expr CFUNC 0.10% 12 SSA unimplemented: unhandled OCONV UINT64 -> FLOAT64 0.09% 11 SSA unimplemented: unhandled OLITERAL 4 0.09% 11 SSA unimplemented: unhandled expr IMAG 0.07% 9 SSA unimplemented: unhandled binary op GE FLOAT64 0.07% 9 SSA unimplemented: unhandled binary op MINUS FLOAT64 0.06% 7 SSA unimplemented: unhandled OCONV FLOAT64 -> FLOAT32 0.06% 7 SSA unimplemented: unhandled binary op NE FLOAT32 0.06% 7 SSA unimplemented: variable address class 5 not implemented 0.05% 6 SSA unimplemented: not lowered: Load COMPLEX128 PTR64 mem 0.05% 6 SSA unimplemented: unhandled expr SLICE3ARR 0.04% 5 SSA unimplemented: unhandled binary op LE FLOAT64 0.03% 4 SSA unimplemented: unhandled OCONV UINTPTR -> FLOAT64 0.03% 4 SSA unimplemented: unhandled binary op EQ COMPLEX128 0.03% 4 SSA unimplemented: unhandled binary op EQ FLOAT32 0.03% 4 SSA unimplemented: unhandled expr COMPLEX 0.02% 3 SSA unimplemented: local variable with class PPARAMOUT,heap unimplemented 0.02% 3 SSA unimplemented: not lowered: Load ARRAY PTR64 mem 0.02% 3 SSA unimplemented: unhandled OCONV INT32 -> FLOAT64 0.02% 3 SSA unimplemented: unhandled OCONV INT64 -> FLOAT32 0.02% 3 SSA unimplemented: unhandled expr SLICE3 0.02% 2 SSA unimplemented: unhandled OCONV COMPLEX64 -> COMPLEX128 0.02% 2 SSA unimplemented: unhandled OCONV FLOAT64 -> INT64 0.02% 2 SSA unimplemented: unhandled OCONV FLOAT64 -> UINT64 0.02% 2 SSA unimplemented: unhandled OCONV INT -> FLOAT64 0.02% 2 SSA unimplemented: unhandled OCONV UINT64 -> FLOAT32 0.02% 2 SSA unimplemented: unhandled binary op EQ COMPLEX64 0.02% 2 SSA unimplemented: unhandled binary op MINUS FLOAT32 0.02% 2 SSA unimplemented: zero for type complex128 not implemented 0.02% 2 SSA unimplemented: zero for type complex64 not implemented 0.02% 2 SSA unimplemented: zero for type float32 not implemented 0.01% 1 SSA unimplemented: not lowered: EqFat BOOL INTER INTER 0.01% 1 SSA unimplemented: not lowered: Store mem UINTPTR COMPLEX128 mem 0.01% 1 SSA unimplemented: unhandled OCONV UINT32 -> FLOAT64 0.01% 1 SSA unimplemented: unhandled cap(chan) 0.01% 1 SSA unimplemented: unhandled expr ARRAYLIT 0.01% 1 SSA unimplemented: unhandled expr PLUS 0.01% 1 SSA unimplemented: unhandled stmt CHECKNIL Change-Id: I43474fe6d6ec22a9f57239090136f6e97eebfdf2 Reviewed-on: https://go-review.googlesource.com/13848 Reviewed-by: Keith Randall <khr@golang.org>
2015-08-11[dev.ssa] cmd/compile: make failed nil checks panicJosh Bleecher Snyder
Introduce pseudo-ops PanicMem and LoweredPanicMem. PanicMem could be rewritten directly into MOVL during lowering, but then we couldn't log nil checks. With this change, runnable nil check tests pass: GOSSAPKG=main go run run.go -- nil*.go Compiler output nil check tests fail: GOSSAPKG=p go run run.go -- nil*.go This is due to several factors: * SSA has improved elimination of unnecessary nil checks. * SSA is missing elimination of implicit nil checks. * SSA is missing extra logging about why nil checks were removed. I'm not sure how best to resolve these failures, particularly in a world in which the two backends will live side by side for some time. For now, punt on the problem. Change-Id: Ib2ca6824551671f92e0e1800b036f5ca0905e2a3 Reviewed-on: https://go-review.googlesource.com/13474 Reviewed-by: Keith Randall <khr@golang.org>
2015-08-04[dev.ssa] cmd/compile/internal/ssa: implement ITABKeith Randall
Implement ITAB, selecting the itable field of an interface. Soften the lowering check to allow lowerings that leave generic but dead ops behind. (The ITAB lowering does this.) Change-Id: Icc84961dd4060d143602f001311aa1d8be0d7fc0 Reviewed-on: https://go-review.googlesource.com/13144 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-25[dev.ssa] cmd/compile/internal/ssa: Handle variables correctlyKeith Randall
Use *Node of type ONAME instead of string as the key for variable maps. This will prevent aliasing between two identically named but differently scoped variables. Introduce an Aux value that encodes the offset of a variable from a base pointer (either global base pointer or stack pointer). Allow LEAQ and derivatives (MOVQ, etc.) to also have such an Aux field. Allocate space for AUTO variables in stackalloc. Change-Id: Ibdccdaea4bbc63a1f4882959ac374f2b467e3acd Reviewed-on: https://go-review.googlesource.com/11238 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-24[dev.ssa] cmd/compile/ssa: add -f suffix to logging methodsJosh Bleecher Snyder
Requested in CL 11380. Change-Id: Icf0d23fb8d383c76272401e363cc9b2169d11403 Reviewed-on: https://go-review.googlesource.com/11450 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-21[dev.ssa] cmd/compile/ssa: separate logging, work in progress, and fatal errorsJosh Bleecher Snyder
The SSA implementation logs for three purposes: * debug logging * fatal errors * unimplemented features Separating these three uses lets us attempt an SSA implementation for all functions, not just _ssa functions. This turns the entire standard library into a compilation test, and makes it easy to figure out things like "how much coverage does SSA have now" and "what should we do next to get more coverage?". Functions called _ssa are still special. They log profusely by default and the output of the SSA implementation is used. For all other functions, logging is off, and the implementation is built and discarded, due to lack of support for the runtime. While we're here, fix a few minor bugs and add some extra Unimplementeds to allow all.bash to pass. As of now, SSA handles 20.79% of the functions in the standard library (689 of 3314). The top missing features are: 10.03% 2597 SSA unimplemented: zero for type error not implemented 7.79% 2016 SSA unimplemented: addr: bad op DOTPTR 7.33% 1898 SSA unimplemented: unhandled expr EQ 6.10% 1579 SSA unimplemented: unhandled expr OROR 4.91% 1271 SSA unimplemented: unhandled expr NE 4.49% 1163 SSA unimplemented: unhandled expr LROT 4.00% 1036 SSA unimplemented: unhandled expr LEN 3.56% 923 SSA unimplemented: unhandled stmt CALLFUNC 2.37% 615 SSA unimplemented: zero for type []byte not implemented 1.90% 492 SSA unimplemented: unhandled stmt CALLMETH 1.74% 450 SSA unimplemented: unhandled expr CALLINTER 1.74% 450 SSA unimplemented: unhandled expr DOT 1.71% 444 SSA unimplemented: unhandled expr ANDAND 1.65% 426 SSA unimplemented: unhandled expr CLOSUREVAR 1.54% 400 SSA unimplemented: unhandled expr CALLMETH 1.51% 390 SSA unimplemented: unhandled stmt SWITCH 1.47% 380 SSA unimplemented: unhandled expr CONV 1.33% 345 SSA unimplemented: addr: bad op * 1.30% 336 SSA unimplemented: unhandled OLITERAL 6 Change-Id: I4ca07951e276714dc13c31de28640aead17a1be7 Reviewed-on: https://go-review.googlesource.com/11160 Reviewed-by: Keith Randall <khr@golang.org>
2015-06-08[dev.ssa] cmd/compile/internal/ssa: autogenerate opcodesKeith Randall
Revamp autogeneration. Get rid of gogenerate commands, they are more trouble than they are worth. (If the code won't compile, gogenerate doesn't work.) Generate opcode enums & tables. This means we only have to specify opcodes in one place instead of two. Add arch prefixes to opcodes so they will be globally unique. Change-Id: I175d0a89b701b2377bbe699f3756731b7c9f5a9f Reviewed-on: https://go-review.googlesource.com/10812 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-30[dev.ssa] cmd/compile/internal/ssa: Implement block rewriting rulesKeith Randall
Change-Id: I47e5349e34fc18118c4d35bf433f875b958cc3e5 Reviewed-on: https://go-review.googlesource.com/10495 Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-28[dev.ssa] Merge remote-tracking branch 'origin/master' into mergebranchKeith Randall
Semi-regular merge of tip to dev.ssa. Complicated a bit by the move of cmd/internal/* to cmd/compile/internal/*. Change-Id: I1c66d3c29bb95cce4a53c5a3476373aa5245303d