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));
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(subRanges, range);
66 variants.push_back(createNewNode(subRanges));
78 llvm::max_element(ranges, [](
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 &&
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.
OpTy release()
Release the referenced op.
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.
size_t getSize() const
Return the size of the module.
ModuleOp getModule() const
If the ReductionNode hasn't been tested the interestingness, it'll be the same module as the one in t...
Region & getRegion() const
Return the region we're reducing.
Tester::Interestingness isInteresting() const
Returns true if the module exhibits the interesting behavior.
ArrayRef< ReductionNode * > generateNewVariants()
Split the ranges and generate new variants.
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).
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.
OpIterator op_begin()
Return iterators that walk the operations nested directly within this region.
Include the generated interface declarations.