2006-05-14 22:18:28 +00:00
|
|
|
//===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
2006-05-14 22:18:28 +00:00
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMTargetMachine.h"
|
2007-01-19 07:51:42 +00:00
|
|
|
#include "ARMTargetAsmInfo.h"
|
2006-08-16 14:43:33 +00:00
|
|
|
#include "ARMFrameInfo.h"
|
2006-05-14 22:18:28 +00:00
|
|
|
#include "ARM.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/PassManager.h"
|
2007-05-16 02:01:49 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2007-01-19 07:51:42 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2008-08-21 00:14:44 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-05-14 22:18:28 +00:00
|
|
|
#include "llvm/Target/TargetMachineRegistry.h"
|
2007-01-19 07:51:42 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2006-05-14 22:18:28 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2007-01-19 07:51:42 +00:00
|
|
|
static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
|
|
|
|
cl::desc("Disable load store optimization pass"));
|
2007-09-20 00:48:22 +00:00
|
|
|
static cl::opt<bool> DisableIfConversion("disable-arm-if-conversion",cl::Hidden,
|
|
|
|
cl::desc("Disable if-conversion pass"));
|
2007-01-19 07:51:42 +00:00
|
|
|
|
2008-11-15 21:36:30 +00:00
|
|
|
/// ARMTargetMachineModule - Note that this is used on hosts that cannot link
|
|
|
|
/// in a library unless there are references into the library. In particular,
|
|
|
|
/// it seems that it is not possible to get things to work on Win32 without
|
|
|
|
/// this. Though it is unused, do not remove it.
|
|
|
|
extern "C" int ARMTargetMachineModule;
|
|
|
|
int ARMTargetMachineModule = 0;
|
|
|
|
|
2008-05-13 00:00:25 +00:00
|
|
|
// Register the target.
|
2008-10-14 20:25:08 +00:00
|
|
|
static RegisterTarget<ARMTargetMachine> X("arm", "ARM");
|
|
|
|
static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb");
|
2006-05-14 22:18:28 +00:00
|
|
|
|
2008-08-17 13:55:10 +00:00
|
|
|
// No assembler printer by default
|
|
|
|
ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0;
|
|
|
|
|
2007-02-23 03:14:31 +00:00
|
|
|
/// ThumbTargetMachine - Create an Thumb architecture model.
|
2006-05-14 22:18:28 +00:00
|
|
|
///
|
2007-07-05 21:15:40 +00:00
|
|
|
unsigned ThumbTargetMachine::getJITMatchQuality() {
|
2007-08-07 01:37:15 +00:00
|
|
|
#if defined(__thumb__)
|
2007-07-05 21:15:40 +00:00
|
|
|
return 10;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-23 03:14:31 +00:00
|
|
|
unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
|
|
|
|
std::string TT = M.getTargetTriple();
|
2009-03-09 20:25:39 +00:00
|
|
|
// Match thumb-foo-bar, as well as things like thumbv5blah-*
|
|
|
|
if (TT.size() >= 6 &&
|
|
|
|
(TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv"))
|
2007-02-23 03:14:31 +00:00
|
|
|
return 20;
|
|
|
|
|
2007-07-09 17:25:29 +00:00
|
|
|
// If the target triple is something non-thumb, we don't match.
|
|
|
|
if (!TT.empty()) return 0;
|
|
|
|
|
2007-07-05 21:15:40 +00:00
|
|
|
if (M.getEndianness() == Module::LittleEndian &&
|
|
|
|
M.getPointerSize() == Module::Pointer32)
|
|
|
|
return 10; // Weak match
|
|
|
|
else if (M.getEndianness() != Module::AnyEndianness ||
|
|
|
|
M.getPointerSize() != Module::AnyPointerSize)
|
|
|
|
return 0; // Match for some other target
|
|
|
|
|
|
|
|
return getJITMatchQuality()/2;
|
2007-02-23 03:14:31 +00:00
|
|
|
}
|
|
|
|
|
2008-08-07 09:54:23 +00:00
|
|
|
ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
|
2007-02-23 03:14:31 +00:00
|
|
|
: ARMTargetMachine(M, FS, true) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// TargetMachine ctor - Create an ARM architecture model.
|
|
|
|
///
|
|
|
|
ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
|
|
|
|
bool isThumb)
|
|
|
|
: Subtarget(M, FS, isThumb),
|
2007-02-13 19:52:28 +00:00
|
|
|
DataLayout(Subtarget.isAPCS_ABI() ?
|
2007-02-13 20:06:15 +00:00
|
|
|
// APCS ABI
|
2007-02-23 03:14:31 +00:00
|
|
|
(isThumb ?
|
2007-02-14 05:52:17 +00:00
|
|
|
std::string("e-p:32:32-f64:32:32-i64:32:32-"
|
|
|
|
"i16:16:32-i8:8:32-i1:8:32-a:0:32") :
|
|
|
|
std::string("e-p:32:32-f64:32:32-i64:32:32")) :
|
2007-02-13 20:06:15 +00:00
|
|
|
// AAPCS ABI
|
2007-02-23 03:14:31 +00:00
|
|
|
(isThumb ?
|
2007-02-14 05:52:17 +00:00
|
|
|
std::string("e-p:32:32-f64:64:64-i64:64:64-"
|
|
|
|
"i16:16:32-i8:8:32-i1:8:32-a:0:32") :
|
|
|
|
std::string("e-p:32:32-f64:64:64-i64:64:64"))),
|
2007-01-22 21:24:13 +00:00
|
|
|
InstrInfo(Subtarget),
|
2007-03-13 01:20:42 +00:00
|
|
|
FrameInfo(Subtarget),
|
2008-11-08 07:38:22 +00:00
|
|
|
JITInfo(),
|
2008-10-30 16:10:54 +00:00
|
|
|
TLInfo(*this) {
|
|
|
|
DefRelocModel = getRelocationModel();
|
|
|
|
}
|
2006-05-14 22:18:28 +00:00
|
|
|
|
2007-07-05 21:15:40 +00:00
|
|
|
unsigned ARMTargetMachine::getJITMatchQuality() {
|
2007-08-07 01:37:15 +00:00
|
|
|
#if defined(__arm__)
|
2007-07-05 21:15:40 +00:00
|
|
|
return 10;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-14 22:18:28 +00:00
|
|
|
unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
|
|
|
|
std::string TT = M.getTargetTriple();
|
2009-03-09 20:25:39 +00:00
|
|
|
// Match arm-foo-bar, as well as things like armv5blah-*
|
|
|
|
if (TT.size() >= 4 &&
|
2008-05-06 02:29:28 +00:00
|
|
|
(TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
|
2006-05-14 22:18:28 +00:00
|
|
|
return 20;
|
2007-07-09 17:25:29 +00:00
|
|
|
// If the target triple is something non-arm, we don't match.
|
|
|
|
if (!TT.empty()) return 0;
|
2006-05-14 22:18:28 +00:00
|
|
|
|
2007-07-05 21:15:40 +00:00
|
|
|
if (M.getEndianness() == Module::LittleEndian &&
|
|
|
|
M.getPointerSize() == Module::Pointer32)
|
|
|
|
return 10; // Weak match
|
|
|
|
else if (M.getEndianness() != Module::AnyEndianness ||
|
|
|
|
M.getPointerSize() != Module::AnyPointerSize)
|
|
|
|
return 0; // Match for some other target
|
|
|
|
|
|
|
|
return getJITMatchQuality()/2;
|
2006-05-14 22:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-19 07:51:42 +00:00
|
|
|
const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
|
2008-08-07 09:54:23 +00:00
|
|
|
switch (Subtarget.TargetType) {
|
|
|
|
case ARMSubtarget::isDarwin:
|
|
|
|
return new ARMDarwinTargetAsmInfo(*this);
|
|
|
|
case ARMSubtarget::isELF:
|
|
|
|
return new ARMELFTargetAsmInfo(*this);
|
|
|
|
default:
|
2008-09-25 21:00:33 +00:00
|
|
|
return new ARMGenericTargetAsmInfo(*this);
|
2008-08-07 09:54:23 +00:00
|
|
|
}
|
2007-01-19 07:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-04 04:14:57 +00:00
|
|
|
// Pass Pipeline Configuration
|
2009-04-29 23:29:43 +00:00
|
|
|
bool ARMTargetMachine::addInstSelector(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
2006-05-14 22:18:28 +00:00
|
|
|
PM.add(createARMISelDag(*this));
|
2006-09-04 04:14:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-09-19 15:49:25 +00:00
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
2007-01-19 07:51:42 +00:00
|
|
|
// FIXME: temporarily disabling load / store optimization pass for Thumb mode.
|
2009-04-29 23:29:43 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None && !DisableLdStOpti && !Subtarget.isThumb())
|
2007-01-19 07:51:42 +00:00
|
|
|
PM.add(createARMLoadStoreOptimizationPass());
|
2008-08-07 09:54:23 +00:00
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None &&
|
|
|
|
!DisableIfConversion && !Subtarget.isThumb())
|
2007-05-16 20:52:46 +00:00
|
|
|
PM.add(createIfConverterPass());
|
|
|
|
|
2007-01-19 07:51:42 +00:00
|
|
|
PM.add(createARMConstantIslandPass());
|
2006-09-19 15:49:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-29 00:15:41 +00:00
|
|
|
bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel,
|
2009-04-29 00:15:41 +00:00
|
|
|
bool Verbose,
|
|
|
|
raw_ostream &Out) {
|
2006-05-14 22:18:28 +00:00
|
|
|
// Output assembly language.
|
2008-08-17 13:55:10 +00:00
|
|
|
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
|
|
|
|
if (AsmPrinterCtor)
|
2009-04-29 00:15:41 +00:00
|
|
|
PM.add(AsmPrinterCtor(Out, *this, OptLevel, Verbose));
|
2008-08-17 13:55:10 +00:00
|
|
|
|
2006-05-14 22:18:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-07-05 21:15:40 +00:00
|
|
|
|
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel,
|
|
|
|
bool DumpAsm,
|
|
|
|
MachineCodeEmitter &MCE) {
|
2007-07-05 21:15:40 +00:00
|
|
|
// FIXME: Move this to TargetJITInfo!
|
2008-10-30 16:10:54 +00:00
|
|
|
if (DefRelocModel == Reloc::Default)
|
|
|
|
setRelocationModel(Reloc::Static);
|
2007-07-05 21:15:40 +00:00
|
|
|
|
|
|
|
// Machine code emitter pass for ARM.
|
|
|
|
PM.add(createARMCodeEmitterPass(*this, MCE));
|
2008-08-17 13:55:10 +00:00
|
|
|
if (DumpAsm) {
|
|
|
|
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
|
|
|
|
if (AsmPrinterCtor)
|
2009-04-29 00:15:41 +00:00
|
|
|
PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
|
2008-08-17 13:55:10 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 21:15:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-04-29 00:15:41 +00:00
|
|
|
bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel,
|
2009-04-29 00:15:41 +00:00
|
|
|
bool DumpAsm,
|
|
|
|
MachineCodeEmitter &MCE) {
|
2007-07-05 21:15:40 +00:00
|
|
|
// Machine code emitter pass for ARM.
|
|
|
|
PM.add(createARMCodeEmitterPass(*this, MCE));
|
2008-08-17 13:55:10 +00:00
|
|
|
if (DumpAsm) {
|
|
|
|
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
|
|
|
|
if (AsmPrinterCtor)
|
2009-04-29 00:15:41 +00:00
|
|
|
PM.add(AsmPrinterCtor(errs(), *this, OptLevel, true));
|
2008-08-17 13:55:10 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 21:15:40 +00:00
|
|
|
return false;
|
|
|
|
}
|