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