|
29 | 29 | */
|
30 | 30 | package com.oracle.truffle.llvm.parser.listeners;
|
31 | 31 |
|
| 32 | +import java.util.ArrayDeque; |
| 33 | +import java.util.ArrayList; |
| 34 | +import java.util.Arrays; |
| 35 | +import java.util.List; |
| 36 | + |
32 | 37 | import com.oracle.truffle.llvm.parser.metadata.MDBaseNode;
|
| 38 | +import com.oracle.truffle.llvm.parser.metadata.MDExpression; |
33 | 39 | import com.oracle.truffle.llvm.parser.metadata.MDKind;
|
| 40 | +import com.oracle.truffle.llvm.parser.metadata.MDLocalVariable; |
34 | 41 | import com.oracle.truffle.llvm.parser.metadata.MDLocation;
|
35 | 42 | import com.oracle.truffle.llvm.parser.metadata.MDSubprogram;
|
36 | 43 | import com.oracle.truffle.llvm.parser.metadata.MDValue;
|
37 | 44 | import com.oracle.truffle.llvm.parser.model.IRScope;
|
| 45 | +import com.oracle.truffle.llvm.parser.model.SymbolImpl; |
38 | 46 | import com.oracle.truffle.llvm.parser.model.attributes.AttributesCodeEntry;
|
39 | 47 | import com.oracle.truffle.llvm.parser.model.blocks.InstructionBlock;
|
40 | 48 | import com.oracle.truffle.llvm.parser.model.functions.FunctionDefinition;
|
|
51 | 59 | import com.oracle.truffle.llvm.parser.model.symbols.instructions.CompareExchangeInstruction;
|
52 | 60 | import com.oracle.truffle.llvm.parser.model.symbols.instructions.CompareInstruction;
|
53 | 61 | import com.oracle.truffle.llvm.parser.model.symbols.instructions.ConditionalBranchInstruction;
|
| 62 | +import com.oracle.truffle.llvm.parser.model.symbols.instructions.DebugInstruction; |
| 63 | +import com.oracle.truffle.llvm.parser.model.symbols.instructions.DebugInstruction.DebugInstructionKind; |
54 | 64 | import com.oracle.truffle.llvm.parser.model.symbols.instructions.ExtractElementInstruction;
|
55 | 65 | import com.oracle.truffle.llvm.parser.model.symbols.instructions.ExtractValueInstruction;
|
56 | 66 | import com.oracle.truffle.llvm.parser.model.symbols.instructions.FenceInstruction;
|
|
93 | 103 | import com.oracle.truffle.llvm.runtime.types.VectorType;
|
94 | 104 | import com.oracle.truffle.llvm.runtime.types.VoidType;
|
95 | 105 |
|
96 |
| -import java.util.ArrayDeque; |
97 |
| -import java.util.ArrayList; |
98 |
| -import java.util.Arrays; |
99 |
| -import java.util.List; |
100 |
| - |
101 | 106 | public final class Function implements ParserListener {
|
102 | 107 |
|
103 | 108 | // See https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Bitcode/LLVMBitCodes.h
|
@@ -252,12 +257,19 @@ public void record(RecordBuffer buffer) {
|
252 | 257 | // since we consume only bitcode after linking, it's safe to ignore
|
253 | 258 | return;
|
254 | 259 |
|
| 260 | + case INSTRUCTION_DEBUG_RECORD_ASSIGN: |
| 261 | + // https://llvm.org/docs/AssignmentTracking.html |
| 262 | + // not used by Sulong |
| 263 | + // parseDebugInstruction(opCode, buffer); |
| 264 | + return; |
| 265 | + |
255 | 266 | case INSTRUCTION_DEBUG_RECORD_VALUE:
|
256 | 267 | case INSTRUCTION_DEBUG_RECORD_DECLARE:
|
257 |
| - case INSTRUCTION_DEBUG_RECORD_ASSIGN: |
258 | 268 | case INSTRUCTION_DEBUG_RECORD_VALUE_SIMPLE:
|
| 269 | + parseDebugInstruction(opCode, buffer); |
| 270 | + return; |
| 271 | + |
259 | 272 | case INSTRUCTION_DEBUG_RECORD_LABEL:
|
260 |
| - // TODO parse debug info |
261 | 273 | return;
|
262 | 274 |
|
263 | 275 | default:
|
@@ -467,6 +479,10 @@ private void emit(VoidInstruction instruction) {
|
467 | 479 | scope.addInstruction(instruction);
|
468 | 480 | }
|
469 | 481 |
|
| 482 | + private void emitDebug(DebugInstruction instruction) { |
| 483 | + instructionBlock.addDebug(instruction); |
| 484 | + } |
| 485 | + |
470 | 486 | private static final int INVOKE_HASEXPLICITFUNCTIONTYPE_SHIFT = 13;
|
471 | 487 |
|
472 | 488 | private void attachOperandBundle(RecordBuffer buffer) {
|
@@ -851,6 +867,32 @@ private void applyDebugLocation() {
|
851 | 867 | instructionBlock.getInstruction(lastInstructionIndex).setDebugLocation(lastLocation);
|
852 | 868 | }
|
853 | 869 |
|
| 870 | + private void parseDebugInstruction(int opCode, RecordBuffer buffer) { |
| 871 | + MDLocation dil = (MDLocation) scope.getMetadata().getOrNull(buffer.readInt()); |
| 872 | + MDLocalVariable variable = (MDLocalVariable) scope.getMetadata().getOrNull(buffer.readInt()); |
| 873 | + MDExpression expression = (MDExpression) scope.getMetadata().getOrNull(buffer.readInt()); |
| 874 | + |
| 875 | + MDBaseNode value; |
| 876 | + if (opCode == INSTRUCTION_DEBUG_RECORD_VALUE_SIMPLE) { |
| 877 | + // this is never forward referenced, see comment and assert in BitcodeReader.cpp:6517 |
| 878 | + int index = readIndexSkipType(buffer); |
| 879 | + SymbolImpl symbol = scope.getSymbols().getOrNull(index); |
| 880 | + value = MDValue.create(symbol); |
| 881 | + } else { |
| 882 | + value = scope.getMetadata().getOrNull(buffer.readInt()); |
| 883 | + } |
| 884 | + |
| 885 | + switch (opCode) { |
| 886 | + case INSTRUCTION_DEBUG_RECORD_DECLARE: |
| 887 | + emitDebug(new DebugInstruction(DebugInstructionKind.DECLARE, dil, variable, expression, value)); |
| 888 | + break; |
| 889 | + case INSTRUCTION_DEBUG_RECORD_VALUE: |
| 890 | + case INSTRUCTION_DEBUG_RECORD_VALUE_SIMPLE: |
| 891 | + emitDebug(new DebugInstruction(DebugInstructionKind.VALUE, dil, variable, expression, value)); |
| 892 | + break; |
| 893 | + } |
| 894 | + } |
| 895 | + |
854 | 896 | private void createAtomicStore(RecordBuffer buffer) {
|
855 | 897 | int destination = readIndexSkipType(buffer);
|
856 | 898 | int source = readIndexSkipType(buffer);
|
|
0 commit comments