[llvm] [SPIR-V] add convergence region analysis (PR #78456)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 22 06:16:08 PST 2024
================
@@ -0,0 +1,326 @@
+//===- ConvergenceRegionAnalysis.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
+//
+//===----------------------------------------------------------------------===//
+//
+// The analysis determines the convergence region for each basic block of
+// the module, and provides a tree-like structure describing the region
+// hierarchy.
+//
+//===----------------------------------------------------------------------===//
+
+#include "SPIRVConvergenceRegionAnalysis.h"
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/InitializePasses.h"
+#include <optional>
+#include <queue>
+
+#define DEBUG_TYPE "spirv-convergence-region-analysis"
+
+namespace llvm {
+void initializeSPIRVConvergenceRegionAnalysisWrapperPassPass(PassRegistry &);
+
+INITIALIZE_PASS_BEGIN(SPIRVConvergenceRegionAnalysisWrapperPass,
+ "convergence-region",
+ "SPIRV convergence regions analysis", true, true);
+INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
+INITIALIZE_PASS_END(SPIRVConvergenceRegionAnalysisWrapperPass,
+ "convergence-region", "SPIRV convergence regions analysis",
+ true, true);
+
+namespace SPIRV {
+
+namespace {
+
+template <typename BasicBlockType, typename IntrinsicInstType>
+std::optional<IntrinsicInstType *>
+getConvergenceTokenInternal(BasicBlockType *BB) {
+ static_assert(std::is_const_v<IntrinsicInstType> ==
+ std::is_const_v<BasicBlockType>,
+ "Constness must match between input and output.");
+ static_assert(std::is_same_v<BasicBlock, std::remove_const_t<BasicBlockType>>,
+ "Input must be a basic block.");
+ static_assert(
+ std::is_same_v<IntrinsicInst, std::remove_const_t<IntrinsicInstType>>,
+ "Output type must be an intrinsic instruction.");
+
+ for (auto &I : *BB) {
+ if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
+ if (II->getIntrinsicID() != Intrinsic::experimental_convergence_entry &&
----------------
Keenuts wrote:
yes, agree, made the change! Thanks!
https://github.com/llvm/llvm-project/pull/78456
More information about the llvm-commits
mailing list