|
108 | 108 | #include "llvm/Target/TargetIntrinsicInfo.h"
|
109 | 109 | #include "llvm/Target/TargetMachine.h"
|
110 | 110 | #include "llvm/Target/TargetOptions.h"
|
| 111 | +#include "llvm/Transforms/Utils/Local.h" |
111 | 112 | #include <algorithm>
|
112 | 113 | #include <cassert>
|
113 | 114 | #include <cstddef>
|
@@ -1131,6 +1132,13 @@ void SelectionDAGBuilder::dropDanglingDebugInfo(const DILocalVariable *Variable,
|
1131 | 1132 |
|
1132 | 1133 | for (auto &DDIMI : DanglingDebugInfoMap) {
|
1133 | 1134 | DanglingDebugInfoVector &DDIV = DDIMI.second;
|
| 1135 | + |
| 1136 | + // If debug info is to be dropped, run it through final checks to see |
| 1137 | + // whether it can be salvaged. |
| 1138 | + for (auto &DDI : DDIV) |
| 1139 | + if (isMatchingDbgValue(DDI)) |
| 1140 | + salvageUnresolvedDbgValue(DDI); |
| 1141 | + |
1134 | 1142 | DDIV.erase(remove_if(DDIV, isMatchingDbgValue), DDIV.end());
|
1135 | 1143 | }
|
1136 | 1144 | }
|
@@ -1179,12 +1187,73 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
|
1179 | 1187 | } else
|
1180 | 1188 | LLVM_DEBUG(dbgs() << "Resolved dangling debug info for " << *DI
|
1181 | 1189 | << "in EmitFuncArgumentDbgValue\n");
|
1182 |
| - } else |
| 1190 | + } else { |
1183 | 1191 | LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n");
|
| 1192 | + auto Undef = |
| 1193 | + UndefValue::get(DDI.getDI()->getVariableLocation()->getType()); |
| 1194 | + auto SDV = |
| 1195 | + DAG.getConstantDbgValue(Variable, Expr, Undef, dl, DbgSDNodeOrder); |
| 1196 | + DAG.AddDbgValue(SDV, nullptr, false); |
| 1197 | + } |
1184 | 1198 | }
|
1185 | 1199 | DDIV.clear();
|
1186 | 1200 | }
|
1187 | 1201 |
|
| 1202 | +void SelectionDAGBuilder::salvageUnresolvedDbgValue(DanglingDebugInfo &DDI) { |
| 1203 | + Value *V = DDI.getDI()->getValue(); |
| 1204 | + DILocalVariable *Var = DDI.getDI()->getVariable(); |
| 1205 | + DIExpression *Expr = DDI.getDI()->getExpression(); |
| 1206 | + DebugLoc DL = DDI.getdl(); |
| 1207 | + DebugLoc InstDL = DDI.getDI()->getDebugLoc(); |
| 1208 | + unsigned SDOrder = DDI.getSDNodeOrder(); |
| 1209 | + |
| 1210 | + // Currently we consider only dbg.value intrinsics -- we tell the salvager |
| 1211 | + // that DW_OP_stack_value is desired. |
| 1212 | + assert(isa<DbgValueInst>(DDI.getDI())); |
| 1213 | + bool StackValue = true; |
| 1214 | + |
| 1215 | + // Can this Value can be encoded without any further work? |
| 1216 | + if (handleDebugValue(V, Var, Expr, DL, InstDL, SDOrder)) |
| 1217 | + return; |
| 1218 | + |
| 1219 | + // Attempt to salvage back through as many instructions as possible. Bail if |
| 1220 | + // a non-instruction is seen, such as a constant expression or global |
| 1221 | + // variable. FIXME: Further work could recover those too. |
| 1222 | + while (isa<Instruction>(V)) { |
| 1223 | + Instruction &VAsInst = *cast<Instruction>(V); |
| 1224 | + DIExpression *NewExpr = salvageDebugInfoImpl(VAsInst, Expr, StackValue); |
| 1225 | + |
| 1226 | + // If we cannot salvage any further, and haven't yet found a suitable debug |
| 1227 | + // expression, bail out. |
| 1228 | + if (!NewExpr) |
| 1229 | + break; |
| 1230 | + |
| 1231 | + // New value and expr now represent this debuginfo. |
| 1232 | + V = VAsInst.getOperand(0); |
| 1233 | + Expr = NewExpr; |
| 1234 | + |
| 1235 | + // Some kind of simplification occurred: check whether the operand of the |
| 1236 | + // salvaged debug expression can be encoded in this DAG. |
| 1237 | + if (handleDebugValue(V, Var, Expr, DL, InstDL, SDOrder)) { |
| 1238 | + LLVM_DEBUG(dbgs() << "Salvaged debug location info for:\n " |
| 1239 | + << DDI.getDI() << "\nBy stripping back to:\n " << V); |
| 1240 | + return; |
| 1241 | + } |
| 1242 | + } |
| 1243 | + |
| 1244 | + // This was the final opportunity to salvage this debug information, and it |
| 1245 | + // couldn't be done. Place an undef DBG_VALUE at this location to terminate |
| 1246 | + // any earlier variable location. |
| 1247 | + auto Undef = UndefValue::get(DDI.getDI()->getVariableLocation()->getType()); |
| 1248 | + auto SDV = DAG.getConstantDbgValue(Var, Expr, Undef, DL, SDNodeOrder); |
| 1249 | + DAG.AddDbgValue(SDV, nullptr, false); |
| 1250 | + |
| 1251 | + LLVM_DEBUG(dbgs() << "Dropping debug value info for:\n " << DDI.getDI() |
| 1252 | + << "\n"); |
| 1253 | + LLVM_DEBUG(dbgs() << " Last seen at:\n " << *DDI.getDI()->getOperand(0) |
| 1254 | + << "\n"); |
| 1255 | +} |
| 1256 | + |
1188 | 1257 | bool SelectionDAGBuilder::handleDebugValue(const Value *V, DILocalVariable *Var,
|
1189 | 1258 | DIExpression *Expr, DebugLoc dl,
|
1190 | 1259 | DebugLoc InstDL, unsigned Order) {
|
@@ -1277,6 +1346,14 @@ bool SelectionDAGBuilder::handleDebugValue(const Value *V, DILocalVariable *Var,
|
1277 | 1346 | return false;
|
1278 | 1347 | }
|
1279 | 1348 |
|
| 1349 | +void SelectionDAGBuilder::resolveOrClearDbgInfo() { |
| 1350 | + // Try to fixup any remaining dangling debug info -- and drop it if we can't. |
| 1351 | + for (auto &Pair : DanglingDebugInfoMap) |
| 1352 | + for (auto &DDI : Pair.getSecond()) |
| 1353 | + salvageUnresolvedDbgValue(DDI); |
| 1354 | + clearDanglingDebugInfo(); |
| 1355 | +} |
| 1356 | + |
1280 | 1357 | /// getCopyFromRegs - If there was virtual register allocated for the value V
|
1281 | 1358 | /// emit CopyFromReg of the specified type Ty. Return empty SDValue() otherwise.
|
1282 | 1359 | SDValue SelectionDAGBuilder::getCopyFromRegs(const Value *V, Type *Ty) {
|
@@ -5552,21 +5629,12 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
|
5552 | 5629 | SDNodeOrder))
|
5553 | 5630 | return nullptr;
|
5554 | 5631 |
|
5555 |
| - // TODO: When we get here we will either drop the dbg.value completely, or |
5556 |
| - // we try to move it forward by letting it dangle for awhile. So we should |
5557 |
| - // probably add an extra DbgValue to the DAG here, with a reference to |
5558 |
| - // "noreg", to indicate that we have lost the debug location for the |
5559 |
| - // variable. |
5560 |
| - |
5561 |
| - if (!V->use_empty() ) { |
5562 |
| - // Do not call getValue(V) yet, as we don't want to generate code. |
5563 |
| - // Remember it for later. |
5564 |
| - DanglingDebugInfoMap[V].emplace_back(&DI, dl, SDNodeOrder); |
5565 |
| - return nullptr; |
5566 |
| - } |
| 5632 | + // TODO: Dangling debug info will eventually either be resolved or produce |
| 5633 | + // an Undef DBG_VALUE. However in the resolution case, a gap may appear |
| 5634 | + // between the original dbg.value location and its resolved DBG_VALUE, which |
| 5635 | + // we should ideally fill with an extra Undef DBG_VALUE. |
5567 | 5636 |
|
5568 |
| - LLVM_DEBUG(dbgs() << "Dropping debug location info for:\n " << DI << "\n"); |
5569 |
| - LLVM_DEBUG(dbgs() << " Last seen at:\n " << *V << "\n"); |
| 5637 | + DanglingDebugInfoMap[V].emplace_back(&DI, dl, SDNodeOrder); |
5570 | 5638 | return nullptr;
|
5571 | 5639 | }
|
5572 | 5640 |
|
|
0 commit comments