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" |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 15 | #include "llvm/Module.h" |
| 16 | #include "llvm/PassManager.h" |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetMachineRegistry.h" |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 18 | #include <iostream> |
| 19 | using namespace llvm; |
| 20 | |
| 21 | namespace { |
| 22 | // Register the target. |
| 23 | RegisterTarget<SparcTargetMachine> X("sparc", " SPARC"); |
| 24 | } |
| 25 | |
| 26 | /// SparcTargetMachine ctor - Create an ILP32 architecture model |
| 27 | /// |
Chris Lattner | 6f95ab7 | 2006-03-23 05:43:16 +0000 | [diff] [blame] | 28 | SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS) |
Chris Lattner | 0fc4541 | 2006-09-03 18:44:02 +0000 | [diff] [blame] | 29 | : DataLayout("E-p:32:32"), |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 30 | Subtarget(M, FS), InstrInfo(Subtarget), |
| 31 | FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) { |
| 32 | } |
| 33 | |
| 34 | unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) { |
| 35 | std::string TT = M.getTargetTriple(); |
| 36 | if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-") |
| 37 | return 20; |
| 38 | |
| 39 | if (M.getEndianness() == Module::BigEndian && |
| 40 | M.getPointerSize() == Module::Pointer32) |
| 41 | #ifdef __sparc__ |
| 42 | return 20; // BE/32 ==> Prefer sparc on sparc |
| 43 | #else |
| 44 | return 5; // BE/32 ==> Prefer ppc elsewhere |
| 45 | #endif |
| 46 | else if (M.getEndianness() != Module::AnyEndianness || |
| 47 | M.getPointerSize() != Module::AnyPointerSize) |
| 48 | return 0; // Match for some other target |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame^] | 53 | bool SparcTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) { |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 54 | PM.add(createSparcISelDag(*this)); |
Chris Lattner | 158e1f5 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 55 | return false; |
| 56 | } |
| 57 | |
Chris Lattner | 12e9730 | 2006-09-04 04:14:57 +0000 | [diff] [blame^] | 58 | /// addPreEmitPass - This pass may be implemented by targets that want to run |
| 59 | /// passes immediately before machine code is emitted. This should return |
| 60 | /// true if -print-machineinstrs should print out the code after the passes. |
| 61 | bool SparcTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) { |
| 62 | PM.add(createSparcFPMoverPass(*this)); |
| 63 | PM.add(createSparcDelaySlotFillerPass(*this)); |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | bool SparcTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, |
| 68 | std::ostream &Out) { |
| 69 | // Output assembly language. |
| 70 | PM.add(createSparcCodePrinterPass(Out, *this)); |
| 71 | return false; |
| 72 | } |