2002-04-09 05:21:26 +00:00
|
|
|
//===-- Sparc.cpp - General implementation file for the Sparc Target ------===//
|
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/InstrSelection.h"
|
|
|
|
#include "llvm/CodeGen/InstrScheduling.h"
|
2003-12-17 22:04:00 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionInfo.h"
|
2002-10-28 01:03:43 +00:00
|
|
|
#include "llvm/CodeGen/MachineCodeForInstruction.h"
|
2003-09-30 22:24:00 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2003-08-13 02:38:16 +00:00
|
|
|
#include "llvm/Target/TargetMachineImpls.h"
|
2003-12-17 22:04:00 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "MappingInfo.h"
|
|
|
|
#include "SparcInternals.h"
|
|
|
|
#include "SparcTargetMachine.h"
|
2002-10-28 01:03:43 +00:00
|
|
|
#include "Support/CommandLine.h"
|
2001-09-15 00:30:44 +00:00
|
|
|
|
2003-12-17 22:04:00 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
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...
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrDescriptor SparcMachineInstrDesc[] = {
|
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 },
|
2001-09-19 15:56:23 +00:00
|
|
|
#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.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
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"));
|
2003-08-12 15:51:02 +00:00
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
cl::opt<bool> DumpInput("dump-input",
|
|
|
|
cl::desc("Print bytecode before code generation"),
|
|
|
|
cl::Hidden);
|
|
|
|
}
|
2003-06-18 21:14:23 +00:00
|
|
|
|
2003-12-17 22:04:00 +00:00
|
|
|
} // End llvm namespace
|
2001-09-14 03:47:57 +00:00
|
|
|
|
2003-12-17 22:04:00 +00:00
|
|
|
SparcTargetMachine::SparcTargetMachine()
|
2003-04-26 20:11:09 +00:00
|
|
|
: TargetMachine("UltraSparc-Native", false),
|
2001-11-08 04:55:13 +00:00
|
|
|
schedInfo(*this),
|
|
|
|
regInfo(*this),
|
2001-11-09 02:16:04 +00:00
|
|
|
frameInfo(*this),
|
2003-09-01 20:40:59 +00:00
|
|
|
cacheInfo(*this) {
|
2001-09-14 03:47:57 +00:00
|
|
|
}
|
|
|
|
|
2002-10-28 01:03:43 +00:00
|
|
|
// addPassesToEmitAssembly - This method controls the entire code generation
|
|
|
|
// process for the ultra sparc.
|
|
|
|
//
|
2003-12-17 22:04:00 +00:00
|
|
|
bool
|
|
|
|
SparcTargetMachine::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out)
|
2002-10-28 01:03:43 +00:00
|
|
|
{
|
2003-06-18 21:14:23 +00:00
|
|
|
// The following 3 passes used to be inserted specially by llc.
|
|
|
|
// Replace malloc and free instructions with library calls.
|
|
|
|
PM.add(createLowerAllocationsPass());
|
|
|
|
|
|
|
|
// Strip all of the symbols from the bytecode so that it will be smaller...
|
|
|
|
if (!DisableStrip)
|
|
|
|
PM.add(createSymbolStrippingPass());
|
|
|
|
|
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
|
|
|
// 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));
|
|
|
|
|
2003-11-07 20:33:25 +00:00
|
|
|
// Specialize LLVM code for this target machine
|
|
|
|
PM.add(createPreSelectionPass(*this));
|
|
|
|
// Run basic dataflow optimizations on LLVM code
|
|
|
|
PM.add(createReassociatePass());
|
|
|
|
PM.add(createLICMPass());
|
|
|
|
PM.add(createGCSEPass());
|
|
|
|
|
2003-07-29 19:58:00 +00:00
|
|
|
// If LLVM dumping after transformations is requested, add it to the pipeline
|
|
|
|
if (DumpInput)
|
2003-09-18 17:37:46 +00:00
|
|
|
PM.add(new PrintFunctionPass("Input code to instr. selection:\n",
|
2003-08-06 23:06:21 +00:00
|
|
|
&std::cerr));
|
2002-10-28 01:03:43 +00:00
|
|
|
|
|
|
|
PM.add(createInstructionSelectionPass(*this));
|
|
|
|
|
|
|
|
if (!DisableSched)
|
|
|
|
PM.add(createInstructionSchedulingWithSSAPass(*this));
|
|
|
|
|
|
|
|
PM.add(getRegisterAllocator(*this));
|
|
|
|
|
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));
|
|
|
|
|
2003-08-12 15:51:02 +00:00
|
|
|
if (EmitMappingInfo)
|
2003-09-18 17:37:46 +00:00
|
|
|
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));
|
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 bytecode to the assembly file into its special section next
|
2003-09-18 17:37:46 +00:00
|
|
|
if (EmitMappingInfo)
|
2003-11-13 00:16:28 +00:00
|
|
|
PM.add(createBytecodeAsmPrinterPass(Out));
|
2003-08-12 15:51:02 +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
|
|
|
|
|
|
|
// addPassesToJITCompile - This method controls the JIT method of code
|
|
|
|
// generation for the UltraSparc.
|
|
|
|
//
|
2003-12-17 22:04:00 +00:00
|
|
|
bool SparcTargetMachine::addPassesToJITCompile(FunctionPassManager &PM) {
|
2003-06-06 07:11:16 +00:00
|
|
|
const TargetData &TD = getTargetData();
|
|
|
|
|
|
|
|
PM.add(new TargetData("lli", TD.isLittleEndian(), TD.getPointerSize(),
|
|
|
|
TD.getPointerAlignment(), TD.getDoubleAlignment()));
|
|
|
|
|
|
|
|
// Replace malloc and free instructions with library calls.
|
|
|
|
// Do this after tracing until lli implements these lib calls.
|
|
|
|
// For now, it will emulate malloc and free internally.
|
|
|
|
PM.add(createLowerAllocationsPass());
|
|
|
|
|
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());
|
|
|
|
|
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
|
|
|
// Construct and initialize the MachineFunction object for this fn.
|
|
|
|
PM.add(createMachineCodeConstructionPass(*this));
|
|
|
|
|
2003-11-07 20:33:25 +00:00
|
|
|
// Specialize LLVM code for this target machine and then
|
|
|
|
// run basic dataflow optimizations on LLVM code.
|
|
|
|
PM.add(createPreSelectionPass(*this));
|
|
|
|
// Run basic dataflow optimizations on LLVM code
|
|
|
|
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
|
|
|
|
2003-05-27 22:24:48 +00:00
|
|
|
PM.add(createInstructionSelectionPass(*this));
|
|
|
|
|
|
|
|
PM.add(getRegisterAllocator(*this));
|
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)
|
|
|
|
PM.add(createPeepholeOptsPass(*this));
|
|
|
|
|
2003-05-27 22:24:48 +00:00
|
|
|
return false; // success!
|
|
|
|
}
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2003-12-17 22:04:00 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
|
|
|
|
// that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
TargetMachine *allocateSparcTargetMachine(const Module &M) {
|
|
|
|
return new SparcTargetMachine();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|