[clang] Reset PostAllocaInsertPt when the AllocaInsertPt is changed in clang::CodeGenFunction (PR #98668)
Eric Wright via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 10:37:32 PDT 2024
https://github.com/efwright created https://github.com/llvm/llvm-project/pull/98668
Clang's CodeGenFunction tracks two insert points for "allocas". One where the alloca instructions are placed, and another (immediately following the allocas) where any address space casts are placed. For code outlining the two helper classes (OutlinedRegionBodyRAII and InlinedRegionBodyRAII) both change the first insert point which then causes a desync between the two insert points.
This changes nulls out the PostAllocaInsertPt whenever the AllocaInsertPt is changed which will cause those two insert points to sync up again the next time the PostAllocaInsertPt is referenced.
>From db22886b15f6bcab77b41846742f07639544bbe7 Mon Sep 17 00:00:00 2001
From: Eric Francis Wright <wright117 at rzansel61.coral.llnl.gov>
Date: Fri, 12 Jul 2024 10:29:11 -0700
Subject: [PATCH] Update PostAllocaInsertPt when AllocaInsertPt is changed
---
clang/lib/CodeGen/CodeGenFunction.h | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index cdb5ae6663405..2955949cbacdd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -428,7 +428,6 @@ class CodeGenFunction : public CodeGenTypeCache {
/// we prefer to insert allocas.
llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
-private:
/// PostAllocaInsertPt - This is a place in the prologue where code can be
/// inserted that will be dominated by all the static allocas. This helps
/// achieve two things:
@@ -439,7 +438,6 @@ class CodeGenFunction : public CodeGenTypeCache {
/// PostAllocaInsertPt will be lazily created when it is *really* required.
llvm::AssertingVH<llvm::Instruction> PostAllocaInsertPt = nullptr;
-public:
/// Return PostAllocaInsertPt. If it is not yet created, then insert it
/// immediately after AllocaInsertPt.
llvm::Instruction *getPostAllocaInsertPoint() {
@@ -2004,11 +2002,17 @@ class CodeGenFunction : public CodeGenTypeCache {
OldReturnBlock = CGF.ReturnBlock;
CGF.ReturnBlock = CGF.getJumpDestInCurrentScope(&RetBB);
+
+ CGF.PostAllocaInsertPt = nullptr;
+
}
~OutlinedRegionBodyRAII() {
CGF.AllocaInsertPt = OldAllocaIP;
CGF.ReturnBlock = OldReturnBlock;
+
+ CGF.PostAllocaInsertPt = nullptr;
+
}
};
@@ -2031,8 +2035,10 @@ class CodeGenFunction : public CodeGenTypeCache {
"Insertion point should be in the entry block of containing "
"function!");
OldAllocaIP = CGF.AllocaInsertPt;
- if (AllocaIP.isSet())
+ if (AllocaIP.isSet()) {
CGF.AllocaInsertPt = &*AllocaIP.getPoint();
+ CGF.PostAllocaInsertPt = nullptr;
+ }
// TODO: Remove the call, after making sure the counter is not used by
// the EHStack.
@@ -2042,7 +2048,11 @@ class CodeGenFunction : public CodeGenTypeCache {
(void)CGF.getJumpDestInCurrentScope(&FiniBB);
}
- ~InlinedRegionBodyRAII() { CGF.AllocaInsertPt = OldAllocaIP; }
+ ~InlinedRegionBodyRAII()
+ {
+ CGF.AllocaInsertPt = OldAllocaIP;
+ CGF.PostAllocaInsertPt = nullptr;
+ }
};
};
More information about the cfe-commits
mailing list