Skip to content

Commit d38f3f3

Browse files
vtjnashfcard
authored andcommitted
Revert "Merge branch 'jn/fix_alloca_callconv'"
This reverts commit 66489fa, reversing changes made to 9611554. This was the wrong version of the branch to merge into master.
1 parent 36f8b13 commit d38f3f3

File tree

8 files changed

+237
-432
lines changed

8 files changed

+237
-432
lines changed

base/inference.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3052,7 +3052,6 @@ end
30523052
function remove_redundant_temp_vars(ast, sa)
30533053
varinfo = ast.args[2][1]
30543054
gensym_types = ast.args[2][3]
3055-
body = ast.args[3]
30563055
for (v,init) in sa
30573056
if ((isa(init,Symbol) || isa(init,SymbolNode)) &&
30583057
any(vi->symequal(vi[1],init), varinfo) &&
@@ -3061,7 +3060,7 @@ function remove_redundant_temp_vars(ast, sa)
30613060
# this transformation is not valid for vars used before def.
30623061
# we need to preserve the point of assignment to know where to
30633062
# throw errors (issue #4645).
3064-
if !occurs_undef(v, body, varinfo)
3063+
if !occurs_undef(v, ast.args[3], varinfo)
30653064

30663065
# the transformation is not ideal if the assignment
30673066
# is present for the auto-unbox functionality
@@ -3070,7 +3069,7 @@ function remove_redundant_temp_vars(ast, sa)
30703069
# everywhere later in the function
30713070
if (isa(init,SymbolNode) ? (init.typ <: (isa(v,GenSym)?gensym_types[(v::GenSym).id+1]:local_typeof(v, varinfo))) : true)
30723071
delete_var!(ast, v)
3073-
sym_replace(body, Any[v], Void[], Any[init], Void[])
3072+
sym_replace(ast.args[3], [v], [], [init], [])
30743073
end
30753074
end
30763075
end

src/builtins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static int NOINLINE compare_fields(jl_value_t *a, jl_value_t *b,
273273
return 1;
274274
}
275275

276-
int jl_egal(jl_value_t *a, jl_value_t *b) // warning: a,b may NOT have been gc-rooted by the caller
276+
int jl_egal(jl_value_t *a, jl_value_t *b)
277277
{
278278
if (a == b)
279279
return 1;

src/ccall.cpp

Lines changed: 54 additions & 122 deletions
Large diffs are not rendered by default.

src/cgutils.cpp

Lines changed: 66 additions & 121 deletions
Large diffs are not rendered by default.

src/codegen.cpp

Lines changed: 81 additions & 114 deletions
Large diffs are not rendered by default.

src/intrinsics.cpp

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,22 @@ static Constant *julia_const_to_llvm(jl_value_t *e)
221221
}
222222
JL_GC_POP();
223223
Type *t = julia_struct_to_llvm(jt);
224-
if (type_is_ghost(t))
224+
if (t == T_void || t->isEmptyTy())
225225
return UndefValue::get(NoopType);
226-
if (t->isVectorTy())
227-
return ConstantVector::get(ArrayRef<Constant*>(fields,llvm_nf));
228-
229-
Constant *init;
230226
if (t->isStructTy()) {
231227
StructType *st = dyn_cast<StructType>(t);
232228
assert(st);
233-
init = ConstantStruct::get(st, ArrayRef<Constant*>(fields,llvm_nf));
229+
return ConstantStruct::get(st, ArrayRef<Constant*>(fields,llvm_nf));
230+
}
231+
else if (t->isVectorTy()) {
232+
return ConstantVector::get(ArrayRef<Constant*>(fields,llvm_nf));
234233
}
235234
else {
236235
assert(t->isArrayTy());
237236
ArrayType *at = dyn_cast<ArrayType>(t);
238237
assert(at);
239-
init = ConstantArray::get(at, ArrayRef<Constant*>(fields,llvm_nf));
238+
return ConstantArray::get(at, ArrayRef<Constant*>(fields,llvm_nf));
240239
}
241-
return new GlobalVariable(*jl_Module, t, true, GlobalVariable::ExternalLinkage, init);
242240
}
243241
return NULL;
244242
}
@@ -265,19 +263,13 @@ static Value *emit_unbox(Type *to, Value *x, jl_value_t *jt)
265263
return UndefValue::get(to);
266264
}
267265
if (ty != jl_pvalue_llvmt) {
268-
if (to->isAggregateType()) {
269-
x = builder.CreateLoad(x); // something stack allocated
270-
ty = x->getType();
271-
}
272-
else {
273-
// bools are stored internally as int8 (for now)
274-
if (ty == T_int1 && to == T_int8)
275-
return builder.CreateZExt(x, T_int8);
276-
if (ty->isPointerTy() && !to->isPointerTy())
277-
return builder.CreatePtrToInt(x, to);
278-
if (!ty->isPointerTy() && to->isPointerTy())
279-
return builder.CreateIntToPtr(x, to);
280-
}
266+
// bools are stored internally as int8 (for now)
267+
if (ty == T_int1 && to == T_int8)
268+
return builder.CreateZExt(x, T_int8);
269+
if (ty->isPointerTy() && !to->isPointerTy())
270+
return builder.CreatePtrToInt(x, to);
271+
if (!ty->isPointerTy() && to->isPointerTy())
272+
return builder.CreateIntToPtr(x, to);
281273
if (ty != to) {
282274
// this can happen when a branch yielding a different type ends
283275
// up being dead code, and type inference knows that the other
@@ -287,20 +279,21 @@ static Value *emit_unbox(Type *to, Value *x, jl_value_t *jt)
287279
}
288280
return x;
289281
}
290-
Value *p = x;
282+
Value *p = data_pointer(x);
291283
if (to == T_int1) {
292284
// bools stored as int8, so an extra Trunc is needed to get an int1
293285
return builder.CreateTrunc(builder.
294286
CreateLoad(builder.
295-
CreateBitCast(p, T_pint8)),
287+
CreateBitCast(p, T_pint8), false),
296288
T_int1);
297289
}
298290
if (to->isStructTy() && !to->isSized()) {
299291
// empty struct - TODO - is this a good way to represent it?
300292
assert(to != T_void);
301293
return UndefValue::get(to);
302294
}
303-
return builder.CreateAlignedLoad(builder.CreateBitCast(p, to->getPointerTo()), 16); // julia's gc gives 16-byte aligned addresses
295+
// TODO: stricter alignment if possible
296+
return builder.CreateAlignedLoad(builder.CreateBitCast(p, to->getPointerTo()), sizeof(void*), false);
304297
}
305298

