blob: 18585586e30a800736f6b21571071748a28ec137 [file] [log] [blame]
Chris Lattner4c95a502018-06-23 16:03:42 -07001//===- BasicBlock.h - MLIR BasicBlock Class ---------------------*- C++ -*-===//
2//
3// Copyright 2019 The MLIR Authors.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// =============================================================================
17
18#ifndef MLIR_IR_BASICBLOCK_H
19#define MLIR_IR_BASICBLOCK_H
20
21#include "mlir/IR/Instructions.h"
22
23namespace mlir {
24
25/// Each basic block in a CFG function contains a list of basic block arguments,
26/// normal instructions, and a terminator instruction.
27///
28/// Basic blocks form a graph (the CFG) which can be traversed through
29/// predecessor and successor edges.
30class BasicBlock {
31public:
32 explicit BasicBlock(CFGFunction *function);
33
34 /// Return the function that a BasicBlock is part of.
35 CFGFunction *getFunction() const {
36 return function;
37 }
38
Chris Lattnered65a732018-06-28 20:45:33 -070039 // TODO: bb arguments
40
41 // TODO: Wrong representation.
42 std::vector<OperationInst*> instList;
Chris Lattner4c95a502018-06-23 16:03:42 -070043
44 void setTerminator(TerminatorInst *inst) {
45 terminator = inst;
46 }
47 TerminatorInst *getTerminator() const { return terminator; }
48
49 void print(raw_ostream &os) const;
50 void dump() const;
51
52private:
53 CFGFunction *const function;
54 // FIXME: wrong representation and API, leaks memory etc.
55 TerminatorInst *terminator = nullptr;
56};
57
58} // end namespace mlir
59
60#endif // MLIR_IR_BASICBLOCK_H