Update ModuleOp::create(...) to take a Location instead of a context.
authorRiver Riddle <riverriddle@google.com>
Wed, 10 Jul 2019 00:57:24 +0000 (17:57 -0700)
committerjpienaar <jpienaar@google.com>
Wed, 10 Jul 2019 17:11:00 +0000 (10:11 -0700)
This allows for giving a Module a more interesting location than 'Unknown'.

PiperOrigin-RevId: 257310117

18 files changed:
mlir/bindings/python/pybind.cpp
mlir/examples/Linalg/Linalg2/Example.cpp
mlir/examples/Linalg/Linalg3/Conversion.cpp
mlir/examples/Linalg/Linalg3/Example.cpp
mlir/examples/Linalg/Linalg3/Execution.cpp
mlir/examples/Linalg/Linalg4/Example.cpp
mlir/examples/toy/Ch2/mlir/MLIRGen.cpp
mlir/examples/toy/Ch3/mlir/MLIRGen.cpp
mlir/examples/toy/Ch4/mlir/MLIRGen.cpp
mlir/examples/toy/Ch5/mlir/MLIRGen.cpp
mlir/include/mlir/IR/Builders.h
mlir/include/mlir/IR/Module.h
mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
mlir/lib/IR/Builders.cpp
mlir/lib/IR/Module.cpp
mlir/lib/Parser/Parser.cpp
mlir/lib/SPIRV/Serialization/ConvertFromBinary.cpp
mlir/unittests/Pass/AnalysisManagerTest.cpp

