Integrate LLVM at llvm/llvm-project@7c57a9bd7d4c Updates LLVM usage to match [7c57a9bd7d4c](https://github.com/llvm/llvm-project/commit/7c57a9bd7d4c) PiperOrigin-RevId: 373739370
diff --git a/SUBMODULE_VERSIONS.txt b/SUBMODULE_VERSIONS.txt index a7ecc5a..1cbfb0b 100644 --- a/SUBMODULE_VERSIONS.txt +++ b/SUBMODULE_VERSIONS.txt
@@ -5,7 +5,7 @@ b1fbd33c06cdb0024c67733c6fdec2009d17b384 third_party/googletest 88b845dee001723c4a0db1fe5477de735b6d3bb0 third_party/liburing 9c5ff8e6e5a2fb264a27ea7ed0e16a5b10430f36 third_party/llvm-bazel -b7a11274f90f07537e2151fa4424db257ff9a950 third_party/llvm-project +7c57a9bd7d4c976b7a824472c427433359200e02 third_party/llvm-project 679d7183b657a24f48d16de1fcefb20d7cd1f6a2 third_party/mlir-emitc d2cc74317c312d5679cf7465e79c63349dcf5207 third_party/mlir-hlo 2b2bd45bbf9be04fd22ece5cc1f54679202e9257 third_party/pffft
diff --git a/bindings/python/tests/compiler_core_test.py b/bindings/python/tests/compiler_core_test.py index 1c64392..88b01fc 100644 --- a/bindings/python/tests/compiler_core_test.py +++ b/bindings/python/tests/compiler_core_test.py
@@ -125,14 +125,14 @@ self.assertIn("vm.module", text) def testExtraArgsStderr(self): - # pass-timing is not special: it just does something and emits to stderr. + # mlir-timing is not special: it just does something and emits to stderr. with io.StringIO() as buf, contextlib.redirect_stderr(buf): iree.compiler.compile_str( SIMPLE_MUL_ASM, - extra_args=["--pass-timing"], + extra_args=["--mlir-timing"], target_backends=iree.compiler.DEFAULT_TESTING_BACKENDS) stderr = buf.getvalue() - self.assertIn("Pass execution timing report", stderr) + self.assertIn("Execution time report", stderr) def testAllOptions(self): binary = iree.compiler.compile_str(
diff --git a/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp b/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp index 426bf3d..f9c013c 100644 --- a/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp +++ b/integrations/tensorflow/iree_tf_compiler/iree-import-tflite-main.cpp
@@ -64,6 +64,7 @@ registerAsmPrinterCLOptions(); registerMLIRContextCLOptions(); registerPassManagerCLOptions(); + registerDefaultTimingManagerCLOptions(); cl::ParseCommandLineOptions(argc, argv); // Initialize dialects. @@ -128,6 +129,7 @@ // Run transformations. PassManager pm(&context, PassManager::Nesting::Implicit); applyPassManagerCLOptions(pm); + applyDefaultTimingPassManagerCLOptions(pm); mlir::iree_integrations::TFL::buildTFLImportPassPipeline(pm); if (failed(pm.run(*module))) { llvm::errs() << "Running iree-import-tflite pass pipeline failed (see "
diff --git a/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp b/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp index e18d1eb..f281422 100644 --- a/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp +++ b/integrations/tensorflow/iree_tf_compiler/iree-import-xla-main.cpp
@@ -119,6 +119,7 @@ // Register any command line options. registerAsmPrinterCLOptions(); registerMLIRContextCLOptions(); + registerDefaultTimingManagerCLOptions(); cl::ParseCommandLineOptions(argc, argv); DialectRegistry registry; @@ -219,6 +220,7 @@ // Run passes. PassManager pm(&context, PassManager::Nesting::Implicit); applyPassManagerCLOptions(pm); + applyDefaultTimingPassManagerCLOptions(pm); iree_integrations::TF::buildMHLOImportPassPipeline(pm);
diff --git a/integrations/tensorflow/iree_tf_compiler/iree-tf-import-main.cpp b/integrations/tensorflow/iree_tf_compiler/iree-tf-import-main.cpp new file mode 100644 index 0000000..a34daa0 --- /dev/null +++ b/integrations/tensorflow/iree_tf_compiler/iree-tf-import-main.cpp
@@ -0,0 +1,244 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Main entry function for the iree-tf-import tool (and derived binaries). +// Note that this is not an e2e tool: it is purely the first stage of the +// pipeline intended to lower TensorFlow GraphDefs and SavedModels to a form +// suitable for input to the IREE compiler. +// +// Since none of the TensorFlow imports come from an MLIR text form, it is a bit +// of an odd fit for a *-translate style tool, which is why this diverges. + +#include "iree_tf_compiler/TF/Passes.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/ToolOutputFile.h" +#include "mlir/IR/AsmState.h" +#include "mlir/IR/BuiltinOps.h" +#include "mlir/IR/Dialect.h" +#include "mlir/IR/MLIRContext.h" +#include "mlir/IR/OperationSupport.h" +#include "mlir/Pass/PassManager.h" +#include "mlir/Support/FileUtilities.h" +#include "tensorflow/cc/saved_model/loader.h" +#include "tensorflow/compiler/mlir/init_mlir.h" +#include "tensorflow/compiler/mlir/tensorflow/dialect_registration.h" +#include "tensorflow/compiler/mlir/tensorflow/translate/import_model.h" +#include "tensorflow/core/platform/errors.h" +using namespace llvm; +using namespace mlir; + +namespace { + +enum ImportType { + savedmodel_v2, + savedmodel_v1, +}; + +} // namespace + +static OwningModuleRef importSavedModelV2( + MLIRContext &context, const std::string &inputPath, + const std::string &savedModelExportedNames) { + tensorflow::SavedModelV2Bundle bundle; + auto loadStatus = tensorflow::SavedModelV2Bundle::Load(inputPath, &bundle); + if (!loadStatus.ok()) { + llvm::errs() << "TensorFlow reported error loading saved model:\n " + << loadStatus.ToString() << "\n\n"; + if (!tensorflow::errors::IsNotFound(loadStatus)) { + llvm::errs() + << "Note: Attempted to load V2 SavedModel. Double check that " + "this is correct " + << "and adjust via the flag " + "--tf-import-type=savedmodel_v1|savedmodel_v2\n"; + } + return nullptr; + } + + std::vector<std::string> exportedNamesVector = + absl::StrSplit(savedModelExportedNames, ',', absl::SkipEmpty()); + auto loadedModule = tensorflow::ConvertSavedModelToMlir( + &bundle, &context, absl::MakeSpan(exportedNamesVector)); + if (!loadedModule.ok()) { + llvm::errs() << "Error performing initial import from SavedModel to MLIR. " + << "Reported error below (and see diagnostics):\n" + << " " << loadedModule.status().ToString() << "\n"; + return nullptr; + } + + return loadedModule.ConsumeValueOrDie(); +} + +static OwningModuleRef importSavedModelV1( + MLIRContext &context, const std::string &inputPath, + const std::string &savedModelExportedNames, + const std::string &savedModelTags) { + tensorflow::SavedModelBundle bundle; + tensorflow::SessionOptions session_options; + // Force saved model states to be restored to CPU. + (*session_options.config.mutable_device_count())["GPU"] = 0; + + std::unordered_set<std::string> tags = + absl::StrSplit(savedModelTags, ',', absl::SkipEmpty()); + auto loadStatus = + tensorflow::LoadSavedModel(session_options, + /*run_options=*/{}, inputPath, tags, &bundle); + if (!loadStatus.ok()) { + llvm::errs() << "TensorFlow reported error loading saved model:\n " + << loadStatus.ToString() << "\n\n"; + if (!tensorflow::errors::IsNotFound(loadStatus)) { + llvm::errs() + << "Note: Attempted to load V1 SavedModel. Double check that " + "this is correct " + << "and adjust via the flag " + "--tf-import-type=savedmodel_v1|savedmodel_v2\n"; + } + return nullptr; + } + + std::vector<std::string> exportedNamesVector = + absl::StrSplit(savedModelExportedNames, ',', absl::SkipEmpty()); + + tensorflow::MLIRImportOptions import_options; + auto loadedModule = ConvertSavedModelV1ToMlir( + bundle, absl::MakeSpan(exportedNamesVector), &context, import_options); + + if (!loadedModule.ok()) { + llvm::errs() << "Error performing initial import from SavedModel to MLIR. " + << "Reported error below (and see diagnostics):\n" + << " " << loadedModule.status().ToString() << "\n"; + return nullptr; + } + + return loadedModule.ConsumeValueOrDie(); +} + +int main(int argc, char **argv) { + tensorflow::InitMlir y(&argc, &argv); + + static cl::opt<std::string> inputPath( + cl::Positional, cl::desc("<saved model directory>"), cl::Required); + static cl::opt<std::string> outputFilename("o", cl::desc("Output filename"), + cl::value_desc("filename"), + cl::init("-")); + static cl::opt<ImportType> importType( + "tf-import-type", cl::desc("The type of TensorFlow model to import"), + cl::values(clEnumVal(savedmodel_v2, + "Import a TensorFlow SavedModel V2 (directory)"), + clEnumVal(savedmodel_v1, + "Import a TensorFlow SavedModel V1 (directory)"))); + + static llvm::cl::opt<std::string> savedModelExportedNames( + "tf-savedmodel-exported-names", + llvm::cl::desc("Names to export from SavedModel, separated by ','. Empty " + "(the default) means export all."), + llvm::cl::init("")); + + static llvm::cl::opt<std::string> savedModelTags( + "tf-savedmodel-tags", + llvm::cl::desc("Tags used to indicate which MetaGraphDef to import, " + "separated by ','"), + llvm::cl::init("serve")); + static llvm::cl::opt<std::string> saveTempTfInput( + "save-temp-tf-input", + llvm::cl::desc("Save the TF pipeline input to this file"), + llvm::cl::init("")); + static llvm::cl::opt<std::string> saveTempIreeImport( + "save-temp-iree-input", + llvm::cl::desc("Save the resultant IR to this file (useful for saving an " + "intermediate in a pipeline)"), + llvm::cl::init("")); + static llvm::cl::opt<bool> prettifyTfDebugInfo( + "prettify-tf-debug-info", + llvm::cl::desc("Prettifies TF debug information to make it easier " + "to look at"), + llvm::cl::init(true)); + + // Register any command line options. + registerAsmPrinterCLOptions(); + registerMLIRContextCLOptions(); + registerPassManagerCLOptions(); + registerDefaultTimingManagerCLOptions(); + cl::ParseCommandLineOptions(argc, argv); + + DialectRegistry registry; + RegisterAllTensorFlowDialects(registry); + + MLIRContext context(registry); + context.loadAllAvailableDialects(); + + llvm::SourceMgr sourceMgr; + mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); + + OwningModuleRef module; + + auto saveToFile = [&](llvm::StringRef savePath) -> LogicalResult { + auto outputFile = openOutputFile(savePath); + if (!outputFile) { + llvm::errs() << "Could not open output file: " << savePath << "\n"; + return failure(); + } + OpPrintingFlags printFlags; + module->print(outputFile->os(), printFlags); + outputFile->os() << "\n"; + outputFile->keep(); + return success(); + }; + + // First stage import. + switch (importType) { + case savedmodel_v2: + module = importSavedModelV2(context, inputPath, savedModelExportedNames); + break; + case savedmodel_v1: + module = importSavedModelV1(context, inputPath, savedModelExportedNames, + savedModelTags); + break; + default: + llvm_unreachable("unsupported import type enum"); + } + if (!module) return 1; + + // Save temp output. + if (!saveTempTfInput.empty()) { + if (failed(saveToFile(saveTempTfInput))) return 10; + } + + // Run passes. + PassManager pm(&context, PassManager::Nesting::Implicit); + applyPassManagerCLOptions(pm); + applyDefaultTimingPassManagerCLOptions(pm); + + if (prettifyTfDebugInfo) { + pm.addPass(iree_integrations::TF::createPrettifyDebugInfoPass()); + } + + iree_integrations::TF::buildTFImportPassPipeline(pm); + if (failed(pm.run(*module))) { + llvm::errs() + << "Running iree-tf-import pass pipeline failed (see diagnostics)\n"; + return 2; + } + + // Save temp output. + if (!saveTempIreeImport.empty()) { + if (failed(saveToFile(saveTempIreeImport))) return 10; + } + + // Save output. + if (failed(saveToFile(outputFilename))) return 3; + return 0; +}
diff --git a/iree/compiler/Conversion/LinalgToLLVM/PlanConvLoopOrder.cpp b/iree/compiler/Conversion/LinalgToLLVM/PlanConvLoopOrder.cpp index 3f87a4a..9a00c68 100644 --- a/iree/compiler/Conversion/LinalgToLLVM/PlanConvLoopOrder.cpp +++ b/iree/compiler/Conversion/LinalgToLLVM/PlanConvLoopOrder.cpp
@@ -57,8 +57,8 @@ OwningRewritePatternList patterns(&getContext()); linalg::populateLinalgConvGeneralizationPatterns(patterns, firstStepMarker); - patterns.insert<linalg::LinalgInterchangePattern<linalg::GenericOp>>( - context, loopOrder, secondStepMarker); + patterns.insert<linalg::GenericOpInterchangePattern>(context, loopOrder, + secondStepMarker); (void)applyPatternsAndFoldGreedily(funcOp, std::move(patterns)); }
diff --git a/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp b/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp index 2cf8812..f9b1593 100644 --- a/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp +++ b/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp
@@ -353,6 +353,7 @@ PassManager passManager(context); mlir::applyPassManagerCLOptions(passManager); + mlir::applyDefaultTimingPassManagerCLOptions(passManager); passManager.addInstrumentation(std::make_unique<PassTracing>()); auto &modulePasses = passManager.nest<IREE::VM::ModuleOp>();
diff --git a/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp b/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp index 0aa51cb..7ff6818 100644 --- a/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp +++ b/iree/compiler/Dialect/VM/Target/C/CModuleTarget.cpp
@@ -640,6 +640,7 @@ PassManager passManager(context); mlir::applyPassManagerCLOptions(passManager); + mlir::applyDefaultTimingPassManagerCLOptions(passManager); auto &modulePasses = passManager.nest<IREE::VM::ModuleOp>(); if (targetOptions.optimize) {
diff --git a/iree/compiler/Translation/IREEVM.cpp b/iree/compiler/Translation/IREEVM.cpp index 07dc6ac..2a14f49 100644 --- a/iree/compiler/Translation/IREEVM.cpp +++ b/iree/compiler/Translation/IREEVM.cpp
@@ -88,6 +88,7 @@ static LogicalResult convertToFlowModule(ModuleOp moduleOp) { PassManager passManager(moduleOp.getContext()); mlir::applyPassManagerCLOptions(passManager); + mlir::applyDefaultTimingPassManagerCLOptions(passManager); passManager.addInstrumentation(std::make_unique<PassTracing>()); IREE::Flow::buildInputTransformPassPipeline(passManager); IREE::Flow::buildFlowTransformPassPipeline(passManager); @@ -104,6 +105,7 @@ ModuleOp moduleOp, IREE::HAL::TargetOptions executableOptions) { PassManager passManager(moduleOp.getContext()); mlir::applyPassManagerCLOptions(passManager); + mlir::applyDefaultTimingPassManagerCLOptions(passManager); passManager.addInstrumentation(std::make_unique<PassTracing>()); IREE::HAL::buildHALTransformPassPipeline(passManager, executableOptions); if (failed(passManager.run(moduleOp))) { @@ -120,6 +122,7 @@ IREE::VM::TargetOptions targetOptions) { PassManager passManager(moduleOp.getContext()); mlir::applyPassManagerCLOptions(passManager); + mlir::applyDefaultTimingPassManagerCLOptions(passManager); passManager.addInstrumentation(std::make_unique<PassTracing>()); IREE::VM::buildVMTransformPassPipeline(passManager, targetOptions); if (failed(passManager.run(moduleOp))) { @@ -180,6 +183,7 @@ IREE::VM::TargetOptions targetOptions) { PassManager passManager(moduleOp.getContext()); mlir::applyPassManagerCLOptions(passManager); + mlir::applyDefaultTimingPassManagerCLOptions(passManager); passManager.addInstrumentation(std::make_unique<PassTracing>()); buildIREEVMTransformPassPipeline(bindingOptions, executableOptions, targetOptions, passManager);
diff --git a/iree/tools/iree-run-mlir-main.cc b/iree/tools/iree-run-mlir-main.cc index 92a0244..ac0adc5 100644 --- a/iree/tools/iree-run-mlir-main.cc +++ b/iree/tools/iree-run-mlir-main.cc
@@ -198,6 +198,7 @@ mlir::PassManager pass_manager(mlir_module->getContext()); pass_manager.enableVerifier(verifyPasses); mlir::applyPassManagerCLOptions(pass_manager); + mlir::applyDefaultTimingPassManagerCLOptions(pass_manager); mlir::iree_compiler::buildDefaultIREEVMTransformPassPipeline(pass_manager); if (failed(pass_manager.run(mlir_module.get()))) { return iree_make_status(IREE_STATUS_INTERNAL,
diff --git a/iree/tools/iree-translate-main.cc b/iree/tools/iree-translate-main.cc index dacb260..d0581da 100644 --- a/iree/tools/iree-translate-main.cc +++ b/iree/tools/iree-translate-main.cc
@@ -88,6 +88,7 @@ mlir::registerAsmPrinterCLOptions(); // Register pass manager command-line options like -print-ir-*. mlir::registerPassManagerCLOptions(); + mlir::registerDefaultTimingManagerCLOptions(); // Add flags for all the registered translations. llvm::cl::opt<const mlir::TranslateFunction *, false, mlir::TranslationParser>
diff --git a/third_party/llvm-project b/third_party/llvm-project index b7a1127..7c57a9b 160000 --- a/third_party/llvm-project +++ b/third_party/llvm-project
@@ -1 +1 @@ -Subproject commit b7a11274f90f07537e2151fa4424db257ff9a950 +Subproject commit 7c57a9bd7d4c976b7a824472c427433359200e02