1
0
mirror of https://github.com/golang/go synced 2024-10-05 16:41:21 -06:00
Commit Graph

635 Commits

Author SHA1 Message Date
David Chase
3a9d0ac3c8 [dev.ssa] cmd/compile: add complex arithmetic
Still to do:
details, more testing corner cases. (e.g. negative zero)
Includes small cleanups for previous CL.

Note: complex division is currently done in the runtime,
so the division code here is apparently not yet necessary
and also not tested.  Seems likely better to open code
division and expose the widening/narrowing to optimization.

Complex64 multiplication and division is done in wide
format to avoid cancellation errors; for division, this
also happens to be compatible with pre-SSA practice
(which uses a single complex128 division function).

It would-be-nice to widen for complex128 multiplication
intermediates as well, but that is trickier to implement
without a handy wider-precision format.

Change-Id: I595a4300f68868fb7641852a54674c6b2b78855e
Reviewed-on: https://go-review.googlesource.com/14028
Reviewed-by: Keith Randall <khr@golang.org>
2015-09-01 17:47:58 +00:00
Keith Randall
65677cabfd [dev.ssa] cmd/compile/internal/ssa: allow ops to have a default type
Specifying types in rewrites for all subexpressions gets verbose
quickly.  Allow opcodes to specify a default type which is used when
none is supplied explicitly.

Provide default types for a few easy opcodes.  There are probably more
we can do, but this is a good start.

Change-Id: Iedc2a1a423cc3e2d4472640433982f9aa76a9f18
Reviewed-on: https://go-review.googlesource.com/14128
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-09-01 16:40:28 +00:00
Todd Neal
a0022d9b8c [dev.ssa] cmd/compile: add more specific regalloc logging
Change-Id: Ib0ea4b9c245f3d551e0f703826caa6b444b56a2d
Reviewed-on: https://go-review.googlesource.com/14136
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-09-01 02:37:42 +00:00
Todd Neal
21e6a055c1 [dev.ssa] cmd/compile: schedule values dependent on the control later
To reduce the number of spills, give any non-phi values whose argument
is the control the same priority as the control.

With mask.bash, this reduces regenerated flags from 603 to 240.

Change-Id: I26883d69e80357c56b343428fb528102b3f26e7a
Reviewed-on: https://go-review.googlesource.com/14042
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-31 22:17:23 +00:00
Dave Cheney
8d478e845c cmd/internal/obj/arm: remove CASE and BCASE
Update #10994

CASE and BCASE were used by 5c in switch statements, cmd/compile
does not use them.

Change-Id: I7a578c461b52b94690e35460926849b28971b770
Reviewed-on: https://go-review.googlesource.com/14009
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-31 21:03:57 +00:00
Todd Neal
3b7f0c9cba [dev.ssa] cmd/compile: fix typo in log
Change-Id: Ic7be8fa3a89e46a93df181df3163ec1bf7e96a23
Reviewed-on: https://go-review.googlesource.com/14076
Reviewed-by: Minux Ma <minux@golang.org>
2015-08-31 03:07:43 +00:00
Todd Neal
cff0c6ad0f [dev.ssa] cmd/compile: add instrumentation to regalloc
Change-Id: Ice206f7e94af4a148d9dd9a7570f5ed21722bedc
Reviewed-on: https://go-review.googlesource.com/14075
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-31 02:53:07 +00:00
Todd Neal
451eca2293 [dev.ssa] cmd/compile: make test panic on failure
Change-Id: Ia5483d23fe0b5dd0b6cfe2099e9b475184742716
Reviewed-on: https://go-review.googlesource.com/14074
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-31 02:29:50 +00:00
Todd Neal
5fdd4fea90 [dev.ssa] cmd/compile: map EQ/NE intptr to OpEqPtr/OpNeqPtr
Change-Id: I8fd3727763c812297967c8069847833fc8516ff2
Reviewed-on: https://go-review.googlesource.com/14073
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-31 02:29:43 +00:00
Håvard Haugen
3c9fa388df cmd/compile/internal/gc: rename Fatal to Fatalf
This helps vet see a real issue:

    cmd/internal/gc$ go vet
    gen.go:1223: unreachable code

Fixes #12106.

Change-Id: I720868b07ae6b6d5a4dc6b238baa8c9c889da6d8
Reviewed-on: https://go-review.googlesource.com/14083
Reviewed-by: Minux Ma <minux@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-08-31 01:35:23 +00:00
Keith Randall
186cf1b9ba [dev.ssa] cmd/compile/internal/ssa: handle dead code a different way
Instead of trying to delete dead code as soon as we find it, just
mark it as dead using a PlainAndDead block kind.  The deadcode pass
will do the real removal.

This way is somewhat more efficient because we don't need to mess
with successor and predecessor lists of all the dead blocks.

Fixes #12347

Change-Id: Ia42d6b5f9cdb3215a51737b3eb117c00bd439b13
Reviewed-on: https://go-review.googlesource.com/14033
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-29 17:21:02 +00:00
Josh Bleecher Snyder
9654873a76 [dev.ssa] cmd/compile: implement PPARAMREF
This also fixes the encoding/gob TestTopLevelNilPointer failure.

Change-Id: I9b29a6fddffd51af305c685f3a8e2a0594bfeeab
Reviewed-on: https://go-review.googlesource.com/14032
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-29 16:33:14 +00:00
Todd Neal
47d6799b0f [dev.ssa] cmd/compile: move addEdge function to ssa
addEdge had two identical implementations so make it an exported method
on Block.

Change-Id: I8c21655a9dc5074fefd7f63b2f5b51897571e608
Reviewed-on: https://go-review.googlesource.com/14040
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-29 13:10:49 +00:00
Todd Neal
67e43c1e3b [dev.ssa] cmd/compile: implement OFALL
Frontend has already rewriten fallthrough statements, we just need to
ignore them.

Change-Id: Iadf89b06a9f8f9e6e2e1e87c934f31add77a19a1
Reviewed-on: https://go-review.googlesource.com/14029
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-29 02:30:17 +00:00
Robert Griesemer
3d3bc88bb5 cmd/compile/internal/gc: use slice instead of linked list for nodes to export
Change-Id: Ib79ab787fdc90a5a29b25474d91afa9bfaf51276
Reviewed-on: https://go-review.googlesource.com/13589
Reviewed-by: Minux Ma <minux@golang.org>
2015-08-28 22:49:15 +00:00
Robert Griesemer
68f4f96c1e cmd/compiler/internal/gc: fix argument for Sprintf
Val.Ctype used to be struct field, it's now a method.

Change-Id: I08f0b32b66dba15b2a392e84a557efb905b530cb
Reviewed-on: https://go-review.googlesource.com/14031
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-08-28 22:46:53 +00:00
Todd Neal
707af252d9 [dev.ssa] cmd/compile: implement len/cap(chan)
Change-Id: I1453ba226376ccd4d79780fc0686876d6dde01ee
Reviewed-on: https://go-review.googlesource.com/14027
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-28 21:55:21 +00:00
David Chase
73151067bc [dev.ssa] cmd/compile: added floating point to [u]int conversions
Change-Id: I8dee400aef07165f911750de2615b8757f826000
Reviewed-on: https://go-review.googlesource.com/13945
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-28 21:46:39 +00:00
Keith Randall
a5cffb6182 [dev.ssa] cmd/compile/internal/ssa: allocate complex zero in the entry block
Fixes build.  There may be no current block.

Change-Id: I0da8bab133dc207124556927698e7cd682e64ef5
Reviewed-on: https://go-review.googlesource.com/13989
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-28 20:53:56 +00:00
Todd Neal
67ac8a3b22 [dev.ssa] cmd/compile: fix type of nil ptr in check
Change-Id: If7a6ab6b1336dbacb006f562be7f153eb93e7253
Reviewed-on: https://go-review.googlesource.com/14025
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-28 20:48:23 +00:00
Keith Randall
f8093b8f24 [dev.ssa] cmd/compile/internal/ssa: add arg-dominating check, fix phielim
Add a check to make sure value arguments dominate the value.

Phi elim output used to fail this test.  When eliminating
redundant phis, phi elim was using one of the args and not
the ultimate source.  For example:

          b1: x = ...
          -> b2 b3

b2: y = Copy x        b3: z = Copy x
-> b4                 -> b4

          b4: w = phi y z

Phi elim eliminates w, but it used to replace w with (Copy y).
That's bad as b2 does not dominate b4.  Instead we should
replace w with (Copy x).

Fixes #12347

Change-Id: I9f340cdabcda8e2e90359fb4f9250877b1fffe98
Reviewed-on: https://go-review.googlesource.com/13986
Reviewed-by: David Chase <drchase@google.com>
2015-08-28 20:40:06 +00:00
David Chase
525785885e [dev.ssa] cmd/compile: add compose/decompose for complex, phi, constants
Still to do: arithmetic

Change-Id: I31fd23b34980c9ed4b4e304b8597134b2ba6ca5c
Reviewed-on: https://go-review.googlesource.com/14024
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-28 20:20:43 +00:00
Todd Neal
e0e4068c6e [dev.ssa] cmd/compile: implement len(map)
Implement len(map) values.

Change-Id: If92be96ec9a7a86aeb3ce566d6758aab01c2fa7d
Reviewed-on: https://go-review.googlesource.com/13961
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-28 20:12:47 +00:00
Josh Bleecher Snyder
44d87035b6 [dev.ssa] cmd/compile: make block kinds clickable in html
Change-Id: I113c07caf504cee66a81730da8830de6de098e49
Reviewed-on: https://go-review.googlesource.com/13981
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-08-27 17:30:50 +00:00
Josh Bleecher Snyder
35ad1fcb11 [dev.ssa] cmd/compile: fix OANDAND and OOROR type
The old backend doesn't like ideal types,
and we want to reuse its stackmap generation.

OOROR and OANDAND expressions have ideal type.
The old backend didn't care,
because those expressions got rewritten away into
jumps before stackmap generation.

Fix the type during conversion.

Change-Id: I488e7499298d9aec71da39c202f6a7235935bc8d
Reviewed-on: https://go-review.googlesource.com/13980
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-08-27 17:26:52 +00:00
Todd Neal
7cadf23afb [dev.ssa] cmd/compile: fix phi floats
The code previously always used AX causing errors.  For now, just
switch off the type in order to at least generate valid code.

Change-Id: Iaf13120a24b62456b9b33c04ab31f2d5104b381b
Reviewed-on: https://go-review.googlesource.com/13943
Reviewed-by: David Chase <drchase@google.com>
2015-08-26 14:40:34 +00:00
Todd Neal
752fe4dcb5 [dev.ssa] cmd/compile: support float zeroing
Change-Id: Iacd302350cf0a8a8164d937e5c4ac55e6a07d380
Reviewed-on: https://go-review.googlesource.com/13942
Reviewed-by: David Chase <drchase@google.com>
2015-08-26 02:19:02 +00:00
Michael Hudson-Doyle
af78482d6b cmd/compile, cmd/link, reflect, runtime: remove type.zero field
No longer used after previous hashmap change.

Change-Id: I558470f872281e84a78406132df4e391d077b833
Reviewed-on: https://go-review.googlesource.com/13785
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-08-26 00:28:17 +00:00
Michael Hudson-Doyle
38519e69d0 cmd/compile, runtime: stop returning t.zero on hashmap miss
Previously t.zero always pointed to runtime.zerovalue. Change the hashmap code
to always return a runtime pointer directly, and change that pointer to point
to a larger buffer if one is needed.

(It might be better to only copy from the pointer returned by the mapaccess
functions when the value type is small enough and have the compiler insert
explicit zeroing for larger value types, but I tried and failed to do this).

This removes all uses of the zero field of the type data; the field itself can
be removed in a separate change.

Fixes #11491

Change-Id: I5b81752ff4067d74a5a281c41e88f151bae0171e
Reviewed-on: https://go-review.googlesource.com/13784
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-26 00:03:21 +00:00
Keith Randall
ee50cb2061 [dev.ssa] Merge remote-tracking branch 'origin/master' into mergebranch
Semi-regular merge of master into dev.ssa.

Change-Id: Ia7f2e29dfdea7618141efcfcf6f6c7c8b5553dfa
2015-08-25 14:46:34 -07:00
Keith Randall
a2f8b0d0e4 [dev.ssa] cmd/compile/internal/ssa: add more critical edges
Add blocks to remove critical edges, even when it looks like
there's no phi that requires it.  Regalloc still likes to have
critical-edge-free graphs for other reasons.

Change-Id: I69f8eaecbc5d79ab9f2a257c2e289d60b18e43c8
Reviewed-on: https://go-review.googlesource.com/13933
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-25 21:20:18 +00:00
Ulrich Kunitz
6ec1809b83 cmd/compile: fix register allocation for == operator
The issue 12226 has been caused by the allocation of the same register
for the equality check of two byte values. The code in cgen.go freed the
register for the second operand before the allocation of the register
for the first operand.

Fixes #12226

Change-Id: Ie4dc33a488bd48a17f8ae9b497fd63c1ae390555
Reviewed-on: https://go-review.googlesource.com/13771
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-25 18:10:14 +00:00
Keith Randall
ec39d78ddd [dev.ssa] cmd/compile/internal/ssa: update TODO and comments
Change-Id: I3c598faff8af18530ae863b9e72f0cef379b4a1f
Reviewed-on: https://go-review.googlesource.com/13909
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-08-25 17:45:06 +00:00
Keith Randall
3526cf586b [dev.ssa] cmd/compile: implement OSLICESTR
Add a new function and generic operation to handle
bounds checking for slices. Unlike the index
bounds checking the index can be equal to the upper
bound.

Do gc-friendly slicing that generates proper code for
0-length result slices.

