2004-04-25 07:04:49 +00:00
|
|
|
//===-- SparcV9TargetMachine.cpp - SparcV9 Target Machine Implementation --===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
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.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
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.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
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"
|
2005-04-21 23:30:14 +00:00
|
|
|
#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"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/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, \
|
2005-08-19 16:56:56 +00:00
|
|
|
ImplicitRegUseList, ImplicitRegUseList, 0 },
|
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.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2004-09-30 20:20:01 +00:00
|
|
|
namespace llvm {
|
|
|
|
bool EmitMappingInfo = false;
|
|
|
|
}
|
|
|
|
|
2003-11-13 00:16:28 +00:00
|
|
|
namespace {
|
|
|
|
cl::opt<bool> DisableSched("disable-sched",
|
2005-05-13 19:45:45 +00:00
|
|
|
cl::desc("Disable sparcv9 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",
|
2005-05-13 19:45:45 +00:00
|
|
|
cl::desc("Disable sparcv9 peephole optimization pass"));
|
2002-10-28 01:03:43 +00:00
|
|
|
|
2005-05-13 19:44:21 +00:00
|
|
|
cl::opt<bool, true> EmitMappingInfoOpt("enable-maps", cl::ReallyHidden,
|
2004-09-30 20:20:01 +00:00
|
|
|
cl::location(EmitMappingInfo),
|
|
|
|
cl::init(false),
|
2003-11-13 00:16:28 +00:00
|
|
|
cl::desc("Emit LLVM-to-MachineCode mapping info to assembly"));
|
2003-06-18 21:14:23 +00:00
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
cl::opt<bool> EnableModSched("enable-modsched",
|
2005-07-27 05:53:44 +00:00
|
|
|
cl::desc("Enable modulo scheduling pass"), cl::Hidden);
|
2005-06-17 04:00:22 +00:00
|
|
|
|
|
|
|
cl::opt<bool> EnableSBModSched("enable-modschedSB",
|
2005-07-27 05:53:44 +00:00
|
|
|
cl::desc("Enable superblock modulo scheduling (experimental)"), cl::Hidden);
|
2004-11-18 18:38:01 +00:00
|
|
|
|
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() {
|
2004-09-29 23:01:17 +00:00
|
|
|
#if defined(__sparcv9)
|
2004-07-11 02:48:49 +00:00
|
|
|
return 10;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SparcV9TargetMachine::getModuleMatchQuality(const Module &M) {
|
2004-12-12 17:40:28 +00:00
|
|
|
// We strongly match "sparcv9-*".
|
|
|
|
std::string TT = M.getTargetTriple();
|
|
|
|
if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "sparcv9-")
|
|
|
|
return 20;
|
|
|
|
|
2004-07-11 02:48:49 +00:00
|
|
|
if (M.getEndianness() == Module::BigEndian &&
|
|
|
|
M.getPointerSize() == Module::Pointer64)
|
2004-12-12 17:40:28 +00:00
|
|
|
return 10; // Weak match
|
2004-07-11 02:48:49 +00:00
|
|
|
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) {}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-12-20 09:17:40 +00:00
|
|
|
const char *getPassName() const {
|
|
|
|
return "ConstructMachineFunction";
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-12-20 09:17:40 +00:00
|
|
|
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"; }
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-12-20 09:17:40 +00:00
|
|
|
static void freeMachineCode(Instruction &I) {
|
|
|
|
MachineCodeForInstruction::destroy(&I);
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-12-20 09:17:40 +00:00
|
|
|
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();
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-12-20 09:17:40 +00:00
|
|
|
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
|
|
|
|
for_each(FI->begin(), FI->end(), freeMachineCode);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-12-22 03:47:58 +00:00
|
|
|
MachineFunction::destruct(&F);
|
2003-12-20 09:17:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2003-12-20 09:17:40 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-06-25 02:48:37 +00:00
|
|
|
/// addPassesToEmitFile - This method controls the entire code generation
|
2004-02-09 23:18:42 +00:00
|
|
|
/// process for the ultra sparc.
|
|
|
|
///
|
2003-12-17 22:04:00 +00:00
|
|
|
bool
|
2005-06-25 02:48:37 +00:00
|
|
|
SparcV9TargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out,
|
|
|
|
CodeGenFileType FileType) {
|
|
|
|
if (FileType != TargetMachine::AssemblyFile) return true;
|
|
|
|
|
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());
|
2005-04-21 23:30:14 +00:00
|
|
|
|
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());
|
2005-04-21 23:30:14 +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());
|
|
|
|
|
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));
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-08-04 07:30:04 +00:00
|
|
|
PM.add(createSparcV9BurgInstSelector(*this));
|
2002-10-28 01:03:43 +00:00
|
|
|
|
2005-06-17 04:00:22 +00:00
|
|
|
if(!DisableSched && PrintMachineCode)
|
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "Before local scheduling:\n"));
|
|
|
|
|
2005-02-10 17:02:06 +00:00
|
|
|
if (!DisableSched)
|
|
|
|
PM.add(createInstructionSchedulingWithSSAPass(*this));
|
|
|
|
|
2005-02-24 02:14:44 +00:00
|
|
|
if(PrintMachineCode && EnableModSched)
|
2004-11-18 18:38:01 +00:00
|
|
|
PM.add(createMachineFunctionPrinterPass(&std::cerr, "Before modulo scheduling:\n"));
|
2002-10-28 01:03:43 +00:00
|
|
|
|
2004-11-18 18:38:01 +00:00
|
|
|
//Use ModuloScheduling if enabled, otherwise use local scheduling if not disabled.
|
|
|
|
if(EnableModSched)
|
|
|
|
PM.add(createModuloSchedulingPass(*this));
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-06-17 04:00:22 +00:00
|
|
|
if(EnableSBModSched)
|
|
|
|
PM.add(createModuloSchedulingSBPass(*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-12-02 21:05:01 +00:00
|
|
|
if (EmitMappingInfo)
|
2003-11-13 00:16:28 +00:00
|
|
|
PM.add(createBytecodeAsmPrinterPass(Out));
|
2005-04-21 23:30:14 +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());
|
2005-04-21 23:30:14 +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());
|
2005-04-21 23:30:14 +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());
|
|
|
|
|
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
|
|
|
|