1 //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===//
3 // The LLVM Compiler Infrastructure
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.
9 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
14 #include "ARMTargetMachine.h"
15 #include "ARMTargetAsmInfo.h"
16 #include "ARMFrameInfo.h"
18 #include "llvm/Module.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Target/TargetMachineRegistry.h"
23 #include "llvm/Target/TargetOptions.h"
26 static cl::opt<bool> DisableLdStOpti("disable-arm-loadstore-opti", cl::Hidden,
27 cl::desc("Disable load store optimization pass"));
28 static cl::opt<bool> EnableIfConversion("enable-arm-if-conversion", cl::Hidden,
29 cl::desc("Enable if-conversion pass"));
32 // Register the target.
33 RegisterTarget<ARMTargetMachine> X("arm", " ARM");
34 RegisterTarget<ThumbTargetMachine> Y("thumb", " Thumb");
37 /// ThumbTargetMachine - Create an Thumb architecture model.
39 unsigned ThumbTargetMachine::getModuleMatchQuality(const Module &M) {
40 std::string TT = M.getTargetTriple();
41 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "thumb-")
44 return M.getPointerSize() == Module::Pointer32;
47 ThumbTargetMachine::ThumbTargetMachine(const Module &M, const std::string &FS)
48 : ARMTargetMachine(M, FS, true) {
51 /// TargetMachine ctor - Create an ARM architecture model.
53 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS,
55 : Subtarget(M, FS, isThumb),
56 DataLayout(Subtarget.isAPCS_ABI() ?
59 std::string("e-p:32:32-f64:32:32-i64:32:32-"
60 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
61 std::string("e-p:32:32-f64:32:32-i64:32:32")) :
64 std::string("e-p:32:32-f64:64:64-i64:64:64-"
65 "i16:16:32-i8:8:32-i1:8:32-a:0:32") :
66 std::string("e-p:32:32-f64:64:64-i64:64:64"))),
71 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
72 std::string TT = M.getTargetTriple();
73 if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
76 return M.getPointerSize() == Module::Pointer32;
80 const TargetAsmInfo *ARMTargetMachine::createTargetAsmInfo() const {
81 return new ARMTargetAsmInfo(*this);
85 // Pass Pipeline Configuration
86 bool ARMTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
87 PM.add(createARMISelDag(*this));
91 bool ARMTargetMachine::addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
92 if (Fast || !EnableIfConversion || Subtarget.isThumb())
95 PM.add(createIfConverterPass());
99 bool ARMTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
100 // FIXME: temporarily disabling load / store optimization pass for Thumb mode.
101 if (!Fast && !DisableLdStOpti && !Subtarget.isThumb())
102 PM.add(createARMLoadStoreOptimizationPass());
104 PM.add(createARMConstantIslandPass());
108 bool ARMTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
110 // Output assembly language.
111 PM.add(createARMCodePrinterPass(Out, *this));