llvm.org GIT mirror llvm / df545e8
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 Adrian Prantl 5 years ago
5 changed file(s) with 27 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
132132 virtual ~AsmPrinter();
133133
134134 DwarfDebug *getDwarfDebug() { return DD; }
135 DwarfDebug *getDwarfDebug() const { return DD; }
135136
136137 /// Return true if assembly output should contain comments.
137138 ///
3636 ByteStreamer &BS;
3737
3838 public:
39 DebugLocDwarfExpression(TargetMachine &TM, ByteStreamer &BS)
40 : DwarfExpression(TM), BS(BS) {}
39 DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
40 : DwarfExpression(AP), BS(BS) {}
4141
4242 void EmitOp(uint8_t Op, const char *Comment) override;
4343 void EmitSigned(int Value) override;
221221 unsigned PieceSizeInBits,
222222 unsigned PieceOffsetInBits) const {
223223 assert(MLoc.isReg() && "MLoc must be a register");
224 DebugLocDwarfExpression Expr(TM, Streamer);
224 DebugLocDwarfExpression Expr(*this, Streamer);
225225 Expr.AddMachineRegPiece(MLoc.getReg(), PieceSizeInBits, PieceOffsetInBits);
226226 }
227227
228228 void AsmPrinter::EmitDwarfOpPiece(ByteStreamer &Streamer,
229229 unsigned PieceSizeInBits,
230230 unsigned PieceOffsetInBits) const {
231 DebugLocDwarfExpression Expr(TM, Streamer);
231 DebugLocDwarfExpression Expr(*this, Streamer);
232232 Expr.AddOpPiece(PieceSizeInBits, PieceOffsetInBits);
233233 }
234234
236236 void AsmPrinter::EmitDwarfRegOp(ByteStreamer &Streamer,
237237 const MachineLocation &MLoc,
238238 bool Indirect) const {
239 DebugLocDwarfExpression Expr(TM, Streamer);
239 DebugLocDwarfExpression Expr(*this, Streamer);
240240 const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
241241 int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
242242 if (Reg < 0) {
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "DwarfExpression.h"
14
15 #include "DwarfDebug.h"
1416 #include "llvm/ADT/SmallBitVector.h"
17 #include "llvm/CodeGen/AsmPrinter.h"
1518 #include "llvm/Support/Dwarf.h"
1619 #include "llvm/Target/TargetMachine.h"
1720 #include "llvm/Target/TargetRegisterInfo.h"
1922
2023
2124 using namespace llvm;
25
26 const TargetRegisterInfo *DwarfExpression::getTRI() const {
27 return AP.TM.getSubtargetImpl()->getRegisterInfo();
28 }
2229
2330 void DwarfExpression::AddReg(int DwarfReg, const char* Comment) {
2431 assert(DwarfReg >= 0 && "invalid negative dwarf register number");
6572 }
6673
6774 bool DwarfExpression::AddMachineRegIndirect(unsigned MachineReg, int Offset) {
68 const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
69 int DwarfReg = TRI->getDwarfRegNum(MachineReg, false);
75 int DwarfReg = getTRI()->getDwarfRegNum(MachineReg, false);
7076 if (DwarfReg < 0)
7177 return false;
7278
8389 void DwarfExpression::AddMachineRegPiece(unsigned MachineReg,
8490 unsigned PieceSizeInBits,
8591 unsigned PieceOffsetInBits) {
86 const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
92 const TargetRegisterInfo *TRI = getTRI();
8793 int Reg = TRI->getDwarfRegNum(MachineReg, false);
8894
8995 // If this is a valid register number, emit it.
1717
1818 namespace llvm {
1919
20 class TargetMachine;
20 class AsmPrinter;
21 class TargetRegisterInfo;
2122
2223 /// Base class containing the logic for constructing DWARF expressions
2324 /// independently of whether they are emitted into a DIE or into a .debug_loc
2425 /// entry.
2526 class DwarfExpression {
2627 protected:
27 TargetMachine &TM;
28 const AsmPrinter &AP;
29 // Various convenience accessors that extract things out of AsmPrinter.
30 const TargetRegisterInfo *getTRI() const;
31
2832 public:
29 DwarfExpression(TargetMachine &TM) : TM(TM) {}
33 DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
3034 virtual ~DwarfExpression() {}
3135
3236 virtual void EmitOp(uint8_t Op, const char* Comment = nullptr) = 0;
4848 DwarfUnit &DU;
4949 DIELoc &DIE;
5050 public:
51 DIEDwarfExpression(TargetMachine &TM, DwarfUnit &DU, DIELoc &DIE)
52 : DwarfExpression(TM), DU(DU), DIE(DIE) {}
51 DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE)
52 : DwarfExpression(AP), DU(DU), DIE(DIE) {}
5353
5454 void EmitOp(uint8_t Op, const char* Comment = nullptr) override;
5555 void EmitSigned(int Value) override;
6767 DU.addUInt(DIE, dwarf::DW_FORM_udata, Value);
6868 }
6969 unsigned DIEDwarfExpression::getFrameRegister() {
70 const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
71 return TRI->getFrameRegister(*DU.getAsmPrinter()->MF);
70 return getTRI()->getFrameRegister(*AP.MF);
7271 }
7372
7473
430429 /// addRegisterOp - Add register operand.
431430 bool DwarfUnit::addRegisterOpPiece(DIELoc &TheDie, unsigned Reg,
432431 unsigned SizeInBits, unsigned OffsetInBits) {
433 DIEDwarfExpression Expr(Asm->TM, *this, TheDie);
432 DIEDwarfExpression Expr(*Asm, *this, TheDie);
434433 Expr.AddMachineRegPiece(Reg, SizeInBits, OffsetInBits);
435434 return true;
436435 }
438437 /// addRegisterOffset - Add register offset.
439438 bool DwarfUnit::addRegisterOffset(DIELoc &TheDie, unsigned Reg,
440439 int64_t Offset) {
441 DIEDwarfExpression Expr(Asm->TM, *this, TheDie);
440 DIEDwarfExpression Expr(*Asm, *this, TheDie);
442441 return Expr.AddMachineRegIndirect(Reg, Offset);
443442 }
444443