Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

133 lines
4.2 KiB
C++

//===- PDLPatternMatch.cpp - Base classes for PDL pattern match
//------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/IR/PatternMatch.h"
#include "llvm/Support/InterleavedRange.h"
using namespace mlir;
//===----------------------------------------------------------------------===//
// PDLValue
//===----------------------------------------------------------------------===//
void PDLValue::print(raw_ostream &os) const {
if (!value) {
os << "<NULL-PDLValue>";
return;
}
switch (kind) {
case Kind::Attribute:
os << cast<Attribute>();
break;
case Kind::Operation:
os << *cast<Operation *>();
break;
case Kind::Type:
os << cast<Type>();
break;
case Kind::TypeRange:
os << llvm::interleaved(cast<TypeRange>());
break;
case Kind::Value:
os << cast<Value>();
break;
case Kind::ValueRange:
os << llvm::interleaved(cast<ValueRange>());
break;
}
}
void PDLValue::print(raw_ostream &os, Kind kind) {
switch (kind) {
case Kind::Attribute:
os << "Attribute";
break;
case Kind::Operation:
os << "Operation";
break;
case Kind::Type:
os << "Type";
break;
case Kind::TypeRange:
os << "TypeRange";
break;
case Kind::Value:
os << "Value";
break;
case Kind::ValueRange:
os << "ValueRange";
break;
}
}
//===----------------------------------------------------------------------===//
// PDLPatternModule
//===----------------------------------------------------------------------===//
void PDLPatternModule::mergeIn(PDLPatternModule &&other) {
// Ignore the other module if it has no patterns.
if (!other.pdlModule)
return;
// Steal the functions and config of the other module.
for (auto &it : other.constraintFunctions)
registerConstraintFunction(it.first(), std::move(it.second));
for (auto &it : other.rewriteFunctions)
registerRewriteFunction(it.first(), std::move(it.second));
for (auto &it : other.configs)
configs.emplace_back(std::move(it));
for (auto &it : other.configMap)
configMap.insert(it);
// Steal the other state if we have no patterns.
if (!pdlModule) {
pdlModule = std::move(other.pdlModule);
return;
}
// Merge the pattern operations from the other module into this one.
Block *block = pdlModule->getBody();
block->getOperations().splice(block->end(),
other.pdlModule->getBody()->getOperations());
}
void PDLPatternModule::attachConfigToPatterns(ModuleOp module,
PDLPatternConfigSet &configSet) {
// Attach the configuration to the symbols within the module. We only add
// to symbols to avoid hardcoding any specific operation names here (given
// that we don't depend on any PDL dialect). We can't use
// cast<SymbolOpInterface> here because patterns may be optional symbols.
module->walk([&](Operation *op) {
if (op->hasTrait<SymbolOpInterface::Trait>())
configMap[op] = &configSet;
});
}
//===----------------------------------------------------------------------===//
// Function Registry
//===----------------------------------------------------------------------===//
void PDLPatternModule::registerConstraintFunction(
StringRef name, PDLConstraintFunction constraintFn) {
// TODO: Is it possible to diagnose when `name` is already registered to
// a function that is not equivalent to `constraintFn`?
// Allow existing mappings in the case multiple patterns depend on the same
// constraint.
constraintFunctions.try_emplace(name, std::move(constraintFn));
}
void PDLPatternModule::registerRewriteFunction(StringRef name,
PDLRewriteFunction rewriteFn) {
// TODO: Is it possible to diagnose when `name` is already registered to
// a function that is not equivalent to `rewriteFn`?
// Allow existing mappings in the case multiple patterns depend on the same
// rewrite.
rewriteFunctions.try_emplace(name, std::move(rewriteFn));
}