Skip to content

Commit d8229b6

Browse files
committed
---
yaml --- r: 273251 b: refs/heads/beta c: de5f824 h: refs/heads/master i: 273249: 03bba67 273247: 216fd9f
1 parent 3288894 commit d8229b6

File tree

14 files changed

+81
-79
lines changed

14 files changed

+81
-79
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: c7172a9935771601a67cdcbedcd2a8cda87367e9
26+
refs/heads/beta: de5f8244f20e434d2e0d351c7f4b55e604b4f3b3
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_llvm/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ bitflags! {
185185
}
186186
}
187187

188-
#[derive(Copy, Clone, Default)]
188+
#[derive(Copy, Clone, Default, Debug)]
189189
pub struct Attributes {
190190
regular: Attribute,
191191
dereferenceable_bytes: u64

branches/beta/src/librustc_trans/trans/abi.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
pub use self::ArgKind::*;
12-
1311
use llvm;
1412
use trans::common::{return_type_is_void, type_is_fat_ptr};
1513
use trans::context::CrateContext;
@@ -43,7 +41,7 @@ pub const FAT_PTR_ADDR: usize = 0;
4341
pub const FAT_PTR_EXTRA: usize = 1;
4442

4543
#[derive(Clone, Copy, PartialEq, Debug)]
46-
pub enum ArgKind {
44+
enum ArgKind {
4745
/// Pass the argument directly using the normal converted
4846
/// LLVM type or by coercing to another specified type
4947
Direct,
@@ -59,7 +57,7 @@ pub enum ArgKind {
5957
/// This is borrowed from clang's ABIInfo.h
6058
#[derive(Clone, Copy, Debug)]
6159
pub struct ArgType {
62-
pub kind: ArgKind,
60+
kind: ArgKind,
6361
/// Original LLVM type
6462
pub original_ty: Type,
6563
/// Sizing LLVM type (pointers are opaque).
@@ -81,28 +79,48 @@ pub struct ArgType {
8179
pub cast: Option<Type>,
8280
/// Dummy argument, which is emitted before the real argument
8381
pub pad: Option<Type>,
84-
/// LLVM attribute of argument
85-
pub attr: Option<llvm::Attribute>
82+
/// LLVM attributes of argument
83+
pub attrs: llvm::Attributes
8684
}
8785

8886
impl ArgType {
8987
fn new(original_ty: Type, ty: Type) -> ArgType {
9088
ArgType {
91-
kind: Direct,
89+
kind: ArgKind::Direct,
9290
original_ty: original_ty,
9391
ty: ty,
9492
cast: None,
9593
pad: None,
96-
attr: None
94+
attrs: llvm::Attributes::default()
9795
}
9896
}
9997

98+
pub fn make_indirect(&mut self, ccx: &CrateContext) {
99+
// Wipe old attributes, likely not valid through indirection.
100+
self.attrs = llvm::Attributes::default();
101+
102+
let llarg_sz = llsize_of_real(ccx, self.ty);
103+
104+
// For non-immediate arguments the callee gets its own copy of
105+
// the value on the stack, so there are no aliases. It's also
106+
// program-invisible so can't possibly capture
107+
self.attrs.set(llvm::Attribute::NoAlias)
108+
.set(llvm::Attribute::NoCapture)
109+
.set_dereferenceable(llarg_sz);
110+
111+
self.kind = ArgKind::Indirect;
112+
}
113+
114+
pub fn ignore(&mut self) {
115+
self.kind = ArgKind::Ignore;
116+
}
117+
100118
pub fn is_indirect(&self) -> bool {
101-
self.kind == Indirect
119+
self.kind == ArgKind::Indirect
102120
}
103121

104122
pub fn is_ignore(&self) -> bool {
105-
self.kind == Ignore
123+
self.kind == ArgKind::Ignore
106124
}
107125
}
108126

@@ -178,7 +196,7 @@ impl FnType {
178196
if ty.is_bool() {
179197
let llty = Type::i1(ccx);
180198
let mut arg = ArgType::new(llty, llty);
181-
arg.attr = Some(llvm::Attribute::ZExt);
199+
arg.attrs.set(llvm::Attribute::ZExt);
182200
arg
183201
} else {
184202
ArgType::new(type_of::type_of(ccx, ty),
@@ -221,7 +239,7 @@ impl FnType {
221239
}
222240
let size = llsize_of_alloc(ccx, arg.ty);
223241
if size > llsize_of_alloc(ccx, ccx.int_type()) {
224-
arg.kind = Indirect;
242+
arg.make_indirect(ccx);
225243
} else if size > 0 {
226244
// We want to pass small aggregates as immediates, but using
227245
// a LLVM aggregate type for this leads to bad optimizations,
@@ -238,6 +256,9 @@ impl FnType {
238256
for arg in &mut fty.args {
239257
fixup(arg);
240258
}
259+
if fty.ret.is_indirect() {
260+
fty.ret.attrs.set(llvm::Attribute::StructRet);
261+
}
241262
return fty;
242263
}
243264

@@ -264,6 +285,10 @@ impl FnType {
264285
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
265286
}
266287

288+
if fty.ret.is_indirect() {
289+
fty.ret.attrs.set(llvm::Attribute::StructRet);
290+
}
291+
267292
fty
268293
}
269294

@@ -302,43 +327,18 @@ impl FnType {
302327
}
303328
}
304329

305-
pub fn llvm_attrs(&self, ccx: &CrateContext) -> llvm::AttrBuilder {
330+
pub fn llvm_attrs(&self) -> llvm::AttrBuilder {
306331
let mut attrs = llvm::AttrBuilder::new();
307332
let mut i = if self.ret.is_indirect() { 1 } else { 0 };
308-
309-
// Add attributes that are always applicable, independent of the concrete foreign ABI
310-
if self.ret.is_indirect() {
311-
let llret_sz = llsize_of_real(ccx, self.ret.ty);
312-
313-
// The outptr can be noalias and nocapture because it's entirely
314-
// invisible to the program. We also know it's nonnull as well
315-
// as how many bytes we can dereference
316-
attrs.arg(i).set(llvm::Attribute::StructRet)
317-
.set(llvm::Attribute::NoAlias)
318-
.set(llvm::Attribute::NoCapture)
319-
.set_dereferenceable(llret_sz);
320-
};
321-
322-
// Add attributes that depend on the concrete foreign ABI
323-
if let Some(attr) = self.ret.attr {
324-
attrs.arg(i).set(attr);
325-
}
326-
333+
*attrs.arg(i) = self.ret.attrs;
327334
i += 1;
328335
for arg in &self.args {
329-
if arg.is_ignore() {
330-
continue;
331-
}
332-
// skip padding
333-
if arg.pad.is_some() { i += 1; }
334-
335-
if let Some(attr) = arg.attr {
336-
attrs.arg(i).set(attr);
336+
if !arg.is_ignore() {
337+
if arg.pad.is_some() { i += 1; }
338+
*attrs.arg(i) = arg.attrs;
339+
i += 1;
337340
}
338-
339-
i += 1;
340341
}
341-
342342
attrs
343343
}
344344
}

branches/beta/src/librustc_trans/trans/cabi_aarch64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![allow(non_upper_case_globals)]
1212

1313
use llvm::{Integer, Pointer, Float, Double, Struct, Array, Vector};
14-
use trans::abi::{FnType, ArgType, Indirect};
14+
use trans::abi::{FnType, ArgType};
1515
use trans::context::CrateContext;
1616
use trans::type_::Type;
1717

@@ -185,7 +185,7 @@ fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) {
185185
ret.cast = Some(llty);
186186
return;
187187
}
188-
ret.kind = Indirect;
188+
ret.make_indirect(ccx);
189189
}
190190

191191
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {
@@ -214,7 +214,7 @@ fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {
214214
arg.cast = Some(llty);
215215
return;
216216
}
217-
arg.kind = Indirect;
217+
arg.make_indirect(ccx);
218218
}
219219

220220
fn is_reg_ty(ty: Type) -> bool {

branches/beta/src/librustc_trans/trans/cabi_arm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![allow(non_upper_case_globals)]
1212

1313
use llvm::{Integer, Pointer, Float, Double, Struct, Array, Vector};
14-
use trans::abi::{FnType, ArgType, Indirect};
14+
use trans::abi::{FnType, ArgType};
1515
use trans::context::CrateContext;
1616
use trans::type_::Type;
1717

@@ -145,7 +145,7 @@ fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType, align_fn: TyAlignFn) {
145145
ret.cast = Some(llty);
146146
return;
147147
}
148-
ret.kind = Indirect;
148+
ret.make_indirect(ccx);
149149
}
150150

151151
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, align_fn: TyAlignFn) {

branches/beta/src/librustc_trans/trans/cabi_asmjs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![allow(non_upper_case_globals)]
1212

1313
use llvm::{Struct, Array, Attribute};
14-
use trans::abi::{FnType, ArgType, Indirect};
14+
use trans::abi::{FnType, ArgType};
1515
use trans::context::CrateContext;
1616
use trans::type_::Type;
1717

@@ -20,36 +20,36 @@ use trans::type_::Type;
2020
// See the https://github.com/kripken/emscripten-fastcomp-clang repository.
2121
// The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions.
2222

23-
fn classify_ret_ty(ret: &mut ArgType) {
23+
fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) {
2424
match ret.ty.kind() {
2525
Struct => {
2626
let field_types = ret.ty.field_types();
2727
if field_types.len() == 1 {
2828
ret.cast = Some(field_types[0]);
2929
} else {
30-
ret.kind = Indirect;
30+
ret.make_indirect(ccx);
3131
}
3232
}
3333
Array => {
34-
ret.kind = Indirect;
34+
ret.make_indirect(ccx);
3535
}
3636
_ => {}
3737
}
3838
}
3939

40-
fn classify_arg_ty(arg: &mut ArgType) {
40+
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {
4141
if arg.ty.is_aggregate() {
42-
arg.kind = Indirect;
43-
arg.attr = Some(Attribute::ByVal);
42+
arg.make_indirect(ccx);
43+
arg.attrs.set(Attribute::ByVal);
4444
}
4545
}
4646

4747
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
4848
if fty.ret.ty != Type::void(ccx) {
49-
classify_ret_ty(&mut fty.ret);
49+
classify_ret_ty(ccx, &mut fty.ret);
5050
}
5151

5252
for arg in &mut fty.args {
53-
classify_arg_ty(arg);
53+
classify_arg_ty(ccx, arg);
5454
}
5555
}

branches/beta/src/librustc_trans/trans/cabi_mips.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use libc::c_uint;
1414
use std::cmp;
1515
use llvm;
1616
use llvm::{Integer, Pointer, Float, Double, Struct, Array, Vector};
17-
use trans::abi::{ArgType, FnType, Indirect};
17+
use trans::abi::{ArgType, FnType};
1818
use trans::context::CrateContext;
1919
use trans::type_::Type;
2020

@@ -148,7 +148,7 @@ fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
148148
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
149149
if fty.ret.ty != Type::void(ccx) {
150150
if !is_reg_ty(fty.ret.ty) {
151-
fty.ret.kind = Indirect;
151+
fty.ret.make_indirect(ccx);
152152
}
153153
}
154154

branches/beta/src/librustc_trans/trans/cabi_powerpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use libc::c_uint;
1212
use llvm;
1313
use llvm::{Integer, Pointer, Float, Double, Struct, Array};
14-
use trans::abi::{FnType, ArgType, Indirect};
14+
use trans::abi::{FnType, ArgType};
1515
use trans::context::CrateContext;
1616
use trans::type_::Type;
1717

@@ -143,7 +143,7 @@ fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
143143
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
144144
if fty.ret.ty != Type::void(ccx) {
145145
if !is_reg_ty(fty.ret.ty) {
146-
fty.ret.kind = Indirect;
146+
fty.ret.make_indirect(ccx);
147147
}
148148
}
149149

branches/beta/src/librustc_trans/trans/cabi_powerpc64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// need to be fixed when PowerPC vector support is added.
1717

1818
use llvm::{Integer, Pointer, Float, Double, Struct, Array};
19-
use trans::abi::{FnType, ArgType, Indirect};
19+
use trans::abi::{FnType, ArgType};
2020
use trans::context::CrateContext;
2121
use trans::type_::Type;
2222

@@ -158,7 +158,7 @@ fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) {
158158

159159
// The PowerPC64 big endian ABI doesn't return aggregates in registers
160160
if ccx.sess().target.target.target_endian == "big" {
161-
ret.kind = Indirect;
161+
ret.make_indirect(ccx);
162162
}
163163

164164
if let Some((base_ty, members)) = is_homogenous_aggregate_ty(ret.ty) {
@@ -182,7 +182,7 @@ fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) {
182182
return;
183183
}
184184

185-
ret.kind = Indirect;
185+
ret.make_indirect(ccx);
186186
}
187187

188188
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {

branches/beta/src/librustc_trans/trans/cabi_x86.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use llvm::*;
12-
use trans::abi::{FnType, Indirect, Ignore};
12+
use trans::abi::FnType;
1313
use trans::type_::Type;
1414
use super::common::*;
1515
use super::machine::*;
@@ -30,20 +30,20 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
3030
2 => fty.ret.cast = Some(Type::i16(ccx)),
3131
4 => fty.ret.cast = Some(Type::i32(ccx)),
3232
8 => fty.ret.cast = Some(Type::i64(ccx)),
33-
_ => fty.ret.kind = Indirect
33+
_ => fty.ret.make_indirect(ccx)
3434
}
3535
} else {
36-
fty.ret.kind = Indirect;
36+
fty.ret.make_indirect(ccx);
3737
}
3838
}
3939

4040
for arg in &mut fty.args {
4141
if arg.ty.kind() == Struct {
4242
if llsize_of_alloc(ccx, arg.ty) == 0 {
43-
arg.kind = Ignore;
43+
arg.ignore();
4444
} else {
45-
arg.kind = Indirect;
46-
arg.attr = Some(Attribute::ByVal);
45+
arg.make_indirect(ccx);
46+
arg.attrs.set(Attribute::ByVal);
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)