forked from OSchip/llvm-project
Update ModuleOp::create(...) to take a Location instead of a context.
This allows for giving a Module a more interesting location than 'Unknown'. PiperOrigin-RevId: 257310117
This commit is contained in:
parent
8c44367891
commit
6b6dc59f30
|
@ -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,
|
||||
|
|
|
@ -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}, {});
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -63,7 +63,6 @@ public:
|
|||
MLIRContext *getContext() const { return context; }
|
||||
|
||||
Identifier getIdentifier(StringRef str);
|
||||
Module createModule();
|
||||
|
||||
// Locations.
|
||||
Location getUnknownLoc();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -32,8 +32,6 @@ Identifier Builder::getIdentifier(StringRef str) {
|
|||
return Identifier::get(str, context);
|
||||
}
|
||||
|
||||
Module Builder::createModule() { return Module::create(context); }
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Locations.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue