[PATCH] D115218: [CodeExtractor] Refactor extractCodeRegion, fix parameter index confusion.

William Moses via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 13:23:18 PST 2022


wsmoses added inline comments.


================
Comment at: llvm/include/llvm/Transforms/Utils/CodeExtractor.h:248
 
+    /// Updates the list of exit blocks (OldTargets and ExitBlocks) after
+    /// changes of the control flow or the Blocks list.
----------------
Update comment since OldTargets appears removed?


================
Comment at: llvm/lib/Transforms/Utils/CodeExtractor.cpp:829
+  default:
+    RetTy = Type::getInt16Ty(Context);
+    break;
----------------
Is it worth here asserting that the numexitblocks fits in an Int16, I've seen some real c++ codes that actually emit an absurd number of blocks.


================
Comment at: llvm/lib/Transforms/Utils/CodeExtractor.cpp:1177
-                       &codeReplacer->getParent()->front().front());
-      ReloadOutputs.push_back(alloca);
-      params.push_back(alloca);
----------------
@Meinersbur in the fixed version can you add a test that hits this issue?


================
Comment at: llvm/lib/Transforms/Utils/CodeExtractor.cpp:1468
 
-  // The new function needs a root node because other nodes can branch to the
-  // head of the region, but the entry node of a function cannot have preds.
-  BasicBlock *newFuncRoot = BasicBlock::Create(header->getContext(),
-                                               "newFuncRoot");
-  auto *BranchI = BranchInst::Create(header);
-  // If the original function has debug info, we have to add a debug location
-  // to the new branch instruction from the artificial entry block.
-  // We use the debug location of the first instruction in the extracted
-  // blocks, as there is no other equivalent line in the source code.
-  if (oldFunction->getSubprogram()) {
-    any_of(Blocks, [&BranchI](const BasicBlock *BB) {
-      return any_of(*BB, [&BranchI](const Instruction &I) {
-        if (!I.getDebugLoc())
-          return false;
-        BranchI->setDebugLoc(I.getDebugLoc());
-        return true;
-      });
-    });
+void CodeExtractor::recomputeExitBlocks() {
+  SwitchCases.clear();
----------------
Can the naming here be consistent between `SwitchCases` (as the externally visible data structure name) and `ExitBlocks` from this function.


================
Comment at: llvm/lib/Transforms/Utils/CodeExtractor.cpp:1577
+      brVal = ConstantInt::get(Type::getInt16Ty(Context), SuccNum);
+      break;
+    }
----------------
Can the get switch type functionality here and above be moved to a separate function?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115218/new/

https://reviews.llvm.org/D115218



More information about the llvm-commits mailing list