Introduce MCCodeGenInfo, which keeps information that can affect codegen

(including compilation, assembly). Move relocation model Reloc::Model from
TargetMachine to MCCodeGenInfo so it's accessible even without TargetMachine.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135468 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng
2011-07-19 06:37:02 +00:00
parent 939ece1b5c
commit 439661395f
74 changed files with 641 additions and 314 deletions

View File

@ -659,6 +659,7 @@ for a_target in $TARGETS_TO_BUILD; do
LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target" LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target"
LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo" LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo"
LLVM_NATIVE_MCASMINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo" LLVM_NATIVE_MCASMINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo"
LLVM_NATIVE_MCCODEGENINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCCodeGenInfo"
LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter" LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter"
if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then
LLVM_NATIVE_ASMPARSER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser" LLVM_NATIVE_ASMPARSER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser"
@ -669,6 +670,8 @@ for a_target in $TARGETS_TO_BUILD; do
[LLVM name for the native TargetInfo init function, if available]) [LLVM name for the native TargetInfo init function, if available])
AC_DEFINE_UNQUOTED(LLVM_NATIVE_MCASMINFO, $LLVM_NATIVE_MCASMINFO, AC_DEFINE_UNQUOTED(LLVM_NATIVE_MCASMINFO, $LLVM_NATIVE_MCASMINFO,
[LLVM name for the native MCAsmInfo init function, if available]) [LLVM name for the native MCAsmInfo init function, if available])
AC_DEFINE_UNQUOTED(LLVM_NATIVE_MCCODEGENINFO, $LLVM_NATIVE_MCCODEGENINFO,
[LLVM name for the native MCCodeGenInfo init function, if available])
AC_DEFINE_UNQUOTED(LLVM_NATIVE_ASMPRINTER, $LLVM_NATIVE_ASMPRINTER, AC_DEFINE_UNQUOTED(LLVM_NATIVE_ASMPRINTER, $LLVM_NATIVE_ASMPRINTER,
[LLVM name for the native AsmPrinter init function, if available]) [LLVM name for the native AsmPrinter init function, if available])
if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then

View File

@ -337,6 +337,7 @@ else ()
set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target) set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo) set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
set(LLVM_NATIVE_MCASMINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo) set(LLVM_NATIVE_MCASMINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo)
set(LLVM_NATIVE_MCCODEGENINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCCODEGENInfo)
set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter) set(LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter)
endif () endif ()

6
configure vendored
View File

@ -5121,6 +5121,7 @@ _ACEOF
LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target" LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target"
LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo" LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo"
LLVM_NATIVE_MCASMINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo" LLVM_NATIVE_MCASMINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo"
LLVM_NATIVE_MCCODEGENINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCCodeGenInfo"
LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter" LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter"
if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then
LLVM_NATIVE_ASMPARSER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser" LLVM_NATIVE_ASMPARSER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser"
@ -5141,6 +5142,11 @@ cat >>confdefs.h <<_ACEOF
_ACEOF _ACEOF
cat >>confdefs.h <<_ACEOF
#define LLVM_NATIVE_MCCODEGENINFO $LLVM_NATIVE_MCCODEGENINFO
_ACEOF
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define LLVM_NATIVE_ASMPRINTER $LLVM_NATIVE_ASMPRINTER #define LLVM_NATIVE_ASMPRINTER $LLVM_NATIVE_ASMPRINTER
_ACEOF _ACEOF

View File

@ -46,6 +46,11 @@ typedef struct LLVMStructLayout *LLVMStructLayoutRef;
#include "llvm/Config/Targets.def" #include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */ #undef LLVM_TARGET /* Explicit undef to make SWIG happier */
#define LLVM_TARGET(TargetName) \
void LLVMInitialize##TargetName##MCCodeGenInfo(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
/** LLVMInitializeAllTargetInfos - The main program should call this function if /** LLVMInitializeAllTargetInfos - The main program should call this function if
it wants access to all available targets that LLVM is configured to it wants access to all available targets that LLVM is configured to
support. */ support. */
@ -73,6 +78,7 @@ static inline LLVMBool LLVMInitializeNativeTarget(void) {
LLVM_NATIVE_TARGETINFO(); LLVM_NATIVE_TARGETINFO();
LLVM_NATIVE_TARGET(); LLVM_NATIVE_TARGET();
LLVM_NATIVE_MCASMINFO(); LLVM_NATIVE_MCASMINFO();
LLVM_NATIVE_MCCODEGENINFO();
return 0; return 0;
#else #else
return 1; return 1;

View File

@ -560,6 +560,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */ /* LLVM name for the native MCAsmInfo init function, if available */
#cmakedefine LLVM_NATIVE_MCASMINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo #cmakedefine LLVM_NATIVE_MCASMINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo
/* LLVM name for the native MCCodeGenInfo init function, if available */
#cmakedefine LLVM_NATIVE_MCCODEGENINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCCodeGenInfo
/* Define if this is Unixish platform */ /* Define if this is Unixish platform */
#cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX} #cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX}

View File

@ -576,6 +576,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */ /* LLVM name for the native MCAsmInfo init function, if available */
#undef LLVM_NATIVE_MCASMINFO #undef LLVM_NATIVE_MCASMINFO
/* LLVM name for the native MCCODEGENInfo init function, if available */
#undef LLVM_NATIVE_MCCODEGENINFO
/* LLVM name for the native Target init function, if available */ /* LLVM name for the native Target init function, if available */
#undef LLVM_NATIVE_TARGET #undef LLVM_NATIVE_TARGET

View File

@ -61,6 +61,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */ /* LLVM name for the native MCAsmInfo init function, if available */
#cmakedefine LLVM_NATIVE_MCASMINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo #cmakedefine LLVM_NATIVE_MCASMINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo
/* LLVM name for the native MCCodeGenInfo init function, if available */
#cmakedefine LLVM_NATIVE_MCCODEGENINFO LLVMInitialize${LLVM_NATIVE_ARCH}MCCodeGenInfo
/* LLVM name for the native AsmPrinter init function, if available */ /* LLVM name for the native AsmPrinter init function, if available */
#cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter #cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter

View File

@ -61,6 +61,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */ /* LLVM name for the native MCAsmInfo init function, if available */
#undef LLVM_NATIVE_MCASMINFO #undef LLVM_NATIVE_MCASMINFO
/* LLVM name for the native MCCodeGenInfo init function, if available */
#undef LLVM_NATIVE_MCCODEGENINFO
/* LLVM name for the native AsmPrinter init function, if available */ /* LLVM name for the native AsmPrinter init function, if available */
#undef LLVM_NATIVE_ASMPRINTER #undef LLVM_NATIVE_ASMPRINTER

View File

@ -18,6 +18,7 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <string> #include <string>
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/ADT/ValueMap.h" #include "llvm/ADT/ValueMap.h"
@ -201,6 +202,7 @@ public:
CodeGenOpt::Level OptLevel = CodeGenOpt::Level OptLevel =
CodeGenOpt::Default, CodeGenOpt::Default,
bool GVsWithCode = true, bool GVsWithCode = true,
Reloc::Model RM = Reloc::Default,
CodeModel::Model CMM = CodeModel::Model CMM =
CodeModel::Default); CodeModel::Default);
@ -463,6 +465,7 @@ private:
CodeGenOpt::Level OptLevel; CodeGenOpt::Level OptLevel;
JITMemoryManager *JMM; JITMemoryManager *JMM;
bool AllocateGVsWithCode; bool AllocateGVsWithCode;
Reloc::Model RelocModel;
CodeModel::Model CMModel; CodeModel::Model CMModel;
std::string MArch; std::string MArch;
std::string MCPU; std::string MCPU;
@ -476,6 +479,7 @@ private:
OptLevel = CodeGenOpt::Default; OptLevel = CodeGenOpt::Default;
JMM = NULL; JMM = NULL;
AllocateGVsWithCode = false; AllocateGVsWithCode = false;
RelocModel = Reloc::Default;
CMModel = CodeModel::Default; CMModel = CodeModel::Default;
UseMCJIT = false; UseMCJIT = false;
} }
@ -517,6 +521,13 @@ public:
return *this; return *this;
} }
/// setRelocationModel - Set the relocation model that the ExecutionEngine
/// target is using. Defaults to target specific default "Reloc::Default".
EngineBuilder &setRelocationModel(Reloc::Model RM) {
RelocModel = RM;
return *this;
}
/// setCodeModel - Set the CodeModel that the ExecutionEngine target /// setCodeModel - Set the CodeModel that the ExecutionEngine target
/// data is using. Defaults to target specific default "CodeModel::Default". /// data is using. Defaults to target specific default "CodeModel::Default".
EngineBuilder &setCodeModel(CodeModel::Model M) { EngineBuilder &setCodeModel(CodeModel::Model M) {
@ -569,6 +580,7 @@ public:
StringRef MArch, StringRef MArch,
StringRef MCPU, StringRef MCPU,
const SmallVectorImpl<std::string>& MAttrs, const SmallVectorImpl<std::string>& MAttrs,
Reloc::Model RM,
std::string *Err); std::string *Err);
ExecutionEngine *create(); ExecutionEngine *create();

View File

@ -0,0 +1,36 @@
//===-- llvm/MC/MCCodeGenInfo.h - Target CodeGen Info -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file tracks information about the target which can affect codegen,
// asm parsing, and asm printing. For example, relocation model.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_MC_MCCODEGENINFO_H
#define LLVM_MC_MCCODEGENINFO_H
namespace llvm {
// Relocation model types.
namespace Reloc {
enum Model { Default, Static, PIC_, DynamicNoPIC };
}
class MCCodeGenInfo {
/// RelocationModel - Relocation model: statcic, pic, etc.
///
Reloc::Model RelocationModel;
public:
void InitMCCodeGenInfo(Reloc::Model RM = Reloc::Default);
Reloc::Model getRelocationModel() const { return RelocationModel; }
};
} // namespace llvm
#endif

View File

