Chris Lattner | 4c95a50 | 2018-06-23 16:03:42 -0700 | [diff] [blame] | 1 | //===- 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 | |
| 23 | namespace 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. |
| 30 | class BasicBlock { |
| 31 | public: |
| 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 Lattner | ed65a73 | 2018-06-28 20:45:33 -0700 | [diff] [blame^] | 39 | // TODO: bb arguments |
| 40 | |
| 41 | // TODO: Wrong representation. |
| 42 | std::vector<OperationInst*> instList; |
Chris Lattner | 4c95a50 | 2018-06-23 16:03:42 -0700 | [diff] [blame] | 43 | |
| 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 | |
| 52 | private: |
| 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 |