Function *DeclareFn; ///< llvm.dbg.declare
Function *ValueFn; ///< llvm.dbg.value
Function *LabelFn; ///< llvm.dbg.label
- Function *AddrFn; ///< llvm.dbg.addr
Function *AssignFn; ///< llvm.dbg.assign
SmallVector<TrackingMDNodeRef, 4> AllEnumTypes;
DIExpression *Expr, const DILocation *DL,
BasicBlock *InsertBB, Instruction *InsertBefore);
- /// Internal helper for insertDbgAddrIntrinsic.
- Instruction *
- insertDbgAddrIntrinsic(llvm::Value *Val, DILocalVariable *VarInfo,
- DIExpression *Expr, const DILocation *DL,
- BasicBlock *InsertBB, Instruction *InsertBefore);
-
public:
/// Construct a builder for a module.
///
const DILocation *DL,
Instruction *InsertBefore);
- /// Insert a new llvm.dbg.addr intrinsic call.
- /// \param Addr llvm::Value of the address
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertAtEnd Location for the new intrinsic.
- Instruction *insertDbgAddrIntrinsic(llvm::Value *Addr,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- BasicBlock *InsertAtEnd);
-
- /// Insert a new llvm.dbg.addr intrinsic call.
- /// \param Addr llvm::Value of the address.
- /// \param VarInfo Variable's debug info descriptor.
- /// \param Expr A complex location expression.
- /// \param DL Debug info location.
- /// \param InsertBefore Location for the new intrinsic.
- Instruction *insertDbgAddrIntrinsic(llvm::Value *Addr,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- Instruction *InsertBefore);
-
/// Replace the vtable holder in the given type.
///
/// If this creates a self reference, it may orphan some unresolved cycles
class Instruction;
class Module;
-/// 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<DbgVariableIntrinsic *> FindDbgAddrUses(Value *V);
-
-/// Like \c FindDbgAddrUses, but only returns dbg.declare intrinsics, not
-/// dbg.addr.
+/// Finds dbg.declare intrinsics declaring local variables as living in the
+/// memory that 'V' points to.
TinyPtrVector<DbgDeclareInst *> FindDbgDeclareUses(Value *V);
/// Finds the llvm.dbg.value intrinsics describing a value.
/// non-variadic form and not considering the debug operands.
/// \p FirstExpr is the DIExpression for the first debug value.
/// \p FirstIndirect should be true if the first debug value is indirect; in
- /// IR this should be true for dbg.declare and dbg.addr intrinsics and false
- /// for dbg.values, and in MIR this should be true only for DBG_VALUE
- /// instructions whose second operand is an immediate value.
+ /// IR this should be true for dbg.declare intrinsics and false for
+ /// dbg.values, and in MIR this should be true only for DBG_VALUE instructions
+ /// whose second operand is an immediate value.
/// \p SecondExpr and \p SecondIndirect have the same meaning as the prior
/// arguments, but apply to the second debug value.
static bool isEqualExpression(const DIExpression *FirstExpr,
switch (ID) {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
- case Intrinsic::dbg_addr:
case Intrinsic::dbg_label:
case Intrinsic::dbg_assign:
return true;
bool hasArgList() const { return isa<DIArgList>(getRawLocation()); }
- /// Does this describe the address of a local variable. True for dbg.addr and
- /// dbg.declare, but not dbg.value, which describes its value, or dbg.assign,
- /// which describes a combination of the variable's value and address.
+ /// Does this describe the address of a local variable. True for dbg.declare,
+ /// but not dbg.value, which describes its value, or dbg.assign, which
+ /// describes a combination of the variable's value and address.
bool isAddressOfVariable() const {
- return getIntrinsicID() != Intrinsic::dbg_value &&
- getIntrinsicID() != Intrinsic::dbg_assign;
+ return getIntrinsicID() == Intrinsic::dbg_declare;
}
void setKillLocation() {
switch (I->getIntrinsicID()) {
case Intrinsic::dbg_declare:
case Intrinsic::dbg_value:
- case Intrinsic::dbg_addr:
case Intrinsic::dbg_assign:
return true;
default:
/// @}
};
-/// This represents the llvm.dbg.addr instruction.
-class DbgAddrIntrinsic : public DbgVariableIntrinsic {
-public:
- Value *getAddress() const {
- assert(getNumVariableLocationOps() == 1 &&
- "dbg.addr must have exactly 1 location operand.");
- return getVariableLocationOp(0);
- }
-
- /// \name Casting methods
- /// @{
- static bool classof(const IntrinsicInst *I) {
- return I->getIntrinsicID() == Intrinsic::dbg_addr;
- }
- static bool classof(const Value *V) {
- return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
- }
-};
-
/// This represents the llvm.dbg.value instruction.
class DbgValueInst : public DbgVariableIntrinsic {
public:
[llvm_metadata_ty,
llvm_metadata_ty,
llvm_metadata_ty]>;
- def int_dbg_addr : DefaultAttrsIntrinsic<[],
- [llvm_metadata_ty,
- llvm_metadata_ty,
- llvm_metadata_ty]>;
def int_dbg_assign : DefaultAttrsIntrinsic<[],
[llvm_metadata_ty,
llvm_metadata_ty,
using namespace llvm;
using namespace llvm::dwarf;
-static cl::opt<bool>
- UseDbgAddr("use-dbg-addr",
- llvm::cl::desc("Use llvm.dbg.addr for all local variables"),
- cl::init(false), cl::Hidden);
-
DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU)
: M(m), VMContext(M.getContext()), CUNode(CU), DeclareFn(nullptr),
- ValueFn(nullptr), LabelFn(nullptr), AddrFn(nullptr), AssignFn(nullptr),
+ ValueFn(nullptr), LabelFn(nullptr), AssignFn(nullptr),
AllowUnresolvedNodes(AllowUnresolvedNodes) {
if (CUNode) {
if (const auto &ETs = CUNode->getEnumTypes())
return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
}
-Instruction *DIBuilder::insertDbgAddrIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- Instruction *InsertBefore) {
- return insertDbgAddrIntrinsic(
- V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
- InsertBefore);
-}
-
-Instruction *DIBuilder::insertDbgAddrIntrinsic(Value *V,
- DILocalVariable *VarInfo,
- DIExpression *Expr,
- const DILocation *DL,
- BasicBlock *InsertAtEnd) {
- return insertDbgAddrIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr);
-}
-
/// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics.
/// This abstracts over the various ways to specify an insert position.
static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL,
}
static Function *getDeclareIntrin(Module &M) {
- return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr
- : Intrinsic::dbg_declare);
+ return Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
}
Instruction *DIBuilder::insertDbgValueIntrinsic(
InsertBefore);
}
-Instruction *DIBuilder::insertDbgAddrIntrinsic(
- llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr,
- const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) {
- if (!AddrFn)
- AddrFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_addr);
- return insertDbgIntrinsic(AddrFn, Val, VarInfo, Expr, DL, InsertBB,
- InsertBefore);
-}
-
Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo,
DIExpression *Expr, const DILocation *DL,
BasicBlock *InsertBB,
using namespace llvm::at;
using namespace llvm::dwarf;
-/// 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<DbgVariableIntrinsic *> llvm::FindDbgAddrUses(Value *V) {
+TinyPtrVector<DbgDeclareInst *> llvm::FindDbgDeclareUses(Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup.
if (!V->isUsedByMetadata())
if (!MDV)
return {};
- TinyPtrVector<DbgVariableIntrinsic *> Declares;
+ TinyPtrVector<DbgDeclareInst *> Declares;
for (User *U : MDV->users()) {
- if (auto *DII = dyn_cast<DbgVariableIntrinsic>(U))
- if (DII->isAddressOfVariable())
- Declares.push_back(DII);
+ if (auto *DDI = dyn_cast<DbgDeclareInst>(U))
+ Declares.push_back(DDI);
}
return Declares;
}
-TinyPtrVector<DbgDeclareInst *> llvm::FindDbgDeclareUses(Value *V) {
- TinyPtrVector<DbgDeclareInst *> DDIs;
- for (DbgVariableIntrinsic *DVI : FindDbgAddrUses(V))
- if (auto *DDI = dyn_cast<DbgDeclareInst>(DVI))
- DDIs.push_back(DDI);
- return DDIs;
-}
-
void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V) {
// This function is hot. Check whether the value has any metadata to avoid a
// DenseMap lookup.
Changed = true;
}
};
- RemoveUses("llvm.dbg.addr");
RemoveUses("llvm.dbg.declare");
RemoveUses("llvm.dbg.label");
RemoveUses("llvm.dbg.value");
"invalid llvm.dbg.declare intrinsic call 1", Call);
visitDbgIntrinsic("declare", cast<DbgVariableIntrinsic>(Call));
break;
- case Intrinsic::dbg_addr: // llvm.dbg.addr
- visitDbgIntrinsic("addr", cast<DbgVariableIntrinsic>(Call));
- break;
case Intrinsic::dbg_value: // llvm.dbg.value
visitDbgIntrinsic("value", cast<DbgVariableIntrinsic>(Call));
break;
Argument *V = new Argument(Type::getInt32Ty(Ctx));
Function *F = Function::Create(FT, Function::ExternalLinkage, "", M);
- Function *DbgAddr = Intrinsic::getDeclaration(M, Intrinsic::dbg_addr);
Function *DbgDeclare = Intrinsic::getDeclaration(M, Intrinsic::dbg_declare);
Function *DbgValue = Intrinsic::getDeclaration(M, Intrinsic::dbg_value);
Value *DIV = MetadataAsValue::get(Ctx, (Metadata *)nullptr);
Instruction *MulInst = cast<Instruction>(Builder1.CreateMul(AddInst, V));
Builder1.CreateCall(DbgDeclare, Args);
Instruction *SubInst = cast<Instruction>(Builder1.CreateSub(MulInst, V));
- Builder1.CreateCall(DbgAddr, Args);
SmallVector<Instruction *, 4> Exp = {Var, AddInst, MulInst, SubInst};
CHECK_ITERATORS(BB1->instructionsWithoutDebug(), Exp);
EXPECT_FALSE(E2);
}
-TEST(DIBuilder, createDbgAddr) {
- LLVMContext C;
- std::unique_ptr<Module> M = parseIR(C, R"(
- define void @f() !dbg !6 {
- %a = alloca i16, align 8
- ;; It is important that we put the debug marker on the return.
- ;; We take advantage of that to conjure up a debug loc without
- ;; having to synthesize one programatically.
- ret void, !dbg !11
- }
- declare void @llvm.dbg.value(metadata, metadata, metadata) #0
- attributes #0 = { nounwind readnone speculatable willreturn }
-
- !llvm.dbg.cu = !{!0}
- !llvm.module.flags = !{!5}
-
- !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
- !1 = !DIFile(filename: "t.ll", directory: "/")
- !2 = !{}
- !5 = !{i32 2, !"Debug Info Version", i32 3}
- !6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
- !7 = !DISubroutineType(types: !2)
- !8 = !{!9}
- !9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
- !10 = !DIBasicType(name: "ty16", size: 16, encoding: DW_ATE_unsigned)
- !11 = !DILocation(line: 1, column: 1, scope: !6)
-)");
- auto *F = M->getFunction("f");
- auto *EntryBlock = &F->getEntryBlock();
-
- auto *CU =
- cast<DICompileUnit>(M->getNamedMetadata("llvm.dbg.cu")->getOperand(0));
- auto *Alloca = &*EntryBlock->begin();
- auto *Ret = EntryBlock->getTerminator();
-
- auto *SP = cast<DISubprogram>(F->getMetadata(LLVMContext::MD_dbg));
- auto *File = SP->getFile();
- std::string Name = "myName";
- const auto *Loc = Ret->getDebugLoc().get();
-
- IRBuilder<> Builder(EntryBlock);
- DIBuilder DIB(*M, true, CU);
- DIType *DT = DIB.createBasicType("ty16", 16, dwarf::DW_ATE_unsigned);
-
- DILocalVariable *LocalVar =
- DIB.createAutoVariable(SP, Name, File, 5 /*line*/, DT,
- /*AlwaysPreserve=*/true);
-
- auto *Inst = DIB.insertDbgAddrIntrinsic(Alloca, LocalVar,
- DIB.createExpression(), Loc, Ret);
-
- DIB.finalize();
-
- EXPECT_EQ(Inst->getDebugLoc().get(), Loc);
-
- auto *MD0 = cast<MetadataAsValue>(Inst->getOperand(0))->getMetadata();
- auto *MD0Local = cast<LocalAsMetadata>(MD0);
- EXPECT_EQ(MD0Local->getValue(), Alloca);
- auto *MD1 = cast<MetadataAsValue>(Inst->getOperand(1))->getMetadata();
- EXPECT_EQ(MD1->getMetadataID(), Metadata::MetadataKind::DILocalVariableKind);
- auto *MD2 = cast<MetadataAsValue>(Inst->getOperand(2))->getMetadata();
- auto *MDExp = cast<DIExpression>(MD2);
- EXPECT_EQ(MDExp->getNumElements(), 0u);
-}
-
TEST(DbgAssignIntrinsicTest, replaceVariableLocationOp) {
LLVMContext C;
std::unique_ptr<Module> M = parseIR(C, R"(