@ -14,6 +14,7 @@
#ifndef LLVM_TARGET_TARGETMACHINE_H #ifndef LLVM_TARGET_TARGETMACHINE_H
#define LLVM_TARGET_TARGETMACHINE_H #define LLVM_TARGET_TARGETMACHINE_H
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include <cassert> #include <cassert>
#include <string> #include <string>
@ -23,6 +24,7 @@ namespace llvm {
class InstrItineraryData; class InstrItineraryData;
class JITCodeEmitter; class JITCodeEmitter;
class MCAsmInfo; class MCAsmInfo;
class MCCodeGenInfo;
class MCContext; class MCContext;
class Pass; class Pass;
class PassManager; class PassManager;
@ -41,16 +43,6 @@ class TargetSubtargetInfo;
class formatted_raw_ostream; class formatted_raw_ostream;
class raw_ostream; class raw_ostream;
// Relocation model types.
namespace Reloc {
enum Model {
Default,
Static,
PIC_, // Cannot be named PIC due to collision with -DPIC
DynamicNoPIC
};
}
// Code model types. // Code model types.
namespace CodeModel { namespace CodeModel {
enum Model { enum Model {
@ -108,6 +100,10 @@ protected: // Can only create subclasses.
std::string TargetCPU; std::string TargetCPU;
std::string TargetFS; std::string TargetFS;
/// CodeGenInfo - Low level target information such as relocation model.
///
const MCCodeGenInfo *CodeGenInfo;
/// AsmInfo - Contains target specific asm information. /// AsmInfo - Contains target specific asm information.
/// ///
const MCAsmInfo *AsmInfo; const MCAsmInfo *AsmInfo;
@ -214,11 +210,7 @@ public:
/// getRelocationModel - Returns the code generation relocation model. The /// getRelocationModel - Returns the code generation relocation model. The
/// choices are static, PIC, and dynamic-no-pic, and target default. /// choices are static, PIC, and dynamic-no-pic, and target default.
static Reloc::Model getRelocationModel(); Reloc::Model getRelocationModel() const;
/// setRelocationModel - Sets the code generation relocation model.
///
static void setRelocationModel(Reloc::Model Model);
/// getCodeModel - Returns the code model. The choices are small, kernel, /// getCodeModel - Returns the code model. The choices are small, kernel,
/// medium, large, and target default. /// medium, large, and target default.
@ -309,7 +301,7 @@ public:
class LLVMTargetMachine : public TargetMachine { class LLVMTargetMachine : public TargetMachine {
protected: // Can only create subclasses. protected: // Can only create subclasses.
LLVMTargetMachine(const Target &T, StringRef TargetTriple, LLVMTargetMachine(const Target &T, StringRef TargetTriple,
StringRef CPU, StringRef FS); StringRef CPU, StringRef FS, Reloc::Model RM);
private: private:
/// addCommonCodeGenPasses - Add standard LLVM codegen passes used for /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for

View File

@ -19,6 +19,7 @@
#ifndef LLVM_TARGET_TARGETREGISTRY_H #ifndef LLVM_TARGET_TARGETREGISTRY_H
#define LLVM_TARGET_TARGETREGISTRY_H #define LLVM_TARGET_TARGETREGISTRY_H
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include <string> #include <string>
#include <cassert> #include <cassert>
@ -37,6 +38,7 @@ namespace llvm {
class MCRegisterInfo; class MCRegisterInfo;
class MCStreamer; class MCStreamer;
class MCSubtargetInfo; class MCSubtargetInfo;
class MCCodeGenInfo;
class TargetAsmBackend; class TargetAsmBackend;
class TargetAsmLexer; class TargetAsmLexer;
class TargetAsmParser; class TargetAsmParser;
@ -68,15 +70,17 @@ namespace llvm {
typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T, typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
StringRef TT); StringRef TT);
typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT, Reloc::Model M);
typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void); typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT); typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT, typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
StringRef CPU, StringRef CPU,
StringRef Features); StringRef Features);
typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T, typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
const std::string &TT, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &Features); StringRef Features,
Reloc::Model RM);
typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM, typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
MCStreamer &Streamer); MCStreamer &Streamer);
typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T, typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
@ -132,6 +136,10 @@ namespace llvm {
/// registered. /// registered.
MCAsmInfoCtorFnTy MCAsmInfoCtorFn; MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
/// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
/// if registered.
MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
/// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo, /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
/// if registered. /// if registered.
MCInstrInfoCtorFnTy MCInstrInfoCtorFn; MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
@ -253,6 +261,14 @@ namespace llvm {
return MCAsmInfoCtorFn(*this, Triple); return MCAsmInfoCtorFn(*this, Triple);
} }
/// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
///
MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model M) const {
if (!MCCodeGenInfoCtorFn)
return 0;
return MCCodeGenInfoCtorFn(Triple, M);
}
/// createMCInstrInfo - Create a MCInstrInfo implementation. /// createMCInstrInfo - Create a MCInstrInfo implementation.
/// ///
MCInstrInfo *createMCInstrInfo() const { MCInstrInfo *createMCInstrInfo() const {
@ -292,12 +308,12 @@ namespace llvm {
/// feature set; it should always be provided. Generally this should be /// feature set; it should always be provided. Generally this should be
/// either the target triple from the module, or the target triple of the /// either the target triple from the module, or the target triple of the
/// host if that does not exist. /// host if that does not exist.
TargetMachine *createTargetMachine(const std::string &Triple, TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
const std::string &CPU, StringRef Features,
const std::string &Features) const { Reloc::Model RM = Reloc::Default) const {
if (!TargetMachineCtorFn) if (!TargetMachineCtorFn)
return 0; return 0;
return TargetMachineCtorFn(*this, Triple, CPU, Features); return TargetMachineCtorFn(*this, Triple, CPU, Features, RM);
} }
/// createAsmBackend - Create a target specific assembly parser. /// createAsmBackend - Create a target specific assembly parser.
@ -500,6 +516,22 @@ namespace llvm {
T.MCAsmInfoCtorFn = Fn; T.MCAsmInfoCtorFn = Fn;
} }
/// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
/// given target.
///
/// Clients are responsible for ensuring that registration doesn't occur
/// while another thread is attempting to access the registry. Typically
/// this is done by initializing all targets at program startup.
///
/// @param T - The target being registered.
/// @param Fn - A function to construct a MCCodeGenInfo for the target.
static void RegisterMCCodeGenInfo(Target &T,
Target::MCCodeGenInfoCtorFnTy Fn) {
// Ignore duplicate registration.
if (!T.MCCodeGenInfoCtorFn)
T.MCCodeGenInfoCtorFn = Fn;
}
/// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
/// given target. /// given target.
/// ///
@ -756,6 +788,39 @@ namespace llvm {
} }
}; };
/// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
/// implementation. This invokes the static "Create" method on the class
/// to actually do the construction. Usage:
///
/// extern "C" void LLVMInitializeFooTarget() {
/// extern Target TheFooTarget;
/// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
/// }
template<class MCCodeGenInfoImpl>
struct RegisterMCCodeGenInfo {
RegisterMCCodeGenInfo(Target &T) {
TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
}
private:
static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model M) {
return new MCCodeGenInfoImpl();
}
};
/// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
/// info implementation. This invokes the specified function to do the
/// construction. Usage:
///
/// extern "C" void LLVMInitializeFooTarget() {
/// extern Target TheFooTarget;
/// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
/// }
struct RegisterMCCodeGenInfoFn {
RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
}
};
/// RegisterMCInstrInfo - Helper template for registering a target instruction /// RegisterMCInstrInfo - Helper template for registering a target instruction
/// info implementation. This invokes the static "Create" method on the class /// info implementation. This invokes the static "Create" method on the class
/// to actually do the construction. Usage: /// to actually do the construction. Usage:
@ -871,10 +936,10 @@ namespace llvm {
} }
private: private:
static TargetMachine *Allocator(const Target &T, const std::string &TT, static TargetMachine *Allocator(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU, StringRef FS,
const std::string &FS) { Reloc::Model RM) {
return new TargetMachineImpl(T, TT, CPU, FS); return new TargetMachineImpl(T, TT, CPU, FS, RM);
} }
}; };

View File

@ -30,6 +30,10 @@ extern "C" {
void LLVMInitialize##TargetName##MCAsmInfo(); void LLVMInitialize##TargetName##MCAsmInfo();
#include "llvm/Config/Targets.def" #include "llvm/Config/Targets.def"
#define LLVM_TARGET(TargetName) \
void LLVMInitialize##TargetName##MCCodeGenInfo();
#include "llvm/Config/Targets.def"
#define LLVM_TARGET(TargetName) \ #define LLVM_TARGET(TargetName) \
void LLVMInitialize##TargetName##MCInstrInfo(); void LLVMInitialize##TargetName##MCInstrInfo();
#include "llvm/Config/Targets.def" #include "llvm/Config/Targets.def"
@ -91,6 +95,16 @@ namespace llvm {
#include "llvm/Config/Targets.def" #include "llvm/Config/Targets.def"
} }
/// InitializeAllMCCodeGenInfos - The main program should call this function
/// if it wants access to all targets machines that LLVM is configured to
/// support, to make them available via the TargetRegistry.
///
/// It is legal for a client to make multiple calls to this function.
inline void InitializeAllMCCodeGenInfos() {
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##MCCodeGenInfo();
#include "llvm/Config/Targets.def"
}
/// InitializeAllMCInstrInfos - The main program should call this function /// InitializeAllMCInstrInfos - The main program should call this function
/// if it wants access to all available instruction infos for targets that /// if it wants access to all available instruction infos for targets that
/// LLVM is configured to support, to make them available via the /// LLVM is configured to support, to make them available via the
@ -164,6 +178,7 @@ namespace llvm {
LLVM_NATIVE_TARGETINFO(); LLVM_NATIVE_TARGETINFO();
LLVM_NATIVE_TARGET(); LLVM_NATIVE_TARGET();
LLVM_NATIVE_MCASMINFO(); LLVM_NATIVE_MCASMINFO();
LLVM_NATIVE_MCCODEGENINFO();
return false; return false;
#else #else
return true; return true;

View File

@ -103,8 +103,10 @@ EnableFastISelOption("fast-isel", cl::Hidden,
cl::desc("Enable the \"fast\" instruction selector")); cl::desc("Enable the \"fast\" instruction selector"));
LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple, LLVMTargetMachine::LLVMTargetMachine(const Target &T, StringRef Triple,
StringRef CPU, StringRef FS) StringRef CPU, StringRef FS,
Reloc::Model RM)
: TargetMachine(T, Triple, CPU, FS) { : TargetMachine(T, Triple, CPU, FS) {
CodeGenInfo = T.createMCCodeGenInfo(Triple, RM);
AsmInfo = T.createMCAsmInfo(Triple); AsmInfo = T.createMCAsmInfo(Triple);
} }

View File

