Skip to content

Commit 617e279

Browse files
fgschdeadprogram
authored andcommitted
Add -llvm-features parameter
With this is possible to enable e.g., SIMD in WASM using -llvm-features +simd128. Multiple features can be specified separated by comma, e.g., -llvm-features +simd128,+tail-call With help from @deadprogram and @aykevl.
1 parent a0908ff commit 617e279

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

builder/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
9494
DefaultStackSize: config.Target.DefaultStackSize,
9595
NeedsStackObjects: config.NeedsStackObjects(),
9696
Debug: config.Debug(),
97+
LLVMFeatures: config.LLVMFeatures(),
9798
}
9899

99100
// Load the target machine, which is the LLVM object that contains all

compileopts/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ func (c *Config) WasmAbi() string {
337337
return c.Target.WasmAbi
338338
}
339339

340+
func (c *Config) LLVMFeatures() string {
341+
return c.Options.LLVMFeatures
342+
}
343+
340344
type TestConfig struct {
341345
CompileTestBinary bool
342346
// TODO: Filter the test functions to run, include verbose flag, etc

compileopts/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Options struct {
3636
TestConfig TestConfig
3737
Programmer string
3838
OpenOCDCommands []string
39+
LLVMFeatures string
3940
}
4041

4142
// Verify performs a validation on the given options, raising an error if options are not valid.

compiler/compiler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Config struct {
5959
DefaultStackSize uint64
6060
NeedsStackObjects bool
6161
Debug bool // Whether to emit debug information in the LLVM module.
62+
LLVMFeatures string
6263
}
6364

6465
// compilerContext contains function-independent data that should still be
@@ -185,7 +186,12 @@ func NewTargetMachine(config *Config) (llvm.TargetMachine, error) {
185186
if err != nil {
186187
return llvm.TargetMachine{}, err
187188
}
188-
features := strings.Join(config.Features, ",")
189+
190+
feat := config.Features
191+
if len(config.LLVMFeatures) > 0 {
192+
feat = append(feat, config.LLVMFeatures)
193+
}
194+
features := strings.Join(feat, ",")
189195

190196
var codeModel llvm.CodeModel
191197
var relocationModel llvm.RelocMode

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ func main() {
911911
programmer := flag.String("programmer", "", "which hardware programmer to use")
912912
ldflags := flag.String("ldflags", "", "Go link tool compatible ldflags")
913913
wasmAbi := flag.String("wasm-abi", "", "WebAssembly ABI conventions: js (no i64 params) or generic")
914+
llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable")
914915

915916
var flagJSON, flagDeps *bool
916917
if command == "help" || command == "list" {
@@ -978,6 +979,7 @@ func main() {
978979
WasmAbi: *wasmAbi,
979980
Programmer: *programmer,
980981
OpenOCDCommands: ocdCommands,
982+
LLVMFeatures: *llvmFeatures,
981983
}
982984

983985
os.Setenv("CC", "clang -target="+*target)

0 commit comments

Comments
 (0)