Skip to content

Commit 6943e5b

Browse files
author
Ariel Ben-Yehuda
authored
Rollup merge of rust-lang#41524 - michaelwu:basic-hexagon, r=alexcrichton
Add Hexagon support This requires an updated LLVM with https://reviews.llvm.org/D31999 and https://reviews.llvm.org/D32000 to build libcore. A basic hello world builds and runs successfully on the hexagon simulator. libcore is fine with LLVM fixes, but libstd requires a lot more work since there's a custom rtos running on most hexagon cores. Running Linux sounds possible though, so maybe getting linux + musl going would be easier. Here's the target file I've been using for testing ``` { "arch": "hexagon", "llvm-target": "hexagon-unknown-elf", "os": "none", "target-endian": "little", "target-pointer-width": "32", "data-layout": "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048", "linker": "hexagon-clang", "linker-flavor": "gcc", "executables": true, "cpu": "hexagonv60" } ```
2 parents acdfc9f + 22eb3c6 commit 6943e5b

File tree

10 files changed

+102
-33
lines changed

10 files changed

+102
-33
lines changed

src/bootstrap/config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# support. You'll need to write a target specification at least, and most
5252
# likely, teach rustc about the C ABI of the target. Get in touch with the
5353
# Rust team and file an issue if you need assistance in porting!
54-
#targets = "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX"
54+
#targets = "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX;Hexagon"
5555

5656
# Cap the number of parallel linker invocations when compiling LLVM.
5757
# This can be useful when building LLVM with debug info, which significantly

src/bootstrap/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn llvm(build: &Build, target: &str) {
8181
// NOTE: remember to also update `config.toml.example` when changing the defaults!
8282
let llvm_targets = match build.config.llvm_targets {
8383
Some(ref s) => s,
84-
None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX",
84+
None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX;Hexagon",
8585
};
8686

8787
let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};

src/librustc_llvm/build.rs

+38-28
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,24 @@ use std::path::{PathBuf, Path};
1717

1818
use build_helper::output;
1919

