Continue pushing const out of the IR types - removing the notion of a 'const

Module'.  NFC.

PiperOrigin-RevId: 239532885
This commit is contained in:
Chris Lattner 2019-03-20 21:14:59 -07:00 committed by jpienaar
parent 2be78730b0
commit 8d526ef173
6 changed files with 21 additions and 38 deletions

View File

@ -35,52 +35,38 @@ class Module {
public:
explicit Module(MLIRContext *context);
MLIRContext *getContext() const { return context; }
MLIRContext *getContext() { return context; }
/// This is the list of functions in the module.
using FunctionListType = llvm::iplist<Function>;
FunctionListType &getFunctions() { return functions; }
const FunctionListType &getFunctions() const { return functions; }
// Iteration over the functions in the module.
using iterator = FunctionListType::iterator;
using const_iterator = FunctionListType::const_iterator;
using reverse_iterator = FunctionListType::reverse_iterator;
using const_reverse_iterator = FunctionListType::const_reverse_iterator;
iterator begin() { return functions.begin(); }
iterator end() { return functions.end(); }
const_iterator begin() const { return functions.begin(); }
const_iterator end() const { return functions.end(); }
reverse_iterator rbegin() { return functions.rbegin(); }
reverse_iterator rend() { return functions.rend(); }
const_reverse_iterator rbegin() const { return functions.rbegin(); }
const_reverse_iterator rend() const { return functions.rend(); }
// Interfaces for working with the symbol table.
/// Look up a function with the specified name, returning null if no such
/// name exists. Function names never include the @ on them.
Function *getNamedFunction(StringRef name);
const Function *getNamedFunction(StringRef name) const {
return const_cast<Module *>(this)->getNamedFunction(name);
}
/// Look up a function with the specified name, returning null if no such
/// name exists. Function names never include the @ on them.
Function *getNamedFunction(Identifier name);
const Function *getNamedFunction(Identifier name) const {
return const_cast<Module *>(this)->getNamedFunction(name);
}
/// Perform (potentially expensive) checks of invariants, used to detect
/// compiler bugs. On error, this reports the error through the MLIRContext
/// and returns true.
bool verify() const;
bool verify();
void print(raw_ostream &os) const;
void dump() const;
void print(raw_ostream &os);
void dump();
private:
friend struct llvm::ilist_traits<Function>;

View File

@ -358,7 +358,7 @@ bool Function::verify() const { return FuncVerifier(*this).verify(); }
/// Perform (potentially expensive) checks of invariants, used to detect
/// compiler bugs. On error, this reports the error through the MLIRContext and
/// returns true.
bool Module::verify() const {
bool Module::verify() {
/// Check that each function is correct.
for (auto &fn : *this) {

View File

@ -273,7 +273,7 @@ void packFunctionArguments(llvm::Module *module) {
// Out of line for PIMPL unique_ptr.
ExecutionEngine::~ExecutionEngine() = default;
std::unique_ptr<llvm::Module> translateModuleToLLVMIR(const Module &m);
std::unique_ptr<llvm::Module> translateModuleToLLVMIR(Module &m);
Expected<std::unique_ptr<ExecutionEngine>> ExecutionEngine::create(
Module *m, std::function<llvm::Error(llvm::Module *)> transformer) {

View File

@ -86,7 +86,7 @@ public:
explicit ModuleState(MLIRContext *context) : context(context) {}
// Initializes module state, populating affine map state.
void initialize(const Module *module);
void initialize(Module *module);
StringRef getAffineMapAlias(AffineMap affineMap) const {
return affineMapToAlias.lookup(affineMap);
@ -266,7 +266,7 @@ void ModuleState::initializeSymbolAliases() {
}
// Initializes module state, populating affine map and integer set state.
void ModuleState::initialize(const Module *module) {
void ModuleState::initialize(Module *module) {
for (auto &fn : *module) {
visitType(fn.getType());
@ -286,7 +286,7 @@ namespace {
class ModulePrinter {
public:
ModulePrinter(raw_ostream &os, ModuleState &state) : os(os), state(state) {}
explicit ModulePrinter(const ModulePrinter &printer)
explicit ModulePrinter(ModulePrinter &printer)
: os(printer.os), state(printer.state) {}
template <typename Container, typename UnaryFunctor>
@ -294,7 +294,7 @@ public:
interleave(c.begin(), c.end(), each_fn, [&]() { os << ", "; });
}
void print(const Module *module);
void print(Module *module);
void printFunctionReference(const Function *func);
void printAttributeAndType(Attribute attr) {
printAttributeOptionalType(attr, /*includeType=*/true);
@ -463,7 +463,7 @@ void ModulePrinter::printLocationInternal(Location loc, bool pretty) {
}
}
void ModulePrinter::print(const Module *module) {
void ModulePrinter::print(Module *module) {
for (const auto &map : state.getAffineMapIds()) {
StringRef alias = state.getAffineMapAlias(map);
if (!alias.empty())
@ -1051,7 +1051,7 @@ namespace {
// CFG and ML functions.
class FunctionPrinter : public ModulePrinter, private OpAsmPrinter {
public:
FunctionPrinter(const Function *function, const ModulePrinter &other);
FunctionPrinter(const Function *function, ModulePrinter &other);
// Prints the function as a whole.
void print();
@ -1162,8 +1162,7 @@ private:
};
} // end anonymous namespace
FunctionPrinter::FunctionPrinter(const Function *function,
const ModulePrinter &other)
FunctionPrinter::FunctionPrinter(const Function *function, ModulePrinter &other)
: ModulePrinter(other), function(function) {
for (auto &block : *function)
@ -1650,13 +1649,13 @@ void Function::print(raw_ostream &os) const {
void Function::dump() const { print(llvm::errs()); }
void Module::print(raw_ostream &os) const {
void Module::print(raw_ostream &os) {
ModuleState state(getContext());
state.initialize(this);
ModulePrinter(os, state).print(this);
}
void Module::dump() const { print(llvm::errs()); }
void Module::dump() { print(llvm::errs()); }
void Location::print(raw_ostream &os) const {
ModuleState state(nullptr);

View File

@ -50,10 +50,10 @@ public:
// Translate the given MLIR module expressed in MLIR LLVM IR dialect into an
// LLVM IR module. The MLIR LLVM IR dialect holds a pointer to an
// LLVMContext, the LLVM IR module will be created in that context.
static std::unique_ptr<llvm::Module> translateModule(const Module &m);
static std::unique_ptr<llvm::Module> translateModule(Module &m);
private:
explicit ModuleTranslation(const Module &module) : mlirModule(module) {}
explicit ModuleTranslation(Module &module) : mlirModule(module) {}
bool convertFunctions();
bool convertOneFunction(const Function &func);
@ -68,7 +68,7 @@ private:
Location loc);
// Original and translated module.
const Module &mlirModule;
Module &mlirModule;
std::unique_ptr<llvm::Module> llvmModule;
// Mappings between original and translated values, used for lookups.
@ -442,8 +442,7 @@ bool ModuleTranslation::convertFunctions() {
return false;
}
std::unique_ptr<llvm::Module>
ModuleTranslation::translateModule(const Module &m) {
std::unique_ptr<llvm::Module> ModuleTranslation::translateModule(Module &m) {
Dialect *dialect = m.getContext()->getRegisteredDialect("llvm");
assert(dialect && "LLVM dialect must be registered");
@ -471,7 +470,7 @@ ModuleTranslation::translateModule(const Module &m) {
return std::move(translator.llvmModule);
}
std::unique_ptr<llvm::Module> translateModuleToLLVMIR(const Module &m) {
std::unique_ptr<llvm::Module> translateModuleToLLVMIR(Module &m) {
return ModuleTranslation::translateModule(m);
}

View File

@ -57,8 +57,7 @@ static Module *parseMLIRInput(StringRef inputFilename, MLIRContext *context) {
return parseSourceFile(sourceMgr, context);
}
static bool printMLIROutput(const Module &module,
llvm::StringRef outputFilename) {
static bool printMLIROutput(Module &module, llvm::StringRef outputFilename) {
if (module.verify())
return true;
auto file = openOutputFile(outputFilename);