Skip to content

Commit

Permalink
Introduce MCCodeGenInfo, which keeps information that can affect codegen
Browse files Browse the repository at this point in the history
(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
  • Loading branch information
Evan Cheng committed Jul 19, 2011
1 parent 939ece1 commit 4396613
Show file tree
Hide file tree
Showing 74 changed files with 641 additions and 314 deletions.
3 changes: 3 additions & 0 deletions autoconf/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ for a_target in $TARGETS_TO_BUILD; do
LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target"
LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo"
LLVM_NATIVE_MCASMINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo"
LLVM_NATIVE_MCCODEGENINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCCodeGenInfo"
LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter"
if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then
LLVM_NATIVE_ASMPARSER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser"
Expand All @@ -669,6 +670,8 @@ for a_target in $TARGETS_TO_BUILD; do
[LLVM name for the native TargetInfo init function, if available])
AC_DEFINE_UNQUOTED(LLVM_NATIVE_MCASMINFO, $LLVM_NATIVE_MCASMINFO,
[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,
[LLVM name for the native AsmPrinter init function, if available])
if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then
Expand Down
1 change: 1 addition & 0 deletions cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ else ()
set(LLVM_NATIVE_TARGET LLVMInitialize${LLVM_NATIVE_ARCH}Target)
set(LLVM_NATIVE_TARGETINFO LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo)
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)
endif ()

Expand Down
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -5121,6 +5121,7 @@ _ACEOF
LLVM_NATIVE_TARGET="LLVMInitialize${LLVM_NATIVE_ARCH}Target"
LLVM_NATIVE_TARGETINFO="LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo"
LLVM_NATIVE_MCASMINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCAsmInfo"
LLVM_NATIVE_MCCODEGENINFO="LLVMInitialize${LLVM_NATIVE_ARCH}MCCodeGenInfo"
LLVM_NATIVE_ASMPRINTER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter"
if test -f ${srcdir}/lib/Target/${LLVM_NATIVE_ARCH}/AsmParser/Makefile ; then
LLVM_NATIVE_ASMPARSER="LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser"
Expand All @@ -5141,6 +5142,11 @@ cat >>confdefs.h <<_ACEOF
_ACEOF


cat >>confdefs.h <<_ACEOF
#define LLVM_NATIVE_MCCODEGENINFO $LLVM_NATIVE_MCCODEGENINFO
_ACEOF


cat >>confdefs.h <<_ACEOF
#define LLVM_NATIVE_ASMPRINTER $LLVM_NATIVE_ASMPRINTER
_ACEOF
Expand Down
6 changes: 6 additions & 0 deletions include/llvm-c/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ typedef struct LLVMStructLayout *LLVMStructLayoutRef;
#include "llvm/Config/Targets.def"
#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
it wants access to all available targets that LLVM is configured to
support. */
Expand Down Expand Up @@ -73,6 +78,7 @@ static inline LLVMBool LLVMInitializeNativeTarget(void) {
LLVM_NATIVE_TARGETINFO();
LLVM_NATIVE_TARGET();
LLVM_NATIVE_MCASMINFO();
LLVM_NATIVE_MCCODEGENINFO();
return 0;
#else
return 1;
Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Config/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */
#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 */
#cmakedefine LLVM_ON_UNIX ${LLVM_ON_UNIX}

Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Config/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */
#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 */
#undef LLVM_NATIVE_TARGET

Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Config/llvm-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */
#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 */
#cmakedefine LLVM_NATIVE_ASMPRINTER LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter

Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Config/llvm-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
/* LLVM name for the native MCAsmInfo init function, if available */
#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 */
#undef LLVM_NATIVE_ASMPRINTER

Expand Down
12 changes: 12 additions & 0 deletions include/llvm/ExecutionEngine/ExecutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <vector>
#include <map>
#include <string>
#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/ValueMap.h"
Expand Down Expand Up @@ -201,6 +202,7 @@ class ExecutionEngine {
CodeGenOpt::Level OptLevel =
CodeGenOpt::Default,
bool GVsWithCode = true,
Reloc::Model RM = Reloc::Default,
CodeModel::Model CMM =
CodeModel::Default);

Expand Down Expand Up @@ -463,6 +465,7 @@ class EngineBuilder {
CodeGenOpt::Level OptLevel;
JITMemoryManager *JMM;
bool AllocateGVsWithCode;
Reloc::Model RelocModel;
CodeModel::Model CMModel;
std::string MArch;
std::string MCPU;
Expand All @@ -476,6 +479,7 @@ class EngineBuilder {
OptLevel = CodeGenOpt::Default;
JMM = NULL;
AllocateGVsWithCode = false;
RelocModel = Reloc::Default;
CMModel = CodeModel::Default;
UseMCJIT = false;
}
Expand Down Expand Up @@ -517,6 +521,13 @@ class EngineBuilder {
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
/// data is using. Defaults to target specific default "CodeModel::Default".
EngineBuilder &setCodeModel(CodeModel::Model M) {
Expand Down Expand Up @@ -569,6 +580,7 @@ class EngineBuilder {
StringRef MArch,
StringRef MCPU,
const SmallVectorImpl<std::string>& MAttrs,
Reloc::Model RM,
std::string *Err);

ExecutionEngine *create();
Expand Down
36 changes: 36 additions & 0 deletions include/llvm/MC/MCCodeGenInfo.h
Original file line number Diff line number Diff line change
@@ -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
24 changes: 8 additions & 16 deletions include/llvm/Target/TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef LLVM_TARGET_TARGETMACHINE_H
#define LLVM_TARGET_TARGETMACHINE_H

#include "llvm/MC/MCCodeGenInfo.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
#include <string>
Expand All @@ -23,6 +24,7 @@ namespace llvm {
class InstrItineraryData;
class JITCodeEmitter;
class MCAsmInfo;
class MCCodeGenInfo;
class MCContext;
class Pass;
class PassManager;
Expand All @@ -41,16 +43,6 @@ class TargetSubtargetInfo;
class formatted_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.
namespace CodeModel {
enum Model {
Expand Down Expand Up @@ -108,6 +100,10 @@ class TargetMachine {
std::string TargetCPU;
std::string TargetFS;

/// CodeGenInfo - Low level target information such as relocation model.
///
const MCCodeGenInfo *CodeGenInfo;

/// AsmInfo - Contains target specific asm information.
///
const MCAsmInfo *AsmInfo;
Expand Down Expand Up @@ -214,11 +210,7 @@ class TargetMachine {

/// 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);
Reloc::Model getRelocationModel() const;

/// getCodeModel - Returns the code model. The choices are small, kernel,
/// medium, large, and target default.
Expand Down Expand Up @@ -309,7 +301,7 @@ class TargetMachine {
class LLVMTargetMachine : public TargetMachine {
protected: // Can only create subclasses.
LLVMTargetMachine(const Target &T, StringRef TargetTriple,
StringRef CPU, StringRef FS);
StringRef CPU, StringRef FS, Reloc::Model RM);

private:
/// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
Expand Down
Loading

0 comments on commit 4396613

Please sign in to comment.