Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
30ec363c
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
30ec363c
编写于
8月 15, 2015
作者:
D
Dylan McKay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce rustc::trans's dependence on pointer width
上级
7ebc5e51
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
41 deletion
+32
-41
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/base.rs
+4
-11
src/librustc_trans/trans/common.rs
src/librustc_trans/trans/common.rs
+10
-8
src/librustc_trans/trans/context.rs
src/librustc_trans/trans/context.rs
+9
-6
src/librustc_trans/trans/intrinsic.rs
src/librustc_trans/trans/intrinsic.rs
+9
-16
未找到文件。
src/librustc_trans/trans/base.rs
浏览文件 @
30ec363c
...
...
@@ -943,11 +943,8 @@ pub fn call_lifetime_end(cx: Block, ptr: ValueRef) {
pub
fn
call_memcpy
(
cx
:
Block
,
dst
:
ValueRef
,
src
:
ValueRef
,
n_bytes
:
ValueRef
,
align
:
u32
)
{
let
_
icx
=
push_ctxt
(
"call_memcpy"
);
let
ccx
=
cx
.ccx
();
let
key
=
match
&
ccx
.sess
()
.target.target.target_pointer_width
[
..
]
{
"32"
=>
"llvm.memcpy.p0i8.p0i8.i32"
,
"64"
=>
"llvm.memcpy.p0i8.p0i8.i64"
,
tws
=>
panic!
(
"Unsupported target word size for memcpy: {}"
,
tws
),
};
let
ptr_width
=
&
ccx
.sess
()
.target.target.target_pointer_width
[
..
];
let
key
=
format!
(
"llvm.memcpy.p0i8.p0i8.i{}"
,
ptr_width
);
let
memcpy
=
ccx
.get_intrinsic
(
&
key
);
let
src_ptr
=
PointerCast
(
cx
,
src
,
Type
::
i8p
(
ccx
));
let
dst_ptr
=
PointerCast
(
cx
,
dst
,
Type
::
i8p
(
ccx
));
...
...
@@ -996,12 +993,8 @@ fn memfill<'a, 'tcx>(b: &Builder<'a, 'tcx>, llptr: ValueRef, ty: Ty<'tcx>, byte:
let
ccx
=
b
.ccx
;
let
llty
=
type_of
::
type_of
(
ccx
,
ty
);
let
intrinsic_key
=
match
&
ccx
.sess
()
.target.target.target_pointer_width
[
..
]
{
"32"
=>
"llvm.memset.p0i8.i32"
,
"64"
=>
"llvm.memset.p0i8.i64"
,
tws
=>
panic!
(
"Unsupported target word size for memset: {}"
,
tws
),
};
let
ptr_width
=
&
ccx
.sess
()
.target.target.target_pointer_width
[
..
];
let
intrinsic_key
=
format!
(
"llvm.memset.p0i8.i{}"
,
ptr_width
);
let
llintrinsicfn
=
ccx
.get_intrinsic
(
&
intrinsic_key
);
let
llptr
=
b
.pointercast
(
llptr
,
Type
::
i8
(
ccx
)
.ptr_to
());
...
...
src/librustc_trans/trans/common.rs
浏览文件 @
30ec363c
...
...
@@ -833,10 +833,11 @@ pub fn C_u64(ccx: &CrateContext, i: u64) -> ValueRef {
pub
fn
C_int
<
I
:
AsI64
>
(
ccx
:
&
CrateContext
,
i
:
I
)
->
ValueRef
{
let
v
=
i
.as_i64
();
match
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
())
{
32
=>
assert
!
(
v
<
(
1
<<
31
)
&&
v
>=
-
(
1
<<
31
)),
64
=>
{},
n
=>
panic!
(
"unsupported target size: {}"
,
n
)
let
bit_size
=
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
());
if
bit_size
<
64
{
// make sure it doesn't overflow
assert
!
(
v
<
(
1
<<
(
bit_size
-
1
))
&&
v
>=
-
(
1
<<
(
bit_size
-
1
)));
}
C_integral
(
ccx
.int_type
(),
v
as
u64
,
true
)
...
...
@@ -845,10 +846,11 @@ pub fn C_int<I: AsI64>(ccx: &CrateContext, i: I) -> ValueRef {
pub
fn
C_uint
<
I
:
AsU64
>
(
ccx
:
&
CrateContext
,
i
:
I
)
->
ValueRef
{
let
v
=
i
.as_u64
();
match
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
())
{
32
=>
assert
!
(
v
<
(
1
<<
32
)),
64
=>
{},
n
=>
panic!
(
"unsupported target size: {}"
,
n
)
let
bit_size
=
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
());
if
bit_size
<
64
{
// make sure it doesn't overflow
assert
!
(
v
<
(
1
<<
bit_size
));
}
C_integral
(
ccx
.int_type
(),
v
,
false
)
...
...
src/librustc_trans/trans/context.rs
浏览文件 @
30ec363c
...
...
@@ -560,7 +560,7 @@ pub fn raw_builder<'a>(&'a self) -> BuilderRef {
self
.local.builder.b
}
pub
fn
get_intrinsic
(
&
self
,
key
:
&
&
'static
str
)
->
ValueRef
{
pub
fn
get_intrinsic
(
&
self
,
key
:
&
str
)
->
ValueRef
{
if
let
Some
(
v
)
=
self
.intrinsics
()
.borrow
()
.get
(
key
)
.cloned
()
{
return
v
;
}
...
...
@@ -791,10 +791,10 @@ pub fn use_dll_storage_attrs(&self) -> bool {
}
/// Declare any llvm intrinsics that you might need
fn
declare_intrinsic
(
ccx
:
&
CrateContext
,
key
:
&
&
'static
str
)
->
Option
<
ValueRef
>
{
fn
declare_intrinsic
(
ccx
:
&
CrateContext
,
key
:
&
str
)
->
Option
<
ValueRef
>
{
macro_rules!
ifn
{
(
$name:expr
,
fn
()
->
$ret:expr
)
=>
(
if
*
key
==
$name
{
if
key
==
$name
{
let
f
=
declare
::
declare_cfn
(
ccx
,
$name
,
Type
::
func
(
&
[],
&
$ret
),
ccx
.tcx
()
.mk_nil
());
ccx
.intrinsics
()
.borrow_mut
()
.insert
(
$name
,
f
.clone
());
...
...
@@ -802,7 +802,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
}
);
(
$name:expr
,
fn
(
$
(
$arg:expr
),
*
)
->
$ret:expr
)
=>
(
if
*
key
==
$name
{
if
key
==
$name
{
let
f
=
declare
::
declare_cfn
(
ccx
,
$name
,
Type
::
func
(
&
[
$
(
$arg
),
*
],
&
$ret
),
ccx
.tcx
()
.mk_nil
());
ccx
.intrinsics
()
.borrow_mut
()
.insert
(
$name
,
f
.clone
());
...
...
@@ -824,10 +824,13 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
let
t_f32
=
Type
::
f32
(
ccx
);
let
t_f64
=
Type
::
f64
(
ccx
);
ifn!
(
"llvm.memcpy.p0i8.p0i8.i16"
,
fn
(
i8p
,
i8p
,
t_i16
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memcpy.p0i8.p0i8.i32"
,
fn
(
i8p
,
i8p
,
t_i32
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memcpy.p0i8.p0i8.i64"
,
fn
(
i8p
,
i8p
,
t_i64
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memmove.p0i8.p0i8.i16"
,
fn
(
i8p
,
i8p
,
t_i16
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memmove.p0i8.p0i8.i32"
,
fn
(
i8p
,
i8p
,
t_i32
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memmove.p0i8.p0i8.i64"
,
fn
(
i8p
,
i8p
,
t_i64
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memset.p0i8.i16"
,
fn
(
i8p
,
t_i8
,
t_i16
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memset.p0i8.i32"
,
fn
(
i8p
,
t_i8
,
t_i32
,
t_i32
,
i1
)
->
void
);
ifn!
(
"llvm.memset.p0i8.i64"
,
fn
(
i8p
,
t_i8
,
t_i64
,
t_i32
,
i1
)
->
void
);
...
...
@@ -942,7 +945,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
if
unsafe
{
llvm
::
LLVMVersionMinor
()
>=
$llvm_version
}
{
// The `if key == $name` is already in ifn!
ifn!
(
$name
,
fn
(
$
(
$arg
),
*
)
->
void
);
}
else
if
*
key
==
$name
{
}
else
if
key
==
$name
{
let
f
=
declare
::
declare_cfn
(
ccx
,
stringify!
(
$cname
),
Type
::
func
(
&
[
$
(
$arg
),
*
],
&
void
),
ccx
.tcx
()
.mk_nil
());
...
...
@@ -965,7 +968,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
if
unsafe
{
llvm
::
LLVMVersionMinor
()
>=
$llvm_version
}
{
// The `if key == $name` is already in ifn!
ifn!
(
$name
,
fn
(
$
(
$arg
),
*
)
->
$ret
);
}
else
if
*
key
==
$name
{
}
else
if
key
==
$name
{
let
f
=
declare
::
declare_cfn
(
ccx
,
stringify!
(
$cname
),
Type
::
func
(
&
[
$
(
$arg
),
*
],
&
$ret
),
ccx
.tcx
()
.mk_nil
());
...
...
src/librustc_trans/trans/intrinsic.rs
浏览文件 @
30ec363c
...
...
@@ -932,20 +932,15 @@ fn copy_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let
align
=
C_i32
(
ccx
,
type_of
::
align_of
(
ccx
,
tp_ty
)
as
i32
);
let
size
=
machine
::
llsize_of
(
ccx
,
lltp_ty
);
let
int_size
=
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
());
let
name
=
if
allow_overlap
{
if
int_size
==
32
{
"llvm.memmove.p0i8.p0i8.i32"
}
else
{
"llvm.memmove.p0i8.p0i8.i64"
}
let
operation
=
if
allow_overlap
{
"memmove"
}
else
{
if
int_size
==
32
{
"llvm.memcpy.p0i8.p0i8.i32"
}
else
{
"llvm.memcpy.p0i8.p0i8.i64"
}
"memcpy"
};
let
name
=
format!
(
"llvm.{}.p0i8.p0i8.i{}"
,
operation
,
int_size
);
let
dst_ptr
=
PointerCast
(
bcx
,
dst
,
Type
::
i8p
(
ccx
));
let
src_ptr
=
PointerCast
(
bcx
,
src
,
Type
::
i8p
(
ccx
));
let
llfn
=
ccx
.get_intrinsic
(
&
name
);
...
...
@@ -973,11 +968,9 @@ fn memset_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let
lltp_ty
=
type_of
::
type_of
(
ccx
,
tp_ty
);
let
align
=
C_i32
(
ccx
,
type_of
::
align_of
(
ccx
,
tp_ty
)
as
i32
);
let
size
=
machine
::
llsize_of
(
ccx
,
lltp_ty
);
let
name
=
if
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
())
==
32
{
"llvm.memset.p0i8.i32"
}
else
{
"llvm.memset.p0i8.i64"
};
let
int_size
=
machine
::
llbitsize_of_real
(
ccx
,
ccx
.int_type
());
let
name
=
format!
(
"llvm.memset.p0i8.i{}"
,
int_size
);
let
dst_ptr
=
PointerCast
(
bcx
,
dst
,
Type
::
i8p
(
ccx
));
let
llfn
=
ccx
.get_intrinsic
(
&
name
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录