[DebugInfo] Refactor DIExpression [SZ]Ext creation into function [NFC]

Summary:
Also, replace the SmallVector with a normal C array.

Reviewers: vsk

Reviewed By: vsk

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70498
This commit is contained in:
David Stenberg 2019-11-21 09:45:20 +01:00
parent 2cada1e4da
commit 3889ff82bf
3 changed files with 16 additions and 4 deletions

View File

@ -2551,6 +2551,11 @@ public:
return 0;
}
/// Append a zero- or sign-extension to \p Expr. Converts the expression to a
/// stack value if it isn't one already.
static DIExpression *appendExt(const DIExpression *Expr, unsigned FromSize,
unsigned ToSize, bool Signed);
/// Check if fragments overlap between a pair of FragmentInfos.
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B) {
return fragmentCmp(A, B) == 0;

View File

@ -1189,6 +1189,15 @@ bool DIExpression::isConstant() const {
return true;
}
DIExpression *DIExpression::appendExt(const DIExpression *Expr,
unsigned FromSize, unsigned ToSize,
bool Signed) {
dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
uint64_t Ops[] = {dwarf::DW_OP_LLVM_convert, FromSize, TK,
dwarf::DW_OP_LLVM_convert, ToSize, TK};
return appendToStack(Expr, Ops);
}
DIGlobalVariableExpression *
DIGlobalVariableExpression::getImpl(LLVMContext &Context, Metadata *Variable,
Metadata *Expression, StorageType Storage,

View File

@ -1867,10 +1867,8 @@ bool llvm::replaceAllDbgUsesWith(Instruction &From, Value &To,
return None;
bool Signed = *Signedness == DIBasicType::Signedness::Signed;
dwarf::TypeKind TK = Signed ? dwarf::DW_ATE_signed : dwarf::DW_ATE_unsigned;
SmallVector<uint64_t, 8> Ops({dwarf::DW_OP_LLVM_convert, ToBits, TK,
dwarf::DW_OP_LLVM_convert, FromBits, TK});
return DIExpression::appendToStack(DII.getExpression(), Ops);
return DIExpression::appendExt(DII.getExpression(), ToBits, FromBits,
Signed);
};
return rewriteDebugUsers(From, To, DomPoint, DT, SignOrZeroExt);
}