This is a takeover of Alexandru's original change,
(https://go-review.googlesource.com/#/c/12764/)
submittable now that the decompose phase is in.

Change-Id: I17d164cf42ed7839f84ca949c6ad3289269c9160
Reviewed-on: https://go-review.googlesource.com/13903
Reviewed-by: David Chase <drchase@google.com>
2015-08-25 17:14:57 +00:00
David Chase
8e601b23cd [dev.ssa] cmd/compile: add FP comparison ops
Basic ops, no particular optimization in the pattern
matching yet (e.g. x!=x for Nan detection, x cmp constant,
etc.)

Change-Id: I0043564081d6dc0eede876c4a9eb3c33cbd1521c
Reviewed-on: https://go-review.googlesource.com/13704
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-25 15:29:22 +00:00
Austin Clements
05a3b1fce5 cmd/compile: fix uninitialized memory in compare of interface value
A comparison of the form l == r where l is an interface and r is
concrete performs a type assertion on l to convert it to r's type.
However, the compiler fails to zero the temporary where the result of
the type assertion is written, so if the type is a pointer type and a
stack scan occurs while in the type assertion, it may see an invalid
pointer on the stack.

Fix this by zeroing the temporary. This is equivalent to the fix for
type switches from c4092ac.

Fixes #12253.

Change-Id: Iaf205d456b856c056b317b4e888ce892f0c555b9
Reviewed-on: https://go-review.googlesource.com/13872
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-25 14:37:08 +00:00
David Chase
4282588694 [dev.ssa] cmd/compile: add [u]int and FP to FP conversions
Change-Id: I8c17f706a3e0f1fa2d754bfb4ccd1f7a027cb3db
Reviewed-on: https://go-review.googlesource.com/13744
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-25 14:26:14 +00:00
Keith Randall
01490eb96c [dev.ssa] cmd/compile: make sure to keep offset and sym of MOV opcodes.
MOVXload and MOVXstore opcodes have both an auxint offset
and an aux offset (a symbol name, like a local or arg or global).
Make sure we keep those values during rewrites.

Change-Id: Ic9fd61bf295b5d1457784c281079a4fb38f7ad3b
Reviewed-on: https://go-review.googlesource.com/13849
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-25 04:33:49 +00:00
Josh Bleecher Snyder
5844603f14 [dev.ssa] cmd/compile: streamline unimplemented strings
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-24 22:13:53 +00:00
Josh Bleecher Snyder
9f8f8c27dc [dev.ssa] cmd/compile: support spilling and loading flags
This CL takes a simple approach to spilling and loading flags.
We never spill. When a load is needed, we recalculate,
loading the arguments as needed.

This is simple and architecture-independent.
It is not very efficient, but as of this CL,
there are fewer than 200 flag spills during make.bash.

This was tested by manually reverting CLs 13813 and 13843,
causing SETcc, MOV, and LEA instructions to clobber flags,
which dramatically increases the number of flags spills.
With that done, all stdlib tests that used to pass
still pass.

For future reference, here are some other, more efficient
amd64-only schemes that we could adapt in the future if needed.

(1) Spill exactly the flags needed.

For example, if we know that the flags will be needed
by a SETcc or Jcc op later, we could use SETcc to
extract just the relevant flag. When needed,
we could use TESTB and change the op to JNE/SETNE.
(Alternatively, we could leave the op unaltered
and prepare an appropriate CMPB instruction
to produce the desired flag.)

However, this requires separate handling for every
instruction that uses the flags register,
including (say) SBBQcarrymask.

We could enable this on an ad hoc basis for common cases
and fall back to recalculation for other cases.

(2) Spill all flags with PUSHF and POPF

This modifies SP, which the runtime won't like.
It also requires coordination with stackalloc to
make sure that we have a stack slot ready for use.

(3) Spill almost all flags with LAHF, SETO, and SAHF

See http://blog.freearrow.com/archives/396
for details. This would handle all the flags we currently
use. However, LAHF and SAHF are not universally available
and it requires arranging for AX to be free.

Change-Id: Ie36600fd8e807ef2bee83e2e2ae3685112a7f276
Reviewed-on: https://go-review.googlesource.com/13844
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-24 22:13:42 +00:00
Josh Bleecher Snyder
f3171994e9 [dev.ssa] cmd/compile: mark LEA and MOV instructions as not clobbering flags
This further reduces the number of flags spills
during make.bash by about 50%.

Note that GetG is implemented by one or two MOVs,
which is why it does not clobber flags.

Change-Id: I6fede8c027b7dc340e00d1e15df1b87bf2b2d9ec
Reviewed-on: https://go-review.googlesource.com/13843
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-24 22:10:55 +00:00
Josh Bleecher Snyder
220e705404 [dev.ssa] cmd/compile: make "*Value".String more robust
Change-Id: I4ae38440a33574421c9e3e350701e86e8a224b92
Reviewed-on: https://go-review.googlesource.com/13842
Reviewed-by: Todd Neal <todd@tneal.org>
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-24 22:10:36 +00:00
Brad Fitzpatrick
b3a508c03e cmd/compile: in usage messages, name the binary "compile" instead of "Xg"
Fixes #12227

Change-Id: I7c1b93e50736185a641fb637000aae2f15bc04ed
Reviewed-on: https://go-review.googlesource.com/13820
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-22 15:39:13 +00:00
Todd Neal
0ffd9c8cad [dev.ssa] cmd/compile/internal: mark len(map), len/cap(chan) unimplemented
Mark these as unimplemented so we don't generate bad code.

Change-Id: I101190c40a753faaa82193ac37e2978b20a96e4e
Reviewed-on: https://go-review.googlesource.com/13748
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-22 13:15:27 +00:00
Brad Fitzpatrick
2468227038 cmd/compile/internal, cmd/internal/obj: used keyed ProgInfo literals
Safer, more readable, shorter.

Change-Id: I5cf1f438e20a3df45fc43cc5c870a533f7c524bf
Reviewed-on: https://go-review.googlesource.com/10517
Reviewed-by: Minux Ma <minux@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-21 22:32:43 +00:00
Alberto Donizetti
85de30e72f cmd/compile: allow huge rsh in constants arithmetic
Currently an expression like

var v = 0 >> 1000

is rejected by gc with a "stupid shift" error, while gotype
compiles it successfully.

As suggested by gri on the issue tracker, allow an rsh right
operand to be any valid uint value.

Fixes #11328

Change-Id: I6ccb3b7f842338d91fd26ae37dd4fa279d7fc440
Reviewed-on: https://go-review.googlesource.com/13777
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-08-21 20:27:22 +00:00
Todd Neal
57d9e7e3c4 [dev.ssa] cmd/compile/internal/ssa: implement OMOD
Change-Id: Iec954c4daefef4ab3fa2c98bfb2c70b2dea8dffb
Reviewed-on: https://go-review.googlesource.com/13743
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-21 20:20:26 +00:00
Robert Griesemer
548041ed08 cmd/compile/internal/big: update vendored math/big
This updates the big package used by the compiler to match the
public big package which contains some updates and bug fixes.
Obtained by running vendor.bash in the internal/big directory.
No manual changes.

Change-Id: I299aecc6599d4a745a721ce48def32449640dbb2
Reviewed-on: https://go-review.googlesource.com/13815
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-08-21 20:03:16 +00:00
Josh Bleecher Snyder
7393c24877 [dev.ssa] cmd/compile: everything is live and reachable after regalloc
This CL makes function printing and HTML generation
accurate after regalloc.

Prior to this CL, text and HTML function outputs
showed live values and blocks as dead.

Change-Id: I70669cd8641af841447fc5d2ecbd754b281356f0
Reviewed-on: https://go-review.googlesource.com/13812
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-21 20:00:51 +00:00
Josh Bleecher Snyder
8f51ae8ba5 [dev.ssa] cmd/compile: SETcc instructions do not clobber flags
This reduces the number of flags spilled during
make.bash by > 90%.

I am working (slowly) on the rest.

Change-Id: I3c08ae228c33e2f726f615962996f0350c8d592b
Reviewed-on: https://go-review.googlesource.com/13813
Reviewed-by: David Chase <drchase@google.com>
2015-08-21 17:49:15 +00:00
Keith Randall
9f954db170 [dev.ssa] cmd/compile: add decompose pass
Decompose breaks compound objects up into pieces that can be
operated on by the target architecture.  The decompose pass only
does phi ops, the rest is done by the rewrite rules in generic.rules.

Compound objects include strings,slices,interfaces,structs,arrays.

Arrays aren't decomposed because of indexing (we could support
constant indexes, but dynamic indexes can't be handled using SSA).
Structs will come in a subsequent CL.

TODO: after this pass we have lost the association between, e.g.,
a string's pointer and its size.  It would be nice if we could keep
that information around for debugging info somehow.

Change-Id: I6379ab962a7beef62297d0f68c421f22aa0a0901
Reviewed-on: https://go-review.googlesource.com/13683
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-20 21:09:24 +00:00
Keith Randall
8d23681cc8 [dev.ssa] cmd/compile: implement more panic stuff
Implement index check panics (and slice check panics, for when
we need those).

Clean up nil check.  Now that the new regalloc is in we can use
the register we just tested as the address 0 destination.

Remove jumps after panic calls, they are unreachable.

Change-Id: Ifee6e510cdea49cc7c7056887e4f06c67488d491
Reviewed-on: https://go-review.googlesource.com/13687
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-19 23:17:48 +00:00
Keith Randall
46e62f873a [dev.ssa] cmd/compile: used Bounded field to fix empty range loops
for i, v := range a {
    }

Walk converts this to a regular for loop, like this:

    for i := 0, p := &a[0]; i < len(a); i++, p++ {
        v := *p
    }

Unfortunately, &a[0] fails its bounds check when a is
the empty slice (or string).  The old compiler gets around this
by marking &a[0] as Bounded, meaning "don't emit bounds checks
for this index op".  This change makes SSA honor that same mark.

The SSA compiler hasn't implemented bounds check panics yet,
so the failed bounds check just causes the current routine
to return immediately.

Fixes bytes package tests.

Change-Id: Ibe838853ef4046c92f76adbded8cca3b1e449e0b
Reviewed-on: https://go-review.googlesource.com/13685
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-19 21:44:44 +00:00
Todd Neal
67cbd5b51d [dev.ssa] cmd/compile/internal/ssa: implement OHMUL
Adds support for high multiply which is used by the frontend when
rewriting const division.  The frontend currently only does this for 8,
16, and 32 bit integer arithmetic.

Change-Id: I9b6c6018f3be827a50ee6c185454ebc79b3094c8
Reviewed-on: https://go-review.googlesource.com/13696
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-19 02:52:50 +00:00
Todd Neal
a45f2d8f28 [dev.ssa] cmd/compile/internal/ssa: implement ODIV
Implement integer division for non-consts.

Change-Id: If40cbde20e5f0ebb9993064def7be468e4eca076
Reviewed-on: https://go-review.googlesource.com/13644
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-18 22:15:53 +00:00
Keith Randall
d9dc2f2230 [dev.ssa] cmd/compile: fix string store rewrite
Store ops now need their size in the auxint field.  I missed this one.

Change-Id: I050fd6b5b00579883731702c426edafa3a5f7561
Reviewed-on: https://go-review.googlesource.com/13682
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-18 17:41:44 +00:00
Russ Cox
f68d1df6b9 cmd/compile: fix interaction between GOEXPERIMENT=fieldtrack and race detector
Tested by hand.
Only lines of code changing are protected by Fieldtrack_enabled > 0,
which is never true in standard Go distributions.

Fixes #12171.

Change-Id: I963b9997dac10829db8ad4bfc97a7d6bf14b55c6
Reviewed-on: https://go-review.googlesource.com/13676
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-08-18 14:36:01 +00:00
Keith Randall
0b46b42943 [dev.ssa] cmd/compile/internal/ssa: New register allocator
Implement a global (whole function) register allocator.
This replaces the local (per basic block) register allocator.

Clobbering of registers by instructions is handled properly.
A separate change will add the correct clobbers to all the instructions.

Change-Id: I38ce4dc7dccb8303c1c0e0295fe70247b0a3f2ea
Reviewed-on: https://go-review.googlesource.com/13622
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Todd Neal <todd@tneal.org>
2015-08-17 21:06:30 +00:00
Josh Bleecher Snyder
759b9c3b80 [dev.ssa] cmd/compile: add likely annotations to blocks in html
This was missing from CL 13472
due to a badly synced client.

Change-Id: If59fc669125dd1caa335dacfbf0f8dbd7b074312
Reviewed-on: https://go-review.googlesource.com/13639
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-17 18:56:33 +00:00
David Chase
997a9f32b0 [dev.ssa] cmd/compile: first unoptimized cut at adding FP support
Added F32 and F64 load, store, and addition.
Added F32 and F64 multiply.
Added F32 and F64 subtraction and division.
Added X15 to "clobber" for FP sub/div
Added FP constants
Added separate FP test in gc/testdata

Change-Id: Ifa60dbad948a40011b478d9605862c4b0cc9134c
Reviewed-on: https://go-review.googlesource.com/13612
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-17 17:38:28 +00:00
Dave Cheney
467a2cb73c cmd/compile/internal/arm64: remove Reginuse check in clearfat
Fixes golang/go#12133

CL 13630 fixed the use of a stale reg[] array in the various arch
backends which was causing the check in clearfat to pass
unconditionally on arm64.

With this check fixed, arm64 now considers REGRT1 to always be in use
as it is part of the reserved register set, see arm64/gsubr.go.

However, ppc64 does not consider REGRT1 and REGRT2 to be part of its
reserved set, so its identical clearfat check passes.

This CL removes the Reginuse check inside clearfat as REGRT1 is
guarenteed always be free on arm64.

Change-Id: I4719150d3c3378fae155b863c474529df18d4c17
Reviewed-on: https://go-review.googlesource.com/13650
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-16 00:29:39 +00:00
Keith Randall
d4cc51d411 [dev.ssa] cmd/compile/internal/ssa: Use explicit size for store ops
Using the type of the store argument is not safe, it may change
during rewriting, giving us the wrong store width.

(Store ptr (Trunc32to16 val) mem)

This should be a 2-byte store.  But we have the rule:

(Trunc32to16 x) -> x

So if the Trunc rewrite happens before the Store -> MOVW rewrite,
then the Store thinks that the value it is storing is 4 bytes
in size and uses a MOVL.  Bad things ensue.

Fix this by encoding the store width explicitly in the auxint field.

In general, we can't rely on the type of arguments, as they may
change during rewrites.  The type of the op itself (as used by
the Load rules) is still ok to use.

Change-Id: I9e2359e4f657bb0ea0e40038969628bf0f84e584
Reviewed-on: https://go-review.googlesource.com/13636
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-15 23:18:21 +00:00
Keith Randall
e97ab0a0ac cmd/compile: remove stale register use array
The reg[] array in .../gc is where truth lies.  The copy in .../ARCH
is incorrect as it is mostly not updated to reflect regalloc decisions.

This bug was introduced in the rewrite
https://go-review.googlesource.com/#/c/7853/.  The new reg[] array was
introduced in .../gc but not all of the uses were removed in the
.../ARCH directories.

Fixes #12133

Change-Id: I6364fc403cdab92d802d17f2913ba1607734037c
Reviewed-on: https://go-review.googlesource.com/13630
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-15 17:37:14 +00:00
Alexandru Moșoi
198fc9a9eb [dev.ssa] cmd/compile/internal/ssa/gen: more simplifications and foldings.
Change-Id: I74d1267dbfced2663072b4f091732c0fb328690f
Reviewed-on: https://go-review.googlesource.com/13641
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-14 23:14:36 +00:00
Alexandru Moșoi
7a6de6d5f2 [dev.ssa] cmd/compile/internal/ssa/gen: fold Mul8 properly.
Mul8 is lowered to MULW, but the rules for constant
folding do not handle the fact that the operands
are int8.

Change-Id: I2c336686d86249393a8079a471c6ff74e6228f3d
Reviewed-on: https://go-review.googlesource.com/13642
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-14 20:47:21 +00:00
Alexandru Moșoi
c55870a541 [dev.ssa] cmd/compile/internal/gc: handle all inputs for shifts.
Disable CX as output for shift operations.

Change-Id: I85e6b22d09009b38847082dc375b6108c2dee80a
Reviewed-on: https://go-review.googlesource.com/13370
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-13 21:58:12 +00:00
Josh Bleecher Snyder
35fb514596 [dev.ssa] cmd/compile: add HTML SSA printer
This is an initial implementation.
There are many rough edges and TODOs,
which will hopefully be polished out
with use.

Fixes #12071.

Change-Id: I1d6fd5a343063b5200623bceef2c2cfcc885794e
Reviewed-on: https://go-review.googlesource.com/13472
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-13 21:56:06 +00:00
Josh Bleecher Snyder
3e7904b648 [dev.ssa] cmd/compile: improve inBounds rewrite rules
Change-Id: Ia238187a89f820cd1620ab5acdbf1c8f003569b1
Reviewed-on: https://go-review.googlesource.com/13587
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-13 21:50:20 +00:00
Keith Randall
bc1f5768ce [dev.ssa] cmd/compile: add register spec to getg
This omission was causing the new regalloc to fail.

Change-Id: If7ba7be38a436dbd0dd443828ddd7ebf6e35be0e
Reviewed-on: https://go-review.googlesource.com/13632
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-13 20:51:56 +00:00
Keith Randall
3b705824ce [dev.ssa] cmd/compile: fix constant subtraction rules
(SUBQconst [x] y) computes y-x, not x-y.

Fixes #12137

Change-Id: Idbd0554eee051102f562240d1756647843666ee6
Reviewed-on: https://go-review.googlesource.com/13631
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-13 19:57:30 +00:00
Josh Bleecher Snyder
f85faefa67 [dev.ssa] cmd/compile: move rewrite logging behind codegen flag
Generating logging code every time causes large
diffs for small changes.

Since the intent is to use this for debugging only,
generate logging code only when requested.
Committed generated code will be logging free.

Change-Id: I9ef9e29c88b76c2557bad4c6b424b9db1255ec8b
Reviewed-on: https://go-review.googlesource.com/13623
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-13 00:10:13 +00:00
Keith Randall
867662da6a [dev.ssa] cmd/compile: make sure entry block has no predecessors
Fix one test that build a violating CFG.

Change-Id: Ie0296ced602984d914a70461c76559c507ce2510
Reviewed-on: https://go-review.googlesource.com/13621
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-12 22:27:15 +00:00
Josh Bleecher Snyder
514ab7c385 [dev.ssa] cmd/compile: log line numbers in generated rewrite rules
This makes it easier to investigate and
understand rewrite behavior.

Change-Id: I790e8964922caf98362ce8a6d6972f52d83eefa8
Reviewed-on: https://go-review.googlesource.com/13588
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-12 22:10:28 +00:00
Josh Bleecher Snyder
3d23afb913 [dev.ssa] cmd/compile: implement OGETG
Change-Id: I7ecf62cf399c710b4a617803c43e83fce09b8a7d
Reviewed-on: https://go-review.googlesource.com/13585
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-12 22:05:42 +00:00
Josh Bleecher Snyder
bbf8c5ce2f [dev.ssa] cmd/compile: initial implementation of likely direction
Change-Id: Id8457b18c07bf717d13c9423d8f314f253eee64f
Reviewed-on: https://go-review.googlesource.com/13580
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-12 22:03:08 +00:00
Josh Bleecher Snyder
212a1763fc [dev.ssa] cmd/compile: update opnames
This claims to be autogenerated from go tool dist,
but I don't see where.

In any case, the update is trivial.

Change-Id: I58daaba755f3d34a0396005046b89411a02ada7e
Reviewed-on: https://go-review.googlesource.com/13584
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-12 20:57:12 +00:00
Josh Bleecher Snyder
a2d1580fdb [dev.ssa] cmd/compile: implement OSPTR
Change-Id: Iaa40f14a1e3e4393af3c446953ffc315e79a3762
Reviewed-on: https://go-review.googlesource.com/13581
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-12 20:56:48 +00:00
Keith Randall
d56d2fa206 [dev.ssa] cmd/compile: fix function call memory
We need to move the memory variable update back to before endBlock
so that all successors use the right memory value.

See https://go-review.googlesource.com/13560

Change-Id: Id72e5526c56e5e070b933d3b28dc503a5a2978dc
Reviewed-on: https://go-review.googlesource.com/13586
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-12 20:35:53 +00:00
Dave Cheney
cda1fc0071 cmd/compile/internal/ppc64: disable DUFFZERO
Update #12108

If DUFFZERO is used within a tail call method it will overwrite the
link register.

Change-Id: I6abd2fde0f0ad909ccd55eb119b992673a74f0e2
Reviewed-on: https://go-review.googlesource.com/13570
Reviewed-by: Russ Cox <rsc@golang.org>
2015-08-12 20:31:26 +00:00
Todd Neal
ce97788914 [dev.ssa] cmd/compile/ssa: fix test for dse
Fix the test broken with dee1f2 by implementing Elem()

Change-Id: I7a4a487885267c24fdc52d79fb7d450231328812
Reviewed-on: https://go-review.googlesource.com/13551
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-12 00:48:39 +00:00
Todd Neal
dee1f2750b [dev.ssa] cmd/compile/ssa: eliminate Zero with dse
Consider OpZero to be a store so it can be eliminated by dse.

Change-Id: Idebb6a190657b76966f0c5b20f2ec9f52fe47499
Reviewed-on: https://go-review.googlesource.com/13447
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-11 23:50:56 +00:00
Josh Bleecher Snyder
463858e6ff [dev.ssa] cmd/compile: make failed nil checks panic
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-11 21:52:48 +00:00
Josh Bleecher Snyder
2af0648014 [dev.ssa] cmd/compile: fix function call memory accounting
We were not recording function calls as
changing the state of memory.

As a result, the scheduler was not aware that
storing values to the stack in order to make a
function call must happen *after* retrieving
results from the stack from a just-completed
function call.

This fixes the container/ring tests.

This was my first experience debugging an issue
using the HTML output. I'm feeling quite
pleased with it.

Change-Id: I9e8276846be9fd7a60422911b11816c5175e3d0a
Reviewed-on: https://go-review.googlesource.com/13560
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-11 21:51:16 +00:00
David Chase
40aba8c4e7 [dev.ssa] cmd/compile: add support for LROT, and tests
Hardcoded the limit on constants only allowed.

Change-Id: Idb9b07b4871db7a752a79e492671e9b41207b956
Reviewed-on: https://go-review.googlesource.com/13257
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-11 19:01:49 +00:00
Todd Neal
e0e556620a [dev.ssa] cmd/compile/ssa: don't nil check phis with non-nil arguments
Move the known-non-nil scan outside the work loop to resolve an issue
with values that were declared outside the block being operated on.
Also consider phis whose arguments are all non-nil, as non-nil.

Change-Id: I4d5b840042de9eb181f2cb918f36913fb5d517a2
Reviewed-on: https://go-review.googlesource.com/13441
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-11 00:00:55 +00:00
Keith Randall
9787ba43ee [dev.ssa] cmd/compile/internal/ssa: Update TODO list
Change-Id: Ibcd4c6984c8728fd9ab76e0c7df555984deaf281
Reviewed-on: https://go-review.googlesource.com/13471
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-10 21:54:42 +00:00
Josh Bleecher Snyder
baf2c3ec4a [dev.ssa] cmd/compile: detect rewrite loops of length > 1
Use a version of Floyd's cycle finding algorithm,
but advance by 1 and 1/2 steps per cycle rather
than by 1 and 2. It is simpler and should be cheaper
in the normal, acyclic case.

This should fix the 386 and arm builds,
which are currently hung.

Change-Id: If8bd443011b28a5ecb004a549239991d3dfc862b
Reviewed-on: https://go-review.googlesource.com/13473
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-10 21:14:17 +00:00
Keith Randall
e98edc88c9 [dev.ssa] cmd/compile/internal/ssa: enforce load-store ordering in scheduler
We must make sure that all loads that use a store are scheduled
before the next store.  Add additional dependency edges to the
value graph to enforce this constraint.

Change-Id: Iab83644f68bc4c30637085b82ca7467b9d5513a5
Reviewed-on: https://go-review.googlesource.com/13470
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-10 20:39:15 +00:00
Josh Bleecher Snyder
0d91018082 [dev.ssa] cmd/compile: add simplifying block rewrite rules
Change-Id: Ia946c259628f84dc7031171456563975d2ad5ea9
Reviewed-on: https://go-review.googlesource.com/13381
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-07 22:03:11 +00:00
Todd Neal
b14b8d6bc7 [dev.ssa] cmd/compile/ssa: don't perform nilcheck on OpAddr/OpAddPtr values
Don't nilcheck values that were constructed as a result of OpAddr or
OpAddPtr.

Change-Id: I38053e905d1b76a2a64e77f84e444d38a5217108
Reviewed-on: https://go-review.googlesource.com/13256
Reviewed-by: David Chase <drchase@google.com>
2015-08-06 23:11:34 +00:00
Josh Bleecher Snyder
0fb818a424 [dev.ssa] cmd/compile: copy values during rewrites
Rather than require an explicit Copy on the RHS of rewrite rules,
use rulegen magic to add it.

The advantages to handling this in rulegen are:

* simpler rules
* harder to accidentally miss a Copy

Change-Id: I46853bade83bdf517eee9495bf5a553175277b53
Reviewed-on: https://go-review.googlesource.com/13242
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 23:02:46 +00:00
Alexandru Moșoi
d2150c8328 [dev.ssa] cmd/compile/internal/ssa/gen: generate better code when right-shifting with a constant.
The lowering rules were missing the non-64 bit case.

SBBLcarrymask can be folded to a int32 integer whose
type has a smaller bit size. Without the new AND rules
the following would be generated:

    v19 = MOVLconst <uint8> [-1] : SI
    v20 = ANDB <uint8> v18 v19 : DI

which is obviously a NOP.

Fixes #12022

Change-Id: I5f4209f78edc0f118e5b9b2908739f09cefebca4
Reviewed-on: https://go-review.googlesource.com/13301
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 19:22:27 +00:00
Josh Bleecher Snyder
ca088cf4e5 [dev.ssa] cmd/compile: handle phi control values
Tests courtesy of Todd Neal.

Change-Id: If657c7c7d3cd1ce01e9d9ad79eb6b2110230c0f9
Reviewed-on: https://go-review.googlesource.com/13267
Reviewed-by: Todd Neal <todd@tneal.org>
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:44:25 +00:00
Keith Randall
cfd8dfaa10 [dev.ssa] cmd/compile/internal/ssa: more checks on ssa structure
Make sure all referenced Blocks and Values are really there.
Fix deadcode to generate SSA graphs that pass this new test.

Change-Id: Ib002ce20e33490eb8c919bd189d209f769d61517
Reviewed-on: https://go-review.googlesource.com/13147
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-06 17:33:19 +00:00
Josh Bleecher Snyder
ddeee0eed3 [dev.ssa] cmd/compile: enforce that all phis are first during regalloc
Change-Id: I035708f5d0659b3deef00808d35e1cc8a80215e0
Reviewed-on: https://go-review.googlesource.com/13243
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:26:43 +00:00
Josh Bleecher Snyder
f1401f1a10 [dev.ssa] cmd/compile: schedule phi control values first
Change-Id: I684440dc316625d5572cc12179adbc206e306429
Reviewed-on: https://go-review.googlesource.com/13263
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:26:34 +00:00
Josh Bleecher Snyder
cd0cb0a9d6 [dev.ssa] cmd/compile: tidy up register setup
No functional changes.
The intent is just to make this
easier to read and maintain.

Change-Id: Iec207546482cd62bcb22eaae8efe5be6c4f15378
Reviewed-on: https://go-review.googlesource.com/13284
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:25:19 +00:00
Josh Bleecher Snyder
5584523224 [dev.ssa] cmd/compile: improve error message for phi location mismatch
Change-Id: I402841743fcdc287631646039eb149f5cfdf886c
Reviewed-on: https://go-review.googlesource.com/13269
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:21:25 +00:00
Josh Bleecher Snyder
6548b63d6b [dev.ssa] cmd/compile: don't move OpSP and OpSB values
regalloc expects to find all OpSP and OpSB values
in the entry block.

There is no value to moving them; don't.

Change-Id: I775198f03ce7420348721ffc5e7d2bab065465b1
Reviewed-on: https://go-review.googlesource.com/13266
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:20:43 +00:00
Josh Bleecher Snyder
e13954981e [dev.ssa] cmd/compile: provide better errors for regnum and localOffset failures
Change-Id: I2667b0923e17df7cbf08e34ebec1b69a0f2f02b2
Reviewed-on: https://go-review.googlesource.com/13265
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:11:29 +00:00
Josh Bleecher Snyder
e5fe33e546 [dev.ssa] cmd/compile: respect phi values in tighten
Given (say)

b1: <- b2 b3
  v1 = Phi <t> v2 v3
b2:
  v2 = ...
b3:
  ...

tighten will move v2 to b1, since it is only used in b1.

This is wrong; v2 needs to be evaluated before entering b1.
Fix it.

Change-Id: I2cc3b30e3ffd221cf594e36cec534dfd9cf3c6a7
Reviewed-on: https://go-review.googlesource.com/13264
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-06 17:07:14 +00:00
Josh Bleecher Snyder
f91ff1a509 [dev.ssa] cmd/compile: add SSA pass to move values closer to uses
Even this very simple, restricted initial implementation helps.

While running make.bash, it moves 84437 values
to new, closer homes.

As a concrete example:

func f_ssa(i, j int, b bool) int {
	if !b {
		return 0
	}
	return i + j
}

It cuts off one stack slot and two instructions:

Before:

"".f_ssa t=1 size=96 value=0 args=0x20 locals=0x18
	0x0000 00000 (x.go:3)	TEXT	"".f_ssa(SB), $24-32
	0x0000 00000 (x.go:3)	SUBQ	$24, SP
	0x0004 00004 (x.go:3)	FUNCDATA	$0, "".gcargs·0(SB)
	0x0004 00004 (x.go:3)	FUNCDATA	$1, "".gclocals·1(SB)
	0x0004 00004 (x.go:5)	MOVQ	$0, AX
	0x0006 00006 (x.go:3)	MOVQ	32(SP), CX
	0x000b 00011 (x.go:3)	MOVQ	40(SP), DX
	0x0010 00016 (x.go:3)	LEAQ	48(SP), BX
	0x0015 00021 (x.go:3)	MOVB	(BX), BPB
	0x0018 00024 (x.go:3)	MOVQ	$0, SI
	0x001a 00026 (x.go:3)	MOVQ	SI, 56(SP)
	0x001f 00031 (x.go:3)	TESTB	BPB, BPB
	0x0022 00034 (x.go:5)	MOVQ	AX, (SP)
	0x0026 00038 (x.go:3)	MOVQ	CX, 8(SP)
	0x002b 00043 (x.go:3)	MOVQ	DX, 16(SP)
	0x0030 00048 (x.go:4)	JEQ	74
	0x0032 00050 (x.go:3)	MOVQ	8(SP), AX
	0x0037 00055 (x.go:3)	MOVQ	16(SP), CX
	0x003c 00060 (x.go:7)	LEAQ	(AX)(CX*1), DX
	0x0040 00064 (x.go:7)	MOVQ	DX, 56(SP)
	0x0045 00069 (x.go:3)	ADDQ	$24, SP
	0x0049 00073 (x.go:3)	RET
	0x004a 00074 (x.go:5)	MOVQ	(SP), AX
	0x004e 00078 (x.go:5)	MOVQ	AX, 56(SP)
	0x0053 00083 (x.go:3)	JMP	69

After:

"".f_ssa t=1 size=80 value=0 args=0x20 locals=0x10
	0x0000 00000 (x.go:3)	TEXT	"".f_ssa(SB), $16-32
	0x0000 00000 (x.go:3)	SUBQ	$16, SP
	0x0004 00004 (x.go:3)	FUNCDATA	$0, "".gcargs·0(SB)
	0x0004 00004 (x.go:3)	FUNCDATA	$1, "".gclocals·1(SB)
	0x0004 00004 (x.go:3)	MOVQ	32(SP), AX
	0x0009 00009 (x.go:3)	MOVQ	24(SP), CX
	0x000e 00014 (x.go:3)	LEAQ	40(SP), DX
	0x0013 00019 (x.go:3)	MOVB	(DX), BL
	0x0015 00021 (x.go:3)	MOVQ	$0, BP
	0x0017 00023 (x.go:3)	MOVQ	BP, 48(SP)
	0x001c 00028 (x.go:3)	TESTB	BL, BL
	0x001e 00030 (x.go:3)	MOVQ	AX, (SP)
	0x0022 00034 (x.go:3)	MOVQ	CX, 8(SP)
	0x0027 00039 (x.go:4)	JEQ	64
	0x0029 00041 (x.go:3)	MOVQ	8(SP), AX
	0x002e 00046 (x.go:3)	MOVQ	(SP), CX
	0x0032 00050 (x.go:7)	LEAQ	(AX)(CX*1), DX
	0x0036 00054 (x.go:7)	MOVQ	DX, 48(SP)
	0x003b 00059 (x.go:3)	ADDQ	$16, SP
	0x003f 00063 (x.go:3)	RET
	0x0040 00064 (x.go:5)	MOVQ	$0, AX
	0x0042 00066 (x.go:5)	MOVQ	AX, 48(SP)
	0x0047 00071 (x.go:3)	JMP	59

Of course, the old backend is still well ahead:

"".f_ssa t=1 size=48 value=0 args=0x20 locals=0x0
	0x0000 00000 (x.go:3)	TEXT	"".f_ssa(SB), $0-32
	0x0000 00000 (x.go:3)	NOP
	0x0000 00000 (x.go:3)	NOP
	0x0000 00000 (x.go:3)	FUNCDATA	$0, gclocals·a8eabfc4a4514ed6b3b0c61e9680e440(SB)
	0x0000 00000 (x.go:3)	FUNCDATA	$1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
	0x0000 00000 (x.go:4)	CMPB	"".b+24(FP), $0
	0x0005 00005 (x.go:4)	JNE	17
	0x0007 00007 (x.go:5)	MOVQ	$0, "".~r3+32(FP)
	0x0010 00016 (x.go:5)	RET
	0x0011 00017 (x.go:7)	MOVQ	"".i+8(FP), BX
	0x0016 00022 (x.go:7)	MOVQ	"".j+16(FP), BP
	0x001b 00027 (x.go:7)	ADDQ	BP, BX
	0x001e 00030 (x.go:7)	MOVQ	BX, "".~r3+32(FP)
	0x0023 00035 (x.go:7)	RET

Some regalloc improvements should help considerably.

Change-Id: I95bb5dd83e56afd70ae4e983f1d32dffd0c3d46a
Reviewed-on: https://go-review.googlesource.com/13142
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-05 02:37:24 +00:00
Keith Randall
d1c15a0e3e [dev.ssa] cmd/compile/internal/ssa: implement ITAB
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-08-04 23:32:42 +00:00
Josh Bleecher Snyder
9495e45c80 [dev.ssa] cmd/compile: make GOSSAFUNC trigger logging
I find myself always adding this in temporarily.
Make it permanent.

Change-Id: I1646b3930a07d0ea01840736ccd449b7fd24f06e
Reviewed-on: https://go-review.googlesource.com/13141
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-04 22:53:11 +00:00
Josh Bleecher Snyder
573c791e81 [dev.ssa] cmd/compile: treat control ops as live at end of block
Failure to treat control ops as live can lead
to them being eliminated when they live in
other blocks.

Change-Id: I604a1977a3d3884b1f4516bea4e15885ce38272d
Reviewed-on: https://go-review.googlesource.com/13138
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-04 22:48:34 +00:00
Josh Bleecher Snyder
54dca047dd [dev.ssa] cmd/compile: always print block control values
They were being omitted after scheduling.

Change-Id: Ia20e2dcb61fde9ec854918b958c3897bafd282a6
Reviewed-on: https://go-review.googlesource.com/13140
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-04 22:05:56 +00:00
Keith Randall
683f5d7bdb [dev.ssa] cmd/compile/internal/ssa: put new values for block rewrites in rewritten block
Don't put them in the control value's block.
That may be many blocks up the dominator tree.

Change-Id: Iab3ea36a890ffe0e355dadec7aeb676901c4f070
Reviewed-on: https://go-review.googlesource.com/13134
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-08-04 19:38:24 +00:00
Josh Bleecher Snyder
b8efee0d8a [dev.ssa] cmd/compile: log progs during ssa codegen
This is helpful when debugging generated code.

Change-Id: I268efa3593a03bb2c4e9f07d9034c004cd40df41
Reviewed-on: https://go-review.googlesource.com/13099
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-04 19:37:19 +00:00
Todd Neal
38ed6c10eb [dev.ssa] cmd/compile: simplify repeated OCOM
Rewrite ^{n}x to be ^{n % 2}x.  This will eventually resolve a fuzz
issue that breaks v1.5.

Updates #11352

Change-Id: I1b3f93872d06222f9ff5f6fd5580178ebaf4c003
Reviewed-on: https://go-review.googlesource.com/13110
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-04 02:18:56 +00:00
Todd Neal
faee392814 [dev.ssa] cmd/compile/ssa : fix typo in error message
Change-Id: Ibb5169aade15190773ff7dd11b303c1f1345a0c2
Reviewed-on: https://go-review.googlesource.com/13100
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-04 00:34:45 +00:00
Keith Randall
a678a5c7a5 [dev.ssa] cmd/compile/internal/ssa: Fix scheduler
The DFS scheduler doesn't do the right thing.  If a Value x is used by
more than one other Value, then x is put into the DFS queue when
its first user (call it y) is visited.  It is not removed and reinserted
when the second user of x (call it z) is visited, so the dependency
between x and z is not respected.  There is no easy way to fix this with
the DFS queue because we'd have to rip values out of the middle of the
DFS queue.

The new scheduler works from the end of the block backwards, scheduling
instructions which have had all of their uses already scheduled.
A simple priority scheme breaks ties between multiple instructions that
are ready to schedule simultaneously.

Keep track of whether we've scheduled or not, and make print() use
the scheduled order if we have.

Fix some shift tests that this change tickles.  Add unsigned right shift tests.

Change-Id: I44164c10bb92ae8ab8f76d7a5180cbafab826ea1
Reviewed-on: https://go-review.googlesource.com/13069
Reviewed-by: Todd Neal <todd@tneal.org>
2015-08-04 00:31:56 +00:00
Todd Neal
4dcf8ea1a4 [dev.ssa] cmd/compile/ssa: speed up nilcheck
Reworks nilcheck to be performed by a depth first traversal of the
dominator tree, keeping an updated map of the values that have been
nil-checked during the traversal.

benchmark                           old ns/op     new ns/op     delta
BenchmarkNilCheckDeep1-8            1242          1825          +46.94%
BenchmarkNilCheckDeep10-8           2397          3942          +64.46%
BenchmarkNilCheckDeep100-8          29105         24873         -14.54%
BenchmarkNilCheckDeep1000-8         2742563       265760        -90.31%
BenchmarkNilCheckDeep10000-8        335690119     3157995       -99.06%

benchmark                           old MB/s     new MB/s     speedup
BenchmarkNilCheckDeep1-8            0.81         0.55         0.68x
BenchmarkNilCheckDeep10-8           4.17         2.54         0.61x
BenchmarkNilCheckDeep100-8          3.44         4.02         1.17x
BenchmarkNilCheckDeep1000-8         0.36         3.76         10.44x
BenchmarkNilCheckDeep10000-8        0.03         3.17         105.67x

benchmark                        old allocs     new allocs     delta
BenchmarkNilCheckDeep1-8         9              14             +55.56%
BenchmarkNilCheckDeep10-8        9              23             +155.56%
BenchmarkNilCheckDeep100-8       9              113            +1155.56%
BenchmarkNilCheckDeep1000-8      9              1015
+11177.78%
BenchmarkNilCheckDeep10000-8     9              10024
+111277.78%

benchmark                        old bytes     new bytes     delta
BenchmarkNilCheckDeep1-8         432           608           +40.74%
BenchmarkNilCheckDeep10-8        1008          1496          +48.41%
BenchmarkNilCheckDeep100-8       8064          11656         +44.54%
BenchmarkNilCheckDeep1000-8      73728         145240        +96.99%
BenchmarkNilCheckDeep10000-8     737280        2144411       +190.85%

Change-Id: I0f86010e9823aec04aac744fdb589b65ec8acefc
Reviewed-on: https://go-review.googlesource.com/12332
Reviewed-by: David Chase <drchase@google.com>
2015-08-03 23:05:17 +00:00
Todd Neal
4ac823eeb8 [dev.ssa] cmd/compile/ssa: test against known values
Modify tests to use a known value instead of comparing the backends
directly.

Change-Id: I32e804e12515885bd94c4f83644cbca03b018fea
Reviewed-on: https://go-review.googlesource.com/13042
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-03 22:32:18 +00:00
Alexandru Moșoi
9b25da732b [dev.ssa] cmd/compile/internal/ssa/gen: add more simplifications rules
This is a follow up on https://go-review.googlesource.com/#/c/12420/
with some rules moved to AMD64 closer to the existing rules.

Change-Id: Id346bb0fc4459b3c49b826a59cc74308a590310e
Reviewed-on: https://go-review.googlesource.com/12906
Reviewed-by: Keith Randall <khr@golang.org>
2015-08-03 17:01:16 +00:00
Russ Cox
c5dff7282e cmd/compile, runtime: fix placement of map bucket overflow pointer on nacl
On most systems, a pointer is the worst case alignment, so adding
a pointer field at the end of a struct guarantees there will be no
padding added after that field (to satisfy overall struct alignment
due to some more-aligned field also present).

In the runtime, the map implementation needs a quick way to
get to the overflow pointer, which is last in the bucket struct,
so it uses size - sizeof(pointer) as the offset.

NaCl/amd64p32 is the exception, as always.
The worst case alignment is 64 bits but pointers are 32 bits.
There's a long history that is not worth going into, but when
we moved the overflow pointer to the end of the struct,
we didn't get the padding computation right.
The compiler computed the regular struct size and then
on amd64p32 added another 32-bit field.
And the runtime assumed it could step back two 32-bit fields
(one 64-bit register size) to get to the overflow pointer.
But in fact if the struct needed 64-bit alignment, the computation
of the regular struct size would have added a 32-bit pad already,
and then the code unconditionally added a second 32-bit pad.
This placed the overflow pointer three words from the end, not two.
The last two were padding, and since the runtime was consistent
about using the second-to-last word as the overflow pointer,
no harm done in the sense of overwriting useful memory.
But writing the overflow pointer to a non-pointer word of memory
means that the GC can't see the overflow blocks, so it will
collect them prematurely. Then bad things happen.

Correct all this in a few steps:

1. Add an explicit check at the end of the bucket layout in the
compiler that the overflow field is last in the struct, never
followed by padding.

2. When padding is needed on nacl (not always, just when needed),
insert it before the overflow pointer, to preserve the "last in the struct"
property.

3. Let the compiler have the final word on the width of the struct,
by inserting an explicit padding field instead of overwriting the
results of the width computation it does.

4. For the same reason (tell the truth to the compiler), set the type
of the overflow field when we're trying to pretend its not a pointer
(in this case the runtime maintains a list of the overflow blocks
elsewhere).

5. Make the runtime use "last in the struct" as its location algorithm.

This fixes TestTraceStress on nacl/amd64p32.
The 'bad map state' and 'invalid free list' failures no longer occur.

Fixes #11838.

Change-Id: If918887f8f252d988db0a35159944d2b36512f92
Reviewed-on: https://go-review.googlesource.com/12971
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2015-07-31 18:49:32 +00:00
Josh Bleecher Snyder
93c354b6cc [dev.ssa] cmd/compile: handle non-in-place NEG and NOT
This fixes the crypto/subtle tests.

Change-Id: Ie6e721eec3481f67f13de1bfbd7988e227793148
Reviewed-on: https://go-review.googlesource.com/13000
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-31 17:10:13 +00:00
Josh Bleecher Snyder
85e0329fbc [dev.ssa] cmd/compile: move most types outside SSA
The only types that remain in the ssa package
are special compiler-only types.

Change-Id: If957abf128ec0778910d67666c297f97f183b7ee
Reviewed-on: https://go-review.googlesource.com/12933
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-30 21:30:59 +00:00
Josh Bleecher Snyder
165c1c16d1 [dev.ssa] cmd/compile: provide stack trace for caught panics
Change-Id: I9cbb6d53a8c2302222b13d2f33b081b704208b8a
Reviewed-on: https://go-review.googlesource.com/12932
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
2015-07-30 20:31:35 +00:00
Alexandru Moșoi
6d9362a1f7 [dev.ssa] cmd/compile/internal/ssa/gen: implement OXOR.
From compiling go there were 260 functions where XOR was needed.

Much of the required changes for implementing XOR were already
done in 12813.

Change-Id: I5a68aa028f5ed597bc1d62cedbef3620753dfe82
Reviewed-on: https://go-review.googlesource.com/12901
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-30 20:18:19 +00:00
Josh Bleecher Snyder
95aff4db54 [dev.ssa] cmd/compile: use Copy instead of ConvNop
The existing backend simply elides OCONVNOP.
There's no reason for us to do any differently.
Rather than insert ConvNops and then rewrite them
away, stop creating them in the first place.

Change-Id: I4bcbe2229fcebd189ae18df24f2c612feb6e215e
Reviewed-on: https://go-review.googlesource.com/12810
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-30 20:17:42 +00:00
Todd Neal
9271ecc8c6 [dev.ssa] cmd/compile: fix SUBQ generation error
Fix code generation error that resulted in a multi-argument NEGQ

doasm: notfound ft=13 tt=13 00134 NEGQ	AX, AX 13 13

Change-Id: I8b712d21a5523eccbae1f33ccea417844c27073e
Reviewed-on: https://go-review.googlesource.com/12869
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-30 19:39:20 +00:00
Keith Randall
359747da15 [dev.ssa] Merge remote-tracking branch 'origin/master' into mergebranch
Semi-regular merge from tip into ssa branch

Change-Id: Ida553b5c504058347c0bdcb1a987727bdcea456b
2015-07-30 12:30:48 -07:00
Keith Randall
4b803151ce [dev.ssa] cmd/compile/internal/ssa: fix shift operations
Convert shift ops to also encode the size of the shift amount.

Change signed right shift from using CMOV to using bit twiddles.
It is a little bit better (5 instructions instead of 4, but fewer
bytes and slightly faster code).  It's also a bit faster than
the 4-instruction branch version, even with a very predictable
branch.  As tested on my machine, YMMV.

Implement OCOM while we are here.

Change-Id: I8ca12dd62fae5d626dc0e6da5d4bbd34fd9640d2
Reviewed-on: https://go-review.googlesource.com/12867
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-30 17:57:12 +00:00
David Chase
6f6bcadc17 cmd/compile: add case for ODOTTYPE to escwalk
ODOTTYPE should be treated a whole lot like ODOT,
but it was missing completely from the switch in
escwalk and thus escape status did not propagate
to fields.

Since interfaces are required to trigger this bug,
the test was added to escape_iface.go.

Fixes #11931.

Change-Id: Id0383981cc4b1a160f6ad447192a112eed084538
Reviewed-on: https://go-review.googlesource.com/12921
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-30 17:39:44 +00:00
Keith Randall
bdb2d2810d [dev.ssa] cmd/compile/internal/ssa: update generated code
Missed somehow in #12813

Change-Id: I28f2789e33822a4ff884d8a3f474522747f61c73
Reviewed-on: https://go-review.googlesource.com/12868
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-30 17:39:02 +00:00
Russ Cox
c4092ac398 cmd/compile: fix uninitialized memory during type switch assertE2I2
Fixes arm64 builder crash.

The bug is possible on all architectures; you just have to get lucky
and hit a preemption or a stack growth on entry to assertE2I2.
The test stacks the deck.

Change-Id: I8419da909b06249b1ad15830cbb64e386b6aa5f6
Reviewed-on: https://go-review.googlesource.com/12890
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-07-30 05:21:56 +00:00
Keith Randall
20550cbaf1 [dev.ssa] cmd/compile/internal/ssa: implement lots of small (<8byte) ops.
Lots and lots of ops!
Also XOR for good measure.

Add a pass to the compiler generator to check that all of the
architecture-specific opcodes are handled by genValue.  We will
catch any missing ones if we come across them during compilation,
but probably better to catch them statically.

Change-Id: Ic4adfbec55c8257f88117bc732fa664486262868
Reviewed-on: https://go-review.googlesource.com/12813
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-29 21:48:04 +00:00
Russ Cox
3952057cf6 cmd/compile: align arm64 stack frames correctly
If the compiler doesn't do it, cmd/internal/obj/arm64 will,
and that will break the zeroing of ambiguously live values
done in zerorange, which in turn produces uninitialized
pointer cells that the GC trips over.

For #9880.

Change-Id: Ice97c30bc8b36d06b7b88d778d87fab8e1827fdc
Reviewed-on: https://go-review.googlesource.com/12847
Reviewed-by: Austin Clements <austin@google.com>
2015-07-29 21:34:50 +00:00
Alexandru Moșoi
7402416a8b [dev.ssa] cmd/compile/internal/ssa/gen: implement OOR.
From compiling go there were 761 functions where OR was needed.

Change-Id: Ied8bf59cec50a3175273387bc7416bd042def6d8
Reviewed-on: https://go-review.googlesource.com/12766
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-29 20:56:34 +00:00
Josh Bleecher Snyder
9f8a677eab [dev.ssa] cmd/compile: lower all integer comparisons
Change-Id: I683281e1293d3df3c39772e7b08f0b55a3b61404
Reviewed-on: https://go-review.googlesource.com/12811
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 23:05:16 +00:00
Josh Bleecher Snyder
1bab5b9b41 [dev.ssa] cmd/compile: add a few more binary ops
With this, all non-float, non-complex
binary ops found in the standard library
are implemented.

Change-Id: I6087f115229888c0dce10ab35db3fd36a0e0a8b1
Reviewed-on: https://go-review.googlesource.com/12799
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 23:04:40 +00:00
Keith Randall
9cb332efd4 [dev.ssa] cmd/compile/internal/ssa: Split OpConst into an OpConst8, OpConst16, ...
Convert the polymorphic OpConst into monomorphic variants.

Change-Id: I90bb8894fbac04ca5e5484ea260c131ef8b506fb
Reviewed-on: https://go-review.googlesource.com/12798
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-28 22:47:36 +00:00
Josh Bleecher Snyder
25d1916816 [dev.ssa] cmd/compile: implement OINDREG in expr context
Change-Id: I1922656c99773255e5bc15b5a2bd79f19a2fe82c
Reviewed-on: https://go-review.googlesource.com/12796
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 21:09:37 +00:00
Josh Bleecher Snyder
71a4c4bb8d [dev.ssa] cmd/compile: finish InvertFlags rewrites
Change-Id: I61b2d2be18f905a17e8ee765a4494b763a425c55
Reviewed-on: https://go-review.googlesource.com/12794
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 20:15:52 +00:00
Josh Bleecher Snyder
3e3d162f50 [dev.ssa] cmd/compile: implement genValue for MOVQstoreidx8
Change-Id: I6b13a26e01ef8739ed60e6fd5f5c1ea045bea581
Reviewed-on: https://go-review.googlesource.com/12793
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 20:15:19 +00:00
Josh Bleecher Snyder
67df7934cc [dev.ssa] cmd/compile: respect Xoffset of static data
Together with teaching SSA to generate static data,
this fixes the encoding/pem and hash/adler32 tests.

Change-Id: I75f81f6c995dcb9c6d99bd3acda94a4feea8b87b
Reviewed-on: https://go-review.googlesource.com/12791
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 19:44:06 +00:00
Josh Bleecher Snyder
6b41665039 [dev.ssa] cmd/compile: implement static data generation
The existing backend recognizes special
assignment statements as being implementable
with static data rather than code.
Unfortunately, it assumes that it is in the middle
of codegen; it emits data and modifies the AST.

This does not play well with SSA's two-phase
bootstrapping approach, in which we attempt to
compile code but fall back to the existing backend
if something goes wrong.

To work around this:

* Add the ability to inquire about static data
without side-effects.
* Save the static data required for a function.
* Emit that static data during SSA codegen.

Change-Id: I2e8a506c866ea3e27dffb597095833c87f62d87e
Reviewed-on: https://go-review.googlesource.com/12790
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 19:43:31 +00:00
Keith Randall
2a5e6c47bc [dev.ssa] cmd/compile/internal/ssa: redo how sign extension is handled
For integer types less than a machine register, we have to decide
what the invariants are for the high bits of the register.  We used
to set the high bits to the correct extension (sign or zero, as
determined by the type) of the low bits.

This CL makes the compiler ignore the high bits of the register
altogether (they are junk).

On this plus side, this means ops that generate subword results don't
have to worry about correctly extending them.  On the minus side,
ops that consume subword arguments have to deal with the input
registers not being correctly extended.

For x86, this tradeoff is probably worth it.  Almost all opcodes
have versions that use only the correct subword piece of their
inputs.  (The one big exception is array indexing.)  Not many opcodes
can correctly sign extend on output.

For other architectures, the tradeoff is probably not so clear, as
they don't have many subword-safe opcodes (e.g. 16-bit compare,
ignoring the high 16/48 bits).  Fortunately we can decide whether
we do this per-architecture.

