A few fixes for 64bit

This commit is contained in:
Alexey Prokhin 2011-02-23 12:49:57 +03:00
parent aa5dfdfd4d
commit e921998d75
11 changed files with 45 additions and 25 deletions

View file

@ -977,6 +977,7 @@ void FuncDeclaration::semantic3(Scope *sc)
#else #else
Type *t; Type *t;
#if !IN_LLVM
if (global.params.is64bit) if (global.params.is64bit)
{ // Declare save area for varargs registers { // Declare save area for varargs registers
Type *t = new TypeIdentifier(loc, Id::va_argsave_t); Type *t = new TypeIdentifier(loc, Id::va_argsave_t);
@ -991,6 +992,7 @@ void FuncDeclaration::semantic3(Scope *sc)
v_argsave->parent = this; v_argsave->parent = this;
} }
} }
#endif
if (f->linkage == LINKd) if (f->linkage == LINKd)
{ // Declare _arguments[] { // Declare _arguments[]

View file

@ -360,6 +360,10 @@ namespace x86_64_D_cc {
return false; return false;
Array* fields = &t->sym->fields; Array* fields = &t->sym->fields;
if (fields->dim == 0)
return false;
d_uns64 nextbyte = 0; d_uns64 nextbyte = 0;
for (d_uns64 i = 0; i < fields->dim; i++) { for (d_uns64 i = 0; i < fields->dim; i++) {
VarDeclaration* field = (VarDeclaration*) fields->data[i]; VarDeclaration* field = (VarDeclaration*) fields->data[i];
@ -549,9 +553,8 @@ bool X86_64TargetABI::returnInArg(TypeFunction* tf) {
Type* rt = tf->next->toBasetype(); Type* rt = tf->next->toBasetype();
if (tf->linkage == LINKd) { if (tf->linkage == LINKd) {
assert(rt->ty != Tsarray && "Update calling convention for static array returns");
// All non-structs can be returned in registers. // All non-structs can be returned in registers.
// FIXME: Update calling convention for static array returns
if (rt->ty != Tstruct) if (rt->ty != Tstruct)
return false; return false;
@ -678,12 +681,14 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
} }
} }
#if 0
if (fty.arg_this) { if (fty.arg_this) {
fty.arg_this->attrs |= llvm::Attribute::Nest; fty.arg_this->attrs |= llvm::Attribute::Nest;
} }
if (fty.arg_nest) { if (fty.arg_nest) {
fty.arg_nest->attrs |= llvm::Attribute::Nest; fty.arg_nest->attrs |= llvm::Attribute::Nest;
} }
#endif
Logger::println("x86-64 D ABI: Transforming arguments"); Logger::println("x86-64 D ABI: Transforming arguments");
LOG_SCOPE; LOG_SCOPE;

View file

@ -472,8 +472,8 @@ namespace AsmParserx8632
/* Op_FCmp1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_0 }, /* Op_FCmp1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_0 },
/* Op_FCmpP */ { mfp, 0, 0, FP_Types, 0, Next_Form, Op_FCmpP1 }, // pops /* Op_FCmpP */ { mfp, 0, 0, FP_Types, 0, Next_Form, Op_FCmpP1 }, // pops
/* Op_FCmpP1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_F0_P }, // pops /* Op_FCmpP1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_F0_P }, // pops
/* Op_FCmpFlg */ { rfp, rfp, 0, 0, Clb_Flags }, /* Op_FCmpFlg */ { rfp, 0, 0, 0, Clb_Flags },
/* Op_FCmpFlgP */ { rfp, rfp, 0, 0, Clb_Flags }, // pops /* Op_FCmpFlgP */ { rfp, 0, 0, 0, Clb_Flags }, // pops
/* Op_fld */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_fldR }, /* Op_fld */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_fldR },
/* Op_fldR */ { rfp, 0, 0, 0, Clb_ST }, /* Op_fldR */ { rfp, 0, 0, 0, Clb_ST },
/* Op_fxch */ { D|rfp,D|rfp, 0, 0, Clb_ST, Next_Form, Op_fxch1 }, // not in intel manual?, but DMD allows it (gas won't), second arg must be ST /* Op_fxch */ { D|rfp,D|rfp, 0, 0, Clb_ST, Next_Form, Op_fxch1 }, // not in intel manual?, but DMD allows it (gas won't), second arg must be ST

View file

@ -549,8 +549,8 @@ namespace AsmParserx8664
/* Op_FCmp1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_0 }, /* Op_FCmp1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_0 },
/* Op_FCmpP */ { mfp, 0, 0, FP_Types, 0, Next_Form, Op_FCmpP1 }, // pops /* Op_FCmpP */ { mfp, 0, 0, FP_Types, 0, Next_Form, Op_FCmpP1 }, // pops
/* Op_FCmpP1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_F0_P }, // pops /* Op_FCmpP1 */ { rfp, 0, 0, 0, 0, Next_Form, Op_F0_P }, // pops
/* Op_FCmpFlg */ { rfp, rfp, 0, 0, Clb_Flags }, /* Op_FCmpFlg */ { rfp, 0, 0, 0, Clb_Flags },
/* Op_FCmpFlgP */ { rfp, rfp, 0, 0, Clb_Flags }, // pops /* Op_FCmpFlgP */ { rfp, 0, 0, 0, Clb_Flags }, // pops
/* Op_fld */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_fldR }, /* Op_fld */ { mfp, 0, 0, FP_Types, Clb_ST, Next_Form, Op_fldR },
/* Op_fldR */ { rfp, 0, 0, 0, Clb_ST }, /* Op_fldR */ { rfp, 0, 0, 0, Clb_ST },
/* Op_fxch */ { D|rfp,D|rfp, 0, 0, Clb_ST, Next_Form, Op_fxch1 }, // not in intel manual?, but DMD allows it (gas won't), second arg must be ST /* Op_fxch */ { D|rfp,D|rfp, 0, 0, Clb_ST, Next_Form, Op_fxch1 }, // not in intel manual?, but DMD allows it (gas won't), second arg must be ST
@ -1106,6 +1106,7 @@ namespace AsmParserx8664
{ "pmulhw", Op_DstSrcMMX }, { "pmulhw", Op_DstSrcMMX },
{ "pmullw", Op_DstSrcMMX }, { "pmullw", Op_DstSrcMMX },
{ "pmuludq", Op_DstSrcMMX }, // also sse { "pmuludq", Op_DstSrcMMX }, // also sse
{ "pop", Op_DstW },
{ "popf", Op_SizedStack }, // rewrite the insn with a special case { "popf", Op_SizedStack }, // rewrite the insn with a special case
{ "popfq", Op_SizedStack }, { "popfq", Op_SizedStack },
{ "popq", Op_push }, { "popq", Op_push },
@ -1150,6 +1151,7 @@ namespace AsmParserx8664
{ "punpckldq", Op_DstSrcMMX }, { "punpckldq", Op_DstSrcMMX },
{ "punpcklqdq",Op_DstSrcMMX }, { "punpcklqdq",Op_DstSrcMMX },
{ "punpcklwd", Op_DstSrcMMX }, { "punpcklwd", Op_DstSrcMMX },
{ "push", Op_push },
{ "pushf", Op_SizedStack }, { "pushf", Op_SizedStack },
{ "pushfq", Op_SizedStack }, { "pushfq", Op_SizedStack },
{ "pushq", Op_push }, { "pushq", Op_push },

