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"
|
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-05-13 00:00:25 +00:00
|
|
|
// Register the target.
|
|
|
|
static RegisterTarget<ARMTargetMachine> X("arm", " ARM");
|
|
|
|
static RegisterTarget<ThumbTargetMachine> Y("thumb", " Thumb");
|
2006-05-14 22:18:28 +00:00
|
|
|
|
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();
|
|
|
|
if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
|
|
|
|
: 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),
|
2007-07-05 21:15:40 +00:00
|
|
|
JITInfo(*this),
|
2007-03-13 01:20:42 +00:00
|
|
|
TLInfo(*this) {}
|
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();
|
2008-05-06 02:29:28 +00: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-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 {
|
|
|
|
return new ARMTargetAsmInfo(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-04 04:14:57 +00:00
|
|
|
// Pass Pipeline Configuration
|
2008-03-11 22:29:46 +00:00
|
|
|
bool ARMTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
|
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
|
|
|
|
2008-03-11 22:29:46 +00:00
|
|
|
bool ARMTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) {
|
2007-01-19 07:51:42 +00:00
|
|
|
// FIXME: temporarily disabling load / store optimization pass for Thumb mode.
|
|
|
|
if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
|
|
|
|
PM.add(createARMLoadStoreOptimizationPass());
|
|
|
|
|
2007-09-20 00:48:22 +00:00
|
|
|
if (!Fast && !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;
|
|
|
|
}
|
|
|
|
|
2008-03-11 22:29:46 +00:00
|
|
|
bool ARMTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
|
2006-09-04 04:14:57 +00:00
|
|
|
std::ostream &Out) {
|
2006-05-14 22:18:28 +00:00
|
|
|
// Output assembly language.
|
|
|
|
PM.add(createARMCodePrinterPass(Out, *this));
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-05 21:15:40 +00:00
|
|
|
|
|
|
|
|
2008-03-11 22:29:46 +00:00
|
|
|
bool ARMTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast,
|
2007-07-20 21:56:13 +00:00
|
|
|
bool DumpAsm, MachineCodeEmitter &MCE) {
|
2007-07-05 21:15:40 +00:00
|
|
|
// FIXME: Move this to TargetJITInfo!
|
|
|
|
setRelocationModel(Reloc::Static);
|
|
|
|
|
|
|
|
// Machine code emitter pass for ARM.
|
|
|
|
PM.add(createARMCodeEmitterPass(*this, MCE));
|
2007-07-20 21:56:13 +00:00
|
|
|
if (DumpAsm)
|
|
|
|
PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
|
2007-07-05 21:15:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-11 22:29:46 +00:00
|
|
|
bool ARMTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, bool Fast,
|
2007-07-20 21:56:13 +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));
|
2007-07-20 21:56:13 +00:00
|
|
|
if (DumpAsm)
|
|
|
|
PM.add(createARMCodePrinterPass(*cerr.stream(), *this));
|
2007-07-05 21:15:40 +00:00
|
|
|
return false;
|
|
|
|
}
|