For the machine-independent opcodes, we pretend that the "register"
size is equal to the type width, so sign extension is immaterial.
Opcodes that care about the signedness of the input (e.g. compare,
right shift) have two different variants.

Change-Id: I465484c5734545ee697afe83bc8bf4b53bd9df8d
Reviewed-on: https://go-review.googlesource.com/12600
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-28 19:09:36 +00:00
Josh Bleecher Snyder
9ca24fcda8 [dev.ssa] cmd/compile: implement non-numeric comparisons
The only slice/interface comparisons that reach
the backend are comparisons to nil.

Funcs, maps, and channels are references types,
so pointer equality is enough.

Change-Id: I60a71da46a36202e9bd62ed370ab7d7f2e2800e7
Reviewed-on: https://go-review.googlesource.com/12715
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 18:44:57 +00:00
Alexandru Moșoi
edff881ce5 [dev.ssa] cmd/compile/internal/ssa/gen: implement OAND.
Before this patch there was only partial support for ANDQconst
which was not lowered. This patch added support for AND operations
for all bit sizes and signs.

Change-Id: I3a6b2cddfac5361b27e85fcd97f7f3537ebfbcb6
Reviewed-on: https://go-review.googlesource.com/12761
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-28 16:52:00 +00:00
Alexandru Moșoi
c15b0e83d2 [dev.ssa] cmd/compile/internal/ssa/gen: implement all bit sizes for Eq and Neq
Change-Id: I2c5c75153493b5dd3f1a743e5edf04403e83b31b
Reviewed-on: https://go-review.googlesource.com/12474
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-27 22:39:49 +00:00
Josh Bleecher Snyder
1807d54d85 [dev.ssa] cmd/compile: detect unbalanced rules
Rules may span multiple lines,
but if we're still unbalanced at the
end of the file, something is wrong.

