Fix setting and default setting of code model for jit. Do this

by allowing backends to override routines that will default
the JIT and Static code generation to an appropriate code model
for the architecture.

Should fix PR 5773.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91824 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2009-12-21 08:15:29 +00:00
parent 1f1b0f748d
commit f4f43cb501
5 changed files with 58 additions and 16 deletions

View File

@ -292,6 +292,13 @@ protected: // Can only create subclasses.
/// ///
bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level); bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level);
private:
// These routines are used by addPassesToEmitFileFinish and
// addPassesToEmitMachineCode to set the CodeModel if it's still marked
// as default.
virtual void setCodeModelForJIT();
virtual void setCodeModelForStatic();
public: public:
/// addPassesToEmitFile - Add passes to the specified pass manager to get the /// addPassesToEmitFile - Add passes to the specified pass manager to get the

View File

@ -83,7 +83,18 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
AsmInfo = T.createAsmInfo(TargetTriple); AsmInfo = T.createAsmInfo(TargetTriple);
} }
// Set the default code model for the JIT for a generic target.
// FIXME: Is small right here? or .is64Bit() ? Large : Small?
void
LLVMTargetMachine::setCodeModelForJIT() {
setCodeModel(CodeModel::Small);
}
// Set the default code model for static compilation for a generic target.
void
LLVMTargetMachine::setCodeModelForStatic() {
setCodeModel(CodeModel::Small);
}
FileModel::Model FileModel::Model
LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
@ -130,6 +141,9 @@ bool LLVMTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM, bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
MachineCodeEmitter *MCE, MachineCodeEmitter *MCE,
CodeGenOpt::Level OptLevel) { CodeGenOpt::Level OptLevel) {
// Make sure the code model is set.
setCodeModelForStatic();
if (MCE) if (MCE)
addSimpleCodeEmitter(PM, OptLevel, *MCE); addSimpleCodeEmitter(PM, OptLevel, *MCE);
if (PrintEmittedAsm) if (PrintEmittedAsm)
@ -146,6 +160,9 @@ bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM, bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
JITCodeEmitter *JCE, JITCodeEmitter *JCE,
CodeGenOpt::Level OptLevel) { CodeGenOpt::Level OptLevel) {
// Make sure the code model is set.
setCodeModelForJIT();
if (JCE) if (JCE)
addSimpleCodeEmitter(PM, OptLevel, *JCE); addSimpleCodeEmitter(PM, OptLevel, *JCE);
if (PrintEmittedAsm) if (PrintEmittedAsm)
@ -162,6 +179,9 @@ bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM, bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
ObjectCodeEmitter *OCE, ObjectCodeEmitter *OCE,
CodeGenOpt::Level OptLevel) { CodeGenOpt::Level OptLevel) {
// Make sure the code model is set.
setCodeModelForStatic();
if (OCE) if (OCE)
addSimpleCodeEmitter(PM, OptLevel, *OCE); addSimpleCodeEmitter(PM, OptLevel, *OCE);
if (PrintEmittedAsm) if (PrintEmittedAsm)
@ -181,6 +201,9 @@ bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM, bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
MachineCodeEmitter &MCE, MachineCodeEmitter &MCE,
CodeGenOpt::Level OptLevel) { CodeGenOpt::Level OptLevel) {
// Make sure the code model is set.
setCodeModelForJIT();
// Add common CodeGen passes. // Add common CodeGen passes.
if (addCommonCodeGenPasses(PM, OptLevel)) if (addCommonCodeGenPasses(PM, OptLevel))
return true; return true;
@ -203,6 +226,9 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM, bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
JITCodeEmitter &JCE, JITCodeEmitter &JCE,
CodeGenOpt::Level OptLevel) { CodeGenOpt::Level OptLevel) {
// Make sure the code model is set.
setCodeModelForJIT();
// Add common CodeGen passes. // Add common CodeGen passes.
if (addCommonCodeGenPasses(PM, OptLevel)) if (addCommonCodeGenPasses(PM, OptLevel))
return true; return true;

View File

@ -50,11 +50,6 @@ MipsTargetMachine(const Target &T, const std::string &TT, const std::string &FS,
else else
setRelocationModel(Reloc::Static); setRelocationModel(Reloc::Static);
} }
// TODO: create an option to enable long calls, like -mlong-calls,
// that would be our CodeModel::Large. It must not work with Abicall.
if (getCodeModel() == CodeModel::Default)
setCodeModel(CodeModel::Small);
} }
MipselTargetMachine:: MipselTargetMachine::

View File

@ -95,10 +95,6 @@ X86TargetMachine::X86TargetMachine(const Target &T, const std::string &TT,
assert(getRelocationModel() != Reloc::Default && assert(getRelocationModel() != Reloc::Default &&
"Relocation mode not picked"); "Relocation mode not picked");
// If no code model is picked, default to small.
if (getCodeModel() == CodeModel::Default)
setCodeModel(CodeModel::Small);
// ELF and X86-64 don't have a distinct DynamicNoPIC model. DynamicNoPIC // 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 // 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 // executables but not necessarily a shared library. On X86-32 we just
@ -188,10 +184,6 @@ bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM,
Subtarget.setPICStyle(PICStyles::None); Subtarget.setPICStyle(PICStyles::None);
} }
// 64-bit JIT places everything in the same buffer except external functions.
if (Subtarget.is64Bit())
setCodeModel(CodeModel::Large);
PM.add(createX86CodeEmitterPass(*this, MCE)); PM.add(createX86CodeEmitterPass(*this, MCE));
return false; return false;
@ -208,9 +200,6 @@ bool X86TargetMachine::addCodeEmitter(PassManagerBase &PM,
Subtarget.setPICStyle(PICStyles::None); Subtarget.setPICStyle(PICStyles::None);
} }
// 64-bit JIT places everything in the same buffer except external functions.
if (Subtarget.is64Bit())
setCodeModel(CodeModel::Large);
PM.add(createX86JITCodeEmitterPass(*this, JCE)); PM.add(createX86JITCodeEmitterPass(*this, JCE));
@ -244,3 +233,23 @@ bool X86TargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
PM.add(createX86ObjectCodeEmitterPass(*this, OCE)); PM.add(createX86ObjectCodeEmitterPass(*this, OCE));
return false; return false;
} }
void X86TargetMachine::setCodeModelForStatic() {
if (getCodeModel() != CodeModel::Default) return;
// For static codegen, if we're not already set, use Small codegen.
setCodeModel(CodeModel::Small);
}
void X86TargetMachine::setCodeModelForJIT() {
if (getCodeModel() != CodeModel::Default) return;
// 64-bit JIT places everything in the same buffer except external functions.
if (Subtarget.is64Bit())
setCodeModel(CodeModel::Large);
else
setCodeModel(CodeModel::Small);
}

View File

@ -38,6 +38,11 @@ class X86TargetMachine : public LLVMTargetMachine {
X86ELFWriterInfo ELFWriterInfo; X86ELFWriterInfo ELFWriterInfo;
Reloc::Model DefRelocModel; // Reloc model before it's overridden. Reloc::Model DefRelocModel; // Reloc model before it's overridden.
private:
// We have specific defaults for X86.
virtual void setCodeModelForJIT();
virtual void setCodeModelForStatic();
public: public:
X86TargetMachine(const Target &T, const std::string &TT, X86TargetMachine(const Target &T, const std::string &TT,
const std::string &FS, bool is64Bit); const std::string &FS, bool is64Bit);