Reduce code size for AVR (#116)

* all: add support for specifying target CPU in target config
* avr: specify the chip name in the target CPU

This reduces code size by a large margin. For examples/blinky, it
reduces code size from 1360 to 1266 when compiling for the Arduino Uno
(94 bytes, or ~7%).
This commit is contained in:
Ayke
2019-01-04 14:58:35 +01:00
committed by Ron Evans
parent a8dd82538e
commit 873c1c3b4d
5 changed files with 9 additions and 1 deletions
+2 -1
View File
@@ -31,6 +31,7 @@ func init() {
// Configure the compiler.
type Config struct {
Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default)
CPU string // LLVM CPU name, e.g. atmega328p (empty string means default)
GC string // garbage collection strategy
CFlags []string // cflags to pass to cgo
LDFlags []string // ldflags to pass to cgo
@@ -108,7 +109,7 @@ func NewCompiler(pkgName string, config Config) (*Compiler, error) {
if err != nil {
return nil, err
}
c.machine = target.CreateTargetMachine(config.Triple, "", "", llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)
c.machine = target.CreateTargetMachine(config.Triple, config.CPU, "", llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)
c.targetData = c.machine.CreateTargetData()
c.ctx = llvm.NewContext()