mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 20:23:11 +01:00
[DebugInfo] Refactor DbgInfoIntrinsic class hierarchy.
In the past, DbgInfoIntrinsic has a strong assumption that these intrinsics all have variables and expressions attached to them. However, it is too strong to derive the class for other debug entities. Now, it has problems for debug labels. In order to make DbgInfoIntrinsic as a base class for 'debug info', I create a class for 'variable debug info', DbgVariableIntrinsic. DbgDeclareInst, DbgAddrIntrinsic, and DbgValueInst will be derived from it. Differential Revision: https://reviews.llvm.org/D50220 llvm-svn: 338984
This commit is contained in:
parent
54514a9035
commit
fd20113dad
@ -1417,7 +1417,9 @@ LLVMTypeRef LLVMX86MMXType(void);
|
||||
macro(CallInst) \
|
||||
macro(IntrinsicInst) \
|
||||
macro(DbgInfoIntrinsic) \
|
||||
macro(DbgVariableIntrinsic) \
|
||||
macro(DbgDeclareInst) \
|
||||
macro(DbgLabelInst) \
|
||||
macro(MemIntrinsic) \
|
||||
macro(MemCpyInst) \
|
||||
macro(MemMoveInst) \
|
||||
|
@ -211,10 +211,12 @@ public:
|
||||
RetTy visitCatchPadInst(CatchPadInst &I) { DELEGATE(FuncletPadInst); }
|
||||
|
||||
// Handle the special instrinsic instruction classes.
|
||||
RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgInfoIntrinsic);}
|
||||
RetTy visitDbgValueInst(DbgValueInst &I) { DELEGATE(DbgInfoIntrinsic);}
|
||||
RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgVariableIntrinsic);}
|
||||
RetTy visitDbgValueInst(DbgValueInst &I) { DELEGATE(DbgVariableIntrinsic);}
|
||||
RetTy visitDbgVariableIntrinsic(DbgVariableIntrinsic &I)
|
||||
{ DELEGATE(DbgInfoIntrinsic);}
|
||||
RetTy visitDbgLabelInst(DbgLabelInst &I) { DELEGATE(DbgInfoIntrinsic);}
|
||||
RetTy visitDbgInfoIntrinsic(DbgInfoIntrinsic &I) { DELEGATE(IntrinsicInst); }
|
||||
RetTy visitDbgInfoIntrinsic(DbgInfoIntrinsic &I){ DELEGATE(IntrinsicInst); }
|
||||
RetTy visitMemSetInst(MemSetInst &I) { DELEGATE(MemIntrinsic); }
|
||||
RetTy visitMemCpyInst(MemCpyInst &I) { DELEGATE(MemTransferInst); }
|
||||
RetTy visitMemMoveInst(MemMoveInst &I) { DELEGATE(MemTransferInst); }
|
||||
|
@ -65,6 +65,27 @@ namespace llvm {
|
||||
|
||||
/// This is the common base class for debug info intrinsics.
|
||||
class DbgInfoIntrinsic : public IntrinsicInst {
|
||||
public:
|
||||
/// \name Casting methods
|
||||
/// @{
|
||||
static bool classof(const IntrinsicInst *I) {
|
||||
switch (I->getIntrinsicID()) {
|
||||
case Intrinsic::dbg_declare:
|
||||
case Intrinsic::dbg_value:
|
||||
case Intrinsic::dbg_addr:
|
||||
case Intrinsic::dbg_label:
|
||||
return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
static bool classof(const Value *V) {
|
||||
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
||||
}
|
||||
/// @}
|
||||
};
|
||||
|
||||
/// This is the common base class for debug info intrinsics for variables.
|
||||
class DbgVariableIntrinsic : public DbgInfoIntrinsic {
|
||||
public:
|
||||
/// Get the location corresponding to the variable referenced by the debug
|
||||
/// info intrinsic. Depending on the intrinsic, this could be the
|
||||
@ -104,7 +125,6 @@ namespace llvm {
|
||||
case Intrinsic::dbg_declare:
|
||||
case Intrinsic::dbg_value:
|
||||
case Intrinsic::dbg_addr:
|
||||
case Intrinsic::dbg_label:
|
||||
return true;
|
||||
default: return false;
|
||||
}
|
||||
@ -116,7 +136,7 @@ namespace llvm {
|
||||
};
|
||||
|
||||
/// This represents the llvm.dbg.declare instruction.
|
||||
class DbgDeclareInst : public DbgInfoIntrinsic {
|
||||
class DbgDeclareInst : public DbgVariableIntrinsic {
|
||||
public:
|
||||
Value *getAddress() const { return getVariableLocation(); }
|
||||
|
||||
@ -132,7 +152,7 @@ namespace llvm {
|
||||
};
|
||||
|
||||
/// This represents the llvm.dbg.addr instruction.
|
||||
class DbgAddrIntrinsic : public DbgInfoIntrinsic {
|
||||
class DbgAddrIntrinsic : public DbgVariableIntrinsic {
|
||||
public:
|
||||
Value *getAddress() const { return getVariableLocation(); }
|
||||
|
||||
@ -147,7 +167,7 @@ namespace llvm {
|
||||
};
|
||||
|
||||
/// This represents the llvm.dbg.value instruction.
|
||||
class DbgValueInst : public DbgInfoIntrinsic {
|
||||
class DbgValueInst : public DbgVariableIntrinsic {
|
||||
public:
|
||||
Value *getValue() const {
|
||||
return getVariableLocation(/* AllowNullOp = */ false);
|
||||
@ -168,17 +188,13 @@ namespace llvm {
|
||||
class DbgLabelInst : public DbgInfoIntrinsic {
|
||||
public:
|
||||
DILabel *getLabel() const {
|
||||
return cast<DILabel>(getRawVariable());
|
||||
return cast<DILabel>(getRawLabel());
|
||||
}
|
||||
|
||||
Metadata *getRawVariable() const {
|
||||
Metadata *getRawLabel() const {
|
||||
return cast<MetadataAsValue>(getArgOperand(0))->getMetadata();
|
||||
}
|
||||
|
||||
Metadata *getRawExpression() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
/// @{
|
||||
static bool classof(const IntrinsicInst *I) {
|
||||
|
@ -44,7 +44,7 @@ class AssumptionCache;
|
||||
class BasicBlock;
|
||||
class BranchInst;
|
||||
class CallInst;
|
||||
class DbgInfoIntrinsic;
|
||||
class DbgVariableIntrinsic;
|
||||
class DbgValueInst;
|
||||
class DIBuilder;
|
||||
class Function;
|
||||
@ -270,17 +270,17 @@ inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
|
||||
|
||||
/// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
|
||||
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
||||
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
||||
StoreInst *SI, DIBuilder &Builder);
|
||||
|
||||
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
|
||||
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
||||
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
||||
LoadInst *LI, DIBuilder &Builder);
|
||||
|
||||
/// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
|
||||
/// llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
||||
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
||||
PHINode *LI, DIBuilder &Builder);
|
||||
|
||||
/// Lowers llvm.dbg.declare intrinsics into appropriate set of
|
||||
@ -294,13 +294,13 @@ void insertDebugValuesForPHIs(BasicBlock *BB,
|
||||
/// Finds all intrinsics declaring local variables as living in the memory that
|
||||
/// 'V' points to. This may include a mix of dbg.declare and
|
||||
/// dbg.addr intrinsics.
|
||||
TinyPtrVector<DbgInfoIntrinsic *> FindDbgAddrUses(Value *V);
|
||||
TinyPtrVector<DbgVariableIntrinsic *> FindDbgAddrUses(Value *V);
|
||||
|
||||
/// Finds the llvm.dbg.value intrinsics describing a value.
|
||||
void findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V);
|
||||
|
||||
/// Finds the debug info intrinsics describing a value.
|
||||
void findDbgUsers(SmallVectorImpl<DbgInfoIntrinsic *> &DbgInsts, Value *V);
|
||||
void findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgInsts, Value *V);
|
||||
|
||||
/// Replaces llvm.dbg.declare instruction when the address it
|
||||
/// describes is replaced with a new value. If Deref is true, an
|
||||
|
@ -5176,7 +5176,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
|
||||
}
|
||||
case Intrinsic::dbg_addr:
|
||||
case Intrinsic::dbg_declare: {
|
||||
const DbgInfoIntrinsic &DI = cast<DbgInfoIntrinsic>(I);
|
||||
const auto &DI = cast<DbgVariableIntrinsic>(I);
|
||||
DILocalVariable *Variable = DI.getVariable();
|
||||
DIExpression *Expression = DI.getExpression();
|
||||
dropDanglingDebugInfo(Variable, Expression);
|
||||
|
@ -32,10 +32,11 @@
|
||||
using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// DbgInfoIntrinsic - This is the common base class for debug info intrinsics
|
||||
/// DbgVariableIntrinsic - This is the common base class for debug info
|
||||
/// intrinsics for variables.
|
||||
///
|
||||
|
||||
Value *DbgInfoIntrinsic::getVariableLocation(bool AllowNullOp) const {
|
||||
Value *DbgVariableIntrinsic::getVariableLocation(bool AllowNullOp) const {
|
||||
Value *Op = getArgOperand(0);
|
||||
if (AllowNullOp && !Op)
|
||||
return nullptr;
|
||||
@ -45,14 +46,11 @@ Value *DbgInfoIntrinsic::getVariableLocation(bool AllowNullOp) const {
|
||||
return V->getValue();
|
||||
|
||||
// When the value goes to null, it gets replaced by an empty MDNode.
|
||||
assert((isa<DbgLabelInst>(this)
|
||||
|| !cast<MDNode>(MD)->getNumOperands())
|
||||
&& "DbgValueInst Expected an empty MDNode");
|
||||
|
||||
assert(!cast<MDNode>(MD)->getNumOperands() && "Expected an empty MDNode");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Optional<uint64_t> DbgInfoIntrinsic::getFragmentSizeInBits() const {
|
||||
Optional<uint64_t> DbgVariableIntrinsic::getFragmentSizeInBits() const {
|
||||
if (auto Fragment = getExpression()->getFragmentInfo())
|
||||
return Fragment->SizeInBits;
|
||||
return getVariable()->getSizeInBits();
|
||||
|
@ -467,7 +467,7 @@ private:
|
||||
void visitUserOp2(Instruction &I) { visitUserOp1(I); }
|
||||
void visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS);
|
||||
void visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI);
|
||||
void visitDbgIntrinsic(StringRef Kind, DbgInfoIntrinsic &DII);
|
||||
void visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII);
|
||||
void visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI);
|
||||
void visitAtomicCmpXchgInst(AtomicCmpXchgInst &CXI);
|
||||
void visitAtomicRMWInst(AtomicRMWInst &RMWI);
|
||||
@ -505,12 +505,12 @@ private:
|
||||
void verifyFrameRecoverIndices();
|
||||
void verifySiblingFuncletUnwinds();
|
||||
|
||||
void verifyFragmentExpression(const DbgInfoIntrinsic &I);
|
||||
void verifyFragmentExpression(const DbgVariableIntrinsic &I);
|
||||
template <typename ValueOrMetadata>
|
||||
void verifyFragmentExpression(const DIVariable &V,
|
||||
DIExpression::FragmentInfo Fragment,
|
||||
ValueOrMetadata *Desc);
|
||||
void verifyFnArgs(const DbgInfoIntrinsic &I);
|
||||
void verifyFnArgs(const DbgVariableIntrinsic &I);
|
||||
|
||||
/// Module-level debug info verification...
|
||||
void verifyCompileUnits();
|
||||
@ -3984,7 +3984,7 @@ void Verifier::visitInstruction(Instruction &I) {
|
||||
visitMDNode(*N);
|
||||
}
|
||||
|
||||
if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&I))
|
||||
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I))
|
||||
verifyFragmentExpression(*DII);
|
||||
|
||||
InstsInThisBlock.insert(&I);
|
||||
@ -4090,13 +4090,13 @@ void Verifier::visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS) {
|
||||
case Intrinsic::dbg_declare: // llvm.dbg.declare
|
||||
Assert(isa<MetadataAsValue>(CS.getArgOperand(0)),
|
||||
"invalid llvm.dbg.declare intrinsic call 1", CS);
|
||||
visitDbgIntrinsic("declare", cast<DbgInfoIntrinsic>(*CS.getInstruction()));
|
||||
visitDbgIntrinsic("declare", cast<DbgVariableIntrinsic>(*CS.getInstruction()));
|
||||
break;
|
||||
case Intrinsic::dbg_addr: // llvm.dbg.addr
|
||||
visitDbgIntrinsic("addr", cast<DbgInfoIntrinsic>(*CS.getInstruction()));
|
||||
visitDbgIntrinsic("addr", cast<DbgVariableIntrinsic>(*CS.getInstruction()));
|
||||
break;
|
||||
case Intrinsic::dbg_value: // llvm.dbg.value
|
||||
visitDbgIntrinsic("value", cast<DbgInfoIntrinsic>(*CS.getInstruction()));
|
||||
visitDbgIntrinsic("value", cast<DbgVariableIntrinsic>(*CS.getInstruction()));
|
||||
break;
|
||||
case Intrinsic::dbg_label: // llvm.dbg.label
|
||||
visitDbgLabelIntrinsic("label", cast<DbgLabelInst>(*CS.getInstruction()));
|
||||
@ -4491,7 +4491,7 @@ void Verifier::visitConstrainedFPIntrinsic(ConstrainedFPIntrinsic &FPI) {
|
||||
"invalid exception behavior argument", &FPI);
|
||||
}
|
||||
|
||||
void Verifier::visitDbgIntrinsic(StringRef Kind, DbgInfoIntrinsic &DII) {
|
||||
void Verifier::visitDbgIntrinsic(StringRef Kind, DbgVariableIntrinsic &DII) {
|
||||
auto *MD = cast<MetadataAsValue>(DII.getArgOperand(0))->getMetadata();
|
||||
AssertDI(isa<ValueAsMetadata>(MD) ||
|
||||
(isa<MDNode>(MD) && !cast<MDNode>(MD)->getNumOperands()),
|
||||
@ -4531,9 +4531,9 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgInfoIntrinsic &DII) {
|
||||
}
|
||||
|
||||
void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) {
|
||||
AssertDI(isa<DILabel>(DLI.getRawVariable()),
|
||||
AssertDI(isa<DILabel>(DLI.getRawLabel()),
|
||||
"invalid llvm.dbg." + Kind + " intrinsic variable", &DLI,
|
||||
DLI.getRawVariable());
|
||||
DLI.getRawLabel());
|
||||
|
||||
// Ignore broken !dbg attachments; they're checked elsewhere.
|
||||
if (MDNode *N = DLI.getDebugLoc().getAsMDNode())
|
||||
@ -4560,10 +4560,7 @@ void Verifier::visitDbgLabelIntrinsic(StringRef Kind, DbgLabelInst &DLI) {
|
||||
Loc->getScope()->getSubprogram());
|
||||
}
|
||||
|
||||
void Verifier::verifyFragmentExpression(const DbgInfoIntrinsic &I) {
|
||||
if (dyn_cast<DbgLabelInst>(&I))
|
||||
return;
|
||||
|
||||
void Verifier::verifyFragmentExpression(const DbgVariableIntrinsic &I) {
|
||||
DILocalVariable *V = dyn_cast_or_null<DILocalVariable>(I.getRawVariable());
|
||||
DIExpression *E = dyn_cast_or_null<DIExpression>(I.getRawExpression());
|
||||
|
||||
@ -4605,7 +4602,7 @@ void Verifier::verifyFragmentExpression(const DIVariable &V,
|
||||
AssertDI(FragSize != *VarSize, "fragment covers entire variable", Desc, &V);
|
||||
}
|
||||
|
||||
void Verifier::verifyFnArgs(const DbgInfoIntrinsic &I) {
|
||||
void Verifier::verifyFnArgs(const DbgVariableIntrinsic &I) {
|
||||
// This function does not take the scope of noninlined function arguments into
|
||||
// account. Don't run it if current function is nodebug, because it may
|
||||
// contain inlined debug intrinsics.
|
||||
|
@ -2144,7 +2144,7 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) {
|
||||
|
||||
// If we are removing an alloca with a dbg.declare, insert dbg.value calls
|
||||
// before each store.
|
||||
TinyPtrVector<DbgInfoIntrinsic *> DIIs;
|
||||
TinyPtrVector<DbgVariableIntrinsic *> DIIs;
|
||||
std::unique_ptr<DIBuilder> DIB;
|
||||
if (isa<AllocaInst>(MI)) {
|
||||
DIIs = FindDbgAddrUses(&MI);
|
||||
@ -2934,7 +2934,7 @@ static bool TryToSinkInstruction(Instruction *I, BasicBlock *DestBlock) {
|
||||
|
||||
// Also sink all related debug uses from the source basic block. Otherwise we
|
||||
// get debug use before the def.
|
||||
SmallVector<DbgInfoIntrinsic *, 1> DbgUsers;
|
||||
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
|
||||
findDbgUsers(DbgUsers, I);
|
||||
for (auto *DII : DbgUsers) {
|
||||
if (DII->getParent() == SrcBlock) {
|
||||
|
@ -508,7 +508,7 @@ bool AggressiveDeadCodeElimination::removeDeadInstructions() {
|
||||
if (isLive(&I))
|
||||
continue;
|
||||
|
||||
if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&I)) {
|
||||
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
|
||||
// Check if the scope of this variable location is alive.
|
||||
if (AliveScopes.count(DII->getDebugLoc()->getScope()))
|
||||
continue;
|
||||
|
@ -788,7 +788,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<DbgInfoIntrinsic *, 1> DbgUsers;
|
||||
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
|
||||
findDbgUsers(DbgUsers, ExpressionChanged);
|
||||
for (auto *DII : DbgUsers) {
|
||||
Value *Undef = UndefValue::get(ExpressionChanged->getType());
|
||||
|
@ -4212,7 +4212,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
|
||||
|
||||
// Migrate debug information from the old alloca to the new alloca(s)
|
||||
// and the individual partitions.
|
||||
TinyPtrVector<DbgInfoIntrinsic *> DbgDeclares = FindDbgAddrUses(&AI);
|
||||
TinyPtrVector<DbgVariableIntrinsic *> DbgDeclares = FindDbgAddrUses(&AI);
|
||||
if (!DbgDeclares.empty()) {
|
||||
auto *Var = DbgDeclares.front()->getVariable();
|
||||
auto *Expr = DbgDeclares.front()->getExpression();
|
||||
@ -4264,7 +4264,7 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
|
||||
}
|
||||
|
||||
// Remove any existing intrinsics describing the same alloca.
|
||||
for (DbgInfoIntrinsic *OldDII : FindDbgAddrUses(Fragment.Alloca))
|
||||
for (DbgVariableIntrinsic *OldDII : FindDbgAddrUses(Fragment.Alloca))
|
||||
OldDII->eraseFromParent();
|
||||
|
||||
DIB.insertDeclare(Fragment.Alloca, Var, FragmentExpr,
|
||||
@ -4379,7 +4379,7 @@ bool SROA::deleteDeadInstructions(
|
||||
// not be able to find it.
|
||||
if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
|
||||
DeletedAllocas.insert(AI);
|
||||
for (DbgInfoIntrinsic *OldDII : FindDbgAddrUses(AI))
|
||||
for (DbgVariableIntrinsic *OldDII : FindDbgAddrUses(AI))
|
||||
OldDII->eraseFromParent();
|
||||
}
|
||||
|
||||
|
@ -1244,7 +1244,7 @@ static bool PhiHasDebugValue(DILocalVariable *DIVar,
|
||||
/// alloc size of the value when doing the comparison. E.g. an i1 value will be
|
||||
/// identified as covering an n-bit fragment, if the store size of i1 is at
|
||||
/// least n bits.
|
||||
static bool valueCoversEntireFragment(Type *ValTy, DbgInfoIntrinsic *DII) {
|
||||
static bool valueCoversEntireFragment(Type *ValTy, DbgVariableIntrinsic *DII) {
|
||||
const DataLayout &DL = DII->getModule()->getDataLayout();
|
||||
uint64_t ValueSize = DL.getTypeAllocSizeInBits(ValTy);
|
||||
if (auto FragmentSize = DII->getFragmentSizeInBits())
|
||||
@ -1262,7 +1262,7 @@ static bool valueCoversEntireFragment(Type *ValTy, DbgInfoIntrinsic *DII) {
|
||||
|
||||
/// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value
|
||||
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
||||
void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
||||
StoreInst *SI, DIBuilder &Builder) {
|
||||
assert(DII->isAddressOfVariable());
|
||||
auto *DIVar = DII->getVariable();
|
||||
@ -1319,7 +1319,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
|
||||
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
|
||||
/// that has an associated llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
||||
void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
||||
LoadInst *LI, DIBuilder &Builder) {
|
||||
auto *DIVar = DII->getVariable();
|
||||
auto *DIExpr = DII->getExpression();
|
||||
@ -1348,7 +1348,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
|
||||
/// Inserts a llvm.dbg.value intrinsic after a phi that has an associated
|
||||
/// llvm.dbg.declare or llvm.dbg.addr intrinsic.
|
||||
void llvm::ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII,
|
||||
void llvm::ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII,
|
||||
PHINode *APN, DIBuilder &Builder) {
|
||||
auto *DIVar = DII->getVariable();
|
||||
auto *DIExpr = DII->getExpression();
|
||||
@ -1450,7 +1450,7 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB,
|
||||
// Map existing PHI nodes to their dbg.values.
|
||||
ValueToValueMapTy DbgValueMap;
|
||||
for (auto &I : *BB) {
|
||||
if (auto DbgII = dyn_cast<DbgInfoIntrinsic>(&I)) {
|
||||
if (auto DbgII = dyn_cast<DbgVariableIntrinsic>(&I)) {
|
||||
if (auto *Loc = dyn_cast_or_null<PHINode>(DbgII->getVariableLocation()))
|
||||
DbgValueMap.insert({Loc, DbgII});
|
||||
}
|
||||
@ -1471,7 +1471,7 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB,
|
||||
for (auto VI : PHI->operand_values()) {
|
||||
auto V = DbgValueMap.find(VI);
|
||||
if (V != DbgValueMap.end()) {
|
||||
auto *DbgII = cast<DbgInfoIntrinsic>(V->second);
|
||||
auto *DbgII = cast<DbgVariableIntrinsic>(V->second);
|
||||
Instruction *NewDbgII = DbgII->clone();
|
||||
NewDbgII->setOperand(0, PhiMAV);
|
||||
auto InsertionPt = Parent->getFirstInsertionPt();
|
||||
@ -1485,7 +1485,7 @@ void llvm::insertDebugValuesForPHIs(BasicBlock *BB,
|
||||
/// Finds all intrinsics declaring local variables as living in the memory that
|
||||
/// 'V' points to. This may include a mix of dbg.declare and
|
||||
/// dbg.addr intrinsics.
|
||||
TinyPtrVector<DbgInfoIntrinsic *> llvm::FindDbgAddrUses(Value *V) {
|
||||
TinyPtrVector<DbgVariableIntrinsic *> llvm::FindDbgAddrUses(Value *V) {
|
||||
// This function is hot. Check whether the value has any metadata to avoid a
|
||||
// DenseMap lookup.
|
||||
if (!V->isUsedByMetadata())
|
||||
@ -1497,9 +1497,9 @@ TinyPtrVector<DbgInfoIntrinsic *> llvm::FindDbgAddrUses(Value *V) {
|
||||
if (!MDV)
|
||||
return {};
|
||||
|
||||
TinyPtrVector<DbgInfoIntrinsic *> Declares;
|
||||
TinyPtrVector<DbgVariableIntrinsic *> Declares;
|
||||
for (User *U : MDV->users()) {
|
||||
if (auto *DII = dyn_cast<DbgInfoIntrinsic>(U))
|
||||
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(U))
|
||||
if (DII->isAddressOfVariable())
|
||||
Declares.push_back(DII);
|
||||
}
|
||||
@ -1519,7 +1519,7 @@ void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V) {
|
||||
DbgValues.push_back(DVI);
|
||||
}
|
||||
|
||||
void llvm::findDbgUsers(SmallVectorImpl<DbgInfoIntrinsic *> &DbgUsers,
|
||||
void llvm::findDbgUsers(SmallVectorImpl<DbgVariableIntrinsic *> &DbgUsers,
|
||||
Value *V) {
|
||||
// This function is hot. Check whether the value has any metadata to avoid a
|
||||
// DenseMap lookup.
|
||||
@ -1528,7 +1528,7 @@ void llvm::findDbgUsers(SmallVectorImpl<DbgInfoIntrinsic *> &DbgUsers,
|
||||
if (auto *L = LocalAsMetadata::getIfExists(V))
|
||||
if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L))
|
||||
for (User *U : MDV->users())
|
||||
if (DbgInfoIntrinsic *DII = dyn_cast<DbgInfoIntrinsic>(U))
|
||||
if (DbgVariableIntrinsic *DII = dyn_cast<DbgVariableIntrinsic>(U))
|
||||
DbgUsers.push_back(DII);
|
||||
}
|
||||
|
||||
@ -1536,7 +1536,7 @@ bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
|
||||
Instruction *InsertBefore, DIBuilder &Builder,
|
||||
bool DerefBefore, int Offset, bool DerefAfter) {
|
||||
auto DbgAddrs = FindDbgAddrUses(Address);
|
||||
for (DbgInfoIntrinsic *DII : DbgAddrs) {
|
||||
for (DbgVariableIntrinsic *DII : DbgAddrs) {
|
||||
DebugLoc Loc = DII->getDebugLoc();
|
||||
auto *DIVar = DII->getVariable();
|
||||
auto *DIExpr = DII->getExpression();
|
||||
@ -1604,7 +1604,7 @@ static MetadataAsValue *wrapValueInMetadata(LLVMContext &C, Value *V) {
|
||||
}
|
||||
|
||||
bool llvm::salvageDebugInfo(Instruction &I) {
|
||||
SmallVector<DbgInfoIntrinsic *, 1> DbgUsers;
|
||||
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
|
||||
findDbgUsers(DbgUsers, &I);
|
||||
if (DbgUsers.empty())
|
||||
return false;
|
||||
@ -1614,7 +1614,7 @@ bool llvm::salvageDebugInfo(Instruction &I) {
|
||||
auto &Ctx = I.getContext();
|
||||
auto wrapMD = [&](Value *V) { return wrapValueInMetadata(Ctx, V); };
|
||||
|
||||
auto doSalvage = [&](DbgInfoIntrinsic *DII, SmallVectorImpl<uint64_t> &Ops) {
|
||||
auto doSalvage = [&](DbgVariableIntrinsic *DII, SmallVectorImpl<uint64_t> &Ops) {
|
||||
auto *DIExpr = DII->getExpression();
|
||||
if (!Ops.empty()) {
|
||||
// Do not add DW_OP_stack_value for DbgDeclare and DbgAddr, because they
|
||||
@ -1628,13 +1628,13 @@ bool llvm::salvageDebugInfo(Instruction &I) {
|
||||
LLVM_DEBUG(dbgs() << "SALVAGE: " << *DII << '\n');
|
||||
};
|
||||
|
||||
auto applyOffset = [&](DbgInfoIntrinsic *DII, uint64_t Offset) {
|
||||
auto applyOffset = [&](DbgVariableIntrinsic *DII, uint64_t Offset) {
|
||||
SmallVector<uint64_t, 8> Ops;
|
||||
DIExpression::appendOffset(Ops, Offset);
|
||||
doSalvage(DII, Ops);
|
||||
};
|
||||
|
||||
auto applyOps = [&](DbgInfoIntrinsic *DII,
|
||||
auto applyOps = [&](DbgVariableIntrinsic *DII,
|
||||
std::initializer_list<uint64_t> Opcodes) {
|
||||
SmallVector<uint64_t, 8> Ops(Opcodes);
|
||||
doSalvage(DII, Ops);
|
||||
@ -1733,16 +1733,16 @@ using DbgValReplacement = Optional<DIExpression *>;
|
||||
/// changes are made.
|
||||
static bool rewriteDebugUsers(
|
||||
Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT,
|
||||
function_ref<DbgValReplacement(DbgInfoIntrinsic &DII)> RewriteExpr) {
|
||||
function_ref<DbgValReplacement(DbgVariableIntrinsic &DII)> RewriteExpr) {
|
||||
// Find debug users of From.
|
||||
SmallVector<DbgInfoIntrinsic *, 1> Users;
|
||||
SmallVector<DbgVariableIntrinsic *, 1> Users;
|
||||
findDbgUsers(Users, &From);
|
||||
if (Users.empty())
|
||||
return false;
|
||||
|
||||
// Prevent use-before-def of To.
|
||||
bool Changed = false;
|
||||
SmallPtrSet<DbgInfoIntrinsic *, 1> DeleteOrSalvage;
|
||||
SmallPtrSet<DbgVariableIntrinsic *, 1> DeleteOrSalvage;
|
||||
if (isa<Instruction>(&To)) {
|
||||
bool DomPointAfterFrom = From.getNextNonDebugInstruction() == &DomPoint;
|
||||
|
||||
@ -1831,7 +1831,7 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
|
||||
Type *FromTy = From.getType();
|
||||
Type *ToTy = To.getType();
|
||||
|
||||
auto Identity = [&](DbgInfoIntrinsic &DII) -> DbgValReplacement {
|
||||
auto Identity = [&](DbgVariableIntrinsic &DII) -> DbgValReplacement {
|
||||
return DII.getExpression();
|
||||
};
|
||||
|
||||
@ -1855,7 +1855,7 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
|
||||
|
||||
// The width of the result has shrunk. Use sign/zero extension to describe
|
||||
// the source variable's high bits.
|
||||
auto SignOrZeroExt = [&](DbgInfoIntrinsic &DII) -> DbgValReplacement {
|
||||
auto SignOrZeroExt = [&](DbgVariableIntrinsic &DII) -> DbgValReplacement {
|
||||
DILocalVariable *Var = DII.getVariable();
|
||||
|
||||
// Without knowing signedness, sign/zero extension isn't possible.
|
||||
|
@ -304,13 +304,13 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
|
||||
// Record all debug intrinsics preceding LoopEntryBranch to avoid duplication.
|
||||
using DbgIntrinsicHash =
|
||||
std::pair<std::pair<Value *, DILocalVariable *>, DIExpression *>;
|
||||
auto makeHash = [](DbgInfoIntrinsic *D) -> DbgIntrinsicHash {
|
||||
auto makeHash = [](DbgVariableIntrinsic *D) -> DbgIntrinsicHash {
|
||||
return {{D->getVariableLocation(), D->getVariable()}, D->getExpression()};
|
||||
};
|
||||
SmallDenseSet<DbgIntrinsicHash, 8> DbgIntrinsics;
|
||||
for (auto I = std::next(OrigPreheader->rbegin()), E = OrigPreheader->rend();
|
||||
I != E; ++I) {
|
||||
if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&*I))
|
||||
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&*I))
|
||||
DbgIntrinsics.insert(makeHash(DII));
|
||||
else
|
||||
break;
|
||||
@ -340,7 +340,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
|
||||
RF_NoModuleLevelChanges | RF_IgnoreMissingLocals);
|
||||
|
||||
// Avoid inserting the same intrinsic twice.
|
||||
if (auto *DII = dyn_cast<DbgInfoIntrinsic>(C))
|
||||
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(C))
|
||||
if (DbgIntrinsics.count(makeHash(DII))) {
|
||||
C->deleteValue();
|
||||
continue;
|
||||
|
@ -116,7 +116,7 @@ struct AllocaInfo {
|
||||
bool OnlyUsedInOneBlock;
|
||||
|
||||
Value *AllocaPointerVal;
|
||||
TinyPtrVector<DbgInfoIntrinsic *> DbgDeclares;
|
||||
TinyPtrVector<DbgVariableIntrinsic *> DbgDeclares;
|
||||
|
||||
void clear() {
|
||||
DefiningBlocks.clear();
|
||||
@ -263,7 +263,7 @@ struct PromoteMem2Reg {
|
||||
/// For each alloca, we keep track of the dbg.declare intrinsic that
|
||||
/// describes it, if any, so that we can convert it to a dbg.value
|
||||
/// intrinsic if the alloca gets promoted.
|
||||
SmallVector<TinyPtrVector<DbgInfoIntrinsic *>, 8> AllocaDbgDeclares;
|
||||
SmallVector<TinyPtrVector<DbgVariableIntrinsic *>, 8> AllocaDbgDeclares;
|
||||
|
||||
/// The set of basic blocks the renamer has already visited.
|
||||
SmallPtrSet<BasicBlock *, 16> Visited;
|
||||
@ -426,7 +426,7 @@ static bool rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info,
|
||||
|
||||
// Record debuginfo for the store and remove the declaration's
|
||||
// debuginfo.
|
||||
for (DbgInfoIntrinsic *DII : Info.DbgDeclares) {
|
||||
for (DbgVariableIntrinsic *DII : Info.DbgDeclares) {
|
||||
DIBuilder DIB(*AI->getModule(), /*AllowUnresolved*/ false);
|
||||
ConvertDebugDeclareToDebugValue(DII, Info.OnlyStore, DIB);
|
||||
DII->eraseFromParent();
|
||||
@ -527,7 +527,7 @@ static bool promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
|
||||
while (!AI->use_empty()) {
|
||||
StoreInst *SI = cast<StoreInst>(AI->user_back());
|
||||
// Record debuginfo for the store before removing it.
|
||||
for (DbgInfoIntrinsic *DII : Info.DbgDeclares) {
|
||||
for (DbgVariableIntrinsic *DII : Info.DbgDeclares) {
|
||||
DIBuilder DIB(*AI->getModule(), /*AllowUnresolved*/ false);
|
||||
ConvertDebugDeclareToDebugValue(DII, SI, DIB);
|
||||
}
|
||||
@ -539,7 +539,7 @@ static bool promoteSingleBlockAlloca(AllocaInst *AI, const AllocaInfo &Info,
|
||||
LBI.deleteValue(AI);
|
||||
|
||||
// The alloca's debuginfo can be removed as well.
|
||||
for (DbgInfoIntrinsic *DII : Info.DbgDeclares) {
|
||||
for (DbgVariableIntrinsic *DII : Info.DbgDeclares) {
|
||||
DII->eraseFromParent();
|
||||
LBI.deleteValue(DII);
|
||||
}
|
||||
@ -932,7 +932,7 @@ NextIteration:
|
||||
|
||||
// The currently active variable for this block is now the PHI.
|
||||
IncomingVals[AllocaNo] = APN;
|
||||
for (DbgInfoIntrinsic *DII : AllocaDbgDeclares[AllocaNo])
|
||||
for (DbgVariableIntrinsic *DII : AllocaDbgDeclares[AllocaNo])
|
||||
ConvertDebugDeclareToDebugValue(DII, APN, DIB);
|
||||
|
||||
// Get the next phi node.
|
||||
@ -992,7 +992,7 @@ NextIteration:
|
||||
|
||||
// Record debuginfo for the store before removing it.
|
||||
IncomingLocs[AllocaNo] = SI->getDebugLoc();
|
||||
for (DbgInfoIntrinsic *DII : AllocaDbgDeclares[ai->second])
|
||||
for (DbgVariableIntrinsic *DII : AllocaDbgDeclares[ai->second])
|
||||
ConvertDebugDeclareToDebugValue(DII, SI, DIB);
|
||||
BB->getInstList().erase(SI);
|
||||
}
|
||||
|
@ -683,25 +683,25 @@ TEST(Local, ReplaceAllDbgUsesWith) {
|
||||
// Simulate i32* <-> i64* conversion.
|
||||
EXPECT_TRUE(replaceAllDbgUsesWith(D, C, C, DT));
|
||||
|
||||
SmallVector<DbgInfoIntrinsic *, 2> CDbgVals;
|
||||
SmallVector<DbgVariableIntrinsic *, 2> CDbgVals;
|
||||
findDbgUsers(CDbgVals, &C);
|
||||
EXPECT_EQ(2U, CDbgVals.size());
|
||||
EXPECT_TRUE(any_of(CDbgVals, [](DbgInfoIntrinsic *DII) {
|
||||
EXPECT_TRUE(any_of(CDbgVals, [](DbgVariableIntrinsic *DII) {
|
||||
return isa<DbgAddrIntrinsic>(DII);
|
||||
}));
|
||||
EXPECT_TRUE(any_of(CDbgVals, [](DbgInfoIntrinsic *DII) {
|
||||
EXPECT_TRUE(any_of(CDbgVals, [](DbgVariableIntrinsic *DII) {
|
||||
return isa<DbgDeclareInst>(DII);
|
||||
}));
|
||||
|
||||
EXPECT_TRUE(replaceAllDbgUsesWith(C, D, D, DT));
|
||||
|
||||
SmallVector<DbgInfoIntrinsic *, 2> DDbgVals;
|
||||
SmallVector<DbgVariableIntrinsic *, 2> DDbgVals;
|
||||
findDbgUsers(DDbgVals, &D);
|
||||
EXPECT_EQ(2U, DDbgVals.size());
|
||||
EXPECT_TRUE(any_of(DDbgVals, [](DbgInfoIntrinsic *DII) {
|
||||
EXPECT_TRUE(any_of(DDbgVals, [](DbgVariableIntrinsic *DII) {
|
||||
return isa<DbgAddrIntrinsic>(DII);
|
||||
}));
|
||||
EXPECT_TRUE(any_of(DDbgVals, [](DbgInfoIntrinsic *DII) {
|
||||
EXPECT_TRUE(any_of(DDbgVals, [](DbgVariableIntrinsic *DII) {
|
||||
return isa<DbgDeclareInst>(DII);
|
||||
}));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user