2002-04-09 05:21:26 +00:00
|
|
|
//===-- Sparc.cpp - General implementation file for the Sparc Target ------===//
|
|
|
|
//
|
|
|
|
// This file contains the code for the Sparc Target that does not fit in any of
|
|
|
|
// the other files in this directory.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-10-22 13:44:23 +00:00
|
|
|
|
2001-09-14 03:47:57 +00:00
|
|
|
#include "SparcInternals.h"
|
2002-10-29 20:47:26 +00:00
|
|
|
#include "llvm/Target/TargetMachineImpls.h"
|
2002-04-07 20:49:59 +00:00
|
|
|
#include "llvm/Function.h"
|
2002-10-28 01:03:43 +00:00
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2002-10-28 00:28:31 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2002-10-28 01:03:43 +00:00
|
|
|
#include "llvm/CodeGen/PreSelection.h"
|
|
|
|
#include "llvm/CodeGen/StackSlots.h"
|
|
|
|
#include "llvm/CodeGen/PeepholeOpts.h"
|
|
|
|
#include "llvm/CodeGen/InstrSelection.h"
|
|
|
|
#include "llvm/CodeGen/InstrScheduling.h"
|
|
|
|
#include "llvm/CodeGen/RegisterAllocation.h"
|
|
|
|
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
|
|
|
#include "llvm/Reoptimizer/Mapping/MappingInfo.h"
|
|
|
|
#include "llvm/Reoptimizer/Mapping/FInfo.h"
|
|
|
|
#include "Support/CommandLine.h"
|
2002-01-20 22:54:45 +00:00
|
|
|
using std::cerr;
|
2001-09-15 00:30:44 +00:00
|
|
|
|
2001-09-19 15:56:23 +00:00
|
|
|
// Build the MachineInstruction Description Array...
|
|
|
|
const MachineInstrDescriptor SparcMachineInstrDesc[] = {
|
|
|
|
#define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
|
|
|
|
NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
|
|
|
|
{ OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
|
|
|
|
NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS },
|
|
|
|
#include "SparcInstr.def"
|
|
|
|
};
|
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.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static cl::opt<bool> DisablePreSelect("nopreselect",
|
|
|
|
cl::desc("Disable preselection pass"));
|
|
|
|
|
|
|
|
static cl::opt<bool> DisableSched("nosched",
|
|
|
|
cl::desc("Disable local scheduling pass"));
|
|
|
|
|
|
|
|
static cl::opt<bool> DisablePeephole("nopeephole",
|
|
|
|
cl::desc("Disable peephole optimization pass"));
|
|
|
|
|
2001-09-18 13:01:29 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2001-09-14 16:56:32 +00:00
|
|
|
// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
|
|
|
|
// that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
|
2001-09-18 13:01:29 +00:00
|
|
|
//----------------------------------------------------------------------------
|
2001-10-15 16:25:28 +00:00
|
|
|
|
2001-09-14 16:56:32 +00:00
|
|
|
TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
|
2001-09-14 03:47:57 +00:00
|
|
|
|
|
|
|
|
2001-10-22 13:44:23 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class UltraSparcFrameInfo
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// Interface to stack frame layout info for the UltraSPARC.
|
2001-11-12 23:26:35 +00:00
|
|
|
// Starting offsets for each area of the stack frame are aligned at
|
|
|
|
// a multiple of getStackFrameSizeAlignment().
|
2001-10-22 13:44:23 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int
|
2002-10-28 00:28:31 +00:00
|
|
|
UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineFunction& ,
|
2001-11-08 04:55:13 +00:00
|
|
|
bool& pos) const
|
2001-10-22 13:44:23 +00:00
|
|
|
{
|
2001-11-08 04:55:13 +00:00
|
|
|
pos = false; // static stack area grows downwards
|
|
|
|
return StaticAreaOffsetFromFP;
|
2001-10-22 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-10-28 00:28:31 +00:00
|
|
|
UltraSparcFrameInfo::getRegSpillAreaOffset(MachineFunction& mcInfo,
|
2001-11-08 04:55:13 +00:00
|
|
|
bool& pos) const
|
2001-10-22 13:44:23 +00:00
|
|
|
{
|
2002-04-25 04:43:45 +00:00
|
|
|
mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
|
|
|
|
|
2001-11-08 04:55:13 +00:00
|
|
|
pos = false; // static stack area grows downwards
|
|
|
|
unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
|
2001-11-12 23:26:35 +00:00
|
|
|
return StaticAreaOffsetFromFP - autoVarsSize;
|
2001-10-22 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-10-28 00:28:31 +00:00
|
|
|
UltraSparcFrameInfo::getTmpAreaOffset(MachineFunction& mcInfo,
|
2001-11-08 04:55:13 +00:00
|
|
|
bool& pos) const
|
2001-10-22 13:44:23 +00:00
|
|
|
{
|
2002-04-25 04:43:45 +00:00
|
|
|
mcInfo.freezeAutomaticVarsArea(); // ensure no more auto vars are added
|
|
|
|
mcInfo.freezeSpillsArea(); // ensure no more spill slots are added
|
|
|
|
|
2001-11-08 04:55:13 +00:00
|
|
|
pos = false; // static stack area grows downwards
|
|
|
|
unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize();
|
|
|
|
unsigned int spillAreaSize = mcInfo.getRegSpillsSize();
|
2001-11-12 23:26:35 +00:00
|
|
|
int offset = autoVarsSize + spillAreaSize;
|
|
|
|
return StaticAreaOffsetFromFP - offset;
|
2001-10-22 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2001-11-08 04:55:13 +00:00
|
|
|
int
|
2002-10-28 00:28:31 +00:00
|
|
|
UltraSparcFrameInfo::getDynamicAreaOffset(MachineFunction& mcInfo,
|
2001-11-08 04:55:13 +00:00
|
|
|
bool& pos) const
|
|
|
|
{
|
2002-03-18 03:08:07 +00:00
|
|
|
// Dynamic stack area grows downwards starting at top of opt-args area.
|
|
|
|
// The opt-args, required-args, and register-save areas are empty except
|
|
|
|
// during calls and traps, so they are shifted downwards on each
|
|
|
|
// dynamic-size alloca.
|
|
|
|
pos = false;
|
2001-11-08 04:55:13 +00:00
|
|
|
unsigned int optArgsSize = mcInfo.getMaxOptionalArgsSize();
|
2002-09-16 15:39:26 +00:00
|
|
|
if (int extra = optArgsSize % getStackFrameSizeAlignment())
|
|
|
|
optArgsSize += (getStackFrameSizeAlignment() - extra);
|
2001-11-12 23:26:35 +00:00
|
|
|
int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP;
|
2002-03-18 03:08:07 +00:00
|
|
|
assert((offset - OFFSET) % getStackFrameSizeAlignment() == 0);
|
2001-11-12 23:26:35 +00:00
|
|
|
return offset;
|
2001-11-08 04:55:13 +00:00
|
|
|
}
|
2001-09-15 00:30:44 +00:00
|
|
|
|
2001-09-14 03:47:57 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class UltraSparcMachine
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// 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 MachineInstrInfo.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2001-09-18 13:01:29 +00:00
|
|
|
UltraSparc::UltraSparc()
|
|
|
|
: TargetMachine("UltraSparc-Native"),
|
2001-11-08 04:55:13 +00:00
|
|
|
schedInfo(*this),
|
|
|
|
regInfo(*this),
|
2001-11-09 02:16:04 +00:00
|
|
|
frameInfo(*this),
|
2002-09-20 00:52:09 +00:00
|
|
|
cacheInfo(*this),
|
|
|
|
optInfo(*this)
|
2001-09-18 13:01:29 +00:00
|
|
|
{
|
2001-09-14 03:47:57 +00:00
|
|
|
optSizeForSubWordData = 4;
|
|
|
|
minMemOpWordSize = 8;
|
|
|
|
maxAtomicMemOpWordSize = 8;
|
|
|
|
}
|
|
|
|
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
// addPassesToEmitAssembly - This method controls the entire code generation
|
|
|
|
// process for the ultra sparc.
|
|
|
|
//
|
|
|
|
void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
|
|
|
|
{
|
|
|
|
// Construct and initialize the MachineFunction object for this fn.
|
2002-10-28 01:12:41 +00:00
|
|
|
PM.add(createMachineCodeConstructionPass(*this));
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
//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));
|
|
|
|
|
|
|
|
// Specialize LLVM code for this target machine and then
|
|
|
|
// run basic dataflow optimizations on LLVM code.
|
|
|
|
if (!DisablePreSelect)
|
|
|
|
{
|
|
|
|
PM.add(createPreSelectionPass(*this));
|
|
|
|
/* PM.add(createReassociatePass()); */
|
|
|
|
PM.add(createLICMPass());
|
|
|
|
PM.add(createGCSEPass());
|
|
|
|
}
|
|
|
|
|
|
|
|
PM.add(createInstructionSelectionPass(*this));
|
|
|
|
|
|
|
|
if (!DisableSched)
|
|
|
|
PM.add(createInstructionSchedulingWithSSAPass(*this));
|
|
|
|
|
|
|
|
PM.add(getRegisterAllocator(*this));
|
|
|
|
|
|
|
|
PM.add(getPrologEpilogInsertionPass());
|
|
|
|
|
|
|
|
if (!DisablePeephole)
|
|
|
|
PM.add(createPeepholeOptsPass(*this));
|
|
|
|
|
|
|
|
PM.add(MappingInfoForFunction(Out));
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
PM.add(getFunctionAsmPrinterPass(Out));
|
2002-10-28 01:12:41 +00:00
|
|
|
PM.add(createMachineCodeDestructionPass()); // Free stuff no longer needed
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
// Emit Module level assembly after all of the functions have been processed.
|
|
|
|
PM.add(getModuleAsmPrinterPass(Out));
|
|
|
|
|
|
|
|
// Emit bytecode to the assembly file into its special section next
|
|
|
|
PM.add(getEmitBytecodeToAsmPass(Out));
|
|
|
|
PM.add(getFunctionInfo(Out));
|
|
|
|
}
|