* 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%).
Этот коммит содержится в:
Ayke 2019-01-04 14:58:35 +01:00 коммит произвёл Ron Evans
родитель a8dd82538e
коммит 873c1c3b4d
5 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -31,6 +31,7 @@ func init() {
// Configure the compiler. // Configure the compiler.
type Config struct { type Config struct {
Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default) 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 GC string // garbage collection strategy
CFlags []string // cflags to pass to cgo CFlags []string // cflags to pass to cgo
LDFlags []string // ldflags 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 { if err != nil {
return nil, err 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.targetData = c.machine.CreateTargetData()
c.ctx = llvm.NewContext() c.ctx = llvm.NewContext()

Просмотреть файл

@ -51,6 +51,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
compilerConfig := compiler.Config{ compilerConfig := compiler.Config{
Triple: spec.Triple, Triple: spec.Triple,
CPU: spec.CPU,
GC: config.gc, GC: config.gc,
CFlags: spec.CFlags, CFlags: spec.CFlags,
LDFlags: spec.LDFlags, LDFlags: spec.LDFlags,

Просмотреть файл

@ -20,6 +20,7 @@ import (
type TargetSpec struct { type TargetSpec struct {
Inherits []string `json:"inherits"` Inherits []string `json:"inherits"`
Triple string `json:"llvm-target"` Triple string `json:"llvm-target"`
CPU string `json:"cpu"`
BuildTags []string `json:"build-tags"` BuildTags []string `json:"build-tags"`
GC string `json:"gc"` GC string `json:"gc"`
Compiler string `json:"compiler"` Compiler string `json:"compiler"`
@ -44,6 +45,9 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
if spec2.Triple != "" { if spec2.Triple != "" {
spec.Triple = spec2.Triple spec.Triple = spec2.Triple
} }
if spec2.CPU != "" {
spec.CPU = spec2.CPU
}
spec.BuildTags = append(spec.BuildTags, spec2.BuildTags...) spec.BuildTags = append(spec.BuildTags, spec2.BuildTags...)
if spec2.GC != "" { if spec2.GC != "" {
spec.GC = spec2.GC spec.GC = spec2.GC

Просмотреть файл

@ -1,6 +1,7 @@
{ {
"inherits": ["avr"], "inherits": ["avr"],
"llvm-target": "avr-atmel-none", "llvm-target": "avr-atmel-none",
"cpu": "atmega328p",
"build-tags": ["arduino", "atmega328p", "atmega", "avr5"], "build-tags": ["arduino", "atmega328p", "atmega", "avr5"],
"cflags": [ "cflags": [
"-mmcu=atmega328p" "-mmcu=atmega328p"

Просмотреть файл

@ -1,6 +1,7 @@
{ {
"inherits": ["avr"], "inherits": ["avr"],
"llvm-target": "avr-atmel-none", "llvm-target": "avr-atmel-none",
"cpu": "attiny85",
"build-tags": ["digispark", "attiny85", "attiny", "avr2", "avr25"], "build-tags": ["digispark", "attiny85", "attiny", "avr2", "avr25"],
"cflags": [ "cflags": [
"-mmcu=attiny85" "-mmcu=attiny85"