diff options
Diffstat (limited to 'llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp index d9458c6..d508486 100644 --- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp +++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp @@ -105,23 +105,23 @@ public: /// Add a def for a variable that is valid for its lifetime. void addSingleLocVar(DebugVariable Var, DIExpression *Expr, DebugLoc DL, - Value *V) { + RawLocationWrapper R) { VarLocInfo VarLoc; VarLoc.VariableID = insertVariable(Var); VarLoc.Expr = Expr; VarLoc.DL = DL; - VarLoc.V = V; + VarLoc.Values = R; SingleLocVars.emplace_back(VarLoc); } /// Add a def to the wedge of defs just before /p Before. void addVarLoc(Instruction *Before, DebugVariable Var, DIExpression *Expr, - DebugLoc DL, Value *V) { + DebugLoc DL, RawLocationWrapper R) { VarLocInfo VarLoc; VarLoc.VariableID = insertVariable(Var); VarLoc.Expr = Expr; VarLoc.DL = DL; - VarLoc.V = V; + VarLoc.Values = R; VarLocsBeforeInst[Before].emplace_back(VarLoc); } }; @@ -148,7 +148,11 @@ void FunctionVarLocs::print(raw_ostream &OS, const Function &Fn) const { auto PrintLoc = [&OS](const VarLocInfo &Loc) { OS << "DEF Var=[" << (unsigned)Loc.VariableID << "]" - << " Expr=" << *Loc.Expr << " V=" << *Loc.V << "\n"; + << " Expr=" << *Loc.Expr << " Values=("; + for (auto *Op : Loc.Values.location_ops()) { + errs() << Op->getName() << " "; + } + errs() << ")\n"; }; // Print the single location variables. @@ -317,7 +321,7 @@ class MemLocFragmentFill { /// IDs for memory location base addresses in maps. Use 0 to indicate that /// there's no memory location. - UniqueVector<Value *> Bases; + UniqueVector<RawLocationWrapper> Bases; UniqueVector<DebugAggregate> Aggregates; DenseMap<const BasicBlock *, VarFragMap> LiveIn; DenseMap<const BasicBlock *, VarFragMap> LiveOut; @@ -370,7 +374,7 @@ class MemLocFragmentFill { /// Return a string for the value that \p BaseID represents. std::string toString(unsigned BaseID) { if (BaseID) - return Bases[BaseID]->getName().str(); + return Bases[BaseID].getVariableLocationOp(0)->getName().str(); else return "None"; } @@ -603,7 +607,7 @@ class MemLocFragmentFill { const auto DerefOffsetInBytes = getDerefOffsetInBytes(DIExpr); const unsigned Base = DerefOffsetInBytes && *DerefOffsetInBytes * 8 == StartBit - ? Bases.insert(VarLoc.V) + ? Bases.insert(VarLoc.Values) : 0; LLVM_DEBUG(dbgs() << "DEF " << DbgVar.getVariable()->getName() << " [" << StartBit << ", " << EndBit << "): " << toString(Base) @@ -1244,10 +1248,11 @@ void AssignmentTrackingLowering::emitDbgValue( const DbgVariableIntrinsic *Source, Instruction *After) { DILocation *DL = Source->getDebugLoc(); - auto Emit = [this, Source, After, DL](Value *Val, DIExpression *Expr) { + auto Emit = [this, Source, After, DL](Metadata *Val, DIExpression *Expr) { assert(Expr); if (!Val) - Val = PoisonValue::get(Type::getInt1Ty(Source->getContext())); + Val = ValueAsMetadata::get( + PoisonValue::get(Type::getInt1Ty(Source->getContext()))); // Find a suitable insert point. Instruction *InsertBefore = After->getNextNode(); @@ -1257,7 +1262,7 @@ void AssignmentTrackingLowering::emitDbgValue( VarLocInfo VarLoc; VarLoc.VariableID = static_cast<VariableID>(Var); VarLoc.Expr = Expr; - VarLoc.V = Val; + VarLoc.Values = RawLocationWrapper(Val); VarLoc.DL = DL; // Insert it into the map for later. InsertBeforeMap[InsertBefore].push_back(VarLoc); @@ -1286,7 +1291,7 @@ void AssignmentTrackingLowering::emitDbgValue( // The address-expression has an implicit deref, add it now. std::tie(Val, Expr) = walkToAllocaAndPrependOffsetDeref(Layout, Val, Expr); - Emit(Val, Expr); + Emit(ValueAsMetadata::get(Val), Expr); return; } } @@ -1295,7 +1300,7 @@ void AssignmentTrackingLowering::emitDbgValue( /// Get the value component, converting to Undef if it is variadic. Value *Val = Source->hasArgList() ? nullptr : Source->getVariableLocationOp(0); - Emit(Val, Source->getExpression()); + Emit(ValueAsMetadata::get(Val), Source->getExpression()); return; } @@ -1373,7 +1378,8 @@ void AssignmentTrackingLowering::processUntaggedInstruction( VarLocInfo VarLoc; VarLoc.VariableID = static_cast<VariableID>(Var); VarLoc.Expr = DIE; - VarLoc.V = const_cast<AllocaInst *>(Info.Base); + VarLoc.Values = RawLocationWrapper( + ValueAsMetadata::get(const_cast<AllocaInst *>(Info.Base))); VarLoc.DL = DILoc; // 3. Insert it into the map for later. InsertBeforeMap[InsertBefore].push_back(VarLoc); @@ -1856,7 +1862,8 @@ static AssignmentTrackingLowering::OverlapMap buildOverlapMapAndRecordDeclares( for (auto &I : BB) { if (auto *DDI = dyn_cast<DbgDeclareInst>(&I)) { FnVarLocs->addSingleLocVar(DebugVariable(DDI), DDI->getExpression(), - DDI->getDebugLoc(), DDI->getAddress()); + DDI->getDebugLoc(), + DDI->getWrappedLocation()); } else if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) { DebugVariable DV = DebugVariable(DII); DebugAggregate DA = {DV.getVariable(), DV.getInlinedAt()}; @@ -2068,14 +2075,15 @@ bool AssignmentTrackingLowering::run(FunctionVarLocsBuilder *FnVarLocsBuilder) { // // Unless we've already done so, create the single location def now. if (AlwaysStackHomed.insert(Aggr).second) { - assert(isa<AllocaInst>(VarLoc.V)); + assert(!VarLoc.Values.hasArgList() && + isa<AllocaInst>(VarLoc.Values.getVariableLocationOp(0))); // TODO: When more complex cases are handled VarLoc.Expr should be // built appropriately rather than always using an empty DIExpression. // The assert below is a reminder. assert(Simple); VarLoc.Expr = DIExpression::get(Fn.getContext(), std::nullopt); DebugVariable Var = FnVarLocs->getVariable(VarLoc.VariableID); - FnVarLocs->addSingleLocVar(Var, VarLoc.Expr, VarLoc.DL, VarLoc.V); + FnVarLocs->addSingleLocVar(Var, VarLoc.Expr, VarLoc.DL, VarLoc.Values); InsertedAnyIntrinsics = true; } } @@ -2119,13 +2127,16 @@ bool AssignmentTrackingLowering::emitPromotedVarLocs( if (VarsWithStackSlot->contains(getAggregate(DVI))) continue; // Wrapper to get a single value (or undef) from DVI. - auto GetValue = [DVI]() -> Value * { + auto GetValue = [DVI]() -> RawLocationWrapper { // We can't handle variadic DIExpressions yet so treat those as // kill locations. + Value *V; if (DVI->isKillLocation() || DVI->getValue() == nullptr || DVI->hasArgList()) - return PoisonValue::get(Type::getInt32Ty(DVI->getContext())); - return DVI->getValue(); + V = PoisonValue::get(Type::getInt32Ty(DVI->getContext())); + else + V = DVI->getVariableLocationOp(0); + return RawLocationWrapper(ValueAsMetadata::get(V)); }; Instruction *InsertBefore = I.getNextNode(); assert(InsertBefore && "Unexpected: debug intrinsics after a terminator"); @@ -2213,7 +2224,8 @@ static bool removeRedundantDbgLocsUsingForwardScan(const BasicBlock *BB, FunctionVarLocsBuilder &FnVarLocs) { bool Changed = false; - DenseMap<DebugVariable, std::pair<Value *, DIExpression *>> VariableMap; + DenseMap<DebugVariable, std::pair<RawLocationWrapper, DIExpression *>> + VariableMap; // Scan over the entire block, not just over the instructions mapped by // FnVarLocs, because wedges in FnVarLocs may only be seperated by debug @@ -2238,9 +2250,9 @@ removeRedundantDbgLocsUsingForwardScan(const BasicBlock *BB, // Update the map if we found a new value/expression describing the // variable, or if the variable wasn't mapped already. - if (VMI == VariableMap.end() || VMI->second.first != Loc.V || + if (VMI == VariableMap.end() || VMI->second.first != Loc.Values || VMI->second.second != Loc.Expr) { - VariableMap[Key] = {Loc.V, Loc.Expr}; + VariableMap[Key] = {Loc.Values, Loc.Expr}; NewDefs.push_back(Loc); continue; } @@ -2320,7 +2332,7 @@ removeUndefDbgLocsFromEntryBlock(const BasicBlock *BB, // Remove undef entries that are encountered before any non-undef // intrinsics from the entry block. - if (isa<UndefValue>(Loc.V) && !HasDefinedBits(Aggr, Var)) { + if (Loc.Values.isKillLocation(Loc.Expr) && !HasDefinedBits(Aggr, Var)) { // Did not insert this Loc, which is the same as removing it. NumDefsRemoved++; ChangedThisWedge = true; |