2005-08-04 07:12:09 +00:00
|
|
|
//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===//
|
2005-07-12 01:41:54 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Nate Begeman and is distributed under the
|
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the X86 specific subclass of TargetSubtarget.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "X86Subtarget.h"
|
|
|
|
#include "llvm/Module.h"
|
2006-01-26 09:53:06 +00:00
|
|
|
#include "X86GenSubtarget.inc"
|
2005-07-12 01:41:54 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-01-26 09:53:06 +00:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#include <mach/mach_host.h>
|
|
|
|
#include <mach/host_info.h>
|
|
|
|
#include <mach/machine.h>
|
|
|
|
|
|
|
|
/// GetCurrentX86CPU - Returns the current CPUs features.
|
|
|
|
static const char *GetCurrentX86CPU() {
|
|
|
|
host_basic_info_data_t hostInfo;
|
|
|
|
mach_msg_type_number_t infoCount;
|
|
|
|
|
|
|
|
infoCount = HOST_BASIC_INFO_COUNT;
|
|
|
|
host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo,
|
|
|
|
&infoCount);
|
|
|
|
|
|
|
|
if (hostInfo.cpu_type != CPU_TYPE_I386) return "generic";
|
|
|
|
|
|
|
|
switch(hostInfo.cpu_subtype) {
|
|
|
|
case CPU_SUBTYPE_386: return "i386";
|
|
|
|
case CPU_SUBTYPE_486:
|
|
|
|
case CPU_SUBTYPE_486SX: return "i486";
|
|
|
|
case CPU_SUBTYPE_PENT: return "pentium";
|
|
|
|
case CPU_SUBTYPE_PENTPRO: return "pentiumpro";
|
|
|
|
case CPU_SUBTYPE_PENTII_M3: return "pentium2";
|
|
|
|
case CPU_SUBTYPE_PENTII_M5: return "pentium2";
|
|
|
|
case CPU_SUBTYPE_CELERON:
|
|
|
|
case CPU_SUBTYPE_CELERON_MOBILE: return "celeron";
|
|
|
|
case CPU_SUBTYPE_PENTIUM_3: return "pentium3";
|
|
|
|
case CPU_SUBTYPE_PENTIUM_3_M: return "pentium3m";
|
|
|
|
case CPU_SUBTYPE_PENTIUM_3_XEON: return "pentium3"; // FIXME: not sure.
|
|
|
|
case CPU_SUBTYPE_PENTIUM_M: return "pentium-m";
|
|
|
|
case CPU_SUBTYPE_PENTIUM_4: return "pentium4";
|
|
|
|
case CPU_SUBTYPE_PENTIUM_4_M: return "pentium4m";
|
|
|
|
// FIXME: prescott, yonah? Check CPU_THREADTYPE_INTEL_HTT?
|
|
|
|
case CPU_SUBTYPE_XEON:
|
|
|
|
case CPU_SUBTYPE_XEON_MP: return "nocona";
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "generic";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-01 21:38:21 +00:00
|
|
|
X86Subtarget::X86Subtarget(const Module &M, const std::string &FS)
|
2005-11-21 22:43:58 +00:00
|
|
|
: stackAlignment(8), indirectExternAndWeakGlobals(false) {
|
2005-11-21 22:31:58 +00:00
|
|
|
|
2006-01-26 09:53:06 +00:00
|
|
|
// Determine default and user specified characteristics
|
|
|
|
std::string CPU = "generic";
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
CPU = GetCurrentX86CPU();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Parse features string.
|
|
|
|
ParseSubtargetFeatures(FS, CPU);
|
|
|
|
|
2005-11-21 22:31:58 +00:00
|
|
|
// Default to ELF unless otherwise specified.
|
|
|
|
TargetType = isELF;
|
|
|
|
|
2005-07-12 01:41:54 +00:00
|
|
|
// Set the boolean corresponding to the current target triple, or the default
|
|
|
|
// if one cannot be determined, to true.
|
|
|
|
const std::string& TT = M.getTargetTriple();
|
|
|
|
if (TT.length() > 5) {
|
2005-11-21 22:31:58 +00:00
|
|
|
if (TT.find("cygwin") != std::string::npos ||
|
|
|
|
TT.find("mingw") != std::string::npos)
|
|
|
|
TargetType = isCygwin;
|
|
|
|
else if (TT.find("darwin") != std::string::npos)
|
|
|
|
TargetType = isDarwin;
|
|
|
|
else if (TT.find("win32") != std::string::npos)
|
|
|
|
TargetType = isWindows;
|
2005-07-12 01:41:54 +00:00
|
|
|
} else if (TT.empty()) {
|
|
|
|
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
2005-11-21 22:31:58 +00:00
|
|
|
TargetType = isCygwin;
|
2005-07-12 01:41:54 +00:00
|
|
|
#elif defined(__APPLE__)
|
2005-11-21 22:31:58 +00:00
|
|
|
TargetType = isDarwin;
|
2005-07-12 01:41:54 +00:00
|
|
|
#elif defined(_WIN32)
|
2005-11-21 22:31:58 +00:00
|
|
|
TargetType = isWindows;
|
2005-07-12 01:41:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-11-21 22:43:58 +00:00
|
|
|
if (TargetType == isDarwin) {
|
2005-07-12 01:41:54 +00:00
|
|
|
stackAlignment = 16;
|
|
|
|
indirectExternAndWeakGlobals = true;
|
|
|
|
}
|
|
|
|
}
|