Age | Commit message (Collapse) | Author | Files | Lines |
|
Instead of building the thunk struct type in the determine_types pass,
build it when we need it. That ensures that we are consistent in
determining whether an argument is constant.
We no longer need to add a field for a call to recover, as the
simplify_thunk_statements pass runs after the build_recover_thunks pass,
so the additional argument will already have been added to the call.
The test case is https://go.dev/cl/440297.
Fixes golang/go#56109
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/440298
|
|
If a comma-ok variable already has a type, and that type is not a
boolean type, then set the type of the temporary variable to bool.
Otherwise we may try to convert an unnamed bool type to an interface
type, which will fail. But we don't want to always use bool, because
the type of the comma-ok variable may be a named bool type, in
which case the assignment would fail (or need an explicit conversion).
The test case is https://go.dev/cl/404496.
Fixes golang/go#52535
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/413894
|
|
Fixes golang/go#52811
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/405617
|
|
The only different between selectnbrecv and selectnbrecv2 is the later
set the input pointer value by second return value from chanrecv.
So by making selectnbrecv return two values from chanrecv, we can get
rid of selectnbrecv2, the compiler can now call only selectnbrecv and
generate simpler code.
This is the gofrontend version of https://golang.org/cl/292890.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339529
|
|
To implement this, change the backend to use flag bits for variables.
Fixes https://gcc.gnu.org/PR100537
PR go/100537
* go-gcc.cc (class Gcc_backend): Update methods that create
variables to take a flags parameter.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/322129
|
|
Test case is https://golang.org/cl/302371.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/302270
|
|
The compiler generally doesn't create a temporary for an expression
that is a variable, because it's normally valid to simply reload the
value from the variable. However, if the variable is in the heap,
then loading the value is a pointer indirection. The process of
creating GCC IR can cause the variable load and the pointer
indirection to be split, such that the second evaluation only does the
pointer indirection. If there are conditionals in between the two
uses, this can cause the second use to load the pointer from an
uninitialized register.
Avoid this by introducing a new Expression method that returns whether
it is safe to evaluate an expression multiple times, and use it
everywhere.
The test case is https://golang.org/cl/300789.
Fixes golang/go#44383
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/300809
|
|
This is the gofrontend version of https://golang.org/cl/245125.
Original CL description:
Currently, we include a "kind" field on scase to distinguish the three
kinds of cases in a select statement: sends, receives, and defaults.
This commit removes by kind field by instead arranging for the
compiler to always place sends before receives, and to provide their
counts separately. It also passes an explicit "block bool" parameter
to avoid needing to include a default case in the array.
It's safe to shuffle cases like this because the runtime will
randomize the order they're polled in anyway.
For golang/go#40410.
This is being brought over to gofrontend as a step toward upgrading to
Go1.16beta1.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/279735
|
|
For golang/go#43200
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/278452
|
|
To make this work from the do_type method, add "byte" and "rune" to
the list of known integer types, and look them up that way rather than
via gogo->lookup_global.
For golang/go#8745
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/275653
|
|
For "a, b := v.(T)" we must set a before b.
For golang/go#13433
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273906
|
|
All type switch clauses must call runtime.eqtype if the linker isn't
able to merge type descriptors pointers. Previously, only interface-type
clauses were doing it.
Updates golang/go#39276
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/255202
|
|
Use specific panic functions instead, which are mostly already in the
runtime package.
Also correct "defer nil" to panic when we execute the defer, rather
than throw when we queue it.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/213642
From-SVN: r279979
|
|
Also add a couple of missing calls to free after mpz_get_str.
This should make the code clean with respect to -Wshadow=local.
Based on patch by Bernd Edlinger.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/198837
From-SVN: r276579
|
|
This relatively minor change increases the number of inlinable
functions/methods in the standard library from 983 to 2179.
In particular it permits inlining math/bits/RotateLeftNN. This
restores the speed of crypto/sha256 back to what it was before the
update to 1.13beta1.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/194340
From-SVN: r275558
|
|
When a defer is executed at most once in a function body,
we can allocate the defer record for it on the stack instead
of on the heap.
This should make defers like this (which are very common) faster.
This is a port of CL 171758 from the gc repo.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/190410
From-SVN: r274613
|
|
In the channel-send case, the value to be sent may needs an
(implicit) type conversion to the channel element type. This CL
ensures that we use the correct value type for the send.
Fixes golang/go#33235.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/187177
From-SVN: r273743
|
|
This patch fixes a buglet in the function body importer. Add hooks for
keeping a stack of blocks corresponding to the block nesting in the
imported function. This ensures that local variables and temps wind up
correctly scoped and don't introduce collisions.
New test case for this problem in CL 186717.
Fixes golang/go#33158.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/186757
From-SVN: r273577
|
|
CL 184998 added optimizations for one- and two-case select
statements. But it didn't handle break statement in the select
case correctly. Specifically, it didn't add the label definition,
so it could result in a dangling goto. This CL fixes this, by
adding the label definition.
A test case is CL 185520.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/185519
From-SVN: r273359
|
|
For a select statement with zero-, one-, or two-case with a
default case, we can generate simpler code instead of calling the
generic selectgo. A zero-case select is just blocking the
execution. A one-case select is mostly just executing the case. A
two-case select with a default case is a non-blocking send or
receive. We add these special cases for lowering a select
statement.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/184998
From-SVN: r273034
|
|
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/184997
From-SVN: r273032
|
|
For zeroing a range of memory that doesn't contain pointer, we
can use builtin memset directly.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/184438
* go-gcc.cc (Gcc_backend::Gcc_backend): Define __builtin_memset.
From-SVN: r272944
|
|
GCC recently introduced -Wformat-diag to scrutinize GCC error messages.
It reports a number of warnings about gofrontend code, such as:
../../trunk/gcc/go/gofrontend/import.cc: In member function ‘Type* Import::type_for_index(int, const string&, size_t, bool*)’:
../../trunk/gcc/go/gofrontend/import.cc:1129:48: warning: unquoted operator ‘>=’ in format [-Wformat-diag]
1129 | "error in %s at %lu: bad type index %d >= %d",
| ^~
../../trunk/gcc/go/gofrontend/ast-dump.cc: In member function ‘void Ast_dump_context::dump(Gogo*, const char*)’:
../../trunk/gcc/go/gofrontend/ast-dump.cc:203:25: warning: unquoted option name ‘-fgo-dump-ast’ in format [-Wformat-diag]
203 | "cannot open %s:%m, -fgo-dump-ast ignored", dumpname.c_str());
| ^~~~~~~~~~~~~
../../trunk/gcc/go/gofrontend/expressions.cc: In static member function ‘static Bexpression* Func_expression::get_code_pointer(Gogo*, Named_object*, Location)’:
../../trunk/gcc/go/gofrontend/expressions.cc:1350:29: warning: misspelled term ‘builtin function’ in format; use ‘built-in function’ instead [-Wformat-diag]
1350 | "invalid use of special builtin function %qs; must be called",
| ^~~~~~~~~~~~~~~~
../../trunk/gcc/go/gofrontend/gogo.cc: In member function ‘void Gogo::add_linkname(const string&, bool, const string&, Location)’:
../../trunk/gcc/go/gofrontend/gogo.cc:2527:4: warning: unquoted sequence of 2 consecutive punctuation characters ‘//’ in format [-Wformat-diag]
2527 | ("%s is not a function; "
| ~^~~~~~~~~~~~~~~~~~~~~~~~
2528 | "//go:linkname is only supported for functions"),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This CL edits error messages to avoid these warnings.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/183497
* go.test/test/blank1.go: Update for diagnostic message changes.
From-SVN: r272608
|
|
GCC recently added a new warning -Wformat-diag which does a lot of
rigorous checks on GCC diagnostic messages. This produces a number of
unnecessary diagnostics on gofrontend diagnostic output, such as
../../trunk/gcc/go/gofrontend/escape.cc: In member function ‘virtual int Escape_analysis_assign::statement(Block*, size_t*, Statement*)’:
../../trunk/gcc/go/gofrontend/escape.cc:1336:33: warning: spurious leading punctuation sequence ‘[’ in format [-Wformat-diag]
1336 | go_inform(s->location(), "[%d] %s esc: %s",
| ^
../../trunk/gcc/go/gofrontend/escape.cc: In member function ‘void Escape_analysis_assign::call(Call_expression*)’:
../../trunk/gcc/go/gofrontend/escape.cc:1964:17: warning: unquoted operator ‘::’ in format [-Wformat-diag]
1964 | "esccall:: indirect call <- %s, untracked",
| ^~
../../trunk/gcc/go/gofrontend/escape.cc:1964:34: warning: unbalanced punctuation character ‘<’ in format [-Wformat-diag]
1964 | "esccall:: indirect call <- %s, untracked",
| ^
Avoid these messages by adding a new function go_debug that uses only
printf formatting, not GCC diagnostic formatting, and change all the
optimization debugging messages to use it. None of the debugging
messages used the GCC diagnostic formatting specifiers anyhow.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/183437
From-SVN: r272607
|
|
Now that type equality is just simple pointer equality, we can
open code some type assertions instead of making runtime calls.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/182977
From-SVN: r272577
|
|
Currently a string slice expression is implemented with a runtime
call __go_string_slice. Change it to open code it, which is more
efficient, and allows the backend to further optimize it.
Also omit the write barrier for length-only update (i.e.
s = s[:n]).
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/182540
From-SVN: r272549
|
|
Also move the determine_types pass on an inlined function body to one
place, rather than doing it ad hoc as needed.
This adds 79 new inlinable functions in the standard library, such as
bytes.HasPrefix and bytes.LastIndexByte.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/181261
From-SVN: r272133
|
|
This permits inlining functions with for loops and some switches, as
they are lowered to if and goto statements before exporting them.
This by itself only adds three new inlinable functions in the standard
library: sort.Search, context.(*emptyCtx).String, and
cmd/go/internal/work.(*Builder).disableBuildID.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/181197
From-SVN: r272131
|
|
This increases the number of inlinable functions from 455 to 500.
An example of a newly inlinable function is strings.Compare.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/181137
From-SVN: r272045
|
|
This increases the number of inlinable functions from 439 to 455.
An example is math/bits.Mul32, which uses temporaries to handle the
tuple assignment.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/180837
From-SVN: r272022
|
|
In the runtime there are specialized fast map routines for
certain kep types. This CL lets the compiler make use of these
functions, instead of always using the generic ones.
As we now generate multiple versions of map delete calls, to make
things easier we delay the expansion of the built-in delete
function to flatten phase.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/180858
From-SVN: r271983
|
|
The gc compiler recognizes append(s, make([]T, n)...), and
generates code to directly zero the tail instead of allocating a
new slice and copying. This CL lets the Go frontend do basically
the same.
The difficulty is that at the point we handle append, there may
already be temporaries introduced (e.g. in order_evaluations),
which makes it hard to find the append-of-make pattern. The
compiler could "see through" the value of a temporary, but it is
only safe to do if the temporary is not assigned multiple times.
For this, we add tracking of assignments and uses for temporaries.
This also helps in optimizing non-escape slice make. We already
optimize non-escape slice make with constant len/cap to stack
allocation. But it failed to handle things like f(make([]T, n))
(where the slice doesn't escape and n is constant), because of
the temporary. With tracking of temporary assignments and uses,
it can handle this now as well.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/179597
From-SVN: r271822
|
|
Let the Go frontend recognize sync/atomic functions and turn them
into intrinsics.
Also make sure not to intrinsify calls in go or defer statements.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/178937
From-SVN: r271784
|
|
If an interface does not escape, it doesn't need a heap
allocation to hold the data (for non-direct interface type).
This CL improves the escape analysis to track interface
conversions, and reduces these allocations.
Implicit interface conversions were mostly added late in the
compilation pipeline, after the escape analysis. For the escape
analysis to see them, we move the introduction of these
conversions earlier, right before the escape analysis.
Now that the compiler can generate interface conversions inlined,
gcc/testsuite/go.test/test/nilptr2.go needs to be adjusted as in
golang.org/cl/176579, so the use function does an actual use.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/176459
* go.test/test/nilptr2.go: Change use function to actually do
something.
From-SVN: r271276
|
|
This adds all of two inlinable functions to the standard library:
crypto/subtle.ConstantTimeLessOrEq, regexp.(*Regexp).Copy.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/176378
From-SVN: r271063
|
|
If a string([]byte) conversion is used immediately as a key for a
map read, we don't need to copy the backing store of the byte
slice, as mapaccess does not keep a reference to it.
The gc compiler does more than this: it also avoids the copy if
the map key is a composite literal that contains the conversion
as a field, like, T{ ... { ..., string(b), ... }, ... }. For now,
we just optimize the simple case, which is probably most common.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/176197
* go.dg/mapstring.go: New test.
From-SVN: r271044
|
|
Add a -fgo-debug-optimization option to emit optimization
diagnostics. This can be used for testing optimizations. Apply
this to the range clear optimizations of maps and arrays.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/170002
gcc/go:
* lang.opt (-fgo-debug-optimization): New option.
* go-c.h (struct go_create_gogo_args): Add debug_optimization
field.
* go-lang.c (go_langhook_init): Set debug_optimization field.
* gccgo.texi (Invoking gccgo): Document -fgo-debug-optimization.
gcc/testsuite:
* go.dg/arrayclear.go: New test.
* go.dg/mapclear.go: New test.
From-SVN: r270993
|
|
Recognize
for i := range a { a[i] = zero }
for array or slice a, and rewrite it to call memclr, as the gc
compiler does.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/169398
From-SVN: r270862
|
|
Recognize
for k := range m { delete(m, k) }
for map m, and rewrite it to runtime.mapclear, as the gc compiler
does.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/169397
From-SVN: r270780
|
|
Support inlining functions that contain only assignments and return
statements, with expressions of either constants or parameters.
Functions that contain other kinds of statements or expressions are
not yet inlined. With this change, about 100 functions in the
standard library are inlinable.
Reviewed-on: https://go-review.googlesource.com/c/150073
From-SVN: r266573
|
|
Start reading the export data generated by the last change in this
series. At this point we will inline direct calls to empty functions
and methods defined in different packages.
Reviewed-on: https://go-review.googlesource.com/c/150062
From-SVN: r266517
|
|
Create a framework for putting function bodies in export data. At
present only empty functions will be put there, and they will be
ignored on import. Later patches will get this to the point of
supporting inlining of (some) functions defined in other packages.
Reviewed-on: https://go-review.googlesource.com/c/150061
From-SVN: r266490
|
|
A single flags parameter replaces the Cmp_tags and errors_are_identical
parameters. The existing behavior is unchanged.
This is a simplification step for future work that will add a new flag.
Reviewed-on: https://go-review.googlesource.com/c/143019
From-SVN: r265293
|
|
This is the gofrontend version of https://golang.org/cl/37933,
https://golang.org/cl/37934, and https://golang.org/cl/37935.
Open code the initialization of select cases.
This is a step toward updating libgo to the 1.11 release.
Reviewed-on: https://go-review.googlesource.com/135000
From-SVN: r264290
|
|
Omit a write barrier for
s = s[0:]
for a slice s. In this case the pointer is not changing and no write
barrier is required.
Omit a write barrier for
s = append(s, v)
in the case where len(s) < cap(s) (and similarly when appending more
values). When the slice has enough capacity the pointer is not
changing and no write barrier is required.
These changes are required to avoid write barriers in the method
randomOrder.reset in the runtime package. That method is called from
procresize, at a point where we do not want to allocate memory.
Otherwise that method can use a write barrier, allocate memory, and
break TestReadMemStats.
Reviewed-on: https://go-review.googlesource.com/134219
From-SVN: r264259
|
|
The last change was incomplete, in that it did not evaluate the array
argument in some cases where it had to be evaluated. This reuses the
existing code for checking whether len/cap is constant.
Also clean up the use of _ as the second variable in a for/range,
which was previously inconsistent depending on whether the statement
used = or :=.
Updates golang/go#22313
Reviewed-on: https://go-review.googlesource.com/91715
From-SVN: r257377
|
|
The language spec says that in `for i = range x`, in which there is no
second iteration variable, if len(x) is constant, then x is not
evaluated. This only matters when x is an expression that panics but
whose type is an array type; in such a case, we should not evaluate x,
since len of any array type is a constant.
Fixes golang/go#22313
Reviewed-on: https://go-review.googlesource.com/91555
From-SVN: r257330
|
|
Encode all external symbol names using only ASCII alphanumeric
characters, underscore, and dot. Use a scheme that can be reliably
demangled to a somewhat readable version as described in the long
comment in names.cc.
A minor cleanup discovered during this was that we were treating
function types as different if one had a NULL parameters_ field and
another has a non-NULL parameters_ field that has no parameters. This
worked because we mangled them slightly differently. We now mangle
them the same, so we treat them as equal, as we should anyhow.
Reviewed-on: https://go-review.googlesource.com/89555
* go.go-torture/execute/names-1.go: New test.
From-SVN: r257033
|
|
Defer statement may need to allocate a thunk. When it is not
inside a loop, this can be stack allocated, as it runs before
the function finishes.
Reviewed-on: https://go-review.googlesource.com/85639
From-SVN: r256410
|
|
GCC has started emitting "control reaches end of non-void function"
warnings. Avoid them for Go by 1) marking the builtin function panic
and the compiler-generated function __go_runtime_error as not
returning and 2) adding a default case to the switch used for select
statements that simply calls __builtin_unreachable.
Fixes golang/go#22767
Reviewed-on: https://go-review.googlesource.com/80416
* go-gcc.cc (Gcc_backend::Gcc_backend): Define
__builtin_unreachable.
(Gcc_backend::function): Add does_not_return parameter.
From-SVN: r255346
|