diff options
author | hsmahesha <mahesha.comp@gmail.com> | 2021-11-10 08:44:58 +0530 |
---|---|---|
committer | hsmahesha <mahesha.comp@gmail.com> | 2021-11-10 08:45:21 +0530 |
commit | 3b9a85d10ac7a073c95b35adca379281ac6ecbcb (patch) | |
tree | 68fce34e05c974839e1785c8c00cf883dbcf13d5 /clang/lib/CodeGen/CodeGenFunction.h | |
parent | 5b7ea8e62921e53fdea73d948eb0d48c071d4b73 (diff) | |
download | llvm-3b9a85d10ac7a073c95b35adca379281ac6ecbcb.zip llvm-3b9a85d10ac7a073c95b35adca379281ac6ecbcb.tar.gz llvm-3b9a85d10ac7a073c95b35adca379281ac6ecbcb.tar.bz2 |
[CFE][Codegen] Make sure to maintain the contiguity of all the static allocas
at the start of the entry block, which in turn would aid better code transformation/optimization.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D110257
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.h')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index dd60e21..e8207511 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -379,6 +379,35 @@ public: /// 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: + /// 1. Contiguity of all static allocas (within the prologue) is maintained. + /// 2. All other prologue code (which are dominated by static allocas) do + /// appear in the source order immediately after all static allocas. + /// + /// 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() { + if (!PostAllocaInsertPt) { + assert(AllocaInsertPt && + "Expected static alloca insertion point at function prologue"); + auto *EBB = AllocaInsertPt->getParent(); + assert(EBB->isEntryBlock() && + "EBB should be entry block of the current code gen function"); + PostAllocaInsertPt = AllocaInsertPt->clone(); + PostAllocaInsertPt->setName("postallocapt"); + PostAllocaInsertPt->insertAfter(AllocaInsertPt); + } + + return PostAllocaInsertPt; + } + /// API for captured statement code generation. class CGCapturedStmtInfo { public: |