Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit a21d820

Browse files
committed
Add segmented stack support for DragonFlyBSD.
Patch by Michael Neumann. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224936 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2a1c1c9 commit a21d820

File tree

4 files changed

+122
-3
lines changed

4 files changed

+122
-3
lines changed

include/llvm/ADT/Triple.h

+2
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ class Triple {
377377
return getOS() == Triple::FreeBSD;
378378
}
379379

380+
bool isOSDragonFly() const { return getOS() == Triple::DragonFly; }
381+
380382
bool isOSSolaris() const {
381383
return getOS() == Triple::Solaris;
382384
}

lib/Target/X86/X86FrameLowering.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,9 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
14761476

14771477
if (MF.getFunction()->isVarArg())
14781478
report_fatal_error("Segmented stacks do not support vararg functions.");
1479-
if (!STI.isTargetLinux() && !STI.isTargetDarwin() &&
1480-
!STI.isTargetWin32() && !STI.isTargetWin64() && !STI.isTargetFreeBSD())
1479+
if (!STI.isTargetLinux() && !STI.isTargetDarwin() && !STI.isTargetWin32() &&
1480+
!STI.isTargetWin64() && !STI.isTargetFreeBSD() &&
1481+
!STI.isTargetDragonFly())
14811482
report_fatal_error("Segmented stacks not supported on this platform.");
14821483

