Skip to content

Commit 0ae467d

Browse files
j7baykevl
authored andcommitted
llvm cpu features
1 parent 4442b13 commit 0ae467d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

compiler/compiler.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func init() {
3030
type Config struct {
3131
Triple string // LLVM target triple, e.g. x86_64-unknown-linux-gnu (empty string means default)
3232
CPU string // LLVM CPU name, e.g. atmega328p (empty string means default)
33+
Features []string // LLVM CPU features
3334
GOOS string //
3435
GOARCH string //
3536
GC string // garbage collection strategy
@@ -101,7 +102,11 @@ func NewCompiler(pkgName string, config Config) (*Compiler, error) {
101102
if err != nil {
102103
return nil, err
103104
}
104-
c.machine = target.CreateTargetMachine(config.Triple, config.CPU, "", llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)
105+
features := ""
106+
if len(config.Features) > 0 {
107+
features = strings.Join(config.Features, `,`)
108+
}
109+
c.machine = target.CreateTargetMachine(config.Triple, config.CPU, features, llvm.CodeGenLevelDefault, llvm.RelocStatic, llvm.CodeModelDefault)
105110
c.targetData = c.machine.CreateTargetData()
106111

107112
c.ctx = llvm.NewContext()

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
9494
compilerConfig := compiler.Config{
9595
Triple: spec.Triple,
9696
CPU: spec.CPU,
97+
Features: spec.Features,
9798
GOOS: spec.GOOS,
9899
GOARCH: spec.GOARCH,
99100
GC: config.gc,

target.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type TargetSpec struct {
2424
Inherits []string `json:"inherits"`
2525
Triple string `json:"llvm-target"`
2626
CPU string `json:"cpu"`
27+
Features []string `json:"features"`
2728
GOOS string `json:"goos"`
2829
GOARCH string `json:"goarch"`
2930
BuildTags []string `json:"build-tags"`
@@ -52,6 +53,7 @@ func (spec *TargetSpec) copyProperties(spec2 *TargetSpec) {
5253
if spec2.CPU != "" {
5354
spec.CPU = spec2.CPU
5455
}
56+
spec.Features = append(spec.Features, spec2.Features...)
5557
if spec2.GOOS != "" {
5658
spec.GOOS = spec2.GOOS
5759
}

0 commit comments

Comments
 (0)