blob: 477e9544140cb3793c9759e9474a79744508bbf4 [file] [log] [blame]
Chris Lattner7c90f732006-02-05 05:50:24 +00001//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Brian Gaekee785e532004-02-25 19:28:19 +00003// 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.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Brian Gaekee785e532004-02-25 19:28:19 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00009//
Brian Gaekee785e532004-02-25 19:28:19 +000010//
11//===----------------------------------------------------------------------===//
12
Chris Lattner7c90f732006-02-05 05:50:24 +000013#include "SparcTargetMachine.h"
14#include "Sparc.h"
Brian Gaekee785e532004-02-25 19:28:19 +000015#include "llvm/Module.h"
16#include "llvm/PassManager.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000017#include "llvm/Target/TargetMachineRegistry.h"
Chris Lattner38343f62004-07-04 17:19:21 +000018#include <iostream>
Chris Lattner8d8a6bc2004-02-28 19:52:49 +000019using namespace llvm;
Brian Gaekee785e532004-02-25 19:28:19 +000020
Chris Lattnerd36c9702004-07-11 02:48:49 +000021namespace {
22 // Register the target.
Chris Lattner7c90f732006-02-05 05:50:24 +000023 RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
Chris Lattnerd36c9702004-07-11 02:48:49 +000024}
25
Chris Lattner7c90f732006-02-05 05:50:24 +000026/// SparcTargetMachine ctor - Create an ILP32 architecture model
Brian Gaekee785e532004-02-25 19:28:19 +000027///
Chris Lattnerbc641b92006-03-23 05:43:16 +000028SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Chris Lattnerc4fa3862006-09-03 18:44:02 +000029 : DataLayout("E-p:32:32"),
Chris Lattner69d39092006-02-04 06:58:46 +000030 Subtarget(M, FS), InstrInfo(Subtarget),
Chris Lattner03a83c92005-12-16 06:06:07 +000031 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
Brian Gaeke0e2d4662004-10-09 05:57:01 +000032}
33
Chris Lattner7c90f732006-02-05 05:50:24 +000034unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
Chris Lattner3ea78c42004-12-12 17:40:28 +000035 std::string TT = M.getTargetTriple();
36 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
37 return 20;
38
Brian Gaeke0e2d4662004-10-09 05:57:01 +000039 if (M.getEndianness() == Module::BigEndian &&
40 M.getPointerSize() == Module::Pointer32)
41#ifdef __sparc__
Chris Lattner7c90f732006-02-05 05:50:24 +000042 return 20; // BE/32 ==> Prefer sparc on sparc
Brian Gaeke0e2d4662004-10-09 05:57:01 +000043#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
Chris Lattner03a83c92005-12-16 06:06:07 +000050 return 0;
Brian Gaeke0e2d4662004-10-09 05:57:01 +000051}
52
Chris Lattner1911fd42006-09-04 04:14:57 +000053bool SparcTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
Chris Lattner7c90f732006-02-05 05:50:24 +000054 PM.add(createSparcISelDag(*this));
Chris Lattner9ff6ba12004-02-28 20:21:45 +000055 return false;
Brian Gaekee785e532004-02-25 19:28:19 +000056}
57
Chris Lattner1911fd42006-09-04 04:14:57 +000058/// 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.
61bool SparcTargetMachine::addPreEmitPass(FunctionPassManager &PM, bool Fast) {
62 PM.add(createSparcFPMoverPass(*this));
63 PM.add(createSparcDelaySlotFillerPass(*this));
64 return true;
65}
66
67bool SparcTargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
68 std::ostream &Out) {
69 // Output assembly language.
70 PM.add(createSparcCodePrinterPass(Out, *this));
71 return false;
72}