Skip to content

Commit 0c5d709

Browse files
committed
Move MIPS-specific GPRel32Directive and EK_GPRel32BlockAddress from generic code to Mips/
Follow-up to 6048629 gprel/gprel64 functions can now be moved from MCTargetStreamer to MipsTargetStreamer.
1 parent f745cb6 commit 0c5d709

File tree

12 files changed

+47
-58
lines changed

12 files changed

+47
-58
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,6 @@ class AsmPrinter : public MachineFunctionPass {
896896
void emitJumpTableImpl(const MachineJumpTableInfo &MJTI,
897897
ArrayRef<unsigned> JumpTableIndices,
898898
bool JTInDiffSection);
899-
void emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
900-
const MachineBasicBlock *MBB, unsigned uid) const;
901899

902900
void emitJumpTableSizesSection(const MachineJumpTableInfo &MJTI,
903901
const Function &F) const;
@@ -911,11 +909,13 @@ class AsmPrinter : public MachineFunctionPass {
911909
GCMetadataPrinter *getOrCreateGCPrinter(GCStrategy &S);
912910
void emitGlobalIFunc(Module &M, const GlobalIFunc &GI);
913911

914-
private:
915912
/// This method decides whether the specified basic block requires a label.
916913
bool shouldEmitLabelForBasicBlock(const MachineBasicBlock &MBB) const;
917914

918915
protected:
916+
virtual void emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
917+
const MachineBasicBlock *MBB,
918+
unsigned uid) const;
919919
virtual void emitGlobalAlias(const Module &M, const GlobalAlias &GA);
920920
virtual bool shouldEmitWeakSwiftAsyncExtendedFramePointerFlags() const {
921921
return false;

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ class MCAsmInfo {
241241
/// True if data directives support signed values
242242
bool SupportsSignedData = true;
243243

244-
/// If non-null, a directive that is used to emit a word which should be
245-
/// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
246-
/// on Alpha. Defaults to nullptr.
247-
const char *GPRel32Directive = nullptr;
248-
249244
/// This is true if this target uses "Sun Style" syntax for section switching
250245
/// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
251246
/// .section directives. Defaults to false.
@@ -450,7 +445,6 @@ class MCAsmInfo {
450445
const char *getData32bitsDirective() const { return Data32bitsDirective; }
451446
const char *getData64bitsDirective() const { return Data64bitsDirective; }
452447
bool supportsSignedData() const { return SupportsSignedData; }
453-
const char *getGPRel32Directive() const { return GPRel32Directive; }
454448

455449
/// Targets can implement this method to specify a section to switch to if the
456450
/// translation unit doesn't have any trampolines that require an executable

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ class MCTargetStreamer {
130130
virtual void emitConstantPools();
131131

132132
virtual void finish();
133-
134-
// MIPS specific functions called by AsmPrinter.
135-
virtual void emitGPRel32Value(const MCExpr *);
136-
virtual void emitGPRel64Value(const MCExpr *);
137133
};
138134

139135
// FIXME: declared here because it is used from

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,9 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
30293029
switch (MJTI.getEntryKind()) {
30303030
case MachineJumpTableInfo::EK_Inline:
30313031
llvm_unreachable("Cannot emit EK_Inline jump table entry");
3032+
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
3033+
case MachineJumpTableInfo::EK_GPRel64BlockAddress:
3034+
llvm_unreachable("MIPS specific");
30323035
case MachineJumpTableInfo::EK_Custom32:
30333036
Value = MF->getSubtarget().getTargetLowering()->LowerCustomJumpTableEntry(
30343037
&MJTI, MBB, UID, OutContext);
@@ -3038,25 +3041,6 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
30383041
// .word LBB123
30393042
Value = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
30403043
break;
3041-
case MachineJumpTableInfo::EK_GPRel32BlockAddress: {
3042-
// EK_GPRel32BlockAddress - Each entry is an address of block, encoded
3043-
// with a relocation as gp-relative, e.g.:
3044-
// .gprel32 LBB123
3045-
MCSymbol *MBBSym = MBB->getSymbol();
3046-
OutStreamer->getTargetStreamer()->emitGPRel32Value(
3047-
MCSymbolRefExpr::create(MBBSym, OutContext));
3048-
return;
3049-
}
3050-
3051-
case MachineJumpTableInfo::EK_GPRel64BlockAddress: {
3052-
// EK_GPRel64BlockAddress - Each entry is an address of block, encoded
3053-
// with a relocation as gp-relative, e.g.:
3054-
// .gpdword LBB123
3055-
MCSymbol *MBBSym = MBB->getSymbol();
3056-
OutStreamer->getTargetStreamer()->emitGPRel64Value(
3057-
MCSymbolRefExpr::create(MBBSym, OutContext));
3058-
return;
3059-
}
30603044

30613045
case MachineJumpTableInfo::EK_LabelDifference32:
30623046
case MachineJumpTableInfo::EK_LabelDifference64: {

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -447,23 +447,12 @@ unsigned TargetLowering::getJumpTableEncoding() const {
447447
if (!isPositionIndependent())
448448
return MachineJumpTableInfo::EK_BlockAddress;
449449

450-
// In PIC mode, if the target supports a GPRel32 directive, use it.
451-
if (getTargetMachine().getMCAsmInfo()->getGPRel32Directive() != nullptr)
452-
return MachineJumpTableInfo::EK_GPRel32BlockAddress;
453-
454450
// Otherwise, use a label difference.
455451
return MachineJumpTableInfo::EK_LabelDifference32;
456452
}
457453

458454
SDValue TargetLowering::getPICJumpTableRelocBase(SDValue Table,
459455
SelectionDAG &DAG) const {
460-
// If our PIC model is GP relative, use the global offset table as the base.
461-
unsigned JTEncoding = getJumpTableEncoding();
462-
463-
if ((JTEncoding == MachineJumpTableInfo::EK_GPRel64BlockAddress) ||
464-
(JTEncoding == MachineJumpTableInfo::EK_GPRel32BlockAddress))
465-
return DAG.getGLOBAL_OFFSET_TABLE(getPointerTy(DAG.getDataLayout()));
466-
467456
return Table;
468457
}
469458

llvm/lib/MC/MCStreamer.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ void MCTargetStreamer::emitRawBytes(StringRef Data) {
9090

9191
void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {}
9292

93-
void MCTargetStreamer::emitGPRel32Value(const MCExpr *) {
94-
report_fatal_error("unsupported directive");
95-
}
96-
97-
void MCTargetStreamer::emitGPRel64Value(const MCExpr *) {
98-
report_fatal_error("unsupported directive");
99-
}
100-
10193
MCStreamer::MCStreamer(MCContext &Ctx)
10294
: Context(Ctx), CurrentWinFrameInfo(nullptr),
10395
CurrentProcWinFrameInfoStartIndex(0) {

llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ MipsELFMCAsmInfo::MipsELFMCAsmInfo(const Triple &TheTriple,
3939
Data64bitsDirective = "\t.8byte\t";
4040
CommentString = "#";
4141
ZeroDirective = "\t.space\t";
42-
GPRel32Directive = "\t.gpword\t";
4342
UseAssignmentForEHBegin = true;
4443
SupportsDebugInformation = true;
4544
ExceptionsType = ExceptionHandling::DwarfCFI;

llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class MipsTargetStreamer : public MCTargetStreamer {
2424
public:
2525
MipsTargetStreamer(MCStreamer &S);
2626

27-
void emitGPRel32Value(const MCExpr *) override;
28-
void emitGPRel64Value(const MCExpr *) override;
27+
virtual void emitGPRel32Value(const MCExpr *);
28+
virtual void emitGPRel64Value(const MCExpr *);
2929
virtual void emitDTPRel32Value(const MCExpr *);
3030
virtual void emitDTPRel64Value(const MCExpr *);
3131
virtual void emitTPRel32Value(const MCExpr *);

llvm/lib/Target/Mips/MipsAsmPrinter.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,29 @@ void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
821821
getTargetStreamer().emitDirectiveSetPop();
822822
}
823823

824+
void MipsAsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
825+
const MachineBasicBlock *MBB,
826+
unsigned uid) const {
827+
MCSymbol *MBBSym = MBB->getSymbol();
828+
switch (MJTI.getEntryKind()) {
829+
case MachineJumpTableInfo::EK_BlockAddress:
830+
OutStreamer->emitValue(MCSymbolRefExpr::create(MBBSym, OutContext),
831+
getDataLayout().getPointerSize());
832+
break;
833+
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
834+
// Each entry is a GP-relative value targeting the block symbol.
835+
getTargetStreamer().emitGPRel32Value(
836+
MCSymbolRefExpr::create(MBBSym, OutContext));
837+
break;
838+
case MachineJumpTableInfo::EK_GPRel64BlockAddress:
839+
getTargetStreamer().emitGPRel64Value(
840+
MCSymbolRefExpr::create(MBBSym, OutContext));
841+
break;
842+
default:
843+
llvm_unreachable("");
844+
}
845+
}
846+
824847
void MipsAsmPrinter::EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol) {
825848
MCInst I;
826849
I.setOpcode(Mips::JAL);

llvm/lib/Target/Mips/MipsAsmPrinter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
8585
void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
8686
const MCSubtargetInfo *EndInfo) const override;
8787

88+
void emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
89+
const MachineBasicBlock *MBB,
90+
unsigned uid) const override;
91+
8892
void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol);
8993

9094
void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg);

0 commit comments

Comments
 (0)