2003-09-30 20:37:50 +02:00
|
|
|
//===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02: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 22:59:05 +02:00
|
|
|
//
|
2003-10-20 22:19:47 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 14:38:31 +02:00
|
|
|
//
|
2006-09-04 06:14:57 +02:00
|
|
|
// This file defines the TargetMachine and LLVMTargetMachine classes.
|
2001-09-18 14:38:31 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_TARGET_TARGETMACHINE_H
|
|
|
|
#define LLVM_TARGET_TARGETMACHINE_H
|
|
|
|
|
2005-11-01 21:06:59 +01:00
|
|
|
#include "llvm/Target/TargetInstrItineraries.h"
|
2003-10-20 17:14:33 +02:00
|
|
|
#include <cassert>
|
2006-05-12 08:33:49 +02:00
|
|
|
#include <string>
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
2006-09-08 00:06:40 +02:00
|
|
|
class TargetAsmInfo;
|
2006-05-12 08:33:49 +02:00
|
|
|
class TargetData;
|
2005-07-12 03:41:54 +02:00
|
|
|
class TargetSubtarget;
|
2003-01-13 01:21:32 +01:00
|
|
|
class TargetInstrInfo;
|
|
|
|
class TargetInstrDescriptor;
|
2003-12-20 02:22:19 +01:00
|
|
|
class TargetJITInfo;
|
2006-03-14 00:17:42 +01:00
|
|
|
class TargetLowering;
|
2002-12-28 21:13:29 +01:00
|
|
|
class TargetFrameInfo;
|
2002-12-02 22:00:50 +01:00
|
|
|
class MachineCodeEmitter;
|
2002-10-30 01:53:02 +01:00
|
|
|
class MRegisterInfo;
|
2006-05-12 08:33:49 +02:00
|
|
|
class Module;
|
2003-08-13 20:17:27 +02:00
|
|
|
class FunctionPassManager;
|
2002-04-28 22:40:25 +02:00
|
|
|
class PassManager;
|
2002-09-16 17:39:35 +02:00
|
|
|
class Pass;
|
2001-09-18 14:38:31 +02:00
|
|
|
|
2006-02-22 21:19:42 +01:00
|
|
|
// Relocation model types.
|
|
|
|
namespace Reloc {
|
|
|
|
enum Model {
|
|
|
|
Default,
|
|
|
|
Static,
|
2006-07-26 23:12:04 +02:00
|
|
|
PIC_, // Cannot be named PIC due to collision with -DPIC
|
2006-02-22 21:19:42 +01:00
|
|
|
DynamicNoPIC
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2006-07-06 03:53:36 +02:00
|
|
|
// Code model types.
|
|
|
|
namespace CodeModel {
|
|
|
|
enum Model {
|
|
|
|
Default,
|
|
|
|
Small,
|
|
|
|
Kernel,
|
|
|
|
Medium,
|
|
|
|
Large
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2002-12-28 21:13:29 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// TargetMachine - Primary interface to the complete machine description for
|
|
|
|
/// the target machine. All target-specific information should be accessible
|
|
|
|
/// through this interface.
|
2005-04-21 22:59:05 +02:00
|
|
|
///
|
2003-06-03 17:28:40 +02:00
|
|
|
class TargetMachine {
|
2006-09-04 06:14:57 +02:00
|
|
|
TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const TargetMachine &); // DO NOT IMPLEMENT
|
2006-09-03 20:44:26 +02:00
|
|
|
protected: // Can only create subclasses.
|
2006-09-08 00:06:40 +02:00
|
|
|
TargetMachine() : AsmInfo(NULL) { }
|
2005-07-12 05:04:49 +02:00
|
|
|
|
|
|
|
/// getSubtargetImpl - virtual method implemented by subclasses that returns
|
|
|
|
/// a reference to that target's TargetSubtarget-derived member variable.
|
|
|
|
virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
|
2006-09-08 00:06:40 +02:00
|
|
|
|
|
|
|
/// AsmInfo - Contains target specific asm information.
|
|
|
|
///
|
|
|
|
mutable const TargetAsmInfo *AsmInfo;
|
|
|
|
|
2006-09-08 01:39:26 +02:00
|
|
|
/// createTargetAsmInfo - Create a new instance of target specific asm
|
|
|
|
/// information.
|
|
|
|
virtual const TargetAsmInfo *createTargetAsmInfo() const { return NULL; }
|
|
|
|
|
2001-09-18 14:38:31 +02:00
|
|
|
public:
|
2003-12-28 22:23:38 +01:00
|
|
|
virtual ~TargetMachine();
|
2002-10-29 22:12:46 +01:00
|
|
|
|
2004-07-11 04:43:07 +02:00
|
|
|
/// getModuleMatchQuality - This static method should be implemented by
|
|
|
|
/// targets to indicate how closely they match the specified module. This is
|
|
|
|
/// used by the LLC tool to determine which target to use when an explicit
|
|
|
|
/// -march option is not specified. If a target returns zero, it will never
|
|
|
|
/// be chosen without an explicit -march option.
|
|
|
|
static unsigned getModuleMatchQuality(const Module &M) { return 0; }
|
|
|
|
|
|
|
|
/// getJITMatchQuality - This static method should be implemented by targets
|
|
|
|
/// that provide JIT capabilities to indicate how suitable they are for
|
|
|
|
/// execution on the current host. If a value of 0 is returned, the target
|
|
|
|
/// will not be used unless an explicit -march option is used.
|
|
|
|
static unsigned getJITMatchQuality() { return 0; }
|
|
|
|
|
2001-09-18 14:38:31 +02:00
|
|
|
// Interfaces to the major aspects of target machine information:
|
|
|
|
// -- Instruction opcode and operand information
|
|
|
|
// -- Pipelines and scheduling information
|
2002-09-20 02:52:09 +02:00
|
|
|
// -- Stack frame information
|
2006-03-14 00:17:42 +01:00
|
|
|
// -- Selection DAG lowering information
|
2005-04-21 22:59:05 +02:00
|
|
|
//
|
2004-06-02 07:53:25 +02:00
|
|
|
virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
|
|
|
|
virtual const TargetFrameInfo *getFrameInfo() const { return 0; }
|
2006-03-14 00:17:42 +01:00
|
|
|
virtual TargetLowering *getTargetLowering() const { return 0; }
|
2006-05-03 03:29:57 +02:00
|
|
|
virtual const TargetData *getTargetData() const { return 0; }
|
2006-09-08 00:06:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
/// getTargetAsmInfo - Return target specific asm information.
|
|
|
|
///
|
|
|
|
const TargetAsmInfo *getTargetAsmInfo() const {
|
|
|
|
if (!AsmInfo) AsmInfo = createTargetAsmInfo();
|
|
|
|
return AsmInfo;
|
|
|
|
}
|
|
|
|
|
2005-07-27 07:53:44 +02:00
|
|
|
/// getSubtarget - This method returns a pointer to the specified type of
|
2005-07-12 05:04:49 +02:00
|
|
|
/// TargetSubtarget. In debug builds, it verifies that the object being
|
|
|
|
/// returned is of the correct type.
|
2005-08-05 23:53:21 +02:00
|
|
|
template<typename STC> const STC &getSubtarget() const {
|
2005-07-12 05:04:49 +02:00
|
|
|
const TargetSubtarget *TST = getSubtargetImpl();
|
2005-08-05 23:53:21 +02:00
|
|
|
assert(TST && dynamic_cast<const STC*>(TST) &&
|
2005-07-12 03:41:54 +02:00
|
|
|
"Not the right kind of subtarget!");
|
2005-08-05 23:53:21 +02:00
|
|
|
return *static_cast<const STC*>(TST);
|
2005-07-12 03:41:54 +02:00
|
|
|
}
|
|
|
|
|
2002-10-30 01:53:02 +01:00
|
|
|
/// getRegisterInfo - If register information is available, return it. If
|
2002-12-28 21:13:29 +01:00
|
|
|
/// not, return null. This is kept separate from RegInfo until RegInfo has
|
|
|
|
/// details of graph coloring register allocation removed from it.
|
2002-10-30 01:53:02 +01:00
|
|
|
///
|
2006-09-03 20:44:26 +02:00
|
|
|
virtual const MRegisterInfo *getRegisterInfo() const { return 0; }
|
2002-10-30 01:53:02 +01:00
|
|
|
|
2003-12-20 02:22:19 +01:00
|
|
|
/// getJITInfo - If this target supports a JIT, return information for it,
|
|
|
|
/// otherwise return null.
|
|
|
|
///
|
|
|
|
virtual TargetJITInfo *getJITInfo() { return 0; }
|
2005-11-01 21:06:59 +01:00
|
|
|
|
|
|
|
/// getInstrItineraryData - Returns instruction itinerary data for the target
|
|
|
|
/// or specific subtarget.
|
|
|
|
///
|
|
|
|
virtual const InstrItineraryData getInstrItineraryData() const {
|
|
|
|
return InstrItineraryData();
|
|
|
|
}
|
2003-12-20 02:22:19 +01:00
|
|
|
|
2006-02-22 21:19:42 +01:00
|
|
|
/// getRelocationModel - Returns the code generation relocation model. The
|
|
|
|
/// choices are static, PIC, and dynamic-no-pic, and target default.
|
|
|
|
static Reloc::Model getRelocationModel();
|
|
|
|
|
|
|
|
/// setRelocationModel - Sets the code generation relocation model.
|
|
|
|
static void setRelocationModel(Reloc::Model Model);
|
|
|
|
|
2006-07-06 03:53:36 +02:00
|
|
|
/// getCodeModel - Returns the code model. The choices are small, kernel,
|
|
|
|
/// medium, large, and target default.
|
|
|
|
static CodeModel::Model getCodeModel();
|
|
|
|
|
|
|
|
/// setCodeModel - Sets the code model.
|
|
|
|
static void setCodeModel(CodeModel::Model Model);
|
|
|
|
|
2005-06-25 04:47:50 +02:00
|
|
|
/// CodeGenFileType - These enums are meant to be passed into
|
|
|
|
/// addPassesToEmitFile to indicate what type of file to emit.
|
|
|
|
enum CodeGenFileType {
|
2005-06-25 05:31:43 +02:00
|
|
|
AssemblyFile, ObjectFile, DynamicLibrary
|
2005-06-25 04:47:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// addPassesToEmitFile - Add passes to the specified pass manager to get
|
|
|
|
/// the specified file emitted. Typically this will involve several steps of
|
2005-11-08 03:12:47 +01:00
|
|
|
/// code generation. If Fast is set to true, the code generator should emit
|
|
|
|
/// code as fast as possible, without regard for compile time. This method
|
|
|
|
/// should return true if emission of this file type is not supported.
|
2002-10-28 02:02:24 +01:00
|
|
|
///
|
2006-09-04 06:14:57 +02:00
|
|
|
virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out,
|
2005-11-08 03:12:47 +01:00
|
|
|
CodeGenFileType FileType, bool Fast) {
|
2002-10-29 22:12:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
2006-09-04 06:14:57 +02:00
|
|
|
|
|
|
|
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
|
|
|
|
/// get machine code emitted. This uses a MachineCodeEmitter object to handle
|
|
|
|
/// actually outputting the machine code and resolving things like the address
|
|
|
|
/// of functions. This method returns true if machine code emission is
|
|
|
|
/// not supported.
|
|
|
|
///
|
|
|
|
virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
|
|
|
|
MachineCodeEmitter &MCE, bool Fast) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-09-16 17:39:35 +02:00
|
|
|
|
2006-09-04 06:14:57 +02:00
|
|
|
/// addPassesToEmitWholeFile - This method can be implemented by targets that
|
|
|
|
/// require having the entire module at once. This is not recommended, do not
|
|
|
|
/// use this.
|
|
|
|
virtual bool WantsWholeFile() const { return false; }
|
|
|
|
virtual bool addPassesToEmitWholeFile(PassManager &PM, std::ostream &Out,
|
|
|
|
CodeGenFileType FileType, bool Fast) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// LLVMTargetMachine - This class describes a target machine that is
|
|
|
|
/// implemented with the LLVM target-independent code generator.
|
|
|
|
///
|
|
|
|
class LLVMTargetMachine : public TargetMachine {
|
|
|
|
protected: // Can only create subclasses.
|
|
|
|
LLVMTargetMachine() { }
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// addPassesToEmitFile - Add passes to the specified pass manager to get
|
|
|
|
/// the specified file emitted. Typically this will involve several steps of
|
|
|
|
/// code generation. If Fast is set to true, the code generator should emit
|
|
|
|
/// code as fast as possible, without regard for compile time. This method
|
|
|
|
/// should return true if emission of this file type is not supported.
|
|
|
|
///
|
|
|
|
/// The default implementation of this method adds components from the
|
|
|
|
/// LLVM retargetable code generator, invoking the methods below to get
|
|
|
|
/// target-specific passes in standard locations.
|
|
|
|
///
|
|
|
|
virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out,
|
|
|
|
CodeGenFileType FileType, bool Fast);
|
|
|
|
|
2002-12-02 22:00:50 +01:00
|
|
|
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
|
2003-08-13 20:17:27 +02:00
|
|
|
/// get machine code emitted. This uses a MachineCodeEmitter object to handle
|
2002-12-02 22:00:50 +01:00
|
|
|
/// actually outputting the machine code and resolving things like the address
|
2006-09-04 06:14:57 +02:00
|
|
|
/// of functions. This method returns true if machine code emission is
|
2002-12-02 22:15:42 +01:00
|
|
|
/// not supported.
|
2002-10-29 21:51:10 +01:00
|
|
|
///
|
2003-08-13 20:17:27 +02:00
|
|
|
virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
|
2006-09-04 06:14:57 +02:00
|
|
|
MachineCodeEmitter &MCE, bool Fast);
|
|
|
|
|
|
|
|
/// Target-Independent Code Generator Pass Configuration Options.
|
|
|
|
|
|
|
|
/// addInstSelector - This method should add any "last minute" LLVM->LLVM
|
|
|
|
/// passes, then install an instruction selector pass, which converts from
|
|
|
|
/// LLVM code to machine instructions.
|
|
|
|
virtual bool addInstSelector(FunctionPassManager &PM, bool Fast) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addPostRegAllocPasses - This method may be implemented by targets that
|
|
|
|
/// want to run passes after register allocation but before prolog-epilog
|
|
|
|
/// insertion. This should return true if -print-machineinstrs should print
|
|
|
|
/// after these passes.
|
|
|
|
virtual bool addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addPreEmitPass - This pass may be implemented by targets that want to run
|
|
|
|
/// passes immediately before machine code is emitted. This should return
|
|
|
|
/// true if -print-machineinstrs should print out the code after the passes.
|
|
|
|
virtual bool addPreEmitPass(FunctionPassManager &PM, bool Fast) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// addAssemblyEmitter - This pass should be overridden by the target to add
|
|
|
|
/// the asmprinter, if asm emission is supported. If this is not supported,
|
|
|
|
/// 'true' should be returned.
|
|
|
|
virtual bool addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
|
|
|
|
std::ostream &Out) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addObjectWriter - This pass should be overridden by the target to add
|
|
|
|
/// the object-file writer, if supported. If this is not supported,
|
|
|
|
/// 'true' should be returned.
|
|
|
|
virtual bool addObjectWriter(FunctionPassManager &PM, bool Fast,
|
|
|
|
std::ostream &Out) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// addCodeEmitter - This pass should be overridden by the target to add a
|
|
|
|
/// code emitter, if supported. If this is not supported, 'true' should be
|
|
|
|
/// returned.
|
|
|
|
virtual bool addCodeEmitter(FunctionPassManager &PM, bool Fast,
|
|
|
|
MachineCodeEmitter &MCE) {
|
2002-12-02 22:00:50 +01:00
|
|
|
return true;
|
|
|
|
}
|
2001-09-18 14:38:31 +02:00
|
|
|
};
|
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-18 14:38:31 +02:00
|
|
|
#endif
|