Index: lib/Target/Mips/MipsSEFrameLowering.h =================================================================== --- lib/Target/Mips/MipsSEFrameLowering.h +++ lib/Target/Mips/MipsSEFrameLowering.h @@ -27,6 +27,9 @@ void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; + int getFrameIndexReference(const MachineFunction &MF, int FI, + unsigned &FrameReg) const override; + bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector &CSI, Index: lib/Target/Mips/MipsSEFrameLowering.cpp =================================================================== --- lib/Target/Mips/MipsSEFrameLowering.cpp +++ lib/Target/Mips/MipsSEFrameLowering.cpp @@ -578,6 +578,24 @@ TII.adjustStackPtr(SP, StackSize, MBB, MBBI); } +int MipsSEFrameLowering::getFrameIndexReference(const MachineFunction &MF, + int FI, + unsigned &FrameReg) const { + const MachineFrameInfo *MFI = MF.getFrameInfo(); + const MipsRegisterInfo *MRI = STI.getRegisterInfo(); + MipsABIInfo ABI = STI.getABI(); + + // Find out the correct register. + FrameReg = ABI.GetStackPtr(); + if (hasBP(MF)) + FrameReg = ABI.GetBasePtr(); + else if (MRI->needsStackRealignment(MF)) + FrameReg = ABI.GetStackPtr(); + + return MFI->getObjectOffset(FI) + MFI->getStackSize() - + getOffsetOfLocalArea() + MFI->getOffsetAdjustment(); +} + bool MipsSEFrameLowering:: spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Index: test/CodeGen/Mips/dynamic-stack-realignment-dwarf.ll =================================================================== --- /dev/null +++ test/CodeGen/Mips/dynamic-stack-realignment-dwarf.ll @@ -0,0 +1,155 @@ +; RUN: llc -filetype=obj -march=mips -mcpu=mips32r2 < %s | \ +; RUN: llvm-dwarfdump -debug-dump=info - | FileCheck %s +; +; Verify that we use the correct DW_OP_bregXX when dynamic stack realignment +; is in use (PR25028). +; +;#include +; +;int foo(int a, int b) { +; int c __attribute__ ((aligned (16))) = a + b; +; return c; +;} +; +;int *bar(int x, int y) { +; int *w = alloca(x); +; int z __attribute__ ((aligned (16))) = x + y; +; *w = z; +; return w; +;} +; + +; DW_OP_reg30 +; CHECK: DW_AT_frame_base [DW_FORM_exprloc] (<0x1> 6e ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "foo") + +; DW_OP_breg29 +; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x2> 8d 08 ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "a" + +; DW_OP_breg29 +; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x2> 8d 04 ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "b" + +; DW_OP_breg29 +; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x2> 8d 00 ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "c" + +define i32 @foo(i32 signext %a, i32 signext %b) #0 { +entry: + %a.addr = alloca i32, align 4 + %b.addr = alloca i32, align 4 + %c = alloca i32, align 16 + store i32 %a, i32* %a.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !15, metadata !16), !dbg !17 + store i32 %b, i32* %b.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !18, metadata !16), !dbg !19 + call void @llvm.dbg.declare(metadata i32* %c, metadata !20, metadata !16), !dbg !21 + %0 = load i32, i32* %a.addr, align 4, !dbg !22 + %1 = load i32, i32* %b.addr, align 4, !dbg !23 + %add = add nsw i32 %0, %1, !dbg !24 + store i32 %add, i32* %c, align 16, !dbg !21 + %2 = load i32, i32* %c, align 16, !dbg !25 + ret i32 %2, !dbg !26 +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +; DW_OP_reg30 +; CHECK: DW_AT_frame_base [DW_FORM_exprloc] (<0x1> 6e ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "bar") + +; DW_OP_breg23 +; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x2> 87 14 ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "x" + +; DW_OP_breg23 +; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x2> 87 10 ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "y" + +; DW_OP_breg23 +; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x2> 87 0c ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "w" + +; DW_OP_breg23 +; CHECK: DW_AT_location [DW_FORM_exprloc] (<0x2> 87 00 ) +; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "z" + +define i32* @bar(i32 signext %x, i32 signext %y) #0 { +entry: + %x.addr = alloca i32, align 4 + %y.addr = alloca i32, align 4 + %w = alloca i32*, align 4 + %z = alloca i32, align 16 + store i32 %x, i32* %x.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !27, metadata !16), !dbg !28 + store i32 %y, i32* %y.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %y.addr, metadata !29, metadata !16), !dbg !30 + call void @llvm.dbg.declare(metadata i32** %w, metadata !31, metadata !16), !dbg !32 + %0 = load i32, i32* %x.addr, align 4, !dbg !33 + %1 = alloca i8, i32 %0, !dbg !33 + %2 = bitcast i8* %1 to i32*, !dbg !33 + store i32* %2, i32** %w, align 4, !dbg !32 + call void @llvm.dbg.declare(metadata i32* %z, metadata !34, metadata !16), !dbg !35 + %3 = load i32, i32* %x.addr, align 4, !dbg !36 + %4 = load i32, i32* %y.addr, align 4, !dbg !37 + %add = add nsw i32 %3, %4, !dbg !38 + store i32 %add, i32* %z, align 16, !dbg !35 + %5 = load i32, i32* %z, align 16, !dbg !39 + %6 = load i32*, i32** %w, align 4, !dbg !40 + store i32 %5, i32* %6, align 4, !dbg !41 + %7 = load i32*, i32** %w, align 4, !dbg !42 + ret i32* %7, !dbg !43 +} + +attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="mips32r2" "target-features"="+fpxx,+mips32r2,+nooddspreg" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!12, !13} +!llvm.ident = !{!14} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 249525) (llvm/trunk 249528)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3) +!1 = !DIFile(filename: "hello.c", directory: "/home/vk/repos/tmp/hello") +!2 = !{} +!3 = !{!4, !8} +!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32, i32)* @foo, variables: !2) +!5 = !DISubroutineType(types: !6) +!6 = !{!7, !7, !7} +!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!8 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 8, type: !9, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, function: i32* (i32, i32)* @bar, variables: !2) +!9 = !DISubroutineType(types: !10) +!10 = !{!11, !7, !7} +!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 32, align: 32) +!12 = !{i32 2, !"Dwarf Version", i32 4} +!13 = !{i32 2, !"Debug Info Version", i32 3} +!14 = !{!"clang version 3.8.0 (trunk 249525) (llvm/trunk 249528)"} +!15 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 3, type: !7) +!16 = !DIExpression() +!17 = !DILocation(line: 3, column: 13, scope: !4) +!18 = !DILocalVariable(name: "b", arg: 2, scope: !4, file: !1, line: 3, type: !7) +!19 = !DILocation(line: 3, column: 20, scope: !4) +!20 = !DILocalVariable(name: "c", scope: !4, file: !1, line: 4, type: !7) +!21 = !DILocation(line: 4, column: 7, scope: !4) +!22 = !DILocation(line: 4, column: 42, scope: !4) +!23 = !DILocation(line: 4, column: 46, scope: !4) +!24 = !DILocation(line: 4, column: 44, scope: !4) +!25 = !DILocation(line: 5, column: 10, scope: !4) +!26 = !DILocation(line: 5, column: 3, scope: !4) +!27 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 8, type: !7) +!28 = !DILocation(line: 8, column: 14, scope: !8) +!29 = !DILocalVariable(name: "y", arg: 2, scope: !8, file: !1, line: 8, type: !7) +!30 = !DILocation(line: 8, column: 21, scope: !8) +!31 = !DILocalVariable(name: "w", scope: !8, file: !1, line: 9, type: !11) +!32 = !DILocation(line: 9, column: 8, scope: !8) +!33 = !DILocation(line: 9, column: 12, scope: !8) +!34 = !DILocalVariable(name: "z", scope: !8, file: !1, line: 10, type: !7) +!35 = !DILocation(line: 10, column: 7, scope: !8) +!36 = !DILocation(line: 10, column: 42, scope: !8) +!37 = !DILocation(line: 10, column: 46, scope: !8) +!38 = !DILocation(line: 10, column: 44, scope: !8) +!39 = !DILocation(line: 11, column: 8, scope: !8) +!40 = !DILocation(line: 11, column: 4, scope: !8) +!41 = !DILocation(line: 11, column: 6, scope: !8) +!42 = !DILocation(line: 12, column: 10, scope: !8) +!43 = !DILocation(line: 12, column: 3, scope: !8)