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