306299
// unbox trying to determine type automatically
@@ -334,9 +327,7 @@ static Value *auto_unbox(jl_value_t *x, jl_codectx_t *ctx)
334327
if (to == T_void) {
335328
return NULL;
336329
}
337-
if (to->isAggregateType() && jl_is_immutable_datatype(bt)) // can lazy load on demand, no copy needed
338-
return builder.CreateBitCast(v, to->getPointerTo());
339-
return emit_reg2mem(emit_unbox(to, v, bt), ctx);
330+
return emit_unbox(to, v, bt);
340331
}
341332

342333
// figure out how many bits a bitstype has at compile time, or -1
@@ -366,10 +357,7 @@ static Value *generic_unbox(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx)
366357
jl_value_t *p = jl_tparam0(et);
367358
if (jl_is_leaf_type(p)) {
368359
Type *to = julia_type_to_llvm(p);
369-
Value *lx = emit_unboxed(x,ctx);
370-
if (to->isAggregateType() && lx->getType() == PointerType::get(to,0) && jl_is_immutable(p)) // can lazy load on demand, no copy needed
371-
return lx;
372-
return emit_reg2mem(emit_unbox(to, lx, p), ctx);
360+
return emit_unbox(to, emit_unboxed(x,ctx), p);
373361
}
374362
}
375363
int nb = try_to_determine_bitstype_nbits(targ, ctx);
@@ -441,9 +429,6 @@ static Value *generic_box(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx)
441429

442430
Value *vx = auto_unbox(x, ctx);
443431
Type *vxt = vx->getType();
444-
if (llvmt->isAggregateType() && vxt->isPointerTy()) {
445-
vxt = vxt->getContainedType(0);
446-
}
447432
//if (vx->getType()->getPrimitiveSizeInBits() != (unsigned)nb)
448433
// jl_errorf("box: expected argument with %d bits, got %d", nb,
449434
// vx->getType()->getPrimitiveSizeInBits());
@@ -487,10 +472,7 @@ static Value *generic_box(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx)
487472
}
488473

489474
// dynamically-determined type; evaluate.
490-
if (llvmt->isAggregateType()) {
491-
vx = builder.CreateLoad(vx); // something stack allocated
492-
}
493-
return allocate_box_dynamic(emit_expr(targ, ctx), ConstantInt::get(T_size,nb), vx);
475+
return allocate_box_dynamic(emit_expr(targ, ctx), ConstantInt::get(T_size,(nb+7)/8), vx);
494476
}
495477

