[llvm] r310021 - Un-revert r310014: false revert, it wasn't the cause of build break
Victor Leschuk via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 21:51:15 PDT 2017
Author: vleschuk
Date: Thu Aug 3 21:51:15 2017
New Revision: 310021
URL: http://llvm.org/viewvc/llvm-project?rev=310021&view=rev
Log:
Un-revert r310014: false revert, it wasn't the cause of build break
Added:
llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll
- copied unchanged from r310019, llvm/trunk/test/DebugInfo/Generic/global-sra-array.ll
llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll
- copied unchanged from r310019, llvm/trunk/test/DebugInfo/Generic/global-sra-struct.ll
Modified:
llvm/trunk/include/llvm/IR/DIBuilder.h
llvm/trunk/lib/IR/DIBuilder.cpp
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
Modified: llvm/trunk/include/llvm/IR/DIBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=310021&r1=310020&r2=310021&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DIBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/DIBuilder.h Thu Aug 3 21:51:15 2017
@@ -551,13 +551,17 @@ namespace llvm {
DIExpression *createExpression(ArrayRef<uint64_t> Addr = None);
DIExpression *createExpression(ArrayRef<int64_t> Addr);
- /// Create a descriptor to describe one part
- /// of aggregate variable that is fragmented across multiple Values.
+ /// 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);
+ unsigned SizeInBits,
+ const DIExpression *Expr = nullptr);
/// Create an expression for a variable that does not have an address, but
/// does have a constant value.
Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=310021&r1=310020&r2=310021&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Thu Aug 3 21:51:15 2017
@@ -668,10 +668,31 @@ DIExpression *DIBuilder::createExpressio
return createExpression(Addr);
}
-DIExpression *DIBuilder::createFragmentExpression(unsigned OffsetInBytes,
- unsigned SizeInBytes) {
- uint64_t Addr[] = {dwarf::DW_OP_LLVM_fragment, OffsetInBytes, SizeInBytes};
- return DIExpression::get(VMContext, 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);
+ uint64_t FragmentSizeInBits = Op.getArg(1);
+ assert((OffsetInBits + SizeInBits <= FragmentSizeInBits) &&
+ "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>
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=310021&r1=310020&r2=310021&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Thu Aug 3 21:51:15 2017
@@ -27,7 +27,9 @@
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Constants.h"
#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"
@@ -419,6 +421,23 @@ static bool GlobalUsersSafeToSRA(GlobalV
return true;
}
+/// Copy over the debug info for a variable to its SRA replacements.
+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 *NGVE = DIGlobalVariableExpression::get(GVE->getContext(), Var, NExpr);
+ NGV->addDebugInfo(NGVE);
+ }
+}
+
/// Perform scalar replacement of aggregates on the specified global variable.
/// This opens the door for other optimizations by exposing the behavior of the
@@ -443,6 +462,7 @@ static GlobalVariable *SRAGlobal(GlobalV
StartAlignment = DL.getABITypeAlignment(GV->getType());
if (StructType *STy = dyn_cast<StructType>(Ty)) {
+ uint64_t FragmentOffset = 0;
NewGlobals.reserve(STy->getNumElements());
const StructLayout &Layout = *DL.getStructLayout(STy);
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
@@ -465,15 +485,22 @@ static GlobalVariable *SRAGlobal(GlobalV
unsigned NewAlign = (unsigned)MinAlign(StartAlignment, FieldOffset);
if (NewAlign > DL.getABITypeAlignment(STy->getElementType(i)))
NGV->setAlignment(NewAlign);
+
+ // Copy over the debug info for the variable.
+ FragmentOffset = alignTo(FragmentOffset, NewAlign);
+ uint64_t Size = DL.getTypeSizeInBits(NGV->getValueType());
+ transferSRADebugInfo(GV, NGV, FragmentOffset, Size);
+ FragmentOffset += Size;
}
} else if (SequentialType *STy = dyn_cast<SequentialType>(Ty)) {
unsigned NumElements = STy->getNumElements();
if (NumElements > 16 && GV->hasNUsesOrMore(16))
return nullptr; // It's not worth it.
NewGlobals.reserve(NumElements);
-
- uint64_t EltSize = DL.getTypeAllocSize(STy->getElementType());
- unsigned EltAlign = DL.getABITypeAlignment(STy->getElementType());
+ auto ElTy = STy->getElementType();
+ uint64_t EltSize = DL.getTypeAllocSize(ElTy);
+ unsigned EltAlign = DL.getABITypeAlignment(ElTy);
+ uint64_t FragmentSizeInBits = DL.getTypeSizeInBits(ElTy);
for (unsigned i = 0, e = NumElements; i != e; ++i) {
Constant *In = Init->getAggregateElement(i);
assert(In && "Couldn't get element of initializer?");
@@ -494,6 +521,8 @@ static GlobalVariable *SRAGlobal(GlobalV
unsigned NewAlign = (unsigned)MinAlign(StartAlignment, EltSize*i);
if (NewAlign > EltAlign)
NGV->setAlignment(NewAlign);
+
+ transferSRADebugInfo(GV, NGV, FragmentSizeInBits * i, FragmentSizeInBits);
}
}
More information about the llvm-commits
mailing list