2011-07-06 22:01:53 +00:00
|
|
|
//===-- X86MCTargetDesc.cpp - X86 Target Descriptions -----------*- C++ -*-===//
|
2011-06-24 01:44:41 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides X86 specific target descriptions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-06 22:01:53 +00:00
|
|
|
#include "X86MCTargetDesc.h"
|
2011-06-28 20:07:07 +00:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2011-06-24 01:44:41 +00:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2011-07-01 22:25:04 +00:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2011-06-24 20:42:09 +00:00
|
|
|
#include "llvm/Target/TargetRegistry.h"
|
2011-07-07 21:06:52 +00:00
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
#include "llvm/Support/Host.h"
|
2011-06-27 18:32:37 +00:00
|
|
|
|
|
|
|
#define GET_REGINFO_MC_DESC
|
|
|
|
#include "X86GenRegisterInfo.inc"
|
2011-06-28 20:07:07 +00:00
|
|
|
|
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
|
|
#include "X86GenInstrInfo.inc"
|
|
|
|
|
2011-07-01 22:25:04 +00:00
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
2011-07-01 22:36:09 +00:00
|
|
|
#include "X86GenSubtargetInfo.inc"
|
2011-07-01 22:25:04 +00:00
|
|
|
|
2011-06-24 01:44:41 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-07 21:06:52 +00:00
|
|
|
|
|
|
|
std::string X86_MC::ParseX86Triple(StringRef TT) {
|
|
|
|
Triple TheTriple(TT);
|
|
|
|
if (TheTriple.getArch() == Triple::x86_64)
|
2011-07-08 23:07:42 +00:00
|
|
|
return "+64bit-mode";
|
2011-07-08 01:53:10 +00:00
|
|
|
return "-64bit-mode";
|
2011-07-07 21:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// GetCpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
|
|
|
|
/// specified arguments. If we can't run cpuid on the host, return true.
|
|
|
|
bool X86_MC::GetCpuIDAndInfo(unsigned value, unsigned *rEAX,
|
|
|
|
unsigned *rEBX, unsigned *rECX, unsigned *rEDX) {
|
|
|
|
#if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
// gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
|
|
|
|
asm ("movq\t%%rbx, %%rsi\n\t"
|
|
|
|
"cpuid\n\t"
|
|
|
|
"xchgq\t%%rbx, %%rsi\n\t"
|
|
|
|
: "=a" (*rEAX),
|
|
|
|
"=S" (*rEBX),
|
|
|
|
"=c" (*rECX),
|
|
|
|
"=d" (*rEDX)
|
|
|
|
: "a" (value));
|
|
|
|
return false;
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
int registers[4];
|
|
|
|
__cpuid(registers, value);
|
|
|
|
*rEAX = registers[0];
|
|
|
|
*rEBX = registers[1];
|
|
|
|
*rECX = registers[2];
|
|
|
|
*rEDX = registers[3];
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
#elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
asm ("movl\t%%ebx, %%esi\n\t"
|
|
|
|
"cpuid\n\t"
|
|
|
|
"xchgl\t%%ebx, %%esi\n\t"
|
|
|
|
: "=a" (*rEAX),
|
|
|
|
"=S" (*rEBX),
|
|
|
|
"=c" (*rECX),
|
|
|
|
"=d" (*rEDX)
|
|
|
|
: "a" (value));
|
|
|
|
return false;
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
__asm {
|
|
|
|
mov eax,value
|
|
|
|
cpuid
|
|
|
|
mov esi,rEAX
|
|
|
|
mov dword ptr [esi],eax
|
|
|
|
mov esi,rEBX
|
|
|
|
mov dword ptr [esi],ebx
|
|
|
|
mov esi,rECX
|
|
|
|
mov dword ptr [esi],ecx
|
|
|
|
mov esi,rEDX
|
|
|
|
mov dword ptr [esi],edx
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void X86_MC::DetectFamilyModel(unsigned EAX, unsigned &Family,
|
|
|
|
unsigned &Model) {
|
|
|
|
Family = (EAX >> 8) & 0xf; // Bits 8 - 11
|
|
|
|
Model = (EAX >> 4) & 0xf; // Bits 4 - 7
|
|
|
|
if (Family == 6 || Family == 0xf) {
|
|
|
|
if (Family == 0xf)
|
|
|
|
// Examine extended family ID if family ID is F.
|
|
|
|
Family += (EAX >> 20) & 0xff; // Bits 20 - 27
|
|
|
|
// Examine extended model ID if family ID is 6 or F.
|
|
|
|
Model += ((EAX >> 16) & 0xf) << 4; // Bits 16 - 19
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 01:53:10 +00:00
|
|
|
MCSubtargetInfo *X86_MC::createX86MCSubtargetInfo(StringRef TT, StringRef CPU,
|
|
|
|
StringRef FS) {
|
2011-07-07 21:06:52 +00:00
|
|
|
std::string ArchFS = X86_MC::ParseX86Triple(TT);
|
|
|
|
if (!FS.empty()) {
|
|
|
|
if (!ArchFS.empty())
|
|
|
|
ArchFS = ArchFS + "," + FS.str();
|
|
|
|
else
|
|
|
|
ArchFS = FS;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CPUName = CPU;
|
2011-07-08 21:14:14 +00:00
|
|
|
if (CPUName.empty()) {
|
|
|
|
#if defined (__x86_64__) || defined(__i386__)
|
2011-07-07 21:06:52 +00:00
|
|
|
CPUName = sys::getHostCPUName();
|
2011-07-08 21:14:14 +00:00
|
|
|
#else
|
|
|
|
CPUName = "generic";
|
|
|
|
#endif
|
|
|
|
}
|
2011-07-07 21:06:52 +00:00
|
|
|
|
2011-07-01 22:25:04 +00:00
|
|
|
MCSubtargetInfo *X = new MCSubtargetInfo();
|
2011-07-11 03:57:24 +00:00
|
|
|
InitX86MCSubtargetInfo(X, TT, CPUName, ArchFS);
|
2011-07-08 01:53:10 +00:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCInstrInfo *createX86MCInstrInfo() {
|
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitX86MCInstrInfo(X);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCRegisterInfo *createX86MCRegisterInfo() {
|
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
|
|
|
InitX86MCRegisterInfo(X);
|
2011-07-01 22:25:04 +00:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-06-24 20:42:09 +00:00
|
|
|
// Force static initialization.
|
2011-07-01 22:25:04 +00:00
|
|
|
extern "C" void LLVMInitializeX86MCInstrInfo() {
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(TheX86_32Target, createX86MCInstrInfo);
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(TheX86_64Target, createX86MCInstrInfo);
|
|
|
|
}
|
|
|
|
|
2011-06-24 20:42:09 +00:00
|
|
|
extern "C" void LLVMInitializeX86MCRegInfo() {
|
|
|
|
TargetRegistry::RegisterMCRegInfo(TheX86_32Target, createX86MCRegisterInfo);
|
|
|
|
TargetRegistry::RegisterMCRegInfo(TheX86_64Target, createX86MCRegisterInfo);
|
|
|
|
}
|
2011-07-09 05:47:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern "C" void LLVMInitializeX86MCSubtargetInfo() {
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(TheX86_32Target,
|
|
|
|
X86_MC::createX86MCSubtargetInfo);
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(TheX86_64Target,
|
|
|
|
X86_MC::createX86MCSubtargetInfo);
|
|
|
|
}
|