19 #include "llvm/ADT/STLExtras.h" 28 llvm::SpecificBumpPtrAllocator<ReductionNode> &allocator)
30 : parent(parentNode == nullptr ? this : parentNode),
31 size(std::numeric_limits<size_t>::
max()), ranges(ranges),
32 startRanges(ranges), allocator(allocator) {
35 llvm_unreachable(
"unexpected initialization failure");
42 module = cast<ModuleOp>(parentModule->clone(mapper));
45 region = block->getParent();
55 auto createNewNode = [
this](
const std::vector<Range> &ranges) {
56 return new (allocator.Allocate())
ReductionNode(
this, ranges, allocator);
62 if (variants.empty() &&
getRanges().size() > 1) {
64 std::vector<Range> subRanges =
getRanges();
65 llvm::erase_value(subRanges, range);
66 variants.push_back(createNewNode(subRanges));
77 auto maxElement = std::max_element(
78 ranges.begin(), ranges.end(), [](
const Range &lhs,
const Range &rhs) {
79 return (lhs.second - lhs.first) > (rhs.second - rhs.first);
84 if (maxElement->second - maxElement->first <= 1)
87 Range maxRange = *maxElement;
88 std::vector<Range> subRanges =
getRanges();
89 auto subRangesIter = subRanges.begin() + (maxElement - ranges.begin());
90 int half = (maxRange.first + maxRange.second) / 2;
91 *subRangesIter = std::make_pair(maxRange.first, half);
92 variants.push_back(createNewNode(subRanges));
93 *subRangesIter = std::make_pair(half, maxRange.second);
94 variants.push_back(createNewNode(subRanges));
96 auto it = ranges.insert(maxElement, std::make_pair(half, maxRange.second));
97 it = ranges.insert(it, std::make_pair(maxRange.first, half));
105 std::tie(interesting, size) = result;
112 ranges.emplace_back(0, std::distance(region->
op_begin(), region->
op_end()));
130 if (!llvm::all_of(variantsFromParent, [](
ReductionNode *node) {
144 if (smallest !=
nullptr &&
Include the generated interface declarations.
This class contains a list of basic blocks and a link to the parent operation it is attached to...
size_t getSize() const
Return the size of the module.
ReductionTreePass will build a reduction tree during module reduction and the ReductionNode represent...
Block represents an ordered list of Operations.
ArrayRef< ReductionNode * > generateNewVariants()
Split the ranges and generate new variants.
ModuleOp getModule() const
If the ReductionNode hasn't been tested the interestingness, it'll be the same module as the one in t...
OpTy release()
Release the referenced op.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
T lookup(T from) const
Lookup a mapped value within the map.
ArrayRef< Range > getRanges() const
Return the range set we are using to generate variants.
ArrayRef< ReductionNode * > getVariants() const
Return the generated variants(the child nodes).
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This class represents an efficient way to signal success or failure.
LogicalResult initialize(ModuleOp parentModule, Region &parentRegion)
Each Reduction Node contains a copy of module for applying rewrite patterns.
Region & getRegion() const
Return the region we're reducing.
std::pair< int, int > Range
Tester::Interestingness isInteresting() const
Returns true if the module exhibits the interesting behavior.
ReductionNode * getParent() const
ReductionNode(ReductionNode *parent, const std::vector< Range > &range, llvm::SpecificBumpPtrAllocator< ReductionNode > &allocator)
Root node will have the parent pointer point to themselves.
OpIterator op_begin()
Return iterators that walk the operations nested directly within this region.
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
void update(std::pair< Tester::Interestingness, size_t > result)
Update the interestingness result from tester.