summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/GlobalOpt.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 68d745f7ed3..ee8fdaebbda 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -420,15 +420,17 @@ static bool GlobalUsersSafeToSRA(GlobalValue *GV) {
/// 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) {
+ uint64_t FragmentSizeInBits,
+ unsigned NumElements) {
SmallVector<DIGlobalVariableExpression *, 1> GVs;
GV->getDebugInfo(GVs);
for (auto *GVE : GVs) {
DIVariable *Var = GVE->getVariable();
DIExpression *Expr = GVE->getExpression();
- auto *NExpr = DIExpression::createFragmentExpression(
- Expr, FragmentOffsetInBits, FragmentSizeInBits);
- auto *NGVE = DIGlobalVariableExpression::get(GVE->getContext(), Var, NExpr);
+ if (NumElements > 1)
+ Expr = DIExpression::createFragmentExpression(Expr, FragmentOffsetInBits,
+ FragmentSizeInBits);
+ auto *NGVE = DIGlobalVariableExpression::get(GVE->getContext(), Var, Expr);
NGV->addDebugInfo(NGVE);
}
}
@@ -458,9 +460,10 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
if (StructType *STy = dyn_cast<StructType>(Ty)) {
uint64_t FragmentOffset = 0;
- NewGlobals.reserve(STy->getNumElements());
+ unsigned NumElements = STy->getNumElements();
+ NewGlobals.reserve(NumElements);
const StructLayout &Layout = *DL.getStructLayout(STy);
- for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
+ for (unsigned i = 0, e = NumElements; i != e; ++i) {
Constant *In = Init->getAggregateElement(i);
assert(In && "Couldn't get element of initializer?");
GlobalVariable *NGV = new GlobalVariable(STy->getElementType(i), false,
@@ -484,7 +487,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
// Copy over the debug info for the variable.
FragmentOffset = alignTo(FragmentOffset, NewAlign);
uint64_t Size = DL.getTypeSizeInBits(NGV->getValueType());
- transferSRADebugInfo(GV, NGV, FragmentOffset, Size);
+ transferSRADebugInfo(GV, NGV, FragmentOffset, Size, NumElements);
FragmentOffset += Size;
}
} else if (SequentialType *STy = dyn_cast<SequentialType>(Ty)) {
@@ -516,8 +519,8 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
unsigned NewAlign = (unsigned)MinAlign(StartAlignment, EltSize*i);
if (NewAlign > EltAlign)
NGV->setAlignment(NewAlign);
-
- transferSRADebugInfo(GV, NGV, FragmentSizeInBits * i, FragmentSizeInBits);
+ transferSRADebugInfo(GV, NGV, FragmentSizeInBits * i, FragmentSizeInBits,
+ NumElements);
}
}
OpenPOWER on IntegriCloud