19#include "llvm/ADT/STLExtras.h"
27 llvm::SpecificBumpPtrAllocator<ReductionNode> &allocator)
29 : parent(parentNode ==
nullptr ? this : parentNode),
30 size(std::numeric_limits<size_t>::
max()), ranges(ranges),
31 startRanges(ranges), allocator(allocator) {
33 if (failed(
initialize(parent->getModule(), parent->getRegion())))
34 llvm_unreachable(
"unexpected initialization failure");
41 module = cast<ModuleOp>(parentModule->clone(mapper));
54 auto createNewNode = [
this](
const std::vector<Range> &ranges) {
55 return new (allocator.Allocate())
ReductionNode(
this, ranges, allocator);
61 if (variants.empty() &&
getRanges().size() > 1) {
63 std::vector<Range> subRanges =
getRanges();
64 llvm::erase(subRanges, range);
65 variants.push_back(createNewNode(subRanges));
78 return (
lhs.second -
lhs.first) > (
rhs.second -
rhs.first);
83 if (maxElement->second - maxElement->first <= 1)
86 Range maxRange = *maxElement;
87 std::vector<Range> subRanges =
getRanges();
88 auto subRangesIter = subRanges.begin() + (maxElement - ranges.begin());
89 int half = (maxRange.first + maxRange.second) / 2;
90 *subRangesIter = std::make_pair(maxRange.first, half);
91 variants.push_back(createNewNode(subRanges));
92 *subRangesIter = std::make_pair(half, maxRange.second);
93 variants.push_back(createNewNode(subRanges));
95 auto it = ranges.insert(maxElement, std::make_pair(half, maxRange.second));
96 it = ranges.insert(it, std::make_pair(maxRange.first, half));
104 std::tie(interesting, size) =
result;
111 ranges.emplace_back(0, std::distance(region->op_begin(), region->op_end()));
114 module.release()->erase();
129 if (!llvm::all_of(variantsFromParent, [](
ReductionNode *node) {
143 if (smallest !=
nullptr &&
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
Block represents an ordered list of Operations.
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
This is a utility class for mapping one set of IR entities to another.
auto lookup(T from) const
Lookup a mapped value within the map.
ReductionTreePass will build a reduction tree during module reduction and the ReductionNode represent...
std::pair< int, int > Range
LogicalResult initialize(ModuleOp parentModule, Region &parentRegion)
Each Reduction Node contains a copy of module for applying rewrite patterns.
ReductionNode(ReductionNode *parent, const std::vector< Range > &range, llvm::SpecificBumpPtrAllocator< ReductionNode > &allocator)
Root node will have the parent pointer point to themselves.
ArrayRef< Range > getRanges() const
Return the range set we are using to generate variants.
size_t getSize() const
Return the size of the module.
Tester::Interestingness isInteresting() const
Returns true if the module exhibits the interesting behavior.
ArrayRef< ReductionNode * > generateNewVariants()
Split the ranges and generate new variants.
ArrayRef< ReductionNode * > getVariants() const
Return the generated variants(the child nodes).
ReductionNode * getParent() const
void update(std::pair< Tester::Interestingness, size_t > result)
Update the interestingness result from tester.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Include the generated interface declarations.