Skip to content

Commit f012c57

Browse files
committed
rewrite
1 parent 398f318 commit f012c57

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/llvm-alloc-helpers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bool AllocUseInfo::addMemOp(Instruction *inst, unsigned opno, uint32_t offset,
8989
memop.isobjref = hasObjref(elty);
9090
auto &field = getField(offset, size, elty);
9191

92-
field.second.hasbits |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
92+
field.second.hasunboxed |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
9393

9494
if (field.second.hasobjref != memop.isobjref)
9595
field.second.multiloc = true; // can't split this field, since it contains a mix of references and bits
@@ -201,7 +201,7 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
201201
auto elty = inst->getType();
202202
required.use_info.has_unknown_objref |= hasObjref(elty);
203203
required.use_info.has_unknown_objrefaggr |= hasObjref(elty) && !isa<PointerType>(elty);
204-
required.use_info.has_unknown_bits |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
204+
required.use_info.has_unknown_unboxed |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
205205
required.use_info.hasunknownmem = true;
206206
} else if (!required.use_info.addMemOp(inst, 0, cur.offset,
207207
inst->getType(),
@@ -293,7 +293,7 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
293293
auto elty = storev->getType();
294294
required.use_info.has_unknown_objref |= hasObjref(elty);
295295
required.use_info.has_unknown_objrefaggr |= hasObjref(elty) && !isa<PointerType>(elty);
296-
required.use_info.has_unknown_bits |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
296+
required.use_info.has_unknown_unboxed |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
297297
required.use_info.hasunknownmem = true;
298298
} else if (!required.use_info.addMemOp(inst, use->getOperandNo(),
299299
cur.offset, storev->getType(),
@@ -322,7 +322,7 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
322322
LLVM_DEBUG(dbgs() << "Atomic inst has unknown offset\n");
323323
required.use_info.has_unknown_objref |= hasObjref(elty);
324324
required.use_info.has_unknown_objrefaggr |= hasObjref(elty) && !isa<PointerType>(elty);
325-
required.use_info.has_unknown_bits |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
325+
required.use_info.has_unknown_unboxed |= !hasObjref(elty) || (hasObjref(elty) && !isa<PointerType>(elty));
326326
required.use_info.hasunknownmem = true;
327327
}
328328
required.use_info.refload = true;

src/llvm-alloc-helpers.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace jl_alloc {
4747
bool multiloc:1;
4848
bool hasload:1;
4949
// The alloc has a non-julia object at this offset.
50-
bool hasbits:1;
50+
bool hasunboxed:1;
5151
llvm::Type *elty;
5252
llvm::SmallVector<MemOp,4> accesses;
5353
Field(uint32_t size, llvm::Type *elty)
@@ -56,7 +56,7 @@ namespace jl_alloc {
5656
hasaggr(false),
5757
multiloc(false),
5858
hasload(false),
59-
hasbits(false),
59+
hasunboxed(false),
6060
elty(elty)
6161
{
6262
}
@@ -99,7 +99,7 @@ namespace jl_alloc {
9999
bool has_unknown_objrefaggr:1;
100100

101101
// The alloc has a non-julia object at an unknown offset.
102-
bool has_unknown_bits:1;
102+
bool has_unknown_unboxed:1;
103103

104104
void reset()
105105
{
@@ -116,7 +116,7 @@ namespace jl_alloc {
116116
allockind = llvm::AllocFnKind::Unknown;
117117
has_unknown_objref = false;
118118
has_unknown_objrefaggr = false;
119-
has_unknown_bits = false;
119+
has_unknown_unboxed = false;
120120
uses.clear();
121121
preserves.clear();
122122
memops.clear();

src/llvm-alloc-opt.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@ void Optimizer::optimizeAll()
252252
removeAlloc(orig);
253253
continue;
254254
}
255-
bool has_bits = use_info.has_unknown_bits;
255+
bool has_unboxed = use_info.has_unknown_bits;
256256
bool has_ref = use_info.has_unknown_objref;
257257
bool has_refaggr = use_info.has_unknown_objrefaggr;
258258
for (auto memop: use_info.memops) {
259259
auto &field = memop.second;
260-
has_bits |= field.hasbits;
260+
has_unboxed |= field.hasbits;
261261
if (field.hasobjref) {
262262
has_ref = true;
263263
// This can be relaxed a little based on hasload
@@ -286,7 +286,11 @@ void Optimizer::optimizeAll()
286286
splitOnStack(orig);
287287
continue;
288288
}
289-
if (has_bits && has_ref) {
289+
// The move to stack code below, if has_ref is set, changes the allocation to an array of jlvalue_t's. This is fine
290+
// if all objects are jlvalue_t's. However, if part of the allocation is not a julia object (e.g. it is a { float, jlvaluet }),
291+
// then the moveToStackCAll will create a [2 x jlvaluet] bitcast to { float, jlvaluet }. The float clearly is not a GC
292+
// value and will result in segfaults and other problems.
293+
if (has_unboxed && has_ref) {
290294
REMARK([&]() {
291295
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
292296
<< "GC allocation could not be split and contained both julia object and non-julia-object data, unable to move to stack " << ore::NV("GC Allocation", orig);

0 commit comments

Comments
 (0)