[llvm] [llvm/llvm-project][Coroutines] ABI Object (PR #106306)
Tyler Nowicki via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 08:17:04 PDT 2024
================
@@ -0,0 +1,182 @@
+//===- SuspendCrossingInfo.cpp - Utility for suspend crossing values ------===//
+//
+// 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 SuspendCrossingInfo maintains data that allows to answer a question
+// whether given two BasicBlocks A and B there is a path from A to B that
+// passes through a suspend point.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TRANSFORMS_COROUTINES_SUSPENDCROSSINGINFO_H
+#define LLVM_LIB_TRANSFORMS_COROUTINES_SUSPENDCROSSINGINFO_H
+
+#include "CoroInstr.h"
+#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/PostOrderIterator.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instruction.h"
+
+namespace llvm {
+
+// Provides two way mapping between the blocks and numbers.
+class BlockToIndexMapping {
+ SmallVector<BasicBlock *, 32> V;
+
+public:
+ size_t size() const { return V.size(); }
+
+ BlockToIndexMapping(Function &F) {
+ for (BasicBlock &BB : F)
+ V.push_back(&BB);
+ llvm::sort(V);
----------------
TylerNowicki wrote:
This is very interesting, I didn't notice this while reading the code earlier. The restriction that we cannot add/remove BB while using SuspendCrossingInfo is not clearly documented. I can add a comment for this.
I suppose if people don't mind using a map we can create one for BB.getNumber() -> BB*, but that is for another PR. Why is it a problem to use a map here?
https://github.com/llvm/llvm-project/pull/106306
More information about the llvm-commits
mailing list