Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm: Add support for vectorcall (X86_VectorCall) convention #30567

Merged
merged 3 commits into from
Jan 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -862,6 +865,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 @@ -1033,11 +1041,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);
}