Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.

Added untested support for Thumb target.
This commit is contained in:
Tomas Lindquist Olsen 2008-10-27 17:37:34 +01:00
parent 29dfacde9a
commit 6b9e85df48
4 changed files with 28 additions and 9 deletions

View file

@ -487,7 +487,7 @@ Expression *Mod(Type *type, Expression *e1, Expression *e2)
c = fmodl(e1->toReal(), r2) + fmodl(e1->toImaginary(), r2) * I; c = fmodl(e1->toReal(), r2) + fmodl(e1->toImaginary(), r2) * I;
#elif defined(IN_GCC) #elif defined(IN_GCC)
c = complex_t(e1->toReal() % r2, e1->toImaginary() % r2); c = complex_t(e1->toReal() % r2, e1->toImaginary() % r2);
#elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) #elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) || defined(__thumb__)
// freebsd is kinda messed up. the STABLE branch doesn't support C99's fmodl !?! // freebsd is kinda messed up. the STABLE branch doesn't support C99's fmodl !?!
// arm also doesn't like fmodl // arm also doesn't like fmodl
c = complex_t(fmod(e1->toReal(), r2), fmod(e1->toImaginary(), r2)); c = complex_t(fmod(e1->toReal(), r2), fmod(e1->toImaginary(), r2));
@ -502,7 +502,7 @@ Expression *Mod(Type *type, Expression *e1, Expression *e2)
c = fmodl(e1->toReal(), i2) + fmodl(e1->toImaginary(), i2) * I; c = fmodl(e1->toReal(), i2) + fmodl(e1->toImaginary(), i2) * I;
#elif defined(IN_GCC) #elif defined(IN_GCC)
c = complex_t(e1->toReal() % i2, e1->toImaginary() % i2); c = complex_t(e1->toReal() % i2, e1->toImaginary() % i2);
#elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) #elif (defined(__FreeBSD__) && __FreeBSD_version < 800000) || defined(__arm__) || defined(__thumb__)
// freebsd is kinda messed up. the STABLE branch doesn't support C99's fmodl !?! // freebsd is kinda messed up. the STABLE branch doesn't support C99's fmodl !?!
// arm also doesn't like fmodl // arm also doesn't like fmodl
c = complex_t(fmod(e1->toReal(), i2), fmod(e1->toImaginary(), i2)); c = complex_t(fmod(e1->toReal(), i2), fmod(e1->toImaginary(), i2));

View file

