blob: f4824da71eb7b593dc11b582dd3ee34b18bab008 [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"
15#include "ARM.h"
16#include "llvm/Assembly/PrintModulePass.h"
17#include "llvm/Module.h"
18#include "llvm/PassManager.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/Passes.h"
21#include "llvm/Target/TargetOptions.h"
22#include "llvm/Target/TargetMachineRegistry.h"
23#include "llvm/Transforms/Scalar.h"
24#include <iostream>
25using namespace llvm;
26
27namespace {
28 // Register the target.
29 RegisterTarget<ARMTargetMachine> X("arm", " ARM");
30}
31
32/// TargetMachine ctor - Create an ILP32 architecture model
33///
34ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS)
Chris Lattner1790d442006-06-16 18:22:52 +000035 : TargetMachine("ARM"), DataLayout("E-p:32:32"),
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000036 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
37}
38
39unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) {
40 std::string TT = M.getTargetTriple();
41 if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-")
42 return 20;
43
44 if (M.getPointerSize() == Module::Pointer32)
45 return 1;
46 else
47 return 0;
48}
49
50/// addPassesToEmitFile - Add passes to the specified pass manager
51/// to implement a static compiler for this target.
52///
53bool ARMTargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out,
54 CodeGenFileType FileType,
55 bool Fast) {
56 if (FileType != TargetMachine::AssemblyFile)
57 return true;
58
59 // Run loop strength reduction before anything else.
60 if (!Fast)
61 PM.add(createLoopStrengthReducePass());
62
63 // FIXME: Implement efficient support for garbage collection intrinsics.
64 PM.add(createLowerGCPass());
65
66 // FIXME: implement the invoke/unwind instructions!
67 PM.add(createLowerInvokePass());
68
69 // Print LLVM code input to instruction selector:
70 if (PrintMachineCode)
71 PM.add(new PrintFunctionPass());
72
73 // Make sure that no unreachable blocks are instruction selected.
74 PM.add(createUnreachableBlockEliminationPass());
75
76 PM.add(createARMISelDag(*this));
77
78 // Print machine instructions as they were initially generated.
79 if (PrintMachineCode)
80 PM.add(createMachineFunctionPrinterPass(&std::cerr));
81
82 PM.add(createRegisterAllocator());
83 PM.add(createPrologEpilogCodeInserter());
84
85 // Print machine instructions after register allocation and prolog/epilog
86 // insertion.
87 if (PrintMachineCode)
88 PM.add(createMachineFunctionPrinterPass(&std::cerr));
89
90 // Output assembly language.
91 PM.add(createARMCodePrinterPass(Out, *this));
92
93 // Delete the MachineInstrs we generated, since they're no longer needed.
94 PM.add(createMachineCodeDeleter());
95 return false;
96}
97