[llvm] [SandboxVectorizer] Use sbvec-passes flag to create a pipeline of Region passes after BottomUpVec. (PR #111223)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 09:48:01 PDT 2024


================
@@ -30,6 +31,57 @@ cl::opt<std::string> UserDefinedPassPipeline(
     cl::desc("Comma-separated list of vectorizer passes. If not set "
              "we run the predefined pipeline."));
 
+static void registerAllRegionPasses(sandboxir::PassRegistry &PR) {
+  PR.registerPass(std::make_unique<sandboxir::NullPass>());
+}
+
+static sandboxir::RegionPassManager &
+parseAndCreatePassPipeline(sandboxir::PassRegistry &PR, StringRef Pipeline) {
+  static constexpr const char EndToken = '\0';
+  // Add EndToken to the end to ease parsing.
+  std::string PipelineStr = std::string(Pipeline) + EndToken;
+  int FlagBeginIdx = 0;
+  auto &RPM = static_cast<sandboxir::RegionPassManager &>(
+      PR.registerPass(std::make_unique<sandboxir::RegionPassManager>("rpm")));
+
+  for (auto [Idx, C] : enumerate(PipelineStr)) {
+    // Keep moving Idx until we find the end of the pass name.
+    bool FoundDelim = C == EndToken || C == PR.PassDelimToken;
+    if (!FoundDelim)
+      continue;
+    unsigned Sz = Idx - FlagBeginIdx;
+    std::string PassName(&PipelineStr[FlagBeginIdx], Sz);
+    FlagBeginIdx = Idx + 1;
+
+    // Get the pass that corresponds to PassName and add it to the pass manager.
+    auto *Pass = PR.getPassByName(PassName);
+    if (Pass == nullptr) {
+      errs() << "Pass '" << PassName << "' not registered!\n";
+      exit(1);
+    }
+    // TODO: Add a type check here. The downcast is correct as long as
+    // registerAllRegionPasses only registers regions passes.
+    RPM.addPass(static_cast<sandboxir::RegionPass *>(Pass));
+  }
+  return RPM;
+}
+
+SandboxVectorizerPass::SandboxVectorizerPass() {
+  registerAllRegionPasses(PR);
+
+  // Create a pipeline to be run on each Region created by BottomUpVec.
+  if (UserDefinedPassPipeline == DefaultPipelineMagicStr) {
----------------
vporpo wrote:

Yeah totally forgot that we were rebuilding it every time.

https://github.com/llvm/llvm-project/pull/111223


More information about the llvm-commits mailing list