Skip to content

Commit 9e94a10

Browse files
committed
[ARM] Remove Subtarget from ARMAsmPrinter
Remove Subtarget uses from ARMAsmPrinter, making use of TargetMachine where applicable and getting the Subtarget from the MF where not. Some of the `if() llvm_unreachable` have been replaced by `asserts`.
1 parent 5593f45 commit 9e94a10

File tree

5 files changed

+37
-44
lines changed

5 files changed

+37
-44
lines changed

llvm/lib/Target/ARM/ARMAsmPrinter.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ using namespace llvm;
5151

5252
ARMAsmPrinter::ARMAsmPrinter(TargetMachine &TM,
5353
std::unique_ptr<MCStreamer> Streamer)
54-
: AsmPrinter(TM, std::move(Streamer), ID), Subtarget(nullptr), AFI(nullptr),
55-
MCP(nullptr), InConstantPool(false), OptimizationGoals(-1) {}
54+
: AsmPrinter(TM, std::move(Streamer), ID), AFI(nullptr), MCP(nullptr),
55+
InConstantPool(false), OptimizationGoals(-1) {}
5656

5757
const ARMBaseTargetMachine &ARMAsmPrinter::getTM() const {
5858
return static_cast<const ARMBaseTargetMachine &>(TM);
@@ -116,7 +116,6 @@ void ARMAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
116116
bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
117117
AFI = MF.getInfo<ARMFunctionInfo>();
118118
MCP = MF.getConstantPool();
119-
Subtarget = &MF.getSubtarget<ARMSubtarget>();
120119

121120
SetupMachineFunction(MF);
122121
const Function &F = MF.getFunction();
@@ -154,7 +153,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
154153
else if (OptimizationGoals != (int)OptimizationGoal) // conflicting goals
155154
OptimizationGoals = 0;
156155

157-
if (Subtarget->isTargetCOFF()) {
156+
if (TM.getTargetTriple().isOSBinFormatCOFF()) {
158157
bool Local = F.hasLocalLinkage();
159158
COFF::SymbolStorageClass Scl =
160159
Local ? COFF::IMAGE_SYM_CLASS_STATIC : COFF::IMAGE_SYM_CLASS_EXTERNAL;
@@ -260,8 +259,8 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
260259
break;
261260
}
262261
case MachineOperand::MO_ConstantPoolIndex:
263-
if (Subtarget->genExecuteOnly())
264-
llvm_unreachable("execute-only should not generate constant pools");
262+
assert(!MF->getSubtarget<ARMSubtarget>().genExecuteOnly() &&
263+
"execute-only should not generate constant pools");
265264
GetCPISymbol(MO.getIndex())->print(O, MAI);
266265
break;
267266
}
@@ -680,14 +679,14 @@ void ARMAsmPrinter::emitAttributes() {
680679
if (isPositionIndependent()) {
681680
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
682681
ARMBuildAttrs::AddressRWPCRel);
683-
} else if (STI.isRWPI()) {
682+
} else if (getTM().isRWPI()) {
684683
// RWPI specific attributes.
685684
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,
686685
ARMBuildAttrs::AddressRWSBRel);
687686
}
688687

689688
// RO data addressing.
690-
if (isPositionIndependent() || STI.isROPI()) {
689+
if (isPositionIndependent() || getTM().isROPI()) {
691690
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,
692691
ARMBuildAttrs::AddressROPCRel);
693692
}
@@ -833,7 +832,7 @@ void ARMAsmPrinter::emitAttributes() {
833832
}
834833

