Skip to content

Commit e4a27bd

Browse files
committed
Fix git mess
1 parent 1d22e85 commit e4a27bd

File tree

2 files changed

+97
-30
lines changed

2 files changed

+97
-30
lines changed

src/llvm-final-gc-lowering.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ bool FinalLowerGC::runOnFunction(Function &F)
230230
initAll(*F.getParent());
231231
if (!pgcstack_getter && !adoptthread_func) {
232232
LLVM_DEBUG(dbgs() << "FINAL GC LOWERING: Skipping function " << F.getName() << "\n");
233-
return false;
233+
goto verify_skip;
234234
}
235235

236236
// Look for a call to 'julia.get_pgcstack'.
237237
pgcstack = getPGCstack(F);
238238
if (!pgcstack) {
239239
LLVM_DEBUG(dbgs() << "FINAL GC LOWERING: Skipping function " << F.getName() << " no pgcstack\n");
240-
return false;
240+
goto verify_skip;
241241
}
242242
LLVM_DEBUG(dbgs() << "FINAL GC LOWERING: Processing function " << F.getName() << "\n");
243243
queueRootFunc = getOrDeclare(jl_well_known::GCQueueRoot);
@@ -277,6 +277,39 @@ bool FinalLowerGC::runOnFunction(Function &F)
277277
}
278278

279279
return true;
280+
281+
verify_skip:
282+
#ifdef JL_VERIFY_PASSES
283+
for (auto &BB : F) {
284+
for (auto &I : make_early_inc_range(BB)) {
285+
auto *CI = dyn_cast<CallInst>(&I);
286+
if (!CI)
287+
continue;
288+
289+
Value *callee = CI->getCalledOperand();
290+
assert(callee);
291+
#define IS_INTRINSIC(INTRINSIC) \
292+
do { \
293+
auto intrinsic = getOrNull(jl_intrinsics::INTRINSIC); \
294+
if (intrinsic == callee) { \
295+
errs() << "Final-GC-lowering didn't eliminate all intrinsics'" << F.getName() << "', dumping entire module!\n\n"; \
296+
errs() << *F.getParent() << "\n"; \
297+
abort(); \
298+
} \
299+
} while (0)
300+
IS_INTRINSIC(newGCFrame);
301+
IS_INTRINSIC(pushGCFrame);
302+
IS_INTRINSIC(popGCFrame);
303+
IS_INTRINSIC(getGCFrameSlot);
304+
IS_INTRINSIC(GCAllocBytes);
305+
IS_INTRINSIC(queueGCRoot);
306+
IS_INTRINSIC(safepoint);
307+
308+
#undef IS_INTRINSIC
309+
}
310+
}
311+
#endif
312+
return false;
280313
}
281314

282315
PreservedAnalyses FinalLowerGCPass::run(Function &F, FunctionAnalysisManager &AM)

