@@ -105,23 +105,23 @@ class FunctionVarLocsBuilder {
105
105
106
106
// / Add a def for a variable that is valid for its lifetime.
107
107
void addSingleLocVar (DebugVariable Var, DIExpression *Expr, DebugLoc DL,
108
- Value *V ) {
108
+ RawLocationWrapper R ) {
109
109
VarLocInfo VarLoc;
110
110
VarLoc.VariableID = insertVariable (Var);
111
111
VarLoc.Expr = Expr;
112
112
VarLoc.DL = DL;
113
- VarLoc.V = V ;
113
+ VarLoc.Values = R ;
114
114
SingleLocVars.emplace_back (VarLoc);
115
115
}
116
116
117
117
// / Add a def to the wedge of defs just before /p Before.
118
118
void addVarLoc (Instruction *Before, DebugVariable Var, DIExpression *Expr,
119
- DebugLoc DL, Value *V ) {
119
+ DebugLoc DL, RawLocationWrapper R ) {
120
120
VarLocInfo VarLoc;
121
121
VarLoc.VariableID = insertVariable (Var);
122
122
VarLoc.Expr = Expr;
123
123
VarLoc.DL = DL;
124
- VarLoc.V = V ;
124
+ VarLoc.Values = R ;
125
125
VarLocsBeforeInst[Before].emplace_back (VarLoc);
126
126
}
127
127
};
@@ -148,7 +148,11 @@ void FunctionVarLocs::print(raw_ostream &OS, const Function &Fn) const {
148
148
149
149
auto PrintLoc = [&OS](const VarLocInfo &Loc) {
150
150
OS << " DEF Var=[" << (unsigned )Loc.VariableID << " ]"
151
- << " Expr=" << *Loc.Expr << " V=" << *Loc.V << " \n " ;
151
+ << " Expr=" << *Loc.Expr << " Values=(" ;
152
+ for (auto *Op : Loc.Values .location_ops ()) {
153
+ errs () << Op->getName () << " " ;
154
+ }
155
+ errs () << " )\n " ;
152
156
};
153
157
154
158
// Print the single location variables.
@@ -317,7 +321,7 @@ class MemLocFragmentFill {
317
321
318
322
// / IDs for memory location base addresses in maps. Use 0 to indicate that
319
323
// / there's no memory location.
320
- UniqueVector<Value * > Bases;
324
+ UniqueVector<RawLocationWrapper > Bases;
321
325
UniqueVector<DebugAggregate> Aggregates;
322
326
DenseMap<const BasicBlock *, VarFragMap> LiveIn;
323
327
DenseMap<const BasicBlock *, VarFragMap> LiveOut;
@@ -370,7 +374,7 @@ class MemLocFragmentFill {
370
374
// / Return a string for the value that \p BaseID represents.
371
375
std::string toString (unsigned BaseID) {
372
376
if (BaseID)
373
- return Bases[BaseID]->getName ().str ();
377
+ return Bases[BaseID]. getVariableLocationOp ( 0 ) ->getName ().str ();
374
378
else
375
379
return " None" ;
376
380
}
@@ -603,7 +607,7 @@ class MemLocFragmentFill {
603
607
const auto DerefOffsetInBytes = getDerefOffsetInBytes (DIExpr);
604
608
const unsigned Base =
605
609
DerefOffsetInBytes && *DerefOffsetInBytes * 8 == StartBit
606
- ? Bases.insert (VarLoc.V )
610
+ ? Bases.insert (VarLoc.Values )
607
611
: 0 ;
608
612
LLVM_DEBUG (dbgs () << " DEF " << DbgVar.getVariable ()->getName () << " ["
609
613
<< StartBit << " , " << EndBit << " ): " << toString (Base)
@@ -1244,10 +1248,11 @@ void AssignmentTrackingLowering::emitDbgValue(
1244
1248
const DbgVariableIntrinsic *Source, Instruction *After) {
1245
1249
1246
1250
DILocation *DL = Source->getDebugLoc ();
1247
- auto Emit = [this , Source, After, DL](Value *Val, DIExpression *Expr) {
1251
+ auto Emit = [this , Source, After, DL](Metadata *Val, DIExpression *Expr) {
1248
1252
assert (Expr);
1249
1253
if (!Val)
1250
- Val = PoisonValue::get (Type::getInt1Ty (Source->getContext ()));
1254
+ Val = ValueAsMetadata::get (
1255
+ PoisonValue::get (Type::getInt1Ty (Source->getContext ())));
1251
1256
1252
1257
// Find a suitable insert point.
1253
1258
Instruction *InsertBefore = After->getNextNode ();
@@ -1257,7 +1262,7 @@ void AssignmentTrackingLowering::emitDbgValue(
1257
1262
VarLocInfo VarLoc;
1258
1263
VarLoc.VariableID = static_cast <VariableID>(Var);
1259
1264
VarLoc.Expr = Expr;
1260
- VarLoc.V = Val;
1265
+ VarLoc.Values = RawLocationWrapper ( Val) ;
1261
1266
VarLoc.DL = DL;
1262
1267
// Insert it into the map for later.
1263
1268
InsertBeforeMap[InsertBefore].push_back (VarLoc);
@@ -1286,7 +1291,7 @@ void AssignmentTrackingLowering::emitDbgValue(
1286
1291
// The address-expression has an implicit deref, add it now.
1287
1292
std::tie (Val, Expr) =
1288
1293
walkToAllocaAndPrependOffsetDeref (Layout, Val, Expr);
1289
- Emit (Val, Expr);
1294
+ Emit (ValueAsMetadata::get ( Val) , Expr);
1290
1295
return ;
1291
1296
}
1292
1297
}
@@ -1295,7 +1300,7 @@ void AssignmentTrackingLowering::emitDbgValue(
1295
1300
// / Get the value component, converting to Undef if it is variadic.
1296
1301
Value *Val =
1297
1302
Source->hasArgList () ? nullptr : Source->getVariableLocationOp (0 );
1298
- Emit (Val, Source->getExpression ());
1303
+ Emit (ValueAsMetadata::get ( Val) , Source->getExpression ());
1299
1304
return ;
1300
1305
}
1301
1306
@@ -1373,7 +1378,8 @@ void AssignmentTrackingLowering::processUntaggedInstruction(
1373
1378
VarLocInfo VarLoc;
1374
1379
VarLoc.VariableID = static_cast <VariableID>(Var);
1375
1380
VarLoc.Expr = DIE;
1376
- VarLoc.V = const_cast <AllocaInst *>(Info.Base );
1381
+ VarLoc.Values = RawLocationWrapper (
1382
+ ValueAsMetadata::get (const_cast <AllocaInst *>(Info.Base )));
1377
1383
VarLoc.DL = DILoc;
1378
1384
// 3. Insert it into the map for later.
1379
1385
InsertBeforeMap[InsertBefore].push_back (VarLoc);
@@ -1856,7 +1862,8 @@ static AssignmentTrackingLowering::OverlapMap buildOverlapMapAndRecordDeclares(
1856
1862
for (auto &I : BB) {
1857
1863
if (auto *DDI = dyn_cast<DbgDeclareInst>(&I)) {
1858
1864
FnVarLocs->addSingleLocVar (DebugVariable (DDI), DDI->getExpression (),
1859
- DDI->getDebugLoc (), DDI->getAddress ());
1865
+ DDI->getDebugLoc (),
1866
+ DDI->getWrappedLocation ());
1860
1867
} else if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
1861
1868
DebugVariable DV = DebugVariable (DII);
1862
1869
DebugAggregate DA = {DV.getVariable (), DV.getInlinedAt ()};
@@ -2068,14 +2075,15 @@ bool AssignmentTrackingLowering::run(FunctionVarLocsBuilder *FnVarLocsBuilder) {
2068
2075
//
2069
2076
// Unless we've already done so, create the single location def now.
2070
2077
if (AlwaysStackHomed.insert (Aggr).second ) {
2071
- assert (isa<AllocaInst>(VarLoc.V ));
2078
+ assert (!VarLoc.Values .hasArgList () &&
2079
+ isa<AllocaInst>(VarLoc.Values .getVariableLocationOp (0 )));
2072
2080
// TODO: When more complex cases are handled VarLoc.Expr should be
2073
2081
// built appropriately rather than always using an empty DIExpression.
2074
2082
// The assert below is a reminder.
2075
2083
assert (Simple);
2076
2084
VarLoc.Expr = DIExpression::get (Fn.getContext (), std::nullopt);
2077
2085
DebugVariable Var = FnVarLocs->getVariable (VarLoc.VariableID );
2078
- FnVarLocs->addSingleLocVar (Var, VarLoc.Expr , VarLoc.DL , VarLoc.V );
2086
+ FnVarLocs->addSingleLocVar (Var, VarLoc.Expr , VarLoc.DL , VarLoc.Values );
2079
2087
InsertedAnyIntrinsics = true ;
2080
2088
}
2081
2089
}
@@ -2119,13 +2127,16 @@ bool AssignmentTrackingLowering::emitPromotedVarLocs(
2119
2127
if (VarsWithStackSlot->contains (getAggregate (DVI)))
2120
2128
continue ;
2121
2129
// Wrapper to get a single value (or undef) from DVI.
2122
- auto GetValue = [DVI]() -> Value * {
2130
+ auto GetValue = [DVI]() -> RawLocationWrapper {
2123
2131
// We can't handle variadic DIExpressions yet so treat those as
2124
2132
// kill locations.
2133
+ Value *V;
2125
2134
if (DVI->isKillLocation () || DVI->getValue () == nullptr ||
2126
2135
DVI->hasArgList ())
2127
- return PoisonValue::get (Type::getInt32Ty (DVI->getContext ()));
2128
- return DVI->getValue ();
2136
+ V = PoisonValue::get (Type::getInt32Ty (DVI->getContext ()));
2137
+ else
2138
+ V = DVI->getVariableLocationOp (0 );
2139
+ return RawLocationWrapper (ValueAsMetadata::get (V));
2129
2140
};
2130
2141
Instruction *InsertBefore = I.getNextNode ();
2131
2142
assert (InsertBefore && " Unexpected: debug intrinsics after a terminator" );
@@ -2213,7 +2224,8 @@ static bool
2213
2224
removeRedundantDbgLocsUsingForwardScan (const BasicBlock *BB,
2214
2225
FunctionVarLocsBuilder &FnVarLocs) {
2215
2226
bool Changed = false ;
2216
- DenseMap<DebugVariable, std::pair<Value *, DIExpression *>> VariableMap;
2227
+ DenseMap<DebugVariable, std::pair<RawLocationWrapper, DIExpression *>>
2228
+ VariableMap;
2217
2229
2218
2230
// Scan over the entire block, not just over the instructions mapped by
2219
2231
// FnVarLocs, because wedges in FnVarLocs may only be seperated by debug
@@ -2238,9 +2250,9 @@ removeRedundantDbgLocsUsingForwardScan(const BasicBlock *BB,
2238
2250
2239
2251
// Update the map if we found a new value/expression describing the
2240
2252
// variable, or if the variable wasn't mapped already.
2241
- if (VMI == VariableMap.end () || VMI->second .first != Loc.V ||
2253
+ if (VMI == VariableMap.end () || VMI->second .first != Loc.Values ||
2242
2254
VMI->second .second != Loc.Expr ) {
2243
- VariableMap[Key] = {Loc.V , Loc.Expr };
2255
+ VariableMap[Key] = {Loc.Values , Loc.Expr };
2244
2256
NewDefs.push_back (Loc);
2245
2257
continue ;
2246
2258
}
@@ -2320,7 +2332,7 @@ removeUndefDbgLocsFromEntryBlock(const BasicBlock *BB,
2320
2332
2321
2333
// Remove undef entries that are encountered before any non-undef
2322
2334
// intrinsics from the entry block.
2323
- if (isa<UndefValue> (Loc.V ) && !HasDefinedBits (Aggr, Var)) {
2335
+ if (Loc. Values . isKillLocation (Loc.Expr ) && !HasDefinedBits (Aggr, Var)) {
2324
2336
// Did not insert this Loc, which is the same as removing it.
2325
2337
NumDefsRemoved++;
2326
2338
ChangedThisWedge = true ;
0 commit comments