835834
// We currently do not support using R9 as the TLS pointer.
836-
if (STI.isRWPI())
835+
if (getTM().isRWPI())
837836
ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,
838837
ARMBuildAttrs::R9IsSB);
839838
else if (STI.isR9Reserved())
@@ -1048,7 +1047,7 @@ void ARMAsmPrinter::emitJumpTableAddrs(const MachineInstr *MI) {
10481047
// .word (LBB1 - LJTI_0_0)
10491048
const MCExpr *Expr = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
10501049

1051-
if (isPositionIndependent() || Subtarget->isROPI())
1050+
if (isPositionIndependent() || getTM().isROPI())
10521051
Expr = MCBinaryExpr::createSub(Expr, MCSymbolRefExpr::create(JTISymbol,
10531052
OutContext),
10541053
OutContext);
@@ -1097,7 +1096,8 @@ void ARMAsmPrinter::emitJumpTableTBInst(const MachineInstr *MI,
10971096
const MachineOperand &MO1 = MI->getOperand(1);
10981097
unsigned JTI = MO1.getIndex();
10991098

1100-
if (Subtarget->isThumb1Only())
1099+
const ARMSubtarget &STI = MF->getSubtarget<ARMSubtarget>();
1100+
if (STI.isThumb1Only())
11011101
emitAlignment(Align(4));
11021102

11031103
MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
@@ -1905,6 +1905,7 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
19051905
ARM_MC::verifyInstructionPredicates(MI->getOpcode(),
19061906
getSubtargetInfo().getFeatureBits());
19071907

1908+
const ARMSubtarget &STI = MF->getSubtarget<ARMSubtarget>();
19081909
const DataLayout &DL = getDataLayout();
19091910
MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
19101911
ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
@@ -1916,8 +1917,8 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
19161917
}
19171918

19181919
// Emit unwinding stuff for frame-related instructions
1919-
if (Subtarget->isTargetEHABICompatible() &&
1920-
MI->getFlag(MachineInstr::FrameSetup))
1920+
if (TM.getTargetTriple().isTargetEHABICompatible() &&
1921+
MI->getFlag(MachineInstr::FrameSetup))
19211922
EmitUnwindingInstruction(MI);
19221923

19231924
// Do any auto-generated pseudo lowerings.
@@ -1983,14 +1984,13 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
19831984
// Add 's' bit operand (always reg0 for this)
19841985
.addReg(0));
19851986