src/llvm-late-gc-lowering.cpp

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,45 +1541,79 @@ State LateLowerGCFrame::LocalScan(Function &F) {
15411541
assert(cast<PointerType>(CI->getArgOperand(0)->getType())->isOpaqueOrPointeeTypeMatches(getAttributeAtIndex(CI->getAttributes(), 1, Attribute::StructRet).getValueAsType()));
15421542
auto tracked = CountTrackedPointers(ElT, true);
15431543
if (tracked.count) {
1544-
AllocaInst *SRet = dyn_cast<AllocaInst>((CI->arg_begin()[0])->stripInBoundsOffsets());
1545-
assert(SRet);
1546-
{
1544+
SmallVector<AllocaInst *> allocas;
1545+
Value *SRetArg = (CI->arg_begin()[0])->stripInBoundsOffsets();
1546+
if (AllocaInst *OneSRet = dyn_cast<AllocaInst>(SRetArg)) {
1547+
allocas.push_back(OneSRet);
1548+
} else {
1549+
SmallVector<Value *> worklist;
1550+
worklist.push_back(SRetArg);
1551+
while (!worklist.empty()) {
1552+
Value *V = worklist.pop_back_val();
1553+
if (AllocaInst *Alloca = dyn_cast<AllocaInst>(V->stripInBoundsOffsets())) {
1554+
allocas.push_back(Alloca);
1555+
} else if (PHINode *Phi = dyn_cast<PHINode>(V)) {
1556+
for (Value *Incoming : Phi->incoming_values()) {
1557+
worklist.push_back(Incoming);
1558+
}
1559+
} else if (SelectInst *SI = dyn_cast<SelectInst>(SRetArg)) {
1560+
AllocaInst *TrueSRet = dyn_cast<AllocaInst>(SI->getTrueValue());
1561+
AllocaInst *FalseSRet = dyn_cast<AllocaInst>(SI->getFalseValue());
1562+
if (TrueSRet && FalseSRet) {
1563+
worklist.push_back(TrueSRet);
1564+
worklist.push_back(FalseSRet);
1565+
} else {
1566+
llvm_dump(SI);
1567+
assert(false && "Malformed Select");
1568+
}
1569+
} else {
1570+
llvm_dump(V);
1571+
assert(false && "Unexpected SRet argument");
1572+
}
1573+
}
1574+
}
1575+
assert(allocas.size() > 0);
1576+
assert(std::all_of(allocas.begin(), allocas.end(), [&] (AllocaInst* SRetAlloca) {return (SRetAlloca->getArraySize() == allocas[0]->getArraySize() && SRetAlloca->getAllocatedType() == allocas[0]->getAllocatedType());}));
1577+
for (AllocaInst *SRet : allocas) {
15471578
if (!(SRet->isStaticAlloca() && isa<PointerType>(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked)) {
15481579
assert(!tracked.derived);
15491580
if (tracked.all) {
15501581
S.ArrayAllocas[SRet] = tracked.count * cast<ConstantInt>(SRet->getArraySize())->getZExtValue();
15511582
}
15521583
else {
15531584
Value *arg1 = (CI->arg_begin()[1])->stripInBoundsOffsets();
1554-
AllocaInst *SRet_gc = nullptr;
1555-
if (PHINode *Phi = dyn_cast<PHINode>(arg1)) {
1556-
for (Value *V : Phi->incoming_values()) {
1557-
if (AllocaInst *Alloca = dyn_cast<AllocaInst>(V->stripInBoundsOffsets())) {
1558-
if (SRet_gc == nullptr) {
1559-
SRet_gc = Alloca;
1560-
} else if (SRet_gc == Alloca) {
1561-
continue;
1562-
} else {
1563-
llvm_dump(Alloca);
1564-
llvm_dump(SRet_gc);
1565-
assert(false && "Allocas in Phi node should match");
1566-
}
1585+
SmallVector<AllocaInst *> gc_allocas;
1586+
SmallVector<Value*> worklist;
1587+
worklist.push_back(arg1);
1588+
while (!worklist.empty()) {
1589+
Value *V = worklist.pop_back_val();
1590+
if (AllocaInst *Alloca = dyn_cast<AllocaInst>(V->stripInBoundsOffsets())) {
1591+
gc_allocas.push_back(Alloca);
1592+
} else if (PHINode *Phi = dyn_cast<PHINode>(V)) {
1593+
for (Value *Incoming : Phi->incoming_values()) {
1594+
worklist.push_back(Incoming);
1595+
}
1596+
} else if (SelectInst *SI = dyn_cast<SelectInst>(arg1)) {
1597+
AllocaInst *TrueSRet = dyn_cast<AllocaInst>(SI->getTrueValue());
1598+
AllocaInst *FalseSRet = dyn_cast<AllocaInst>(SI->getFalseValue());
1599+
if (TrueSRet && FalseSRet) {
1600+
worklist.push_back(TrueSRet);
1601+
worklist.push_back(FalseSRet);
15671602
} else {
1568-
llvm_dump(V->stripInBoundsOffsets());
1569-
assert(false && "Expected alloca");
1603+
llvm_dump(SI);
1604+
assert(false && "Malformed Select");
15701605
}
1606+
} else {
1607+
llvm_dump(V);
1608+
assert(false && "Unexpected SRet argument");
15711609
}
1572-
} else {
1573-
SRet_gc = dyn_cast<AllocaInst>(arg1);
15741610
}
1575-
if (!SRet_gc) {
1576-
llvm_dump(CI);
1577-
llvm_dump(arg1);
1578-
assert(false && "Expected alloca");
1579-
}
1580-
Type *ElT = SRet_gc->getAllocatedType();
1581-
if (!(SRet_gc->isStaticAlloca() && isa<PointerType>(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked)) {
1582-
S.ArrayAllocas[SRet_gc] = tracked.count * cast<ConstantInt>(SRet_gc->getArraySize())->getZExtValue();
1611+
1612+
assert(gc_allocas.size() > 0);
1613+
assert(std::all_of(gc_allocas.begin(), gc_allocas.end(), [&] (AllocaInst* SRetAlloca) {return (SRetAlloca->getArraySize() == gc_allocas[0]->getArraySize() && SRetAlloca->getAllocatedType() == gc_allocas[0]->getAllocatedType());}));
1614+
for (AllocaInst *SRet_gc : gc_allocas) {
1615+
if (!(SRet_gc->isStaticAlloca() && isa<PointerType>(ElT) && ElT->getPointerAddressSpace() == AddressSpace::Tracked))
1616+
S.ArrayAllocas[SRet_gc] = tracked.count * cast<ConstantInt>(SRet_gc->getArraySize())->getZExtValue();
15831617
}
15841618
}
15851619
}

0 commit comments

Comments
 (0)