diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 071111384d2d..a0a3cc5eb76e 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -2124,23 +2124,21 @@ X86TargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, return std::make_pair(RRC, Cost); } +unsigned X86TargetLowering::getAddressSpace() const { + if (Subtarget.is64Bit()) + return (getTargetMachine().getCodeModel() == CodeModel::Kernel) ? 256 : 257; + return 256; +} + bool X86TargetLowering::getStackCookieLocation(unsigned &AddressSpace, unsigned &Offset) const { if (!Subtarget.isTargetLinux()) return false; - if (Subtarget.is64Bit()) { - // %fs:0x28, unless we're using a Kernel code model, in which case it's %gs: - Offset = 0x28; - if (getTargetMachine().getCodeModel() == CodeModel::Kernel) - AddressSpace = 256; - else - AddressSpace = 257; - } else { - // %gs:0x14 on i386 - Offset = 0x14; - AddressSpace = 256; - } + // %fs:0x28, unless we're using a Kernel code model, in which case it's %gs: + // %gs:0x14 on i386 + Offset = (Subtarget.is64Bit()) ? 0x28 : 0x14; + AddressSpace = getAddressSpace(); return true; } @@ -2152,19 +2150,11 @@ Value *X86TargetLowering::getSafeStackPointerLocation(IRBuilder<> &IRB) const { // definition of TLS_SLOT_SAFESTACK in // https://android.googlesource.com/platform/bionic/+/master/libc/private/bionic_tls.h unsigned AddressSpace, Offset; - if (Subtarget.is64Bit()) { - // %fs:0x48, unless we're using a Kernel code model, in which case it's %gs: - Offset = 0x48; - if (getTargetMachine().getCodeModel() == CodeModel::Kernel) - AddressSpace = 256; - else - AddressSpace = 257; - } else { - // %gs:0x24 on i386 - Offset = 0x24; - AddressSpace = 256; - } + // %fs:0x48, unless we're using a Kernel code model, in which case it's %gs: + // %gs:0x24 on i386 + Offset = (Subtarget.is64Bit()) ? 0x48 : 0x24; + AddressSpace = getAddressSpace(); return ConstantExpr::getIntToPtr( ConstantInt::get(Type::getInt32Ty(IRB.getContext()), Offset), Type::getInt8PtrTy(IRB.getContext())->getPointerTo(AddressSpace)); diff --git a/llvm/lib/Target/X86/X86ISelLowering.h b/llvm/lib/Target/X86/X86ISelLowering.h index c40e6e39d6ad..0a5edd815e30 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.h +++ b/llvm/lib/Target/X86/X86ISelLowering.h @@ -1012,6 +1012,8 @@ namespace llvm { unsigned GetAlignedArgumentStackSize(unsigned StackSize, SelectionDAG &DAG) const; + unsigned getAddressSpace(void) const; + std::pair FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG, bool isSigned, bool isReplace) const;