1986-
assert(Subtarget->hasV4TOps());
1987-
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
1988-
.addReg(MI->getOperand(0).getReg()));
1987+
assert(STI.hasV4TOps() && "Expected V4TOps for BX call");
1988+
EmitToStreamer(*OutStreamer,
1989+
MCInstBuilder(ARM::BX).addReg(MI->getOperand(0).getReg()));
19891990
return;
19901991
}
19911992
case ARM::tBX_CALL: {
1992-
if (Subtarget->hasV5TOps())
1993-
llvm_unreachable("Expected BLX to be selected for v5t+");
1993+
assert(!STI.hasV5TOps() && "Expected BLX to be selected for v5t+");
19941994

19951995
// On ARM v4t, when doing a call from thumb mode, we need to ensure
19961996
// that the saved lr has its LSB set correctly (the arch doesn't
@@ -2279,8 +2279,8 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
22792279
return;
22802280
}
22812281
case ARM::CONSTPOOL_ENTRY: {
2282-
if (Subtarget->genExecuteOnly())
2283-
llvm_unreachable("execute-only should not generate constant pools");
2282+
assert(!STI.genExecuteOnly() &&
2283+
"execute-only should not generate constant pools");
22842284

22852285
/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
22862286
/// in the function. The first operand is the ID# for this instruction, the
@@ -2486,7 +2486,7 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
24862486
case ARM::TRAP: {
24872487
// Non-Darwin binutils don't yet support the "trap" mnemonic.
24882488
// FIXME: Remove this special case when they do.
2489-
if (!Subtarget->isTargetMachO()) {
2489+
if (!TM.getTargetTriple().isOSBinFormatMachO()) {
24902490
uint32_t Val = 0xe7ffdefeUL;
24912491
OutStreamer->AddComment("trap");
24922492
ATS.emitInst(Val);
@@ -2497,7 +2497,7 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
24972497
case ARM::tTRAP: {
24982498
// Non-Darwin binutils don't yet support the "trap" mnemonic.
24992499
// FIXME: Remove this special case when they do.
2500-
if (!Subtarget->isTargetMachO()) {
2500+
if (!TM.getTargetTriple().isOSBinFormatMachO()) {
25012501
uint16_t Val = 0xdefe;
25022502
OutStreamer->AddComment("trap");
25032503
ATS.emitInst(Val, 'n');
@@ -2657,9 +2657,6 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
26572657
.addImm(ARMCC::AL)
26582658
.addReg(0));
26592659

2660-
const MachineFunction &MF = *MI->getParent()->getParent();
2661-
const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
2662-
26632660
if (STI.isTargetDarwin() || STI.isTargetWindows()) {
26642661
// These platforms always use the same frame register
26652662
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)
@@ -2688,7 +2685,7 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
26882685
.addReg(0));
26892686
}
26902687

2691-
assert(Subtarget->hasV4TOps());
2688+
assert(STI.hasV4TOps());
26922689
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)
26932690
.addReg(ScratchReg)
26942691
// Predicate.
@@ -2705,9 +2702,6 @@ void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {
27052702
Register SrcReg = MI->getOperand(0).getReg();
27062703
Register ScratchReg = MI->getOperand(1).getReg();
27072704

2708-
const MachineFunction &MF = *MI->getParent()->getParent();
2709-
const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
2710-
27112705
EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)
27122706
.addReg(ScratchReg)
27132707
.addReg(SrcReg)

llvm/lib/Target/ARM/ARMAsmPrinter.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
1010
#define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H
1111

12-
#include "ARMSubtarget.h"
1312
#include "llvm/CodeGen/AsmPrinter.h"
1413
#include "llvm/Target/TargetMachine.h"
1514

1615
namespace llvm {
1716

1817
class ARMFunctionInfo;
18+
class ARMBaseTargetMachine;
1919
class MCOperand;
2020
class MachineConstantPool;
2121
class MachineOperand;
@@ -33,10 +33,6 @@ class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
3333
static char ID;
3434

3535
private:
36-
/// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
37-
/// make the right decision when printing asm code for different targets.
38-
const ARMSubtarget *Subtarget;
39-
4036
/// AFI - Keep a pointer to ARMFunctionInfo for the current
4137
/// MachineFunction.
4238
ARMFunctionInfo *AFI;

llvm/lib/Target/ARM/ARMMCInstLower.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ bool ARMAsmPrinter::lowerOperand(const MachineOperand &MO,
112112
MCOp = GetSymbolRef(MO, GetJTISymbol(MO.getIndex()));
113113
break;
114114
case MachineOperand::MO_ConstantPoolIndex:
115-
if (Subtarget->genExecuteOnly())
116-
llvm_unreachable("execute-only should not generate constant pools");
115+
assert(!MF->getSubtarget<ARMSubtarget>().genExecuteOnly() &&
116+
"execute-only should not generate constant pools");
117117
MCOp = GetSymbolRef(MO, GetCPISymbol(MO.getIndex()));
118118
break;
119119
case MachineOperand::MO_BlockAddress:

llvm/lib/Target/ARM/ARMSubtarget.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,8 @@ void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
308308
}
309309
}
310310

311-
bool ARMSubtarget::isROPI() const {
312-
return TM.getRelocationModel() == Reloc::ROPI ||
313-
TM.getRelocationModel() == Reloc::ROPI_RWPI;
314-
}
315-
bool ARMSubtarget::isRWPI() const {
316-
return TM.getRelocationModel() == Reloc::RWPI ||
317-
TM.getRelocationModel() == Reloc::ROPI_RWPI;
318-
}
311+
bool ARMSubtarget::isROPI() const { return TM.isROPI(); }
312+
bool ARMSubtarget::isRWPI() const { return TM.isRWPI(); }
319313

320314
bool ARMSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const {
321315
return TM.isGVIndirectSymbol(GV);

llvm/lib/Target/ARM/ARMTargetMachine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ class ARMBaseTargetMachine : public CodeGenTargetMachineImpl {
8686
TargetTriple.isOSWindows() || TargetABI == ARM::ARM_ABI_AAPCS16;
8787
}
8888

89+
bool isROPI() const {
90+
return getRelocationModel() == Reloc::ROPI ||
91+
getRelocationModel() == Reloc::ROPI_RWPI;
92+
}
93+
bool isRWPI() const {
94+
return getRelocationModel() == Reloc::RWPI ||
95+
getRelocationModel() == Reloc::ROPI_RWPI;
96+
}
97+
8998
bool targetSchedulesPostRAScheduling() const override { return true; };
9099

91100
MachineFunctionInfo *

0 commit comments

Comments
 (0)