Ensures allocas are at the start of entry block.
Allocas were not created in the entry block. Now we force allocas to be
created in the entry block and they are the first instructions in this block.
In the Portable, they hold the shadow frame.
The LLVM code generator optimizes allocas in the entry block by placing them in
the static stack frame. This prevents from using a register as a frame pointer
to access them.
Hopefully, this might reduce code size since we use fewer instructions to
allocate/deallocate stack in prologue/epilogue.
Change-Id: I4424481c886247a59a85e0ea507daf2c086ee3b2
diff --git a/src/compiler_llvm/gbc_expander.cc b/src/compiler_llvm/gbc_expander.cc
index 086d29d..d8392d7 100644
--- a/src/compiler_llvm/gbc_expander.cc
+++ b/src/compiler_llvm/gbc_expander.cc
@@ -1135,12 +1135,19 @@
llvm::StructType* shadow_frame_type =
irb_.getShadowFrameTy(num_vregs);
+ // Create allocas at the start of entry block.
+ llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
+ llvm::BasicBlock* entry_block = &func_->front();
+ irb_.SetInsertPoint(&entry_block->front());
+
shadow_frame_ = irb_.CreateAlloca(shadow_frame_type);
// Alloca a pointer to old shadow frame
old_shadow_frame_ =
irb_.CreateAlloca(shadow_frame_type->getElementType(0)->getPointerTo());
+ irb_.restoreIP(irb_ip_original);
+
// Push the shadow frame
llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();