NFC: Cleanup the naming scheme for registering legalization actions to be consistent, and move a file functions to the source file.
PiperOrigin-RevId: 252639629
This commit is contained in:
parent
8ad35b90ec
commit
eb28b30940
@ -422,7 +422,7 @@ void linalg::convertToLLVM(mlir::Module &module) {
|
||||
populateLinalg1ToLLVMConversionPatterns(patterns, module.getContext());
|
||||
|
||||
ConversionTarget target(*module.getContext());
|
||||
target.addLegalDialects<LLVM::LLVMDialect>();
|
||||
target.addLegalDialect<LLVM::LLVMDialect>();
|
||||
auto r =
|
||||
applyConversionPatterns(module, target, converter, std::move(patterns));
|
||||
(void)r;
|
||||
|
||||
@ -163,7 +163,7 @@ void linalg::convertLinalg3ToLLVM(Module &module) {
|
||||
populateLinalg3ToLLVMConversionPatterns(patterns, module.getContext());
|
||||
|
||||
ConversionTarget target(*module.getContext());
|
||||
target.addLegalDialects<LLVM::LLVMDialect>();
|
||||
target.addLegalDialect<LLVM::LLVMDialect>();
|
||||
auto r =
|
||||
applyConversionPatterns(module, target, converter, std::move(patterns));
|
||||
(void)r;
|
||||
|
||||
@ -127,7 +127,7 @@ public:
|
||||
struct EarlyLoweringPass : public FunctionPass<EarlyLoweringPass> {
|
||||
void runOnFunction() override {
|
||||
ConversionTarget target(getContext());
|
||||
target.addLegalDialects<linalg::LinalgDialect, StandardOpsDialect>();
|
||||
target.addLegalDialect<linalg::LinalgDialect, StandardOpsDialect>();
|
||||
target.addLegalOp<toy::AllocOp, toy::TypeCastOp>();
|
||||
|
||||
OwningRewritePatternList patterns;
|
||||
|
||||
@ -345,8 +345,8 @@ struct LateLoweringPass : public ModulePass<LateLoweringPass> {
|
||||
|
||||
// Perform Toy specific lowering.
|
||||
ConversionTarget target(getContext());
|
||||
target.addLegalDialects<AffineOpsDialect, linalg::LinalgDialect,
|
||||
LLVM::LLVMDialect, StandardOpsDialect>();
|
||||
target.addLegalDialect<AffineOpsDialect, linalg::LinalgDialect,
|
||||
LLVM::LLVMDialect, StandardOpsDialect>();
|
||||
target.addLegalOp<toy::AllocOp, toy::TypeCastOp>();
|
||||
if (failed(applyConversionPatterns(getModule(), target, typeConverter,
|
||||
std::move(toyPatterns)))) {
|
||||
|
||||
@ -180,9 +180,7 @@ public:
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
/// Register a legality action for the given operation.
|
||||
void setOpAction(OperationName op, LegalizationAction action) {
|
||||
legalOperations[op] = action;
|
||||
}
|
||||
void setOpAction(OperationName op, LegalizationAction action);
|
||||
template <typename OpT> void setOpAction(LegalizationAction action) {
|
||||
setOpAction(OperationName(OpT::getOperationName(), &ctx), action);
|
||||
}
|
||||
@ -196,21 +194,6 @@ public:
|
||||
addLegalOp<OpT2, OpTs...>();
|
||||
}
|
||||
|
||||
/// Register the operations of the given dialects as legal.
|
||||
void addLegalDialects(ArrayRef<StringRef> dialectNames) {
|
||||
for (auto &dialect : dialectNames)
|
||||
legalDialects[dialect] = LegalizationAction::Legal;
|
||||
}
|
||||
template <typename... Names>
|
||||
void addLegalDialects(StringRef name, Names... names) {
|
||||
SmallVector<StringRef, 2> dialectNames({name, names...});
|
||||
addLegalDialects(dialectNames);
|
||||
}
|
||||
template <typename... Args> void addLegalDialects() {
|
||||
SmallVector<StringRef, 2> dialectNames({Args::getDialectNamespace()...});
|
||||
addLegalDialects(dialectNames);
|
||||
}
|
||||
|
||||
/// Register the given operation as dynamically legal, i.e. requiring custom
|
||||
/// handling by the target via 'isLegal'.
|
||||
template <typename OpT> void addDynamicallyLegalOp() {
|
||||
@ -222,22 +205,39 @@ public:
|
||||
addDynamicallyLegalOp<OpT2, OpTs...>();
|
||||
}
|
||||
|
||||
/// Register a legality action for the given dialects.
|
||||
void setDialectAction(ArrayRef<StringRef> dialectNames,
|
||||
LegalizationAction action);
|
||||
|
||||
/// Register the operations of the given dialects as legal.
|
||||
template <typename... Names>
|
||||
void addLegalDialect(StringRef name, Names... names) {
|
||||
SmallVector<StringRef, 2> dialectNames({name, names...});
|
||||
setDialectAction(dialectNames, LegalizationAction::Legal);
|
||||
}
|
||||
template <typename... Args> void addLegalDialect() {
|
||||
SmallVector<StringRef, 2> dialectNames({Args::getDialectNamespace()...});
|
||||
setDialectAction(dialectNames, LegalizationAction::Legal);
|
||||
}
|
||||
|
||||
/// Register the operations of the given dialects as dynamically legal, i.e.
|
||||
/// requiring custom handling by the target via 'isLegal'.
|
||||
template <typename... Names>
|
||||
void addDynamicallyLegalDialect(StringRef name, Names... names) {
|
||||
SmallVector<StringRef, 2> dialectNames({name, names...});
|
||||
setDialectAction(dialectNames, LegalizationAction::Dynamic);
|
||||
}
|
||||
template <typename... Args> void addDynamicallyLegalDialect() {
|
||||
SmallVector<StringRef, 2> dialectNames({Args::getDialectNamespace()...});
|
||||
setDialectAction(dialectNames, LegalizationAction::Dynamic);
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Legality Querying
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
/// Get the legality action for the given operation.
|
||||
llvm::Optional<LegalizationAction> getOpAction(OperationName op) const {
|
||||
// Check for an action for this specific operation.
|
||||
auto it = legalOperations.find(op);
|
||||
if (it != legalOperations.end())
|
||||
return it->second;
|
||||
// Otherwise, default to checking for an action on the parent dialect.
|
||||
auto dialectIt = legalDialects.find(op.getDialect());
|
||||
if (dialectIt != legalDialects.end())
|
||||
return dialectIt->second;
|
||||
return llvm::None;
|
||||
}
|
||||
llvm::Optional<LegalizationAction> getOpAction(OperationName op) const;
|
||||
|
||||
private:
|
||||
/// A deterministic mapping of operation name to the specific legality action
|
||||
|
||||
@ -994,7 +994,7 @@ struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
|
||||
populateStdToLLVMConversionPatterns(converter, patterns);
|
||||
|
||||
ConversionTarget target(getContext());
|
||||
target.addLegalDialects<LLVM::LLVMDialect>();
|
||||
target.addLegalDialect<LLVM::LLVMDialect>();
|
||||
if (failed(
|
||||
applyConversionPatterns(m, target, converter, std::move(patterns))))
|
||||
signalPassFailure();
|
||||
|
||||
@ -689,7 +689,7 @@ void LowerLinalgToLLVMPass::runOnModule() {
|
||||
populateLinalgToLLVMConversionPatterns(converter, patterns, &getContext());
|
||||
|
||||
ConversionTarget target(getContext());
|
||||
target.addLegalDialects<LLVM::LLVMDialect>();
|
||||
target.addLegalDialect<LLVM::LLVMDialect>();
|
||||
if (failed(applyConversionPatterns(module, target, converter,
|
||||
std::move(patterns))))
|
||||
signalPassFailure();
|
||||
|
||||
@ -724,6 +724,37 @@ FunctionType TypeConverter::convertFunctionSignatureType(
|
||||
return FunctionType::get(arguments, results, type.getContext());
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ConversionTarget
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Register a legality action for the given operation.
|
||||
void ConversionTarget::setOpAction(OperationName op,
|
||||
LegalizationAction action) {
|
||||
legalOperations[op] = action;
|
||||
}
|
||||
|
||||
/// Register a legality action for the given dialects.
|
||||
void ConversionTarget::setDialectAction(ArrayRef<StringRef> dialectNames,
|
||||
LegalizationAction action) {
|
||||
for (StringRef dialect : dialectNames)
|
||||
legalDialects[dialect] = action;
|
||||
}
|
||||
|
||||
/// Get the legality action for the given operation.
|
||||
auto ConversionTarget::getOpAction(OperationName op) const
|
||||
-> llvm::Optional<LegalizationAction> {
|
||||
// Check for an action for this specific operation.
|
||||
auto it = legalOperations.find(op);
|
||||
if (it != legalOperations.end())
|
||||
return it->second;
|
||||
// Otherwise, default to checking for an action on the parent dialect.
|
||||
auto dialectIt = legalDialects.find(op.getDialect());
|
||||
if (dialectIt != legalDialects.end())
|
||||
return dialectIt->second;
|
||||
return llvm::None;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// applyConversionPatterns
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@ -597,7 +597,7 @@ LogicalResult mlir::lowerAffineConstructs(Function &function) {
|
||||
AffineTerminatorLowering>::build(patterns,
|
||||
function.getContext());
|
||||
ConversionTarget target(*function.getContext());
|
||||
target.addLegalDialects<StandardOpsDialect>();
|
||||
target.addLegalDialect<StandardOpsDialect>();
|
||||
return applyConversionPatterns(function, target, std::move(patterns));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user