Chris Lattner | e225987 | 2018-06-21 15:22:42 -0700 | [diff] [blame] | 1 | //===- Module.h - MLIR Module 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 | // Module is the top-level container for code in an MLIR program. |
| 19 | // |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | #ifndef MLIR_IR_MODULE_H |
| 23 | #define MLIR_IR_MODULE_H |
| 24 | |
| 25 | #include "mlir/IR/Function.h" |
Chris Lattner | a8e4767 | 2018-07-25 14:08:16 -0700 | [diff] [blame] | 26 | #include "llvm/ADT/ilist.h" |
Chris Lattner | 21e67f6 | 2018-07-06 10:46:19 -0700 | [diff] [blame] | 27 | #include <vector> |
Chris Lattner | e225987 | 2018-06-21 15:22:42 -0700 | [diff] [blame] | 28 | |
| 29 | namespace mlir { |
Uday Bondhugula | faf37dd | 2018-06-29 18:09:29 -0700 | [diff] [blame] | 30 | |
| 31 | class AffineMap; |
| 32 | |
Chris Lattner | e225987 | 2018-06-21 15:22:42 -0700 | [diff] [blame] | 33 | class Module { |
| 34 | public: |
Chris Lattner | 158e0a3e | 2018-07-08 20:51:38 -0700 | [diff] [blame] | 35 | explicit Module(MLIRContext *context); |
| 36 | |
| 37 | MLIRContext *getContext() const { return context; } |
Chris Lattner | e225987 | 2018-06-21 15:22:42 -0700 | [diff] [blame] | 38 | |
Chris Lattner | a8e4767 | 2018-07-25 14:08:16 -0700 | [diff] [blame] | 39 | // TODO: We should have a symbol table for function names. |
| 40 | |
| 41 | /// This is the list of functions in the module. |
| 42 | typedef llvm::iplist<Function> FunctionListType; |
| 43 | FunctionListType &getFunctions() { return functions; } |
| 44 | const FunctionListType &getFunctions() const { return functions; } |
| 45 | |
| 46 | // Iteration over the functions in the module. |
| 47 | using iterator = FunctionListType::iterator; |
| 48 | using const_iterator = FunctionListType::const_iterator; |
| 49 | using reverse_iterator = FunctionListType::reverse_iterator; |
| 50 | using const_reverse_iterator = FunctionListType::const_reverse_iterator; |
| 51 | |
| 52 | iterator begin() { return functions.begin(); } |
| 53 | iterator end() { return functions.end(); } |
| 54 | const_iterator begin() const { return functions.begin(); } |
| 55 | const_iterator end() const { return functions.end(); } |
| 56 | reverse_iterator rbegin() { return functions.rbegin(); } |
| 57 | reverse_iterator rend() { return functions.rend(); } |
| 58 | const_reverse_iterator rbegin() const { return functions.rbegin(); } |
| 59 | const_reverse_iterator rend() const { return functions.rend(); } |
Chris Lattner | e225987 | 2018-06-21 15:22:42 -0700 | [diff] [blame] | 60 | |
Chris Lattner | 21e67f6 | 2018-07-06 10:46:19 -0700 | [diff] [blame] | 61 | /// Perform (potentially expensive) checks of invariants, used to detect |
Chris Lattner | 4074644 | 2018-07-21 14:32:09 -0700 | [diff] [blame] | 62 | /// compiler bugs. On error, this fills in the string and return true, |
| 63 | /// or aborts if the string was not provided. |
| 64 | bool verify(std::string *errorResult = nullptr) const; |
Chris Lattner | 21e67f6 | 2018-07-06 10:46:19 -0700 | [diff] [blame] | 65 | |
Chris Lattner | 4c95a50 | 2018-06-23 16:03:42 -0700 | [diff] [blame] | 66 | void print(raw_ostream &os) const; |
| 67 | void dump() const; |
Chris Lattner | 158e0a3e | 2018-07-08 20:51:38 -0700 | [diff] [blame] | 68 | |
Chris Lattner | a8e4767 | 2018-07-25 14:08:16 -0700 | [diff] [blame] | 69 | /// getSublistAccess() - Returns pointer to member of function list |
| 70 | static FunctionListType Module::*getSublistAccess(Function *) { |
| 71 | return &Module::functions; |
| 72 | } |
| 73 | |
Chris Lattner | 158e0a3e | 2018-07-08 20:51:38 -0700 | [diff] [blame] | 74 | private: |
| 75 | MLIRContext *context; |
Chris Lattner | a8e4767 | 2018-07-25 14:08:16 -0700 | [diff] [blame] | 76 | FunctionListType functions; |
Chris Lattner | e225987 | 2018-06-21 15:22:42 -0700 | [diff] [blame] | 77 | }; |
| 78 | } // end namespace mlir |
| 79 | |
| 80 | #endif // MLIR_IR_FUNCTION_H |