@ -422,6 +422,7 @@ ExecutionEngine *ExecutionEngine::createJIT(Module *M,
JITMemoryManager *JMM, JITMemoryManager *JMM,
CodeGenOpt::Level OptLevel, CodeGenOpt::Level OptLevel,
bool GVsWithCode, bool GVsWithCode,
Reloc::Model RM,
CodeModel::Model CMM) { CodeModel::Model CMM) {
if (ExecutionEngine::JITCtor == 0) { if (ExecutionEngine::JITCtor == 0) {
if (ErrorStr) if (ErrorStr)
@ -436,7 +437,7 @@ ExecutionEngine *ExecutionEngine::createJIT(Module *M,
SmallVector<std::string, 1> MAttrs; SmallVector<std::string, 1> MAttrs;
TargetMachine *TM = TargetMachine *TM =
EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs, ErrorStr); EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs, RM, ErrorStr);
if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0; if (!TM || (ErrorStr && ErrorStr->length() > 0)) return 0;
TM->setCodeModel(CMM); TM->setCodeModel(CMM);
@ -465,8 +466,8 @@ ExecutionEngine *EngineBuilder::create() {
// Unless the interpreter was explicitly selected or the JIT is not linked, // Unless the interpreter was explicitly selected or the JIT is not linked,
// try making a JIT. // try making a JIT.
if (WhichEngine & EngineKind::JIT) { if (WhichEngine & EngineKind::JIT) {
if (TargetMachine *TM = if (TargetMachine *TM = EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs,
EngineBuilder::selectTarget(M, MArch, MCPU, MAttrs, ErrorStr)) { RelocModel, ErrorStr)) {
TM->setCodeModel(CMModel); TM->setCodeModel(CMModel);
if (UseMCJIT && ExecutionEngine::MCJITCtor) { if (UseMCJIT && ExecutionEngine::MCJITCtor) {

View File

@ -100,9 +100,10 @@ public:
CodeGenOpt::Level OptLevel = CodeGenOpt::Level OptLevel =
CodeGenOpt::Default, CodeGenOpt::Default,
bool GVsWithCode = true, bool GVsWithCode = true,
Reloc::Model RM = Reloc::Default,
CodeModel::Model CMM = CodeModel::Default) { CodeModel::Model CMM = CodeModel::Default) {
return ExecutionEngine::createJIT(M, Err, JMM, OptLevel, GVsWithCode, return ExecutionEngine::createJIT(M, Err, JMM, OptLevel, GVsWithCode,
CMM); RM, CMM);
} }
virtual void addModule(Module *M); virtual void addModule(Module *M);

View File

@ -30,6 +30,7 @@ TargetMachine *EngineBuilder::selectTarget(Module *Mod,
StringRef MArch, StringRef MArch,
StringRef MCPU, StringRef MCPU,
const SmallVectorImpl<std::string>& MAttrs, const SmallVectorImpl<std::string>& MAttrs,
Reloc::Model RM,
std::string *ErrorStr) { std::string *ErrorStr) {
Triple TheTriple(Mod->getTargetTriple()); Triple TheTriple(Mod->getTargetTriple());
if (TheTriple.getTriple().empty()) if (TheTriple.getTriple().empty())
@ -83,8 +84,8 @@ TargetMachine *EngineBuilder::selectTarget(Module *Mod,
} }
// Allocate a target... // Allocate a target...
TargetMachine *Target = TargetMachine *Target = TheTarget->createTargetMachine(TheTriple.getTriple(),
TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, FeaturesStr); MCPU, FeaturesStr, RM);
assert(Target && "Could not allocate target machine!"); assert(Target && "Could not allocate target machine!");
return Target; return Target;
} }

View File

@ -6,6 +6,7 @@ add_llvm_library(LLVMMC
MCAsmStreamer.cpp MCAsmStreamer.cpp
MCAssembler.cpp MCAssembler.cpp
MCCodeEmitter.cpp MCCodeEmitter.cpp
MCCodeGenInfo.cpp
MCContext.cpp MCContext.cpp
MCDisassembler.cpp MCDisassembler.cpp
MCELF.cpp MCELF.cpp

20
lib/MC/MCCodeGenInfo.cpp Normal file
View File

@ -0,0 +1,20 @@
//===-- MCCodeGenInfo.cpp - Target CodeGen Info -----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file tracks information about the target which can affect codegen,
// asm parsing, and asm printing. For example, relocation model.
//
//===----------------------------------------------------------------------===//
#include "llvm/MC/MCCodeGenInfo.h"
using namespace llvm;
void MCCodeGenInfo::InitMCCodeGenInfo(Reloc::Model RM) {
RelocationModel = RM;
}

View File

@ -41,6 +41,7 @@ LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
// FIXME: We shouldn't need to initialize the Target(Machine)s. // FIXME: We shouldn't need to initialize the Target(Machine)s.
llvm::InitializeAllTargets(); llvm::InitializeAllTargets();
llvm::InitializeAllMCAsmInfos(); llvm::InitializeAllMCAsmInfos();
llvm::InitializeAllMCCodeGenInfos();
llvm::InitializeAllMCRegisterInfos(); llvm::InitializeAllMCRegisterInfos();
llvm::InitializeAllAsmPrinters(); llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers(); llvm::InitializeAllAsmParsers();

View File

@ -108,6 +108,7 @@ void EDDisassembler::initialize() {
InitializeAllTargetInfos(); InitializeAllTargetInfos();
InitializeAllTargets(); InitializeAllTargets();
InitializeAllMCCodeGenInfos();
InitializeAllMCAsmInfos(); InitializeAllMCAsmInfos();
InitializeAllMCRegisterInfos(); InitializeAllMCRegisterInfos();
InitializeAllMCSubtargetInfos(); InitializeAllMCSubtargetInfos();

View File

@ -62,25 +62,22 @@ extern "C" void LLVMInitializeARMTarget() {
/// TargetMachine ctor - Create an ARM architecture model. /// TargetMachine ctor - Create an ARM architecture model.
/// ///
ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, StringRef TT,
const std::string &TT, StringRef CPU, StringRef FS,
const std::string &CPU, Reloc::Model RM)
const std::string &FS) : LLVMTargetMachine(T, TT, CPU, FS, RM),
: LLVMTargetMachine(T, TT, CPU, FS),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
JITInfo(), JITInfo(),
InstrItins(Subtarget.getInstrItineraryData()) { InstrItins(Subtarget.getInstrItineraryData()) {
DefRelocModel = getRelocationModel();
// Default to soft float ABI // Default to soft float ABI
if (FloatABIType == FloatABI::Default) if (FloatABIType == FloatABI::Default)
FloatABIType = FloatABI::Soft; FloatABIType = FloatABI::Soft;
} }
ARMTargetMachine::ARMTargetMachine(const Target &T, const std::string &TT, ARMTargetMachine::ARMTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU, StringRef FS,
const std::string &FS) Reloc::Model RM)
: ARMBaseTargetMachine(T, TT, CPU, FS), InstrInfo(Subtarget), : ARMBaseTargetMachine(T, TT, CPU, FS, RM), InstrInfo(Subtarget),
DataLayout(Subtarget.isAPCS_ABI() ? DataLayout(Subtarget.isAPCS_ABI() ?
std::string("e-p:32:32-f64:32:64-i64:32:64-" std::string("e-p:32:32-f64:32:64-i64:32:64-"
"v128:32:128-v64:32:64-n32") : "v128:32:128-v64:32:64-n32") :
@ -95,10 +92,10 @@ ARMTargetMachine::ARMTargetMachine(const Target &T, const std::string &TT,
"support ARM mode execution!"); "support ARM mode execution!");
} }
ThumbTargetMachine::ThumbTargetMachine(const Target &T, const std::string &TT, ThumbTargetMachine::ThumbTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU, StringRef FS,
const std::string &FS) Reloc::Model RM)
: ARMBaseTargetMachine(T, TT, CPU, FS), : ARMBaseTargetMachine(T, TT, CPU, FS, RM),
InstrInfo(Subtarget.hasThumb2() InstrInfo(Subtarget.hasThumb2()
? ((ARMBaseInstrInfo*)new Thumb2InstrInfo(Subtarget)) ? ((ARMBaseInstrInfo*)new Thumb2InstrInfo(Subtarget))
: ((ARMBaseInstrInfo*)new Thumb1InstrInfo(Subtarget))), : ((ARMBaseInstrInfo*)new Thumb1InstrInfo(Subtarget))),
@ -179,10 +176,6 @@ bool ARMBaseTargetMachine::addPreEmitPass(PassManagerBase &PM,
bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM, bool ARMBaseTargetMachine::addCodeEmitter(PassManagerBase &PM,
CodeGenOpt::Level OptLevel, CodeGenOpt::Level OptLevel,
JITCodeEmitter &JCE) { JITCodeEmitter &JCE) {
// FIXME: Move this to TargetJITInfo!
if (DefRelocModel == Reloc::Default)
setRelocationModel(Reloc::Static);
// Machine code emitter pass for ARM. // Machine code emitter pass for ARM.
PM.add(createARMJITCodeEmitterPass(*this, JCE)); PM.add(createARMJITCodeEmitterPass(*this, JCE));
return false; return false;

View File

@ -37,11 +37,10 @@ protected:
private: private:
ARMJITInfo JITInfo; ARMJITInfo JITInfo;
InstrItineraryData InstrItins; InstrItineraryData InstrItins;
Reloc::Model DefRelocModel; // Reloc model before it's overridden.
public: public:
ARMBaseTargetMachine(const Target &T, const std::string &TT, ARMBaseTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual ARMJITInfo *getJITInfo() { return &JITInfo; } virtual ARMJITInfo *getJITInfo() { return &JITInfo; }
virtual const ARMSubtarget *getSubtargetImpl() const { return &Subtarget; } virtual const ARMSubtarget *getSubtargetImpl() const { return &Subtarget; }
@ -69,8 +68,8 @@ class ARMTargetMachine : public ARMBaseTargetMachine {
ARMSelectionDAGInfo TSInfo; ARMSelectionDAGInfo TSInfo;
ARMFrameLowering FrameLowering; ARMFrameLowering FrameLowering;
public: public:
ARMTargetMachine(const Target &T, const std::string &TT, ARMTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const ARMRegisterInfo *getRegisterInfo() const { virtual const ARMRegisterInfo *getRegisterInfo() const {
return &InstrInfo.getRegisterInfo(); return &InstrInfo.getRegisterInfo();
@ -108,8 +107,8 @@ class ThumbTargetMachine : public ARMBaseTargetMachine {
// Either Thumb1FrameLowering or ARMFrameLowering. // Either Thumb1FrameLowering or ARMFrameLowering.
OwningPtr<ARMFrameLowering> FrameLowering; OwningPtr<ARMFrameLowering> FrameLowering;
public: public:
ThumbTargetMachine(const Target &T, const std::string &TT, ThumbTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
/// returns either Thumb1RegisterInfo or Thumb2RegisterInfo /// returns either Thumb1RegisterInfo or Thumb2RegisterInfo
virtual const ARMBaseRegisterInfo *getRegisterInfo() const { virtual const ARMBaseRegisterInfo *getRegisterInfo() const {

View File

@ -15,7 +15,7 @@
#include "llvm/MC/MCParser/MCParsedAsmOperand.h" #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
#include "llvm/Target/TargetAsmLexer.h" #include "llvm/Target/TargetAsmLexer.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h" // FIXME
#include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetRegistry.h"
#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/OwningPtr.h"

View File

@ -142,3 +142,17 @@ extern "C" void LLVMInitializeARMMCAsmInfo() {
RegisterMCAsmInfoFn A(TheARMTarget, createARMMCAsmInfo); RegisterMCAsmInfoFn A(TheARMTarget, createARMMCAsmInfo);
RegisterMCAsmInfoFn B(TheThumbTarget, createARMMCAsmInfo); RegisterMCAsmInfoFn B(TheThumbTarget, createARMMCAsmInfo);
} }
MCCodeGenInfo *createARMMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
if (RM == Reloc::Default)
RM = Reloc::DynamicNoPIC;
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeARMMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheARMTarget, createARMMCCodeGenInfo);
TargetRegistry::RegisterMCCodeGenInfo(TheThumbTarget, createARMMCCodeGenInfo);
}

View File

@ -22,19 +22,17 @@ extern "C" void LLVMInitializeAlphaTarget() {
RegisterTargetMachine<AlphaTargetMachine> X(TheAlphaTarget); RegisterTargetMachine<AlphaTargetMachine> X(TheAlphaTarget);
} }
AlphaTargetMachine::AlphaTargetMachine(const Target &T, const std::string &TT, AlphaTargetMachine::AlphaTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
DataLayout("e-f128:128:128-n64"), DataLayout("e-f128:128:128-n64"),
FrameLowering(Subtarget), FrameLowering(Subtarget),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
TLInfo(*this), TLInfo(*this),
TSInfo(*this) { TSInfo(*this) {
setRelocationModel(Reloc::PIC_);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Pass Pipeline Configuration // Pass Pipeline Configuration
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -36,8 +36,8 @@ class AlphaTargetMachine : public LLVMTargetMachine {
AlphaSelectionDAGInfo TSInfo; AlphaSelectionDAGInfo TSInfo;
public: public:
AlphaTargetMachine(const Target &T, const std::string &TT, AlphaTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const AlphaInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const AlphaInstrInfo *getInstrInfo() const { return &InstrInfo; }
virtual const TargetFrameLowering *getFrameLowering() const { virtual const TargetFrameLowering *getFrameLowering() const {

View File

@ -65,3 +65,15 @@ extern "C" void LLVMInitializeAlphaMCSubtargetInfo() {
extern "C" void LLVMInitializeAlphaMCAsmInfo() { extern "C" void LLVMInitializeAlphaMCAsmInfo() {
RegisterMCAsmInfo<AlphaMCAsmInfo> X(TheAlphaTarget); RegisterMCAsmInfo<AlphaMCAsmInfo> X(TheAlphaTarget);
} }
MCCodeGenInfo *createAlphaMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
X->InitMCCodeGenInfo(Reloc::PIC_);
return X;
}
extern "C" void LLVMInitializeAlphaMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheAlphaTarget,
createAlphaMCCodeGenInfo);
}

View File

@ -22,10 +22,10 @@ extern "C" void LLVMInitializeBlackfinTarget() {
} }
BlackfinTargetMachine::BlackfinTargetMachine(const Target &T, BlackfinTargetMachine::BlackfinTargetMachine(const Target &T,
const std::string &TT, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
DataLayout("e-p:32:32-i64:32-f64:32-n32"), DataLayout("e-p:32:32-i64:32-f64:32-n32"),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
TLInfo(*this), TLInfo(*this),

View File

@ -35,8 +35,8 @@ namespace llvm {
BlackfinFrameLowering FrameLowering; BlackfinFrameLowering FrameLowering;
BlackfinIntrinsicInfo IntrinsicInfo; BlackfinIntrinsicInfo IntrinsicInfo;
public: public:
BlackfinTargetMachine(const Target &T, const std::string &TT, BlackfinTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const BlackfinInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const BlackfinInstrInfo *getInstrInfo() const { return &InstrInfo; }
virtual const TargetFrameLowering *getFrameLowering() const { virtual const TargetFrameLowering *getFrameLowering() const {

View File

@ -68,3 +68,14 @@ extern "C" void LLVMInitializeBlackfinMCSubtargetInfo() {
extern "C" void LLVMInitializeBlackfinMCAsmInfo() { extern "C" void LLVMInitializeBlackfinMCAsmInfo() {
RegisterMCAsmInfo<BlackfinMCAsmInfo> X(TheBlackfinTarget); RegisterMCAsmInfo<BlackfinMCAsmInfo> X(TheBlackfinTarget);
} }
MCCodeGenInfo *createBlackfinMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeBlackfinMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheBlackfinTarget,
createBlackfinMCCodeGenInfo);
}

View File

@ -71,6 +71,8 @@ extern "C" void LLVMInitializeCBackendMCInstrInfo() {}
extern "C" void LLVMInitializeCBackendMCSubtargetInfo() {} extern "C" void LLVMInitializeCBackendMCSubtargetInfo() {}
extern "C" void LLVMInitializeCBackendMCCodeGenInfo() {}
namespace { namespace {
class CBEMCAsmInfo : public MCAsmInfo { class CBEMCAsmInfo : public MCAsmInfo {
public: public:

View File

@ -20,8 +20,8 @@
namespace llvm { namespace llvm {
struct CTargetMachine : public TargetMachine { struct CTargetMachine : public TargetMachine {
CTargetMachine(const Target &T, const std::string &TT, CTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS) StringRef CPU, StringRef FS, Reloc::Model RM)
: TargetMachine(T, TT, CPU, FS) {} : TargetMachine(T, TT, CPU, FS) {}
virtual bool addPassesToEmitFile(PassManagerBase &PM, virtual bool addPassesToEmitFile(PassManagerBase &PM,

View File

@ -77,3 +77,16 @@ static MCAsmInfo *createSPUMCAsmInfo(const Target &T, StringRef TT) {
extern "C" void LLVMInitializeCellSPUMCAsmInfo() { extern "C" void LLVMInitializeCellSPUMCAsmInfo() {
RegisterMCAsmInfoFn X(TheCellSPUTarget, createSPUMCAsmInfo); RegisterMCAsmInfoFn X(TheCellSPUTarget, createSPUMCAsmInfo);
} }
MCCodeGenInfo *createSPUMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
// For the time being, use static relocations, since there's really no
// support for PIC yet.
X->InitMCCodeGenInfo(Reloc::Static);
return X;
}
extern "C" void LLVMInitializeCellSPUMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheCellSPUTarget,
createSPUMCCodeGenInfo);
}

View File

@ -31,9 +31,9 @@ SPUFrameLowering::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
return &LR[0]; return &LR[0];
} }
SPUTargetMachine::SPUTargetMachine(const Target &T, const std::string &TT, SPUTargetMachine::SPUTargetMachine(const Target &T, StringRef TT,
const std::string &CPU,const std::string &FS) StringRef CPU,StringRef FS, Reloc::Model RM)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
DataLayout(Subtarget.getTargetDataString()), DataLayout(Subtarget.getTargetDataString()),
InstrInfo(*this), InstrInfo(*this),
@ -41,9 +41,6 @@ SPUTargetMachine::SPUTargetMachine(const Target &T, const std::string &TT,
TLInfo(*this), TLInfo(*this),
TSInfo(*this), TSInfo(*this),
InstrItins(Subtarget.getInstrItineraryData()) { InstrItins(Subtarget.getInstrItineraryData()) {
// For the time being, use static relocations, since there's really no
// support for PIC yet.
setRelocationModel(Reloc::Static);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -38,8 +38,8 @@ class SPUTargetMachine : public LLVMTargetMachine {
SPUSelectionDAGInfo TSInfo; SPUSelectionDAGInfo TSInfo;
InstrItineraryData InstrItins; InstrItineraryData InstrItins;
public: public:
SPUTargetMachine(const Target &T, const std::string &TT, SPUTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
/// Return the subtarget implementation object /// Return the subtarget implementation object
virtual const SPUSubtarget *getSubtargetImpl() const { virtual const SPUSubtarget *getSubtargetImpl() const {

View File

@ -85,6 +85,8 @@ extern "C" void LLVMInitializeCppBackendMCInstrInfo() {}
extern "C" void LLVMInitializeCppBackendMCSubtargetInfo() {} extern "C" void LLVMInitializeCppBackendMCSubtargetInfo() {}
extern "C" void LLVMInitializeCppBackendMCCodeGenInfo() {}
namespace { namespace {
typedef std::vector<Type*> TypeList; typedef std::vector<Type*> TypeList;
typedef std::map<Type*,std::string> TypeMap; typedef std::map<Type*,std::string> TypeMap;

View File

@ -22,8 +22,8 @@ namespace llvm {
class formatted_raw_ostream; class formatted_raw_ostream;
struct CPPTargetMachine : public TargetMachine { struct CPPTargetMachine : public TargetMachine {
CPPTargetMachine(const Target &T, const std::string &TT, CPPTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS) StringRef CPU, StringRef FS, Reloc::Model RM)
: TargetMachine(T, TT, CPU, FS) {} : TargetMachine(T, TT, CPU, FS) {}
virtual bool addPassesToEmitFile(PassManagerBase &PM, virtual bool addPassesToEmitFile(PassManagerBase &PM,

View File

@ -19,7 +19,7 @@
#include "llvm/MC/MCParser/MCParsedAsmOperand.h" #include "llvm/MC/MCParser/MCParsedAsmOperand.h"
#include "llvm/Target/TargetAsmLexer.h" #include "llvm/Target/TargetAsmLexer.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h" // FIXME
#include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetRegistry.h"
#include <string> #include <string>

View File

@ -67,19 +67,15 @@ extern "C" void LLVMInitializeMBlazeTarget() {
// offset from the stack/frame pointer, using StackGrowsUp enables // offset from the stack/frame pointer, using StackGrowsUp enables
// an easier handling. // an easier handling.
MBlazeTargetMachine:: MBlazeTargetMachine::
MBlazeTargetMachine(const Target &T, const std::string &TT, MBlazeTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS): StringRef CPU, StringRef FS, Reloc::Model RM):
LLVMTargetMachine(T, TT, CPU, FS), LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
DataLayout("E-p:32:32:32-i8:8:8-i16:16:16"), DataLayout("E-p:32:32:32-i8:8:8-i16:16:16"),
InstrInfo(*this), InstrInfo(*this),
FrameLowering(Subtarget), FrameLowering(Subtarget),
TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this), TLInfo(*this), TSInfo(*this), ELFWriterInfo(*this),
InstrItins(Subtarget.getInstrItineraryData()) { InstrItins(Subtarget.getInstrItineraryData()) {
if (getRelocationModel() == Reloc::Default) {
setRelocationModel(Reloc::Static);
}
if (getCodeModel() == CodeModel::Default) if (getCodeModel() == CodeModel::Default)
setCodeModel(CodeModel::Small); setCodeModel(CodeModel::Small);
} }

View File

@ -41,8 +41,8 @@ namespace llvm {
InstrItineraryData InstrItins; InstrItineraryData InstrItins;
public: public:
MBlazeTargetMachine(const Target &T, const std::string &TT, MBlazeTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const MBlazeInstrInfo *getInstrInfo() const virtual const MBlazeInstrInfo *getInstrInfo() const
{ return &InstrInfo; } { return &InstrInfo; }

View File

@ -74,3 +74,16 @@ static MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
extern "C" void LLVMInitializeMBlazeMCAsmInfo() { extern "C" void LLVMInitializeMBlazeMCAsmInfo() {
RegisterMCAsmInfoFn X(TheMBlazeTarget, createMCAsmInfo); RegisterMCAsmInfoFn X(TheMBlazeTarget, createMCAsmInfo);
} }
MCCodeGenInfo *createMBlazeMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
if (RM == Reloc::Default)
RM = Reloc::Static;
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeMBlazeMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheMBlazeTarget,
createMBlazeMCCodeGenInfo);
}

View File

@ -66,3 +66,14 @@ extern "C" void LLVMInitializeMSP430MCSubtargetInfo() {
extern "C" void LLVMInitializeMSP430MCAsmInfo() { extern "C" void LLVMInitializeMSP430MCAsmInfo() {
RegisterMCAsmInfo<MSP430MCAsmInfo> X(TheMSP430Target); RegisterMCAsmInfo<MSP430MCAsmInfo> X(TheMSP430Target);
} }
MCCodeGenInfo *createMSP430MCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeMSP430MCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheMSP430Target,
createMSP430MCCodeGenInfo);
}

View File

@ -25,10 +25,10 @@ extern "C" void LLVMInitializeMSP430Target() {
} }
MSP430TargetMachine::MSP430TargetMachine(const Target &T, MSP430TargetMachine::MSP430TargetMachine(const Target &T,
const std::string &TT, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
// FIXME: Check TargetData string. // FIXME: Check TargetData string.
DataLayout("e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"), DataLayout("e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"),

View File

@ -38,8 +38,8 @@ class MSP430TargetMachine : public LLVMTargetMachine {
MSP430FrameLowering FrameLowering; MSP430FrameLowering FrameLowering;
public: public:
MSP430TargetMachine(const Target &T, const std::string &TT, MSP430TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const TargetFrameLowering *getFrameLowering() const { virtual const TargetFrameLowering *getFrameLowering() const {
return &FrameLowering; return &FrameLowering;

View File

@ -77,3 +77,24 @@ extern "C" void LLVMInitializeMipsMCAsmInfo() {
RegisterMCAsmInfoFn X(TheMipsTarget, createMipsMCAsmInfo); RegisterMCAsmInfoFn X(TheMipsTarget, createMipsMCAsmInfo);
RegisterMCAsmInfoFn Y(TheMipselTarget, createMipsMCAsmInfo); RegisterMCAsmInfoFn Y(TheMipselTarget, createMipsMCAsmInfo);
} }
MCCodeGenInfo *createMipsMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
if (RM == Reloc::Default) {
// Abicall enables PIC by default
if (TT.find("mipsallegrex") != std::string::npos ||
TT.find("psp") != std::string::npos)
RM = Reloc::Static;
else
RM = Reloc::PIC_;
}
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeMipsMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheMipsTarget,
createMipsMCCodeGenInfo);
TargetRegistry::RegisterMCCodeGenInfo(TheMipselTarget,
createMipsMCCodeGenInfo);
}

View File

@ -31,10 +31,10 @@ extern "C" void LLVMInitializeMipsTarget() {
// an easier handling. // an easier handling.
// Using CodeModel::Large enables different CALL behavior. // Using CodeModel::Large enables different CALL behavior.
MipsTargetMachine:: MipsTargetMachine::
MipsTargetMachine(const Target &T, const std::string &TT, MipsTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS, StringRef CPU, StringRef FS, Reloc::Model RM,
bool isLittle=false): bool isLittle=false):
LLVMTargetMachine(T, TT, CPU, FS), LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS, isLittle), Subtarget(TT, CPU, FS, isLittle),
DataLayout(isLittle ? DataLayout(isLittle ?
std::string("e-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32") : std::string("e-p:32:32:32-i8:8:32-i16:16:32-i64:64:64-n32") :
@ -42,19 +42,12 @@ MipsTargetMachine(const Target &T, const std::string &TT,
InstrInfo(*this), InstrInfo(*this),
FrameLowering(Subtarget), FrameLowering(Subtarget),
TLInfo(*this), TSInfo(*this) { TLInfo(*this), TSInfo(*this) {
// Abicall enables PIC by default
if (getRelocationModel() == Reloc::Default) {
if (Subtarget.isABI_O32())
setRelocationModel(Reloc::PIC_);
else
setRelocationModel(Reloc::Static);
}
} }
MipselTargetMachine:: MipselTargetMachine::
MipselTargetMachine(const Target &T, const std::string &TT, MipselTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS) : StringRef CPU, StringRef FS, Reloc::Model RM) :
MipsTargetMachine(T, TT, CPU, FS, true) {} MipsTargetMachine(T, TT, CPU, FS, RM, true) {}
// Install an instruction selector pass using // Install an instruction selector pass using
// the ISelDag to gen Mips code. // the ISelDag to gen Mips code.

View File

@ -34,9 +34,9 @@ namespace llvm {
MipsTargetLowering TLInfo; MipsTargetLowering TLInfo;
MipsSelectionDAGInfo TSInfo; MipsSelectionDAGInfo TSInfo;
public: public:
MipsTargetMachine(const Target &T, const std::string &TT, MipsTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS, StringRef CPU, StringRef FS,
bool isLittle); Reloc::Model RM, bool isLittle);
virtual const MipsInstrInfo *getInstrInfo() const virtual const MipsInstrInfo *getInstrInfo() const
{ return &InstrInfo; } { return &InstrInfo; }
@ -73,8 +73,8 @@ namespace llvm {
/// ///
class MipselTargetMachine : public MipsTargetMachine { class MipselTargetMachine : public MipsTargetMachine {
public: public:
MipselTargetMachine(const Target &T, const std::string &TT, MipselTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
}; };
} // End llvm namespace } // End llvm namespace

View File

@ -70,3 +70,14 @@ extern "C" void LLVMInitializePTXMCAsmInfo() {
RegisterMCAsmInfo<PTXMCAsmInfo> X(ThePTX32Target); RegisterMCAsmInfo<PTXMCAsmInfo> X(ThePTX32Target);
RegisterMCAsmInfo<PTXMCAsmInfo> Y(ThePTX64Target); RegisterMCAsmInfo<PTXMCAsmInfo> Y(ThePTX64Target);
} }
MCCodeGenInfo *createPTXMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializePTXMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(ThePTX32Target, createPTXMCCodeGenInfo);
TargetRegistry::RegisterMCCodeGenInfo(ThePTX64Target, createPTXMCCodeGenInfo);
}

View File

@ -47,11 +47,11 @@ namespace {
// DataLayout and FrameLowering are filled with dummy data // DataLayout and FrameLowering are filled with dummy data
PTXTargetMachine::PTXTargetMachine(const Target &T, PTXTargetMachine::PTXTargetMachine(const Target &T,
const std::string &TT, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS, StringRef FS,
bool is64Bit) Reloc::Model RM, bool is64Bit)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
DataLayout(is64Bit ? DataLayout64 : DataLayout32), DataLayout(is64Bit ? DataLayout64 : DataLayout32),
Subtarget(TT, CPU, FS, is64Bit), Subtarget(TT, CPU, FS, is64Bit),
FrameLowering(Subtarget), FrameLowering(Subtarget),
@ -59,18 +59,16 @@ PTXTargetMachine::PTXTargetMachine(const Target &T,
TLInfo(*this) { TLInfo(*this) {
} }
PTX32TargetMachine::PTX32TargetMachine(const Target &T, PTX32TargetMachine::PTX32TargetMachine(const Target &T, StringRef TT,
const std::string& TT, StringRef CPU, StringRef FS,
const std::string& CPU, Reloc::Model RM)
const std::string& FS) : PTXTargetMachine(T, TT, CPU, FS, RM, false) {
: PTXTargetMachine(T, TT, CPU, FS, false) {
} }
PTX64TargetMachine::PTX64TargetMachine(const Target &T, PTX64TargetMachine::PTX64TargetMachine(const Target &T, StringRef TT,
const std::string& TT, StringRef CPU, StringRef FS,
const std::string& CPU, Reloc::Model RM)
const std::string& FS) : PTXTargetMachine(T, TT, CPU, FS, RM, true) {
: PTXTargetMachine(T, TT, CPU, FS, true) {
} }
bool PTXTargetMachine::addInstSelector(PassManagerBase &PM, bool PTXTargetMachine::addInstSelector(PassManagerBase &PM,

View File

@ -32,8 +32,8 @@ class PTXTargetMachine : public LLVMTargetMachine {
PTXTargetLowering TLInfo; PTXTargetLowering TLInfo;
public: public:
PTXTargetMachine(const Target &T, const std::string &TT, PTXTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS, StringRef CPU, StringRef FS, Reloc::Model RM,
bool is64Bit); bool is64Bit);
virtual const TargetData *getTargetData() const { return &DataLayout; } virtual const TargetData *getTargetData() const { return &DataLayout; }
@ -61,15 +61,15 @@ class PTXTargetMachine : public LLVMTargetMachine {
class PTX32TargetMachine : public PTXTargetMachine { class PTX32TargetMachine : public PTXTargetMachine {
public: public:
PTX32TargetMachine(const Target &T, const std::string &TT, PTX32TargetMachine(const Target &T, StringRef TT,
const std::string& CPU, const std::string& FS); StringRef CPU, StringRef FS, Reloc::Model RM);
}; // class PTX32TargetMachine }; // class PTX32TargetMachine
class PTX64TargetMachine : public PTXTargetMachine { class PTX64TargetMachine : public PTXTargetMachine {
public: public:
PTX64TargetMachine(const Target &T, const std::string &TT, PTX64TargetMachine(const Target &T, StringRef TT,
const std::string& CPU, const std::string& FS); StringRef CPU, StringRef FS, Reloc::Model RM);
}; // class PTX32TargetMachine }; // class PTX32TargetMachine
} // namespace llvm } // namespace llvm

View File

@ -93,3 +93,22 @@ extern "C" void LLVMInitializePowerPCMCAsmInfo() {
RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo); RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo);
RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo); RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo);
} }
MCCodeGenInfo *createPPCMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
if (RM == Reloc::Default) {
Triple T(TT);
if (T.isOSDarwin())
RM = Reloc::DynamicNoPIC;
else
RM = Reloc::Static;
}
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializePowerPCMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo);
TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo);
}

View File

@ -52,40 +52,32 @@ extern "C" void LLVMInitializePowerPCTarget() {
TargetRegistry::RegisterObjectStreamer(ThePPC64Target, createMCStreamer); TargetRegistry::RegisterObjectStreamer(ThePPC64Target, createMCStreamer);
} }
PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT, StringRef CPU, StringRef FS,
const std::string &CPU, Reloc::Model RM, bool is64Bit)
const std::string &FS, bool is64Bit) : LLVMTargetMachine(T, TT, CPU, FS, RM),
: LLVMTargetMachine(T, TT, CPU, FS),
Subtarget(TT, CPU, FS, is64Bit), Subtarget(TT, CPU, FS, is64Bit),
DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this), DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
FrameLowering(Subtarget), JITInfo(*this, is64Bit), FrameLowering(Subtarget), JITInfo(*this, is64Bit),
TLInfo(*this), TSInfo(*this), TLInfo(*this), TSInfo(*this),
InstrItins(Subtarget.getInstrItineraryData()) { InstrItins(Subtarget.getInstrItineraryData()) {
if (getRelocationModel() == Reloc::Default) {
if (Subtarget.isDarwin())
setRelocationModel(Reloc::DynamicNoPIC);
else
setRelocationModel(Reloc::Static);
}
} }
/// Override this for PowerPC. Tail merging happily breaks up instruction issue /// Override this for PowerPC. Tail merging happily breaks up instruction issue
/// groups, which typically degrades performance. /// groups, which typically degrades performance.
bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; } bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT, PPC32TargetMachine::PPC32TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: PPCTargetMachine(T, TT, CPU, FS, false) { : PPCTargetMachine(T, TT, CPU, FS, RM, false) {
} }
PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT, PPC64TargetMachine::PPC64TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: PPCTargetMachine(T, TT, CPU, FS, true) { : PPCTargetMachine(T, TT, CPU, FS, RM, true) {
} }
@ -110,19 +102,11 @@ bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM, bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
CodeGenOpt::Level OptLevel, CodeGenOpt::Level OptLevel,
JITCodeEmitter &JCE) { JITCodeEmitter &JCE) {
// The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
// FIXME: This should be moved to TargetJITInfo!! // FIXME: This should be moved to TargetJITInfo!!
if (Subtarget.isPPC64()) { if (Subtarget.isPPC64())
// We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
// instructions to materialize arbitrary global variable + function +
// constant pool addresses.
setRelocationModel(Reloc::PIC_);
// Temporary workaround for the inability of PPC64 JIT to handle jump // Temporary workaround for the inability of PPC64 JIT to handle jump
// tables. // tables.
DisableJumpTables = true; DisableJumpTables = true;
} else {
setRelocationModel(Reloc::Static);
}
// Inform the subtarget that we are in JIT mode. FIXME: does this break macho // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
// writing? // writing?

View File

@ -40,9 +40,9 @@ class PPCTargetMachine : public LLVMTargetMachine {
InstrItineraryData InstrItins; InstrItineraryData InstrItins;
public: public:
PPCTargetMachine(const Target &T, const std::string &TT, PPCTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS, StringRef CPU, StringRef FS,
bool is64Bit); Reloc::Model RM, bool is64Bit);
virtual const PPCInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const PPCInstrInfo *getInstrInfo() const { return &InstrInfo; }
virtual const PPCFrameLowering *getFrameLowering() const { virtual const PPCFrameLowering *getFrameLowering() const {
@ -77,16 +77,16 @@ public:
/// ///
class PPC32TargetMachine : public PPCTargetMachine { class PPC32TargetMachine : public PPCTargetMachine {
public: public:
PPC32TargetMachine(const Target &T, const std::string &TT, PPC32TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
}; };
/// PPC64TargetMachine - PowerPC 64-bit target machine. /// PPC64TargetMachine - PowerPC 64-bit target machine.
/// ///
class PPC64TargetMachine : public PPCTargetMachine { class PPC64TargetMachine : public PPCTargetMachine {
public: public:
PPC64TargetMachine(const Target &T, const std::string &TT, PPC64TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -65,3 +65,17 @@ extern "C" void LLVMInitializeSparcMCAsmInfo() {
RegisterMCAsmInfo<SparcELFMCAsmInfo> X(TheSparcTarget); RegisterMCAsmInfo<SparcELFMCAsmInfo> X(TheSparcTarget);
RegisterMCAsmInfo<SparcELFMCAsmInfo> Y(TheSparcV9Target); RegisterMCAsmInfo<SparcELFMCAsmInfo> Y(TheSparcV9Target);
} }
MCCodeGenInfo *createSparcMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeSparcMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheSparcTarget,
createSparcMCCodeGenInfo);
TargetRegistry::RegisterMCCodeGenInfo(TheSparcV9Target,
createSparcMCCodeGenInfo);
}

View File

@ -24,10 +24,10 @@ extern "C" void LLVMInitializeSparcTarget() {
/// SparcTargetMachine ctor - Create an ILP32 architecture model /// SparcTargetMachine ctor - Create an ILP32 architecture model
/// ///
SparcTargetMachine::SparcTargetMachine(const Target &T, const std::string &TT, SparcTargetMachine::SparcTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU, StringRef FS,
const std::string &FS, bool is64bit) Reloc::Model RM, bool is64bit)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS, is64bit), Subtarget(TT, CPU, FS, is64bit),
DataLayout(Subtarget.getDataLayout()), DataLayout(Subtarget.getDataLayout()),
TLInfo(*this), TSInfo(*this), InstrInfo(Subtarget), TLInfo(*this), TSInfo(*this), InstrInfo(Subtarget),
@ -51,15 +51,15 @@ bool SparcTargetMachine::addPreEmitPass(PassManagerBase &PM,
} }
SparcV8TargetMachine::SparcV8TargetMachine(const Target &T, SparcV8TargetMachine::SparcV8TargetMachine(const Target &T,
const std::string &TT, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: SparcTargetMachine(T, TT, CPU, FS, false) { : SparcTargetMachine(T, TT, CPU, FS, RM, false) {
} }
SparcV9TargetMachine::SparcV9TargetMachine(const Target &T, SparcV9TargetMachine::SparcV9TargetMachine(const Target &T,
const std::string &TT, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: SparcTargetMachine(T, TT, CPU, FS, true) { : SparcTargetMachine(T, TT, CPU, FS, RM, true) {
} }

View File

@ -33,9 +33,9 @@ class SparcTargetMachine : public LLVMTargetMachine {
SparcInstrInfo InstrInfo; SparcInstrInfo InstrInfo;
SparcFrameLowering FrameLowering; SparcFrameLowering FrameLowering;
public: public:
SparcTargetMachine(const Target &T, const std::string &TT, SparcTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS, StringRef CPU, StringRef FS,
bool is64bit); Reloc::Model RM, bool is64bit);
virtual const SparcInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const SparcInstrInfo *getInstrInfo() const { return &InstrInfo; }
virtual const TargetFrameLowering *getFrameLowering() const { virtual const TargetFrameLowering *getFrameLowering() const {
@ -62,16 +62,16 @@ public:
/// ///
class SparcV8TargetMachine : public SparcTargetMachine { class SparcV8TargetMachine : public SparcTargetMachine {
public: public:
SparcV8TargetMachine(const Target &T, const std::string &TT, SparcV8TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
}; };
/// SparcV9TargetMachine - Sparc 64-bit target machine /// SparcV9TargetMachine - Sparc 64-bit target machine
/// ///
class SparcV9TargetMachine : public SparcTargetMachine { class SparcV9TargetMachine : public SparcTargetMachine {
public: public:
SparcV9TargetMachine(const Target &T, const std::string &TT, SparcV9TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -67,3 +67,16 @@ extern "C" void LLVMInitializeSystemZMCSubtargetInfo() {
extern "C" void LLVMInitializeSystemZMCAsmInfo() { extern "C" void LLVMInitializeSystemZMCAsmInfo() {
RegisterMCAsmInfo<SystemZMCAsmInfo> X(TheSystemZTarget); RegisterMCAsmInfo<SystemZMCAsmInfo> X(TheSystemZTarget);
} }
MCCodeGenInfo *createSystemZMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
if (RM == Reloc::Default)
RM = Reloc::Static;
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeSystemZMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheSystemZTarget,
createSystemZMCCodeGenInfo);
}

View File

@ -21,18 +21,15 @@ extern "C" void LLVMInitializeSystemZTarget() {
/// SystemZTargetMachine ctor - Create an ILP64 architecture model /// SystemZTargetMachine ctor - Create an ILP64 architecture model
/// ///
SystemZTargetMachine::SystemZTargetMachine(const Target &T, SystemZTargetMachine::SystemZTargetMachine(const Target &T,
const std::string &TT, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
DataLayout("E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-i64:64:64-f32:32:32" DataLayout("E-p:64:64:64-i8:8:16-i16:16:16-i32:32:32-i64:64:64-f32:32:32"
"-f64:64:64-f128:128:128-a0:16:16-n32:64"), "-f64:64:64-f128:128:128-a0:16:16-n32:64"),
InstrInfo(*this), TLInfo(*this), TSInfo(*this), InstrInfo(*this), TLInfo(*this), TSInfo(*this),
FrameLowering(Subtarget) { FrameLowering(Subtarget) {
if (getRelocationModel() == Reloc::Default)
setRelocationModel(Reloc::Static);
} }
bool SystemZTargetMachine::addInstSelector(PassManagerBase &PM, bool SystemZTargetMachine::addInstSelector(PassManagerBase &PM,

View File

@ -37,8 +37,8 @@ class SystemZTargetMachine : public LLVMTargetMachine {
SystemZSelectionDAGInfo TSInfo; SystemZSelectionDAGInfo TSInfo;
SystemZFrameLowering FrameLowering; SystemZFrameLowering FrameLowering;
public: public:
SystemZTargetMachine(const Target &T, const std::string &TT, SystemZTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const TargetFrameLowering *getFrameLowering() const { virtual const TargetFrameLowering *getFrameLowering() const {
return &FrameLowering; return &FrameLowering;

View File

@ -40,7 +40,6 @@ namespace llvm {
bool JITExceptionHandling; bool JITExceptionHandling;
bool JITEmitDebugInfo; bool JITEmitDebugInfo;
bool JITEmitDebugInfoToDisk; bool JITEmitDebugInfoToDisk;
Reloc::Model RelocationModel;
CodeModel::Model CMModel; CodeModel::Model CMModel;
bool GuaranteedTailCallOpt; bool GuaranteedTailCallOpt;
unsigned StackAlignmentOverride; unsigned StackAlignmentOverride;
@ -143,21 +142,6 @@ EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
cl::location(JITEmitDebugInfoToDisk), cl::location(JITEmitDebugInfoToDisk),
cl::init(false)); cl::init(false));
static cl::opt<llvm::Reloc::Model, true>
DefRelocationModel("relocation-model",
cl::desc("Choose relocation model"),
cl::location(RelocationModel),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
static cl::opt<llvm::CodeModel::Model, true> static cl::opt<llvm::CodeModel::Model, true>
DefCodeModel("code-model", DefCodeModel("code-model",
cl::desc("Choose code model"), cl::desc("Choose code model"),
@ -236,13 +220,10 @@ TargetMachine::~TargetMachine() {
/// getRelocationModel - Returns the code generation relocation model. The /// getRelocationModel - Returns the code generation relocation model. The
/// choices are static, PIC, and dynamic-no-pic, and target default. /// choices are static, PIC, and dynamic-no-pic, and target default.
Reloc::Model TargetMachine::getRelocationModel() { Reloc::Model TargetMachine::getRelocationModel() const {
return RelocationModel; if (!CodeGenInfo)
} return Reloc::Default;
return CodeGenInfo->getRelocationModel();
/// setRelocationModel - Sets the code generation relocation model.
void TargetMachine::setRelocationModel(Reloc::Model Model) {
RelocationModel = Model;
} }
/// getCodeModel - Returns the code model. The choices are small, kernel, /// getCodeModel - Returns the code model. The choices are small, kernel,

View File

@ -338,3 +338,50 @@ extern "C" void LLVMInitializeX86MCAsmInfo() {
RegisterMCAsmInfoFn A(TheX86_32Target, createX86MCAsmInfo); RegisterMCAsmInfoFn A(TheX86_32Target, createX86MCAsmInfo);
RegisterMCAsmInfoFn B(TheX86_64Target, createX86MCAsmInfo); RegisterMCAsmInfoFn B(TheX86_64Target, createX86MCAsmInfo);
} }
MCCodeGenInfo *createX86MCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
Triple T(TT);
bool is64Bit = T.getArch() == Triple::x86_64;
if (RM == Reloc::Default) {
// Darwin defaults to PIC in 64 bit mode and dynamic-no-pic in 32 bit mode.
// Win64 requires rip-rel addressing, thus we force it to PIC. Otherwise we
// use static relocation model by default.
if (T.isOSDarwin()) {
if (is64Bit)
RM = Reloc::PIC_;
else
RM = Reloc::DynamicNoPIC;
} else if (T.isOSWindows() && is64Bit)
RM = Reloc::PIC_;
else
RM = Reloc::Static;
}
// ELF and X86-64 don't have a distinct DynamicNoPIC model. DynamicNoPIC
// is defined as a model for code which may be used in static or dynamic
// executables but not necessarily a shared library. On X86-32 we just
// compile in -static mode, in x86-64 we use PIC.
if (RM == Reloc::DynamicNoPIC) {
if (is64Bit)
RM = Reloc::PIC_;
else if (!T.isOSDarwin())
RM = Reloc::Static;
}
// If we are on Darwin, disallow static relocation model in X86-64 mode, since
// the Mach-O file format doesn't support it.
if (RM == Reloc::Static && T.isOSDarwin() && is64Bit)
RM = Reloc::PIC_;
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeX86MCCodeGenInfo() {
// Register the target asm info.
RegisterMCCodeGenInfoFn A(TheX86_32Target, createX86MCCodeGenInfo);
RegisterMCCodeGenInfoFn B(TheX86_64Target, createX86MCCodeGenInfo);
}

View File

@ -65,10 +65,10 @@ extern "C" void LLVMInitializeX86Target() {
} }
X86_32TargetMachine::X86_32TargetMachine(const Target &T, const std::string &TT, X86_32TargetMachine::X86_32TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU, StringRef FS,
const std::string &FS) Reloc::Model RM)
: X86TargetMachine(T, TT, CPU, FS, false), : X86TargetMachine(T, TT, CPU, FS, RM, false),
DataLayout(getSubtargetImpl()->isTargetDarwin() ? DataLayout(getSubtargetImpl()->isTargetDarwin() ?
"e-p:32:32-f64:32:64-i64:32:64-f80:128:128-f128:128:128-n8:16:32" : "e-p:32:32-f64:32:64-i64:32:64-f80:128:128-f128:128:128-n8:16:32" :
(getSubtargetImpl()->isTargetCygMing() || (getSubtargetImpl()->isTargetCygMing() ||
@ -82,10 +82,10 @@ X86_32TargetMachine::X86_32TargetMachine(const Target &T, const std::string &TT,
} }
X86_64TargetMachine::X86_64TargetMachine(const Target &T, const std::string &TT, X86_64TargetMachine::X86_64TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU, StringRef FS,
const std::string &FS) Reloc::Model RM)
: X86TargetMachine(T, TT, CPU, FS, true), : X86TargetMachine(T, TT, CPU, FS, RM, true),
DataLayout("e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128-f128:128:128-n8:16:32:64"), DataLayout("e-p:64:64-s:64-f64:64:64-i64:64:64-f80:128:128-f128:128:128-n8:16:32:64"),
InstrInfo(*this), InstrInfo(*this),
TSInfo(*this), TSInfo(*this),
@ -95,52 +95,13 @@ X86_64TargetMachine::X86_64TargetMachine(const Target &T, const std::string &TT,
/// X86TargetMachine ctor - Create an X86 target. /// X86TargetMachine ctor - Create an X86 target.
/// ///
X86TargetMachine::X86TargetMachine(const Target &T, const std::string &TT, X86TargetMachine::X86TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU, StringRef FS,
const std::string &FS, bool is64Bit) Reloc::Model RM, bool is64Bit)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS, StackAlignmentOverride, is64Bit), Subtarget(TT, CPU, FS, StackAlignmentOverride, is64Bit),
FrameLowering(*this, Subtarget), FrameLowering(*this, Subtarget),
ELFWriterInfo(is64Bit, true) { ELFWriterInfo(is64Bit, true) {
DefRelocModel = getRelocationModel();
// If no relocation model was picked, default as appropriate for the target.
if (getRelocationModel() == Reloc::Default) {
// Darwin defaults to PIC in 64 bit mode and dynamic-no-pic in 32 bit mode.
// Win64 requires rip-rel addressing, thus we force it to PIC. Otherwise we
// use static relocation model by default.
if (Subtarget.isTargetDarwin()) {
if (Subtarget.is64Bit())
setRelocationModel(Reloc::PIC_);
else
setRelocationModel(Reloc::DynamicNoPIC);
} else if (Subtarget.isTargetWin64())
setRelocationModel(Reloc::PIC_);
else
setRelocationModel(Reloc::Static);
}
assert(getRelocationModel() != Reloc::Default &&
"Relocation mode not picked");
// ELF and X86-64 don't have a distinct DynamicNoPIC model. DynamicNoPIC
// is defined as a model for code which may be used in static or dynamic
// executables but not necessarily a shared library. On X86-32 we just
// compile in -static mode, in x86-64 we use PIC.
if (getRelocationModel() == Reloc::DynamicNoPIC) {
if (is64Bit)
setRelocationModel(Reloc::PIC_);
else if (!Subtarget.isTargetDarwin())
setRelocationModel(Reloc::Static);
}
// If we are on Darwin, disallow static relocation model in X86-64 mode, since
// the Mach-O file format doesn't support it.
if (getRelocationModel() == Reloc::Static &&
Subtarget.isTargetDarwin() &&
is64Bit)
setRelocationModel(Reloc::PIC_);
// Determine the PICStyle based on the target selected. // Determine the PICStyle based on the target selected.
if (getRelocationModel() == Reloc::Static) { if (getRelocationModel() == Reloc::Static) {
// Unless we're in PIC or DynamicNoPIC mode, set the PIC style to None. // Unless we're in PIC or DynamicNoPIC mode, set the PIC style to None.
@ -161,10 +122,6 @@ X86TargetMachine::X86TargetMachine(const Target &T, const std::string &TT,
Subtarget.setPICStyle(PICStyles::GOT); Subtarget.setPICStyle(PICStyles::GOT);
} }
// Finally, if we have "none" as our PIC style, force to static mode.
if (Subtarget.getPICStyle() == PICStyles::None)
setRelocationModel(Reloc::Static);
// default to hard float ABI // default to hard float ABI
if (FloatABIType == FloatABI::Default) if (FloatABIType == FloatABI::Default)
FloatABIType = FloatABI::Hard; FloatABIType = FloatABI::Hard;
@ -210,15 +167,6 @@ bool X86TargetMachine::addPreEmitPass(PassManagerBase &PM,
bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM, bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM,
CodeGenOpt::Level OptLevel, CodeGenOpt::Level OptLevel,
JITCodeEmitter &JCE) { JITCodeEmitter &JCE) {
// FIXME: Move this to TargetJITInfo!
// On Darwin, do not override 64-bit setting made in X86TargetMachine().
if (DefRelocModel == Reloc::Default &&
(!Subtarget.isTargetDarwin() || !Subtarget.is64Bit())) {
setRelocationModel(Reloc::Static);
Subtarget.setPICStyle(PICStyles::None);
}
PM.add(createX86JITCodeEmitterPass(*this, JCE)); PM.add(createX86JITCodeEmitterPass(*this, JCE));
return false; return false;

View File

@ -29,12 +29,12 @@
namespace llvm { namespace llvm {
class formatted_raw_ostream; class formatted_raw_ostream;
class StringRef;
class X86TargetMachine : public LLVMTargetMachine { class X86TargetMachine : public LLVMTargetMachine {
X86Subtarget Subtarget; X86Subtarget Subtarget;
X86FrameLowering FrameLowering; X86FrameLowering FrameLowering;
X86ELFWriterInfo ELFWriterInfo; X86ELFWriterInfo ELFWriterInfo;
Reloc::Model DefRelocModel; // Reloc model before it's overridden.
private: private:
// We have specific defaults for X86. // We have specific defaults for X86.
@ -42,9 +42,9 @@ private:
virtual void setCodeModelForStatic(); virtual void setCodeModelForStatic();
public: public:
X86TargetMachine(const Target &T, const std::string &TT, X86TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS, StringRef CPU, StringRef FS,
bool is64Bit); Reloc::Model RM, bool is64Bit);
virtual const X86InstrInfo *getInstrInfo() const { virtual const X86InstrInfo *getInstrInfo() const {
llvm_unreachable("getInstrInfo not implemented"); llvm_unreachable("getInstrInfo not implemented");
@ -87,8 +87,8 @@ class X86_32TargetMachine : public X86TargetMachine {
X86TargetLowering TLInfo; X86TargetLowering TLInfo;
X86JITInfo JITInfo; X86JITInfo JITInfo;
public: public:
X86_32TargetMachine(const Target &T, const std::string &M, X86_32TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const TargetData *getTargetData() const { return &DataLayout; } virtual const TargetData *getTargetData() const { return &DataLayout; }
virtual const X86TargetLowering *getTargetLowering() const { virtual const X86TargetLowering *getTargetLowering() const {
return &TLInfo; return &TLInfo;
@ -113,8 +113,8 @@ class X86_64TargetMachine : public X86TargetMachine {
X86TargetLowering TLInfo; X86TargetLowering TLInfo;
X86JITInfo JITInfo; X86JITInfo JITInfo;
public: public:
X86_64TargetMachine(const Target &T, const std::string &TT, X86_64TargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const TargetData *getTargetData() const { return &DataLayout; } virtual const TargetData *getTargetData() const { return &DataLayout; }
virtual const X86TargetLowering *getTargetLowering() const { virtual const X86TargetLowering *getTargetLowering() const {
return &TLInfo; return &TLInfo;

View File

@ -75,3 +75,14 @@ static MCAsmInfo *createXCoreMCAsmInfo(const Target &T, StringRef TT) {
extern "C" void LLVMInitializeXCoreMCAsmInfo() { extern "C" void LLVMInitializeXCoreMCAsmInfo() {
RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo); RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
} }
MCCodeGenInfo *createXCoreMCCodeGenInfo(StringRef TT, Reloc::Model RM) {
MCCodeGenInfo *X = new MCCodeGenInfo();
X->InitMCCodeGenInfo(RM);
return X;
}
extern "C" void LLVMInitializeXCoreMCCodeGenInfo() {
TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget,
createXCoreMCCodeGenInfo);
}

View File

@ -19,10 +19,10 @@ using namespace llvm;
/// XCoreTargetMachine ctor - Create an ILP32 architecture model /// XCoreTargetMachine ctor - Create an ILP32 architecture model
/// ///
XCoreTargetMachine::XCoreTargetMachine(const Target &T, const std::string &TT, XCoreTargetMachine::XCoreTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, StringRef CPU,
const std::string &FS) StringRef FS, Reloc::Model RM)
: LLVMTargetMachine(T, TT, CPU, FS), : LLVMTargetMachine(T, TT, CPU, FS, RM),
Subtarget(TT, CPU, FS), Subtarget(TT, CPU, FS),
DataLayout("e-p:32:32:32-a0:0:32-f32:32:32-f64:32:32-i1:8:32-i8:8:32-" DataLayout("e-p:32:32:32-a0:0:32-f32:32:32-f64:32:32-i1:8:32-i8:8:32-"
"i16:16:32-i32:32:32-i64:32:32-n32"), "i16:16:32-i32:32:32-i64:32:32-n32"),

View File

@ -32,8 +32,8 @@ class XCoreTargetMachine : public LLVMTargetMachine {
XCoreTargetLowering TLInfo; XCoreTargetLowering TLInfo;
XCoreSelectionDAGInfo TSInfo; XCoreSelectionDAGInfo TSInfo;
public: public:
XCoreTargetMachine(const Target &T, const std::string &TT, XCoreTargetMachine(const Target &T, StringRef TT,
const std::string &CPU, const std::string &FS); StringRef CPU, StringRef FS, Reloc::Model RM);
virtual const XCoreInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const XCoreInstrInfo *getInstrInfo() const { return &InstrInfo; }
virtual const XCoreFrameLowering *getFrameLowering() const { virtual const XCoreFrameLowering *getFrameLowering() const {

View File

@ -1,5 +1,4 @@
; RUN: llc < %s -march=thumb -mattr=+thumb2 | FileCheck %s ; RUN: llc < %s -march=thumb -mattr=+thumb2 | FileCheck %s
; RUN: llc < %s -march=thumb -mattr=+thumb2 | not grep it
; If-conversion defeats the purpose of this test, which is to check CBZ ; If-conversion defeats the purpose of this test, which is to check CBZ
; generation, so use memory barrier instruction to make sure it doesn't ; generation, so use memory barrier instruction to make sure it doesn't
; happen and we get actual branches. ; happen and we get actual branches.

View File

@ -76,6 +76,21 @@ MAttrs("mattr",
cl::desc("Target specific attributes (-mattr=help for details)"), cl::desc("Target specific attributes (-mattr=help for details)"),
cl::value_desc("a1,+a2,-a3,...")); cl::value_desc("a1,+a2,-a3,..."));
static cl::opt<Reloc::Model>
RelocModel("relocation-model",
cl::desc("Choose relocation model"),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
static cl::opt<bool> static cl::opt<bool>
RelaxAll("mc-relax-all", RelaxAll("mc-relax-all",
cl::desc("When used with filetype=obj, " cl::desc("When used with filetype=obj, "
@ -202,6 +217,7 @@ int main(int argc, char **argv) {
// Initialize targets first, so that --version shows registered targets. // Initialize targets first, so that --version shows registered targets.
InitializeAllTargets(); InitializeAllTargets();
InitializeAllMCAsmInfos(); InitializeAllMCAsmInfos();
InitializeAllMCCodeGenInfos();
InitializeAllMCSubtargetInfos(); InitializeAllMCSubtargetInfos();
InitializeAllAsmPrinters(); InitializeAllAsmPrinters();
InitializeAllAsmParsers(); InitializeAllAsmParsers();
@ -272,7 +288,7 @@ int main(int argc, char **argv) {
std::auto_ptr<TargetMachine> std::auto_ptr<TargetMachine>
target(TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, target(TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU,
FeaturesStr)); FeaturesStr, RelocModel));
assert(target.get() && "Could not allocate target machine!"); assert(target.get() && "Could not allocate target machine!");
TargetMachine &Target = *target.get(); TargetMachine &Target = *target.get();

View File

@ -108,6 +108,21 @@ namespace {
NoLazyCompilation("disable-lazy-compilation", NoLazyCompilation("disable-lazy-compilation",
cl::desc("Disable JIT lazy compilation"), cl::desc("Disable JIT lazy compilation"),
cl::init(false)); cl::init(false));
cl::opt<Reloc::Model>
RelocModel("relocation-model",
cl::desc("Choose relocation model"),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
} }
static ExecutionEngine *EE = 0; static ExecutionEngine *EE = 0;
@ -164,6 +179,7 @@ int main(int argc, char **argv, char * const *envp) {
builder.setMArch(MArch); builder.setMArch(MArch);
builder.setMCPU(MCPU); builder.setMCPU(MCPU);
builder.setMAttrs(MAttrs); builder.setMAttrs(MAttrs);
builder.setRelocationModel(RelocModel);
builder.setErrorStr(&ErrorMsg); builder.setErrorStr(&ErrorMsg);
builder.setEngineKind(ForceInterpreter builder.setEngineKind(ForceInterpreter
? EngineKind::Interpreter ? EngineKind::Interpreter

View File

@ -111,6 +111,21 @@ MCPU("mcpu",
cl::value_desc("cpu-name"), cl::value_desc("cpu-name"),
cl::init("")); cl::init(""));
static cl::opt<Reloc::Model>
RelocModel("relocation-model",
cl::desc("Choose relocation model"),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
static cl::opt<bool> static cl::opt<bool>
NoInitialTextSection("n", cl::desc("Don't assume assembly file starts " NoInitialTextSection("n", cl::desc("Don't assume assembly file starts "
"in the text section")); "in the text section"));
@ -321,7 +336,8 @@ static int AssembleInput(const char *ProgName) {
// the .cpu and .code16 directives). // the .cpu and .code16 directives).
OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName, OwningPtr<TargetMachine> TM(TheTarget->createTargetMachine(TripleName,
MCPU, MCPU,
FeaturesStr)); FeaturesStr,
RelocModel));
if (!TM) { if (!TM) {
errs() << ProgName << ": error: could not create target for triple '" errs() << ProgName << ": error: could not create target for triple '"
@ -440,6 +456,7 @@ int main(int argc, char **argv) {
// FIXME: We shouldn't need to initialize the Target(Machine)s. // FIXME: We shouldn't need to initialize the Target(Machine)s.
llvm::InitializeAllTargets(); llvm::InitializeAllTargets();
llvm::InitializeAllMCAsmInfos(); llvm::InitializeAllMCAsmInfos();
llvm::InitializeAllMCCodeGenInfos();
llvm::InitializeAllMCInstrInfos(); llvm::InitializeAllMCInstrInfos();
llvm::InitializeAllMCRegisterInfos(); llvm::InitializeAllMCRegisterInfos();
llvm::InitializeAllMCSubtargetInfos(); llvm::InitializeAllMCSubtargetInfos();

View File

@ -270,6 +270,7 @@ int main(int argc, char **argv) {
// FIXME: We shouldn't need to initialize the Target(Machine)s. // FIXME: We shouldn't need to initialize the Target(Machine)s.
llvm::InitializeAllTargets(); llvm::InitializeAllTargets();
llvm::InitializeAllMCAsmInfos(); llvm::InitializeAllMCAsmInfos();
llvm::InitializeAllMCCodeGenInfos();
llvm::InitializeAllAsmPrinters(); llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers(); llvm::InitializeAllAsmParsers();
llvm::InitializeAllDisassemblers(); llvm::InitializeAllDisassemblers();

View File

@ -75,6 +75,7 @@ LTOCodeGenerator::LTOCodeGenerator()
{ {
InitializeAllTargets(); InitializeAllTargets();
InitializeAllMCAsmInfos(); InitializeAllMCAsmInfos();
InitializeAllMCCodeGenInfos();
InitializeAllMCRegisterInfos(); InitializeAllMCRegisterInfos();
InitializeAllMCSubtargetInfos(); InitializeAllMCSubtargetInfos();
InitializeAllAsmPrinters(); InitializeAllAsmPrinters();
@ -252,15 +253,16 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
// The relocation model is actually a static member of TargetMachine // The relocation model is actually a static member of TargetMachine
// and needs to be set before the TargetMachine is instantiated. // and needs to be set before the TargetMachine is instantiated.
Reloc::Model RelocModel = Reloc::Default;
switch( _codeModel ) { switch( _codeModel ) {
case LTO_CODEGEN_PIC_MODEL_STATIC: case LTO_CODEGEN_PIC_MODEL_STATIC:
TargetMachine::setRelocationModel(Reloc::Static); RelocModel = Reloc::Static;
break; break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC: case LTO_CODEGEN_PIC_MODEL_DYNAMIC:
TargetMachine::setRelocationModel(Reloc::PIC_); RelocModel = Reloc::PIC_;
break; break;
case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC: case LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC:
TargetMachine::setRelocationModel(Reloc::DynamicNoPIC); RelocModel = Reloc::DynamicNoPIC;
break; break;
} }
@ -268,7 +270,8 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
SubtargetFeatures Features; SubtargetFeatures Features;
Features.getDefaultSubtargetFeatures(llvm::Triple(Triple)); Features.getDefaultSubtargetFeatures(llvm::Triple(Triple));
std::string FeatureStr = Features.getString(); std::string FeatureStr = Features.getString();
_target = march->createTargetMachine(Triple, _mCpu, FeatureStr); _target = march->createTargetMachine(Triple, _mCpu, FeatureStr,
RelocModel);
} }
return false; return false;
} }

View File

@ -136,6 +136,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
static bool Initialized = false; static bool Initialized = false;
if (!Initialized) { if (!Initialized) {
InitializeAllTargets(); InitializeAllTargets();
InitializeAllMCCodeGenInfos();
InitializeAllMCAsmInfos(); InitializeAllMCAsmInfos();
InitializeAllMCSubtargetInfos(); InitializeAllMCSubtargetInfos();
InitializeAllAsmParsers(); InitializeAllAsmParsers();