Strongly home flag registration statics in C++ files. (#12372)
The way this was, the statics were getting visibility restricted due to
being inline in headers and an interplay of esoteric rules. Strongly
homing such things in cc files is the gold standard, so do that. This
fixes some lingering flag registration issues in shared library builds.
diff --git a/compiler/src/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp b/compiler/src/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp
index 025bb82..4e0b6d5 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp
+++ b/compiler/src/iree/compiler/Dialect/HAL/Target/TargetBackend.cpp
@@ -15,6 +15,9 @@
#include "mlir/IR/Dialect.h"
#include "mlir/Support/FileUtilities.h"
+IREE_DEFINE_COMPILER_OPTION_FLAGS(
+ mlir::iree_compiler::IREE::HAL::TargetOptions);
+
namespace mlir {
namespace iree_compiler {
namespace IREE {
diff --git a/compiler/src/iree/compiler/Dialect/VM/Conversion/TargetOptions.cpp b/compiler/src/iree/compiler/Dialect/VM/Conversion/TargetOptions.cpp
index 3f93629..02add2d 100644
--- a/compiler/src/iree/compiler/Dialect/VM/Conversion/TargetOptions.cpp
+++ b/compiler/src/iree/compiler/Dialect/VM/Conversion/TargetOptions.cpp
@@ -8,6 +8,8 @@
#include "llvm/Support/CommandLine.h"
+IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::IREE::VM::TargetOptions);
+
namespace mlir {
namespace iree_compiler {
namespace IREE {
diff --git a/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp b/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp
index 7f38e52..31cbebe 100644
--- a/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp
+++ b/compiler/src/iree/compiler/Dialect/VM/Target/Bytecode/BytecodeModuleTarget.cpp
@@ -39,6 +39,9 @@
#include "mlir/Transforms/LocationSnapshot.h"
#include "mlir/Transforms/Passes.h"
+IREE_DEFINE_COMPILER_OPTION_FLAGS(
+ mlir::iree_compiler::IREE::VM::BytecodeTargetOptions);
+
namespace mlir {
namespace iree_compiler {
namespace IREE {
diff --git a/compiler/src/iree/compiler/Pipelines/Options.cpp b/compiler/src/iree/compiler/Pipelines/Options.cpp
index 51642e9..c5dfcc2 100644
--- a/compiler/src/iree/compiler/Pipelines/Options.cpp
+++ b/compiler/src/iree/compiler/Pipelines/Options.cpp
@@ -6,6 +6,13 @@
#include "iree/compiler/Pipelines/Options.h"
+IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::BindingOptions);
+IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::InputDialectOptions);
+IREE_DEFINE_COMPILER_OPTION_FLAGS(
+ mlir::iree_compiler::HighLevelOptimizationOptions);
+IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::SchedulingOptions);
+IREE_DEFINE_COMPILER_OPTION_FLAGS(mlir::iree_compiler::PreprocessingOptions);
+
namespace mlir {
namespace iree_compiler {
diff --git a/compiler/src/iree/compiler/Utils/OptionUtils.h b/compiler/src/iree/compiler/Utils/OptionUtils.h
index 4bc2f3e..33b17a9 100644
--- a/compiler/src/iree/compiler/Utils/OptionUtils.h
+++ b/compiler/src/iree/compiler/Utils/OptionUtils.h
@@ -209,21 +209,31 @@
llvm::SmallVector<LocalOptionInfo> localOptions;
};
+// Generic class that is used for allocating an Options class that initializes
+// from flags. Every Options type that can have FromFlags called on it needs
+// to include definitions in one implementation module (at the top level
+// namespace):
+// IREE_DEFINE_COMPILER_OPTION_FLAGS(DerivedTy);
template <typename DerivedTy>
class OptionsFromFlags {
public:
- static DerivedTy &get() {
- struct InitializedTy : DerivedTy {
- InitializedTy() {
- OptionsBinder binder = OptionsBinder::global();
- DerivedTy::bindOptions(binder);
- }
- };
- static InitializedTy singleton;
- return singleton;
- }
+ static DerivedTy &get();
};
+#define IREE_DEFINE_COMPILER_OPTION_FLAGS(DerivedTy) \
+ template <> \
+ DerivedTy &mlir::iree_compiler::OptionsFromFlags<DerivedTy>::get() { \
+ struct InitializedTy : DerivedTy { \
+ InitializedTy() { \
+ mlir::iree_compiler::OptionsBinder binder = \
+ mlir::iree_compiler::OptionsBinder::global(); \
+ DerivedTy::bindOptions(binder); \
+ } \
+ }; \
+ static InitializedTy singleton; \
+ return singleton; \
+ }
+
} // namespace iree_compiler
} // namespace mlir