Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 1 | //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "SparcTargetMachine.h" |
| 14 | #include "Sparc.h" |
| 15 | #include "llvm/Assembly/PrintModulePass.h" |
| 16 | #include "llvm/Module.h" |
| 17 | #include "llvm/PassManager.h" |
| 18 | #include "llvm/CodeGen/MachineFunction.h" |
| 19 | #include "llvm/CodeGen/Passes.h" |
| 20 | #include "llvm/Target/TargetOptions.h" |
| 21 | #include "llvm/Target/TargetMachineRegistry.h" |
| 22 | #include "llvm/Transforms/Scalar.h" |
| 23 | #include "llvm/Support/CommandLine.h" |
| 24 | #include <iostream> |
| 25 | using namespace llvm; |
| 26 | |
| 27 | namespace { |
| 28 | // Register the target. |
| 29 | RegisterTarget<SparcTargetMachine> X("sparc", " SPARC"); |
Chris Lattner | c75d5b0 | 2006-02-09 05:06:36 +0000 | [diff] [blame^] | 30 | |
| 31 | cl::opt<bool> EnableLSR("enable-sparc-lsr", cl::Hidden); |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /// SparcTargetMachine ctor - Create an ILP32 architecture model |
| 35 | /// |
| 36 | SparcTargetMachine::SparcTargetMachine(const Module &M, IntrinsicLowering *IL, |
| 37 | const std::string &FS) |
| 38 | : TargetMachine("Sparc", IL, false, 4, 4), |
| 39 | Subtarget(M, FS), InstrInfo(Subtarget), |
| 40 | FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) { |
| 41 | } |
| 42 | |
| 43 | unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) { |
| 44 | std::string TT = M.getTargetTriple(); |
| 45 | if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-") |
| 46 | return 20; |
| 47 | |
| 48 | if (M.getEndianness() == Module::BigEndian && |
| 49 | M.getPointerSize() == Module::Pointer32) |
| 50 | #ifdef __sparc__ |
| 51 | return 20; // BE/32 ==> Prefer sparc on sparc |
| 52 | #else |
| 53 | return 5; // BE/32 ==> Prefer ppc elsewhere |
| 54 | #endif |
| 55 | else if (M.getEndianness() != Module::AnyEndianness || |
| 56 | M.getPointerSize() != Module::AnyPointerSize) |
| 57 | return 0; // Match for some other target |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | /// addPassesToEmitFile - Add passes to the specified pass manager |
| 63 | /// to implement a static compiler for this target. |
| 64 | /// |
| 65 | bool SparcTargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out, |
| 66 | CodeGenFileType FileType, |
| 67 | bool Fast) { |
| 68 | if (FileType != TargetMachine::AssemblyFile) return true; |
| 69 | |
Chris Lattner | c75d5b0 | 2006-02-09 05:06:36 +0000 | [diff] [blame^] | 70 | // Run loop strength reduction before anything else. |
| 71 | if (EnableLSR && !Fast) PM.add(createLoopStrengthReducePass()); |
| 72 | |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 73 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 74 | PM.add(createLowerGCPass()); |
| 75 | |
| 76 | // FIXME: implement the invoke/unwind instructions! |
| 77 | PM.add(createLowerInvokePass()); |
| 78 | |
| 79 | // FIXME: implement the switch instruction in the instruction selector. |
| 80 | PM.add(createLowerSwitchPass()); |
Chris Lattner | c75d5b0 | 2006-02-09 05:06:36 +0000 | [diff] [blame^] | 81 | |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 82 | // Print LLVM code input to instruction selector: |
| 83 | if (PrintMachineCode) |
| 84 | PM.add(new PrintFunctionPass()); |
| 85 | |
| 86 | // Make sure that no unreachable blocks are instruction selected. |
| 87 | PM.add(createUnreachableBlockEliminationPass()); |
| 88 | |
| 89 | PM.add(createSparcISelDag(*this)); |
| 90 | |
| 91 | // Print machine instructions as they were initially generated. |
| 92 | if (PrintMachineCode) |
| 93 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 94 | |
| 95 | PM.add(createRegisterAllocator()); |
| 96 | PM.add(createPrologEpilogCodeInserter()); |
| 97 | |
| 98 | // Print machine instructions after register allocation and prolog/epilog |
| 99 | // insertion. |
| 100 | if (PrintMachineCode) |
| 101 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 102 | |
| 103 | PM.add(createSparcFPMoverPass(*this)); |
| 104 | |
| 105 | PM.add(createSparcDelaySlotFillerPass(*this)); |
| 106 | |
| 107 | // Print machine instructions after filling delay slots. |
| 108 | if (PrintMachineCode) |
| 109 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 110 | |
| 111 | // Output assembly language. |
| 112 | PM.add(createSparcCodePrinterPass(Out, *this)); |
| 113 | |
| 114 | // Delete the MachineInstrs we generated, since they're no longer needed. |
| 115 | PM.add(createMachineCodeDeleter()); |
| 116 | return false; |
| 117 | } |
| 118 | |