2002-10-29 22:37:54 +00:00
|
|
|
//===-- X86TargetMachine.cpp - Define TargetMachine for the X86 -----------===//
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 23:38:14 +00:00
|
|
|
//
|
2002-10-29 22:37:54 +00:00
|
|
|
// This file defines the X86 specific subclass of TargetMachine.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "X86TargetMachine.h"
|
2002-12-24 00:04:01 +00:00
|
|
|
#include "X86.h"
|
2003-04-23 16:24:55 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2002-10-30 00:47:49 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2003-01-13 00:51:23 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2011-08-23 01:14:17 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-14 20:18:05 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2004-07-11 04:17:10 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2003-12-20 01:22:19 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2011-02-17 12:23:50 +00:00
|
|
|
extern "C" void LLVMInitializeX86Target() {
|
2009-07-25 06:49:55 +00:00
|
|
|
// Register the target.
|
|
|
|
RegisterTargetMachine<X86_32TargetMachine> X(TheX86_32Target);
|
|
|
|
RegisterTargetMachine<X86_64TargetMachine> Y(TheX86_64Target);
|
2006-09-07 23:39:26 +00:00
|
|
|
}
|
2006-09-08 06:48:29 +00:00
|
|
|
|
2009-08-12 07:22:17 +00:00
|
|
|
|
2011-07-19 06:37:02 +00:00
|
|
|
X86_32TargetMachine::X86_32TargetMachine(const Target &T, StringRef TT,
|
|
|
|
StringRef CPU, StringRef FS,
|
2011-07-20 07:51:56 +00:00
|
|
|
Reloc::Model RM, CodeModel::Model CM)
|
|
|
|
: X86TargetMachine(T, TT, CPU, FS, RM, CM, false),
|
2010-10-03 18:59:45 +00:00
|
|
|
DataLayout(getSubtargetImpl()->isTargetDarwin() ?
|
2011-10-14 20:36:23 +00:00
|
|
|
"e-p:32:32-f64:32:64-i64:32:64-f80:128:128-f128:128:128-"
|
|
|
|
"n8:16:32-S128" :
|
2010-10-03 18:59:45 +00:00
|
|
|
(getSubtargetImpl()->isTargetCygMing() ||
|
|
|
|
getSubtargetImpl()->isTargetWindows()) ?
|
2011-10-14 20:36:23 +00:00
|
|
|
"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"),
|
2010-10-03 18:59:45 +00:00
|
|
|
InstrInfo(*this),
|
|
|
|
TSInfo(*this),
|
|
|
|
TLInfo(*this),
|
|
|
|
JITInfo(*this) {
|
2006-09-08 06:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-19 06:37:02 +00:00
|
|
|
X86_64TargetMachine::X86_64TargetMachine(const Target &T, StringRef TT,
|
|
|
|
StringRef CPU, StringRef FS,
|
2011-07-20 07:51:56 +00:00
|
|
|
Reloc::Model RM, CodeModel::Model CM)
|
|
|
|
: X86TargetMachine(T, TT, CPU, FS, RM, CM, true),
|
2011-10-14 20:36:23 +00:00
|
|
|
DataLayout("e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128-f128:128:128-"
|
|
|
|
"n8:16:32:64-S128"),
|
2010-10-03 18:59:45 +00:00
|
|
|
InstrInfo(*this),
|
|
|
|
TSInfo(*this),
|
|
|
|
TLInfo(*this),
|
|
|
|
JITInfo(*this) {
|
2006-09-08 06:48:29 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 03:32:31 +00:00
|
|
|
/// X86TargetMachine ctor - Create an X86 target.
|
2002-10-29 22:37:54 +00:00
|
|
|
///
|
2011-07-19 06:37:02 +00:00
|
|
|
X86TargetMachine::X86TargetMachine(const Target &T, StringRef TT,
|
|
|
|
StringRef CPU, StringRef FS,
|
2011-07-20 07:51:56 +00:00
|
|
|
Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
bool is64Bit)
|
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, RM, CM),
|
2011-07-08 22:30:25 +00:00
|
|
|
Subtarget(TT, CPU, FS, StackAlignmentOverride, is64Bit),
|
2011-01-10 12:39:04 +00:00
|
|
|
FrameLowering(*this, Subtarget),
|
2010-10-03 18:59:45 +00:00
|
|
|
ELFWriterInfo(is64Bit, true) {
|
2009-07-09 03:32:31 +00:00
|
|
|
// Determine the PICStyle based on the target selected.
|
|
|
|
if (getRelocationModel() == Reloc::Static) {
|
|
|
|
// Unless we're in PIC or DynamicNoPIC mode, set the PIC style to None.
|
|
|
|
Subtarget.setPICStyle(PICStyles::None);
|
2010-08-21 17:21:11 +00:00
|
|
|
} else if (Subtarget.is64Bit()) {
|
|
|
|
// PIC in 64 bit mode is always rip-rel.
|
|
|
|
Subtarget.setPICStyle(PICStyles::RIPRel);
|
2009-07-09 03:32:31 +00:00
|
|
|
} else if (Subtarget.isTargetCygMing()) {
|
2009-07-09 03:15:51 +00:00
|
|
|
Subtarget.setPICStyle(PICStyles::None);
|
|
|
|
} else if (Subtarget.isTargetDarwin()) {
|
2010-08-21 17:21:11 +00:00
|
|
|
if (getRelocationModel() == Reloc::PIC_)
|
2009-07-10 20:58:47 +00:00
|
|
|
Subtarget.setPICStyle(PICStyles::StubPIC);
|
|
|
|
else {
|
|
|
|
assert(getRelocationModel() == Reloc::DynamicNoPIC);
|
|
|
|
Subtarget.setPICStyle(PICStyles::StubDynamicNoPIC);
|
|
|
|
}
|
2008-02-20 11:22:39 +00:00
|
|
|
} else if (Subtarget.isTargetELF()) {
|
2010-08-21 17:21:11 +00:00
|
|
|
Subtarget.setPICStyle(PICStyles::GOT);
|
2008-02-20 11:22:39 +00:00
|
|
|
}
|
2010-08-21 17:21:11 +00:00
|
|
|
|
2011-06-23 17:54:54 +00:00
|
|
|
// default to hard float ABI
|
|
|
|
if (FloatABIType == FloatABI::Default)
|
|
|
|
FloatABIType = FloatABI::Hard;
|
2006-02-03 18:59:39 +00:00
|
|
|
}
|
2002-10-29 22:37:54 +00:00
|
|
|
|
2011-08-23 01:14:17 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Command line options for x86
|
|
|
|
//===----------------------------------------------------------------------===//
|
2011-09-03 03:45:06 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
UseVZeroUpper("x86-use-vzeroupper",
|
2011-08-23 01:14:17 +00:00
|
|
|
cl::desc("Minimize AVX to SSE transition penalty"),
|
2011-10-18 23:10:11 +00:00
|
|
|
cl::init(false));
|
2011-08-23 01:14:17 +00:00
|
|
|
|
2006-09-04 04:14:57 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pass Pipeline Configuration
|
|
|
|
//===----------------------------------------------------------------------===//
|
2003-08-05 16:34:44 +00:00
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
bool X86TargetMachine::addInstSelector(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
2005-08-18 23:53:15 +00:00
|
|
|
// Install an instruction selector.
|
2009-04-29 00:15:41 +00:00
|
|
|
PM.add(createX86ISelDag(*this, OptLevel));
|
2008-10-25 17:46:52 +00:00
|
|
|
|
2010-07-10 09:00:22 +00:00
|
|
|
// For 32-bit, prepend instructions to set the "global base reg" for PIC.
|
|
|
|
if (!Subtarget.is64Bit())
|
|
|
|
PM.add(createGlobalBaseRegPass());
|
|
|
|
|
2006-09-04 04:14:57 +00:00
|
|
|
return false;
|
2003-06-18 21:43:21 +00:00
|
|
|
}
|
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
bool X86TargetMachine::addPreRegAlloc(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
2010-04-06 20:26:37 +00:00
|
|
|
PM.add(createX86MaxStackAlignmentHeuristicPass());
|
2008-04-23 18:23:05 +00:00
|
|
|
return false; // -print-machineinstr shouldn't print after this.
|
|
|
|
}
|
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
bool X86TargetMachine::addPostRegAlloc(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
2003-01-13 00:51:23 +00:00
|
|
|
PM.add(createX86FloatingPointStackifierPass());
|
2006-09-04 04:14:57 +00:00
|
|
|
return true; // -print-machineinstr should print after this.
|
|
|
|
}
|
2003-01-13 00:51:23 +00:00
|
|
|
|
2010-03-25 17:25:00 +00:00
|
|
|
bool X86TargetMachine::addPreEmitPass(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
2011-09-15 18:27:32 +00:00
|
|
|
bool ShouldPrint = false;
|
2011-11-09 09:37:21 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None) {
|
|
|
|
if (Subtarget.hasXMMInt()) {
|
|
|
|
PM.add(createExecutionDependencyFixPass(&X86::VR128RegClass));
|
|
|
|
ShouldPrint = true;
|
|
|
|
}
|
|
|
|
if (Subtarget.hasAVX2()) {
|
|
|
|
// FIXME this should be turned on for just AVX, but the pass doesn't check
|
|
|
|
// that instructions are valid before replacing them and there are AVX2
|
|
|
|
// integer instructions in the table.
|
|
|
|
PM.add(createExecutionDependencyFixPass(&X86::VR256RegClass));
|
|
|
|
ShouldPrint = true;
|
|
|
|
}
|
2010-03-25 17:25:00 +00:00
|
|
|
}
|
2011-08-23 01:14:17 +00:00
|
|
|
|
|
|
|
if (Subtarget.hasAVX() && UseVZeroUpper) {
|
|
|
|
PM.add(createX86IssueVZeroUpperPass());
|
2011-09-15 18:27:32 +00:00
|
|
|
ShouldPrint = true;
|
2011-08-23 01:14:17 +00:00
|
|
|
}
|
2011-09-15 18:27:32 +00:00
|
|
|
|
|
|
|
return ShouldPrint;
|
2010-03-25 17:25:00 +00:00
|
|
|
}
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel,
|
2009-06-01 19:57:37 +00:00
|
|
|
JITCodeEmitter &JCE) {
|
2009-05-30 20:51:52 +00:00
|
|
|
PM.add(createX86JITCodeEmitterPass(*this, JCE));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|