14831484
// Eventually StackSize will be calculated by a link-time pass; which will
@@ -1531,6 +1532,9 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
15311532
} else if (STI.isTargetFreeBSD()) {
15321533
TlsReg = X86::FS;
15331534
TlsOffset = 0x18;
1535+
} else if (STI.isTargetDragonFly()) {
1536+
TlsReg = X86::FS;
1537+
TlsOffset = 0x20; // use tls_tcb.tcb_segstack
15341538
} else {
15351539
report_fatal_error("Segmented stacks not supported on this platform.");
15361540
}
@@ -1553,6 +1557,9 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
15531557
} else if (STI.isTargetWin32()) {
15541558
TlsReg = X86::FS;
15551559
TlsOffset = 0x14; // pvArbitrary, reserved for application use
1560+
} else if (STI.isTargetDragonFly()) {
1561+
TlsReg = X86::FS;
1562+
TlsOffset = 0x10; // use tls_tcb.tcb_segstack
15561563
} else if (STI.isTargetFreeBSD()) {
15571564
report_fatal_error("Segmented stacks not supported on FreeBSD i386.");
15581565
} else {
@@ -1565,7 +1572,8 @@ X86FrameLowering::adjustForSegmentedStacks(MachineFunction &MF) const {
15651572
BuildMI(checkMBB, DL, TII.get(X86::LEA32r), ScratchReg).addReg(X86::ESP)
15661573
.addImm(1).addReg(0).addImm(-StackSize).addReg(0);
15671574

1568-
if (STI.isTargetLinux() || STI.isTargetWin32() || STI.isTargetWin64()) {
1575+
if (STI.isTargetLinux() || STI.isTargetWin32() || STI.isTargetWin64() ||
1576+
STI.isTargetDragonFly()) {
15691577
BuildMI(checkMBB, DL, TII.get(X86::CMP32rm)).addReg(ScratchReg)
15701578
.addReg(0).addImm(0).addReg(0).addImm(TlsOffset).addReg(TlsReg);
15711579
} else if (STI.isTargetDarwin()) {

lib/Target/X86/X86Subtarget.h

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ class X86Subtarget final : public X86GenSubtargetInfo {
404404

405405
bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
406406
bool isTargetFreeBSD() const { return TargetTriple.isOSFreeBSD(); }
407+
bool isTargetDragonFly() const { return TargetTriple.isOSDragonFly(); }
407408
bool isTargetSolaris() const { return TargetTriple.isOSSolaris(); }
408409

409410
bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }

test/CodeGen/X86/segmented-stacks.ll

+108
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-darwin -verify-machineinstrs | FileCheck %s -check-prefix=X64-Darwin
66
; RUN: llc < %s -mcpu=generic -mtriple=i686-mingw32 -verify-machineinstrs | FileCheck %s -check-prefix=X32-MinGW
77
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-freebsd -verify-machineinstrs | FileCheck %s -check-prefix=X64-FreeBSD
8+
; RUN: llc < %s -mcpu=generic -mtriple=i686-dragonfly -verify-machineinstrs | FileCheck %s -check-prefix=X32-DFlyBSD
9+
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-dragonfly -verify-machineinstrs | FileCheck %s -check-prefix=X64-DFlyBSD
810
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-mingw32 -verify-machineinstrs | FileCheck %s -check-prefix=X64-MinGW
911

1012
; We used to crash with filetype=obj
@@ -15,6 +17,8 @@
1517
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-darwin -filetype=obj
1618
; RUN: llc < %s -mcpu=generic -mtriple=i686-mingw32 -filetype=obj
1719
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-freebsd -filetype=obj
20+
; RUN: llc < %s -mcpu=generic -mtriple=i686-dragonfly -filetype=obj
21+
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-dragonfly -filetype=obj
1822
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-mingw32 -filetype=obj
1923

2024
; RUN: not llc < %s -mcpu=generic -mtriple=x86_64-solaris 2> %t.log
@@ -114,6 +118,26 @@ define void @test_basic() #0 {
114118
; X64-FreeBSD-NEXT: callq __morestack
115119
; X64-FreeBSD-NEXT: ret
116120

121+
; X32-DFlyBSD-LABEL: test_basic:
122+
123+
; X32-DFlyBSD: cmpl %fs:16, %esp
124+
; X32-DFlyBSD-NEXT: ja .LBB0_2
125+
126+
; X32-DFlyBSD: pushl $0
127+
; X32-DFlyBSD-NEXT: pushl $48
128+
; X32-DFlyBSD-NEXT: calll __morestack
129+
; X32-DFlyBSD-NEXT: ret
130+
131+
; X64-DFlyBSD-LABEL: test_basic:
132+
133+
; X64-DFlyBSD: cmpq %fs:32, %rsp
134+
; X64-DFlyBSD-NEXT: ja .LBB0_2
135+
136+
; X64-DFlyBSD: movabsq $40, %r10
137+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
138+
; X64-DFlyBSD-NEXT: callq __morestack
139+
; X64-DFlyBSD-NEXT: ret
140+
117141
}
118142

119143
define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
@@ -199,6 +223,24 @@ define i32 @test_nested(i32 * nest %closure, i32 %other) #0 {
199223
; X64-FreeBSD-NEXT: ret
200224
; X64-FreeBSD-NEXT: movq %rax, %r10
201225

226+
; X32-DFlyBSD: cmpl %fs:16, %esp
227+
; X32-DFlyBSD-NEXT: ja .LBB1_2
228+
229+
; X32-DFlyBSD: pushl $4
230+
; X32-DFlyBSD-NEXT: pushl $52
231+
; X32-DFlyBSD-NEXT: calll __morestack
232+
; X32-DFlyBSD-NEXT: ret
233+
234+
; X64-DFlyBSD: cmpq %fs:32, %rsp
235+
; X64-DFlyBSD-NEXT: ja .LBB1_2
236+
237+
; X64-DFlyBSD: movq %r10, %rax
238+
; X64-DFlyBSD-NEXT: movabsq $56, %r10
239+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
240+
; X64-DFlyBSD-NEXT: callq __morestack
241+
; X64-DFlyBSD-NEXT: ret
242+
; X64-DFlyBSD-NEXT: movq %rax, %r10
243+
202244
}
203245

204246
define void @test_large() #0 {
@@ -280,6 +322,24 @@ define void @test_large() #0 {
280322
; X64-FreeBSD-NEXT: callq __morestack
281323
; X64-FreeBSD-NEXT: ret
282324

325+
; X32-DFlyBSD: leal -40008(%esp), %ecx
326+
; X32-DFlyBSD-NEXT: cmpl %fs:16, %ecx
327+
; X32-DFlyBSD-NEXT: ja .LBB2_2
328+
329+
; X32-DFlyBSD: pushl $0
330+
; X32-DFlyBSD-NEXT: pushl $40008
331+
; X32-DFlyBSD-NEXT: calll __morestack
332+
; X32-DFlyBSD-NEXT: ret
333+
334+
; X64-DFlyBSD: leaq -40008(%rsp), %r11
335+
; X64-DFlyBSD-NEXT: cmpq %fs:32, %r11
336+
; X64-DFlyBSD-NEXT: ja .LBB2_2
337+
338+
; X64-DFlyBSD: movabsq $40008, %r10
339+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
340+
; X64-DFlyBSD-NEXT: callq __morestack
341+
; X64-DFlyBSD-NEXT: ret
342+
283343
}
284344

285345
define fastcc void @test_fastcc() #0 {
@@ -368,6 +428,26 @@ define fastcc void @test_fastcc() #0 {
368428
; X64-FreeBSD-NEXT: callq __morestack
369429
; X64-FreeBSD-NEXT: ret
370430

431+
; X32-DFlyBSD-LABEL: test_fastcc:
432+
433+
; X32-DFlyBSD: cmpl %fs:16, %esp
434+
; X32-DFlyBSD-NEXT: ja .LBB3_2
435+
436+
; X32-DFlyBSD: pushl $0
437+
; X32-DFlyBSD-NEXT: pushl $48
438+
; X32-DFlyBSD-NEXT: calll __morestack
439+
; X32-DFlyBSD-NEXT: ret
440+
441+
; X64-DFlyBSD-LABEL: test_fastcc:
442+
443+
; X64-DFlyBSD: cmpq %fs:32, %rsp
444+
; X64-DFlyBSD-NEXT: ja .LBB3_2
445+
446+
; X64-DFlyBSD: movabsq $40, %r10
447+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
448+
; X64-DFlyBSD-NEXT: callq __morestack
449+
; X64-DFlyBSD-NEXT: ret
450+
371451
}
372452

