NFC: Refactor the files related to passes.

* PassRegistry is split into its own source file.
* Pass related files are moved to a new library 'Pass'.

PiperOrigin-RevId: 234705771
This commit is contained in:
River Riddle 2019-02-19 17:17:46 -08:00 committed by jpienaar
parent 5021dc4fa0
commit 48ccae2476
33 changed files with 188 additions and 170 deletions

View File

@ -11,7 +11,7 @@
#include "third_party/llvm/llvm/projects/google_mlir/include/mlir/ExecutionEngine/ExecutionEngine.h"
#include "third_party/llvm/llvm/projects/google_mlir/include/mlir/IR/BuiltinOps.h"
#include "third_party/llvm/llvm/projects/google_mlir/include/mlir/IR/Module.h"
#include "third_party/llvm/llvm/projects/google_mlir/include/mlir/Pass.h"
#include "third_party/llvm/llvm/projects/google_mlir/include/mlir/Pass/Pass.h"
#include "third_party/llvm/llvm/projects/google_mlir/include/mlir/Target/LLVMIR.h"
#include "third_party/llvm/llvm/projects/google_mlir/include/mlir/Transforms/Passes.h"
#include "pybind11/pybind11.h"

View File

@ -15,13 +15,10 @@
// limitations under the License.
// =============================================================================
#ifndef MLIR_PASS_H
#define MLIR_PASS_H
#ifndef MLIR_PASS_PASS_H
#define MLIR_PASS_PASS_H
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include <functional>
#include "mlir/Pass/PassRegistry.h"
namespace mlir {
class Function;
@ -36,8 +33,6 @@ struct LLVM_NODISCARD PassResult {
operator bool() const { return value == Failure; }
};
class PassInfo;
class Pass {
public:
explicit Pass(const void *passID) : passID(passID) {}
@ -92,66 +87,6 @@ public:
// Iterates over all functions in a module, halting upon failure.
virtual PassResult runOnModule(Module *m) override;
};
using PassAllocatorFunction = std::function<Pass *()>;
/// Structure to group information about a pass (argument to invoke via
/// mlir-opt, description, pass allocator and unique ID).
class PassInfo {
public:
/// PassInfo constructor should not be invoked directly, instead use
/// PassRegistration or registerPass.
PassInfo(StringRef arg, StringRef description, const void *passID,
PassAllocatorFunction allocator)
: arg(arg), description(description), allocator(allocator),
passID(passID) {}
/// Returns an allocated instance of this pass.
Pass *createPass() const {
assert(allocator &&
"Cannot call createPass on PassInfo without default allocator");
return allocator();
}
/// Returns the command line option that may be passed to 'mlir-opt' that will
/// cause this pass to run or null if there is no such argument.
StringRef getPassArgument() const { return arg; }
/// Returns a description for the pass, this never returns null.
StringRef getPassDescription() const { return description; }
private:
// The argument with which to invoke the pass via mlir-opt.
StringRef arg;
// Description of the pass.
StringRef description;
// Allocator to construct an instance of this pass.
PassAllocatorFunction allocator;
// Unique identifier for pass.
const void *passID;
};
/// Register a specific dialect creation function with the system, typically
/// used through the PassRegistration template.
void registerPass(StringRef arg, StringRef description, const void *passID,
const PassAllocatorFunction &function);
/// PassRegistration provides a global initializer that registers a Pass
/// allocation routine.
///
/// Usage:
///
/// // At namespace scope.
/// static PassRegistration<MyPass> Unused("unused", "Unused pass");
template <typename ConcretePass> struct PassRegistration {
PassRegistration(StringRef arg, StringRef description) {
registerPass(arg, description, &ConcretePass::passID,
[&]() { return new ConcretePass(); });
}
};
} // end namespace mlir
#endif // MLIR_PASS_H
#endif // MLIR_PASS_PASS_H

View File

