Skip to content

Commit a17c38b

Browse files
authored
Merge pull request #24 from schweitzpgi/release_50
SROA: This changeset was inspired by c8ef2d5, which fixed a bug in
2 parents b5dc647 + 2c504a9 commit a17c38b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

include/llvm/IR/DebugInfoMetadata.h

+2
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,8 @@ class DIVariable : public DINode {
23452345
DITypeRef getType() const { return DITypeRef(getRawType()); }
23462346
uint32_t getAlignInBits() const { return AlignInBits; }
23472347
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
2348+
/// Determines the size of the variable's type.
2349+
Optional<uint64_t> getSizeInBits() const;
23482350

23492351
StringRef getFilename() const {
23502352
if (auto *F = getFile())

lib/IR/DebugInfoMetadata.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,29 @@ DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
626626
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
627627
}
628628

629+
Optional<uint64_t> DIVariable::getSizeInBits() const {
630+
// This is used by the Verifier so be mindful of broken types.
631+
const Metadata *RawType = getRawType();
632+
while (RawType) {
633+
// Try to get the size directly.
634+
if (auto *T = dyn_cast<DIType>(RawType))
635+
if (uint64_t Size = T->getSizeInBits())
636+
return Size;
637+
638+
if (auto *DT = dyn_cast<DIDerivedType>(RawType)) {
639+
// Look at the base type.
640+
RawType = DT->getRawBaseType();
641+
continue;
642+
}
643+
644+
// Missing type or size.
645+
break;
646+
}
647+
648+
// Fail gracefully.
649+
return None;
650+
}
651+
629652
DIExpression *DIExpression::getImpl(LLVMContext &Context,
630653
ArrayRef<uint64_t> Elements,
631654
StorageType Storage, bool ShouldCreate) {

lib/Transforms/Scalar/SROA.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4047,12 +4047,15 @@ bool SROA::splitAlloca(AllocaInst &AI, AllocaSlices &AS) {
40474047
if (DbgDeclareInst *DbgDecl = FindAllocaDbgDeclare(&AI)) {
40484048
auto *Var = DbgDecl->getVariable();
40494049
auto *Expr = DbgDecl->getExpression();
4050+
auto VarSize = Var->getSizeInBits();
40504051
DIBuilder DIB(*AI.getModule(), /*AllowUnresolved*/ false);
40514052
uint64_t AllocaSize = DL.getTypeSizeInBits(AI.getAllocatedType());
40524053
for (auto Fragment : Fragments) {
40534054
// Create a fragment expression describing the new partition or reuse AI's
40544055
// expression if there is only one partition.
40554056
auto *FragmentExpr = Expr;
4057+
if (VarSize && (Fragment.Size >= *VarSize))
4058+
continue;
40564059
if (Fragment.Size < AllocaSize || Expr->isFragment()) {
40574060
// If this alloca is already a scalar replacement of a larger aggregate,
40584061
// Fragment.Offset describes the offset inside the scalar.

0 commit comments

Comments
 (0)