20-
fn detect_llvm_link(llvm_config: &Path) -> (&'static str, Option<&'static str>) {
21-
let mut version_cmd = Command::new(llvm_config);
22-
version_cmd.arg("--version");
23-
let version_output = output(&mut version_cmd);
24-
let mut parts = version_output.split('.').take(2)
25-
.filter_map(|s| s.parse::<u32>().ok());
26-
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
27-
if major > 3 || (major == 3 && minor >= 9) {
28-
// Force the link mode we want, preferring static by default, but
29-
// possibly overridden by `configure --enable-llvm-link-shared`.
30-
if env::var_os("LLVM_LINK_SHARED").is_some() {
31-
return ("dylib", Some("--link-shared"));
32-
} else {
33-
return ("static", Some("--link-static"));
34-
}
35-
} else if major == 3 && minor == 8 {
36-
// Find out LLVM's default linking mode.
37-
let mut mode_cmd = Command::new(llvm_config);
38-
mode_cmd.arg("--shared-mode");
39-
if output(&mut mode_cmd).trim() == "shared" {
40-
return ("dylib", None);
41-
} else {
42-
return ("static", None);
43-
}
20+
fn detect_llvm_link(major: u32, minor: u32, llvm_config: &Path)
21+
-> (&'static str, Option<&'static str>) {
22+
if major > 3 || (major == 3 && minor >= 9) {
23+
// Force the link mode we want, preferring static by default, but
24+
// possibly overridden by `configure --enable-llvm-link-shared`.
25+
if env::var_os("LLVM_LINK_SHARED").is_some() {
26+
return ("dylib", Some("--link-shared"));
27+
} else {
28+
return ("static", Some("--link-static"));
29+
}
30+
} else if major == 3 && minor == 8 {
31+
// Find out LLVM's default linking mode.
32+
let mut mode_cmd = Command::new(llvm_config);
33+
mode_cmd.arg("--shared-mode");
34+
if output(&mut mode_cmd).trim() == "shared" {
35+
return ("dylib", None);
36+
} else {
37+
return ("static", None);
4438
}
4539
}
4640
("static", None)
@@ -92,9 +86,25 @@ fn main() {
9286
let host = env::var("HOST").expect("HOST was not set");
9387
let is_crossed = target != host;
9488

95-
let optional_components =
96-
["x86", "arm", "aarch64", "mips", "powerpc", "pnacl", "systemz", "jsbackend", "msp430",
97-
"sparc", "nvptx"];
89+
let mut optional_components =
90+
vec!["x86", "arm", "aarch64", "mips", "powerpc", "pnacl",
91+
"systemz", "jsbackend", "msp430", "sparc", "nvptx"];
92+
93+
let mut version_cmd = Command::new(&llvm_config);
94+
version_cmd.arg("--version");
95+
let version_output = output(&mut version_cmd);
96+
let mut parts = version_output.split('.').take(2)
97+
.filter_map(|s| s.parse::<u32>().ok());
98+
let (major, minor) =
99+
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
100+
(major, minor)
101+
} else {
102+
(3, 7)
103+
};
104+
105+
if major > 3 {
106+
optional_components.push("hexagon");
107+
}
98108

99109
// FIXME: surely we don't need all these components, right? Stuff like mcjit
100110
// or interpreter the compiler itself never uses.
@@ -158,7 +168,7 @@ fn main() {
158168
.cpp_link_stdlib(None) // we handle this below
159169
.compile("librustllvm.a");
160170

161-
let (llvm_kind, llvm_link_arg) = detect_llvm_link(&llvm_config);
171+
let (llvm_kind, llvm_link_arg) = detect_llvm_link(major, minor, &llvm_config);
162172

163173
// Link in all LLVM libraries, if we're uwring the "wrong" llvm-config then
164174
// we don't pick up system libs because unfortunately they're for the host

src/librustc_llvm/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ pub fn initialize_available_targets() {
382382
LLVMInitializeNVPTXTarget,
383383
LLVMInitializeNVPTXTargetMC,
384384
LLVMInitializeNVPTXAsmPrinter);
385+
init_target!(llvm_component = "hexagon",
386+
LLVMInitializeHexagonTargetInfo,
387+
LLVMInitializeHexagonTarget,
388+
LLVMInitializeHexagonTargetMC,
389+
LLVMInitializeHexagonAsmPrinter,
390+
LLVMInitializeHexagonAsmParser);
385391
}
386392

387393
pub fn last_error() -> Option<String> {

src/librustc_trans/abi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use cabi_sparc;
2929
use cabi_sparc64;
3030
use cabi_nvptx;
3131
use cabi_nvptx64;
32+
use cabi_hexagon;
3233
use machine::llalign_of_min;
3334
use type_::Type;
3435
use type_of;
@@ -896,6 +897,7 @@ impl<'a, 'tcx> FnType<'tcx> {
896897
"sparc64" => cabi_sparc64::compute_abi_info(ccx, self),
897898
"nvptx" => cabi_nvptx::compute_abi_info(ccx, self),
898899
"nvptx64" => cabi_nvptx64::compute_abi_info(ccx, self),
900+
"hexagon" => cabi_hexagon::compute_abi_info(ccx, self),
899901
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
900902
}
901903

src/librustc_trans/cabi_hexagon.rs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2012-2013 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+
#![allow(non_upper_case_globals)]
12+
13+
use abi::{FnType, ArgType, LayoutExt};
14+
use context::CrateContext;
15+
16+
fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
17+
if ret.layout.is_aggregate() && ret.layout.size(ccx).bits() > 64 {
18+
ret.make_indirect(ccx);
19+
} else {
20+
ret.extend_integer_width_to(32);
21+
}
22+
}
23+
24+
fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
25+
if arg.layout.is_aggregate() && arg.layout.size(ccx).bits() > 64 {
26+
arg.make_indirect(ccx);
27+
} else {
28+
arg.extend_integer_width_to(32);
29+
}
30+
}
31+
32+
pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
33+
if !fty.ret.is_ignore() {
34+
classify_ret_ty(ccx, &mut fty.ret);
35+
}
36+
37+
for arg in &mut fty.args {
38+
if arg.is_ignore() {
39+
continue;
40+
}
41+
classify_arg_ty(ccx, arg);
42+
}
43+
}

src/librustc_trans/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ mod builder;
9797
mod cabi_aarch64;
9898
mod cabi_arm;
9999
mod cabi_asmjs;
100+
mod cabi_hexagon;
100101
mod cabi_mips;
101102
mod cabi_mips64;
102103
mod cabi_msp430;

src/rustllvm/PassWrapper.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
147147
#define SUBTARGET_SPARC
148148
#endif
149149

150+
#ifdef LLVM_COMPONENT_HEXAGON
151+
#define SUBTARGET_HEXAGON SUBTARGET(Hexagon)
152+
#else
153+
#define SUBTARGET_HEXAGON
154+
#endif
155+
150156
#define GEN_SUBTARGETS \
151157
SUBTARGET_X86 \
152158
SUBTARGET_ARM \
@@ -155,7 +161,8 @@ extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
155161
SUBTARGET_PPC \
156162
SUBTARGET_SYSTEMZ \
157163
SUBTARGET_MSP430 \
158-
SUBTARGET_SPARC
164+
SUBTARGET_SPARC \
165+
SUBTARGET_HEXAGON
159166

160167
#define SUBTARGET(x) \
161168
namespace llvm { \

src/rustllvm/llvm-rebuild-trigger

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# If this file is modified, then llvm will be (optionally) cleaned and then rebuilt.
22
# The actual contents of this file do not matter, but to trigger a change on the
33
# build bots then the contents should be changed so git updates the mtime.
4-
2017-03-23
4+
2017-04-25

0 commit comments

Comments
 (0)