|
1 |
| -//! Utility handlers for 32 bit and 64 bit nvptx targets |
2 |
| -//! |
3 |
| -//! NVVM IR only supports nvptx64-nvidia-cuda and nvptx-nvidia-cuda |
4 |
| -//! Therefore we completely ignore the target set in the session. |
5 |
| -//! This allows the user to cfg for targets like arm/x86/etc while still |
6 |
| -//! compiling for nvptx |
7 |
| -
|
8 | 1 | use crate::llvm::{self, Type};
|
9 | 2 | use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, Target, TargetOptions};
|
10 |
| -use std::sync::atomic::{AtomicBool, Ordering}; |
11 |
| - |
12 |
| -/// Whether we are compiling for 32 bit (nvptx-nvidia-cuda). |
13 |
| -/// This is a global variable so we don't have to pass around a variable to |
14 |
| -/// a lot of things when this never varies across codegen invocations. |
15 |
| -static TARGET_32_BIT: AtomicBool = AtomicBool::new(false); |
16 | 3 |
|
17 |
| -/// The data layouts of NVVM targets |
18 |
| -/// <https://docs.nvidia.com/cuda/nvvm-ir-spec/index.html#data-layout> |
19 |
| -pub fn data_layout() -> &'static str { |
20 |
| - if TARGET_32_BIT.load(Ordering::SeqCst) { |
21 |
| - "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" |
22 |
| - } else { |
23 |
| - "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" |
24 |
| - } |
25 |
| -} |
26 |
| - |
27 |
| -/// The target triples of NVVM targets |
28 |
| -/// <https://docs.nvidia.com/cuda/nvvm-ir-spec/index.html#target-triple> |
29 |
| -pub fn target_triple() -> &'static str { |
30 |
| - if TARGET_32_BIT.load(Ordering::SeqCst) { |
31 |
| - "nvptx-nvidia-cuda" |
32 |
| - } else { |
33 |
| - "nvptx64-nvidia-cuda" |
34 |
| - } |
35 |
| -} |
| 4 | +pub const DATA_LAYOUT: &str = "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"; |
| 5 | +pub const TARGET_TRIPLE: &str = "nvptx64-nvidia-cuda"; |
| 6 | +pub const POINTER_WIDTH: u32 = 64; |
36 | 7 |
|
37 | 8 | /// The pointer width of the current target
|
38 | 9 | pub(crate) unsafe fn usize_ty(llcx: &'_ llvm::Context) -> &'_ Type {
|
39 |
| - if TARGET_32_BIT.load(Ordering::SeqCst) { |
40 |
| - llvm::LLVMInt32TypeInContext(llcx) |
41 |
| - } else { |
42 |
| - llvm::LLVMInt64TypeInContext(llcx) |
43 |
| - } |
44 |
| -} |
45 |
| - |
46 |
| -pub fn pointer_size() -> usize { |
47 |
| - if TARGET_32_BIT.load(Ordering::SeqCst) { |
48 |
| - 32 |
49 |
| - } else { |
50 |
| - 64 |
51 |
| - } |
| 10 | + llvm::LLVMInt64TypeInContext(llcx) |
52 | 11 | }
|
53 | 12 |
|
54 | 13 | pub fn target() -> Target {
|
55 | 14 | Target {
|
56 | 15 | arch: "nvptx".to_string(),
|
57 |
| - data_layout: data_layout().to_string(), |
58 |
| - llvm_target: target_triple().to_string(), |
59 |
| - pointer_width: pointer_size() as u32, |
| 16 | + data_layout: DATA_LAYOUT.to_string(), |
| 17 | + llvm_target: "nvptx64-nvidia-cuda".to_string(), |
| 18 | + pointer_width: 64, |
60 | 19 |
|
61 | 20 | options: TargetOptions {
|
62 | 21 | os: "cuda".to_string(),
|
|
0 commit comments