-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proper ABI implementation support for ccall, and start work on the sa…
…me for cfunction
- Loading branch information
Showing
24 changed files
with
1,645 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===-- abi_llvm.cpp - LLVM Target ABI description --------------*- C++ -*-===// | ||
// | ||
// LDC – the LLVM D compiler | ||
// | ||
// This file is distributed under the BSD-style LDC license. See the LICENSE | ||
// file for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This ABI implementation does whatever LLVM decides is fine. | ||
// It can be useful when first porting Julia to a new platform | ||
// (until a platform-specific implementation can be developed). | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
typedef bool AbiState; | ||
AbiState default_abi_state = 0; | ||
|
||
bool use_sret(AbiState *state,jl_value_t *ty) | ||
{ | ||
return false; | ||
} | ||
|
||
void needPassByRef(AbiState *state,jl_value_t *ty, bool *byRef, bool *inReg) | ||
{ | ||
return; | ||
} | ||
|
||
Type *preferred_llvm_type(jl_value_t *ty, bool isret) | ||
{ | ||
return NULL; | ||
} | ||
|
||
bool need_private_copy(jl_value_t *ty, bool byRef) | ||
{ | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//===-- abi_win64.cpp - Windows x86_64 ABI description ----------*- C++ -*-===// | ||
// | ||
// LDC – the LLVM D compiler | ||
// | ||
// This file is distributed under the BSD-style LDC license. See the LICENSE | ||
// file for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The ABI implementation used for 64 bit x86 (i.e. x86_64/AMD64/x64) targets | ||
// on Windows. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
// Windows only uses the first four registers of either | ||
struct AbiState { | ||
unsigned char int_regs, sse_regs; | ||
}; | ||
|
||
const AbiState default_abi_state = {4,4}; | ||
|
||
|
||
bool use_sret(AbiState *state,jl_value_t *ty) | ||
{ | ||
if(!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty)) | ||
return false; | ||
size_t size = jl_datatype_size(ty); | ||
bool sret = !(size == 1 || size == 2 || size == 4 || size == 8); // || jl_is_sse(ty) if every implemented | ||
if(sret) | ||
state->int_regs--; | ||
return sret; | ||
} | ||
|
||
void needPassByRef(AbiState *state,jl_value_t *ty, bool *byRef, bool *inReg, bool *byRefAttr) | ||
{ | ||
if(!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty)) | ||
return; | ||
if ((jl_datatype_t*)ty == jl_float32_type || (jl_datatype_t*)ty == jl_float64_type) { | ||
state->sse_regs--; | ||
return; | ||
} | ||
size_t size = jl_datatype_size(ty); | ||
*byRef = !(size == 1 || size == 2 || size == 4 || size == 8); // but not sse types | ||
*byRefAttr = *byRef; | ||
if(state->int_regs > 0) { | ||
state->int_regs--; //Windows passes these by pointer | ||
//*inReg = true; | ||
} | ||
} | ||
|
||
Type *preferred_llvm_type(jl_value_t *ty, bool isret) | ||
{ | ||
if(!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty)) | ||
return NULL; | ||
if(jl_is_bitstype(ty)) | ||
return NULL; | ||
size_t size = jl_datatype_size(ty); | ||
if (size == 1 || size == 2 || size == 4 || size == 8) | ||
return T_int64; | ||
return NULL; | ||
} | ||
|
||
// Windows needs all types pased byRef to be passed in caller allocated memory | ||
bool need_private_copy(jl_value_t *ty, bool byRef) | ||
{ | ||
return byRef; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===-- abi_x86.cpp - x86 ABI description -----------------------*- C++ -*-===// | ||
// | ||
// LDC – the LLVM D compiler | ||
// | ||
// This file is distributed under the BSD-style LDC license. See the LICENSE | ||
// file for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// The ABI implementation used for 32 bit x86 targets. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
|
||
typedef bool AbiState; | ||
AbiState default_abi_state = 0; | ||
|
||
inline bool is_complex64(jl_value_t *ty) | ||
{ | ||
return jl_subtype(ty,(jl_value_t*)jl_complex_type,0) && jl_tparam0(ty) == (jl_value_t*)jl_float32_type; | ||
} | ||
|
||
inline bool is_complex128(jl_value_t *ty) | ||
{ | ||
return jl_subtype(ty,(jl_value_t*)jl_complex_type,0) && jl_tparam0(ty) == (jl_value_t*)jl_float64_type; | ||
} | ||
|
||
bool use_sret(AbiState *state,jl_value_t *ty) | ||
{ | ||
if(!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_bitstype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty)) | ||
return false; | ||
if(is_complex64(ty)) | ||
return false; | ||
return jl_is_structtype(ty); | ||
} | ||
|
||
void needPassByRef(AbiState *state,jl_value_t *ty, bool *byRef, bool *inReg, bool *byRefAttr) | ||
{ | ||
if(!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_bitstype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty)) | ||
return; | ||
if(jl_is_structtype(ty) && !need_destructure_argument(ty)) | ||
*byRef = true; | ||
*byRefAttr = *byRef; | ||
} | ||
|
||
Type *preferred_llvm_type(jl_value_t *ty, bool isret) | ||
{ | ||
if(!isret) | ||
return NULL; | ||
if(!jl_is_datatype(ty) || jl_is_abstracttype(ty) || jl_is_bitstype(ty) || jl_is_cpointer_type(ty) || jl_is_array_type(ty)) | ||
return NULL; | ||
// special case Complex{Float32} as a return type | ||
if(jl_subtype(ty,(jl_value_t*)jl_complex_type,0) && jl_tparam0(ty) == (jl_value_t*)jl_float32_type) | ||
return T_int64; | ||
return NULL; | ||
} | ||
|
||
bool need_private_copy(jl_value_t *ty, bool byRef) | ||
{ | ||
return false; | ||
} |
Oops, something went wrong.
9053bff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git bisect
flags this commit as the source of a segfault inPkg.test("Tk")
. It fails on this line and the segfault happens here. Thatccall
looks good to me, and it gets called many times previously, so I worry this is exposing some internal julia bug.9053bff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a bug in Tk's cfunction usage
9053bff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are so right; many thanks.