@ -0,0 +1,104 @@
//===- PassRegistry.h - Pass Registration Utilities -------------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
// 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
//
// http://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.
// =============================================================================
//
// This file contains utilities for registering information about compiler
// passes.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_PASS_PASSREGISTRY_H_
#define MLIR_PASS_PASSREGISTRY_H_
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include <functional>
namespace mlir {
class Pass;
using PassAllocatorFunction = std::function<Pass *()>;
/// Structure to group information about a pass (argument to invoke via
/// mlir-opt, description, pass allocator and unique ID).
class PassInfo {
public:
/// PassInfo constructor should not be invoked directly, instead use
/// PassRegistration or registerPass.
PassInfo(StringRef arg, StringRef description, const void *passID,
PassAllocatorFunction allocator)
: arg(arg), description(description), allocator(allocator),
passID(passID) {}
/// Returns an allocated instance of this pass.
Pass *createPass() const {
assert(allocator &&
"Cannot call createPass on PassInfo without default allocator");
return allocator();
}
/// Returns the command line option that may be passed to 'mlir-opt' that will
/// cause this pass to run or null if there is no such argument.
StringRef getPassArgument() const { return arg; }
/// Returns a description for the pass, this never returns null.
StringRef getPassDescription() const { return description; }
private:
// The argument with which to invoke the pass via mlir-opt.
StringRef arg;
// Description of the pass.
StringRef description;
// Allocator to construct an instance of this pass.
PassAllocatorFunction allocator;
// Unique identifier for pass.
const void *passID;
};
/// Register a specific dialect creation function with the system, typically
/// used through the PassRegistration template.
void registerPass(StringRef arg, StringRef description, const void *passID,
const PassAllocatorFunction &function);
/// PassRegistration provides a global initializer that registers a Pass
/// allocation routine.
///
/// Usage:
///
/// // At namespace scope.
/// static PassRegistration<MyPass> Unused("unused", "Unused pass");
template <typename ConcretePass> struct PassRegistration {
PassRegistration(StringRef arg, StringRef description) {
registerPass(arg, description, &ConcretePass::passID,
[&]() { return new ConcretePass(); });
}
};
/// Adds command line option for each registered pass.
struct PassNameParser : public llvm::cl::parser<const PassInfo *> {
PassNameParser(llvm::cl::Option &opt);
void printOptionInfo(const llvm::cl::Option &O,
size_t GlobalWidth) const override;
};
} // end namespace mlir
#endif // MLIR_PASS_PASSREGISTRY_H_

View File

@ -1,40 +0,0 @@
//===- PassNameParser.h - Base classes for compiler passes ------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
// 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
//
// http://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.
// =============================================================================
//
// The PassNameParser class adds all passes linked in to the system that are
// creatable to the tool.
//
//===----------------------------------------------------------------------===//
#ifndef MLIR_SUPPORT_PASSNAMEPARSER_H_
#define MLIR_SUPPORT_PASSNAMEPARSER_H_
#include "llvm/Support/CommandLine.h"
namespace mlir {
class PassInfo;
/// Adds command line option for each registered pass.
struct PassNameParser : public llvm::cl::parser<const PassInfo *> {
PassNameParser(llvm::cl::Option &opt);
void printOptionInfo(const llvm::cl::Option &O,
size_t GlobalWidth) const override;
};
} // end namespace mlir
#endif // MLIR_SUPPORT_PASSNAMEPARSER_H_

View File

