diff options
author | Hans Wennborg <hans@chromium.org> | 2021-03-17 13:36:48 +0100 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2021-03-17 13:36:48 +0100 |
commit | 01ac6d1587e8613ba4278786e8341f8b492ac941 (patch) | |
tree | baf00c4693ff3fafe624fc178ca78286f8ae3811 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | c165a99a1b8861af87e0509a2e14debf2764804b (diff) | |
download | llvm-01ac6d1587e8613ba4278786e8341f8b492ac941.zip llvm-01ac6d1587e8613ba4278786e8341f8b492ac941.tar.gz llvm-01ac6d1587e8613ba4278786e8341f8b492ac941.tar.bz2 |
Revert "[DebugInfo] Handle multiple variable location operands in IR"
This caused non-deterministic compiler output; see comment on the
code review.
> This patch updates the various IR passes to correctly handle dbg.values with a
> DIArgList location. This patch does not actually allow DIArgLists to be produced
> by salvageDebugInfo, and it does not affect any pass after codegen-prepare.
> Other than that, it should cover every IR pass.
>
> Most of the changes simply extend code that operated on a single debug value to
> operate on the list of debug values in the style of any_of, all_of, for_each,
> etc. Instances of setOperand(0, ...) have been replaced with with
> replaceVariableLocationOp, which takes the value that is being replaced as an
> additional argument. In places where this value isn't readily available, we have
> to track the old value through to the point where it gets replaced.
>
> Differential Revision: https://reviews.llvm.org/D88232
This reverts commit df69c69427dea7f5b3b3a4d4564bc77b0926ec88.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 104 |
1 files changed, 22 insertions, 82 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 64c2042..e899bb13 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -411,7 +411,7 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I, return true; } if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(I)) { - if (DVI->hasArgList() || DVI->getValue(0)) + if (DVI->getValue()) return false; return true; } @@ -1360,7 +1360,7 @@ static bool PhiHasDebugValue(DILocalVariable *DIVar, SmallVector<DbgValueInst *, 1> DbgValues; findDbgValues(DbgValues, APN); for (auto *DVI : DbgValues) { - assert(is_contained(DVI->getValues(), APN)); + assert(DVI->getValue() == APN); if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr)) return true; } @@ -1387,19 +1387,13 @@ static bool valueCoversEntireFragment(Type *ValTy, DbgVariableIntrinsic *DII) { // We can't always calculate the size of the DI variable (e.g. if it is a // VLA). Try to use the size of the alloca that the dbg intrinsic describes // intead. - if (DII->isAddressOfVariable()) { - // DII should have exactly 1 location when it is an address. - assert(DII->getNumVariableLocationOps() == 1 && - "address of variable must have exactly 1 location operand."); - if (auto *AI = - dyn_cast_or_null<AllocaInst>(DII->getVariableLocationOp(0))) { + if (DII->isAddressOfVariable()) + if (auto *AI = dyn_cast_or_null<AllocaInst>(DII->getVariableLocationOp(0))) if (Optional<TypeSize> FragmentSize = AI->getAllocationSizeInBits(DL)) { assert(ValueSize.isScalable() == FragmentSize->isScalable() && "Both sizes should agree on the scalable flag."); return TypeSize::isKnownGE(ValueSize, *FragmentSize); } - } - } // Could not determine size of variable. Conservatively return false. return false; } @@ -1602,26 +1596,17 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB, ValueToValueMapTy DbgValueMap; for (auto &I : *BB) { if (auto DbgII = dyn_cast<DbgVariableIntrinsic>(&I)) { - for (Value *V : DbgII->location_ops()) - if (auto *Loc = dyn_cast_or_null<PHINode>(V)) - DbgValueMap.insert({Loc, DbgII}); + if (auto *Loc = + dyn_cast_or_null<PHINode>(DbgII->getVariableLocationOp(0))) + DbgValueMap.insert({Loc, DbgII}); } } if (DbgValueMap.size() == 0) return; - // Map a pair of the destination BB and old dbg.value to the new dbg.value, - // so that if a dbg.value is being rewritten to use more than one of the - // inserted PHIs in the same destination BB, we can update the same dbg.value - // with all the new PHIs instead of creating one copy for each. - SmallDenseMap<std::pair<BasicBlock *, DbgVariableIntrinsic *>, - DbgVariableIntrinsic *> - NewDbgValueMap; // Then iterate through the new PHIs and look to see if they use one of the - // previously mapped PHIs. If so, create a new dbg.value intrinsic that will - // propagate the info through the new PHI. If we use more than one new PHI in - // a single destination BB with the same old dbg.value, merge the updates so - // that we get a single new dbg.value with all the new PHIs. + // previously mapped PHIs. If so, insert a new dbg.value intrinsic that will + // propagate the info through the new PHI. for (auto PHI : InsertedPHIs) { BasicBlock *Parent = PHI->getParent(); // Avoid inserting an intrinsic into an EH block. @@ -1631,27 +1616,15 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB, auto V = DbgValueMap.find(VI); if (V != DbgValueMap.end()) { auto *DbgII = cast<DbgVariableIntrinsic>(V->second); - auto NewDI = NewDbgValueMap.find({Parent, DbgII}); - if (NewDI == NewDbgValueMap.end()) { - auto *NewDbgII = cast<DbgVariableIntrinsic>(DbgII->clone()); - NewDI = NewDbgValueMap.insert({{Parent, DbgII}, NewDbgII}).first; - } - DbgVariableIntrinsic *NewDbgII = NewDI->second; - // If PHI contains VI as an operand more than once, we may - // replaced it in NewDbgII; confirm that it is present. - if (is_contained(NewDbgII->location_ops(), VI)) - NewDbgII->replaceVariableLocationOp(VI, PHI); + DbgVariableIntrinsic *NewDbgII = + cast<DbgVariableIntrinsic>(DbgII->clone()); + NewDbgII->replaceVariableLocationOp(VI, PHI); + auto InsertionPt = Parent->getFirstInsertionPt(); + assert(InsertionPt != Parent->end() && "Ill-formed basic block"); + NewDbgII->insertBefore(&*InsertionPt); } } } - // Insert thew new dbg.values into their destination blocks. - for (auto DI : NewDbgValueMap) { - BasicBlock *Parent = DI.first.first; - auto *NewDbgII = DI.second; - auto InsertionPt = Parent->getFirstInsertionPt(); - assert(InsertionPt != Parent->end() && "Ill-formed basic block"); - NewDbgII->insertBefore(&*InsertionPt); - } } /// Finds all intrinsics declaring local variables as living in the memory that @@ -1692,25 +1665,11 @@ void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V) { // DenseMap lookup. if (!V->isUsedByMetadata()) return; - // TODO: If this value appears multiple times in a DIArgList, we should still - // only add the owning DbgValueInst once; use this set to track ArgListUsers. - // This behaviour can be removed when we can automatically remove duplicates. - SmallPtrSet<DbgValueInst *, 4> EncounteredDbgValues; - if (auto *L = LocalAsMetadata::getIfExists(V)) { - if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L)) { + if (auto *L = LocalAsMetadata::getIfExists(V)) + if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L)) for (User *U : MDV->users()) if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(U)) DbgValues.push_back(DVI); - } - for (Metadata *AL : L->getAllArgListUsers()) { - if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), AL)) { - for (User *U : MDV->users()) - if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(U)) - if (EncounteredDbgValues.insert(DVI).second) - DbgValues.push_back(DVI); - } - } - } } void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers, @@ -1719,25 +1678,11 @@ void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers, // DenseMap lookup. if (!V->isUsedByMetadata()) return; - // TODO: If this value appears multiple times in a DIArgList, we should still - // only add the owning DbgValueInst once; use this set to track ArgListUsers. - // This behaviour can be removed when we can automatically remove duplicates. - SmallPtrSet<DbgVariableIntrinsic *, 4> EncounteredDbgValues; - if (auto *L = LocalAsMetadata::getIfExists(V)) { - if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L)) { + if (auto *L = LocalAsMetadata::getIfExists(V)) + if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L)) for (User *U : MDV->users()) if (DbgVariableIntrinsic *DII = dyn_cast<DbgVariableIntrinsic>(U)) DbgUsers.push_back(DII); - } - for (Metadata *AL : L->getAllArgListUsers()) { - if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), AL)) { - for (User *U : MDV->users()) - if (DbgVariableIntrinsic *DII = dyn_cast<DbgVariableIntrinsic>(U)) - if (EncounteredDbgValues.insert(DII).second) - DbgUsers.push_back(DII); - } - } - } } bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress, @@ -1807,14 +1752,9 @@ void llvm::salvageDebugInfoForDbgValues( // are implicitly pointing out the value as a DWARF memory location // description. bool StackValue = isa<DbgValueInst>(DII); - auto DIILocation = DII->location_ops(); - assert( - is_contained(DIILocation, &I) && - "DbgVariableIntrinsic must use salvaged instruction as its location"); - unsigned LocNo = std::distance(DIILocation.begin(), find(DIILocation, &I)); DIExpression *DIExpr = - salvageDebugInfoImpl(I, DII->getExpression(), StackValue, LocNo); + salvageDebugInfoImpl(I, DII->getExpression(), StackValue); // salvageDebugInfoImpl should fail on examining the first element of // DbgUsers, or none of them. @@ -1907,7 +1847,7 @@ bool getSalvageOpsForBinOp(BinaryOperator *BI, DIExpression *llvm::salvageDebugInfoImpl(Instruction &I, DIExpression *SrcDIExpr, - bool WithStackValue, unsigned LocNo) { + bool WithStackValue) { auto &M = *I.getModule(); auto &DL = M.getDataLayout(); @@ -1915,7 +1855,7 @@ DIExpression *llvm::salvageDebugInfoImpl(Instruction &I, auto doSalvage = [&](SmallVectorImpl<uint64_t> &Ops) -> DIExpression * { DIExpression *DIExpr = SrcDIExpr; if (!Ops.empty()) { - DIExpr = DIExpression::appendOpsToArg(DIExpr, Ops, LocNo, WithStackValue); + DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, WithStackValue); } return DIExpr; }; |