Skip to content

Commit 077f4ee

Browse files
committed
Auto merge of #30567 - steffengy:master, r=alexcrichton
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
2 parents 1f516dc + 4396a2d commit 077f4ee

File tree

8 files changed

+81
-6
lines changed

8 files changed

+81
-6
lines changed

src/doc/book/ffi.md

+2
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ are:
478478
* `aapcs`
479479
* `cdecl`
480480
* `fastcall`
481+
* `vectorcall`
482+
This is currently hidden behind the `abi_vectorcall` gate and is subject to change.
481483
* `Rust`
482484
* `rust-intrinsic`
483485
* `system`

src/doc/reference.md

+3
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,9 @@ The currently implemented features of the reference compiler are:
23902390

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

2393+
* - `abi_vectorcall` - Allows the usage of the vectorcall calling convention
2394+
(e.g. `extern "vectorcall" func fn_();`)
2395+
23932396
If a feature is promoted to a language feature, then all existing programs will
23942397
start to receive compilation warnings about `#![feature]` directives which enabled
23952398
the new feature (because the directive is no longer necessary). However, if a

src/librustc_llvm/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub enum CallConv {
8585
X86StdcallCallConv = 64,
8686
X86FastcallCallConv = 65,
8787
X86_64_Win64 = 79,
88+
X86_VectorCall = 80
8889
}
8990

9091
#[derive(Copy, Clone)]

src/librustc_trans/trans/foreign.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ use std::cmp;
3535
use std::iter::once;
3636
use libc::c_uint;
3737
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
38-
use syntax::abi::{PlatformIntrinsic, RustIntrinsic, Rust, RustCall, Stdcall, Fastcall, System};
38+
use syntax::abi::{PlatformIntrinsic, RustIntrinsic, Rust, RustCall, Stdcall};
39+
use syntax::abi::{Fastcall, Vectorcall, System};
3940
use syntax::attr;
4041
use syntax::codemap::Span;
4142
use syntax::parse::token::{InternedString, special_idents};
@@ -104,6 +105,7 @@ pub fn llvm_calling_convention(ccx: &CrateContext,
104105

105106
Stdcall => llvm::X86StdcallCallConv,
106107
Fastcall => llvm::X86FastcallCallConv,
108+
Vectorcall => llvm::X86_VectorCall,
107109
C => llvm::CCallConv,
108110
Win64 => llvm::X86_64_Win64,
109111

src/libsyntax/abi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub enum Abi {
3939
Cdecl,
4040
Stdcall,
4141
Fastcall,
42+
Vectorcall,
4243
Aapcs,
4344
Win64,
4445

@@ -85,6 +86,7 @@ const AbiDatas: &'static [AbiData] = &[
8586
AbiData {abi: Cdecl, name: "cdecl" },
8687
AbiData {abi: Stdcall, name: "stdcall" },
8788
AbiData {abi: Fastcall, name: "fastcall" },
89+
AbiData {abi: Vectorcall, name: "vectorcall"},
8890
AbiData {abi: Aapcs, name: "aapcs" },
8991
AbiData {abi: Win64, name: "win64" },
9092

src/libsyntax/feature_gate.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
239239

240240
// Allows cfg(target_thread_local)
241241
("cfg_target_thread_local", "1.7.0", Some(29594), Active),
242+
243+
// rustc internal
244+
("abi_vectorcall", "1.7.0", None, Active)
242245
];
243246
// (changing above list without updating src/doc/reference.md makes @cmr sad)
244247

@@ -872,6 +875,11 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
872875
Abi::PlatformIntrinsic => {
873876
Some(("platform_intrinsics",
874877
"platform intrinsics are experimental and possibly buggy"))
878+
},
879+
Abi::Vectorcall => {
880+
Some(("abi_vectorcall",
881+
"vectorcall is experimental and subject to change"
882+
))
875883
}
876884
_ => None
877885
};
@@ -1045,11 +1053,17 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
10451053
"intrinsics are subject to change")
10461054
}
10471055
FnKind::ItemFn(_, _, _, _, abi, _) |
1048-
FnKind::Method(_, &ast::MethodSig { abi, .. }, _) if abi == Abi::RustCall => {
1049-
self.gate_feature("unboxed_closures",
1050-
span,
1051-
"rust-call ABI is subject to change")
1052-
}
1056+
FnKind::Method(_, &ast::MethodSig { abi, .. }, _) => match abi {
1057+
Abi::RustCall => {
1058+
self.gate_feature("unboxed_closures", span,
1059+
"rust-call ABI is subject to change");
1060+
},
1061+
Abi::Vectorcall => {
1062+
self.gate_feature("abi_vectorcall", span,
1063+
"vectorcall is experimental and subject to change");
1064+
},
1065+
_ => {}
1066+
},
10531067
_ => {}
10541068
}
10551069
visit::walk_fn(self, fn_kind, fn_decl, block, span);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
extern "vectorcall" { //~ ERROR vectorcall is experimental and subject to change
12+
fn bar();
13+
}
14+
15+
extern "vectorcall" fn baz() { //~ ERROR vectorcall is experimental and subject to change
16+
}
17+
18+
fn main() {
19+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
#![feature(abi_vectorcall)]
12+
13+
trait A {
14+
extern "vectorcall" fn test1(i: i32);
15+
}
16+
17+
struct S;
18+
19+
impl A for S {
20+
extern "vectorcall" fn test1(i: i32) {
21+
assert_eq!(i, 1);
22+
}
23+
}
24+
25+
extern "vectorcall" fn test2(i: i32) {
26+
assert_eq!(i, 2);
27+
}
28+
29+
fn main() {
30+
<S as A>::test1(1);
31+
test2(2);
32+
}

0 commit comments

Comments
 (0)