]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/cabi_nvptx.rs
5ece19f764a8ac2572f9161815e7f62a9040c22e
[rust.git] / src / librustc_trans / cabi_nvptx.rs
1 // Copyright 2016 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 // Reference: PTX Writer's Guide to Interoperability
12 // http://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability
13
14 #![allow(non_upper_case_globals)]
15
16 use llvm::Struct;
17
18 use abi::{self, ArgType, FnType};
19 use context::CrateContext;
20 use type_::Type;
21
22 fn ty_size(ty: Type) -> usize {
23     abi::ty_size(ty, 4)
24 }
25
26 fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) {
27     if ret.ty.kind() == Struct && ty_size(ret.ty) > 32 {
28         ret.make_indirect(ccx);
29     } else {
30         ret.extend_integer_width_to(32);
31     }
32 }
33
34 fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {
35     if arg.ty.kind() == Struct && ty_size(arg.ty) > 32 {
36         arg.make_indirect(ccx);
37     } else {
38         arg.extend_integer_width_to(32);
39     }
40 }
41
42 pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
43     if !fty.ret.is_ignore() {
44         classify_ret_ty(ccx, &mut fty.ret);
45     }
46
47     for arg in &mut fty.args {
48         if arg.is_ignore() {
49             continue;
50         }
51         classify_arg_ty(ccx, arg);
52     }
53 }