Skip to content

Commit

Permalink
Auto merge of #30567 - steffengy:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Add support to use functions exported using vectorcall.
This essentially only allows to pass a new LLVM calling convention
from rust to LLVM.

```rust
extern "vectorcall" fn abc(param: c_void);
```

references
----
http://llvm.org/docs/doxygen/html/CallingConv_8h_source.html
https://msdn.microsoft.com/en-us/library/dn375768.aspx
  • Loading branch information
bors committed Jan 16, 2016
2 parents 1f516dc + 4396a2d commit 077f4ee
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/doc/book/ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ are:
* `aapcs`
* `cdecl`
* `fastcall`
* `vectorcall`
This is currently hidden behind the `abi_vectorcall` gate and is subject to change.
* `Rust`
* `rust-intrinsic`
* `system`
Expand Down
3 changes: 3 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2390,6 +2390,9 @@ The currently implemented features of the reference compiler are:

* - `type_ascription` - Allows type ascription expressions `expr: Type`.

* - `abi_vectorcall` - Allows the usage of the vectorcall calling convention
(e.g. `extern "vectorcall" func fn_();`)

If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about `#![feature]` directives which enabled
the new feature (because the directive is no longer necessary). However, if a
Expand Down
1 change: 1 addition & 0 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub enum CallConv {
X86StdcallCallConv = 64,
X86FastcallCallConv = 65,
X86_64_Win64 = 79,
X86_VectorCall = 80
}

#[derive(Copy, Clone)]
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_trans/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ use std::cmp;
use std::iter::once;
use libc::c_uint;
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
use syntax::abi::{PlatformIntrinsic, RustIntrinsic, Rust, RustCall, Stdcall, Fastcall, System};
use syntax::abi::{PlatformIntrinsic, RustIntrinsic, Rust, RustCall, Stdcall};
use syntax::abi::{Fastcall, Vectorcall, System};
use syntax::attr;
use syntax::codemap::Span;
use syntax::parse::token::{InternedString, special_idents};
Expand Down Expand Up @@ -104,6 +105,7 @@ pub fn llvm_calling_convention(ccx: &CrateContext,

Stdcall => llvm::X86StdcallCallConv,
Fastcall => llvm::X86FastcallCallConv,
Vectorcall => llvm::X86_VectorCall,
C => llvm::CCallConv,
Win64 => llvm::X86_64_Win64,

Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub enum Abi {
Cdecl,
Stdcall,
Fastcall,
Vectorcall,
Aapcs,
Win64,

Expand Down Expand Up @@ -85,6 +86,7 @@ const AbiDatas: &'static [AbiData] = &[
AbiData {abi: Cdecl, name: "cdecl" },
AbiData {abi: Stdcall, name: "stdcall" },
AbiData {abi: Fastcall, name: "fastcall" },
AbiData {abi: Vectorcall, name: "vectorcall"},
AbiData {abi: Aapcs, name: "aapcs" },
AbiData {abi: Win64, name: "win64" },

Expand Down
24 changes: 19 additions & 5 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status

// Allows cfg(target_thread_local)
("cfg_target_thread_local", "1.7.0", Some(29594), Active),

// rustc internal
("abi_vectorcall", "1.7.0", None, Active)
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)

Expand Down Expand Up @@ -872,6 +875,11 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
Abi::PlatformIntrinsic => {
Some(("platform_intrinsics",
"platform intrinsics are experimental and possibly buggy"))
},
Abi::Vectorcall => {
Some(("abi_vectorcall",
"vectorcall is experimental and subject to change"
))
}
_ => None
};
Expand Down Expand Up @@ -1045,11 +1053,17 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
"intrinsics are subject to change")
}
FnKind::ItemFn(_, _, _, _, abi, _) |
FnKind::Method(_, &ast::MethodSig { abi, .. }, _) if abi == Abi::RustCall => {
self.gate_feature("unboxed_closures",
span,
"rust-call ABI is subject to change")
}
FnKind::Method(_, &ast::MethodSig { abi, .. }, _) => match abi {
Abi::RustCall => {
self.gate_feature("unboxed_closures", span,
"rust-call ABI is subject to change");
},
Abi::Vectorcall => {
self.gate_feature("abi_vectorcall", span,
"vectorcall is experimental and subject to change");
},
_ => {}
},
_ => {}
}
visit::walk_fn(self, fn_kind, fn_decl, block, span);
Expand Down
19 changes: 19 additions & 0 deletions src/test/compile-fail/feature-gate-abi-vectorcall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern "vectorcall" { //~ ERROR vectorcall is experimental and subject to change
fn bar();
}

extern "vectorcall" fn baz() { //~ ERROR vectorcall is experimental and subject to change
}

fn main() {
}
32 changes: 32 additions & 0 deletions src/test/run-pass/extern-vectorcall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(abi_vectorcall)]

trait A {
extern "vectorcall" fn test1(i: i32);
}

struct S;

impl A for S {
extern "vectorcall" fn test1(i: i32) {
assert_eq!(i, 1);
}
}

extern "vectorcall" fn test2(i: i32) {
assert_eq!(i, 2);
}

fn main() {
<S as A>::test1(1);
test2(2);
}

0 comments on commit 077f4ee

Please sign in to comment.