blob: 477e9544140cb3793c9759e9474a79744508bbf4 [file] [log] [blame]
Chris Lattner158e1f52006-02-05 05:50:24 +00001//===-- 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 Lattner158e1f52006-02-05 05:50:24 +000015#include "llvm/Module.h"
16#include "llvm/PassManager.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000017#include "llvm/Target/TargetMachineRegistry.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000018#include <iostream>
19using namespace llvm;
20
21namespace {
22 // Register the target.
23 RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
24}
25
26/// SparcTargetMachine ctor - Create an ILP32 architecture model
27///
Chris Lattner6f95ab72006-03-23 05:43:16 +000028SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
Chris Lattner0fc45412006-09-03 18:44:02 +000029 : DataLayout("E-p:32:32"),
Chris Lattner158e1f52006-02-05 05:50:24 +000030 Subtarget(M, FS), InstrInfo(Subtarget),
31 FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
32}
33
34unsigned 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 Lattner12e97302006-09-04 04:14:57 +000053bool SparcTargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
Chris Lattner158e1f52006-02-05 05:50:24 +000054 PM.add(createSparcISelDag(*this));
Chris Lattner158e1f52006-02-05 05:50:24 +000055 return false;
56}
57
Chris Lattner12e97302006-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}