I write unbalanced rules depressingly often.

Change-Id: Ibd04aa06539e2a0ffef73bb665febf3542fd11f1
Reviewed-on: https://go-review.googlesource.com/12710
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-27 22:32:28 +00:00
Josh Bleecher Snyder
15dcdfba0f [dev.ssa] cmd/compile: implement OCALLMETH
This mimics the way the old backend
compiles OCALLMETH.

Change-Id: I635c8e7a48c8b5619bd837f78fa6eeba83a57b2f
Reviewed-on: https://go-review.googlesource.com/12549
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-27 22:24:02 +00:00
Todd Neal
c9a38ce758 [dev.ssa] cmd/compile: don't flush a value derived from the current value
If flushing a value from a register that might be used by the current
old-schedule value, save it to the home location.

This resolves the error that was changed from panic to unimplemented in
CL 12655.

Change-Id: If864be34abcd6e11d6117a061376e048a3e29b3a
Reviewed-on: https://go-review.googlesource.com/12682
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-27 20:14:14 +00:00
Josh Bleecher Snyder
b61f8c8df3 [dev.ssa] cmd/compile: fix registers for in-place instructions
Some of these were right; others weren't.

Fixes 'GOGC=off GOSSAPKG=mime go test -a mime'.

The right long term fix is probably to teach the
register allocator about in-place instructions.
In the meantime, all the tests that we can run
now pass.

Change-Id: I8e37b00a5f5e14f241b427d45d5f5cc1064883a2
Reviewed-on: https://go-review.googlesource.com/12664
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-27 17:24:54 +00:00
Josh Bleecher Snyder
0bb2a50a55 [dev.ssa] cmd/compile: respect stack slot width when storing/loading registers
Prior to this, we were smashing our own stack,
which caused the crypto/sha256 tests to fail.

Change-Id: I7dd94cf466d175b3be0cd65f9c4fe8b1223081fe
Reviewed-on: https://go-review.googlesource.com/12660
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-27 17:22:29 +00:00
Todd Neal
db5232620a [dev.ssa] cmd/compile: only fold 32 bit integers for add/multiply
Fix an issue where doasm fails if trying to multiply by a larger
than 32 bit const (doasm: notfound ft=9 tt=14 00008 IMULQ
$34359738369, CX 9 14).  Fix truncation of 64 to 32 bit integer
when generating LEA causing incorrect values to be computed.

Change-Id: I1e65b63cc32ac673a9bb5a297b578b44c2f1ac8f
Reviewed-on: https://go-review.googlesource.com/12678
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-27 02:08:59 +00:00
Todd Neal
52d76f7a6a [dev.ssa] cmd/compile: rewrite if not
Rewrite if !cond by swapping the branches and removing the not.

Change-Id: If3af1bac02bfc566faba872a8c7f7e5ce38e9f58
Reviewed-on: https://go-review.googlesource.com/12610
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-26 02:10:45 +00:00
Josh Bleecher Snyder
7e74e43366 [dev.ssa] cmd/compile: minor cleanup
Cull dead code. Add TODOs.

Change-Id: I81d24371de47f5a27d3a3a0ec0ef5baaf6814c06
Reviewed-on: https://go-review.googlesource.com/12659
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-24 22:28:43 +00:00
Matthew Dempsky
c09d284953 cmd/compile: add missing quotation mark
Change-Id: I102901e3df76830ccd5ab74d757203d103eef9e8
Reviewed-on: https://go-review.googlesource.com/12657
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-24 22:12:14 +00:00
Josh Bleecher Snyder
71b570774d [dev.ssa] cmd/compile: finish implementing comparisons
Change-Id: I4e496c7c7239111133631f76ca25e14be64800c6
Reviewed-on: https://go-review.googlesource.com/12656
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-24 20:44:11 +00:00
Josh Bleecher Snyder
5c5f2a731c [dev.ssa] cmd/compile: convert localOffset panic to unimplemented
This prevents panics while attempting to generate code
for the runtime package. Now:

<unknown line number>: internal compiler error: localOffset of non-LocalSlot value: v10 = ADDQconst <*m> [256] v22

Change-Id: I20ed6ec6aae2c91183b8c826b8ebcc98e8ceebff
Reviewed-on: https://go-review.googlesource.com/12655
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-24 20:43:53 +00:00
Josh Bleecher Snyder
8d31df18af [dev.ssa] cmd/compile: use string contents instead of offset from string header
This generates more efficient code.

Before:

	0x003a 00058 (rr.go:7)	LEAQ	go.string.hdr."="(SB), BX
	0x0041 00065 (rr.go:7)	LEAQ	16(BX), BP
	0x0045 00069 (rr.go:7)	MOVQ	BP, 16(SP)

After:

	0x003a 00058 (rr.go:7)	LEAQ	go.string."="(SB), BX
	0x0041 00065 (rr.go:7)	MOVQ	BX, 16(SP)

It also matches the existing backend
and is more robust to other changes,
such as CL 11698, which I believe broke
the current code.

This CL fixes the encoding/base64 tests, as run with:

	GOGC=off GOSSAPKG=base64 go test -a encoding/base64

Change-Id: I3c475bed1dd3335cc14e13309e11d23f0ed32c17
Reviewed-on: https://go-review.googlesource.com/12654
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-24 20:43:32 +00:00
Todd Neal
d90e0481bf [dev.ssa] cmd/compile: implement LEAQ2/LEAQ4/LEAQ8 opcodes
Change-Id: I8da76b9a4c5c80e8515e69e105d6349fe3ad9281
Reviewed-on: https://go-review.googlesource.com/12611
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-24 15:16:23 +00:00
David Chase
731dcdae6d cmd/compile: prepend captured args to called-closure params
Old code appended, did not play well with a closure
with a ... param.

Fixes #11075.

Change-Id: Ib7c8590c5c4e576e798837e7499e00f3494efb4a
Reviewed-on: https://go-review.googlesource.com/12580
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: David Chase <drchase@google.com>
2015-07-23 19:02:19 +00:00
Josh Bleecher Snyder
851ceebceb [dev.ssa] cmd/compile: don't alloc new CSE classes
This reduces the time to compile
test/slice3.go on my laptop from ~12s to ~3.8s.
It reduces the max memory use from ~4.8gb to
~450mb.

This is still considerably worse than tip,
at 1s and 300mb respectively, but it's
getting closer.

Hopefully this will fix the build at long last.

Change-Id: Iac26b52023f408438cba3ea1b81dcd82ca402b90
Reviewed-on: https://go-review.googlesource.com/12566
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 18:13:32 +00:00
Josh Bleecher Snyder
317226e61c [dev.ssa] cmd/compile: use v.Args[x].Op in CSE key
Experimentally, the Ops of v.Args do a good job
of differentiating values that will end up in
different partitions.

Most values have at most two args, so use them.

This reduces the wall time to run test/slice3.go
on my laptop from ~20s to ~12s.

Credit to Todd Neal for the idea.

Change-Id: I55d08f09eb678bbe8366924ca2fabcd32526bf41
Reviewed-on: https://go-review.googlesource.com/12565
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 18:12:44 +00:00
Josh Bleecher Snyder
5254be3a9c [dev.ssa] cmd/compile: make etypes readable
Change-Id: Id89ea3b458597dd93d269b9fe5475e9cccc6d992
Reviewed-on: https://go-review.googlesource.com/12562
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 18:09:12 +00:00
Josh Bleecher Snyder
d298209b1c [dev.ssa] cmd/compile: add GOSSAFUNC and GOSSAPKG
These temporary environment variables make it
possible to enable using SSA-generated code
for a particular function or package without
having to rebuild the compiler.

This makes it possible to start bulk testing
SSA generated code.

First, bump up the default stack size
(_StackMin in runtime/stack2.go) to something
large like 32768, because without stackmaps
we can't grow stacks.

Then run something like:

for pkg in `go list std`
do
  GOGC=off GOSSAPKG=`basename $pkg` go test -a $pkg
done

When a test fails, you can re-run those tests,
selectively enabling one function after another,
until you find the one that is causing trouble.

Doing this right now yields some interesting results:

* There are several packages for which we generate
  some code and whose tests pass. Yay!

* We can generate code for encoding/base64, but
  tests there fail, so there's a bug to fix.

* Attempting to build the runtime yields a panic during codegen:
  panic: interface conversion: ssa.Location is nil, not *ssa.LocalSlot

* The top unimplemented codegen items are (simplified):
  59 genValue not implemented: REPMOVSB
  18 genValue not implemented: REPSTOSQ
  14 genValue not implemented: SUBQ
   9 branch not implemented: If v -> b b. Control: XORQconst <bool> [1]
   8 genValue not implemented: MOVQstoreidx8
   4 branch not implemented: If v -> b b. Control: SETG <bool>
   3 branch not implemented: If v -> b b. Control: SETLE <bool>
   2 load flags not implemented: LoadReg8 <flags>
   2 genValue not implemented: InvertFlags <flags>
   1 store flags not implemented: StoreReg8 <flags>
   1 branch not implemented: If v -> b b. Control: SETGE <bool>

Change-Id: Ib64809ac0c917e25bcae27829ae634c70d290c7f
Reviewed-on: https://go-review.googlesource.com/12547
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 18:08:17 +00:00
Josh Bleecher Snyder
8c954d5780 [dev.ssa] cmd/compile: speed up cse
By walking only the current set of partitions
at any given point, the cse pass ended up doing
lots of extraneous, effectively O(n^2) work.

Using a regular for loop allows each cse pass to
make as much progress as possible by processing
each new class as it is introduced.

This can and should be optimized further,
but it already reduces by 75% cse time on test/slice3.go.

The overall time to compile test/slice3.go is still
dominated by the O(n^2) work in the liveness pass.
However, Keith is rewriting regalloc anyway.

Change-Id: I8be020b2f69352234587eeadeba923481bf43fcc
Reviewed-on: https://go-review.googlesource.com/12244
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 18:06:04 +00:00
Josh Bleecher Snyder
00437ebe73 [dev.ssa] cmd/compile: don't combine phi vars from different blocks in CSE
Here is a concrete case in which this goes wrong.

func f_ssa() int {
	var n int
Next:
	for j := 0; j < 3; j++ {
		for i := 0; i < 10; i++ {
			if i == 6 {
				continue Next
			}
			n = i
		}
		n += j + j + j + j + j + j + j + j + j + j // j * 10
	}
	return n
}

What follows is the function printout before and after CSE.

Note blocks b8 and b10 in the before case.

b8 is the inner loop's condition: i < 10.
b10 is the inner loop's increment: i++.
v82 is i. On entry to b8, it is either 0 (v19) the first time,
or the result of incrementing v82, by way of v29.

The CSE pass considered v82 and v49 to be common subexpressions,
and eliminated v82 in favor of v49.

In the after case, v82 is now dead and will shortly be eliminated.
As a result, v29 is also dead, and we have lost the increment.
The loop runs forever.

BEFORE CSE