index f58e854..3c57888 100644 (file)
@@ -146,7 +146,8 @@ struct PythonFunction {
 /// Trivial C++ wrappers make use of the EDSC C API.
 struct PythonMLIRModule {
   PythonMLIRModule()
-      : mlirContext(), module(mlir::Module::create(&mlirContext)),
+      : mlirContext(),
+        module(mlir::Module::create(mlir::UnknownLoc::get(&mlirContext))),
         moduleManager(*module) {}
 
   PythonType makeScalarType(const std::string &mlirElemType,
index 57e6a0f..4ed3a39 100644 (file)
@@ -34,7 +34,7 @@ using namespace linalg::intrinsics;
 
 TEST_FUNC(linalg_ops) {
   MLIRContext context;
-  OwningModuleRef module = Module::create(&context);
+  OwningModuleRef module = Module::create(UnknownLoc::get(&context));
   auto indexType = mlir::IndexType::get(&context);
   mlir::FuncOp f = makeFunction(*module, "linalg_ops",
                                 {indexType, indexType, indexType}, {});
@@ -73,7 +73,7 @@ TEST_FUNC(linalg_ops) {
 
 TEST_FUNC(linalg_ops_folded_slices) {
   MLIRContext context;
-  OwningModuleRef module = Module::create(&context);
+  OwningModuleRef module = Module::create(UnknownLoc::get(&context));
   auto indexType = mlir::IndexType::get(&context);
   mlir::FuncOp f = makeFunction(*module, "linalg_ops_folded_slices",
                                 {indexType, indexType, indexType}, {});
index 7ba6dfc..51fdbfa 100644 (file)
@@ -66,7 +66,7 @@ FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
 
 TEST_FUNC(foo) {
   MLIRContext context;
-  OwningModuleRef module = Module::create(&context);
+  OwningModuleRef module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_as_loops");
   lowerToLoops(f);
 
index 2b5540f..36c148b 100644 (file)
@@ -63,7 +63,7 @@ FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
 
 TEST_FUNC(matmul_as_matvec) {
   MLIRContext context;
-  Module module = Module::create(&context);
+  Module module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f = makeFunctionWithAMatmulOp(module, "matmul_as_matvec");
   lowerToFinerGrainedTensorContraction(f);
   composeSliceOps(f);
@@ -81,7 +81,7 @@ TEST_FUNC(matmul_as_matvec) {
 
 TEST_FUNC(matmul_as_dot) {
   MLIRContext context;
-  Module module = Module::create(&context);
+  Module module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f = makeFunctionWithAMatmulOp(module, "matmul_as_dot");
   lowerToFinerGrainedTensorContraction(f);
   lowerToFinerGrainedTensorContraction(f);
@@ -102,7 +102,7 @@ TEST_FUNC(matmul_as_dot) {
 
 TEST_FUNC(matmul_as_loops) {
   MLIRContext context;
-  Module module = Module::create(&context);
+  Module module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f = makeFunctionWithAMatmulOp(module, "matmul_as_loops");
   lowerToLoops(f);
   composeSliceOps(f);
@@ -134,7 +134,7 @@ TEST_FUNC(matmul_as_loops) {
 
 TEST_FUNC(matmul_as_matvec_as_loops) {
   MLIRContext context;
-  Module module = Module::create(&context);
+  Module module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f =
       makeFunctionWithAMatmulOp(module, "matmul_as_matvec_as_loops");
   lowerToFinerGrainedTensorContraction(f);
@@ -165,7 +165,7 @@ TEST_FUNC(matmul_as_matvec_as_loops) {
 
 TEST_FUNC(matmul_as_matvec_as_affine) {
   MLIRContext context;
-  Module module = Module::create(&context);
+  Module module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f =
       makeFunctionWithAMatmulOp(module, "matmul_as_matvec_as_affine");
   lowerToFinerGrainedTensorContraction(f);
index a70cad8..8e5a1c6 100644 (file)
@@ -109,7 +109,7 @@ TEST_FUNC(execution) {
   // linalg.matmul operation and lower it all the way down to the LLVM IR
   // dialect through partial conversions.
   MLIRContext context;
-  OwningModuleRef module = Module::create(&context);
+  OwningModuleRef module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_as_loops");
   lowerToLoops(f);
   convertLinalg3ToLLVM(*module);
index ef8097d..a1afc49 100644 (file)
@@ -64,7 +64,7 @@ FuncOp makeFunctionWithAMatmulOp(Module module, StringRef name) {
 
 TEST_FUNC(matmul_tiled_loops) {
   MLIRContext context;
-  OwningModuleRef module = Module::create(&context);
+  OwningModuleRef module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_tiled_loops");
   lowerToTiledLoops(f, {8, 9});
   PassManager pm;
@@ -95,7 +95,7 @@ TEST_FUNC(matmul_tiled_loops) {
 
 TEST_FUNC(matmul_tiled_views) {
   MLIRContext context;
-  OwningModuleRef module = Module::create(&context);
+  OwningModuleRef module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f = makeFunctionWithAMatmulOp(*module, "matmul_tiled_views");
   OpBuilder b(f.getBody());
   lowerToTiledViews(f, {b.create<ConstantIndexOp>(f.getLoc(), 8),
@@ -124,7 +124,7 @@ TEST_FUNC(matmul_tiled_views) {
 
 TEST_FUNC(matmul_tiled_views_as_loops) {
   MLIRContext context;
-  OwningModuleRef module = Module::create(&context);
+  OwningModuleRef module = Module::create(UnknownLoc::get(&context));
   mlir::FuncOp f =
       makeFunctionWithAMatmulOp(*module, "matmul_tiled_views_as_loops");
   OpBuilder b(f.getBody());
index 831e2ab..3b3f4e8 100644 (file)
@@ -70,7 +70,7 @@ public:
   mlir::Module mlirGen(ModuleAST &moduleAST) {
     // We create an empty MLIR module and codegen functions one at a time and
     // add them to the module.
-    theModule = mlir::Module::create(&context);
+    theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
 
     for (FunctionAST &F : moduleAST) {
       auto func = mlirGen(F);
index fb106d8..e0764bd 100644 (file)
@@ -71,7 +71,7 @@ public:
   mlir::OwningModuleRef mlirGen(ModuleAST &moduleAST) {
     // We create an empty MLIR module and codegen functions one at a time and
     // add them to the module.
-    theModule = mlir::Module::create(&context);
+    theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
 
     for (FunctionAST &F : moduleAST) {
       auto func = mlirGen(F);
index 0fabbfd..503b634 100644 (file)
@@ -71,7 +71,7 @@ public:
   mlir::OwningModuleRef mlirGen(ModuleAST &moduleAST) {
     // We create an empty MLIR module and codegen functions one at a time and
     // add them to the module.
-    theModule = mlir::Module::create(&context);
+    theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
 
     for (FunctionAST &F : moduleAST) {
       auto func = mlirGen(F);
index 0fc1fc4..62b49c7 100644 (file)
@@ -71,7 +71,7 @@ public:
   mlir::OwningModuleRef mlirGen(ModuleAST &moduleAST) {
     // We create an empty MLIR module and codegen functions one at a time and
     // add them to the module.
-    theModule = mlir::Module::create(&context);
+    theModule = mlir::Module::create(mlir::UnknownLoc::get(&context));
 
     for (FunctionAST &F : moduleAST) {
       auto func = mlirGen(F);
index 07ed991..f88440e 100644 (file)
@@ -63,7 +63,6 @@ public:
   MLIRContext *getContext() const { return context; }
 
   Identifier getIdentifier(StringRef str);
-  Module createModule();
 
   // Locations.
   Location getUnknownLoc();
index 59b28fd..35f72ff 100644 (file)
@@ -44,8 +44,8 @@ public:
 
   static void build(Builder *builder, OperationState *result);
 
-  /// Construct a module from the given context.
-  static ModuleOp create(MLIRContext *context);
+  /// Construct a module from the given location.
+  static ModuleOp create(Location loc);
 
   /// Operation hooks.
   static ParseResult parse(OpAsmParser *parser, OperationState *result);
index 8f38160..d7d0b4e 100644 (file)
@@ -139,7 +139,7 @@ LogicalResult
 GpuKernelToCubinPass::translateGpuKernelToCubinAnnotation(FuncOp &function) {
   Builder builder(function.getContext());
 
-  OwningModuleRef module = builder.createModule();
+  OwningModuleRef module = Module::create(function.getLoc());
 
   // TODO(herhut): Also handle called functions.
   module->push_back(function.clone());
index ddead2e..40f1622 100644 (file)
@@ -32,8 +32,6 @@ Identifier Builder::getIdentifier(StringRef str) {
   return Identifier::get(str, context);
 }
 
-Module Builder::createModule() { return Module::create(context); }
-
 //===----------------------------------------------------------------------===//
 // Locations.
 //===----------------------------------------------------------------------===//
index 70d8e45..ff986b8 100644 (file)
@@ -38,9 +38,9 @@ void ModuleOp::build(Builder *builder, OperationState *result) {
 }
 
 /// Construct a module from the given context.
-ModuleOp ModuleOp::create(MLIRContext *context) {
-  OperationState state(UnknownLoc::get(context), "module");
-  Builder builder(context);
+ModuleOp ModuleOp::create(Location loc) {
+  OperationState state(loc, "module");
+  Builder builder(loc->getContext());
   ModuleOp::build(&builder, &state);
   return llvm::cast<ModuleOp>(Operation::create(state));
 }
index 444d192..929796e 100644 (file)
@@ -3982,9 +3982,11 @@ ParseResult ModuleParser::parseModule(ModuleOp module) {
 /// null.
 Module mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr,
                              MLIRContext *context) {
+  auto sourceBuf = sourceMgr.getMemoryBuffer(sourceMgr.getMainFileID());
 
   // This is the result module we are parsing into.
-  OwningModuleRef module(Module::create(context));
+  OwningModuleRef module(Module::create(FileLineColLoc::get(
+      sourceBuf->getBufferIdentifier(), /*line=*/0, /*column=*/0, context)));
 
   ParserState state(sourceMgr, context);
   if (ModuleParser(state).parseModule(*module))
index d1efd56..9adf852 100644 (file)
@@ -80,7 +80,8 @@ OwningModuleRef deserializeModule(llvm::StringRef inputFilename,
   // converted SPIR-V ModuleOp inside a MLIR module. This should be changed to
   // return the SPIR-V ModuleOp directly after module and function are migrated
   // to be general ops.
-  OwningModuleRef module(builder.createModule());
+  OwningModuleRef module(Module::create(
+      FileLineColLoc::get(inputFilename, /*line=*/0, /*column=*/0, context)));
   Block *block = createOneBlockFunction(builder, module.get());
   block->push_front(spirvModule->getOperation());
 
index b6de02e..732cd51 100644 (file)
@@ -37,7 +37,7 @@ TEST(AnalysisManagerTest, FineGrainModuleAnalysisPreservation) {
   MLIRContext context;
 
   // Test fine grain invalidation of the module analysis manager.
-  OwningModuleRef module(Module::create(&context));
+  OwningModuleRef module(Module::create(UnknownLoc::get(&context)));
   ModuleAnalysisManager mam(*module, /*passInstrumentor=*/nullptr);
 
   // Query two different analyses, but only preserve one before invalidating.
@@ -58,7 +58,7 @@ TEST(AnalysisManagerTest, FineGrainFunctionAnalysisPreservation) {
   Builder builder(&context);
 
   // Create a function and a module.
-  OwningModuleRef module(Module::create(&context));
+  OwningModuleRef module(Module::create(UnknownLoc::get(&context)));
   FuncOp func1 =
       FuncOp::create(builder.getUnknownLoc(), "foo",
                      builder.getFunctionType(llvm::None, llvm::None));
@@ -86,7 +86,7 @@ TEST(AnalysisManagerTest, FineGrainChildFunctionAnalysisPreservation) {
   Builder builder(&context);
 
   // Create a function and a module.
-  OwningModuleRef module(Module::create(&context));
+  OwningModuleRef module(Module::create(UnknownLoc::get(&context)));
   FuncOp func1 =
       FuncOp::create(builder.getUnknownLoc(), "foo",
                      builder.getFunctionType(llvm::None, llvm::None));