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.
2

gccgo: The Go Team didn't know

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

3

Why write a Go compiler in C++?

4

rationale: architecture support

5

rationale: code generation

6

rationale: technical honesty

7

gccgo improvements through a telescope

8

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);
}
9

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
10

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

11

Keeping up

12

gccgo: runtime and garbage collector parity

13

beyond gccgo: compiler stack maps

14

llvmgo: another "other Go compiler"

15

OS support: OSX and Windows

16

Thank you

Chris Manghane

Google Gopher | Compilers and Toolchains

Use the left and right arrow keys or click the left and right edges of the page to navigate between slides.
(Press 'H' or navigate to hide this message.)