f_ssa <nil>
  b1:
    v1 = Arg <mem>
    v2 = SP <uint64>
    v4 = Addr <*int> {~r0} v2
    v13 = Zero <mem> [8] v4 v1
    v14 = Const <int>
    v15 = Const <int>
    v17 = Const <int> [3]
    v19 = Const <int>
    v21 = Const <int> [10]
    v24 = Const <int> [6]
    v28 = Const <int> [1]
    v43 = Const <int> [1]
    Plain -> b3
  b2: <- b7
    Exit v47
  b3: <- b1
    Plain -> b4
  b4: <- b3 b6
    v49 = Phi <int> v15 v44
    v68 = Phi <int> v14 v67
    v81 = Phi <mem> v13 v81
    v18 = Less <bool> v49 v17
    If v18 -> b5 b7
  b5: <- b4
    Plain -> b8
  b6: <- b12 b11
    v67 = Phi <int> v66 v41
    v44 = Add <int> v49 v43
    Plain -> b4
  b7: <- b4
    v47 = Store <mem> v4 v68 v81
    Plain -> b2
  b8: <- b5 b10
    v66 = Phi <int> v68 v82
    v82 = Phi <int> v19 v29
    v22 = Less <bool> v82 v21
    If v22 -> b9 b11
  b9: <- b8
    v25 = Eq <bool> v82 v24
    If v25 -> b12 b13
  b10: <- b13
    v29 = Add <int> v82 v28
    Plain -> b8
  b11: <- b8
    v32 = Add <int> v49 v49
    v33 = Add <int> v32 v49
    v34 = Add <int> v33 v49
    v35 = Add <int> v34 v49
    v36 = Add <int> v35 v49
    v37 = Add <int> v36 v49
    v38 = Add <int> v37 v49
    v39 = Add <int> v38 v49
    v40 = Add <int> v39 v49
    v41 = Add <int> v66 v40
    Plain -> b6
  b12: <- b9
    Plain -> b6
  b13: <- b9
    Plain -> b10

AFTER CSE

f_ssa <nil>
  b1:
    v1 = Arg <mem>
    v2 = SP <uint64>
    v4 = Addr <*int> {~r0} v2
    v13 = Zero <mem> [8] v4 v1
    v14 = Const <int>
    v15 = Const <int>
    v17 = Const <int> [3]
    v19 = Const <int>
    v21 = Const <int> [10]
    v24 = Const <int> [6]
    v28 = Const <int> [1]
    v43 = Const <int> [1]
    Plain -> b3
  b2: <- b7
    Exit v47
  b3: <- b1
    Plain -> b4
  b4: <- b3 b6
    v49 = Phi <int> v19 v44
    v68 = Phi <int> v19 v67
    v81 = Phi <mem> v13 v81
    v18 = Less <bool> v49 v17
    If v18 -> b5 b7
  b5: <- b4
    Plain -> b8
  b6: <- b12 b11
    v67 = Phi <int> v66 v41
    v44 = Add <int> v49 v43
    Plain -> b4
  b7: <- b4
    v47 = Store <mem> v4 v68 v81
    Plain -> b2
  b8: <- b5 b10
    v66 = Phi <int> v68 v49
    v82 = Phi <int> v19 v29
    v22 = Less <bool> v49 v21
    If v22 -> b9 b11
  b9: <- b8
    v25 = Eq <bool> v49 v24
    If v25 -> b12 b13
  b10: <- b13
    v29 = Add <int> v49 v43
    Plain -> b8
  b11: <- b8
    v32 = Add <int> v49 v49
    v33 = Add <int> v32 v49
    v34 = Add <int> v33 v49
    v35 = Add <int> v34 v49
    v36 = Add <int> v35 v49
    v37 = Add <int> v36 v49
    v38 = Add <int> v37 v49
    v39 = Add <int> v38 v49
    v40 = Add <int> v39 v49
    v41 = Add <int> v66 v40
    Plain -> b6
  b12: <- b9
    Plain -> b6
  b13: <- b9
    Plain -> b10

Change-Id: I16fc4ec527ec63f24f7d0d79d1a4a59bf37269de
Reviewed-on: https://go-review.googlesource.com/12444
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 18:05:33 +00:00
Keith Randall
be1eb57a8b [dev.ssa] cmd/compile/internal/ssa: implement multiplies
Use width-and-signed-specific multiply opcodes.
Implement OMUL.
A few other cleanups.

Fixes #11467

Change-Id: Ib0fe80a1a9b7208dbb8a2b6b652a478847f5d244
Reviewed-on: https://go-review.googlesource.com/12540
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-23 17:58:59 +00:00
Josh Bleecher Snyder
d5297f7261 [dev.ssa] cmd/compile: speed up liveness analysis
This reduces the wall time to run test/slice3.go
on my laptop from >10m to ~20s.

This could perhaps be further reduced by using
a worklist of blocks and/or implementing the
suggestion in the comment in this CL, but at this
point, it's fast enough that there is no need.

Change-Id: I741119e0c8310051d7185459f78be8b89237b85b
Reviewed-on: https://go-review.googlesource.com/12564
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 17:27:08 +00:00
Josh Bleecher Snyder
e61e7c96f7 [dev.ssa] cmd/compile: add some common binary ops
Change-Id: I1af486a69960b9b66d5c2c9bbfcf7db6ef075d8c
Reviewed-on: https://go-review.googlesource.com/12563
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 17:10:56 +00:00
Josh Bleecher Snyder
e0ac5c5337 [dev.ssa] cmd/compile: minor cleanup
Change-Id: Ib33f3b1cfa09f410675d275e214d8ddc246c53c3
Reviewed-on: https://go-review.googlesource.com/12548
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 17:10:28 +00:00
David Chase
2584974d16 cmd/compile: adjust annotation of implicit operations.
Limit probe to ODOT/OIND/ODOTPTR for now; that works.

Fixes #11790

Change-Id: I411271e702c5fe6ceb880ca47c7dacc37ffcbb6a
Reviewed-on: https://go-review.googlesource.com/12532
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-23 14:19:07 +00:00
Josh Bleecher Snyder
61aa0953e5 [dev.ssa] cmd/compile: implement control flow handling
Add label and goto checks and improve test coverage.

Implement OSWITCH and OSELECT.

Implement OBREAK and OCONTINUE.

Allow generation of code in dead blocks.

Change-Id: Ibebb7c98b4b2344f46d38db7c9dce058c56beaac
Reviewed-on: https://go-review.googlesource.com/12445
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-23 00:45:26 +00:00
Alexandru Moșoi
3e7e519c36 [dev.ssa] cmd/compile/internal/ssa/gen: generalize strength reduction.
Handle multiplication with -1, 0, 3, 5, 9 and all powers of two.

Change-Id: I8e87e7670dae389aebf6f446d7a56950cacb59e0
Reviewed-on: https://go-review.googlesource.com/12350
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-22 22:00:31 +00:00
Alexandru Moșoi
954d5ada29 [dev.ssa] cmd/compile/internal/ssa/gen: implement OMINUS
Change-Id: Ibc645d6cf229ecc18af3549dd3750be9d7451abe
Reviewed-on: https://go-review.googlesource.com/12472
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-22 22:00:17 +00:00
Russ Cox
75d779566b runtime/cgo: make compatible with race detector
Some routines run without and m or g and cannot invoke the
race detector runtime. They must be opaque to the runtime.
That used to be true because they were written in C.
Now that they are written in Go, disable the race detector
annotations for those functions explicitly.

Add test.

Fixes #10874.

Change-Id: Ia8cc28d51e7051528f9f9594b75634e6bb66a785
Reviewed-on: https://go-review.googlesource.com/12534
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-22 20:28:47 +00:00
Josh Bleecher Snyder
8fb6358153 [dev.ssa] cmd/compile: don't generate zero values for ssa ops
Shorter code, easier to read, no pointless empty slices.

Change-Id: Id410364b4f6924b5665188af3373a5e914117c38
Reviewed-on: https://go-review.googlesource.com/12480
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-21 16:03:54 +00:00
Josh Bleecher Snyder
ac1935b3a7 [dev.ssa] cmd/compile: fix build
Bad rebase in CL 12439.

Change-Id: I7ad359519c6274be37456b655f19bf0ca6ac6692
Reviewed-on: https://go-review.googlesource.com/12449
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-21 14:02:34 +00:00
Josh Bleecher Snyder
a402b58e51 [dev.ssa] cmd/compile: implement "if SETEQ" branches
Change-Id: I814fd0c2f1a622cca7dfd1b771f81de309a1904c
Reviewed-on: https://go-review.googlesource.com/12441
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-21 13:50:14 +00:00
Josh Bleecher Snyder
2574e4ac1c [dev.ssa] cmd/compile: call through to expr for expression statements
Change-Id: I8625eff33f5a49dbaaec060c3fa067d7531193c4
Reviewed-on: https://go-review.googlesource.com/12313
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-21 13:49:48 +00:00
Josh Bleecher Snyder
67bfd69564 [dev.ssa] cmd/compile: fix stackalloc handling of zero-aligned variables
Prior to this fix, a zero-aligned variable such as a flags
variable would reset n to 0.

While we're here, log the stack layout so that debugging
and reading the generated assembly is easier.

Change-Id: I18ef83ea95b6ea877c83f2e595e14c48c9ad7d84
Reviewed-on: https://go-review.googlesource.com/12439
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-21 13:49:10 +00:00
Josh Bleecher Snyder
26f135d7c1 [dev.ssa] cmd/compile: mark LoadReg8 and StoreReg8 of flags as unimplemented
It is not clear to me what the right implementation is.
LoadReg8 and StoreReg8 are introduced during regalloc,
so after the amd64 rewrites. But implementing them
in genValue seems silly.

Change-Id: Ia708209c4604867bddcc0e5d75ecd17cf32f52c3
Reviewed-on: https://go-review.googlesource.com/12437
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-21 13:41:39 +00:00
Josh Bleecher Snyder
a794074da0 [dev.ssa] cmd/compile: implement genValue for AMD64SETxx
Change-Id: I591f2c0465263dcdeef46920aabf1bbb8e7ac5c0
Reviewed-on: https://go-review.googlesource.com/12436
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-21 13:40:52 +00:00
Josh Bleecher Snyder
983bc8d1a2 Revert "[dev.ssa] cmd/compile: don't Compile if Unimplemented"
This reverts commit 766bcc92a5.

Change-Id: I55413c1aa80d82c856a3ea89b4ffccf80fb58013
Reviewed-on: https://go-review.googlesource.com/12361
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-21 13:38:53 +00:00
Keith Randall
67fdb0de86 [dev.ssa] cmd/compile/internal/ssa: use width and sign specific opcodes
Bake the bit width and signedness into opcodes.
Pro: Rewrite rules become easier.  Less chance for confusion.
Con: Lots more opcodes.

Let me know what you think.  I'm leaning towards this, but I could be
convinced otherwise if people think this is too ugly.

Update #11467

Change-Id: Icf1b894268cdf73515877bb123839800d97b9df9
Reviewed-on: https://go-review.googlesource.com/12362
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-21 04:34:02 +00:00
Josh Bleecher Snyder
8043f450c1 [dev.ssa] cmd/compile: fix test verb
The verb doesn't do anything, but if/when we move
these to the test directory, having it be right
will be one fewer thing to remember.

Change-Id: Ibf0280d7cc14bf48927e25215de6b91c111983d9
Reviewed-on: https://go-review.googlesource.com/12438
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-21 00:09:24 +00:00
Josh Bleecher Snyder
21bd483c4a [dev.ssa] cmd/compile: refactor out zero value creation
This will be used in a subsequent commit.

Change-Id: I43eca21f4692d99e164c9f6be0760597c46e6a26
Reviewed-on: https://go-review.googlesource.com/12440
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-21 00:08:59 +00:00
Josh Bleecher Snyder
f421735bb4 [dev.ssa] cmd/compile: handle OpCopy loops in rewrite
Change-Id: Icbaad6e5cbfc5430a651538fe90c0a9ee664faf4
Reviewed-on: https://go-review.googlesource.com/12360
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-20 17:35:08 +00:00
Michael Hudson-Doyle
1125cd4997 cmd/compile: define func value symbols at declaration
This is mostly Russ's https://golang.org/cl/12145 but with some extra fixes to
account for the fact that function declarations without implementations now
break shared libraries, and including my test case.

Fixes #11480.

Change-Id: Iabdc2934a0378e5025e4e7affadb535eaef2c8f1
Reviewed-on: https://go-review.googlesource.com/12340
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-20 00:50:46 +00:00
Ian Lance Taylor
dabb268170 cmd/compile: ignore carriage return in magic comments
Update #11771.

Change-Id: I3bb3262619765d3ca79652817e17e8f260f41907
Reviewed-on: https://go-review.googlesource.com/12379
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-18 17:33:53 +00:00
Keith Randall
c1593da817 [dev.ssa] cmd/compile/internal/ssa/gen: Fix *64 strength reduction
*64 is <<6, not <<5.

Change-Id: I2eb7e113d5003b2c77fbd3abc3defc4d98976a5e
Reviewed-on: https://go-review.googlesource.com/12323
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-17 15:59:10 +00:00
Keith Randall
3dcc424be7 [dev.ssa] cmd/compile/internal/ssa: compute outarg size correctly
Keep track of the outargs size needed at each call.
Compute the size of the outargs section of the stack frame.  It's just
the max of the outargs size at all the callsites in the function.

Change-Id: I3d0640f654f01307633b1a5f75bab16e211ea6c0
Reviewed-on: https://go-review.googlesource.com/12178
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-16 21:06:13 +00:00
Josh Bleecher Snyder
8adc905a10 [dev.ssa] cmd/compile: implement lowering of constant bools
Change-Id: Ia56ee9798eefe123d4da04138a6a559d2c25ddf3
Reviewed-on: https://go-review.googlesource.com/12312
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-16 19:28:45 +00:00
Josh Bleecher Snyder
766bcc92a5 [dev.ssa] cmd/compile: don't Compile if Unimplemented
If we've already hit an Unimplemented, there may be important
SSA invariants that do not hold and which could cause
ssa.Compile to hang or spin.

While we're here, make detected dependency cycles stop execution.

Change-Id: Ic7d4eea659e1fe3f2c9b3e8a4eee5567494f46ad
Reviewed-on: https://go-review.googlesource.com/12310
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-16 18:54:09 +00:00
Keith Randall
cd7e059496 [dev.ssa] cmd/compile/internal/ssa: implement ODOT
Implement ODOT.  Similar to ArrayIndex, StructSelect selects a field
out of a larger Value.

We may need more ways to rewrite StructSelect, but StructSelect/Load
is the typical way it is used.

Change-Id: Ida7b8aab3298f4754eaf9fee733974cf8736e45d
Reviewed-on: https://go-review.googlesource.com/12265
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-16 05:43:36 +00:00
Todd Neal
078ba138d3 [dev.ssa] cmd/compile/internal : Implement Lengauer-Tarjan for dominators
Implements the simple Lengauer-Tarjan algorithm for dominator
and post-dominator calculation.

benchmark                           old ns/op     new ns/op     delta
BenchmarkDominatorsLinear-8         1403862       1292741       -7.92%
BenchmarkDominatorsFwdBack-8        1270633       1428285       +12.41%
BenchmarkDominatorsManyPred-8       225932354     1530886       -99.32%
BenchmarkDominatorsMaxPred-8        445994225     1393612       -99.69%
BenchmarkDominatorsMaxPredVal-8     447235248     1246899       -99.72%
BenchmarkNilCheckDeep1-8            829           1259          +51.87%
BenchmarkNilCheckDeep10-8           2199          2397          +9.00%
BenchmarkNilCheckDeep100-8          57325         29405         -48.70%
BenchmarkNilCheckDeep1000-8         6625837       2933151       -55.73%
BenchmarkNilCheckDeep10000-8        763559787     319105541     -58.21%

benchmark                           old MB/s     new MB/s     speedup
BenchmarkDominatorsLinear-8         7.12         7.74         1.09x
BenchmarkDominatorsFwdBack-8        7.87         7.00         0.89x
BenchmarkDominatorsManyPred-8       0.04         6.53         163.25x
BenchmarkDominatorsMaxPred-8        0.02         7.18         359.00x
BenchmarkDominatorsMaxPredVal-8     0.02         8.02         401.00x
BenchmarkNilCheckDeep1-8            1.21         0.79         0.65x
BenchmarkNilCheckDeep10-8           4.55         4.17         0.92x
BenchmarkNilCheckDeep100-8          1.74         3.40         1.95x
BenchmarkNilCheckDeep1000-8         0.15         0.34         2.27x
BenchmarkNilCheckDeep10000-8        0.01         0.03         3.00x

Change-Id: Icec3d774422a9bc64914779804c8c0ab73aa72bf
Reviewed-on: https://go-review.googlesource.com/11971
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-15 16:17:04 +00:00
Ian Lance Taylor
2e4b659954 cmd/compile: recognize embedded field in inlined function
There was already special code to recognize "?" in hidden_structdcl,
which is used for inlined types and variables.  This recognizes "?" in
structdcl as well, a case that arises when a struct type appears
within an inlined function body.

Fixes #10219.

Change-Id: Ic5257ae54f817e0d4a189c2294dcd633c9f2101a
Reviewed-on: https://go-review.googlesource.com/12241
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-15 06:04:51 +00:00
Russ Cox
7feb424928 cmd/compile: fix PtrTo(t) for unnamed t with embedded fields
Fixes #8427.

Change-Id: I826a3bc4519845ad30d6dbaf058fe7ed7bee8db0
Reviewed-on: https://go-review.googlesource.com/12233
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-07-15 05:36:27 +00:00
Russ Cox
ea918ef535 Revert "cmd/compile: define func value symbols at declaration"
This reverts commit 3b411bf1a1bb08d6868083981cecba8088dc7aea.

Change-Id: I321a43fa378a43b3e4d7aa97e0222775640af64b
Reviewed-on: https://go-review.googlesource.com/12205
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-15 04:11:54 +00:00
Russ Cox
fa1ea497d5 cmd/compile: define func value symbols at declaration
These used to be defined at use, but that breaks when shared libraries
are involved.

For #11480.

Change-Id: I416a848754fb615c0d75f9f0ccc00723d07f7f01
Reviewed-on: https://go-review.googlesource.com/12145
Reviewed-by: Rob Pike <r@golang.org>
2015-07-15 04:11:01 +00:00
Todd Neal
b383de2ef9 [dev.ssa] cmd/compile: implement OIND
Change-Id: I15aee8095e6388822e2222f1995fe2278ac956ca
Reviewed-on: https://go-review.googlesource.com/12129
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-15 03:24:05 +00:00
Keith Randall
4e204b42f5 [dev.ssa] cmd/compile/internal/ssa: ensure Phi ops are scheduled first
Phi ops should always be scheduled first.  They have the semantics
of all happening simultaneously at the start of the block.  The regalloc
phase assumes all the phis will appear first.

Change-Id: I30291e1fa384a0819205218f1d1ec3aef6d538dd
Reviewed-on: https://go-review.googlesource.com/12154
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-14 15:39:56 +00:00
Brad Fitzpatrick
337b7e7e3b [dev.ssa] cmd/compile: handle OLITERAL nil expressions
Change-Id: I02b8fb277b486eaf0916ddcd8f28c062d4022d4b
Reviewed-on: https://go-review.googlesource.com/12150
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-14 00:07:31 +00:00
Keith Randall
c3c84a2544 [dev.ssa] cmd/compile/internal/gc: Implement ODOT and ODOTPTR in addr.
Change-Id: If8a9d5901fa2141d16b1c8d001761ea62bc23207
Reviewed-on: https://go-review.googlesource.com/12141
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-13 23:17:08 +00:00
Brad Fitzpatrick
b06961b4f0 [dev.ssa] cmd/compile: treat unsafe.Pointer as a pointer
Change-Id: I3f3ac3055c93858894b8852603d79592bbc1696b
Reviewed-on: https://go-review.googlesource.com/12140
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-13 22:36:24 +00:00
Brad Fitzpatrick
a92bd66282 [dev.ssa] cmd/compile: support zero type for *T
Change-Id: I4c9bcea01e2c4333c2a3592b66f1da9f424747a4
Reviewed-on: https://go-review.googlesource.com/12130
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-13 21:29:01 +00:00
Brad Fitzpatrick
50e59bb9c8 [dev.ssa] cmd/compile/internal/gc: fix tests on non-amd64
Change-Id: Ibd6a59db2d5feea41a21fbea5c1a7fdd49238aa8
Reviewed-on: https://go-review.googlesource.com/12131
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-13 21:27:44 +00:00
Brad Fitzpatrick
e81671115c [dev.ssa] cmd/compile: OANDAND, OOROR
Joint hacking with josharian. Hints from matloob and Todd Neal.

