For a prototype, I would like to reuse some operations of some in-tree dialects with only some slight modifications (e.g., a changed operation name). For example, I would like to create a mir.switch
operation that for now is equivalent to the cf.switch
operation, but might deviate in the future.
I would like to avoid copying the tablegen definition from ControlFlowOps.td along other stuff like the definitions for parsing the custom assembly format from ControlFlowOps.cpp. Hence, I tried to extend the mlir::cf::SwitchOp
class and only override the getOperationName()
method like so in my Mir.h
:
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/CastInterfaces.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Interfaces/VectorInterfaces.h"
#define GET_OP_CLASSES
namespace mlir {
namespace mir {
// "Copy" the switch op from the `cf` dialect.
class SwitchOp : public mlir::cf::SwitchOp {
public:
static constexpr ::llvm::StringLiteral getOperationName() {
return ::llvm::StringLiteral("mir.switch");
}
};
} // namespace mir
} // namespace mlir
MLIR_DECLARE_EXPLICIT_TYPE_ID(::mlir::mir::SwitchOp)
// clang-format off
#include "mir/MirEnums.h.inc"
#include "mir/Mir.h.inc"
After that, I register the operation in MirDialect.cpp
:
// Mir Dialect Implementation.
void MirDialect::initialize() {
// [...]
addOperations<::mlir::mir::SwitchOp>();
}
However, the build fails with
Undefined symbols for architecture x86_64:
"mlir::detail::TypeIDResolver<mlir::mir::Mir_SwitchOp, void>::id", referenced from:
mlir::detail::TypeIDResolver<mlir::mir::Mir_SwitchOp, void>::resolveTypeID() in libMLIRmir.a(MirDialect.cpp.o)
ld: symbol(s) not found for architecture x86_64
May anyone give me a hint what the problem here is? The problem only happens for this operation where I inherited from another operation, not for those that were generated by TableGen. I realized that in the error message, there is a second template parameter next to the operation, which is void
. Unfortunately, I was not able to trace back where this might come from.
P.S. I hope this is the right forum for these kinds of topics. If not, I will ask on StackOverflow…