[llvm] [SandboxVec] Add barebones Region class. (PR #108899)
Jorge Gorbe Moya via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 14:44:24 PDT 2024
================
@@ -0,0 +1,107 @@
+//===- Region.h -------------------------------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_REGION_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_REGION_H
+
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/SandboxIR/SandboxIR.h"
+#include "llvm/Support/InstructionCost.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm::sandboxir {
+
+/// The main job of the Region is to point to new instructions generated by
+/// vectorization passes. It is the unit that RegionPasses operate on with their
+/// runOnRegion() function.
+///
+/// The region allows us to stack transformations horizontally, meaning that
+/// each transformation operates on a single region and the resulting region is
+/// the input to the next transformation, as opposed to vertically, which is the
+/// common way of applying a transformation across the whole BB. This enables us
+/// to check for profitability and decide whether we accept or rollback at a
+/// region granularity, which is much better than doing this at the BB level.
+///
+// Traditional approach: transformations applied vertically for the whole BB
+// BB
+// +----+
+// | |
+// | |
+// | | -> Transform1 -> ... -> TransformN -> Check Cost
+// | |
+// | |
+// +----+
+//
+// Region-based approach: transformations applied horizontally, for each Region
+// BB
+// +----+
+// |Rgn1| -> Transform1 -> ... -> TransformN -> Check Cost
+// | |
+// |Rgn2| -> Transform1 -> ... -> TransformN -> Check Cost
+// | |
+// |Rgn3| -> Transform1 -> ... -> TransformN -> Check Cost
+// +----+
+
+class Region {
+ /// All the instructions in the Region. Only new instructions generated during
+ /// vectorization are part of the Region.
+ SetVector<sandboxir::Instruction *> Insts;
----------------
slackito wrote:
Done. Also moved the code in Region.cpp to the `llvm::sandboxir` namespace.
https://github.com/llvm/llvm-project/pull/108899
More information about the llvm-commits
mailing list