2004-04-25 07:04:49 +00:00
|
|
|
//===-- SparcV9TargetMachine.cpp - SparcV9 Target Machine Implementation --===//
|
2003-10-20 19:43:21 +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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2003-12-17 22:04:00 +00:00
|
|
|
//
|
|
|
|
// Primary interface to machine description for the UltraSPARC. Primarily just
|
|
|
|
// initializes machine-dependent parameters in class TargetMachine, and creates
|
|
|
|
// machine-dependent subclasses for classes such as TargetInstrInfo.
|
|
|
|
//
|
2002-04-09 05:21:26 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-22 13:44:23 +00:00
|
|
|
|
2002-04-07 20:49:59 +00:00
|
|
|
#include "llvm/Function.h"
|
2002-10-28 01:03:43 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2003-08-13 02:38:16 +00:00
|
|
|
#include "llvm/Assembly/PrintModulePass.h"
|
2002-10-28 01:03:43 +00:00
|
|
|
#include "llvm/CodeGen/InstrScheduling.h"
|
2004-06-20 07:49:54 +00:00
|
|
|
#include "llvm/CodeGen/IntrinsicLowering.h"
|
2003-12-17 22:04:00 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2003-09-30 22:24:00 +00:00
|
|
|
#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"
|
2003-12-17 22:04:00 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "MappingInfo.h"
|
2004-08-16 21:55:02 +00:00
|
|
|
#include "MachineFunctionInfo.h"
|
|
|
|
#include "MachineCodeForInstruction.h"
|
2004-02-25 18:44:15 +00:00
|
|
|
#include "SparcV9Internals.h"
|
|
|
|
#include "SparcV9TargetMachine.h"
|
2004-08-04 07:30:04 +00:00
|
|
|
#include "SparcV9BurgISel.h"
|
2002-10-28 01:03:43 +00:00
|
|
|
#include "Support/CommandLine.h"
|
2003-12-17 22:04:00 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2002-12-03 05:41:54 +00:00
|
|
|
static const unsigned ImplicitRegUseList[] = { 0 }; /* not used yet */
|
2001-09-19 15:56:23 +00:00
|
|
|
// Build the MachineInstruction Description Array...
|
2004-02-25 18:44:15 +00:00
|
|
|
const TargetInstrDescriptor llvm::SparcV9MachineInstrDesc[] = {
|
2001-09-19 15:56:23 +00:00
|
|
|
#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
|
|
|
|
NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
|
|
|
|
{ OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
|
2002-12-03 05:41:54 +00:00
|
|
|
NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS, 0, \
|
|
|
|
ImplicitRegUseList, ImplicitRegUseList },
|
2004-02-25 18:44:15 +00:00
|
|
|
#include "SparcV9Instr.def"
|
2001-09-19 15:56:23 +00:00
|
|
|
};
|
2001-09-18 13:01:29 +00:00
|
|
|
|
2002-10-28 01:03:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Command line options to control choice of code generation passes.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
namespace {
|
|
|
|
cl::opt<bool> DisableSched("disable-sched",
|
|
|
|
cl::desc("Disable local scheduling pass"));
|
2002-10-28 01:03:43 +00:00
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
cl::opt<bool> DisablePeephole("disable-peephole",
|
2002-10-28 01:03:43 +00:00
|
|
|
cl::desc("Disable peephole optimization pass"));
|
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
cl::opt<bool> EmitMappingInfo("enable-maps",
|
|
|
|
cl::desc("Emit LLVM-to-MachineCode mapping info to assembly"));
|
2003-06-18 21:14:23 +00:00
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
cl::opt<bool> DisableStrip("disable-strip",
|
|
|
|
cl::desc("Do not strip the LLVM bytecode in executable"));
|
2004-07-11 02:48:49 +00:00
|
|
|
|
|
|
|
// Register the target.
|
2004-07-11 03:27:42 +00:00
|
|
|
RegisterTarget<SparcV9TargetMachine> X("sparcv9", " SPARC V9");
|
2004-07-11 02:48:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SparcV9TargetMachine::getJITMatchQuality() {
|
|
|
|
#if defined(sparc) || defined(__sparc__) || defined(__sparcv9)
|
|
|
|
return 10;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SparcV9TargetMachine::getModuleMatchQuality(const Module &M) {
|
|
|
|
if (M.getEndianness() == Module::BigEndian &&
|
|
|
|
M.getPointerSize() == Module::Pointer64)
|
|
|
|
return 10; // Direct match
|
|
|
|
else if (M.getEndianness() != Module::AnyEndianness ||
|
|
|
|
M.getPointerSize() != Module::AnyPointerSize)
|
|
|
|
return 0; // Match for some other target
|
|
|
|
|
|
|
|
return getJITMatchQuality()/2;
|
2003-11-13 00:16:28 +00:00
|
|
|
}
|
2003-06-18 21:14:23 +00:00
|
|
|
|
2003-12-20 09:17:40 +00:00
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
// Code generation/destruction passes
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class ConstructMachineFunction : public FunctionPass {
|
|
|
|
TargetMachine &Target;
|
|
|
|
public:
|
|
|
|
ConstructMachineFunction(TargetMachine &T) : Target(T) {}
|
|
|
|
|
|
|
|
const char *getPassName() const {
|
|
|
|
return "ConstructMachineFunction";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnFunction(Function &F) {
|
2004-08-18 18:13:37 +00:00
|
|
|
MachineFunction::construct(&F, Target).getInfo<SparcV9FunctionInfo>()->CalculateArgSize();
|
2003-12-20 09:17:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DestroyMachineFunction : public FunctionPass {
|
2004-02-27 21:01:14 +00:00
|
|
|
const char *getPassName() const { return "DestroyMachineFunction"; }
|
2003-12-20 09:17:40 +00:00
|
|
|
|
|
|
|
static void freeMachineCode(Instruction &I) {
|
|
|
|
MachineCodeForInstruction::destroy(&I);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnFunction(Function &F) {
|
|
|
|
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
|
|
|
|
for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I)
|
|
|
|
MachineCodeForInstruction::get(I).dropAllReferences();
|
|
|
|
|
|
|
|
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
|
|
|
|
for_each(FI->begin(), FI->end(), freeMachineCode);
|
|
|
|
|
2003-12-22 03:47:58 +00:00
|
|
|
MachineFunction::destruct(&F);
|
2003-12-20 09:17:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
FunctionPass *createMachineCodeConstructionPass(TargetMachine &Target) {
|
|
|
|
return new ConstructMachineFunction(Target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-25 18:44:15 +00:00
|
|
|
FunctionPass *llvm::createSparcV9MachineCodeDestructionPass() {
|
2003-12-20 09:17:40 +00:00
|
|
|
return new DestroyMachineFunction();
|
|
|
|
}
|
|
|
|
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2004-07-11 02:48:49 +00:00
|
|
|
SparcV9TargetMachine::SparcV9TargetMachine(const Module &M,
|
|
|
|
IntrinsicLowering *il)
|
2004-02-25 18:44:15 +00:00
|
|
|
: TargetMachine("UltraSparcV9-Native", il, false),
|
2001-11-08 04:55:13 +00:00
|
|
|
schedInfo(*this),
|
|
|
|
regInfo(*this),
|
2001-11-09 02:16:04 +00:00
|
|
|
frameInfo(*this),
|
2003-12-28 21:23:38 +00:00
|
|
|
jitInfo(*this) {
|
2001-09-14 03:47:57 +00:00
|
|
|
}
|
|
|
|
|
2004-02-09 23:18:42 +00:00
|
|
|
/// addPassesToEmitAssembly - This method controls the entire code generation
|
|
|
|
/// process for the ultra sparc.
|
|
|
|
///
|
2003-12-17 22:04:00 +00:00
|
|
|
bool
|
2004-02-25 18:44:15 +00:00
|
|
|
SparcV9TargetMachine::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
|
2002-10-28 01:03:43 +00:00
|
|
|
{
|
2004-05-23 21:23:35 +00:00
|
|
|
// FIXME: Implement efficient support for garbage collection intrinsics.
|
|
|
|
PM.add(createLowerGCPass());
|
|
|
|
|
2003-06-18 21:14:23 +00:00
|
|
|
// Replace malloc and free instructions with library calls.
|
|
|
|
PM.add(createLowerAllocationsPass());
|
|
|
|
|
2003-04-23 16:24:55 +00:00
|
|
|
// FIXME: implement the switch instruction in the instruction selector.
|
|
|
|
PM.add(createLowerSwitchPass());
|
2003-10-05 19:16:09 +00:00
|
|
|
|
|
|
|
// FIXME: implement the invoke/unwind instructions!
|
|
|
|
PM.add(createLowerInvokePass());
|
2003-06-18 21:14:23 +00:00
|
|
|
|
2003-08-01 15:53:24 +00:00
|
|
|
// decompose multi-dimensional array references into single-dim refs
|
|
|
|
PM.add(createDecomposeMultiDimRefsPass());
|
2002-10-28 01:03:43 +00:00
|
|
|
|
2004-04-02 17:52:40 +00:00
|
|
|
// Lower LLVM code to the form expected by the SPARCv9 instruction selector.
|
2003-11-07 20:33:25 +00:00
|
|
|
PM.add(createPreSelectionPass(*this));
|
2004-04-02 17:52:40 +00:00
|
|
|
PM.add(createLowerSelectPass());
|
|
|
|
|
|
|
|
// Run basic LLVM dataflow optimizations, to clean up after pre-selection.
|
2003-11-07 20:33:25 +00:00
|
|
|
PM.add(createReassociatePass());
|
|
|
|
PM.add(createLICMPass());
|
|
|
|
PM.add(createGCSEPass());
|
|
|
|
|
2004-05-28 19:33:59 +00:00
|
|
|
// If the user's trying to read the generated code, they'll need to see the
|
|
|
|
// transformed input.
|
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(new PrintModulePass());
|
|
|
|
|
2004-04-02 17:52:40 +00:00
|
|
|
// Construct and initialize the MachineFunction object for this fn.
|
|
|
|
PM.add(createMachineCodeConstructionPass(*this));
|
|
|
|
|
|
|
|
// Insert empty stackslots in the stack frame of each function
|
|
|
|
// so %fp+offset-8 and %fp+offset-16 are empty slots now!
|
|
|
|
PM.add(createStackSlotsPass(*this));
|
|
|
|
|
2004-08-04 07:30:04 +00:00
|
|
|
PM.add(createSparcV9BurgInstSelector(*this));
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
if (!DisableSched)
|
|
|
|
PM.add(createInstructionSchedulingWithSSAPass(*this));
|
|
|
|
|
2004-03-12 21:19:08 +00:00
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "Before reg alloc:\n"));
|
|
|
|
|
2002-10-28 01:03:43 +00:00
|
|
|
PM.add(getRegisterAllocator(*this));
|
2004-03-04 19:16:23 +00:00
|
|
|
|
|
|
|
if (PrintMachineCode)
|
2004-03-12 21:19:08 +00:00
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "After reg alloc:\n"));
|
2004-03-04 19:16:23 +00:00
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
PM.add(createPrologEpilogInsertionPass());
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
if (!DisablePeephole)
|
|
|
|
PM.add(createPeepholeOptsPass(*this));
|
|
|
|
|
2004-06-14 05:05:45 +00:00
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "Final code:\n"));
|
|
|
|
|
2004-06-03 05:03:01 +00:00
|
|
|
if (EmitMappingInfo) {
|
|
|
|
PM.add(createInternalGlobalMapperPass());
|
|
|
|
PM.add(getMappingInfoAsmPrinterPass(Out));
|
|
|
|
}
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
// Output assembly language to the .s file. Assembly emission is split into
|
|
|
|
// two parts: Function output and Global value output. This is because
|
|
|
|
// function output is pipelined with all of the rest of code generation stuff,
|
|
|
|
// allowing machine code representations for functions to be free'd after the
|
|
|
|
// function has been emitted.
|
2003-11-13 00:16:28 +00:00
|
|
|
PM.add(createAsmPrinterPass(Out, *this));
|
2004-02-27 21:15:40 +00:00
|
|
|
|
|
|
|
// Free machine-code IR which is no longer needed:
|
2004-03-01 15:28:27 +00:00
|
|
|
PM.add(createSparcV9MachineCodeDestructionPass());
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
// Emit bytecode to the assembly file into its special section next
|
2004-04-02 17:52:40 +00:00
|
|
|
if (EmitMappingInfo) {
|
|
|
|
// Strip all of the symbols from the bytecode so that it will be smaller...
|
|
|
|
if (!DisableStrip)
|
|
|
|
PM.add(createSymbolStrippingPass());
|
2003-11-13 00:16:28 +00:00
|
|
|
PM.add(createBytecodeAsmPrinterPass(Out));
|
2004-04-02 17:52:40 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 21:12:46 +00:00
|
|
|
return false;
|
2002-10-28 01:03:43 +00:00
|
|
|
}
|
2003-05-27 22:24:48 +00:00
|
|
|
|
2004-02-09 23:18:42 +00:00
|
|
|
/// addPassesToJITCompile - This method controls the JIT method of code
|
2004-02-25 18:44:15 +00:00
|
|
|
/// generation for the UltraSparcV9.
|
2004-02-09 23:18:42 +00:00
|
|
|
///
|
2004-02-25 18:44:15 +00:00
|
|
|
void SparcV9JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
|
2004-05-23 21:23:35 +00:00
|
|
|
// FIXME: Implement efficient support for garbage collection intrinsics.
|
|
|
|
PM.add(createLowerGCPass());
|
|
|
|
|
2003-06-06 07:11:16 +00:00
|
|
|
// Replace malloc and free instructions with library calls.
|
|
|
|
PM.add(createLowerAllocationsPass());
|
2004-04-02 17:52:40 +00:00
|
|
|
|
2003-05-27 22:24:48 +00:00
|
|
|
// FIXME: implement the switch instruction in the instruction selector.
|
|
|
|
PM.add(createLowerSwitchPass());
|
|
|
|
|
2003-10-05 19:16:09 +00:00
|
|
|
// FIXME: implement the invoke/unwind instructions!
|
|
|
|
PM.add(createLowerInvokePass());
|
2004-04-02 17:52:40 +00:00
|
|
|
|
2003-08-06 23:06:21 +00:00
|
|
|
// decompose multi-dimensional array references into single-dim refs
|
|
|
|
PM.add(createDecomposeMultiDimRefsPass());
|
2003-05-27 22:24:48 +00:00
|
|
|
|
2004-04-02 17:52:40 +00:00
|
|
|
// Lower LLVM code to the form expected by the SPARCv9 instruction selector.
|
2003-12-20 01:22:19 +00:00
|
|
|
PM.add(createPreSelectionPass(TM));
|
2004-04-02 17:52:40 +00:00
|
|
|
PM.add(createLowerSelectPass());
|
|
|
|
|
|
|
|
// Run basic LLVM dataflow optimizations, to clean up after pre-selection.
|
2003-11-07 20:33:25 +00:00
|
|
|
PM.add(createReassociatePass());
|
2003-11-08 00:01:39 +00:00
|
|
|
// FIXME: these passes crash the FunctionPassManager when being added...
|
|
|
|
//PM.add(createLICMPass());
|
|
|
|
//PM.add(createGCSEPass());
|
2003-11-07 20:33:25 +00:00
|
|
|
|
2004-06-14 05:05:45 +00:00
|
|
|
// If the user's trying to read the generated code, they'll need to see the
|
|
|
|
// transformed input.
|
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(new PrintFunctionPass());
|
|
|
|
|
2004-04-02 17:52:40 +00:00
|
|
|
// Construct and initialize the MachineFunction object for this fn.
|
|
|
|
PM.add(createMachineCodeConstructionPass(TM));
|
|
|
|
|
2004-08-04 07:30:04 +00:00
|
|
|
PM.add(createSparcV9BurgInstSelector(TM));
|
2003-05-27 22:24:48 +00:00
|
|
|
|
2004-04-02 17:52:40 +00:00
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "Before reg alloc:\n"));
|
|
|
|
|
2003-12-20 01:22:19 +00:00
|
|
|
PM.add(getRegisterAllocator(TM));
|
2004-04-02 17:52:40 +00:00
|
|
|
|
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "After reg alloc:\n"));
|
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
PM.add(createPrologEpilogInsertionPass());
|
2003-05-27 22:24:48 +00:00
|
|
|
|
2003-05-30 20:00:13 +00:00
|
|
|
if (!DisablePeephole)
|
2003-12-20 01:22:19 +00:00
|
|
|
PM.add(createPeepholeOptsPass(TM));
|
2004-06-14 05:05:45 +00:00
|
|
|
|
|
|
|
if (PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "Final code:\n"));
|
2003-05-27 22:24:48 +00:00
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|