Now with tests, and OROR.

Change-Id: Iff8826fde475691fb72a3eea7396a640b6274af9
Reviewed-on: https://go-review.googlesource.com/12041
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-13 04:08:16 +00:00
Keith Randall
7e4c06dad0 [dev.ssa] cmd/compile/internal/gc: handle _ label correctly
An empty label statement can just be ignored, as it cannot
be the target of any gotos.

Tests are already in test/fixedbugs/issue7538*.go

Fixes #11589
Fixes #11593

Change-Id: Iadcd639e7200ce16aa40fd7fa3eaf82522513e82
Reviewed-on: https://go-review.googlesource.com/12093
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-12 20:43:01 +00:00
Daniel Morsing
4c521ac8f2 [dev.ssa] cmd/compile/internal/gc: implement more no-op statements
Change-Id: I26c268f46dcffe39912b8c92ce9abb875310934f
Reviewed-on: https://go-review.googlesource.com/12100
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-12 16:55:31 +00:00
Brad Fitzpatrick
783297ad6a all: link to https for golang subdomains too
The previous commit (git 2ae77376) just did golang.org.  This one
includes golang.org subdomains like blog, play, and build.

Change-Id: I4469f7b307ae2a12ea89323422044e604c5133ae
Reviewed-on: https://go-review.googlesource.com/12071
Reviewed-by: Rob Pike <r@golang.org>
2015-07-12 04:42:40 +00:00
Keith Randall
accf9b5951 [dev.ssa] cmd/compile/internal/ssa: comment why replacing phi with copy is ok
Change-Id: I3e2e8862f2fde4349923016b97e8330b0d494e0e
Reviewed-on: https://go-review.googlesource.com/12092
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-07-12 04:39:44 +00:00
Brad Fitzpatrick
d9c72d739c [dev.ssa] cmd/compile: implement ONOT
Co-hacking with josharian at Gophercon.

Change-Id: Ia59dfab676c6ed598c2c25483439cd1395a4ea87
Reviewed-on: https://go-review.googlesource.com/12029
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-12 04:30:03 +00:00
Brad Fitzpatrick
7af53d98cf [dev.ssa] cmd/compile: implement OCAP
And dependent fixes and misc cleanup.

Co-hacking with josharian at Gophercon.

Change-Id: Ib85dc13b303929017eb0a4d2fc2f603485f7479b
Reviewed-on: https://go-review.googlesource.com/12027
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-12 04:14:58 +00:00
Keith Randall
050ce4390a [dev.ssa] cmd/compile/internal/ssa: Phi inputs from dead blocks are not live
Fixes #11676

Change-Id: I941f951633c89bb1454ce6d1d1b4124d46a7d9dd
Reviewed-on: https://go-review.googlesource.com/12091
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-11 22:45:14 +00:00
ALTree
7a982e3c49 [dev.ssa] cmd/compile/ssa: Replace less-or-equal with equal in len comparison with zero
Since the spec guarantees than 0 <= len always:

https://golang.org/ref/spec#Length_and_capacity

replace len(...) <= 0 check with len(...) == 0 check

Change-Id: I5517a9cb6b190f0b1ee314a67487477435f3b409
Reviewed-on: https://go-review.googlesource.com/12034
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-11 19:38:57 +00:00
Keith Randall
06f329220f [dev.ssa] cmd/compile/internal/ssa: Use Ninit from expressions
If an expression has an Ninit list, generate code for it.
Required for (at least) OANDAND.

Change-Id: I94c9e22e2a76955736f4a8e574d92711419c5e5c
Reviewed-on: https://go-review.googlesource.com/12072
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-11 19:32:35 +00:00
Brad Fitzpatrick
2ae77376f7 all: link to https instead of http
The one in misc/makerelease/makerelease.go is particularly bad and
probably warrants rotating our keys.

I didn't update old weekly notes, and reverted some changes involving
test code for now, since we're late in the Go 1.5 freeze. Otherwise,
the rest are all auto-generated changes, and all manually reviewed.

Change-Id: Ia2753576ab5d64826a167d259f48a2f50508792d
Reviewed-on: https://go-review.googlesource.com/12048
Reviewed-by: Rob Pike <r@golang.org>
2015-07-11 14:36:33 +00:00
Josh Bleecher Snyder
9b048527db [dev.ssa] cmd/compile/ssa: handle nested dead blocks
removePredecessor can change which blocks are live.
However, it cannot remove dead blocks from the function's
slice of blocks because removePredecessor may have been
called from within a function doing a walk of the blocks.

CL 11879 did not handle this correctly and broke the build.

To fix this, mark the block as dead but leave its actual
removal for a deadcode pass. Blocks that are dead must have
no successors, predecessors, values, or control values,
so they will generally be ignored by other passes.
To be safe, we add a deadcode pass after the opt pass,
which is the only other pass that calls removePredecessor.

Two alternatives that I considered and discarded:

(1) Make all call sites aware of the fact that removePrecessor
might make arbitrary changes to the list of blocks. This
will needlessly complicate callers.

(2) Handle the things that can go wrong in practice when
we encounter a dead-but-not-removed block. CL 11930 takes
this approach (and the tests are stolen from that CL).
However, this is just patching over the problem.

Change-Id: Icf0687b0a8148ce5e96b2988b668804411b05bd8
Reviewed-on: https://go-review.googlesource.com/12004
Reviewed-by: Todd Neal <todd@tneal.org>
Reviewed-by: Michael Matloob <michaelmatloob@gmail.com>
2015-07-11 00:08:50 +00:00
Josh Bleecher Snyder
9201c86b57 [dev.ssa] cmd/compile/ssa: print lazily
Reduces 'go run run.go 64bit.go' from 23s to 8s on my machine.

Change-Id: Ie5b642d0abb56e8eb3899d69472bc88a85a1c985
Reviewed-on: https://go-review.googlesource.com/12023
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-07-11 00:07:52 +00:00
Josh Bleecher Snyder
5173868325 [dev.ssa] cmd/compile/ssa: place for loop incr in a separate block
This is a prerequisite for implementing break and continue;
blocks ending in break or continue need to have
the increment block as a successor.

While we're here, implement for loops with no condition.

Change-Id: I85d8ba020628d805bfd0bd583dfd16e1be6f6fae
Reviewed-on: https://go-review.googlesource.com/11941
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-10 03:39:20 +00:00
Russ Cox
9f90f31c3a cmd/compile: allow static init for unsafe.Pointer(&x) where x is global
This avoids both a write barrier and then dynamic initialization
globals of the form

	var x something
	var xp = unsafe.Pointer(&x)

Using static initialization avoids emitting a relocation for &x,
which helps cgo.

Fixes #9411.

Change-Id: I0dbf480859cce6ab57ab805d1b8609c45b48f156
Reviewed-on: https://go-review.googlesource.com/11693
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
2015-07-07 21:51:57 +00:00
David Chase
7929a0ddfa cmd/compile: initialize line number properly for temporaries
The expansion of structure, array, slice, and map literals
does not use the right line number in its introduced assignments
to temporaries, which leads to incorrect line number attribution
for expressions in those literals.

Inlining also incorrectly replaced the line numbers of args to
inlined functions.

This was revealed in CL 9721 because a now-avoided temporary
assignment introduced the correct line number.
I.e. before CL 9721
  "tmp_wrongline := expr"
was transformed to
  "tmp_rightline := expr; tmp_wrongline := tmp_rightline"

Also includes a repair to CL 10334 involving line numbers
where a spurious -1 remained (should have been 0, now is 0).

Fixes #11400.

Change-Id: I3a4687efe463977fa1e2c996606f4d91aaf22722
Reviewed-on: https://go-review.googlesource.com/11730
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-07 21:30:59 +00:00
Todd Neal
41dafe6ecc [dev.ssa] cmd/compile/ssa: dominator tests and benchmarks
This change has some tests verifying functionality and an assortment of
benchmarks of various block lists. It modifies NewBlock to allocate in
contiguous blocks improving the performance of intersect() for extremely
large graphs by 30-40%.

benchmark                           old ns/op      new ns/op     delta
BenchmarkDominatorsLinear-8         1185619        901154        -23.99%
BenchmarkDominatorsFwdBack-8        1302138        863537        -33.68%
BenchmarkDominatorsManyPred-8       404670521      247450911     -38.85%
BenchmarkDominatorsMaxPred-8        455809002      471675119     +3.48%
BenchmarkDominatorsMaxPredVal-8     819315864      468257300     -42.85%

BenchmarkNilCheckDeep1-8            766            706           -7.83%
BenchmarkNilCheckDeep10-8           2553           2209          -13.47%
BenchmarkNilCheckDeep100-8          58606          57545         -1.81%
BenchmarkNilCheckDeep1000-8         7753012        8025750       +3.52%
BenchmarkNilCheckDeep10000-8        1224165946     789995184     -35.47%

Change-Id: Id3d6bc9cb1138e8177934441073ac7873ddf7ade
Reviewed-on: https://go-review.googlesource.com/11716
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-07 19:42:35 +00:00
Josh Bleecher Snyder
7d10a2c04a [dev.ssa] cmd/compile/ssa: implement constant booleans
The removal of if false { ... } blocks in the opt
pass exposed that removePredecessor needed
to do more cleaning, on pain of failing later
consistency checks.

Change-Id: I45d4ff7e1f7f1486fdd99f867867ce6ea006a288
Reviewed-on: https://go-review.googlesource.com/11879
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-06 21:54:10 +00:00
Josh Bleecher Snyder
cc3f031a31 [dev.ssa] cmd/compile/ssa: implement OLEN
Change-Id: Ie23b13142fd820d7071a348a8370175e58b76d64
Reviewed-on: https://go-review.googlesource.com/11878
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-05 03:52:56 +00:00
Josh Bleecher Snyder
6c14059e65 [dev.ssa] cmd/compile/ssa: handle loops that don't loop
Loops such as

func f(c chan int) int {
	for x := range c {
		return x
	}
	return 0
}

don't loop. Remove the assumption that they must.

Partly fixes the build.

Change-Id: I766cebeec8e36d14512bea26f54c06c8eaf95e23
Reviewed-on: https://go-review.googlesource.com/11876
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-05 03:52:34 +00:00
Josh Bleecher Snyder
d465f049cd [dev.ssa] cmd/compile/ssa: stop compilation immediately on leading goto
There is clearly work to do to fix labels and gotos.
The compiler currently hangs on ken/label.go.

For the moment, stop the bleeding.

Fixes the build.

Change-Id: Ib68360d583cf53e1a8ca4acff50644b570382728
Reviewed-on: https://go-review.googlesource.com/11877
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-05 03:51:44 +00:00
Josh Bleecher Snyder
0a133cddd5 [dev.ssa] cmd/compile/ssa: mark race/nodfp as unimplemented
Partly fixes the build, by punting.
Other things have broken in the meantime.

Change-Id: I1e2b8310057cbbbd9ffc501ef51e744690e00726
Reviewed-on: https://go-review.googlesource.com/11875
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-05 03:50:17 +00:00
Josh Bleecher Snyder
1edf4897df [dev.ssa] cmd/compile/ssa: add Logf state helper
Change-Id: I4e4200b0fa847a1ff8a8b7d1e318bbc1c5e26b5b
Reviewed-on: https://go-review.googlesource.com/11874
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-05 03:36:56 +00:00
Daniel Morsing
be2a3e2ac9 [dev.ssa] cmd/compile/internal/gc: mark unimplemented variable classes as such
Doesn't fix the build entirely, but does make it get to the race
detector tests.

Change-Id: Ie986d52374936855b7ee975dc68742306527eb15
Reviewed-on: https://go-review.googlesource.com/11835
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-02 08:29:33 +00:00
Josh Bleecher Snyder
596ddf4368 [dev.ssa] cmd/compile/ssa: add checks for nil args in values
These additional checks were useful in
tracking down the broken build (CL 11238).

This CL does not fix the build, sadly.

Change-Id: I34de3bed223f450aaa97c1cadaba2e4e5850050b
Reviewed-on: https://go-review.googlesource.com/11681
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-01 16:10:38 +00:00
Daniel Morsing
66b47812eb [dev.ssa] cmd/compile/internal/ssa: Initial implementation of memory zeroing
This will make it possible for us to start implementing interfaces
and other stack allocated types which are more than one machine word.

Change-Id: I52b187a791cf1919cb70ed6dabdc9f57b317ea83
Reviewed-on: https://go-review.googlesource.com/11631
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-01 15:47:41 +00:00
Keith Randall
c9372619f2 [dev.ssa] cmd/compile/internal/gc: fix stringsym call
Forgot to add this in the tip merge.

Change-Id: I0e5a2681133f4ae7a7c360ae2c2d71d46420c693
Reviewed-on: https://go-review.googlesource.com/11793
Reviewed-by: Keith Randall <khr@golang.org>
2015-07-01 04:18:52 +00:00
Keith Randall
90b0a93244 [dev.ssa] Merge remote-tracking branch 'origin/master' into ssamerge
Semi-regular merge from tip into ssa branch.

Change-Id: I9cbe23f566410496d4ceb97c1435e2df7f2b56ec
2015-06-30 21:11:33 -07:00
Russ Cox
e8f2eb4349 cmd/compile: allow linker to drop string headers when not needed
Compiling a simple file containing a slice of 100,000 strings,
the size of the resulting binary dropped from 5,896,224 bytes
to 3,495,968 bytes, which is the expected 2,400,000 bytes,
give or take.

Fixes #7384.

Change-Id: I3e551b5a1395b523a41b33518d81a1bf28da0906
Reviewed-on: https://go-review.googlesource.com/11698
Reviewed-by: Austin Clements <austin@google.com>
2015-06-30 19:27:52 +00:00
Russ Cox
3b6e86f48a cmd/compile: fix race detector handling of OBLOCK nodes
Fixes #7561 correctly.
Fixes #9137.

Change-Id: I7f27e199d7101b785a7645f789e8fe41a405a86f
Reviewed-on: https://go-review.googlesource.com/11713
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2015-06-30 19:25:18 +00:00
Dmitry Vyukov
19b8aa3b5d cmd/compile/internal/gc: give OASWB name
Change-Id: Iacb84421215ca80c7add2818118b2af1a650fd58
Reviewed-on: https://go-review.googlesource.com/11639
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-30 15:51:59 +00:00
Russ Cox
1122836b5f cmd/compile: reject large floating point exponents without math/big
For #11326 (but not a fix).

Change-Id: Ic51814f5cd7357427c3fd990a5522775d05e7987
Reviewed-on: https://go-review.googlesource.com/11673
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-06-29 21:18:01 +00:00
Russ Cox
27edd7209e cmd/compile: enable PAUTO capture variables on arch != 6
Fixes #9865.

Change-Id: I8ce5b1708ed938910c59899706e470271c2e7e9d
Reviewed-on: https://go-review.googlesource.com/11699
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-29 19:49:18 +00:00
Russ Cox
55203c7dd5 cmd/compile: allow unnamed constants to set line number
Fixes #8836.

Change-Id: Idda9f4a987e03b3bdf5e8fdb984fe56d6f84aa59
Reviewed-on: https://go-review.googlesource.com/11672
Reviewed-by: David Chase <drchase@google.com>
2015-06-29 17:35:55 +00:00
Josh Bleecher Snyder
46815b9f62 [dev.ssa] cmd/compile/ssa: add comparison ops
Increase SSA coverage of functions in the
standard library from 20.79% to 27.81%.

The most significant unimplemented items are now:

 10.16%  2597 SSA unimplemented: zero for type error not implemented
  8.44%  2157 SSA unimplemented: addr: bad op DOTPTR
  7.98%  2039 SSA unimplemented: unhandled OLITERAL 7
  6.29%  1607 SSA unimplemented: unhandled expr OROR
  4.73%  1209 SSA unimplemented: unhandled expr LEN
  4.55%  1163 SSA unimplemented: unhandled expr LROT
  3.42%   874 SSA unimplemented: unhandled OLITERAL 6
  2.46%   629 SSA unimplemented: unhandled expr DOT
  2.41%   615 SSA unimplemented: zero for type []byte not implemented
  2.02%   516 SSA unimplemented: unhandled stmt CALLMETH
  1.90%   486 SSA unimplemented: unhandled expr ANDAND
  1.79%   458 SSA unimplemented: unhandled expr CALLINTER
  1.69%   433 SSA unimplemented: unhandled stmt SWITCH
  1.67%   428 SSA unimplemented: unhandled expr CALLMETH
  1.67%   426 SSA unimplemented: unhandled expr CLOSUREVAR

Change-Id: I40959b22993c4f70784b4eca472cae752347879c
Reviewed-on: https://go-review.googlesource.com/11452
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-29 16:26:35 +00:00
Josh Bleecher Snyder
1746e711ad [dev.ssa] cmd/compile/ssa: add nilcheckelim benchmarks
These benchmarks demonstrate that
the nilcheckelim pass is roughly O(n^2):

BenchmarkNilCheckDeep1    	 2000000	       741 ns/op	   1.35 MB/s
BenchmarkNilCheckDeep10   	 1000000	      2237 ns/op	   4.47 MB/s
BenchmarkNilCheckDeep100  	   20000	     60713 ns/op	   1.65 MB/s
BenchmarkNilCheckDeep1000 	     200	   7925198 ns/op	   0.13 MB/s
BenchmarkNilCheckDeep10000	       1	1220104252 ns/op	   0.01 MB/s

Profiling suggests that building the
dominator tree is also O(n^2),
and before size factors take over,
considerably more expensive than nilcheckelim.

Change-Id: If966b38ec52243a25f355dab871300d29db02e16
Reviewed-on: https://go-review.googlesource.com/11520
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-29 04:07:11 +00:00
Josh Bleecher Snyder
d9a704cd40 [dev.ssa] cmd/compile/ssa: refine type equality in cse
The correct way to compare gc.Types is Eqtype,
rather than pointer equality.
Introduce an Equal method for ssa.Type to allow
us to use it.

In the cse pass, use a type's string to build
the coarse partition, and then use Type.Equal
during refinement.

This lets the cse pass do a better job.
In the ~20% of the standard library that SSA
can compile, the number of common subexpressions
recognized by the cse pass increases from
27,550 to 32,199 (+17%). The number of nil checks
eliminated increases from 75 to 115 (+50%).

Change-Id: I0bdbfcf613ca6bc2ec987eb19b6b1217b51f3008
Reviewed-on: https://go-review.googlesource.com/11451
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-29 03:27:30 +00:00
Keith Randall
dbd83c4464 [dev.ssa] cmd/compile/internal/gc: Fix constant shift generation
Change-Id: Ib142185de3f6e4d2f4983511c063492529d8fb8a
Reviewed-on: https://go-review.googlesource.com/11656
Reviewed-by: Michael Matloob <michaelmatloob@gmail.com>
2015-06-29 02:10:44 +00:00
Russ Cox
32fddadd98 runtime: reduce slice growth during append to 2x
The new inlined code for append assumed that it could pass the
desired new cap to growslice, not the number of new elements.
But growslice still interpreted the argument as the number of new elements,
making it always grow by >2x (more precisely, 2x+1 rounded up
to the next malloc block size). At the time, I had intended to change
the other callers to use the new cap as well, but it's too late for that.
Instead, introduce growslice_n for the old callers and keep growslice
for the inlined (common case) caller.

Fixes #11403.

Filed #11419 to merge them.

