Index: include/llvm/IR/DebugInfoMetadata.h =================================================================== --- include/llvm/IR/DebugInfoMetadata.h +++ include/llvm/IR/DebugInfoMetadata.h @@ -2477,14 +2477,18 @@ static const DIExpression *extractAddressClass(const DIExpression *Expr, unsigned &AddrClass); - /// Constants for DIExpression::prepend. - enum { NoDeref = false, WithDeref = true, WithStackValue = true }; + /// Used for DIExpression::prepend. + enum DIExpressionFlags : uint16_t { + NoFlags = 0, + DerefBefore = 1 << 0, + DerefAfter = 1 << 1, + StackValue = 1 << 2 + }; /// Prepend \p DIExpr with a deref and offset operation and optionally turn it /// into a stack value. - static DIExpression *prepend(const DIExpression *Expr, bool DerefBefore, - int64_t Offset = 0, bool DerefAfter = false, - bool StackValue = false); + static DIExpression *prepend(const DIExpression *Expr, uint16_t Flags, + int64_t Offset = 0); /// Prepend \p DIExpr with the given opcodes and optionally turn it into a /// stack value. Index: lib/CodeGen/LiveDebugValues.cpp =================================================================== --- lib/CodeGen/LiveDebugValues.cpp +++ lib/CodeGen/LiveDebugValues.cpp @@ -462,8 +462,9 @@ // Create a DBG_VALUE instruction to describe the Var in its spilled // location. VarLoc::SpillLoc SpillLocation = extractSpillBaseRegAndOffset(MI); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; auto *SpillExpr = - DIExpression::prepend(DMI->getDebugExpression(), DIExpression::NoDeref, + DIExpression::prepend(DMI->getDebugExpression(), DIExprFlags, SpillLocation.SpillOffset); NewDMI = BuildMI(*MF, DMI->getDebugLoc(), DMI->getDesc(), true, Index: lib/CodeGen/LiveDebugVariables.cpp =================================================================== --- lib/CodeGen/LiveDebugVariables.cpp +++ lib/CodeGen/LiveDebugVariables.cpp @@ -1316,11 +1316,13 @@ // that the original virtual register was a pointer. Also, add the stack slot // offset for the spilled register to the expression. const DIExpression *Expr = Expression; + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; bool IsIndirect = Loc.wasIndirect(); if (Spilled) { - auto Deref = IsIndirect ? DIExpression::WithDeref : DIExpression::NoDeref; + if (IsIndirect) + DIExprFlags |= DIExpression::DIExpressionFlags::DerefAfter; Expr = - DIExpression::prepend(Expr, DIExpression::NoDeref, SpillOffset, Deref); + DIExpression::prepend(Expr, DIExprFlags, SpillOffset); IsIndirect = true; } Index: lib/CodeGen/MachineInstr.cpp =================================================================== --- lib/CodeGen/MachineInstr.cpp +++ lib/CodeGen/MachineInstr.cpp @@ -2075,7 +2075,9 @@ const DIExpression *Expr = MI.getDebugExpression(); if (MI.isIndirectDebugValue()) { assert(MI.getOperand(1).getImm() == 0 && "DBG_VALUE with nonzero offset"); - Expr = DIExpression::prepend(Expr, DIExpression::WithDeref); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; + DIExprFlags |= DIExpression::DIExpressionFlags::DerefBefore; + Expr = DIExpression::prepend(Expr, DIExprFlags); } return Expr; } Index: lib/CodeGen/PrologEpilogInserter.cpp =================================================================== --- lib/CodeGen/PrologEpilogInserter.cpp +++ lib/CodeGen/PrologEpilogInserter.cpp @@ -1181,17 +1181,18 @@ MI.getOperand(0).setIsDebug(); const DIExpression *DIExpr = MI.getDebugExpression(); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; // If we have DBG_VALUE that is indirect and has a Implicit location // expression need to insert a deref before prepending a Memory // location expression. Also after doing this we change the DBG_VALUE // to be direct. if (MI.isIndirectDebugValue() && DIExpr->isImplicit()) { SmallVector Ops = {dwarf::DW_OP_deref_size, Size}; - DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, DIExpression::WithStackValue); + DIExpr = DIExpression::prependOpcodes(DIExpr, Ops, true); // Make the DBG_VALUE direct. MI.getOperand(1).ChangeToRegister(0, false); } - DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref, Offset); + DIExpr = DIExpression::prepend(DIExpr, DIExprFlags, Offset); MI.getOperand(3).setMetadata(DIExpr); continue; } Index: lib/CodeGen/SafeStack.cpp =================================================================== --- lib/CodeGen/SafeStack.cpp +++ lib/CodeGen/SafeStack.cpp @@ -576,7 +576,7 @@ // Replace alloc with the new location. replaceDbgDeclare(Arg, BasePointer, BasePointer->getNextNode(), DIB, - DIExpression::NoDeref, -Offset, DIExpression::NoDeref); + false, -Offset, false); Arg->replaceAllUsesWith(NewArg); IRB.SetInsertPoint(cast(NewArg)->getNextNode()); IRB.CreateMemCpy(Off, Align, Arg, Arg->getParamAlignment(), Size); @@ -591,8 +591,7 @@ if (Size == 0) Size = 1; // Don't create zero-sized stack objects. - replaceDbgDeclareForAlloca(AI, BasePointer, DIB, DIExpression::NoDeref, - -Offset, DIExpression::NoDeref); + replaceDbgDeclareForAlloca(AI, BasePointer, DIB, false, -Offset, false); replaceDbgValueForAlloca(AI, BasePointer, DIB, -Offset); // Replace uses of the alloca with the new location. @@ -683,8 +682,7 @@ if (AI->hasName() && isa(NewAI)) NewAI->takeName(AI); - replaceDbgDeclareForAlloca(AI, NewAI, DIB, DIExpression::NoDeref, 0, - DIExpression::NoDeref); + replaceDbgDeclareForAlloca(AI, NewAI, DIB, false, 0, false); AI->replaceAllUsesWith(NewAI); AI->eraseFromParent(); } Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -7945,9 +7945,9 @@ // DIExpression, we need to mark the expression with a // DW_OP_stack_value. auto *DIExpr = DV->getExpression(); - DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref, Offset, - DIExpression::NoDeref, - DIExpression::WithStackValue); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; + DIExprFlags |= DIExpression::DIExpressionFlags::StackValue; + DIExpr = DIExpression::prepend(DIExpr, DIExprFlags, Offset); SDDbgValue *Clone = getDbgValue(DV->getVariable(), DIExpr, N0.getNode(), N0.getResNo(), DV->isIndirect(), DV->getDebugLoc(), DV->getOrder()); Index: lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1362,9 +1362,9 @@ continue; DIExpression *Expr = DI->getExpression(); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; if (Offset.getBoolValue()) - Expr = DIExpression::prepend(Expr, DIExpression::NoDeref, - Offset.getZExtValue()); + Expr = DIExpression::prepend(Expr, DIExprFlags, Offset.getZExtValue()); MF->setVariableDbgInfo(DI->getVariable(), Expr, FI, DI->getDebugLoc()); } } Index: lib/IR/DebugInfoMetadata.cpp =================================================================== --- lib/IR/DebugInfoMetadata.cpp +++ lib/IR/DebugInfoMetadata.cpp @@ -979,17 +979,18 @@ return Expr; } -DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore, - int64_t Offset, bool DerefAfter, - bool StackValue) { +DIExpression *DIExpression::prepend(const DIExpression *Expr, uint16_t Flags, + int64_t Offset) { SmallVector Ops; - if (DerefBefore) + if (Flags & DIExpression::DIExpressionFlags::DerefBefore) Ops.push_back(dwarf::DW_OP_deref); appendOffset(Ops, Offset); - if (DerefAfter) + if (Flags & DIExpression::DIExpressionFlags::DerefAfter) Ops.push_back(dwarf::DW_OP_deref); + bool StackValue = Flags & DIExpression::DIExpressionFlags::StackValue; + return prependOpcodes(Expr, Ops, StackValue); } Index: lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp =================================================================== --- lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp +++ lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp @@ -72,8 +72,9 @@ TFI.getFrameIndexReference(MF, MI.getOperand(0).getIndex(), Reg); MI.getOperand(0).ChangeToRegister(Reg, /*isDef=*/false); MI.getOperand(0).setIsDebug(); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; auto *DIExpr = DIExpression::prepend(MI.getDebugExpression(), - DIExpression::NoDeref, Offset); + DIExprFlags, Offset); MI.getOperand(3).setMetadata(DIExpr); continue; } Index: lib/Target/X86/X86OptimizeLEAs.cpp =================================================================== --- lib/Target/X86/X86OptimizeLEAs.cpp +++ lib/Target/X86/X86OptimizeLEAs.cpp @@ -568,11 +568,11 @@ unsigned VReg, int64_t AddrDispShift) { DIExpression *Expr = const_cast(MI.getDebugExpression()); - - if (AddrDispShift != 0) - Expr = DIExpression::prepend(Expr, DIExpression::NoDeref, AddrDispShift, - DIExpression::NoDeref, - DIExpression::WithStackValue); + if (AddrDispShift != 0) { + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; + DIExprFlags |= DIExpression::DIExpressionFlags::StackValue; + Expr = DIExpression::prepend(Expr, DIExprFlags, AddrDispShift); + } // Replace DBG_VALUE instruction with modified version. MachineBasicBlock *MBB = MI.getParent(); Index: lib/Transforms/IPO/GlobalOpt.cpp =================================================================== --- lib/Transforms/IPO/GlobalOpt.cpp +++ lib/Transforms/IPO/GlobalOpt.cpp @@ -1671,7 +1671,7 @@ dwarf::DW_OP_constu, ValMinus, dwarf::DW_OP_mul, dwarf::DW_OP_constu, ValInit, dwarf::DW_OP_plus}; - E = DIExpression::prependOpcodes(E, Ops, DIExpression::WithStackValue); + E = DIExpression::prependOpcodes(E, Ops, true); DIGlobalVariableExpression *DGVE = DIGlobalVariableExpression::get(NewGV->getContext(), DGV, E); NewGV->addDebugInfo(DGVE); Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -3109,7 +3109,7 @@ for (const auto &Desc : SVD) { AllocaInst *AI = Desc.AI; replaceDbgDeclareForAlloca(AI, LocalStackBaseAlloca, DIB, Deref, - Desc.Offset, DIExpression::NoDeref); + Desc.Offset, false); Value *NewAllocaPtr = IRB.CreateIntToPtr( IRB.CreateAdd(LocalStackBase, ConstantInt::get(IntptrTy, Desc.Offset)), AI->getType()); Index: lib/Transforms/Utils/InlineFunction.cpp =================================================================== --- lib/Transforms/Utils/InlineFunction.cpp +++ lib/Transforms/Utils/InlineFunction.cpp @@ -1817,8 +1817,7 @@ // Move any dbg.declares describing the allocas into the entry basic block. DIBuilder DIB(*Caller->getParent()); for (auto &AI : IFI.StaticAllocas) - replaceDbgDeclareForAlloca(AI, AI, DIB, DIExpression::NoDeref, 0, - DIExpression::NoDeref); + replaceDbgDeclareForAlloca(AI, AI, DIB, false, 0, false); } SmallVector VarArgsToForward; Index: lib/Transforms/Utils/Local.cpp =================================================================== --- lib/Transforms/Utils/Local.cpp +++ lib/Transforms/Utils/Local.cpp @@ -1559,7 +1559,12 @@ auto *DIVar = DII->getVariable(); auto *DIExpr = DII->getExpression(); assert(DIVar && "Missing variable"); - DIExpr = DIExpression::prepend(DIExpr, DerefBefore, Offset, DerefAfter); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; + if (DerefBefore) + DIExprFlags |= DIExpression::DIExpressionFlags::DerefBefore; + if (DerefAfter) + DIExprFlags |= DIExpression::DIExpressionFlags::DerefAfter; + DIExpr = DIExpression::prepend(DIExpr, DIExprFlags, Offset); // Insert llvm.dbg.declare immediately before InsertBefore, and remove old // llvm.dbg.declare. Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore); Index: unittests/IR/MetadataTest.cpp =================================================================== --- unittests/IR/MetadataTest.cpp +++ unittests/IR/MetadataTest.cpp @@ -2335,7 +2335,11 @@ // Test DIExpression::prepend(). uint64_t Elts0[] = {dwarf::DW_OP_LLVM_fragment, 0, 32}; auto *N0 = DIExpression::get(Context, Elts0); - auto *N0WithPrependedOps = DIExpression::prepend(N0, true, 64, true, true); + uint16_t DIExprFlags = DIExpression::DIExpressionFlags::NoFlags; + DIExprFlags |= DIExpression::DIExpressionFlags::DerefBefore; + DIExprFlags |= DIExpression::DIExpressionFlags::DerefAfter; + DIExprFlags |= DIExpression::DIExpressionFlags::StackValue; + auto *N0WithPrependedOps = DIExpression::prepend(N0, DIExprFlags, 64); uint64_t Elts1[] = {dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 64, dwarf::DW_OP_deref, Index: unittests/Transforms/Utils/LocalTest.cpp =================================================================== --- unittests/Transforms/Utils/LocalTest.cpp +++ unittests/Transforms/Utils/LocalTest.cpp @@ -153,8 +153,7 @@ ASSERT_TRUE(DII); Value *NewBase = Constant::getNullValue(Type::getInt32PtrTy(C)); DIBuilder DIB(*M); - replaceDbgDeclare(AI, NewBase, DII, DIB, DIExpression::NoDeref, 0, - DIExpression::NoDeref); + replaceDbgDeclare(AI, NewBase, DII, DIB, false, 0, false); // There should be exactly two dbg.declares. int Declares = 0;