use crate::llvm::{self, Type};
use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, Target, TargetOptions};
use std::sync::atomic::{AtomicBool, Ordering};
static TARGET_32_BIT: AtomicBool = AtomicBool::new(false);
pub fn data_layout() -> &'static str {
if TARGET_32_BIT.load(Ordering::SeqCst) {
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
} else {
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
}
}
pub fn target_triple() -> &'static str {
if TARGET_32_BIT.load(Ordering::SeqCst) {
"nvptx-nvidia-cuda"
} else {
"nvptx64-nvidia-cuda"
}
}
pub(crate) unsafe fn usize_ty(llcx: &'_ llvm::Context) -> &'_ Type {
if TARGET_32_BIT.load(Ordering::SeqCst) {
llvm::LLVMInt32TypeInContext(llcx)
} else {
llvm::LLVMInt64TypeInContext(llcx)
}
}
pub fn pointer_size() -> usize {
if TARGET_32_BIT.load(Ordering::SeqCst) {
32
} else {
64
}
}
pub fn target() -> Target {
Target {
arch: "nvptx".to_string(),
data_layout: data_layout().to_string(),
llvm_target: target_triple().to_string(),
pointer_width: pointer_size() as u32,
options: TargetOptions {
os: "cuda".to_string(),
vendor: "nvidia".to_string(),
linker_flavor: LinkerFlavor::PtxLinker,
linker: None,
cpu: "sm_30".to_string(),
max_atomic_width: Some(64),
panic_strategy: PanicStrategy::Abort,
dynamic_linking: true,
executables: true,
only_cdylib: true,
obj_is_bitcode: true,
dll_prefix: "".to_string(),
dll_suffix: ".ptx".to_string(),
exe_suffix: ".ptx".to_string(),
merge_functions: MergeFunctions::Disabled,
..Default::default()
},
}
}