496478
static Type *staticeval_bitstype(jl_value_t *targ, const char *fname, jl_codectx_t *ctx)

test/ccall.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

33
import Base.copy, Base.==
4-
const verbose = false
4+
const verbose = false
55
ccall((:set_verbose, "./libccalltest"), Void, (Int32,), verbose)
66

77
# Test for proper argument register truncation
@@ -115,7 +115,7 @@ b = ccall((:test_big, "./libccalltest"), Struct_Big, (Struct_Big,), a)
115115
@test b.y == sbig.y - 2
116116
@test b.z == sbig.z - Int('A')
117117

118-
verbose && Libc.flush_cstdio()
118+
verbose && flush_cstdio()
119119
verbose && println("Testing cfunction roundtrip: ")
120120
# cfunction roundtrip
121121
for (t,v) in ((Complex{Int32},:ci32),(Complex{Int64},:ci64),
@@ -184,13 +184,7 @@ for (t,v) in ((Complex{Int32},:ci32),(Complex{Int64},:ci64),
184184
if ($(t).mutable)
185185
@test !(b === a)
186186
end
187-
b = ccall(cfunction($fname,Any,(Ref{$t},)),Any,(Ref{$t},),$v)
188-
verbose && println("C: ",b)
189-
@test b == $v
190-
@test b === c
191-
if ($(t).mutable)
192-
@test !(b === a)
193-
end
194187
#b = ccall(cfunction($fname,Any,(Ref{Any},)),Any,(Ref{Any},),$v) # unimplemented
188+
#b = ccall(cfunction($fname,Any,(Ref{$t},)),Any,(Ref{$t},),$v) # broken due to #2818
195189
end
196190
end

test/llvmcall.jl

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22

33
using Base.llvmcall
44

5-
#function add1234(x::Tuple{Int32,Int32,Int32,Int32})
6-
# llvmcall("""%3 = add <4 x i32> %1, %0
7-
# ret <4 x i32> %3""",
8-
# Tuple{Int32,Int32,Int32,Int32},
9-
# Tuple{Tuple{Int32,Int32,Int32,Int32},
10-
# Tuple{Int32,Int32,Int32,Int32}},
11-
# (Int32(1),Int32(2),Int32(3),Int32(4)),
12-
# x)
13-
#end
14-
#
15-
#function add1234(x::NTuple{4,Int64})
16-
# llvmcall("""%3 = add <4 x i64> %1, %0
17-
# ret <4 x i64> %3""",NTuple{4,Int64},
18-
# Tuple{NTuple{4,Int64},NTuple{4,Int64}},
19-
# (Int64(1),Int64(2),Int64(3),Int64(4)),
20-
# x)
21-
#end
22-
#
235
function add1234(x::Tuple{Int32,Int32,Int32,Int32})
246
llvmcall("""%3 = extractvalue [4 x i32] %0, 0
257
%4 = extractvalue [4 x i32] %0, 1
@@ -43,6 +25,14 @@ function add1234(x::Tuple{Int32,Int32,Int32,Int32})
4325
x)
4426
end
4527

28+
# function add1234(x::NTuple{4,Int64})
29+
# llvmcall("""%3 = add <4 x i64> %1, %0
30+
# ret <4 x i64> %3""",NTuple{4,Int64},
31+
# Tuple{NTuple{4,Int64},NTuple{4,Int64}},
32+
# (Int64(1),Int64(2),Int64(3),Int64(4)),
33+
# x)
34+
# end
35+
4636
@test add1234(map(Int32,(2,3,4,5))) === map(Int32,(3,5,7,9))
4737
#@test add1234(map(Int64,(2,3,4,5))) === map(Int64,(3,5,7,9))
4838

@@ -54,11 +44,7 @@ baremodule PlusTest
5444

5545
function +(x::Int32, y::Int32)
5646
llvmcall("""%3 = add i32 %1, %0
57-
ret i32 %3""",
58-
Int32,
59-
Tuple{Int32, Int32},
60-
x,
61-
y)
47+
ret i32 %3""", Int32, Tuple{Int32, Int32}, x, y)
6248
end
63-
@test Int32(1) + Int32(2) == Int32(3)
49+
@test Int32(1)+Int32(2)==Int32(3)
6450
end

0 commit comments

Comments
 (0)