[X86] Extend some Linux special cases to cover kFreeBSD.

Both Linux and kFreeBSD use glibc, so follow similiar code paths.
Add isTargetGlibc to check for this, and use it instead of isTargetLinux
in a few places.

Fixes PR22248 for kFreeBSD.

Differential Revision: http://reviews.llvm.org/D19104

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268624 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marcin Koscielnicki 2016-05-05 11:35:51 +00:00
parent 68065ba043
commit d11ea2f4ad
7 changed files with 26 additions and 5 deletions

View File

@ -523,6 +523,16 @@ public:
return getOS() == Triple::Linux;
}
/// Tests whether the OS is kFreeBSD.
bool isOSKFreeBSD() const {
return getOS() == Triple::KFreeBSD;
}
/// Tests whether the OS uses glibc.
bool isOSGlibc() const {
return getOS() == Triple::Linux || getOS() == Triple::KFreeBSD;
}
/// Tests whether the OS uses the ELF binary format.
bool isOSBinFormatELF() const {
return getObjectFormat() == Triple::ELF;

View File

@ -719,7 +719,7 @@ bool X86DAGToDAGISel::matchLoadInAddress(LoadSDNode *N, X86ISelAddressMode &AM){
// For more information see http://people.redhat.com/drepper/tls.pdf
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Address))
if (C->getSExtValue() == 0 && AM.Segment.getNode() == nullptr &&
Subtarget->isTargetLinux())
Subtarget->isTargetGlibc())
switch (N->getPointerInfo().getAddrSpace()) {
case 256:
AM.Segment = CurDAG->getRegister(X86::GS, MVT::i16);

View File

@ -1919,7 +1919,9 @@ unsigned X86TargetLowering::getAddressSpace() const {
}
Value *X86TargetLowering::getIRStackGuard(IRBuilder<> &IRB) const {
if (!Subtarget.isTargetLinux())
// glibc has a special slot for the stack guard in tcbhead_t, use it instead
// of the usual global variable (see sysdeps/{i386,x86_64}/nptl/tls.h)
if (!Subtarget.isTargetGlibc())
return TargetLowering::getIRStackGuard(IRB);
// %fs:0x28, unless we're using a Kernel code model, in which case it's %gs:
@ -1932,7 +1934,7 @@ Value *X86TargetLowering::getIRStackGuard(IRBuilder<> &IRB) const {
}
void X86TargetLowering::insertSSPDeclarations(Module &M) const {
if (!Subtarget.isTargetLinux())
if (!Subtarget.isTargetGlibc())
TargetLowering::insertSSPDeclarations(M);
}

View File

@ -262,12 +262,12 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
assert((!In64BitMode || HasX86_64) &&
"64-bit code requested on a subtarget that doesn't support it!");
// Stack alignment is 16 bytes on Darwin, Linux and Solaris (both
// Stack alignment is 16 bytes on Darwin, Linux, kFreeBSD and Solaris (both
// 32 and 64 bit) and for all 64-bit targets.
if (StackAlignOverride)
stackAlignment = StackAlignOverride;
else if (isTargetDarwin() || isTargetLinux() || isTargetSolaris() ||
In64BitMode)
isTargetKFreeBSD() || In64BitMode)
stackAlignment = 16;
}

View File

@ -467,6 +467,8 @@ public:
bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
bool isTargetKFreeBSD() const { return TargetTriple.isOSKFreeBSD(); }
bool isTargetGlibc() const { return TargetTriple.isOSGlibc(); }
bool isTargetAndroid() const { return TargetTriple.isAndroid(); }
bool isTargetNaCl() const { return TargetTriple.isOSNaCl(); }
bool isTargetNaCl32() const { return isTargetNaCl() && !is64Bit(); }

View File

@ -1,7 +1,9 @@
; RUN: llc < %s -mcpu=generic -mtriple=i386-linux | FileCheck %s -check-prefix=LINUX-I386
; RUN: llc < %s -mcpu=generic -mtriple=i386-kfreebsd | FileCheck %s -check-prefix=KFREEBSD-I386
; RUN: llc < %s -mcpu=generic -mtriple=i386-netbsd | FileCheck %s -check-prefix=NETBSD-I386
; RUN: llc < %s -mcpu=generic -mtriple=i686-apple-darwin8 | FileCheck %s -check-prefix=DARWIN-I386
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux | FileCheck %s -check-prefix=LINUX-X86_64
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-kfreebsd | FileCheck %s -check-prefix=KFREEBSD-X86_64
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-netbsd | FileCheck %s -check-prefix=NETBSD-X86_64
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-apple-darwin8 | FileCheck %s -check-prefix=DARWIN-X86_64
@ -11,6 +13,7 @@ entry:
ret i32 0
; LINUX-I386: subl $12, %esp
; KFREEBSD-I386: subl $12, %esp
; DARWIN-I386: subl $12, %esp
; NETBSD-I386-NOT: subl {{.*}}, %esp
@ -20,6 +23,8 @@ entry:
; DARWIN-X86_64-NOT: subq {{.*}}, %rsp
; NETBSD-X86_64: pushq %{{.*}}
; NETBSD-X86_64-NOT: subq {{.*}}, %rsp
; KFREEBSD-X86_64: pushq %{{.*}}
; KFREEBSD-X86_64-NOT: subq {{.*}}, %rsp
}
declare void @test2()

View File

@ -3,6 +3,8 @@
; RUN: llc -mtriple=x86_64-linux < %s -o - | FileCheck --check-prefix=LINUX-X64 %s
; RUN: llc -mtriple=i386-linux-android < %s -o - | FileCheck --check-prefix=LINUX-I386 %s
; RUN: llc -mtriple=x86_64-linux-android < %s -o - | FileCheck --check-prefix=LINUX-X64 %s
; RUN: llc -mtriple=i386-kfreebsd < %s -o - | FileCheck --check-prefix=LINUX-I386 %s
; RUN: llc -mtriple=x86_64-kfreebsd < %s -o - | FileCheck --check-prefix=LINUX-X64 %s
define void @_Z1fv() sspreq {
entry: