1
Fork 0

add rustc_codegen_ssa support for csky and correct some code

This commit is contained in:
Dirreke 2023-07-14 19:16:38 +08:00 committed by dirreke
parent 8ed7aa16bd
commit 8c51e28bd5
7 changed files with 26 additions and 3 deletions

View file

@ -209,6 +209,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
"hexagon" => Architecture::Hexagon, "hexagon" => Architecture::Hexagon,
"bpf" => Architecture::Bpf, "bpf" => Architecture::Bpf,
"loongarch64" => Architecture::LoongArch64, "loongarch64" => Architecture::LoongArch64,
"csky" => Architecture::Csky,
// Unsupported architecture. // Unsupported architecture.
_ => return None, _ => return None,
}; };
@ -307,6 +308,13 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
// the appropriate EF_AVR_ARCH flag. // the appropriate EF_AVR_ARCH flag.
ef_avr_arch(&sess.target.options.cpu) ef_avr_arch(&sess.target.options.cpu)
} }
Architecture::Csky => {
let e_flags = match sess.target.options.abi.as_ref() {
"abiv2" => elf::EF_CSKY_ABIV2,
_ => elf::EF_CSKY_ABIV1,
};
e_flags
}
_ => 0, _ => 0,
}; };
// adapted from LLVM's `MCELFObjectTargetWriter::getOSABI` // adapted from LLVM's `MCELFObjectTargetWriter::getOSABI`

View file

@ -296,6 +296,16 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))]; const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
const CSKY_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("hard-float", Some(sym::csky_target_feature)),
("hard-float-abi", Some(sym::csky_target_feature)),
("fpuv2_sf", Some(sym::csky_target_feature)),
("fpuv2_df", Some(sym::csky_target_feature)),
("fpuv3_sf", Some(sym::csky_target_feature)),
("fpuv3_df", Some(sym::csky_target_feature)),
("vdspv2", Some(sym::csky_target_feature)),
("dspv2", Some(sym::csky_target_feature)),
];
/// When rustdoc is running, provide a list of all known features so that all their respective /// When rustdoc is running, provide a list of all known features so that all their respective
/// primitives may be documented. /// primitives may be documented.
/// ///
@ -311,6 +321,7 @@ pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol
.chain(RISCV_ALLOWED_FEATURES.iter()) .chain(RISCV_ALLOWED_FEATURES.iter())
.chain(WASM_ALLOWED_FEATURES.iter()) .chain(WASM_ALLOWED_FEATURES.iter())
.chain(BPF_ALLOWED_FEATURES.iter()) .chain(BPF_ALLOWED_FEATURES.iter())
.chain(CSKY_ALLOWED_FEATURES)
.cloned() .cloned()
} }
@ -325,6 +336,7 @@ pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Opt
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES, "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES, "wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
"bpf" => BPF_ALLOWED_FEATURES, "bpf" => BPF_ALLOWED_FEATURES,
"csky" => CSKY_ALLOWED_FEATURES,
_ => &[], _ => &[],
} }
} }
@ -396,6 +408,7 @@ pub fn from_target_feature(
Some(sym::ermsb_target_feature) => rust_features.ermsb_target_feature, Some(sym::ermsb_target_feature) => rust_features.ermsb_target_feature,
Some(sym::bpf_target_feature) => rust_features.bpf_target_feature, Some(sym::bpf_target_feature) => rust_features.bpf_target_feature,
Some(sym::aarch64_ver_target_feature) => rust_features.aarch64_ver_target_feature, Some(sym::aarch64_ver_target_feature) => rust_features.aarch64_ver_target_feature,
Some(sym::csky_target_feature) => rust_features.csky_target_feature,
Some(name) => bug!("unknown target feature gate {}", name), Some(name) => bug!("unknown target feature gate {}", name),
None => true, None => true,
}; };

View file

@ -282,6 +282,7 @@ declare_features! (
(active, arm_target_feature, "1.27.0", Some(44839), None), (active, arm_target_feature, "1.27.0", Some(44839), None),
(active, avx512_target_feature, "1.27.0", Some(44839), None), (active, avx512_target_feature, "1.27.0", Some(44839), None),
(active, bpf_target_feature, "1.54.0", Some(44839), None), (active, bpf_target_feature, "1.54.0", Some(44839), None),
(active, csky_target_feature, "1.72.0", Some(44839), None),
(active, ermsb_target_feature, "1.49.0", Some(44839), None), (active, ermsb_target_feature, "1.49.0", Some(44839), None),
(active, hexagon_target_feature, "1.27.0", Some(44839), None), (active, hexagon_target_feature, "1.27.0", Some(44839), None),
(active, mips_target_feature, "1.27.0", Some(44839), None), (active, mips_target_feature, "1.27.0", Some(44839), None),

View file

@ -574,6 +574,7 @@ symbols! {
crate_type, crate_type,
crate_visibility_modifier, crate_visibility_modifier,
crt_dash_static: "crt-static", crt_dash_static: "crt-static",
csky_target_feature,
cstring_type, cstring_type,
ctlz, ctlz,
ctlz_nonzero, ctlz_nonzero,

View file

@ -6,7 +6,7 @@ use crate::spec::{Target, TargetOptions};
pub fn target() -> Target { pub fn target() -> Target {
Target { Target {
//https://github.com/llvm/llvm-project/blob/8b76aea8d8b1b71f6220bc2845abc749f18a19b7/clang/lib/Basic/Targets/CSKY.h //https://github.com/llvm/llvm-project/blob/8b76aea8d8b1b71f6220bc2845abc749f18a19b7/clang/lib/Basic/Targets/CSKY.h
llvm_target: "csky-unknown-linux".into(), llvm_target: "csky-unknown-linux-gnuabiv2".into(),
pointer_width: 32, pointer_width: 32,
data_layout: "e-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-a:0:32-Fi32-n32".into(), data_layout: "e-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-a:0:32-Fi32-n32".into(),
arch: "csky".into(), arch: "csky".into(),

View file

@ -2,7 +2,7 @@
**Tier: 3** **Tier: 3**
This target supports [C-SKY](https://github.com/c-sky) v2 CPUs with `glibc`. This target supports [C-SKY](https://github.com/c-sky) CPUs with `abi` v2 and `glibc`.
https://c-sky.github.io/ https://c-sky.github.io/
## Target maintainers ## Target maintainers

View file

@ -4,7 +4,7 @@ warning: unexpected `cfg` condition value
LL | #[cfg(target(os = "linux", arch = "X"))] LL | #[cfg(target(os = "linux", arch = "X"))]
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64` = note: expected values for `target_arch` are: `aarch64`, `arm`, `avr`, `bpf`, `csky`, `hexagon`, `loongarch64`, `m68k`, `mips`, `mips32r6`, `mips64`, `mips64r6`, `msp430`, `nvptx64`, `powerpc`, `powerpc64`, `riscv32`, `riscv64`, `s390x`, `sparc`, `sparc64`, `wasm32`, `wasm64`, `x86`, `x86_64`
= note: `#[warn(unexpected_cfgs)]` on by default = note: `#[warn(unexpected_cfgs)]` on by default
warning: 1 warning emitted warning: 1 warning emitted