View file

@ -117,12 +117,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
lidx++; lidx++;
} }
} }
#if DMDV2
else
{
fty.c_vararg = true;
}
#else
else if (f->linkage == LINKc) else if (f->linkage == LINKc)
{ {
fty.c_vararg = true; fty.c_vararg = true;
@ -132,7 +126,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
type->error(0, "invalid linkage for variadic function"); type->error(0, "invalid linkage for variadic function");
fatal(); fatal();
} }
#endif
} }
// if this _Dmain() doesn't have an argument, we force it to have one // if this _Dmain() doesn't have an argument, we force it to have one

View file

@ -1592,9 +1592,9 @@ size_t realignOffset(size_t offset, Type* type)
// if it differs we need to insert manual padding as well // if it differs we need to insert manual padding as well
if (alignsize != alignsize2) if (alignsize != alignsize2)
{ {
assert(alignsize > alignsize2 && "this is not good, the D and LLVM " //assert(alignsize > alignsize2 && "this is not good, the D and LLVM "
"type alignments differ, but LLVM's is bigger! This will break " // "type alignments differ, but LLVM's is bigger! This will break "
"aggregate type mapping"); // "aggregate type mapping");
// don't try and align the offset, and let the mappers pad 100% manually // don't try and align the offset, and let the mappers pad 100% manually
return offset; return offset;
} }

