]>
git.proxmox.com Git - rustc.git/blob - src/librustc_mir/build/cfg.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
14 //! Routines for manipulating the control-flow graph.
17 use rustc
::middle
::region
::CodeExtent
;
20 impl<'tcx
> CFG
<'tcx
> {
21 pub fn block_data(&self, blk
: BasicBlock
) -> &BasicBlockData
<'tcx
> {
22 &self.basic_blocks
[blk
]
25 pub fn block_data_mut(&mut self, blk
: BasicBlock
) -> &mut BasicBlockData
<'tcx
> {
26 &mut self.basic_blocks
[blk
]
29 // llvm.org/PR32488 makes this function use an excess of stack space. Mark
30 // it as #[inline(never)] to keep rustc's stack use in check.
32 pub fn start_new_block(&mut self) -> BasicBlock
{
33 self.basic_blocks
.push(BasicBlockData
::new(None
))
36 pub fn start_new_cleanup_block(&mut self) -> BasicBlock
{
37 let bb
= self.start_new_block();
38 self.block_data_mut(bb
).is_cleanup
= true;
42 pub fn push(&mut self, block
: BasicBlock
, statement
: Statement
<'tcx
>) {
43 debug
!("push({:?}, {:?})", block
, statement
);
44 self.block_data_mut(block
).statements
.push(statement
);
47 pub fn push_end_region(&mut self,
49 source_info
: SourceInfo
,
51 self.push(block
, Statement
{
52 source_info
: source_info
,
53 kind
: StatementKind
::EndRegion(extent
),
57 pub fn push_assign(&mut self,
59 source_info
: SourceInfo
,
60 lvalue
: &Lvalue
<'tcx
>,
61 rvalue
: Rvalue
<'tcx
>) {
62 self.push(block
, Statement
{
63 source_info
: source_info
,
64 kind
: StatementKind
::Assign(lvalue
.clone(), rvalue
)
68 pub fn push_assign_constant(&mut self,
70 source_info
: SourceInfo
,
72 constant
: Constant
<'tcx
>) {
73 self.push_assign(block
, source_info
, temp
,
74 Rvalue
::Use(Operand
::Constant(box constant
)));
77 pub fn push_assign_unit(&mut self,
79 source_info
: SourceInfo
,
80 lvalue
: &Lvalue
<'tcx
>) {
81 self.push_assign(block
, source_info
, lvalue
, Rvalue
::Aggregate(
82 box AggregateKind
::Tuple
, vec
![]
86 pub fn terminate(&mut self,
88 source_info
: SourceInfo
,
89 kind
: TerminatorKind
<'tcx
>) {
90 debug
!("terminating block {:?} <- {:?}", block
, kind
);
91 debug_assert
!(self.block_data(block
).terminator
.is_none(),
92 "terminate: block {:?}={:?} already has a terminator set",
94 self.block_data(block
));
95 self.block_data_mut(block
).terminator
= Some(Terminator
{
96 source_info
: source_info
,