Skip to content

Commit c558a2a

Browse files
committed
Add Hexagon support
This requires an updated LLVM with D31999 and D32000 to build libcore. A basic hello world builds and runs successfully on the hexagon simulator.
1 parent 0777c75 commit c558a2a

File tree

6 files changed

+61
-2
lines changed

6 files changed

+61
-2
lines changed

src/librustc_llvm/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn main() {
9494

9595
let optional_components =
9696
["x86", "arm", "aarch64", "mips", "powerpc", "pnacl", "systemz", "jsbackend", "msp430",
97-
"sparc", "nvptx"];
97+
"sparc", "nvptx", "hexagon"];
9898

9999
// FIXME: surely we don't need all these components, right? Stuff like mcjit
100100
// or interpreter the compiler itself never uses.

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 { \

0 commit comments

Comments
 (0)