2004-02-25 19:28:19 +00:00
|
|
|
//===-- SparcV8TargetMachine.cpp - Define TargetMachine for SparcV8 -------===//
|
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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SparcV8TargetMachine.h"
|
|
|
|
#include "SparcV8.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"
|
2005-12-17 07:47:01 +00:00
|
|
|
#include "llvm/Support/CommandLine.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.
|
2004-07-11 03:27:42 +00:00
|
|
|
RegisterTarget<SparcV8TargetMachine> X("sparcv8"," SPARC V8 (experimental)");
|
2005-12-17 07:47:01 +00:00
|
|
|
|
|
|
|
cl::opt<bool> DisableV8DAGDAG("disable-v8-dag-isel", cl::Hidden,
|
|
|
|
cl::desc("Disable DAG-to-DAG isel for V8"),
|
|
|
|
cl::init(1));
|
2004-07-11 02:48:49 +00:00
|
|
|
}
|
|
|
|
|
2004-02-25 19:28:19 +00:00
|
|
|
/// SparcV8TargetMachine ctor - Create an ILP32 architecture model
|
|
|
|
///
|
|
|
|
SparcV8TargetMachine::SparcV8TargetMachine(const Module &M,
|
2005-09-01 21:38:21 +00:00
|
|
|
IntrinsicLowering *IL,
|
|
|
|
const std::string &FS)
|
2004-12-11 05:19:04 +00:00
|
|
|
: TargetMachine("SparcV8", IL, false, 4, 4),
|
2005-12-16 06:06:07 +00:00
|
|
|
FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) {
|
2004-10-09 05:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SparcV8TargetMachine::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__
|
|
|
|
return 20; // BE/32 ==> Prefer sparcv8 on sparc
|
|
|
|
#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.
|
|
|
|
///
|
2005-06-25 02:48:37 +00:00
|
|
|
bool SparcV8TargetMachine::addPassesToEmitFile(PassManager &PM,
|
|
|
|
std::ostream &Out,
|
2005-11-08 02:11:51 +00:00
|
|
|
CodeGenFileType FileType,
|
|
|
|
bool Fast) {
|
2005-06-25 02:48:37 +00:00
|
|
|
if (FileType != TargetMachine::AssemblyFile) return true;
|
|
|
|
|
2004-06-15 20:37:12 +00:00
|
|
|
// FIXME: Implement efficient support for garbage collection intrinsics.
|
|
|
|
PM.add(createLowerGCPass());
|
|
|
|
|
|
|
|
// Replace malloc and free instructions with library calls.
|
|
|
|
PM.add(createLowerAllocationsPass());
|
2004-06-18 08:46:15 +00:00
|
|
|
|
2004-06-15 20:37:12 +00:00
|
|
|
// FIXME: implement the switch instruction in the instruction selector.
|
|
|
|
PM.add(createLowerSwitchPass());
|
|
|
|
|
|
|
|
// FIXME: implement the invoke/unwind instructions!
|
|
|
|
PM.add(createLowerInvokePass());
|
|
|
|
|
2004-07-02 05:49:11 +00:00
|
|
|
// Make sure that no unreachable blocks are instruction selected.
|
|
|
|
PM.add(createUnreachableBlockEliminationPass());
|
|
|
|
|
2004-12-10 08:39:30 +00:00
|
|
|
// FIXME: implement the select instruction in the instruction selector.
|
|
|
|
PM.add(createLowerSelectPass());
|
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
|
|
|
|
2005-12-17 07:47:01 +00:00
|
|
|
if (DisableV8DAGDAG)
|
|
|
|
PM.add(createSparcV8SimpleInstructionSelector(*this));
|
|
|
|
else
|
|
|
|
PM.add(createSparcV8ISelDag(*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
|
|
|
|
2004-09-29 03:26:27 +00:00
|
|
|
PM.add(createSparcV8FPMoverPass(*this));
|
2004-04-06 23:21:24 +00:00
|
|
|
PM.add(createSparcV8DelaySlotFillerPass(*this));
|
|
|
|
|
|
|
|
// 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.
|
2004-03-04 06:00:41 +00:00
|
|
|
PM.add(createSparcV8CodePrinterPass(Out, *this));
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|