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