View file

@ -353,7 +353,7 @@ LLType* DtoUnpaddedStructType(Type* dty) {
CacheT::iterator it = cache->find(dty); CacheT::iterator it = cache->find(dty);
if (it != cache->end()) if (it != cache->end())
return it->second; return it->second;
TypeStruct* sty = (TypeStruct*) dty; TypeStruct* sty = (TypeStruct*) dty;
Array& fields = sty->sym->fields; Array& fields = sty->sym->fields;

View file

@ -491,7 +491,10 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
Logger::cout() << "expects: " << *callableTy->getParamType(j) << '\n'; Logger::cout() << "expects: " << *callableTy->getParamType(j) << '\n';
} }
#endif #endif
arg = DtoBitCast(arg, callableTy->getParamType(j)); if (isaStruct(arg))
arg = DtoAggrPaint(arg, callableTy->getParamType(j));
else
arg = DtoBitCast(arg, callableTy->getParamType(j));
} }
// param attrs // param attrs

View file

@ -682,7 +682,8 @@ void TypeInfoStructDeclaration::llvmDefine()
ClassDeclaration* tscd = Type::typeinfostruct; ClassDeclaration* tscd = Type::typeinfostruct;
assert(tscd->fields.dim == 11); assert((!global.params.is64bit && tscd->fields.dim == 11) ||
(global.params.is64bit && tscd->fields.dim == 13));
// const(MemberInfo[]) function(in char[]) xgetMembers; // const(MemberInfo[]) function(in char[]) xgetMembers;
b.push_funcptr(sd->findGetMembers()); b.push_funcptr(sd->findGetMembers());
@ -694,7 +695,24 @@ void TypeInfoStructDeclaration::llvmDefine()
b.push_funcptr(sd->postblit); b.push_funcptr(sd->postblit);
//uint m_align; //uint m_align;
b.push_uint(0); // FIXME b.push_uint(tc->alignsize());
if (global.params.is64bit)
{
TypeTuple *tup = tc->toArgTypes();
assert(tup->arguments->dim <= 2);
for (int i = 0; i < 2; i++)
{
if (i < tup->arguments->dim)
{
Type *targ = ((Parameter *)tup->arguments->data[i])->type;
targ = targ->merge();
b.push_typeinfo(targ);
}
else
b.push_null(Type::typeinfo->type);
}
}
#endif #endif

View file

@ -16,7 +16,7 @@
IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, unsigned a) IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, unsigned a)
{ {
type = t; type = t;
ltype = bref ? DtoType(t->pointerTo()) : DtoType(t); ltype = t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t);
attrs = a; attrs = a;
byref = bref; byref = bref;
rewrite = NULL; rewrite = NULL;

View file

@ -71,6 +71,7 @@ elseif(D_VERSION EQUAL 2)
file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d) file(GLOB_RECURSE DCRT_D ${RUNTIME_DC_DIR}/*.d)
file(GLOB_RECURSE LDC_D ${RUNTIME_DIR}/src/ldc/*.d) file(GLOB_RECURSE LDC_D ${RUNTIME_DIR}/src/ldc/*.d)
list(REMOVE_ITEM DCRT_D list(REMOVE_ITEM DCRT_D
${RUNTIME_DC_DIR}/alloca.d
${RUNTIME_DC_DIR}/arraybyte.d ${RUNTIME_DC_DIR}/arraybyte.d
${RUNTIME_DC_DIR}/arraycast.d ${RUNTIME_DC_DIR}/arraycast.d
${RUNTIME_DC_DIR}/arraycat.d ${RUNTIME_DC_DIR}/arraycat.d
@ -261,8 +262,6 @@ set_target_properties(
LINKER_LANGUAGE C LINKER_LANGUAGE C
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
COMPILE_FLAGS "-m32"
LINK_FLAGS "-m32"
) )
# BCLIBS is empty if BUILD_BC_LIBS is not selected # BCLIBS is empty if BUILD_BC_LIBS is not selected
@ -280,7 +279,5 @@ if(PHOBOS2_DIR)
LINKER_LANGUAGE C LINKER_LANGUAGE C
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib
COMPILE_FLAGS "-m32"
LINK_FLAGS "-m32"
) )
endif(PHOBOS2_DIR) endif(PHOBOS2_DIR)