2006-05-15 06:18:28 +08:00
|
|
|
//===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
2006-05-15 06:18:28 +08:00
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMTargetMachine.h"
|
2007-01-19 15:51:42 +08:00
|
|
|
#include "ARMTargetAsmInfo.h"
|
2006-08-16 22:43:33 +08:00
|
|
|
#include "ARMFrameInfo.h"
|
2006-05-15 06:18:28 +08:00
|
|
|
#include "ARM.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/PassManager.h"
|
2007-05-16 10:01:49 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2007-01-19 15:51:42 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2008-08-21 08:14:44 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-05-15 06:18:28 +08:00
|
|
|
#include "llvm/Target/TargetMachineRegistry.h"
|
2007-01-19 15:51:42 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2006-05-15 06:18:28 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
|
|
|
|
cl::desc("Disable load store optimization pass"));
|
2007-09-20 08:48:22 +08:00
|
|
|
static cl::opt<bool> DisableIfConversion("disable-arm-if-conversion",cl::Hidden,
|
|
|
|
cl::desc("Disable if-conversion pass"));
|
2007-01-19 15:51:42 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
// Register the target.
|
|
|
|
static RegisterTarget<ARMTargetMachine> X("arm", " ARM");
|
|
|
|
static RegisterTarget<ThumbTargetMachine> Y("thumb", " Thumb");
|
2006-05-15 06:18:28 +08:00
|
|
|
|
2008-08-17 21:55:10 +08:00
|
|
|
// No assembler printer by default
|
|
|
|
ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0;
|
|
|
|
|
2007-02-23 11:14:31 +08:00
|
|
|
/// ThumbTargetMachine - Create an Thumb architecture model.
|
2006-05-15 06:18:28 +08:00
|
|
|
///
|
2007-07-06 05:15:40 +08:00
|
|
|
unsigned ThumbTargetMachine::getJITMatchQuality() {
|
2007-08-07 09:37:15 +08:00
|
|
|
#if defined(__thumb__)
|
2007-07-06 05:15:40 +08:00
|
|
|
return 10;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-23 11:14:31 +08:00
|
|
|
unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
|
|
|
|
std::string TT = M.getTargetTriple();
|
|
|
|
if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
|
|
|
|
return 20;
|
|
|
|
|
2007-07-10 01:25:29 +08:00
|
|
|
// If the target triple is something non-thumb, we don't match.
|
|
|
|
if (!TT.empty()) return 0;
|
|
|
|
|
2007-07-06 05:15:40 +08: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 11:14:31 +08:00
|
|
|
}
|
|
|
|
|
2008-08-07 17:54:23 +08:00
|
|
|
ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
|
2007-02-23 11:14:31 +08: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-14 03:52:28 +08:00
|
|
|
DataLayout(Subtarget.isAPCS_ABI() ?
|
2007-02-14 04:06:15 +08:00
|
|
|
// APCS ABI
|
2007-02-23 11:14:31 +08:00
|
|
|
(isThumb ?
|
2007-02-14 13:52:17 +08: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-14 04:06:15 +08:00
|
|
|
// AAPCS ABI
|
2007-02-23 11:14:31 +08:00
|
|
|
(isThumb ?
|
2007-02-14 13:52:17 +08: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-23 05:24:13 +08:00
|
|
|
InstrInfo(Subtarget),
|
2007-03-13 09:20:42 +08:00
|
|
|
FrameInfo(Subtarget),
|
2007-07-06 05:15:40 +08:00
|
|
|
JITInfo(*this),
|
2007-03-13 09:20:42 +08:00
|
|
|
TLInfo(*this) {}
|
2006-05-15 06:18:28 +08:00
|
|
|
|
2007-07-06 05:15:40 +08:00
|
|
|
unsigned ARMTargetMachine::getJITMatchQuality() {
|
2007-08-07 09:37:15 +08:00
|
|
|
#if defined(__arm__)
|
2007-07-06 05:15:40 +08:00
|
|
|
return 10;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-15 06:18:28 +08:00
|
|
|
unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
|
|
|
|
std::string TT = M.getTargetTriple();
|
2008-05-06 10:29:28 +08:00
|
|
|
if (TT.size() >= 4 && // Match arm-foo-bar, as well as things like armv5blah-*
|
|
|
|
(TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
|
2006-05-15 06:18:28 +08:00
|
|
|
return 20;
|
2007-07-10 01:25:29 +08:00
|
|
|
// If the target triple is something non-arm, we don't match.
|
|
|
|
if (!TT.empty()) return 0;
|
2006-05-15 06:18:28 +08:00
|
|
|
|
2007-07-06 05:15:40 +08: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-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
|
2008-08-07 17:54:23 +08:00
|
|
|
switch (Subtarget.TargetType) {
|
|
|
|
case ARMSubtarget::isDarwin:
|
|
|
|
return new ARMDarwinTargetAsmInfo(*this);
|
|
|
|
case ARMSubtarget::isELF:
|
|
|
|
return new ARMELFTargetAsmInfo(*this);
|
|
|
|
default:
|
|
|
|
return new ARMTargetAsmInfo(*this);
|
|
|
|
}
|
2007-01-19 15:51:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-04 12:14:57 +08:00
|
|
|
// Pass Pipeline Configuration
|
2008-03-12 06:29:46 +08:00
|
|
|
bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
|
2006-05-15 06:18:28 +08:00
|
|
|
PM.add(createARMISelDag(*this));
|
2006-09-04 12:14:57 +08:00
|
|
|
return false;
|
|
|
|
}
|
2006-09-19 23:49:25 +08:00
|
|
|
|
2008-03-12 06:29:46 +08:00
|
|
|
bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
|
2007-01-19 15:51:42 +08:00
|
|
|
// FIXME: temporarily disabling load / store optimization pass for Thumb mode.
|
|
|
|
if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
|
|
|
|
PM.add(createARMLoadStoreOptimizationPass());
|
2008-08-07 17:54:23 +08:00
|
|
|
|
2007-09-20 08:48:22 +08:00
|
|
|
if (!Fast && !DisableIfConversion && !Subtarget.isThumb())
|
2007-05-17 04:52:46 +08:00
|
|
|
PM.add(createIfConverterPass());
|
|
|
|
|
2007-01-19 15:51:42 +08:00
|
|
|
PM.add(createARMConstantIslandPass());
|
2006-09-19 23:49:25 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-07 17:54:23 +08:00
|
|
|
bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
|
2008-08-21 08:14:44 +08:00
|
|
|
raw_ostream &Out) {
|
2006-05-15 06:18:28 +08:00
|
|
|
// Output assembly language.
|
2008-08-17 21:55:10 +08:00
|
|
|
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
|
|
|
|
if (AsmPrinterCtor)
|
|
|
|
PM.add(AsmPrinterCtor(Out, *this));
|
|
|
|
|
2006-05-15 06:18:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
2007-07-06 05:15:40 +08:00
|
|
|
|
|
|
|
|
2008-03-12 06:29:46 +08:00
|
|
|
bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
|
2007-07-21 05:56:13 +08:00
|
|
|
bool DumpAsm, MachineCodeEmitter &MCE) {
|
2007-07-06 05:15:40 +08:00
|
|
|
// FIXME: Move this to TargetJITInfo!
|
|
|
|
setRelocationModel(Reloc::Static);
|
|
|
|
|
|
|
|
// Machine code emitter pass for ARM.
|
|
|
|
PM.add(createARMCodeEmitterPass(*this, MCE));
|
2008-08-17 21:55:10 +08:00
|
|
|
if (DumpAsm) {
|
|
|
|
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
|
|
|
|
if (AsmPrinterCtor)
|
2008-08-21 08:14:44 +08:00
|
|
|
PM.add(AsmPrinterCtor(errs(), *this));
|
2008-08-17 21:55:10 +08:00
|
|
|
}
|
|
|
|
|
2007-07-06 05:15:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-12 06:29:46 +08:00
|
|
|
bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
|
2007-07-21 05:56:13 +08:00
|
|
|
bool DumpAsm, MachineCodeEmitter &MCE) {
|
2007-07-06 05:15:40 +08:00
|
|
|
// Machine code emitter pass for ARM.
|
|
|
|
PM.add(createARMCodeEmitterPass(*this, MCE));
|
2008-08-17 21:55:10 +08:00
|
|
|
if (DumpAsm) {
|
|
|
|
assert(AsmPrinterCtor && "AsmPrinter was not linked in");
|
|
|
|
if (AsmPrinterCtor)
|
2008-08-21 08:14:44 +08:00
|
|
|
PM.add(AsmPrinterCtor(errs(), *this));
|
2008-08-17 21:55:10 +08:00
|
|
|
}
|
|
|
|
|
2007-07-06 05:15:40 +08:00
|
|
|
return false;
|
|
|
|
}
|