blob: 8e45f8d5f81f4ddf3e3ac1f3d3255fdfbad89242 [file] [log] [blame]
Chris Lattnere2259872018-06-21 15:22:42 -07001//===- 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 Lattnera8e47672018-07-25 14:08:16 -070026#include "llvm/ADT/ilist.h"
Chris Lattner21e67f62018-07-06 10:46:19 -070027#include <vector>
Chris Lattnere2259872018-06-21 15:22:42 -070028
29namespace mlir {
Uday Bondhugulafaf37dd2018-06-29 18:09:29 -070030
31class AffineMap;
32
Chris Lattnere2259872018-06-21 15:22:42 -070033class Module {
34public:
Chris Lattner158e0a3e2018-07-08 20:51:38 -070035 explicit Module(MLIRContext *context);
36
37 MLIRContext *getContext() const { return context; }
Chris Lattnere2259872018-06-21 15:22:42 -070038
Chris Lattnera8e47672018-07-25 14:08:16 -070039 // 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 Lattnere2259872018-06-21 15:22:42 -070060
Chris Lattner21e67f62018-07-06 10:46:19 -070061 /// Perform (potentially expensive) checks of invariants, used to detect
Chris Lattner40746442018-07-21 14:32:09 -070062 /// 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 Lattner21e67f62018-07-06 10:46:19 -070065
Chris Lattner4c95a502018-06-23 16:03:42 -070066 void print(raw_ostream &os) const;
67 void dump() const;
Chris Lattner158e0a3e2018-07-08 20:51:38 -070068
Chris Lattnera8e47672018-07-25 14:08:16 -070069 /// getSublistAccess() - Returns pointer to member of function list
70 static FunctionListType Module::*getSublistAccess(Function *) {
71 return &Module::functions;
72 }
73
Chris Lattner158e0a3e2018-07-08 20:51:38 -070074private:
75 MLIRContext *context;
Chris Lattnera8e47672018-07-25 14:08:16 -070076 FunctionListType functions;
Chris Lattnere2259872018-06-21 15:22:42 -070077};
78} // end namespace mlir
79
80#endif // MLIR_IR_FUNCTION_H