Skip to content

Commit 660b48f

Browse files
author
Julian Orth
committed
Add support for target-cpu=native
1 parent 638832e commit 660b48f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/rustllvm/PassWrapper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/Support/CBindingWrapping.h"
1616
#include "llvm/Support/FileSystem.h"
17+
#include "llvm/Support/Host.h"
1718
#include "llvm/Target/TargetLibraryInfo.h"
1819
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
1920

@@ -83,6 +84,11 @@ LLVMRustCreateTargetMachine(const char *triple,
8384
return NULL;
8485
}
8586

87+
StringRef real_cpu = cpu;
88+
if (real_cpu == "native") {
89+
real_cpu = sys::getHostCPUName();
90+
}
91+
8692
TargetOptions Options;
8793
Options.PositionIndependentExecutable = PositionIndependentExecutable;
8894
Options.NoFramePointerElim = NoFramePointerElim;
@@ -96,7 +102,7 @@ LLVMRustCreateTargetMachine(const char *triple,
96102
}
97103

98104
TargetMachine *TM = TheTarget->createTargetMachine(Trip.getTriple(),
99-
cpu,
105+
real_cpu,
100106
feature,
101107
Options,
102108
RM,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs -C target-cpu=native
5+
$(call RUN,foo)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
}

0 commit comments

Comments
 (0)