diff options
| -rw-r--r-- | llvm/include/llvm/Transforms/Utils/Local.h | 6 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 8 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 11 |
3 files changed, 18 insertions, 7 deletions
diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index 86a32bb6300..ec8b0eda364 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -174,6 +174,12 @@ bool RecursivelyDeleteDeadPHINode(PHINode *PN, bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI = nullptr); +/// Replace all the uses of an SSA value in @llvm.dbg intrinsics with +/// undef. This is useful for signaling that a variable, e.g. has been +/// found dead and hence it's unavailable at a given program point. +/// Returns true if the dbg values have been changed. +bool replaceDbgUsesWithUndef(Instruction *I); + //===----------------------------------------------------------------------===// // Control Flow Graph Restructuring. // diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index 61b6d7ca259..cb893eab165 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -789,13 +789,7 @@ void ReassociatePass::RewriteExprTree(BinaryOperator *I, // Discard any debug info related to the expressions that has changed (we // can leave debug infor related to the root, since the result of the // expression tree should be the same even after reassociation). - SmallVector<DbgVariableIntrinsic *, 1> DbgUsers; - findDbgUsers(DbgUsers, ExpressionChanged); - for (auto *DII : DbgUsers) { - Value *Undef = UndefValue::get(ExpressionChanged->getType()); - DII->setOperand(0, MetadataAsValue::get(DII->getContext(), - ValueAsMetadata::get(Undef))); - } + replaceDbgUsesWithUndef(ExpressionChanged); ExpressionChanged->moveBefore(I); ExpressionChanged = cast<BinaryOperator>(*ExpressionChanged->user_begin()); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index d9e0c15dda3..2b7d7ad9d4d 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -476,6 +476,17 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions( } } +bool llvm::replaceDbgUsesWithUndef(Instruction *I) { + SmallVector<DbgVariableIntrinsic *, 1> DbgUsers; + findDbgUsers(DbgUsers, I); + for (auto *DII : DbgUsers) { + Value *Undef = UndefValue::get(I->getType()); + DII->setOperand(0, MetadataAsValue::get(DII->getContext(), + ValueAsMetadata::get(Undef))); + } + return !DbgUsers.empty(); +} + /// areAllUsesEqual - Check whether the uses of a value are all the same. /// This is similar to Instruction::hasOneUse() except this will also return /// true when there are no uses or multiple uses that all refer to the same |

