Make DwarfExpression store the AsmPrinter instead of the TargetMachine.

NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225731 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adrian Prantl 2015-01-12 23:36:56 +00:00
parent 0ec7e836f9
commit df545e8d6c
5 changed files with 27 additions and 17 deletions

View File

@ -133,6 +133,7 @@ public:
virtual ~AsmPrinter();
DwarfDebug *getDwarfDebug() { return DD; }
DwarfDebug *getDwarfDebug() const { return DD; }
/// Return true if assembly output should contain comments.
///

View File

@ -37,8 +37,8 @@ class DebugLocDwarfExpression : public DwarfExpression {
ByteStreamer &BS;
public:
DebugLocDwarfExpression(TargetMachine &TM, ByteStreamer &BS)
: DwarfExpression(TM), BS(BS) {}
DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
: DwarfExpression(AP), BS(BS) {}
void EmitOp(uint8_t Op, const char *Comment) override;
void EmitSigned(int Value) override;
@ -222,14 +222,14 @@ void AsmPrinter::EmitDwarfRegOpPiece(ByteStreamer &Streamer,
unsigned PieceSizeInBits,
unsigned PieceOffsetInBits) const {
assert(MLoc.isReg() && "MLoc must be a register");
DebugLocDwarfExpression Expr(TM, Streamer);
DebugLocDwarfExpression Expr(*this, Streamer);
Expr.AddMachineRegPiece(MLoc.getReg(), PieceSizeInBits, PieceOffsetInBits);
}
void AsmPrinter::EmitDwarfOpPiece(ByteStreamer &Streamer,
unsigned PieceSizeInBits,
unsigned PieceOffsetInBits) const {
DebugLocDwarfExpression Expr(TM, Streamer);
DebugLocDwarfExpression Expr(*this, Streamer);
Expr.AddOpPiece(PieceSizeInBits, PieceOffsetInBits);
}
@ -237,7 +237,7 @@ void AsmPrinter::EmitDwarfOpPiece(ByteStreamer &Streamer,
void AsmPrinter::EmitDwarfRegOp(ByteStreamer &Streamer,
const MachineLocation &MLoc,
bool Indirect) const {
DebugLocDwarfExpression Expr(TM, Streamer);
DebugLocDwarfExpression Expr(*this, Streamer);
const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
if (Reg < 0) {

View File

@ -12,7 +12,10 @@
//===----------------------------------------------------------------------===//
#include "DwarfExpression.h"
#include "DwarfDebug.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetRegisterInfo.h"
@ -21,6 +24,10 @@
using namespace llvm;
const TargetRegisterInfo *DwarfExpression::getTRI() const {
return AP.TM.getSubtargetImpl()->getRegisterInfo();
}
void DwarfExpression::AddReg(int DwarfReg, const char* Comment) {
assert(DwarfReg >= 0 && "invalid negative dwarf register number");
if (DwarfReg < 32) {
@ -66,8 +73,7 @@ void DwarfExpression::AddShr(unsigned ShiftBy) {
}
bool DwarfExpression::AddMachineRegIndirect(unsigned MachineReg, int Offset) {
const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
int DwarfReg = TRI->getDwarfRegNum(MachineReg, false);
int DwarfReg = getTRI()->getDwarfRegNum(MachineReg, false);
if (DwarfReg < 0)
return false;
@ -84,7 +90,7 @@ bool DwarfExpression::AddMachineRegIndirect(unsigned MachineReg, int Offset) {
void DwarfExpression::AddMachineRegPiece(unsigned MachineReg,
unsigned PieceSizeInBits,
unsigned PieceOffsetInBits) {
const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
const TargetRegisterInfo *TRI = getTRI();
int Reg = TRI->getDwarfRegNum(MachineReg, false);
// If this is a valid register number, emit it.

View File

@ -18,16 +18,20 @@
namespace llvm {
class TargetMachine;
class AsmPrinter;
class TargetRegisterInfo;
/// Base class containing the logic for constructing DWARF expressions
/// independently of whether they are emitted into a DIE or into a .debug_loc
/// entry.
class DwarfExpression {
protected:
TargetMachine &TM;
const AsmPrinter &AP;
// Various convenience accessors that extract things out of AsmPrinter.
const TargetRegisterInfo *getTRI() const;
public:
DwarfExpression(TargetMachine &TM) : TM(TM) {}
DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
virtual ~DwarfExpression() {}
virtual void EmitOp(uint8_t Op, const char* Comment = nullptr) = 0;

View File

@ -49,8 +49,8 @@ class DIEDwarfExpression : public DwarfExpression {
DwarfUnit &DU;
DIELoc &DIE;
public:
DIEDwarfExpression(TargetMachine &TM, DwarfUnit &DU, DIELoc &DIE)
: DwarfExpression(TM), DU(DU), DIE(DIE) {}
DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE)
: DwarfExpression(AP), DU(DU), DIE(DIE) {}
void EmitOp(uint8_t Op, const char* Comment = nullptr) override;
void EmitSigned(int Value) override;
@ -68,8 +68,7 @@ void DIEDwarfExpression::EmitUnsigned(unsigned Value) {
DU.addUInt(DIE, dwarf::DW_FORM_udata, Value);
}
unsigned DIEDwarfExpression::getFrameRegister() {
const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
return TRI->getFrameRegister(*DU.getAsmPrinter()->MF);
return getTRI()->getFrameRegister(*AP.MF);
}
@ -431,7 +430,7 @@ void DwarfUnit::addSourceLine(DIE &Die, DINameSpace NS) {
/// addRegisterOp - Add register operand.
bool DwarfUnit::addRegisterOpPiece(DIELoc &TheDie, unsigned Reg,
unsigned SizeInBits, unsigned OffsetInBits) {
DIEDwarfExpression Expr(Asm->TM, *this, TheDie);
DIEDwarfExpression Expr(*Asm, *this, TheDie);
Expr.AddMachineRegPiece(Reg, SizeInBits, OffsetInBits);
return true;
}
@ -439,7 +438,7 @@ bool DwarfUnit::addRegisterOpPiece(DIELoc &TheDie, unsigned Reg,
/// addRegisterOffset - Add register offset.
bool DwarfUnit::addRegisterOffset(DIELoc &TheDie, unsigned Reg,
int64_t Offset) {
DIEDwarfExpression Expr(Asm->TM, *this, TheDie);
DIEDwarfExpression Expr(*Asm, *this, TheDie);
return Expr.AddMachineRegIndirect(Reg, Offset);
}