diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-12-10 22:05:32 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-12-10 22:05:32 +0000 |
commit | 002f8aa584810cf076a9bc136e16246f7226d6c6 (patch) | |
tree | 907b12be9dee2f3f657c58995dafbb66658e1e81 /llvm/lib/Target/X86/X86TargetMachine.cpp | |
parent | 30b2a9a59f6276ae76f45a5e8f7865c265b40822 (diff) | |
download | bcm5719-llvm-002f8aa584810cf076a9bc136e16246f7226d6c6.tar.gz bcm5719-llvm-002f8aa584810cf076a9bc136e16246f7226d6c6.zip |
Refactor the computation of the x86 datalayout.
llvm-svn: 196976
Diffstat (limited to 'llvm/lib/Target/X86/X86TargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/X86/X86TargetMachine.cpp | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp index ddf580f7314..4d55b21f87b 100644 --- a/llvm/lib/Target/X86/X86TargetMachine.cpp +++ b/llvm/lib/Target/X86/X86TargetMachine.cpp @@ -30,21 +30,58 @@ extern "C" void LLVMInitializeX86Target() { void X86_32TargetMachine::anchor() { } +static std::string computeDataLayout(const X86Subtarget &ST) { + // X86 is little endian + std::string Ret = "e"; + + // X86 and x32 have 32 bit pointers, x86-64 has 64 bit pointers + if (ST.isTarget64BitILP32() || !ST.is64Bit()) + Ret += "-p:32:32"; + else + Ret += "-p:64:64"; + + // Objects on the stack ore aligned to 64 bits. + // FIXME: of any size? + if (ST.is64Bit()) + Ret += "-s:64"; + + // Some ABIs align 64 bit integers and doubles to 64 bits, others to 32. + if (ST.is64Bit() || ST.isTargetCygMing() || ST.isTargetWindows()) + Ret += "-f64:64:64-i64:64:64"; + else + Ret += "-f64:32:64-i64:32:64"; + + // Some ABIs align long double to 128 bits, others to 32. + if (ST.is64Bit() || ST.isTargetDarwin()) + Ret += "-f80:128:128"; + else + Ret += "-f80:32:32"; + + // 128 bit floats (?) are aligned to 128 bits. + Ret += "-f128:128:128"; + + // The registers can hold 8, 16, 32 or, in x86-64, 64 bits. + if (ST.is64Bit()) + Ret += "-n8:16:32:64"; + else + Ret += "-n8:16:32"; + + // The stack is aligned to 32 bits on some ABIs and 128 bits on others. + if (!ST.is64Bit() && (ST.isTargetCygMing() || ST.isTargetWindows())) + Ret += "-S32"; + else + Ret += "-S128"; + + return Ret; +} + X86_32TargetMachine::X86_32TargetMachine(const Target &T, StringRef TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL) : X86TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false), - DL(getSubtargetImpl()->isTargetDarwin() ? - "e-p:32:32-f64:32:64-i64:32:64-f80:128:128-f128:128:128-" - "n8:16:32-S128" : - (getSubtargetImpl()->isTargetCygMing() || - getSubtargetImpl()->isTargetWindows()) ? - "e-p:32:32-f64:64:64-i64:64:64-f80:32:32-f128:128:128-" - "n8:16:32-S32" : - "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-f128:128:128-" - "n8:16:32-S128"), + DL(computeDataLayout(*getSubtargetImpl())), InstrInfo(*this), TLInfo(*this), TSInfo(*this), @@ -61,11 +98,7 @@ X86_64TargetMachine::X86_64TargetMachine(const Target &T, StringRef TT, CodeGenOpt::Level OL) : X86TargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true), // The x32 ABI dictates the ILP32 programming model for x64. - DL(getSubtargetImpl()->isTarget64BitILP32() ? - "e-p:32:32-s:64-f64:64:64-i64:64:64-f80:128:128-f128:128:128-" - "n8:16:32:64-S128" : - "e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128-f128:128:128-" - "n8:16:32:64-S128"), + DL(computeDataLayout(*getSubtargetImpl())), InstrInfo(*this), TLInfo(*this), TSInfo(*this), |