This patch makes AsmPrinter less reliant on DwarfDebug by relying on the DWARF version in the AsmPrinter's MCStreamer's MCContext. This allows us to remove the redundant DWARF version from DwarfDebug. It also lets us change code that used to access the AsmPrinter's DwarfDebug just to get to the DWARF version by changing the DWARF version accessor on AsmPrinter so that it grabs the version from its MCStreamer's MCContext.
Differential Revision: https://reviews.llvm.org/D27032
llvm-svn: 287839
DwarfDebug *getDwarfDebug() { return DD; }
DwarfDebug *getDwarfDebug() const { return DD; }
+ uint16_t getDwarfVersion() const;
+ void setDwarfVersion(uint16_t Version);
+
bool isPositionIndependent() const;
/// Return true if assembly output should contain comments.
Sleds.emplace_back(
XRayFunctionEntry{ Sled, CurrentFnSym, Kind, AlwaysInstrument, Fn });
}
+
+uint16_t AsmPrinter::getDwarfVersion() const {
+ return OutStreamer->getContext().getDwarfVersion();
+}
+
+void AsmPrinter::setDwarfVersion(uint16_t Version) {
+ OutStreamer->getContext().setDwarfVersion(Version);
+}
/// EmitDwarfRegOp - Emit dwarf register operation.
void AsmPrinter::EmitDwarfRegOp(ByteStreamer &Streamer,
const MachineLocation &MLoc) const {
- DebugLocDwarfExpression Expr(getDwarfDebug()->getDwarfVersion(), Streamer);
+ DebugLocDwarfExpression Expr(getDwarfVersion(), Streamer);
const MCRegisterInfo *MRI = MMI->getContext().getRegisterInfo();
int Reg = MRI->getDwarfRegNum(MLoc.getReg(), false);
if (Reg < 0) {
case dwarf::DW_FORM_addr:
return AP->getPointerSize();
case dwarf::DW_FORM_ref_addr:
- if (AP->OutStreamer->getContext().getDwarfVersion() == 2)
+ if (AP->getDwarfVersion() == 2)
return AP->getPointerSize();
return sizeof(int32_t);
default: llvm_unreachable("DIE Value form not supported yet");
// specified to be four bytes in the DWARF 32-bit format and eight bytes
// in the DWARF 64-bit format, while DWARF Version 2 specifies that such
// references have the same size as an address on the target system.
- const DwarfDebug *DD = AP->getDwarfDebug();
- assert(DD && "Expected Dwarf Debug info to be available");
- if (DD->getDwarfVersion() == 2)
+ if (AP->getDwarfVersion() == 2)
return AP->getPointerSize();
return sizeof(int32_t);
}
UseAllLinkageNames = DwarfLinkageNames == AllLinkageNames;
unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
- DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
+ unsigned DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
: MMI->getModule()->getDwarfVersion();
// Use dwarf 4 by default if nothing is requested.
DwarfVersion = DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION;
Fn = Scope->getFilename();
Dir = Scope->getDirectory();
if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
- if (DwarfVersion >= 4)
+ if (getDwarfVersion() >= 4)
Discriminator = LBF->getDiscriminator();
unsigned CUID = Asm->OutStreamer->getContext().getDwarfCompileUnitID();
const DebugLocEntry::Value &Value,
unsigned PieceOffsetInBits) {
DIExpressionCursor ExprCursor(Value.getExpression());
- DebugLocDwarfExpression DwarfExpr(AP.getDwarfDebug()->getDwarfVersion(),
- Streamer);
+ DebugLocDwarfExpression DwarfExpr(AP.getDwarfVersion(), Streamer);
// Regular entry.
if (Value.isInt()) {
if (BT && (BT->getEncoding() == dwarf::DW_ATE_signed ||
assert(Offset <= PieceOffset && "overlapping or duplicate pieces");
if (Offset < PieceOffset) {
// The DWARF spec seriously mandates pieces with no locations for gaps.
- DebugLocDwarfExpression Expr(AP.getDwarfDebug()->getDwarfVersion(),
- Streamer);
+ DebugLocDwarfExpression Expr(AP.getDwarfVersion(), Streamer);
Expr.AddOpPiece(PieceOffset-Offset, 0);
Offset += PieceOffset-Offset;
}
return;
AccelTypes.AddName(InfoHolder.getStringPool().getEntry(*Asm, Name), &Die);
}
+
+uint16_t DwarfDebug::getDwarfVersion() const {
+ return Asm->OutStreamer->getContext().getDwarfVersion();
+}
/// Whether to emit all linkage names, or just abstract subprograms.
bool UseAllLinkageNames;
- /// Version of dwarf we're emitting.
- unsigned DwarfVersion;
-
/// DWARF5 Experimental Options
/// @{
bool HasDwarfAccelTables;
bool useSplitDwarf() const { return HasSplitDwarf; }
/// Returns the Dwarf Version.
- unsigned getDwarfVersion() const { return DwarfVersion; }
+ uint16_t getDwarfVersion() const;
/// Returns the previous CU that was being updated
const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
DIEDwarfExpression::DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU,
DIELoc &DIE)
- : DwarfExpression(AP.getDwarfDebug()->getDwarfVersion()), AP(AP), DU(DU),
+ : DwarfExpression(AP.getDwarfVersion()), AP(AP), DU(DU),
DIE(DIE) {}
void DIEDwarfExpression::EmitOp(uint8_t Op, const char* Comment) {