Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e9214a14
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
e9214a14
编写于
9月 12, 2019
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
codegen: be more explicit about setting giving names to allocas.
上级
f71826e8
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
42 addition
and
55 deletion
+42
-55
src/librustc_codegen_llvm/abi.rs
src/librustc_codegen_llvm/abi.rs
+1
-1
src/librustc_codegen_llvm/builder.rs
src/librustc_codegen_llvm/builder.rs
+5
-18
src/librustc_codegen_llvm/intrinsic.rs
src/librustc_codegen_llvm/intrinsic.rs
+1
-1
src/librustc_codegen_ssa/mir/block.rs
src/librustc_codegen_ssa/mir/block.rs
+9
-9
src/librustc_codegen_ssa/mir/mod.rs
src/librustc_codegen_ssa/mir/mod.rs
+15
-11
src/librustc_codegen_ssa/mir/operand.rs
src/librustc_codegen_ssa/mir/operand.rs
+1
-1
src/librustc_codegen_ssa/mir/place.rs
src/librustc_codegen_ssa/mir/place.rs
+2
-6
src/librustc_codegen_ssa/mir/rvalue.rs
src/librustc_codegen_ssa/mir/rvalue.rs
+1
-1
src/librustc_codegen_ssa/traits/builder.rs
src/librustc_codegen_ssa/traits/builder.rs
+2
-3
src/test/codegen/personality_lifetimes.rs
src/test/codegen/personality_lifetimes.rs
+5
-4
未找到文件。
src/librustc_codegen_llvm/abi.rs
浏览文件 @
e9214a14
...
...
@@ -229,7 +229,7 @@ fn store(
// We instead thus allocate some scratch space...
let
scratch_size
=
cast
.size
(
bx
);
let
scratch_align
=
cast
.align
(
bx
);
let
llscratch
=
bx
.alloca
(
cast
.llvm_type
(
bx
),
"abi_cast"
,
scratch_align
);
let
llscratch
=
bx
.alloca
(
cast
.llvm_type
(
bx
),
scratch_align
);
bx
.lifetime_start
(
llscratch
,
scratch_size
);
// ...where we first store the value...
...
...
src/librustc_codegen_llvm/builder.rs
浏览文件 @
e9214a14
...
...
@@ -387,23 +387,17 @@ fn checked_binop(
)
}
fn
alloca
(
&
mut
self
,
ty
:
&
'll
Type
,
name
:
&
str
,
align
:
Align
)
->
&
'll
Value
{
fn
alloca
(
&
mut
self
,
ty
:
&
'll
Type
,
align
:
Align
)
->
&
'll
Value
{
let
mut
bx
=
Builder
::
with_cx
(
self
.cx
);
bx
.position_at_start
(
unsafe
{
llvm
::
LLVMGetFirstBasicBlock
(
self
.llfn
())
});
bx
.dynamic_alloca
(
ty
,
name
,
align
)
bx
.dynamic_alloca
(
ty
,
align
)
}
fn
dynamic_alloca
(
&
mut
self
,
ty
:
&
'll
Type
,
name
:
&
str
,
align
:
Align
)
->
&
'll
Value
{
fn
dynamic_alloca
(
&
mut
self
,
ty
:
&
'll
Type
,
align
:
Align
)
->
&
'll
Value
{
unsafe
{
let
alloca
=
if
name
.is_empty
()
{
llvm
::
LLVMBuildAlloca
(
self
.llbuilder
,
ty
,
UNNAMED
)
}
else
{
let
name
=
SmallCStr
::
new
(
name
);
llvm
::
LLVMBuildAlloca
(
self
.llbuilder
,
ty
,
name
.as_ptr
())
};
let
alloca
=
llvm
::
LLVMBuildAlloca
(
self
.llbuilder
,
ty
,
UNNAMED
);
llvm
::
LLVMSetAlignment
(
alloca
,
align
.bytes
()
as
c_uint
);
alloca
}
...
...
@@ -412,16 +406,9 @@ fn dynamic_alloca(&mut self, ty: &'ll Type, name: &str, align: Align) -> &'ll Va
fn
array_alloca
(
&
mut
self
,
ty
:
&
'll
Type
,
len
:
&
'll
Value
,
name
:
&
str
,
align
:
Align
)
->
&
'll
Value
{
unsafe
{
let
alloca
=
if
name
.is_empty
()
{
llvm
::
LLVMBuildArrayAlloca
(
self
.llbuilder
,
ty
,
len
,
UNNAMED
)
}
else
{
let
name
=
SmallCStr
::
new
(
name
);
llvm
::
LLVMBuildArrayAlloca
(
self
.llbuilder
,
ty
,
len
,
name
.as_ptr
())
};
let
alloca
=
llvm
::
LLVMBuildArrayAlloca
(
self
.llbuilder
,
ty
,
len
,
UNNAMED
);
llvm
::
LLVMSetAlignment
(
alloca
,
align
.bytes
()
as
c_uint
);
alloca
}
...
...
src/librustc_codegen_llvm/intrinsic.rs
浏览文件 @
e9214a14
...
...
@@ -871,7 +871,7 @@ fn codegen_msvc_try(
// More information can be found in libstd's seh.rs implementation.
let
i64p
=
bx
.type_ptr_to
(
bx
.type_i64
());
let
ptr_align
=
bx
.tcx
()
.data_layout.pointer_align.abi
;
let
slot
=
bx
.alloca
(
i64p
,
"slot"
,
ptr_align
);
let
slot
=
bx
.alloca
(
i64p
,
ptr_align
);
bx
.invoke
(
func
,
&
[
data
],
normal
.llbb
(),
catchswitch
.llbb
(),
None
);
normal
.ret
(
bx
.const_i32
(
0
));
...
...
src/librustc_codegen_ssa/mir/block.rs
浏览文件 @
e9214a14
...
...
@@ -276,7 +276,7 @@ fn codegen_return_terminator(&mut self, mut bx: Bx) {
let
llslot
=
match
op
.val
{
Immediate
(
_
)
|
Pair
(
..
)
=>
{
let
scratch
=
PlaceRef
::
alloca
(
&
mut
bx
,
self
.fn_ty.ret.layout
,
"ret"
);
PlaceRef
::
alloca
(
&
mut
bx
,
self
.fn_ty.ret.layout
);
op
.val
.store
(
&
mut
bx
,
scratch
);
scratch
.llval
}
...
...
@@ -767,7 +767,7 @@ fn codegen_call_terminator<'b>(
match
(
arg
,
op
.val
)
{
(
&
mir
::
Operand
::
Copy
(
_
),
Ref
(
_
,
None
,
_
))
|
(
&
mir
::
Operand
::
Constant
(
_
),
Ref
(
_
,
None
,
_
))
=>
{
let
tmp
=
PlaceRef
::
alloca
(
&
mut
bx
,
op
.layout
,
"const"
);
let
tmp
=
PlaceRef
::
alloca
(
&
mut
bx
,
op
.layout
);
op
.val
.store
(
&
mut
bx
,
tmp
);
op
.val
=
Ref
(
tmp
.llval
,
None
,
tmp
.align
);
}
...
...
@@ -925,7 +925,7 @@ fn codegen_argument(
Immediate
(
_
)
|
Pair
(
..
)
=>
{
match
arg
.mode
{
PassMode
::
Indirect
(
..
)
|
PassMode
::
Cast
(
_
)
=>
{
let
scratch
=
PlaceRef
::
alloca
(
bx
,
arg
.layout
,
"arg"
);
let
scratch
=
PlaceRef
::
alloca
(
bx
,
arg
.layout
);
op
.val
.store
(
bx
,
scratch
);
(
scratch
.llval
,
scratch
.align
,
true
)
}
...
...
@@ -940,7 +940,7 @@ fn codegen_argument(
// think that ATM (Rust 1.16) we only pass temporaries, but we shouldn't
// have scary latent bugs around.
let
scratch
=
PlaceRef
::
alloca
(
bx
,
arg
.layout
,
"arg"
);
let
scratch
=
PlaceRef
::
alloca
(
bx
,
arg
.layout
);
base
::
memcpy_ty
(
bx
,
scratch
.llval
,
scratch
.align
,
llval
,
align
,
op
.layout
,
MemFlags
::
empty
());
(
scratch
.llval
,
scratch
.align
,
true
)
...
...
@@ -1017,7 +1017,7 @@ fn get_personality_slot(
cx
.tcx
()
.mk_mut_ptr
(
cx
.tcx
()
.types.u8
),
cx
.tcx
()
.types.i32
]));
let
slot
=
PlaceRef
::
alloca
(
bx
,
layout
,
"personalityslot"
);
let
slot
=
PlaceRef
::
alloca
(
bx
,
layout
);
self
.personality_slot
=
Some
(
slot
);
slot
}
...
...
@@ -1116,7 +1116,7 @@ fn make_return_dest(
return
if
fn_ret
.is_indirect
()
{
// Odd, but possible, case, we have an operand temporary,
// but the calling convention has an indirect return.
let
tmp
=
PlaceRef
::
alloca
(
bx
,
fn_ret
.layout
,
"tmp_ret"
);
let
tmp
=
PlaceRef
::
alloca
(
bx
,
fn_ret
.layout
);
tmp
.storage_live
(
bx
);
llargs
.push
(
tmp
.llval
);
ReturnDest
::
IndirectOperand
(
tmp
,
index
)
...
...
@@ -1124,7 +1124,7 @@ fn make_return_dest(
// Currently, intrinsics always need a location to store
// the result, so we create a temporary `alloca` for the
// result.
let
tmp
=
PlaceRef
::
alloca
(
bx
,
fn_ret
.layout
,
"tmp_ret"
);
let
tmp
=
PlaceRef
::
alloca
(
bx
,
fn_ret
.layout
);
tmp
.storage_live
(
bx
);
ReturnDest
::
IndirectOperand
(
tmp
,
index
)
}
else
{
...
...
@@ -1174,7 +1174,7 @@ fn codegen_transmute(
LocalRef
::
Operand
(
None
)
=>
{
let
dst_layout
=
bx
.layout_of
(
self
.monomorphized_place_ty
(
&
dst
.as_ref
()));
assert
!
(
!
dst_layout
.ty
.has_erasable_regions
());
let
place
=
PlaceRef
::
alloca
(
bx
,
dst_layout
,
"transmute_temp"
);
let
place
=
PlaceRef
::
alloca
(
bx
,
dst_layout
);
place
.storage_live
(
bx
);
self
.codegen_transmute_into
(
bx
,
src
,
place
);
let
op
=
bx
.load_operand
(
place
);
...
...
@@ -1227,7 +1227,7 @@ fn store_return(
DirectOperand
(
index
)
=>
{
// If there is a cast, we have to store and reload.
let
op
=
if
let
PassMode
::
Cast
(
_
)
=
ret_ty
.mode
{
let
tmp
=
PlaceRef
::
alloca
(
bx
,
ret_ty
.layout
,
"tmp_ret"
);
let
tmp
=
PlaceRef
::
alloca
(
bx
,
ret_ty
.layout
);
tmp
.storage_live
(
bx
);
bx
.store_arg_ty
(
&
ret_ty
,
llval
,
tmp
);
let
op
=
bx
.load_operand
(
tmp
);
...
...
src/librustc_codegen_ssa/mir/mod.rs
浏览文件 @
e9214a14
...
...
@@ -268,11 +268,13 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
debug!
(
"alloc: {:?} ({}) -> place"
,
local
,
name
);
if
layout
.is_unsized
()
{
let
indirect_place
=
PlaceRef
::
alloca_unsized_indirect
(
&
mut
bx
,
layout
,
&
name
.as_str
());
PlaceRef
::
alloca_unsized_indirect
(
&
mut
bx
,
layout
);
bx
.set_var_name
(
indirect_place
.llval
,
name
);
// FIXME: add an appropriate debuginfo
LocalRef
::
UnsizedPlace
(
indirect_place
)
}
else
{
let
place
=
PlaceRef
::
alloca
(
&
mut
bx
,
layout
,
&
name
.as_str
());
let
place
=
PlaceRef
::
alloca
(
&
mut
bx
,
layout
);
bx
.set_var_name
(
place
.llval
,
name
);
if
dbg
{
let
(
scope
,
span
)
=
fx
.debug_loc
(
mir
::
SourceInfo
{
span
:
decl
.source_info.span
,
...
...
@@ -293,14 +295,13 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
}
else
if
memory_locals
.contains
(
local
)
{
debug!
(
"alloc: {:?} -> place"
,
local
);
if
layout
.is_unsized
()
{
let
indirect_place
=
PlaceRef
::
alloca_unsized_indirect
(
&
mut
bx
,
layout
,
&
format!
(
"{:?}"
,
local
),
);
let
indirect_place
=
PlaceRef
::
alloca_unsized_indirect
(
&
mut
bx
,
layout
);
bx
.set_var_name
(
indirect_place
.llval
,
format_args!
(
"{:?}"
,
local
));
LocalRef
::
UnsizedPlace
(
indirect_place
)
}
else
{
LocalRef
::
Place
(
PlaceRef
::
alloca
(
&
mut
bx
,
layout
,
&
format!
(
"{:?}"
,
local
)))
let
place
=
PlaceRef
::
alloca
(
&
mut
bx
,
layout
);
bx
.set_var_name
(
place
.llval
,
format_args!
(
"{:?}"
,
local
));
LocalRef
::
Place
(
place
)
}
}
else
{
// If this is an immediate local, we do not create an
...
...
@@ -470,7 +471,8 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
_
=>
bug!
(
"spread argument isn't a tuple?!"
)
};
let
place
=
PlaceRef
::
alloca
(
bx
,
bx
.layout_of
(
arg_ty
),
&
name
);
let
place
=
PlaceRef
::
alloca
(
bx
,
bx
.layout_of
(
arg_ty
));
bx
.set_var_name
(
place
.llval
,
name
);
for
i
in
0
..
tupled_arg_tys
.len
()
{
let
arg
=
&
fx
.fn_ty.args
[
idx
];
idx
+=
1
;
...
...
@@ -558,11 +560,13 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
llarg_idx
+=
1
;
let
indirect_operand
=
OperandValue
::
Pair
(
llarg
,
llextra
);
let
tmp
=
PlaceRef
::
alloca_unsized_indirect
(
bx
,
arg
.layout
,
&
name
);
let
tmp
=
PlaceRef
::
alloca_unsized_indirect
(
bx
,
arg
.layout
);
bx
.set_var_name
(
tmp
.llval
,
name
);
indirect_operand
.store
(
bx
,
tmp
);
tmp
}
else
{
let
tmp
=
PlaceRef
::
alloca
(
bx
,
arg
.layout
,
&
name
);
let
tmp
=
PlaceRef
::
alloca
(
bx
,
arg
.layout
);
bx
.set_var_name
(
tmp
.llval
,
name
);
if
fx
.fn_ty.c_variadic
&&
last_arg_idx
.map
(|
idx
|
arg_index
==
idx
)
.unwrap_or
(
false
)
{
let
va_list_did
=
match
tcx
.lang_items
()
.va_list
()
{
Some
(
did
)
=>
did
,
...
...
src/librustc_codegen_ssa/mir/operand.rs
浏览文件 @
e9214a14
...
...
@@ -367,7 +367,7 @@ pub fn store_unsized<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
// Allocate an appropriate region on the stack, and copy the value into it
let
(
llsize
,
_
)
=
glue
::
size_and_align_of_dst
(
bx
,
unsized_ty
,
Some
(
llextra
));
let
lldst
=
bx
.array_alloca
(
bx
.cx
()
.type_i8
(),
llsize
,
"unsized_tmp"
,
max_align
);
let
lldst
=
bx
.array_alloca
(
bx
.cx
()
.type_i8
(),
llsize
,
max_align
);
bx
.memcpy
(
lldst
,
max_align
,
llptr
,
min_align
,
llsize
,
flags
);
// Store the allocated region and the extra to the indirect place.
...
...
src/librustc_codegen_ssa/mir/place.rs
浏览文件 @
e9214a14
...
...
@@ -71,11 +71,9 @@ fn new_thin_place<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
pub
fn
alloca
<
Bx
:
BuilderMethods
<
'a
,
'tcx
,
Value
=
V
>>
(
bx
:
&
mut
Bx
,
layout
:
TyLayout
<
'tcx
>
,
name
:
&
str
)
->
Self
{
debug!
(
"alloca({:?}: {:?})"
,
name
,
layout
);
assert
!
(
!
layout
.is_unsized
(),
"tried to statically allocate unsized place"
);
let
tmp
=
bx
.alloca
(
bx
.cx
()
.backend_type
(
layout
),
name
,
layout
.align.abi
);
let
tmp
=
bx
.alloca
(
bx
.cx
()
.backend_type
(
layout
),
layout
.align.abi
);
Self
::
new_sized
(
tmp
,
layout
)
}
...
...
@@ -83,13 +81,11 @@ pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
pub
fn
alloca_unsized_indirect
<
Bx
:
BuilderMethods
<
'a
,
'tcx
,
Value
=
V
>>
(
bx
:
&
mut
Bx
,
layout
:
TyLayout
<
'tcx
>
,
name
:
&
str
,
)
->
Self
{
debug!
(
"alloca_unsized_indirect({:?}: {:?})"
,
name
,
layout
);
assert
!
(
layout
.is_unsized
(),
"tried to allocate indirect place for sized values"
);
let
ptr_ty
=
bx
.cx
()
.tcx
()
.mk_mut_ptr
(
layout
.ty
);
let
ptr_layout
=
bx
.cx
()
.layout_of
(
ptr_ty
);
Self
::
alloca
(
bx
,
ptr_layout
,
name
)
Self
::
alloca
(
bx
,
ptr_layout
)
}
pub
fn
len
<
Cx
:
ConstMethods
<
'tcx
,
Value
=
V
>>
(
...
...
src/librustc_codegen_ssa/mir/rvalue.rs
浏览文件 @
e9214a14
...
...
@@ -64,7 +64,7 @@ pub fn codegen_rvalue(
// index into the struct, and this case isn't
// important enough for it.
debug!
(
"codegen_rvalue: creating ugly alloca"
);
let
scratch
=
PlaceRef
::
alloca
(
&
mut
bx
,
operand
.layout
,
"__unsize_temp"
);
let
scratch
=
PlaceRef
::
alloca
(
&
mut
bx
,
operand
.layout
);
scratch
.storage_live
(
&
mut
bx
);
operand
.val
.store
(
&
mut
bx
,
scratch
);
base
::
coerce_unsized_into
(
&
mut
bx
,
scratch
,
dest
);
...
...
src/librustc_codegen_ssa/traits/builder.rs
浏览文件 @
e9214a14
...
...
@@ -109,13 +109,12 @@ fn checked_binop(
rhs
:
Self
::
Value
,
)
->
(
Self
::
Value
,
Self
::
Value
);
fn
alloca
(
&
mut
self
,
ty
:
Self
::
Type
,
name
:
&
str
,
align
:
Align
)
->
Self
::
Value
;
fn
dynamic_alloca
(
&
mut
self
,
ty
:
Self
::
Type
,
name
:
&
str
,
align
:
Align
)
->
Self
::
Value
;
fn
alloca
(
&
mut
self
,
ty
:
Self
::
Type
,
align
:
Align
)
->
Self
::
Value
;
fn
dynamic_alloca
(
&
mut
self
,
ty
:
Self
::
Type
,
align
:
Align
)
->
Self
::
Value
;
fn
array_alloca
(
&
mut
self
,
ty
:
Self
::
Type
,
len
:
Self
::
Value
,
name
:
&
str
,
align
:
Align
,
)
->
Self
::
Value
;
...
...
src/test/codegen/personality_lifetimes.rs
浏览文件 @
e9214a14
...
...
@@ -20,12 +20,13 @@ pub fn test() {
let
_
s
=
S
;
// Check that the personality slot alloca gets a lifetime start in each cleanup block, not just
// in the first one.
// CHECK: [[SLOT:%[0-9]+]] = alloca { i8*, i32 }
// CHECK-LABEL: cleanup:
// CHECK:
bitcast{{.*}}personalityslot
// CHECK-NEXT: call void @llvm.lifetime.start
// CHECK:
[[BITCAST:%[0-9]+]] = bitcast { i8*, i32 }* [[SLOT]] to i8*
// CHECK-NEXT: call void @llvm.lifetime.start
.{{.*}}({{.*}}, i8* [[BITCAST]])
// CHECK-LABEL: cleanup1:
// CHECK:
bitcast{{.*}}personalityslot
// CHECK-NEXT: call void @llvm.lifetime.start
// CHECK:
[[BITCAST1:%[0-9]+]] = bitcast { i8*, i32 }* [[SLOT]] to i8*
// CHECK-NEXT: call void @llvm.lifetime.start
.{{.*}}({{.*}}, i8* [[BITCAST1]])
might_unwind
();
let
_
t
=
S
;
might_unwind
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录