[llvm] d335c13 - Fix dynamic alloca detection in CloneBasicBlock
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 15:06:47 PDT 2020
Author: Arthur Eubanks
Date: 2020-06-22T15:06:28-07:00
New Revision: d335c1317b6170918311fcbccc39fe31b3a84bda
URL: https://github.com/llvm/llvm-project/commit/d335c1317b6170918311fcbccc39fe31b3a84bda
DIFF: https://github.com/llvm/llvm-project/commit/d335c1317b6170918311fcbccc39fe31b3a84bda.diff
LOG: Fix dynamic alloca detection in CloneBasicBlock
Summary:
Simply check AI->isStaticAlloca instead of reimplementing checks for
static/dynamic allocas.
Reviewers: efriedma
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82328
Added:
Modified:
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/unittests/Transforms/Utils/CloningTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index fce926fb447c..788983c15690 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -46,7 +46,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
if (BB->hasName())
NewBB->setName(BB->getName() + NameSuffix);
- bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
+ bool hasCalls = false, hasDynamicAllocas = false;
Module *TheModule = F ? F->getParent() : nullptr;
// Loop over all instructions, and copy them over.
@@ -62,18 +62,15 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, ValueToValueMapTy &VMap,
hasCalls |= (isa<CallInst>(I) && !isa<DbgInfoIntrinsic>(I));
if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
- if (isa<ConstantInt>(AI->getArraySize()))
- hasStaticAllocas = true;
- else
+ if (!AI->isStaticAlloca()) {
hasDynamicAllocas = true;
+ }
}
}
if (CodeInfo) {
CodeInfo->ContainsCalls |= hasCalls;
CodeInfo->ContainsDynamicAllocas |= hasDynamicAllocas;
- CodeInfo->ContainsDynamicAllocas |= hasStaticAllocas &&
- BB != &BB->getParent()->getEntryBlock();
}
return NewBB;
}
diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp
index 28ad4bc88077..fc0b3de23641 100644
--- a/llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -659,6 +659,65 @@ static int GetDICompileUnitCount(const Module& M) {
return 0;
}
+TEST(CloneFunction, CloneEmptyFunction) {
+ StringRef ImplAssembly = R"(
+ define void @foo() {
+ ret void
+ }
+ declare void @bar()
+ )";
+
+ LLVMContext Context;
+ SMDiagnostic Error;
+
+ auto ImplModule = parseAssemblyString(ImplAssembly, Error, Context);
+ EXPECT_TRUE(ImplModule != nullptr);
+ auto *ImplFunction = ImplModule->getFunction("foo");
+ EXPECT_TRUE(ImplFunction != nullptr);
+ auto *DeclFunction = ImplModule->getFunction("bar");
+ EXPECT_TRUE(DeclFunction != nullptr);
+
+ ValueToValueMapTy VMap;
+ SmallVector<ReturnInst *, 8> Returns;
+ ClonedCodeInfo CCI;
+ CloneFunctionInto(DeclFunction, ImplFunction, VMap, true, Returns, "", &CCI);
+
+ EXPECT_FALSE(verifyModule(*ImplModule, &errs()));
+ EXPECT_FALSE(CCI.ContainsCalls);
+ EXPECT_FALSE(CCI.ContainsDynamicAllocas);
+}
+
+TEST(CloneFunction, CloneFunctionWithInalloca) {
+ StringRef ImplAssembly = R"(
+ declare void @a(i32* inalloca)
+ define void @foo() {
+ %a = alloca inalloca i32
+ call void @a(i32* inalloca %a)
+ ret void
+ }
+ declare void @bar()
+ )";
+
+ LLVMContext Context;
+ SMDiagnostic Error;
+
+ auto ImplModule = parseAssemblyString(ImplAssembly, Error, Context);
+ EXPECT_TRUE(ImplModule != nullptr);
+ auto *ImplFunction = ImplModule->getFunction("foo");
+ EXPECT_TRUE(ImplFunction != nullptr);
+ auto *DeclFunction = ImplModule->getFunction("bar");
+ EXPECT_TRUE(DeclFunction != nullptr);
+
+ ValueToValueMapTy VMap;
+ SmallVector<ReturnInst *, 8> Returns;
+ ClonedCodeInfo CCI;
+ CloneFunctionInto(DeclFunction, ImplFunction, VMap, true, Returns, "", &CCI);
+
+ EXPECT_FALSE(verifyModule(*ImplModule, &errs()));
+ EXPECT_TRUE(CCI.ContainsCalls);
+ EXPECT_TRUE(CCI.ContainsDynamicAllocas);
+}
+
TEST(CloneFunction, CloneFunctionToDifferentModule) {
StringRef ImplAssembly = R"(
define void @foo() {
More information about the llvm-commits
mailing list