2006-02-05 05:50:24 +00:00
|
|
|
//===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "SparcTargetMachine.h"
|
|
|
|
#include "Sparc.h"
|
2004-12-11 05:19:04 +00:00
|
|
|
#include "llvm/Assembly/PrintModulePass.h"
|
2004-02-25 19:28:19 +00:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2004-07-11 04:17:10 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2004-07-11 02:48:49 +00:00
|
|
|
#include "llvm/Target/TargetMachineRegistry.h"
|
2004-06-15 20:37:12 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2004-07-04 17:19:21 +00:00
|
|
|
#include <iostream>
|
2004-02-28 19:52:49 +00:00
|
|
|
using namespace llvm;
|
2004-02-25 19:28:19 +00:00
|
|
|
|
2004-07-11 02:48:49 +00:00
|
|
|
namespace {
|
|
|
|
// Register the target.
|
2006-02-05 05:50:24 +00:00
|
|
|
RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
|
2004-07-11 02:48:49 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
/// SparcTargetMachine ctor - Create an ILP32 architecture model
|
2004-02-25 19:28:19 +00:00
|
|
|
///
|
2006-03-23 05:43:16 +00:00
|
|
|
SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &FS)
|
2006-09-03 18:44:02 +00:00
|
|
|
: DataLayout("E-p:32:32"),
|
2006-02-04 06:58:46 +00:00
|
|
|
Subtarget(M, FS), InstrInfo(Subtarget),
|
2005-12-16 06:06:07 +00:00
|
|
|
FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
|
2004-10-09 05:57:01 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
unsigned SparcTargetMachine::getModuleMatchQuality(const Module &M) {
|
2004-12-12 17:40:28 +00:00
|
|
|
std::string TT = M.getTargetTriple();
|
|
|
|
if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
|
|
|
|
return 20;
|
|
|
|
|
2004-10-09 05:57:01 +00:00
|
|
|
if (M.getEndianness() == Module::BigEndian &&
|
|
|
|
M.getPointerSize() == Module::Pointer32)
|
|
|
|
#ifdef __sparc__
|
2006-02-05 05:50:24 +00:00
|
|
|
return 20; // BE/32 ==> Prefer sparc on sparc
|
2004-10-09 05:57:01 +00:00
|
|
|
#else
|
|
|
|
return 5; // BE/32 ==> Prefer ppc elsewhere
|
|
|
|
#endif
|
|
|
|
else if (M.getEndianness() != Module::AnyEndianness ||
|
|
|
|
M.getPointerSize() != Module::AnyPointerSize)
|
|
|
|
return 0; // Match for some other target
|
|
|
|
|
2005-12-16 06:06:07 +00:00
|
|
|
return 0;
|
2004-10-09 05:57:01 +00:00
|
|
|
}
|
|
|
|
|
2005-06-25 02:48:37 +00:00
|
|
|
/// addPassesToEmitFile - Add passes to the specified pass manager
|
2004-02-25 19:28:19 +00:00
|
|
|
/// to implement a static compiler for this target.
|
|
|
|
///
|
2006-02-05 05:50:24 +00:00
|
|
|
bool SparcTargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out,
|
|
|
|
CodeGenFileType FileType,
|
|
|
|
bool Fast) {
|
2005-06-25 02:48:37 +00:00
|
|
|
if (FileType != TargetMachine::AssemblyFile) return true;
|
|
|
|
|
2006-02-09 05:06:36 +00:00
|
|
|
// Run loop strength reduction before anything else.
|
2006-02-09 19:59:55 +00:00
|
|
|
if (!Fast) PM.add(createLoopStrengthReducePass());
|
2006-02-09 05:06:36 +00:00
|
|
|
|
2004-06-15 20:37:12 +00:00
|
|
|
// FIXME: Implement efficient support for garbage collection intrinsics.
|
|
|
|
PM.add(createLowerGCPass());
|
|
|
|
|
|
|
|
// FIXME: implement the invoke/unwind instructions!
|
|
|
|
PM.add(createLowerInvokePass());
|
|
|
|
|
2004-12-11 05:19:04 +00:00
|
|
|
// Print LLVM code input to instruction selector:
|
|
|
|
if (PrintMachineCode)
|
2004-12-11 22:17:07 +00:00
|
|
|
PM.add(new PrintFunctionPass());
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2006-01-23 07:20:15 +00:00
|
|
|
// Make sure that no unreachable blocks are instruction selected.
|
|
|
|
PM.add(createUnreachableBlockEliminationPass());
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
PM.add(createSparcISelDag(*this));
|
2004-02-29 00:27:00 +00:00
|
|
|
|
2004-03-04 19:22:16 +00:00
|
|
|
// Print machine instructions as they were initially generated.
|
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr));
|
2004-02-29 00:27:00 +00:00
|
|
|
|
2004-02-25 19:28:19 +00:00
|
|
|
PM.add(createRegisterAllocator());
|
|
|
|
PM.add(createPrologEpilogCodeInserter());
|
2004-02-29 00:27:00 +00:00
|
|
|
|
2004-03-04 19:22:16 +00:00
|
|
|
// Print machine instructions after register allocation and prolog/epilog
|
|
|
|
// insertion.
|
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr));
|
2004-02-29 00:27:00 +00:00
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
PM.add(createSparcFPMoverPass(*this));
|
2005-12-20 08:00:11 +00:00
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
PM.add(createSparcDelaySlotFillerPass(*this));
|
2004-04-06 23:21:24 +00:00
|
|
|
|
|
|
|
// Print machine instructions after filling delay slots.
|
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr));
|
|
|
|
|
2004-03-04 19:22:16 +00:00
|
|
|
// Output assembly language.
|
2006-02-05 05:50:24 +00:00
|
|
|
PM.add(createSparcCodePrinterPass(Out, *this));
|
2004-03-04 06:00:41 +00:00
|
|
|
|
2004-03-04 19:22:16 +00:00
|
|
|
// Delete the MachineInstrs we generated, since they're no longer needed.
|
2004-02-25 19:28:19 +00:00
|
|
|
PM.add(createMachineCodeDeleter());
|
2004-02-28 20:21:45 +00:00
|
|
|
return false;
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|