Change-Id: I1338b1e5b352f3be4e43641f44b652ef7195251b
Reviewed-on: https://go-review.googlesource.com/11541
Reviewed-by: Austin Clements <austin@google.com>
2015-06-26 17:49:33 +00:00
Todd Neal
765c0f37ed cmd/compile: fix half multiply issue
In walkdiv, an OMUL node was created and passed to typecheck,
before the op was changed back to OHMUL.  In some instances,
the node that came back was an evaluated literal constant that
occurred with a full multiply.  The end result was a literal node
with a non-shifted value and an OHMUL op. This change causes code
to be generated for the OHMUL.

Fixes #11358
Fixes #11369

Change-Id: If42a98c6830d07fe065d5ca57717704fb8cfbd33
Reviewed-on: https://go-review.googlesource.com/11400
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-26 15:55:22 +00:00
Dmitry Vyukov
cd0a8ed48a cmd/compile: add instrumentation of OKEY
Instrument operands of OKEY.
Also instrument OSLICESTR. Previously it was not needed
because of preceeding bounds checks (which were instrumented).
But the preceeding bounds checks have disappeared.

Change-Id: I3b0de213e23cbcf5b8ef800abeded5eeeb3f8287
Reviewed-on: https://go-review.googlesource.com/11417
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-26 15:54:03 +00:00
Keith Randall
7b858018b3 [dev.ssa] cmd/compile/internal/gc: Interpret init list of OFOR conditions
Fixes build.  Some variables are initialized in this list.

Q: How do we tell that we've included all the required Ninit lists?

Change-Id: I96b3f03c291440130303a2b95a651e97e4d8113c
Reviewed-on: https://go-review.googlesource.com/11542
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-26 04:08:44 +00:00
Todd Neal
929c2aa2ae [dev.ssa] cmd/compile/ssa: fix unit tests
Fix out of bounds array panic due to CL 11238.

Change-Id: Id8a46f1ee20cb1f46775d0c04cc4944d729dfceb
Reviewed-on: https://go-review.googlesource.com/11540
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-26 02:25:57 +00:00
Keith Randall
8c46aa5481 [dev.ssa] cmd/compile/internal/ssa: Handle variables correctly
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-25 17:54:18 +00:00
Keith Randall
dbe9ab69d9 cmd/compile/internal/gc: make sure nonzero-sized objects have nonzero alignment
See issue #11354.

Change-Id: I6817d499e6c02e4a9c83f80bc66a2bee368a69ec
Reviewed-on: https://go-review.googlesource.com/11406
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-25 02:22:58 +00:00
Russ Cox
66130907d1 cmd/compile: handle copy in escape analysis
Somehow we missed this!
Fixes #11387.

Change-Id: Ida08fe52eff7da2ef7765b4cf35a39a301420c43
Reviewed-on: https://go-review.googlesource.com/11460
Reviewed-by: David Chase <drchase@google.com>
2015-06-24 22:22:55 +00:00
Josh Bleecher Snyder
37ddc270ca [dev.ssa] cmd/compile/ssa: add -f suffix to logging methods
Requested in CL 11380.

Change-Id: Icf0d23fb8d383c76272401e363cc9b2169d11403
Reviewed-on: https://go-review.googlesource.com/11450
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-24 21:48:26 +00:00
Josh Bleecher Snyder
d779b20cd2 [dev.ssa] cmd/compile/ssa: improve comments, logging, and debug output
Change-Id: Id949db82ddaf802c1aa245a337081d4d46fd914f
Reviewed-on: https://go-review.googlesource.com/11380
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-24 20:44:57 +00:00
Josh Bleecher Snyder
44be0e9c60 [dev.ssa] cmd/compile/ssa: fix build
Somehow I missed this in CL 11160.
Without it, all.bash fails on fixedbugs/bug303.go.

The right fix is probably to discard the variable
and keep going, even though the code is dead.

For now, defer the decision by declaring
such situations unimplemented and get the build
fixed.

Change-Id: I679197f780c7a3d3eb7d05e91c86a4cdc3b70131
Reviewed-on: https://go-review.googlesource.com/11440
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-24 20:32:11 +00:00
Josh Bleecher Snyder
2a846d2bd3 [dev.ssa] cmd/compile/ssa: add nilcheckelim pass
The nilcheckelim pass eliminates unnecessary nil checks.
The initial implementation removes redundant nil checks.
See the comments in nilcheck.go for ideas for future
improvements.

The efficacy of the cse pass has a significant impact
on this efficacy of this pass.

There are 886 nil checks in the parts of the standard
library that SSA can currently compile (~20%).

This pass eliminates 75 (~8.5%) of them.

As a data point, with a more aggressive but unsound
cse pass that treats many more types as identical,
this pass eliminates 115 (~13%) of the nil checks.

Change-Id: I13e567a39f5f6909fc33434d55c17a7e3884a704
Reviewed-on: https://go-review.googlesource.com/11430
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-06-24 19:56:51 +00:00
Josh Bleecher Snyder
8c6abfeacb [dev.ssa] cmd/compile/ssa: separate logging, work in progress, and fatal errors
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-21 02:56:36 +00:00
Russ Cox
7bcc6a1615 cmd/compile: add -importmap option
The -importmap option takes an argument of the form old=new
and specifies that import "old" should be interpreted as if it said
import "new". The option may be repeated to specify multiple mappings.

This option is here to support the go command's new -vendor flag.

Change-Id: I31b4ed4249b549982a720bf61bb230462b33c59b
Reviewed-on: https://go-review.googlesource.com/10922
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-19 18:50:12 +00:00
Michael Matloob
32f2f72c47 cmd/compile: provide better error when method called without receiver
When a method is called using the Type.Method(receiver, args...) syntax
without the receiver, or enough arguments, provide the more helpful
error message "not enough arguments in call to method expression
Type.Method" instead of the old message "not enough arguments in call
to Type.Method".

Fixes #8385

Change-Id: Id5037eb1ee5fa93687d4a6557b4a8233b29e9df2
Reviewed-on: https://go-review.googlesource.com/2193
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-18 19:37:38 +00:00
Russ Cox
08e25fc1ba cmd/compile: introduce //go:systemstack annotation
//go:systemstack means that the function must run on the system stack.

Add one use in runtime as a demonstration.

Fixes #9174.

Change-Id: I8d4a509cb313541426157da703f1c022e964ace4
Reviewed-on: https://go-review.googlesource.com/10840
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
2015-06-17 14:23:00 +00:00
Michael Matloob
2aabacdb5a [dev.ssa] cmd/compile/internal/gc: support CALLFUNC as statement
I don't have strong understanding of the AST structure, so I'm
not sure if this is the right way to handle function call statements.

Change-Id: Ib526f667ab483b32d9fd17da800b5d6f4b26c4c9
Reviewed-on: https://go-review.googlesource.com/11139
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-17 03:34:34 +00:00
David Chase
5be61b18d4 cmd/compile: run escape analysis after method wrapper generation
Also modified test/run.go to ignore messages prefixed <autogenerated>
because those cannot be described with "// ERROR ...", and backed out
patch from issue #9537 because it is no longer necessary.  The reasons
described in the 9537 discussion for why escape analysis cannot run
late no longer hold, happily.

Fixes #11053.

Change-Id: Icb14eccdf2e8cde3d0f8fb8a216b765400a96385
Reviewed-on: https://go-review.googlesource.com/11088
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: David Chase <drchase@google.com>
2015-06-17 02:36:45 +00:00
Michael Matloob
73054f5729 [dev.ssa] cmd/compile/internal/ssa: adds for 8,16,32 bit ints
Change-Id: I33025a4a41fd91f6ee317d33a6eebf27fa00ab51
Reviewed-on: https://go-review.googlesource.com/11115
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-17 00:13:58 +00:00
Michael Matloob
0991ec454b [dev.ssa] cmd/compile/internal/ssa: set line in newValue variants
This CL sets line numbers on Values in the newValue variants
introduced in cl/10929.

Change-Id: Ibd15bc90631a1e948177878ea4191d995e8bb19b
Reviewed-on: https://go-review.googlesource.com/11090
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-17 00:12:24 +00:00
Josh Bleecher Snyder
a5c3b6642b [dev.ssa] cmd/compile/ssa: fix string compilation
Compilation of f_ssa was broken by CL 10929.

This CL does not include tests because
I have a work in progress CL that will catch
this and much more.

package p

func f_ssa() string {
	return "ABC"
}

Change-Id: I0ce0e905e4d30ec206cce808da406b9b7f0f38e9
Reviewed-on: https://go-review.googlesource.com/11136
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-16 23:38:59 +00:00
Keith Randall
50ceef26e6 [dev.ssa] cmd/compile/internal/ssa: Fix bootstrap of ssa codegen
The cmd/compile/internal/ssa/gen directory can't depend on cmd/internal/gc
because that package doesn't exist in go1.4.  Use strings instead of
constants from that package.

The asm fields seem somewhat redundant to the opcode names we
conventionally use.  Maybe we can just trim the lowercase from the end
of the op name?  At least by default?

Change-Id: I96e8cda44833763951709e2721588fbd34580989
Reviewed-on: https://go-review.googlesource.com/11129
Reviewed-by: Michael Matloob <michaelmatloob@gmail.com>
2015-06-16 21:28:21 +00:00
Michael Matloob
703ef06039 [dev.ssa] cmd/compile/internal/gc: reduce genValue redundancy
Add an asm field to opcodeTable containing the Prog's as field.
Then instructions that fill the Prog the same way can be collapsed
into a single switch case.

I'm still thinking of a better way to reduce redundancy, but
I think this might be a good temporary solution to prevent duplication
from getting out of control. What do you think?

Change-Id: I0c4a0992741f908bd357ee2707edb82e76e4ce61
Reviewed-on: https://go-review.googlesource.com/11130
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-16 19:37:59 +00:00
Shenghou Ma
d00e7ad640 cmd/compile: show compiler panics when -d panic=1
Fixes #10683.

Change-Id: I4cce3f298b787c736dbabe544a11a9215bcd3671
Reviewed-on: https://go-review.googlesource.com/10336
Reviewed-by: Russ Cox <rsc@golang.org>
2015-06-16 16:50:21 +00:00
Russ Cox
80ec711755 runtime: use type-based write barrier for remote stack write during chansend
A send on an unbuffered channel to a blocked receiver is the only
case in the runtime where one goroutine writes directly to the stack
of another. The garbage collector assumes that if a goroutine is
blocked, its stack contains no new pointers since the last time it ran.
The send on an unbuffered channel violates this, so it needs an
explicit write barrier. It has an explicit write barrier, but not one that
can handle a write to another stack. Use one that can (based on type bitmap
instead of heap bitmap).

To make this work, raise the limit for type bitmaps so that they are
used for all types up to 64 kB in size (256 bytes of bitmap).
(The runtime already imposes a limit of 64 kB for a channel element size.)

I have been unable to reproduce this problem in a simple test program.

Could help #11035.

Change-Id: I06ad994032d8cff3438c9b3eaa8d853915128af5
Reviewed-on: https://go-review.googlesource.com/10815
Reviewed-by: Austin Clements <austin@google.com>
2015-06-15 16:50:30 +00:00
Daniel Morsing
3b817ef8f8 [dev.ssa] fix equivalence class after aux/auxint refactor.
This caused the following code snippet to be miscompiled

	var f int
	x := g(&f)
	f = 10

Moving the store of 10 above the function call.

Change-Id: Ic6951f5e7781b122cd881df324a38e519d6d66f0
Reviewed-on: https://go-review.googlesource.com/11073
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-15 12:06:05 +00:00
Daniel Morsing
c31b6dd0be [dev.ssa] initial implementation of PAUTO|PHEAP variables
Call to the runtime to generate escaping variables and use the returned
address when accessing these variables.

Fix a couple of errors on the way. The rule for CALLstatic was missed
during the Aux refactor and OCONVNOP wasn't converted.

Change-Id: I2096beff92cca92d648bfb6e8ec0b120f02f44af
Reviewed-on: https://go-review.googlesource.com/11072
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-14 20:01:03 +00:00
Michael Matloob
ea5cd68646 [dev.ssa] cmd/compile/internal/gc: fix call to newValue1
Change-Id: I235a759e4688358adc088cf5a80f8ce7ad12d2f2
Reviewed-on: https://go-review.googlesource.com/11093
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-14 17:36:24 +00:00
Michael Matloob
3a0df1f82a [dev.ssa] cmd/compile/internal/ssa: set Line in NewValue funcs
In the previous line number CL the NewValue\d? functions took
a line number argument but neglected to set the Line field on
the value struct. Fix that.

Change-Id: I53c79ff93703f66f5f0266178c94803719ae2074
Reviewed-on: https://go-review.googlesource.com/11054
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-14 16:46:01 +00:00
Michael Matloob
47791c1a18 [dev.ssa] cmd/compile/internal/gc: generate TESTQ instruction
TESTQ is produced by the IsNonNil lowering.

Change-Id: I9df8f17e6def7e34d07e3ddf2dd5dd8f0406aa04
Reviewed-on: https://go-review.googlesource.com/11053
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-14 16:45:20 +00:00
Daniel Morsing
2efdaefdb0 [dev.ssa] Protect control value from being moved away from end of block
If there isn't a value dependency between the control value of a
block and some other value, the schedule pass might move the control
value to a spot that is not EOB. Fix by handling the control value
specially like phis.

Change-Id: Iddaf0924d98c5b3d9515c3ced927b0c85722818c
Reviewed-on: https://go-review.googlesource.com/11071
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-14 16:40:40 +00:00
Keith Randall
8f22b5292f [dev.ssa] cmd/compiler/internal/ssa: Add auxint field
Add an additional int64 auxiliary field to Value.

There are two main reasons for doing this:
1) Ints in interfaces require allocation, and we store ints in Aux a lot.
2) I'd like to have both *gc.Sym and int offsets included in lots
   of operations (e.g. MOVQloadidx8).  It will be more efficient to
   store them as separate fields instead of a pointer to a sym/int pair.

It also simplifies a bunch of code.

This is just the refactoring.  I'll start using this some more in a
subsequent changelist.

Change-Id: I1ca797ff572553986cf90cab3ac0a0c1d01ad241
Reviewed-on: https://go-review.googlesource.com/10929
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-14 06:00:30 +00:00
Keith Randall
0ad9c8c720 [dev.ssa] cmd/compile/internal/gc: Small fixes
Allow labels to be unreachable via fallthrough from above.
Implement OCONVNOP.

Change-Id: I6869993cad8a27ad134dd637de89a40117daf47b
Reviewed-on: https://go-review.googlesource.com/11001
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2015-06-14 03:56:47 +00:00
Daniel Morsing
d5ad9ced1c [dev.ssa] clarify ODCL todo, remove irrelevant colas todo
ODCL nodes are used as the point where the variable is allocated in
the old pass. colas is irrelevant at this point of the compile. All
the checks on it happen at parse time and an ODCL node will have been
inserted right before it.

Change-Id: I1aca053aaa4363bacd12e1156de86fa7b6190a55
Reviewed-on: https://go-review.googlesource.com/10901
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-12 09:24:08 +00:00
Josh Bleecher Snyder
ba8a146af4 [dev.ssa] cmd/compile/ssa: print reg names in generated code
Change-Id: I6c6196449dd3d5e036d420fa7ae90feb0cf8d417
Reviewed-on: https://go-review.googlesource.com/10928
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-12 03:40:13 +00:00
Keith Randall
e707fbe1d7 [dev.ssa] Merge remote-tracking branch 'origin/master' into mbranch
Semi-regular merge of tip into dev.ssa.

Change-Id: Iec8e4266426bed233892e7dbe4448d16c8b89018
2015-06-11 11:06:21 -07:00
Ainar Garipov
7f9f70e5b6 all: fix misprints in comments
These were found by grepping the comments from the go code and feeding
the output to aspell.

Change-Id: Id734d6c8d1938ec3c36bd94a4dbbad577e3ad395
Reviewed-on: https://go-review.googlesource.com/10941
Reviewed-by: Aamir Khan <syst3m.w0rm@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-11 14:18:57 +00:00
Keith Randall
6f1884757f [dev.ssa] cmd/compile/internal/ssa: Complete 64-bit shifts
Implement correct Go shifts.

Allow multi-line rewrite rules.

Fix offset & alignment in stack alloc.

Change-Id: I0ae9e522c83df9205bbe4ab94bc0e43d16dace58
Reviewed-on: https://go-review.googlesource.com/10891
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-11 03:54:06 +00:00
Keith Randall
290d8fc14a [dev.ssa] cmd/compile/internal/ssa: add call opcodes
Add calls, particularly closure calls.

Reorg SSAable variable test for converting to SSA.

Change-Id: Ia75c04295e6b0b040122f97e2381836a393b7f42
Reviewed-on: https://go-review.googlesource.com/10912
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-11 03:10:01 +00:00
Michael Matloob
81ccf508aa [dev.ssa] cmd/compile/internal/ssa: add line numbers to Values
Change-Id: I1dfffd75cc1f49307c654f910f7133c03da6c84f
Reviewed-on: https://go-review.googlesource.com/10559
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-10 15:01:13 +00:00
Josh Bleecher Snyder
442959ec47 cmd/compile: fix builtin generation
This was a refactoring bug during
'go tool compile', CL 10289.

Change-Id: Ibfd333be39ec72bba331fdf352df619cc21851a9
Reviewed-on: https://go-review.googlesource.com/10849
Reviewed-by: Minux Ma <minux@golang.org>
2015-06-09 21:26:39 +00:00
Josh Bleecher Snyder
a44becef4a cmd/compile: use generated temps in bool codegen
Bool codegen was generating a temp for function calls
and other complex expressions, but was not using it.

This was a refactoring bug introduced by CL 7853.
The cmp code used to do (in short):

	l, r := &n1, &n2

It was changed to:

	l, r := nl, nr

But the requisite assignments:

	nl, nr = &n1, &n2

were only introduced on one of two code paths.

Fixes #10654.

Change-Id: Ie8de0b3a333842a048d4308e02911bb10c6915ce
Reviewed-on: https://go-review.googlesource.com/10844
Reviewed-by: Minux Ma <minux@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-09 17:38:26 +00:00
Michael Matloob
43a2676ff0 [dev.ssa] cmd/compile/internal/ssa: delete lowergeneric.go
It's been replaced by rewritegeneric.go

Change-Id: I2658abbc6201ecfedae4513c6da04ea3cac8bb9c
Reviewed-on: https://go-review.googlesource.com/10846
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-09 15:29:12 +00:00
Josh Bleecher Snyder
494ff188f8 cmd/compile: early typecheck top level OAS2 nodes
Fixes #10977.

Change-Id: I706c953c16daad48595c7fae2d82124614dfc3ad
Reviewed-on: https://go-review.googlesource.com/10780
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-09 00:25:02 +00:00
Keith Randall
0dca7351e9 [dev.ssa] cmd/compile/internal/ssa: autogenerate opcodes
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-06-08 21:02:03 +00:00
Michael Matloob
6241a41e33 [dev.ssa] cmd/compile/internal/ssa: enforce single live mem
Change-Id: I21edff280a283895e4f0cbf91a3b4406f2f86788
Reviewed-on: https://go-review.googlesource.com/10558
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-08 20:12:40 +00:00
Austin Clements
9389a86b01 cmd/compile: use obj.ARET instead of ppc64.ARETURN
obj.ARET is the portable return mnemonic. ppc64.ARETURN is a legacy
alias.

This was done with
    sed -i s/ppc64\.ARETURN/obj.ARET/ cmd/compile/**/*.go
    sed -i s/ARETURN/obj.ARET/ cmd/internal/obj/ppc64/obj9.go

Change-Id: I4d8e83ff411cee764774a40ef4c7c34dcbca4e43
Reviewed-on: https://go-review.googlesource.com/10673
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
2015-06-06 00:07:31 +00:00
Michael Matloob
c8285bb501 [dev.ssa] cmd/compile/internal/ssa: add missing copyright notices
Change-Id: I9d4e0f3e9afc9920ee0d77b0073ac8597c7c048f
Reviewed-on: https://go-review.googlesource.com/10756
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-05 17:19:05 +00:00
Russ Cox
cd9f417dbb cmd/compile: document Node fields used by each Op
Change-Id: If969d7a06c83447ee38da30f1477a6cf4bfa1a03
Reviewed-on: https://go-review.googlesource.com/10691
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-05 05:01:24 +00:00
Russ Cox
630930c35e cmd/compile, cmd/link: add docs
These are the Go 1.4 docs but refreshed for Go 1.5.
The most sigificant change is that all references to the Plan 9 toolchain are gone.
The tools no longer bear any meaningful resemblance.

