blob: 3815875b22a0b80a71984b7077822308296547a3 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the "Instituto Nokia de Tecnologia" and
6// is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10//
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARMTargetMachine.h"
Evan Chenga8e29892007-01-19 07:51:42 +000015#include "ARMTargetAsmInfo.h"
Rafael Espindolaec46ea32006-08-16 14:43:33 +000016#include "ARMFrameInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARM.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000018#include "llvm/Module.h"
19#include "llvm/PassManager.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Support/CommandLine.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/Target/TargetMachineRegistry.h"
Evan Chenga8e29892007-01-19 07:51:42 +000022#include "llvm/Target/TargetOptions.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000023using namespace llvm;
24
Evan Chenga8e29892007-01-19 07:51:42 +000025static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
26 cl::desc("Disable load store optimization pass"));
27
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000028namespace {
29 // Register the target.
Evan Cheng04321f72007-02-23 03:14:31 +000030 RegisterTarget<ARMTargetMachine> X("arm", " ARM");
31 RegisterTarget<ThumbTargetMachine> Y("thumb", " Thumb");
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000032}
33
Evan Cheng04321f72007-02-23 03:14:31 +000034/// ThumbTargetMachine - Create an Thumb architecture model.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000035///
Evan Cheng04321f72007-02-23 03:14:31 +000036unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
37 std::string TT = M.getTargetTriple();
38 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
39 return 20;
40
41 return M.getPointerSize() == Module::Pointer32;
42}
43
44ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
45 : ARMTargetMachine(M, FS, true) {
46}
47
48/// TargetMachine ctor - Create an ARM architecture model.
49///
50ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
51 bool isThumb)
52 : Subtarget(M, FS, isThumb),
Lauro Ramos Venancio3630e782007-02-13 19:52:28 +000053 DataLayout(Subtarget.isAPCS_ABI() ?
Lauro Ramos Venancio75016052007-02-13 20:06:15 +000054 // APCS ABI
Evan Cheng04321f72007-02-23 03:14:31 +000055 (isThumb ?
Chris Lattnerd2b7cec2007-02-14 05:52:17 +000056 std::string("e-p:32:32-f64:32:32-i64:32:32-"
57 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
58 std::string("e-p:32:32-f64:32:32-i64:32:32")) :
Lauro Ramos Venancio75016052007-02-13 20:06:15 +000059 // AAPCS ABI
Evan Cheng04321f72007-02-23 03:14:31 +000060 (isThumb ?
Chris Lattnerd2b7cec2007-02-14 05:52:17 +000061 std::string("e-p:32:32-f64:64:64-i64:64:64-"
62 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
63 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
Evan Chengd44ecd82007-01-22 21:24:13 +000064 InstrInfo(Subtarget),
Evan Chenge8308df2007-03-13 01:20:42 +000065 FrameInfo(Subtarget),
66 TLInfo(*this) {}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000067
68unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
69 std::string TT = M.getTargetTriple();
70 if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
71 return 20;
72
Evan Cheng04321f72007-02-23 03:14:31 +000073 return M.getPointerSize() == Module::Pointer32;
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000074}
75
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000076
Evan Chenga8e29892007-01-19 07:51:42 +000077const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
78 return new ARMTargetAsmInfo(*this);
79}
80
81
Chris Lattner1911fd42006-09-04 04:14:57 +000082// Pass Pipeline Configuration
83bool ARMTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000084 PM.add(createARMISelDag(*this));
Chris Lattner1911fd42006-09-04 04:14:57 +000085 return false;
86}
Rafael Espindola71f3b942006-09-19 15:49:25 +000087
Evan Chenga8e29892007-01-19 07:51:42 +000088bool ARMTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
89 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
90 if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
91 PM.add(createARMLoadStoreOptimizationPass());
92
93 PM.add(createARMConstantIslandPass());
Rafael Espindola71f3b942006-09-19 15:49:25 +000094 return true;
95}
96
Chris Lattner1911fd42006-09-04 04:14:57 +000097bool ARMTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
98 std::ostream &Out) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000099 // Output assembly language.
100 PM.add(createARMCodePrinterPass(Out, *this));
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000101 return false;
102}