]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/build/cfg.rs
Number of filtered out tests in tests summary
[rust.git] / 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.
4 //
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.
10
11
12
13
14 //! Routines for manipulating the control-flow graph.
15
16 use build::CFG;
17 use rustc::mir::*;
18
19 impl<'tcx> CFG<'tcx> {
20     pub fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
21         &self.basic_blocks[blk]
22     }
23
24     pub fn block_data_mut(&mut self, blk: BasicBlock) -> &mut BasicBlockData<'tcx> {
25         &mut self.basic_blocks[blk]
26     }
27
28     // llvm.org/PR32488 makes this function use an excess of stack space. Mark
29     // it as #[inline(never)] to keep rustc's stack use in check.
30     #[inline(never)]
31     pub fn start_new_block(&mut self) -> BasicBlock {
32         self.basic_blocks.push(BasicBlockData::new(None))
33     }
34
35     pub fn start_new_cleanup_block(&mut self) -> BasicBlock {
36         let bb = self.start_new_block();
37         self.block_data_mut(bb).is_cleanup = true;
38         bb
39     }
40
41     pub fn push(&mut self, block: BasicBlock, statement: Statement<'tcx>) {
42         debug!("push({:?}, {:?})", block, statement);
43         self.block_data_mut(block).statements.push(statement);
44     }
45
46     pub fn push_assign(&mut self,
47                        block: BasicBlock,
48                        source_info: SourceInfo,
49                        lvalue: &Lvalue<'tcx>,
50                        rvalue: Rvalue<'tcx>) {
51         self.push(block, Statement {
52             source_info: source_info,
53             kind: StatementKind::Assign(lvalue.clone(), rvalue)
54         });
55     }
56
57     pub fn push_assign_constant(&mut self,
58                                 block: BasicBlock,
59                                 source_info: SourceInfo,
60                                 temp: &Lvalue<'tcx>,
61                                 constant: Constant<'tcx>) {
62         self.push_assign(block, source_info, temp,
63                          Rvalue::Use(Operand::Constant(constant)));
64     }
65
66     pub fn push_assign_unit(&mut self,
67                             block: BasicBlock,
68                             source_info: SourceInfo,
69                             lvalue: &Lvalue<'tcx>) {
70         self.push_assign(block, source_info, lvalue, Rvalue::Aggregate(
71             AggregateKind::Tuple, vec![]
72         ));
73     }
74
75     pub fn terminate(&mut self,
76                      block: BasicBlock,
77                      source_info: SourceInfo,
78                      kind: TerminatorKind<'tcx>) {
79         debug!("terminating block {:?} <- {:?}", block, kind);
80         debug_assert!(self.block_data(block).terminator.is_none(),
81                       "terminate: block {:?}={:?} already has a terminator set",
82                       block,
83                       self.block_data(block));
84         self.block_data_mut(block).terminator = Some(Terminator {
85             source_info: source_info,
86             kind: kind,
87         });
88     }
89 }