@ -23,7 +23,7 @@
#define MLIR_TRANSFORMS_DIALECTCONVERSION_H_
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/LLVM.h"
namespace mlir {

View File

@ -24,7 +24,7 @@
#define MLIR_TRANSFORMS_MLPATTERNLOWERINGPASS_H
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include <type_traits>
namespace mlir {

View File

@ -26,7 +26,7 @@
#include "mlir/IR/AffineStructures.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "llvm/Support/Debug.h"

View File

@ -25,7 +25,7 @@
#include "mlir/IR/AffineStructures.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "llvm/Support/Debug.h"

View File

@ -18,7 +18,7 @@
#include "mlir/IR/Instruction.h"
#include "mlir/IR/Module.h"
#include "mlir/IR/OperationSupport.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"

View File

@ -23,7 +23,7 @@
#include "mlir/IR/Module.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/IR/Types.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "llvm/Support/raw_ostream.h"

View File

@ -22,7 +22,7 @@
#include "mlir/ExecutionEngine/ExecutionEngine.h"
#include "mlir/IR/Function.h"
#include "mlir/IR/Module.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Target/LLVMIR.h"
#include "mlir/Transforms/Passes.h"

View File

@ -26,7 +26,7 @@
#include "mlir/IR/Module.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/LLVMIR/LLVMDialect.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/Support/Functional.h"
#include "mlir/Transforms/DialectConversion.h"

47
mlir/lib/Pass/Pass.cpp Normal file
View File

@ -0,0 +1,47 @@
//===- Pass.cpp - Pass infrastructure implementation ----------------------===//
//
// Copyright 2019 The MLIR Authors.
//
// 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
//
// http://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.
// =============================================================================
//
// This file implements common pass infrastructure.
//
//===----------------------------------------------------------------------===//
#include "mlir/Pass/Pass.h"
#include "mlir/IR/Module.h"
using namespace mlir;
/// Out of line virtual method to ensure vtables and metadata are emitted to a
/// single .o file.
void Pass::anchor() {}
/// Out of line virtual method to ensure vtables and metadata are emitted to a
/// single .o file.
void ModulePass::anchor() {}
/// Function passes walk a module and look at each function with their
/// corresponding hooks and terminates upon error encountered.
PassResult FunctionPass::runOnModule(Module *m) {
for (auto &fn : *m) {
// All function passes ignore external functions.
if (fn.empty())
continue;
if (runOnFunction(&fn))
return failure();
}
return success();
}

View File

@ -1,4 +1,4 @@
//===- Pass.cpp - Pass infrastructure implementation ----------------------===//
//===- PassRegistry.cpp - Pass Registration Utilities ---------------------===//
//
// Copyright 2019 The MLIR Authors.
//
@ -14,42 +14,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
//
// This file implements common pass infrastructure.
//
//===----------------------------------------------------------------------===//
#include "mlir/Pass.h"
#include "mlir/IR/Function.h"
#include "mlir/IR/Module.h"
#include "mlir/Support/PassNameParser.h"
#include "mlir/Pass/PassRegistry.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/ManagedStatic.h"
using namespace mlir;
/// Out of line virtual method to ensure vtables and metadata are emitted to a
/// single .o file.
void Pass::anchor() {}
/// Out of line virtual method to ensure vtables and metadata are emitted to a
/// single .o file.
void ModulePass::anchor() {}
/// Function passes walk a module and look at each function with their
/// corresponding hooks and terminates upon error encountered.
PassResult FunctionPass::runOnModule(Module *m) {
for (auto &fn : *m) {
// All function passes ignore external functions.
if (fn.empty())
continue;
if (runOnFunction(&fn))
return failure();
}
return success();
}
// TODO: The pass registry and pass name parsing should be moved out.
/// Static mapping of all of the registered passes.
static llvm::ManagedStatic<llvm::DenseMap<const void *, PassInfo>> passRegistry;
void mlir::registerPass(StringRef arg, StringRef description,

View File

@ -24,7 +24,7 @@
#include "mlir/IR/Attributes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Function.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/Functional.h"
#include "mlir/Transforms/Passes.h"
#include "mlir/Transforms/Utils.h"

View File

@ -22,7 +22,7 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/Passes.h"
using namespace mlir;

View File

@ -18,7 +18,7 @@
#include "mlir/AffineOps/AffineOps.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/Function.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/Passes.h"
#include "mlir/Transforms/Utils.h"

View File

@ -26,7 +26,7 @@
#include "mlir/IR/AffineStructures.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/Transforms/Passes.h"
#include "mlir/Transforms/Utils.h"

View File

@ -28,7 +28,7 @@
#include "mlir/IR/AffineStructures.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/Transforms/LoopUtils.h"
#include "mlir/Transforms/Passes.h"

View File

@ -24,7 +24,7 @@
#include "mlir/Analysis/LoopAnalysis.h"
#include "mlir/IR/AffineStructures.h"
#include "mlir/IR/Builders.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/LoopUtils.h"
#include "mlir/Transforms/Passes.h"
#include "mlir/Transforms/Utils.h"

View File

@ -27,7 +27,7 @@
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/LoopUtils.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/CommandLine.h"

View File

@ -50,7 +50,7 @@
#include "mlir/IR/BlockAndValueMapping.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/LoopUtils.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/CommandLine.h"

View File

@ -26,7 +26,7 @@
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/Support/Functional.h"
#include "mlir/Transforms/Passes.h"

View File

@ -36,7 +36,7 @@
#include "mlir/IR/OperationSupport.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/Types.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/SuperVectorOps/SuperVectorOps.h"
#include "mlir/Support/Functional.h"

View File

@ -36,7 +36,7 @@
#include "mlir/IR/Location.h"
#include "mlir/IR/OperationSupport.h"
#include "mlir/IR/Types.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/SuperVectorOps/SuperVectorOps.h"
#include "mlir/Support/Functional.h"

View File

@ -25,7 +25,7 @@
#include "mlir/Analysis/AffineAnalysis.h"
#include "mlir/Analysis/Dominance.h"
#include "mlir/Analysis/Utils.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/Transforms/Passes.h"
#include "llvm/ADT/SmallPtrSet.h"

View File

@ -26,7 +26,7 @@
#include "mlir/Analysis/LoopAnalysis.h"
#include "mlir/Analysis/Utils.h"
#include "mlir/IR/Builders.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/Transforms/LoopUtils.h"
#include "mlir/Transforms/Utils.h"

View File

@ -23,7 +23,7 @@
#include "mlir/IR/Function.h"
#include "mlir/IR/Instruction.h"
#include "mlir/IR/IntegerSet.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/Passes.h"
#define DEBUG_TYPE "simplify-affine-structure"

View File

@ -17,7 +17,7 @@
#include "mlir/IR/Function.h"
#include "mlir/IR/Instruction.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/Passes.h"
using namespace mlir;

View File

@ -27,7 +27,7 @@
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/StandardTypes.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/Functional.h"
#include "mlir/Support/STLExtras.h"
#include "mlir/Transforms/Passes.h"

View File

@ -29,7 +29,7 @@
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/Types.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/StandardOps/StandardOps.h"
#include "mlir/SuperVectorOps/SuperVectorOps.h"
#include "mlir/Support/Functional.h"

View File

@ -17,7 +17,7 @@
#include "mlir/Transforms/ViewFunctionGraph.h"
#include "mlir/IR/FunctionGraphTraits.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;

View File

@ -28,9 +28,8 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Module.h"
#include "mlir/Parser.h"
#include "mlir/Pass.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/PassNameParser.h"
#include "mlir/TensorFlow/ControlFlowOps.h"
#include "mlir/TensorFlow/Passes.h"
#include "mlir/TensorFlowLite/Passes.h"