LLVM API Documentation
00001 //===-- ARMTargetMachine.cpp - Define TargetMachine for ARM ---------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the "Instituto Nokia de Tecnologia" and 00006 // is distributed under the University of Illinois Open Source 00007 // License. See LICENSE.TXT for details. 00008 // 00009 //===----------------------------------------------------------------------===// 00010 // 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "ARMTargetMachine.h" 00015 #include "ARM.h" 00016 #include "llvm/Assembly/PrintModulePass.h" 00017 #include "llvm/Module.h" 00018 #include "llvm/PassManager.h" 00019 #include "llvm/CodeGen/MachineFunction.h" 00020 #include "llvm/CodeGen/Passes.h" 00021 #include "llvm/Target/TargetOptions.h" 00022 #include "llvm/Target/TargetMachineRegistry.h" 00023 #include "llvm/Transforms/Scalar.h" 00024 #include <iostream> 00025 using namespace llvm; 00026 00027 namespace { 00028 // Register the target. 00029 RegisterTarget<ARMTargetMachine> X("arm", " ARM"); 00030 } 00031 00032 /// TargetMachine ctor - Create an ILP32 architecture model 00033 /// 00034 ARMTargetMachine::ARMTargetMachine(const Module &M, const std::string &FS) 00035 : TargetMachine("ARM"), DataLayout("E-p:32:32"), 00036 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) { 00037 } 00038 00039 unsigned ARMTargetMachine::getModuleMatchQuality(const Module &M) { 00040 std::string TT = M.getTargetTriple(); 00041 if (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "arm-") 00042 return 20; 00043 00044 if (M.getPointerSize() == Module::Pointer32) 00045 return 1; 00046 else 00047 return 0; 00048 } 00049 00050 /// addPassesToEmitFile - Add passes to the specified pass manager 00051 /// to implement a static compiler for this target. 00052 /// 00053 bool ARMTargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out, 00054 CodeGenFileType FileType, 00055 bool Fast) { 00056 if (FileType != TargetMachine::AssemblyFile) 00057 return true; 00058 00059 // Run loop strength reduction before anything else. 00060 if (!Fast) 00061 PM.add(createLoopStrengthReducePass()); 00062 00063 // FIXME: Implement efficient support for garbage collection intrinsics. 00064 PM.add(createLowerGCPass()); 00065 00066 // FIXME: implement the invoke/unwind instructions! 00067 PM.add(createLowerInvokePass()); 00068 00069 // Print LLVM code input to instruction selector: 00070 if (PrintMachineCode) 00071 PM.add(new PrintFunctionPass()); 00072 00073 // Make sure that no unreachable blocks are instruction selected. 00074 PM.add(createUnreachableBlockEliminationPass()); 00075 00076 PM.add(createARMISelDag(*this)); 00077 00078 // Print machine instructions as they were initially generated. 00079 if (PrintMachineCode) 00080 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00081 00082 PM.add(createRegisterAllocator()); 00083 PM.add(createPrologEpilogCodeInserter()); 00084 00085 // Print machine instructions after register allocation and prolog/epilog 00086 // insertion. 00087 if (PrintMachineCode) 00088 PM.add(createMachineFunctionPrinterPass(&std::cerr)); 00089 00090 // Output assembly language. 00091 PM.add(createARMCodePrinterPass(Out, *this)); 00092 00093 // Delete the MachineInstrs we generated, since they're no longer needed. 00094 PM.add(createMachineCodeDeleter()); 00095 return false; 00096 } 00097