Change-Id: I44f5cadb832a982323d7fee0b77673e55d761b35
Reviewed-on: https://go-review.googlesource.com/10298
Reviewed-by: Rob Pike <r@golang.org>
2015-06-05 04:42:35 +00:00
Josh Bleecher Snyder
e00d60901a [dev.ssa] cmd/compile/internal/ssa: minor fixes
* Improve some docs and logging.
* Set correct type and len for indexing into strings.

Fixes #11029.

Change-Id: Ib22c45908e41ba3752010d2f5759e37e3921a48e
Reviewed-on: https://go-review.googlesource.com/10635
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-04 23:13:45 +00:00
Keith Randall
8d32360bdd [dev.ssa] cmd/internal/ssa: add deadstore pass
Eliminate dead stores.  Dead stores are those which are
unconditionally followed by another store to the same location, with
no intervening load.

Just a simple intra-block implementation for now.

Change-Id: I2bf54e3a342608fc4e01edbe1b429e83f24764ab
Reviewed-on: https://go-review.googlesource.com/10386
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-04 23:03:41 +00:00
Keith Randall
1114a76ae6 [dev.ssa] cmd/compile/internal/ssa: Add dummy frontend for testing.
Change-Id: Ica26c0297ac7afeb0b5b668cf5f5cd1667c6cc43
Reviewed-on: https://go-review.googlesource.com/10699
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-04 22:26:22 +00:00
Keith Randall
f7f604e284 [dev.ssa] cmd/internal/ssa: add string operations
Add ops to load, store, select ptr & len, and build constant strings.
A few other minor cleanups.

Change-Id: I6f0f7419d641b119b613ed44561cd308a466051c
Reviewed-on: https://go-review.googlesource.com/10449
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-04 22:00:27 +00:00
Russ Cox
81d5810be9 cmd/compile: merge Node.Opt and Node.Val behind access methods
$ sizeof -p cmd/compile/internal/gc Node
Node 144
$

Change-Id: I688e3790964fe42f48c19f697ec38094a92fe1c1
Reviewed-on: https://go-review.googlesource.com/10531
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-04 03:58:41 +00:00
Russ Cox
a53710ffcb cmd/compile: cleanups for Node trimming sequence
Suggested during code reviews of last 15 CLs (or so).

Change-Id: If780f6eb47a7a31df133c64d5dcf0eaf04d8447b
Reviewed-on: https://go-review.googlesource.com/10675
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-04 03:58:27 +00:00
Russ Cox
73d109c509 cmd/internal/gc: accept map literals with omitted key type
Fixes #10209.

Change-Id: I248434f9195c868befd1ed8a6000a9cac72d1df8
Reviewed-on: https://go-review.googlesource.com/10263
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-04 02:31:38 +00:00
Robert Griesemer
1e48683708 src/cmd/compile/internal/gc: re-vendor math/big, manually adjust mparith3.go
The only unreviewed change is in mparith3.go.

Change-Id: Iec0885e7688981cbaed04c152dc9b1c7032677e6
Reviewed-on: https://go-review.googlesource.com/10665
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
2015-06-03 22:28:06 +00:00
Russ Cox
0f6da8923f cmd/internal/gc: add -buildid flag to write build ID into object file
The build ID is an opaque token supplied by the build system.
The compiler writes it out early in the Go export metadata
(the second line), in a way that does not bother existing readers.

The intent is that the go command can use this to store information
about the sources for the generated code, so that it can detect
stale packages even in cases (like removed files) where mtimes fail.

Change-Id: Ib5082515d6cde8a07a8d4b5c69d1e8e4190cb5e1
Reviewed-on: https://go-review.googlesource.com/9153
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-03 20:43:51 +00:00
Russ Cox
3be7f28e82 cmd/compile: remove Node.Nname, now unused
$ sizeof -p cmd/compile/internal/gc Node
Node 160
$

Change-Id: Ib0bd4230c8547f36972b2a9d81ba3eca81496e39
Reviewed-on: https://go-review.googlesource.com/10537
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:11:25 +00:00
Russ Cox
f1f0eda446 cmd/compile: remove use of Node.Nname in initplan
$ sizeof -p cmd/compile/internal/gc Node
Node 168
$

Change-Id: Ie7e2cee8cec101560bd5dd013b23969278f89b12
Reviewed-on: https://go-review.googlesource.com/10536
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:10:42 +00:00
Russ Cox
da094f19f1 cmd/compile: move OCASE/OXCASE Node.Nname into Node.Rlist (type switch variable)
$ sizeof -p cmd/compile/internal/gc Node
Node 168
$

Change-Id: I22bcea8099f308298c9db75c937f35e7fca906f1
Reviewed-on: https://go-review.googlesource.com/10535
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:10:31 +00:00
Russ Cox
bd4fff6358 cmd/compile: move ODCLFUNC Node.Nname into Node.Func.Nname
$ sizeof -p cmd/compile/internal/gc Node
Node 168
$

Change-Id: I7decd950fe068c0f294c6c9bff07ef809c394429
Reviewed-on: https://go-review.googlesource.com/10534
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:10:17 +00:00
Russ Cox
8f4d964641 cmd/compile, cmd/internal: replace %P with %v in a few final prints
$ sizeof -p cmd/compile/internal/gc Node
Node 168
$

Change-Id: I1e2f17bfee0e6ca7213706c4cef8d990f4461915
Reviewed-on: https://go-review.googlesource.com/10533
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:10:03 +00:00
Russ Cox
fd2154f906 cmd/compile: move Node.Curfn into both Node.Func and Node.Name
$ sizeof -p cmd/compile/internal/gc Node
Node 168
$

Change-Id: If624a2d72ec04ef30a1bc7ce76c0d61a526d8a37
Reviewed-on: https://go-review.googlesource.com/10532
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-03 20:09:52 +00:00
Russ Cox
3c3019aa51 cmd/compile: move Node.Param, Node.Funcdepth into Node.Name; remove Node.Walkgen
$ sizeof -p cmd/compile/internal/gc Node
Node 176
$

Change-Id: Ibf1ab531a60d4af8a0c242c0e504f4fd50cd5b36
Reviewed-on: https://go-review.googlesource.com/10530
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:09:41 +00:00
Russ Cox
11322d45a1 cmd/compile: move Node.Vargen, Node.Iota into Node.Name
$ sizeof -p cmd/compile/internal/gc Node
Node 192
$

Change-Id: I8f0c1a3cc2bf9c8eff02bbd8d061ff98affc9eb0
Reviewed-on: https://go-review.googlesource.com/10529
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:09:20 +00:00
Russ Cox
3007e953d0 cmd/compile: remove Node.Escflowsrc, Node.Escretval, Node.Escloopdepth, Node.Esclevel
$ sizeof -p cmd/compile/internal/gc Node
Node 200
$

Change-Id: Iba4e88eac6bee3e2349e818a5a2326deabcb96f9
Reviewed-on: https://go-review.googlesource.com/10528
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:08:30 +00:00
Russ Cox
ac2bda1b00 cmd/compile: move Node.Pkg to Node.Name.Pkg
$ sizeof -p cmd/compile/internal/gc Node
Node 224
$

Change-Id: Id0969e8df99c43a5f6f8d77a38f20a71a467e7c6
Reviewed-on: https://go-review.googlesource.com/10527
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 20:07:22 +00:00
Russ Cox
140ef3c59a cmd/compile: move Node.Pack to Node.Name.Pack
$ sizeof -p cmd/compile/internal/gc Node
Node 232
$

Change-Id: I4be025f4ec11f882f24ae7582821d36d3b122b77
Reviewed-on: https://go-review.googlesource.com/10526
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-06-03 19:50:26 +00:00
Russ Cox
60e5f5bdff cmd/compile: remove Node.Alloc
$ sizeof -p cmd/compile/internal/gc Node
Node 240
$

Change-Id: Id12710c480ed4e0a5bf4f5006f6bd56ef91a2af1
Reviewed-on: https://go-review.googlesource.com/10525
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 17:50:52 +00:00
Russ Cox
71080fbb9e cmd/compile: remove Val.Ctype
$ sizeof -p cmd/compile/internal/gc Node
Node 248
$

Change-Id: I0fbfeb0d0b36e225eb282fce9e480a96ec1d278f
Reviewed-on: https://go-review.googlesource.com/10524
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 17:50:42 +00:00
Russ Cox
4fdd53680c cmd/compile: move Node.Defn to Node.Name.Defn
$ sizeof -p cmd/compile/internal/gc Node
Node 256
$

Change-Id: I89ac8bbe077664aa076092bfd096947e84c0624c
Reviewed-on: https://go-review.googlesource.com/10523
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 17:50:35 +00:00
Russ Cox
496ad0a286 cmd/compile: move Node.Paramfld to Node.Param.Field
$ sizeof -p cmd/compile/internal/gc Node
Node 264
$

Change-Id: I5c90089dcf5df51c874250f28a1bc3ec32f764b9
Reviewed-on: https://go-review.googlesource.com/10522
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 17:50:28 +00:00
Russ Cox
66be1481df cmd/compile: remove Node.Ntest, Node.Stkdelta
$ sizeof -p cmd/compile/internal/gc Node
Node 272
$

Change-Id: I3d9b67eebfc0be0a4b9768d3de3dc76300abd89c
Reviewed-on: https://go-review.googlesource.com/10521
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 17:50:19 +00:00
Russ Cox
ffef180f82 cmd/compile: remove Node.Nincr, Node.Nelse, Node.Initplan
$ sizeof -p cmd/compile/internal/gc Node
Node 288
$

Change-Id: I4e316efa246132b3faa3a892e4fe9c9039250665
Reviewed-on: https://go-review.googlesource.com/10520
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-06-03 17:50:11 +00:00
Michael Matloob
bd95412d23 [dev.ssa] cmd/compile/internal/ssa: add a String() method to Func
The string method has the same output as printFunc.

Change-Id: Iab2ebc17a3d6418edfeb7b585e4f251e7a11f399
Reviewed-on: https://go-review.googlesource.com/10552
Reviewed-by: Keith Randall <khr@golang.org>
2015-06-03 04:35:55 +00:00
Keith Randall
a9cec30fdc [dev.ssa] cmd/compile/internal/ssa: Implement block rewriting rules
Change-Id: I47e5349e34fc18118c4d35bf433f875b958cc3e5
Reviewed-on: https://go-review.googlesource.com/10495
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-30 06:08:26 +00:00
Keith Randall
b0da62903d [dev.ssa] cmd/compile/internal/ssa: Add code to test generated opcode counts
Add test handler to count and check generated opcodes.  This will be
useful for testing that certain optimizations don't regress.

Also pass a *Config to the Fun constructor so that compile() works.

Change-Id: Iee679e87cf0bc635ddcbe433fc1bd4c1d9c953cc
Reviewed-on: https://go-review.googlesource.com/10502
Reviewed-by: Michael Matloob <michaelmatloob@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2015-05-30 05:09:59 +00:00
Michael Matloob
7bdecbf840 [dev.ssa] cmd/compile/internal/ssa: remove cgen pass
Code generation is now done in genssa.
Also remove the asm field in opInfo. It's no longer used.

Change-Id: I65fffac267e138fd424b2ef8aa7ed79f0ebb63d5
Reviewed-on: https://go-review.googlesource.com/10539
Reviewed-by: Keith Randall <khr@golang.org>
2015-05-29 18:54:49 +00:00
Russ Cox
c413c45e6d cmd/internal/obj: make Prog.From3 a pointer
It is almost never set and Addr is large, so having the full struct
in the Prog wastes memory most of the time.

Before (on a 64-bit system):

$ sizeof -p cmd/internal/obj Addr Prog
Addr 80
Prog 376
$

After:

$ sizeof -p cmd/internal/obj Addr Prog
Addr 80
Prog 304
$

Change-Id: I491f201241f87543964a7d0f48b85830759be9d0
Reviewed-on: https://go-review.googlesource.com/10457
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-05-29 16:19:02 +00:00
Keith Randall
067e8dfd82 [dev.ssa] Merge remote-tracking branch 'origin/master' into mergebranch
Semi-regular merge of tip to dev.ssa.

Complicated a bit by the move of cmd/internal/* to cmd/compile/internal/*.

Change-Id: I1c66d3c29bb95cce4a53c5a3476373aa5245303d
2015-05-28 13:51:18 -07:00
David Chase
596bb76248 cmd/compile: reject p-notation floats in Go source files
Use pkgimport == nil (or not) to distinguish between
parsing .go source files where "p" exponent specifier
is not allowed and parsing .a or .o export data where
it is.  Use that to control error when p-exponent is
seen.

Fixes #9036

Change-Id: I8924f09c91d4945ef3f20e80a6e544008a94a7e4
Reviewed-on: https://go-review.googlesource.com/10450
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-28 18:52:14 +00:00
Josh Bleecher Snyder
bd8bb67357 cmd/internal/gc: unembed Param field
This is an automated follow-up to CL 10210.
It was generated with a combination of eg and gofmt -r.

No functional changes. Passes toolstash -cmp.

Change-Id: I35f5897948a270b472d8cf80612071b4b29e9a2b
Reviewed-on: https://go-review.googlesource.com/10253
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-05-28 17:46:52 +00:00
Austin Clements
f90d802b61 cmd/compile: avoid temporary in race mode with slice and append
Currently when the race detector is enabled, orderexpr always creates
a temporary for slice and append operations. This used to be necessary
because the race detector had a different code path for slice
assignment that required this temporary. Unfortunately, creating this
temporary inhibits the optimization that eliminates write barriers
when a slice is assigned only to change its length or cap. For most
code, this is bad for performance, and in go:nowritebarrier functions
in the runtime, this can mean the difference between compiling and not
compiling.

Now the race detector uses the regular slice assignment code, so
creating this temporary is no longer necessary.

Change-Id: I296042e1edc571b77c407f709c2ff9091c4aa795
Reviewed-on: https://go-review.googlesource.com/10456
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-28 17:39:26 +00:00
Shenghou Ma
0f27b91522 cmd/internal/obj: make arm64 use RegTo2 instead of a full fledged Addr To2
It shrinks Prog type from 448 bytes down to 376 bytes on amd64.

It also makes sense, because I don't know of any modern architecture
that have instructions which can write to two destinations, none of
which is a register (even x86 doesn't have such instructions).

Change-Id: I3061f1c9ac93d79ee2b92ecb9049641d0e0f6300
Reviewed-on: https://go-review.googlesource.com/10330
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-28 01:09:38 +00:00
David Chase
05d8f1d166 cmd/compile: propagate correct line numbers in treecopy
Added a lineno parameter to treecopy and listtreecopy
(ignored if = 0).  When nodes are copied the copy is
assigned the non-zero lineno (normally this would be
the destination).

Fixes #8183

Change-Id: Iffb767a745093fb89aa08bf8a7692c2f0122be98
Reviewed-on: https://go-review.googlesource.com/10334
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-27 17:29:15 +00:00
Russ Cox
972a478ddf cmd/compile: don't cater to race detector in write barriers
The new lower-level barriers work fine and don't need special handling,
because they appear to the race detector as (visible) ordinary assignments.

Change-Id: I7477d73a3deecbebf68716580678c595cc4151e3
Reviewed-on: https://go-review.googlesource.com/10316
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-05-26 13:50:08 +00:00
Robert Griesemer
1893d3b320 cmd/compile/internal/big: update and apply vendor.bash
Package-external tests must use the vendored math/big package, not
the original one, otherwise tests may fail if there are discrepancies
in the implementation.

Change-Id: Ic5f0489aa6420ffea1f488633453f871ce1f0f66
Reviewed-on: https://go-review.googlesource.com/10380
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-05-22 22:46:44 +00:00
Robert Griesemer
75250a9f79 cmd/compile/internal/gc: simplify mpgetflt (remove switch and indirection)
Change-Id: I6ae3534defdae9367e1b856dbb8e846c3263a758
Reviewed-on: https://go-review.googlesource.com/10358
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-22 21:23:04 +00:00
Robert Griesemer
bd7c1f1fb3 cmd/compile/internal/gc: correctly use Float32 in mpgetfltN
This resolves the compiler part of issue #10321.

Change-Id: I44b9909f992b37dd34b1c5292decd12de3d3a65e
Reviewed-on: https://go-review.googlesource.com/10355
Reviewed-by: Alan Donovan <adonovan@google.com>
2015-05-22 21:20:14 +00:00
Robert Griesemer
db0594b633 cmd/compile/internal/big: update to latest version (run sh vendor.bash)
No manual code changes.

This will permit addressing the compiler aspect of issue #10321 in a
subsequent change.

Change-Id: I3376dc38cafa0ec98bf54de33293015d0183cc82
Reviewed-on: https://go-review.googlesource.com/10354
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-05-22 21:16:02 +00:00
David Chase
e5060c7f75 cmd/internal/gc: move check for large-hence-heap-allocated types into escape analysis
Before this change, the check for too-large arrays (and other large
types) occurred after escape analysis.  If the data moved off stack
and onto the heap contained any pointers, it would therefore escape,
but because the too-large check occurred after escape analysis this
would not be recorded and a stack pointer would leak to the heap
(see the modified escape_array.go for an example).

Some of these appear to remain, in calls to typecheck from within walk.

Also corrected a few comments in escape_array.go about "BAD"
analysis that is now done correctly.

Enhanced to move aditional EscNone-but-large-so-heap checks into esc.c.

Change-Id: I770c111baff28a9ed5f8beb601cf09dacc561b83
Reviewed-on: https://go-review.googlesource.com/10268
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-22 02:13:54 +00:00
David Chase
b19ec6842d cmd/internal/gc: make indirect calls properly escape-y
Indirect function and method calls should leak everything,
but they didn't.

This fix had no particular effect on the cost of running the
compiler on html/template/*.go and added a single new "escape"
to the standard library:

    syscall/syscall_unix.go:85: &b[0] escapes to heap
in
	if errno := m.munmap(uintptr(unsafe.Pointer(&b[0])),
	                     uintptr(len(b))); errno != nil {

Added specific escape testing to escape_calls.go
(and verified that it fails without this patch)

I also did a little code cleanup around the changes in esc.c.

Fixes #10925

Change-Id: I9984b701621ad4c49caed35b01e359295c210033
Reviewed-on: https://go-review.googlesource.com/10295
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-22 01:36:11 +00:00
Russ Cox
cf932cd897 all: retire architecture letter in file names, public API
This CL removes the remaining visible uses of the "architecture letter" concept.
(They are no longer in tool names nor in source directory names.)

Because the architecture letter concept is now gone, delete GOCHAR
from "go env" output, and change go/build.ArchChar to return an
error always.

The architecture letter is still used in the compiler and linker sources
as a clumsy architecture enumeration, but that use is not visible to
Go users and can be cleaned up separately.

Change-Id: I4d97a38f372003fb610c9c5241bea440d9dbeb8d
Reviewed-on: https://go-review.googlesource.com/10289
Reviewed-by: Rob Pike <r@golang.org>
2015-05-21 17:32:17 +00:00
Russ Cox
17eba6e6b7 cmd/compile, cmd/link: create from 5g, 5l, etc
Trivial merging of 5g, 6g, ... into go tool compile,
and similarlly 5l, 6l, ... into go tool link.
The files compile/main.go and link/main.go are new.
Everything else in those directories is a move followed by
change of imports and package name.

This CL breaks the build. Manual fixups are in the next CL.

See golang-dev thread titled "go tool compile, etc" for background.

Change-Id: Id35ff5a5859ad9037c61275d637b1bd51df6828b
Reviewed-on: https://go-review.googlesource.com/10287
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Rob Pike <r@golang.org>
2015-05-21 17:31:51 +00:00