[llvm] [SandboxVec] Tag insts in a Region with metadata. (PR #109353)

Jorge Gorbe Moya via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 14:02:59 PDT 2024


================
@@ -42,4 +54,27 @@ void Region::dump() const {
 }
 #endif // NDEBUG
 
+SmallVector<std::unique_ptr<Region>> Region::createRegionsFromMD(Function &F) {
+  SmallVector<std::unique_ptr<Region>> Regions;
+  DenseMap<MDNode *, Region *> MDNToRegion;
+  auto &Ctx = F.getContext();
+  for (BasicBlock &BB : F) {
+    for (Instruction &Inst : BB) {
+      if (auto *MDN = cast<llvm::Instruction>(Inst.Val)->getMetadata(MDKind)) {
+        Region *R = nullptr;
+        auto It = MDNToRegion.find(MDN);
----------------
slackito wrote:

I don't think the lambda wins us any clarity here. It needs to access both `Regions` and `MDNToRegion` from the surrounding scope, so it's not very self-contained anyway, and this block is just 10 lines of code.

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


More information about the llvm-commits mailing list