Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 19, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/131960.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/IROutliner.cpp (+8-13)
diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 29e3beaa7f314..fd76d3a32049c 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -1539,27 +1539,22 @@ CallInst *replaceCalledFunction(Module &M, OutlinableRegion &Region) {
 /// \returns The found or newly created BasicBlock to contain the needed
 /// PHINodes to be used as outputs.
 static BasicBlock *findOrCreatePHIBlock(OutlinableGroup &Group, Value *RetVal) {
-  DenseMap<Value *, BasicBlock *>::iterator PhiBlockForRetVal,
-      ReturnBlockForRetVal;
-  PhiBlockForRetVal = Group.PHIBlocks.find(RetVal);
-  ReturnBlockForRetVal = Group.EndBBs.find(RetVal);
+  // Find if a PHIBlock exists for this return value already.  If it is
+  // the first time we are analyzing this, we will not, so we record it.
+  auto [PhiBlockForRetVal, Inserted] = Group.PHIBlocks.try_emplace(RetVal);
+  if (!Inserted)
+    return PhiBlockForRetVal->second;
+
+  auto ReturnBlockForRetVal = Group.EndBBs.find(RetVal);
   assert(ReturnBlockForRetVal != Group.EndBBs.end() &&
          "Could not find output value!");
   BasicBlock *ReturnBB = ReturnBlockForRetVal->second;
 
-  // Find if a PHIBlock exists for this return value already.  If it is
-  // the first time we are analyzing this, we will not, so we record it.
-  PhiBlockForRetVal = Group.PHIBlocks.find(RetVal);
-  if (PhiBlockForRetVal != Group.PHIBlocks.end())
-    return PhiBlockForRetVal->second;
-  
   // If we did not find a block, we create one, and insert it into the
   // overall function and record it.
-  bool Inserted = false;
   BasicBlock *PHIBlock = BasicBlock::Create(ReturnBB->getContext(), "phi_block",
                                             ReturnBB->getParent());
-  std::tie(PhiBlockForRetVal, Inserted) =
-      Group.PHIBlocks.insert(std::make_pair(RetVal, PHIBlock));
+  PhiBlockForRetVal->second = PHIBlock;
 
   // We find the predecessors of the return block in the newly created outlined
   // function in order to point them to the new PHIBlock rather than the already

@kazutakahirata kazutakahirata merged commit f97a852 into llvm:main Mar 19, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_IPO branch March 19, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants