[llvm] r312165 - Refactor DIBuilder::createFragmentExpression into a static DIExpression member
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 30 13:04:17 PDT 2017
Author: adrian
Date: Wed Aug 30 13:04:17 2017
New Revision: 312165
URL: http://llvm.org/viewvc/llvm-project?rev=312165&view=rev
Log:
Refactor DIBuilder::createFragmentExpression into a static DIExpression member
NFC
Modified:
llvm/trunk/include/llvm/IR/DIBuilder.h
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
llvm/trunk/lib/IR/DIBuilder.cpp
llvm/trunk/lib/IR/DebugInfoMetadata.cpp
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/lib/Transforms/Scalar/SROA.cpp
Modified: llvm/trunk/include/llvm/IR/DIBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=312165&r1=312164&r2=312165&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DIBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/DIBuilder.h Wed Aug 30 13:04:17 2017
@@ -551,18 +551,6 @@ namespace llvm {
DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);
DIExpression *createExpression(ArrayRef<int64_t> Addr);
- /// Create a descriptor to describe one part of an aggregate variable that
- /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
- /// will be appended to the elements of \c Expr. If \c Expr already contains
- /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
- /// into the existing fragment.
- ///
- /// \param OffsetInBits Offset of the piece in bits.
- /// \param SizeInBits Size of the piece in bits.
- DIExpression *createFragmentExpression(unsigned OffsetInBits,
- unsigned SizeInBits,
- const DIExpression *Expr = nullptr);
-
/// Create an expression for a variable that does not have an address, but
/// does have a constant value.
DIExpression *createConstantValueExpression(uint64_t Val) {
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=312165&r1=312164&r2=312165&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Wed Aug 30 13:04:17 2017
@@ -2293,6 +2293,18 @@ public:
/// into a stack value.
static DIExpression *prepend(const DIExpression *DIExpr, bool Deref,
int64_t Offset = 0, bool StackValue = false);
+
+ /// Create a DIExpression to describe one part of an aggregate variable that
+ /// is fragmented across multiple Values. The DW_OP_LLVM_fragment operation
+ /// will be appended to the elements of \c Expr. If \c Expr already contains
+ /// a \c DW_OP_LLVM_fragment \c OffsetInBits is interpreted as an offset
+ /// into the existing fragment.
+ ///
+ /// \param OffsetInBits Offset of the piece in bits.
+ /// \param SizeInBits Size of the piece in bits.
+ static DIExpression *createFragmentExpression(const DIExpression *Exp,
+ unsigned OffsetInBits,
+ unsigned SizeInBits);
};
/// Global variables.
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp?rev=312165&r1=312164&r2=312165&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp Wed Aug 30 13:04:17 2017
@@ -19,8 +19,8 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/IR/CallingConv.h"
-#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
@@ -826,10 +826,10 @@ void DAGTypeLegalizer::GetExpandedIntege
Hi = Entry.second;
}
-/// Transfer debug valies by generating fragment expressions for split-up
+/// Transfer debug values by generating fragment expressions for split-up
/// values.
-static void transferDbgValues(SelectionDAG &DAG, DIBuilder &DIB, SDValue From,
- SDValue To, unsigned OffsetInBits) {
+static void transferDbgValues(SelectionDAG &DAG, SDValue From, SDValue To,
+ unsigned OffsetInBits) {
SDNode *FromNode = From.getNode();
SDNode *ToNode = To.getNode();
assert(FromNode != ToNode);
@@ -840,9 +840,8 @@ static void transferDbgValues(SelectionD
break;
DIVariable *Var = Dbg->getVariable();
- DIExpression *Fragment = DIB.createFragmentExpression(
- OffsetInBits, To.getValueSizeInBits(),
- cast_or_null<DIExpression>(Dbg->getExpression()));
+ auto *Fragment = DIExpression::createFragmentExpression(
+ Dbg->getExpression(), OffsetInBits, To.getValueSizeInBits());
SDDbgValue *Clone =
DAG.getDbgValue(Var, Fragment, ToNode, To.getResNo(), Dbg->isIndirect(),
Dbg->getDebugLoc(), Dbg->getOrder());
@@ -865,10 +864,8 @@ void DAGTypeLegalizer::SetExpandedIntege
AnalyzeNewValue(Hi);
// Transfer debug values.
- const Module *M = DAG.getMachineFunction().getMMI().getModule();
- DIBuilder DIB(*const_cast<Module *>(M));
- transferDbgValues(DAG, DIB, Op, Lo, 0);
- transferDbgValues(DAG, DIB, Op, Hi, Lo.getValueSizeInBits());
+ transferDbgValues(DAG, Op, Lo, 0);
+ transferDbgValues(DAG, Op, Hi, Lo.getValueSizeInBits());
// Remember that this is the result of the node.
std::pair<SDValue, SDValue> &Entry = ExpandedIntegers[Op];
Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=312165&r1=312164&r2=312165&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Wed Aug 30 13:04:17 2017
@@ -670,33 +670,6 @@ DIExpression *DIBuilder::createExpressio
return createExpression(Addr);
}
-DIExpression *DIBuilder::createFragmentExpression(unsigned OffsetInBits,
- unsigned SizeInBits,
- const DIExpression *Expr) {
- SmallVector<uint64_t, 8> Ops;
- // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
- if (Expr) {
- for (auto Op : Expr->expr_ops()) {
- if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
- // Make the new offset point into the existing fragment.
- uint64_t FragmentOffsetInBits = Op.getArg(0);
- // Op.getArg(1) is FragmentSizeInBits.
- assert((OffsetInBits + SizeInBits <= Op.getArg(1)) &&
- "new fragment outside of original fragment");
- OffsetInBits += FragmentOffsetInBits;
- break;
- }
- Ops.push_back(Op.getOp());
- for (unsigned I = 0; I < Op.getNumArgs(); ++I)
- Ops.push_back(Op.getArg(I));
- }
- }
- Ops.push_back(dwarf::DW_OP_LLVM_fragment);
- Ops.push_back(OffsetInBits);
- Ops.push_back(SizeInBits);
- return DIExpression::get(VMContext, Ops);
-}
-
template <class... Ts>
static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) {
if (IsDistinct)
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=312165&r1=312164&r2=312165&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Wed Aug 30 13:04:17 2017
@@ -724,6 +724,34 @@ DIExpression *DIExpression::prepend(cons
return DIExpression::get(Expr->getContext(), Ops);
}
+DIExpression *DIExpression::createFragmentExpression(const DIExpression *Expr,
+ unsigned OffsetInBits,
+ unsigned SizeInBits) {
+ SmallVector<uint64_t, 8> Ops;
+ // Copy over the expression, but leave off any trailing DW_OP_LLVM_fragment.
+ if (Expr) {
+ for (auto Op : Expr->expr_ops()) {
+ if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
+ // Make the new offset point into the existing fragment.
+ uint64_t FragmentOffsetInBits = Op.getArg(0);
+ // Op.getArg(0) is FragmentOffsetInBits.
+ // Op.getArg(1) is FragmentSizeInBits.
+ assert((OffsetInBits + SizeInBits <= Op.getArg(0) + Op.getArg(1)) &&
+ "new fragment outside of original fragment");
+ OffsetInBits += FragmentOffsetInBits;
+ break;
+ }
+ Ops.push_back(Op.getOp());
+ for (unsigned I = 0; I < Op.getNumArgs(); ++I)
+ Ops.push_back(Op.getArg(I));
+ }
+ }
+ Ops.push_back(dwarf::DW_OP_LLVM_fragment);
+ Ops.push_back(OffsetInBits);
+ Ops.push_back(SizeInBits);
+ return DIExpression::get(Expr->getContext(), Ops);
+}
+
bool DIExpression::isConstant() const {
// Recognize DW_OP_constu C DW_OP_stack_value (DW_OP_LLVM_fragment Len Ofs)?.
if (getNumElements() != 3 && getNumElements() != 6)
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=312165&r1=312164&r2=312165&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Wed Aug 30 13:04:17 2017
@@ -29,7 +29,6 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
-#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/Instructions.h"
@@ -422,14 +421,13 @@ static bool GlobalUsersSafeToSRA(GlobalV
static void transferSRADebugInfo(GlobalVariable *GV, GlobalVariable *NGV,
uint64_t FragmentOffsetInBits,
uint64_t FragmentSizeInBits) {
- DIBuilder DIB(*GV->getParent(), /*AllowUnresolved*/ false);
SmallVector<DIGlobalVariableExpression *, 1> GVs;
GV->getDebugInfo(GVs);
for (auto *GVE : GVs) {
DIVariable *Var = GVE->getVariable();
DIExpression *Expr = GVE->getExpression();
- DIExpression *NExpr = DIB.createFragmentExpression(
- FragmentOffsetInBits, FragmentSizeInBits, Expr);
+ auto *NExpr = DIExpression::createFragmentExpression(
+ Expr, FragmentOffsetInBits, FragmentSizeInBits);
auto *NGVE = DIGlobalVariableExpression::get(GVE->getContext(), Var, NExpr);
NGV->addDebugInfo(NGVE);
}
Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=312165&r1=312164&r2=312165&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Wed Aug 30 13:04:17 2017
@@ -4068,7 +4068,14 @@ bool SROA::splitAlloca(AllocaInst &AI, A
continue;
Size = std::min(Size, AbsEnd - Start);
}
- FragmentExpr = DIB.createFragmentExpression(Start, Size);
+ // The new, smaller fragment is stenciled out from the old fragment.
+ if (auto OrigFragment = FragmentExpr->getFragmentInfo()) {
+ assert(Start >= OrigFragment->OffsetInBits &&
+ "new fragment is outside of original fragment");
+ Start -= OrigFragment->OffsetInBits;
+ }
+ FragmentExpr =
+ DIExpression::createFragmentExpression(Expr, Start, Size);
}
// Remove any existing dbg.declare intrinsic describing the same alloca.
More information about the llvm-commits
mailing list