/// Sets up the metadata and links the node to its parent.
ReductionNode::ReductionNode(ModuleOp module, ReductionNode *parent)
- : module(module), evaluated(false), parent(parent) {
+ : module(module), evaluated(false) {
+
+ if (parent != nullptr)
+ parent->linkVariant(this);
+}
+
+ReductionNode::ReductionNode(ModuleOp module, ReductionNode *parent,
+ std::vector<bool> transformSpace)
+ : module(module), evaluated(false), transformSpace(transformSpace) {
if (parent != nullptr)
parent->linkVariant(this);
}
/// Calculates and updates the size and interesting values of the module.
-void ReductionNode::measureAndTest(const Tester *test) {
+void ReductionNode::measureAndTest(const Tester &test) {
SmallString<128> filepath;
int fd;
- // Print module to temprary file.
+ // Print module to temporary file.
std::error_code ec =
llvm::sys::fs::createTemporaryFile("mlir-reduce", "mlir", fd, filepath);
llvm::report_fatal_error("Error emitting bitcode to file '" + filepath);
size = out.os().tell();
- interesting = test->isInteresting(filepath);
+ interesting = test.isInteresting(filepath);
evaluated = true;
}
return nullptr;
}
+/// Returns the number of child variants.
+int ReductionNode::variantsSize() const { return variants.size(); }
+
/// Returns true if the child variants vector is empty.
bool ReductionNode::variantsEmpty() const { return variants.empty(); }
}
/// Sort the child variants and remove the uninteresting ones.
-void ReductionNode::organizeVariants(const Tester *test) {
+void ReductionNode::organizeVariants(const Tester &test) {
// Ensure all variants are evaluated.
for (auto &var : variants)
if (!var->isEvaluated())
// Remove uninteresting variants.
variants.resize(interestingCount);
}
+
+/// Returns the number of non transformed indices.
+int ReductionNode::transformSpaceSize() {
+ return std::count(transformSpace.begin(), transformSpace.end(), false);
+}
+
+/// Returns a vector of the transformable indices in the Module.
+const std::vector<bool> ReductionNode::getTransformSpace() {
+ return transformSpace;
+}