Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
915f0918
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,发现更多精彩内容 >>
提交
915f0918
编写于
6月 06, 2022
作者:
T
Tomasz Miąsko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove duplicated implementations of borrowed locals analysis
上级
37a42258
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
29 addition
and
133 deletion
+29
-133
compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs
compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs
+20
-0
compiler/rustc_mir_dataflow/src/impls/mod.rs
compiler/rustc_mir_dataflow/src/impls/mod.rs
+1
-0
compiler/rustc_mir_transform/src/dead_store_elimination.rs
compiler/rustc_mir_transform/src/dead_store_elimination.rs
+6
-68
compiler/rustc_mir_transform/src/dest_prop.rs
compiler/rustc_mir_transform/src/dest_prop.rs
+2
-65
未找到文件。
compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs
浏览文件 @
915f0918
...
...
@@ -145,3 +145,23 @@ fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Loc
}
}
}
/// The set of locals that are borrowed at some point in the MIR body.
pub
fn
borrowed_locals
(
body
:
&
Body
<
'_
>
)
->
BitSet
<
Local
>
{
struct
Borrowed
(
BitSet
<
Local
>
);
impl
GenKill
<
Local
>
for
Borrowed
{
#[inline]
fn
gen
(
&
mut
self
,
elem
:
Local
)
{
self
.0
.gen
(
elem
)
}
#[inline]
fn
kill
(
&
mut
self
,
_
:
Local
)
{
// Ignore borrow invalidation.
}
}
let
mut
borrowed
=
Borrowed
(
BitSet
::
new_empty
(
body
.local_decls
.len
()));
TransferFunction
{
trans
:
&
mut
borrowed
}
.visit_body
(
body
);
borrowed
.0
}
compiler/rustc_mir_dataflow/src/impls/mod.rs
浏览文件 @
915f0918
...
...
@@ -23,6 +23,7 @@
mod
liveness
;
mod
storage_liveness
;
pub
use
self
::
borrowed_locals
::
borrowed_locals
;
pub
use
self
::
borrowed_locals
::
MaybeBorrowedLocals
;
pub
use
self
::
init_locals
::
MaybeInitializedLocals
;
pub
use
self
::
liveness
::
MaybeLiveLocals
;
...
...
compiler/rustc_mir_transform/src/dead_store_elimination.rs
浏览文件 @
915f0918
...
...
@@ -13,16 +13,15 @@
//!
use
rustc_index
::
bit_set
::
BitSet
;
use
rustc_middle
::{
mir
::{
visit
::
Visitor
,
*
},
ty
::
TyCtxt
,
};
use
rustc_mir_dataflow
::{
impls
::
MaybeTransitiveLiveLocals
,
Analysis
};
use
rustc_middle
::
mir
::
*
;
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_mir_dataflow
::
impls
::{
borrowed_locals
,
MaybeTransitiveLiveLocals
};
use
rustc_mir_dataflow
::
Analysis
;
/// Performs the optimization on the body
///
/// The `borrowed` set must be a `BitSet` of all the locals that are ever borrowed in this body. It
/// can be generated via the [`
get_
borrowed_locals`] function.
/// can be generated via the [`borrowed_locals`] function.
pub
fn
eliminate
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
body
:
&
mut
Body
<
'tcx
>
,
borrowed
:
&
BitSet
<
Local
>
)
{
let
mut
live
=
MaybeTransitiveLiveLocals
::
new
(
borrowed
)
.into_engine
(
tcx
,
body
)
...
...
@@ -73,67 +72,6 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
}
}
pub
fn
get_borrowed_locals
(
body
:
&
Body
<
'_
>
)
->
BitSet
<
Local
>
{
let
mut
b
=
BorrowedLocals
(
BitSet
::
new_empty
(
body
.local_decls
.len
()));
b
.visit_body
(
body
);
b
.0
}
struct
BorrowedLocals
(
BitSet
<
Local
>
);
impl
<
'tcx
>
Visitor
<
'tcx
>
for
BorrowedLocals
{
fn
visit_rvalue
(
&
mut
self
,
rvalue
:
&
Rvalue
<
'tcx
>
,
loc
:
Location
)
{
self
.super_rvalue
(
rvalue
,
loc
);
match
rvalue
{
Rvalue
::
AddressOf
(
_
,
borrowed_place
)
|
Rvalue
::
Ref
(
_
,
_
,
borrowed_place
)
=>
{
if
!
borrowed_place
.is_indirect
()
{
self
.0
.insert
(
borrowed_place
.local
);
}
}
Rvalue
::
Cast
(
..
)
|
Rvalue
::
ShallowInitBox
(
..
)
|
Rvalue
::
Use
(
..
)
|
Rvalue
::
Repeat
(
..
)
|
Rvalue
::
Len
(
..
)
|
Rvalue
::
BinaryOp
(
..
)
|
Rvalue
::
CheckedBinaryOp
(
..
)
|
Rvalue
::
NullaryOp
(
..
)
|
Rvalue
::
UnaryOp
(
..
)
|
Rvalue
::
Discriminant
(
..
)
|
Rvalue
::
Aggregate
(
..
)
|
Rvalue
::
ThreadLocalRef
(
..
)
=>
{}
}
}
fn
visit_terminator
(
&
mut
self
,
terminator
:
&
Terminator
<
'tcx
>
,
location
:
Location
)
{
self
.super_terminator
(
terminator
,
location
);
match
terminator
.kind
{
TerminatorKind
::
Drop
{
place
:
dropped_place
,
..
}
=>
{
if
!
dropped_place
.is_indirect
()
{
self
.0
.insert
(
dropped_place
.local
);
}
}
TerminatorKind
::
Abort
|
TerminatorKind
::
DropAndReplace
{
..
}
|
TerminatorKind
::
Assert
{
..
}
|
TerminatorKind
::
Call
{
..
}
|
TerminatorKind
::
FalseEdge
{
..
}
|
TerminatorKind
::
FalseUnwind
{
..
}
|
TerminatorKind
::
GeneratorDrop
|
TerminatorKind
::
Goto
{
..
}
|
TerminatorKind
::
Resume
|
TerminatorKind
::
Return
|
TerminatorKind
::
SwitchInt
{
..
}
|
TerminatorKind
::
Unreachable
|
TerminatorKind
::
Yield
{
..
}
|
TerminatorKind
::
InlineAsm
{
..
}
=>
{}
}
}
}
pub
struct
DeadStoreElimination
;
impl
<
'tcx
>
MirPass
<
'tcx
>
for
DeadStoreElimination
{
...
...
@@ -142,7 +80,7 @@ fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
}
fn
run_pass
(
&
self
,
tcx
:
TyCtxt
<
'tcx
>
,
body
:
&
mut
Body
<
'tcx
>
)
{
let
borrowed
=
get_
borrowed_locals
(
body
);
let
borrowed
=
borrowed_locals
(
body
);
eliminate
(
tcx
,
body
,
&
borrowed
);
}
}
compiler/rustc_mir_transform/src/dest_prop.rs
浏览文件 @
915f0918
...
...
@@ -104,7 +104,7 @@
Rvalue
,
Statement
,
StatementKind
,
Terminator
,
TerminatorKind
,
};
use
rustc_middle
::
ty
::
TyCtxt
;
use
rustc_mir_dataflow
::
impls
::{
MaybeInitializedLocals
,
MaybeLiveLocals
};
use
rustc_mir_dataflow
::
impls
::{
borrowed_locals
,
MaybeInitializedLocals
,
MaybeLiveLocals
};
use
rustc_mir_dataflow
::
Analysis
;
// Empirical measurements have resulted in some observations:
...
...
@@ -805,7 +805,7 @@ fn find_candidates<'tcx>(body: &Body<'tcx>) -> Vec<CandidateAssignment<'tcx>> {
let
mut
visitor
=
FindAssignments
{
body
,
candidates
:
Vec
::
new
(),
ever_borrowed_locals
:
ever_
borrowed_locals
(
body
),
ever_borrowed_locals
:
borrowed_locals
(
body
),
locals_used_as_array_index
:
locals_used_as_array_index
(
body
),
};
visitor
.visit_body
(
body
);
...
...
@@ -886,69 +886,6 @@ fn is_local_required(local: Local, body: &Body<'_>) -> bool {
}
}
/// Walks MIR to find all locals that have their address taken anywhere.
fn
ever_borrowed_locals
(
body
:
&
Body
<
'_
>
)
->
BitSet
<
Local
>
{
let
mut
visitor
=
BorrowCollector
{
locals
:
BitSet
::
new_empty
(
body
.local_decls
.len
())
};
visitor
.visit_body
(
body
);
visitor
.locals
}
struct
BorrowCollector
{
locals
:
BitSet
<
Local
>
,
}
impl
<
'tcx
>
Visitor
<
'tcx
>
for
BorrowCollector
{
fn
visit_rvalue
(
&
mut
self
,
rvalue
:
&
Rvalue
<
'tcx
>
,
location
:
Location
)
{
self
.super_rvalue
(
rvalue
,
location
);
match
rvalue
{
Rvalue
::
AddressOf
(
_
,
borrowed_place
)
|
Rvalue
::
Ref
(
_
,
_
,
borrowed_place
)
=>
{
if
!
borrowed_place
.is_indirect
()
{
self
.locals
.insert
(
borrowed_place
.local
);
}
}
Rvalue
::
Cast
(
..
)
|
Rvalue
::
ShallowInitBox
(
..
)
|
Rvalue
::
Use
(
..
)
|
Rvalue
::
Repeat
(
..
)
|
Rvalue
::
Len
(
..
)
|
Rvalue
::
BinaryOp
(
..
)
|
Rvalue
::
CheckedBinaryOp
(
..
)
|
Rvalue
::
NullaryOp
(
..
)
|
Rvalue
::
UnaryOp
(
..
)
|
Rvalue
::
Discriminant
(
..
)
|
Rvalue
::
Aggregate
(
..
)
|
Rvalue
::
ThreadLocalRef
(
..
)
=>
{}
}
}
fn
visit_terminator
(
&
mut
self
,
terminator
:
&
Terminator
<
'tcx
>
,
location
:
Location
)
{
self
.super_terminator
(
terminator
,
location
);
match
terminator
.kind
{
TerminatorKind
::
Drop
{
place
:
dropped_place
,
..
}
|
TerminatorKind
::
DropAndReplace
{
place
:
dropped_place
,
..
}
=>
{
self
.locals
.insert
(
dropped_place
.local
);
}
TerminatorKind
::
Abort
|
TerminatorKind
::
Assert
{
..
}
|
TerminatorKind
::
Call
{
..
}
|
TerminatorKind
::
FalseEdge
{
..
}
|
TerminatorKind
::
FalseUnwind
{
..
}
|
TerminatorKind
::
GeneratorDrop
|
TerminatorKind
::
Goto
{
..
}
|
TerminatorKind
::
Resume
|
TerminatorKind
::
Return
|
TerminatorKind
::
SwitchInt
{
..
}
|
TerminatorKind
::
Unreachable
|
TerminatorKind
::
Yield
{
..
}
|
TerminatorKind
::
InlineAsm
{
..
}
=>
{}
}
}
}
/// `PlaceElem::Index` only stores a `Local`, so we can't replace that with a full `Place`.
///
/// Collect locals used as indices so we don't generate candidates that are impossible to apply
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录