Skip to content

Commit 3d6427a

Browse files
committed
Strip debugging pseudo-instructions from the Yk AOT module.
Also added a comment about the way we lower the AOT IR. Before: ``` bb1: call llvm.dbg.value(?op<i32 %0>, ?op<!31 = !DILocalVariable(name: "argc", arg: 1, scope: !23, file: !2, line: 46, type: !26)>, ?op<!DIExpression()>) call llvm.dbg.value(?op<ptr %1>, ?op<!32 = !DILocalVariable(name: "argv", arg: 2, scope: !23, file: !2, line: 46, type: !27)>, ?op<!DIExpression()>) $1_2: ptr = ptradd $0_1, 16i64 store $1_2, GlobalDecl(shadowstack_0, tls=false) $1_4: ptr = call yk_mt_new(const_ptr) call llvm.experimental.stackmap(1i64, 0i32, $0_0, $0_1, $0_4, $0_5, $0_6, $0_7) br ``` After: ``` bb1: $1_0: ptr = ptradd $0_1, 16i64 store $1_0, GlobalDecl(shadowstack_0, tls=false) $1_2: ptr = call yk_mt_new(const_ptr) call llvm.experimental.stackmap(1i64, 0i32, $0_0, $0_1, $0_4, $0_5, $0_6, $0_7) br ```
1 parent 4038168 commit 3d6427a

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

llvm/lib/YkIR/YkIRWriter.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,46 @@ class YkIRWriter {
619619

620620
void serialiseBlock(BasicBlock &BB, ValueLoweringMap &VLMap,
621621
unsigned &BBIdx) {
622+
// Keep the instruction skipping logic in one place.
623+
auto ShouldSkipInstr = [](Instruction *I) {
624+
// Skip non-semantic instrucitons for now.
625+
//
626+
// We may come back to them later if we need better debugging
627+
// facilities, but for now they just clutter up our AOT module.
628+
return I->isDebugOrPseudoInst();
629+
};
630+
631+
// Count instructions.
632+
//
633+
// FIXME: I don't like this much:
634+
//
635+
// - Assumes one LLVM instruction becomes exactly one Yk IR instruction.
636+
// - Requires a second loop to count ahead of time.
637+
//
638+
// Can we emit the instrucitons into a temp buffer and keep a running count
639+
// of how many instructions we generated instead?
640+
size_t NumInstrs = 0;
641+
for (Instruction &I : BB) {
642+
if (ShouldSkipInstr(&I)) {
643+
continue;
644+
}
645+
NumInstrs++;
646+
}
647+
622648
// num_instrs:
623-
OutStreamer.emitSizeT(BB.size());
649+
OutStreamer.emitSizeT(NumInstrs);
624650
// instrs:
625651
unsigned InstIdx = 0;
626652
for (Instruction &I : BB) {
653+
if (ShouldSkipInstr(&I)) {
654+
continue;
655+
}
627656
serialiseInst(&I, VLMap, BBIdx, InstIdx);
628657
}
658+
659+
// Check we emitted the number of instructions that we promised.
660+
assert(InstIdx == NumInstrs);
661+
629662
BBIdx++;
630663
}
631664

0 commit comments

Comments
 (0)