@ -186,7 +186,7 @@ Usage:\n\
\n\ \n\
Codegen control:\n\ Codegen control:\n\
-m<arch> emit code specific to <arch> being one of:\n\ -m<arch> emit code specific to <arch> being one of:\n\
x86 x86-64 ppc32 ppc64\n\ x86 x86-64 ppc32 ppc64 arm thumb\n\
-t<os> emit code specific to <os> being one of:\n\ -t<os> emit code specific to <os> being one of:\n\
Linux, Windows, MacOSX, FreeBSD\n\ Linux, Windows, MacOSX, FreeBSD\n\
\n\ \n\
@ -830,6 +830,8 @@ int main(int argc, char *argv[], char** envp)
global.params.llvmArch = "ppc32"; global.params.llvmArch = "ppc32";
#elif defined(__arm__) #elif defined(__arm__)
global.params.llvmArch = "arm"; global.params.llvmArch = "arm";
#elif defined(__thumb__)
global.params.llvmArch = "thumb";
#else #else
#error #error
#endif #endif
@ -840,7 +842,6 @@ int main(int argc, char *argv[], char** envp)
global.params.isLE = true; global.params.isLE = true;
global.params.is64bit = false; global.params.is64bit = false;
global.params.cpu = ARCHx86; global.params.cpu = ARCHx86;
//global.params.data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-f80:32:32-v64:64:64-v128:128:128-a0:0:64";
if (global.params.useInlineAsm) { if (global.params.useInlineAsm) {
VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86"); VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86");
} }
@ -850,21 +851,18 @@ int main(int argc, char *argv[], char** envp)
global.params.isLE = true; global.params.isLE = true;
global.params.is64bit = true; global.params.is64bit = true;
global.params.cpu = ARCHx86_64; global.params.cpu = ARCHx86_64;
//global.params.data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
} }
else if (strcmp(global.params.llvmArch,"ppc32")==0) { else if (strcmp(global.params.llvmArch,"ppc32")==0) {
VersionCondition::addPredefinedGlobalIdent("PPC"); VersionCondition::addPredefinedGlobalIdent("PPC");
global.params.isLE = false; global.params.isLE = false;
global.params.is64bit = false; global.params.is64bit = false;
global.params.cpu = ARCHppc; global.params.cpu = ARCHppc;
//global.params.data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64";
} }
else if (strcmp(global.params.llvmArch,"ppc64")==0) { else if (strcmp(global.params.llvmArch,"ppc64")==0) {
VersionCondition::addPredefinedGlobalIdent("PPC64"); VersionCondition::addPredefinedGlobalIdent("PPC64");
global.params.isLE = false; global.params.isLE = false;
global.params.is64bit = true; global.params.is64bit = true;
global.params.cpu = ARCHppc_64; global.params.cpu = ARCHppc_64;
//global.params.data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
} }
else if (strcmp(global.params.llvmArch,"arm")==0) { else if (strcmp(global.params.llvmArch,"arm")==0) {
VersionCondition::addPredefinedGlobalIdent("ARM"); VersionCondition::addPredefinedGlobalIdent("ARM");
@ -872,6 +870,12 @@ int main(int argc, char *argv[], char** envp)
global.params.is64bit = false; global.params.is64bit = false;
global.params.cpu = ARCHarm; global.params.cpu = ARCHarm;
} }
else if (strcmp(global.params.llvmArch,"thumb")==0) {
VersionCondition::addPredefinedGlobalIdent("Thumb");
global.params.isLE = true;
global.params.is64bit = false;
global.params.cpu = ARCHthumb;
}
else { else {
assert(0 && "Invalid arch"); assert(0 && "Invalid arch");
} }
@ -927,6 +931,12 @@ int main(int argc, char *argv[], char** envp)
Logger::println("Target triple: %s", global.params.targetTriple); Logger::println("Target triple: %s", global.params.targetTriple);
// build a minimal data layout so llvm can find the target
global.params.dataLayout = global.params.isLE
? (char*)(global.params.is64bit ? "e-p:64:64" : "e-p:32:32")
: (char*)(global.params.is64bit ? "E-p:64:64" : "E-p:32:32");
Logger::println("Layout: %s", global.params.dataLayout);
// Initialization // Initialization
Type::init(); Type::init();
Id::initialize(); Id::initialize();

View file

@ -45,7 +45,8 @@ enum ARCH
ARCHx86_64, ARCHx86_64,
ARCHppc, ARCHppc,
ARCHppc_64, ARCHppc_64,
ARCHarm ARCHarm,
ARCHthumb
}; };
enum OUTPUTFLAG enum OUTPUTFLAG
{ {
@ -161,6 +162,7 @@ struct Param
// target stuff // target stuff
char *targetTriple; char *targetTriple;
char *dataLayout;
}; };
struct Global struct Global

View file

@ -104,6 +104,7 @@ void Module::genobjfile(int multiobj, char** envp)
// set target stuff // set target stuff
ir.module->setTargetTriple(global.params.targetTriple); ir.module->setTargetTriple(global.params.targetTriple);
ir.module->setDataLayout(global.params.dataLayout);
// get the target machine // get the target machine
const llvm::TargetMachineRegistry::entry* MArch; const llvm::TargetMachineRegistry::entry* MArch;
@ -131,7 +132,13 @@ void Module::genobjfile(int multiobj, char** envp)
llvm::TargetMachine &Target = *target.get(); llvm::TargetMachine &Target = *target.get();
gTargetData = Target.getTargetData(); gTargetData = Target.getTargetData();
ir.module->setDataLayout(gTargetData->getStringRepresentation());
// set final data layout
std::string datalayout = gTargetData->getStringRepresentation();
ir.module->setDataLayout(datalayout);
if (Logger::enabled())
Logger::cout() << "Final data layout: " << datalayout << '\n';
assert(memcmp(global.params.dataLayout, datalayout.c_str(), 9) == 0); // "E-p:xx:xx"
// debug info // debug info
if (global.params.symdebug) { if (global.params.symdebug) {