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