aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/statements.h
AgeCommit message (Collapse)AuthorFilesLines
2020-09-22compiler: call runtime.eqtype for non-interface type switch on aixClément Chigot1-2/+2
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
2019-09-10compiler: permit inlining constant expressions and expression statementsIan Lance Taylor1-0/+7
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
2019-08-17compiler, runtime: allocate defer records on the stackIan Lance Taylor1-1/+18
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
2019-07-04compiler: optimize 0,1,2-case select statementIan Lance Taylor1-3/+37
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
2019-06-10compiler: permit inlining functions with labels and goto statementsIan Lance Taylor1-3/+41
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
2019-06-07compiler: support inlining functions with if statementsIan Lance Taylor1-0/+19
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
2019-06-07compiler: do simple deadcode eliminationIan Lance Taylor1-0/+8
Normally the backend will do deadcode elimination and this is sufficient. However, the escape analysis operates on the AST that may have deadcode, and may cause things to escape that otherwise do not. This CL adds a simple deadcode elimination, run before the escape analysis. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/181080 From-SVN: r272043
2019-06-06compiler: permit inlining temporary statements and referencesIan Lance Taylor1-0/+11
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
2019-05-31compiler: optimize append of makeIan Lance Taylor1-1/+36
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
2019-05-16compiler: improve escape analysis on interface conversionsCherry Zhang1-0/+22
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
2019-05-10compiler: permit inlining variable declaration statementsIan Lance Taylor1-6/+15
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
2019-05-03compiler: recognize and optimize array range clearIan Lance Taylor1-0/+5
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
2019-05-01compiler: recognize and optimize map range clearIan Lance Taylor1-0/+4
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
2018-11-28compiler: inline functions with assignments and return statementsIan Lance Taylor1-0/+14
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
2018-11-27compiler: pass a Location to import_expressionIan Lance Taylor1-1/+3
Separate the Location that import_expression uses when creating a new Expression from the Location used to report an error. This is a step toward importing expressions for inlined functions. This is a pure refactoring that does not affect compiler behavior. Reviewed-on: https://go-review.googlesource.com/c/150064 From-SVN: r266525
2018-11-27compiler: import inlinable functions from package dataIan Lance Taylor1-0/+4
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
2018-11-26compiler: initial support for exporting function bodiesIan Lance Taylor1-0/+40
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
2018-09-13compiler, runtime: open code selectIan Lance Taylor1-11/+39
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
2018-09-13compiler: omit a couple of write barriersIan Lance Taylor1-2/+12
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
2017-09-14compiler, runtime: simplify select and channel operationsIan Lance Taylor1-21/+11
In preparation for upgrading libgo to the 1.9 release, this approximately incorporates https://golang.org/cl/37661 and https://golang.org/cl/38351. CL 37661 changed the gc compiler such that the select statement simply returns an integer which is then used as the argument for a switch. Since gccgo already worked that way, this just adjusts the switch code to look like the gc switch code by removing the explicit case index expression and calculating it from the order of calls to selectsend, selectrecv, and selectdefault. CL 38351 simplifies the channel code by not passing the unused channel type descriptor pointer. Reviewed-on: https://go-review.googlesource.com/62730 From-SVN: r252749
2017-01-14libgo: update to Go 1.8 release candidate 1Ian Lance Taylor1-1/+1
Compiler changes: * Change map assignment to use mapassign and assign value directly. * Change string iteration to use decoderune, faster for ASCII strings. * Change makeslice to take int, and use makeslice64 for larger values. * Add new noverflow field to hmap struct used for maps. Unresolved problems, to be fixed later: * Commented out test in go/types/sizes_test.go that doesn't compile. * Commented out reflect.TestStructOf test for padding after zero-sized field. Reviewed-on: https://go-review.googlesource.com/35231 gotools/: Updates for Go 1.8rc1. * Makefile.am (go_cmd_go_files): Add bug.go. (s-zdefaultcc): Write defaultPkgConfig. * Makefile.in: Rebuild. From-SVN: r244456
2016-09-23compiler: better abstraction layer for diagnostics.Than McIntosh1-2/+2
Introduce an abstraction layer for reporting diagnostics, so as to avoid directly using the native GCC interfaces such as "error_at", "warning_at", "open_quote", "close_quote", etc. The new interfaces have the same look and feel as the GCC equivalents, but make calls into back-end functions to allow the back end to select the proper final reporting routine. Reviewed-on: https://go-review.googlesource.com/29191 * go-gcc-diagnostics.cc: New file. * go-location.h (Location): Remove operator source_location. Add operator==. * go-system.h: #include <sstream>. * Make-lang.in (GO_OBJS): Add go/go-diagnostics.o and go/go-gcc-diagnostics.o. (CFLAGS-go/go-gcc-diagnostics.o): New variable. From-SVN: r240453
2016-09-21compiler, runtime: replace hashmap code with Go 1.7 hashmapIan Lance Taylor1-15/+6
This change removes the gccgo-specific hashmap code and replaces it with the hashmap code from the Go 1.7 runtime. The Go 1.7 hashmap code is more efficient, does a better job on details like when to update a key, and provides some support against denial-of-service attacks. The compiler is changed to call the new hashmap functions instead of the old ones. The compiler now tracks which types are reflexive and which require updating when used as a map key, and records the information in map type descriptors. Map_index_expression is simplified. The special case for a map index on the right hand side of a tuple expression has been unnecessary for some time, and is removed. The support for specially marking a map index as an lvalue is removed, in favor of lowering an assignment to a map index into a function call. The long-obsolete support for a map index of a pointer to a map is removed. The __go_new_map_big function (known to the compiler as Runtime::MAKEMAPBIG) is no longer needed, as the new runtime.makemap function takes an int64 hint argument. The old map descriptor type and supporting expression is removed. The compiler was still supporting the long-obsolete syntax `m[k] = 0, false` to delete a value from a map. That is now removed, requiring a change to one of the gccgo-specific tests. The builtin len function applied to a map or channel p is now compiled as `p == nil ? 0 : *(*int)(p)`. The __go_chan_len function (known to the compiler as Runtime::CHAN_LEN) is removed. Support for a shared zero value for maps to large value types is introduced, along the lines of the gc compiler. The zero value is handled as a common variable. The hash function is changed to take a seed argument, changing the runtime hash functions and the compiler-generated hash functions. Unlike the gc compiler, both the hash and equal functions continue to take the type length. Types that can not be compared now store nil for the hash and equal functions, rather than pointing to functions that throw. Interface hash and comparison functions now check explicitly for nil. This matches the gc compiler and permits a simple implementation for ismapkey. The compiler is changed to permit marking struct and array types as incomparable, meaning that they have no hash or equal function. We use this for thunk types, removing the existing special code to avoid generating hash/equal functions for them. The C runtime code adds memclr, memequal, and memmove functions. The hashmap code uses go:linkname comments to make the functions visible, as otherwise the compiler would discard them. The hashmap code comments out the unused reference to the address of the first parameter in the race code, as otherwise the compiler thinks that the parameter escapes and copies it onto the heap. This is probably not needed when we enable escape analysis. Several runtime map tests that ere previously skipped for gccgo are now run. The Go runtime picks up type kind information and stubs. The type kind information causes the generated runtime header file to define some constants, including `empty`, and the C code is adjusted accordingly. A Go-callable version of runtime.throw, that takes a Go string, is added to be called from the hashmap code. Reviewed-on: https://go-review.googlesource.com/29447 * go.go-torture/execute/map-1.go: Replace old map deletion syntax with call to builtin delete function. From-SVN: r240334
2016-06-14escape: Implement assign phase.Ian Lance Taylor1-1/+160
Implementation of the assign/connect phase. Statements containing expressions which alias local, parameter, and global objects are analyzed and the alias relationship between objects containing pointers are captured in a connection graph to summarize the assignments within a function. Reviewed-on: https://go-review.googlesource.com/18302 From-SVN: r237424
2016-04-29escape: Remove previously existing analysis.Chris Manghane1-13/+0
* Make-lang.in (GO_OBJS): Remove go/dataflow.o, go/escape.o. Reviewed-on: https://go-review.googlesource.com/18261 From-SVN: r235649
2015-04-17compiler: Escape analysis.Chris Manghane1-0/+137
By Chris Manghane. Comprises three changes to gofrontend repository: compiler: Add escape information to export data. compiler: Stack-allocate non-escaping variables. This change allows variables initialized through make or new to be allocated on the stack via a temporary variable if they do not escape their function. It also improves the analysis to consider situations where variables escape in the standard library and go testsuite such as: *nested composite literals and composite literal arguments *method receivers always escaping *escape via statements in closures referring to enclosing variables *escape via calls with multiple return results compiler: Basic escape analysis for the go frontend. This is an implementation of the algorithm described in "Escape Analysis in Java" by Choi et. al. It relies on dataflow information to discover variable references to one another. Handles assignments to closures and association between closures variables and the variables of the enclosing scope. Dataflow analysis does not discover references through range statements e.g. for _, v := range a will not recognize that all values of v are references to a. * Make-lang.in (GO_OBJS): Add go/escape.o. From-SVN: r222188
2015-03-06compiler: Do not declare type switch variable outside case statements.Ian Lance Taylor1-6/+7
For expressions containing a TypeSwitchGuard with a short variable declaration e.g. var := x.(type), the spec says that var is declared at the beginning of the implicit block for each in each clause. Previously, var was declared in the block for the switch statement and each implicit block, which led to errors if the type case clause referenced a type with a similar name as the declared variable. Fixes golang/go#10047. From-SVN: r221230
2014-12-19compiler: More cases that need a temporary for interface conversion.Ian Lance Taylor1-0/+3
From-SVN: r218952
2014-12-19compiler: Avoid multiple evaluations in interface conversions.Ian Lance Taylor1-0/+3
Added assertions for cases that might lead to multiple evaluations, and fixed all the problems I saw. Test case already in master Go testsuite (https://go-review.googlesource.com/#/c/1710/). From-SVN: r218884
2014-12-16compiler: Don't built hash/equality functions for thunk structs.Ian Lance Taylor1-0/+7
They are never necessary, and they can cause problems when a thunk is used to pass an unexported type from a different package to a function defined in that package. The resulting struct type may need to call the comparison routine from the other package, which will fail because the type is not exported. This will be bug492 in the master testsuite. From-SVN: r218798
2014-10-21compiler: Remove obsolete hidden_fields_are_ok code.Ian Lance Taylor1-20/+2
The language used to forbid assigning structs with hidden fields, but that was changed before the Go 1 release. At the time the change was experimental, so I left the old code in the compiler. At this point it's clearly not experimental, so this removes the unused code. From-SVN: r216519
2014-01-09compiler: Add flattening passIan Lance Taylor1-0/+19
From-SVN: r206502
2013-09-03compiler, runtime: Use runtime functions to pass closure value.Ian Lance Taylor1-0/+46
This changes the compiler and runtime to not pass a closure value as the last argument, but to instead pass it via __go_set_closure and retrieve it via __go_get_closure. This eliminates the need for function descriptor wrapper functions. It will make it possible to retrieve the closure value in a reflect.MakeFunc function. From-SVN: r202233
2013-06-24compiler: Add support for method values.Ian Lance Taylor1-0/+7
From-SVN: r200379
2013-06-12compiler: implement Go 1.1 spec of terminating statements.Ian Lance Taylor1-2/+21
From-SVN: r200047
2013-01-29compiler: Correct initialization order determination.Ian Lance Taylor1-0/+5
From-SVN: r195526
2012-01-24compiler: Error if type switch case can not implement switch value.Ian Lance Taylor1-2/+2
From-SVN: r183500
2011-12-28compiler: Rework range over slice.Ian Lance Taylor1-0/+5
From-SVN: r182697
2011-12-01compiler/runtime: Copy channel implementation from master library.Ian Lance Taylor1-30/+53
From-SVN: r181874
2011-11-29compiler: Define and use backend-independent Location class.Sanjoy Das1-56/+56
From Sanjoy Das. * go-location.h: New file. * go-linemap.cc: New file. * go-gcc.cc: Change all uses of source_location to Location. * Make-lang.in (GO_OBJS): Add go/go-linemap.o. (GO_LINEMAP_H): New variable. (GO_LEX_H): Use $(GO_LINEMAP_H). (GO_GOGO_H, GO_TYPES_H, GO_IMPORT_H): Likewise. (go/go-linemap.o): New target. Co-Authored-By: Ian Lance Taylor <iant@google.com> From-SVN: r181813
2011-09-20Emit compiler errors for unused values.Ian Lance Taylor1-2/+4
From-SVN: r179008
2011-09-13Fix inheriting hidden methods with arguments of hidden type.Ian Lance Taylor1-4/+3
From-SVN: r178827
2011-09-13Fix inherited hidden methods that return hidden types.Ian Lance Taylor1-3/+22
From-SVN: r178818
2011-08-25Change Bound_method_expression to refer to a constant method.Ian Lance Taylor1-9/+5
From-SVN: r178091
2011-08-03gccgo: Added code to dump the AST tree.Roberto Lublinerman1-1/+70
gccgo: Added code to dump the AST tree. The AST dump is activated with -fgo-dump-ast. Initial version, it only dumps (most) constructs that are expected after the lowering transformation. * Make-lang.in (GO_OBJS): Add go/ast-dump.o. (go/ast-dump.o): New target. (go/expressions.o): Depend on go/gofrontend/ast-dump.h. (go/statements.o): Likewise. From-SVN: r177225
2011-08-01Use temporary variables for calls with multiple results.Ian Lance Taylor1-9/+15
From-SVN: r176998
2011-04-23Define go_unreachable to replace gcc_unreachable.Ian Lance Taylor1-6/+6
From Evan Shaw. From-SVN: r172882
2011-04-21Define go_assert to replace gcc_assertIan Lance Taylor1-8/+8
This is defined in go-system.h in the backend. * go-system.h (go_assert, go_unreachable): Define. From-SVN: r172846
2011-04-19statement.cc no longer includes gcc headers.Ian Lance Taylor1-14/+4
* go-system.h: Include "intl.h". * Make-lang.in (GO_SYSTEM_H): Add intl.h. (go/statements.o): Remove dependencies on intl.h $(TREE_H) $(GIMPLE_H) convert.h tree-iterator.h $(TREE_FLOW_H) $(REAL_H). From-SVN: r172743
2011-04-19Change general statement method to always use backend interface.Ian Lance Taylor1-30/+30
From-SVN: r172740