373453
define fastcc void @test_fastcc_large() #0 {
@@ -464,6 +544,28 @@ define fastcc void @test_fastcc_large() #0 {
464544
; X64-FreeBSD-NEXT: callq __morestack
465545
; X64-FreeBSD-NEXT: ret
466546

547+
; X32-DFlyBSD-LABEL: test_fastcc_large:
548+
549+
; X32-DFlyBSD: leal -40008(%esp), %eax
550+
; X32-DFlyBSD-NEXT: cmpl %fs:16, %eax
551+
; X32-DFlyBSD-NEXT: ja .LBB4_2
552+
553+
; X32-DFlyBSD: pushl $0
554+
; X32-DFlyBSD-NEXT: pushl $40008
555+
; X32-DFlyBSD-NEXT: calll __morestack
556+
; X32-DFlyBSD-NEXT: ret
557+
558+
; X64-DFlyBSD-LABEL: test_fastcc_large:
559+
560+
; X64-DFlyBSD: leaq -40008(%rsp), %r11
561+
; X64-DFlyBSD-NEXT: cmpq %fs:32, %r11
562+
; X64-DFlyBSD-NEXT: ja .LBB4_2
563+
564+
; X64-DFlyBSD: movabsq $40008, %r10
565+
; X64-DFlyBSD-NEXT: movabsq $0, %r11
566+
; X64-DFlyBSD-NEXT: callq __morestack
567+
; X64-DFlyBSD-NEXT: ret
568+
467569
}
468570

469571
define fastcc void @test_fastcc_large_with_ecx_arg(i32 %a) #0 {
@@ -515,6 +617,12 @@ define void @test_nostack() #0 {
515617

516618
; X64-FreeBSD-LABEL: test_nostack:
517619
; X64-FreeBSD-NOT: callq __morestack
620+
621+
; X32-DFlyBSD-LABEL: test_nostack:
622+
; X32-DFlyBSD-NOT: calll __morestack
623+
624+
; X64-DFlyBSD-LABEL: test_nostack:
625+
; X64-DFlyBSD-NOT: callq __morestack
518626
}
519627

520628
attributes #0 = { "split-stack" }

0 commit comments

Comments
 (0)