Keeping up with the Gophers

A brief history of gccgo, improvements, and the future

Chris Manghane

Google Gopher | Compilers and Toolchains

gccgo: "The Other Go Compiler"

2010-01-26  Ian Lance Taylor  <iant@google.com>

        * MAINTAINERS: Add myself as Go frontend maintainer.

gccgo: The Go Team didn't know

"Ian just showed up at our door with a fully working compiler" ~ probably Rob

Why write a Go compiler in C++?

rationale: architecture support

rationale: code generation

rationale: technical honesty

gccgo improvements through a telescope

gofrontend: no dependency on gcc

gofrontend (gcc/go/gofrontend/expressions.cc)

-  tree val_type_tree = type_to_tree(this->type()->get_backend(gogo));
-  go_assert(val_type_tree != error_mark_node);
-  return build_int_cstu(val_type_tree, val);
+  mpz_t cst;
+  mpz_init_set_ui(cst, val);
+  Btype* int_btype = this->type()->get_backend(gogo);
+  return gogo->backend()->integer_constant_expression(int_btype, cst);

backend (gcc/go/go-gcc.cc)

Bexpression*
Gcc_backend::integer_constant_expression(Btype* btype, mpz_t val)
{
  tree t = btype->get_tree();
  tree ret = double_int_to_tree(t, mpz_get_double_int(t, val, true));
  return this->make_expression(ret);
}

gccgo: builds the `go` tool

$ cat hello.go
package main

import "fmt"

func main() {
     fmt.Println("Hello World!")
}

$ go run -gccgoflags="-fgo-optimize-allocs" hello.go
Hello World!

$ go version
go version go1.4.2 gccgo (GCC) 6.0.0 20150714 (experimental) linux/amd64

gofrontend: basic escape analysis

escape.go

package main

var global *int

func f(i *int) { global = i }

func main() {
    a := new(int)
    f(a)
}

Connection Graph

Keeping up

gccgo: runtime and garbage collector parity

beyond gccgo: compiler stack maps

llvmgo: another "other Go compiler"

OS support: OSX and Windows

演讲者

Chris Manghane

Google Gopher | Compilers and Toolchains