blob: e2de9d4b363afe76ffd607fdc6d6fe803823b7e2 [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
39 // TODO: bb arguments, instruction list.
40
41 void setTerminator(TerminatorInst *inst) {
42 terminator = inst;
43 }
44 TerminatorInst *getTerminator() const { return terminator; }
45
46 void print(raw_ostream &os) const;
47 void dump() const;
48
49private:
50 CFGFunction *const function;
51 // FIXME: wrong representation and API, leaks memory etc.
52 TerminatorInst *terminator = nullptr;
53};
54
55} // end namespace mlir
56
57#endif // MLIR_IR_BASICBLOCK_H