summaryrefslogtreecommitdiff
path: root/src/ortho/llvm
diff options
context:
space:
mode:
authorTristan Gingold2015-03-21 05:29:17 +0100
committerTristan Gingold2015-03-21 05:29:17 +0100
commit417195eef5d019d3ca4f26ab7f04063a8a6fdfce (patch)
tree573749d2d1be27b603305a4680cfb7f573ca64bb /src/ortho/llvm
parent87f69712557aacc410e49bc9e51523171f37ddbe (diff)
downloadghdl-417195eef5d019d3ca4f26ab7f04063a8a6fdfce.tar.gz
ghdl-417195eef5d019d3ca4f26ab7f04063a8a6fdfce.tar.bz2
ghdl-417195eef5d019d3ca4f26ab7f04063a8a6fdfce.zip
ortho_llvm: fix new_alloca when first instruction of a basic block.
Diffstat (limited to 'src/ortho/llvm')
-rw-r--r--src/ortho/llvm/ortho_llvm.adb24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/ortho/llvm/ortho_llvm.adb b/src/ortho/llvm/ortho_llvm.adb
index be0c60f..a1c85db 100644
--- a/src/ortho/llvm/ortho_llvm.adb
+++ b/src/ortho/llvm/ortho_llvm.adb
@@ -1670,11 +1670,25 @@ package body Ortho_LLVM is
and then Cur_Declare_Block.Prev /= null
then
-- Save stack pointer at entry of block
- PositionBuilderBefore
- (Extra_Builder, GetFirstInstruction (Cur_Declare_Block.Stmt_Bb));
- Cur_Declare_Block.Stack_Value :=
- BuildCall (Extra_Builder, Stacksave_Fun,
- (1 .. 0 => Null_ValueRef), 0, Empty_Cstring);
+ declare
+ First_Insn : ValueRef;
+ Bld : BuilderRef;
+ begin
+ First_Insn := GetFirstInstruction (Cur_Declare_Block.Stmt_Bb);
+ if First_Insn = Null_ValueRef then
+ -- Alloca is the first instruction, save the stack now.
+ Bld := Builder;
+ else
+ -- There are instructions before alloca, insert the save
+ -- at the beginning.
+ PositionBuilderBefore (Extra_Builder, First_Insn);
+ Bld := Extra_Builder;
+ end if;
+
+ Cur_Declare_Block.Stack_Value :=
+ BuildCall (Bld, Stacksave_Fun,
+ (1 .. 0 => Null_ValueRef), 0, Empty_Cstring);
+ end;
end if;
Res := BuildArrayAlloca