[llvm] 0c5d709 - Move MIPS-specific GPRel32Directive and EK_GPRel32BlockAddress from generic code to Mips/
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 2 15:38:01 PST 2025
Author: Fangrui Song
Date: 2025-03-02T15:37:55-08:00
New Revision: 0c5d709301b25b588ccb9cfb4d9c219cc5bdcaf1
URL: https://github.com/llvm/llvm-project/commit/0c5d709301b25b588ccb9cfb4d9c219cc5bdcaf1
DIFF: https://github.com/llvm/llvm-project/commit/0c5d709301b25b588ccb9cfb4d9c219cc5bdcaf1.diff
LOG: Move MIPS-specific GPRel32Directive and EK_GPRel32BlockAddress from generic code to Mips/
Follow-up to 60486292b79885b7800b082754153202bef5b1f0
gprel/gprel64 functions can now be moved from MCTargetStreamer
to MipsTargetStreamer.
Added:
Modified:
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
llvm/lib/Target/Mips/MipsAsmPrinter.cpp
llvm/lib/Target/Mips/MipsAsmPrinter.h
llvm/lib/Target/Mips/MipsISelLowering.cpp
llvm/lib/Target/Mips/MipsISelLowering.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index 3da63af5ba571..f805bf8a05f18 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -896,8 +896,6 @@ class AsmPrinter : public MachineFunctionPass {
void emitJumpTableImpl(const MachineJumpTableInfo &MJTI,
ArrayRef<unsigned> JumpTableIndices,
bool JTInDiffSection);
- void emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
- const MachineBasicBlock *MBB, unsigned uid) const;
void emitJumpTableSizesSection(const MachineJumpTableInfo &MJTI,
const Function &F) const;
@@ -911,11 +909,13 @@ class AsmPrinter : public MachineFunctionPass {
GCMetadataPrinter *getOrCreateGCPrinter(GCStrategy &S);
void emitGlobalIFunc(Module &M, const GlobalIFunc &GI);
-private:
/// This method decides whether the specified basic block requires a label.
bool shouldEmitLabelForBasicBlock(const MachineBasicBlock &MBB) const;
protected:
+ virtual void emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
+ const MachineBasicBlock *MBB,
+ unsigned uid) const;
virtual void emitGlobalAlias(const Module &M, const GlobalAlias &GA);
virtual bool shouldEmitWeakSwiftAsyncExtendedFramePointerFlags() const {
return false;
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 87914d056714b..5ae28b22b1ebb 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -241,11 +241,6 @@ class MCAsmInfo {
/// True if data directives support signed values
bool SupportsSignedData = true;
- /// If non-null, a directive that is used to emit a word which should be
- /// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
- /// on Alpha. Defaults to nullptr.
- const char *GPRel32Directive = nullptr;
-
/// This is true if this target uses "Sun Style" syntax for section switching
/// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
/// .section directives. Defaults to false.
@@ -450,7 +445,6 @@ class MCAsmInfo {
const char *getData32bitsDirective() const { return Data32bitsDirective; }
const char *getData64bitsDirective() const { return Data64bitsDirective; }
bool supportsSignedData() const { return SupportsSignedData; }
- const char *getGPRel32Directive() const { return GPRel32Directive; }
/// Targets can implement this method to specify a section to switch to if the
/// translation unit doesn't have any trampolines that require an executable
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index 1192e5dbd9454..1dc6ddfd7566b 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -130,10 +130,6 @@ class MCTargetStreamer {
virtual void emitConstantPools();
virtual void finish();
-
- // MIPS specific functions called by AsmPrinter.
- virtual void emitGPRel32Value(const MCExpr *);
- virtual void emitGPRel64Value(const MCExpr *);
};
// FIXME: declared here because it is used from
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 798de0e919424..6f39bff80abda 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3029,6 +3029,9 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
switch (MJTI.getEntryKind()) {
case MachineJumpTableInfo::EK_Inline:
llvm_unreachable("Cannot emit EK_Inline jump table entry");
+ case MachineJumpTableInfo::EK_GPRel32BlockAddress:
+ case MachineJumpTableInfo::EK_GPRel64BlockAddress:
+ llvm_unreachable("MIPS specific");
case MachineJumpTableInfo::EK_Custom32:
Value = MF->getSubtarget().getTargetLowering()->LowerCustomJumpTableEntry(
&MJTI, MBB, UID, OutContext);
@@ -3038,25 +3041,6 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
// .word LBB123
Value = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);
break;
- case MachineJumpTableInfo::EK_GPRel32BlockAddress: {
- // EK_GPRel32BlockAddress - Each entry is an address of block, encoded
- // with a relocation as gp-relative, e.g.:
- // .gprel32 LBB123
- MCSymbol *MBBSym = MBB->getSymbol();
- OutStreamer->getTargetStreamer()->emitGPRel32Value(
- MCSymbolRefExpr::create(MBBSym, OutContext));
- return;
- }
-
- case MachineJumpTableInfo::EK_GPRel64BlockAddress: {
- // EK_GPRel64BlockAddress - Each entry is an address of block, encoded
- // with a relocation as gp-relative, e.g.:
- // .gpdword LBB123
- MCSymbol *MBBSym = MBB->getSymbol();
- OutStreamer->getTargetStreamer()->emitGPRel64Value(
- MCSymbolRefExpr::create(MBBSym, OutContext));
- return;
- }
case MachineJumpTableInfo::EK_LabelDifference32:
case MachineJumpTableInfo::EK_LabelDifference64: {
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 7771958f5adc9..bd72718c49031 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -447,23 +447,12 @@ unsigned TargetLowering::getJumpTableEncoding() const {
if (!isPositionIndependent())
return MachineJumpTableInfo::EK_BlockAddress;
- // In PIC mode, if the target supports a GPRel32 directive, use it.
- if (getTargetMachine().getMCAsmInfo()->getGPRel32Directive() != nullptr)
- return MachineJumpTableInfo::EK_GPRel32BlockAddress;
-
// Otherwise, use a label
diff erence.
return MachineJumpTableInfo::EK_LabelDifference32;
}
SDValue TargetLowering::getPICJumpTableRelocBase(SDValue Table,
SelectionDAG &DAG) const {
- // If our PIC model is GP relative, use the global offset table as the base.
- unsigned JTEncoding = getJumpTableEncoding();
-
- if ((JTEncoding == MachineJumpTableInfo::EK_GPRel64BlockAddress) ||
- (JTEncoding == MachineJumpTableInfo::EK_GPRel32BlockAddress))
- return DAG.getGLOBAL_OFFSET_TABLE(getPointerTy(DAG.getDataLayout()));
-
return Table;
}
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 16658bed381d0..99b7651a9ab31 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -90,14 +90,6 @@ void MCTargetStreamer::emitRawBytes(StringRef Data) {
void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {}
-void MCTargetStreamer::emitGPRel32Value(const MCExpr *) {
- report_fatal_error("unsupported directive");
-}
-
-void MCTargetStreamer::emitGPRel64Value(const MCExpr *) {
- report_fatal_error("unsupported directive");
-}
-
MCStreamer::MCStreamer(MCContext &Ctx)
: Context(Ctx), CurrentWinFrameInfo(nullptr),
CurrentProcWinFrameInfoStartIndex(0) {
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
index eddf1115e33a2..59c5bcb89bede 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
@@ -39,7 +39,6 @@ MipsELFMCAsmInfo::MipsELFMCAsmInfo(const Triple &TheTriple,
Data64bitsDirective = "\t.8byte\t";
CommentString = "#";
ZeroDirective = "\t.space\t";
- GPRel32Directive = "\t.gpword\t";
UseAssignmentForEHBegin = true;
SupportsDebugInformation = true;
ExceptionsType = ExceptionHandling::DwarfCFI;
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
index 581f834f84026..b726a80ce6b72 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
@@ -24,8 +24,8 @@ class MipsTargetStreamer : public MCTargetStreamer {
public:
MipsTargetStreamer(MCStreamer &S);
- void emitGPRel32Value(const MCExpr *) override;
- void emitGPRel64Value(const MCExpr *) override;
+ virtual void emitGPRel32Value(const MCExpr *);
+ virtual void emitGPRel64Value(const MCExpr *);
virtual void emitDTPRel32Value(const MCExpr *);
virtual void emitDTPRel64Value(const MCExpr *);
virtual void emitTPRel32Value(const MCExpr *);
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index ee642117095ce..0a70c298dd0da 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -821,6 +821,29 @@ void MipsAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
getTargetStreamer().emitDirectiveSetPop();
}
+void MipsAsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
+ const MachineBasicBlock *MBB,
+ unsigned uid) const {
+ MCSymbol *MBBSym = MBB->getSymbol();
+ switch (MJTI.getEntryKind()) {
+ case MachineJumpTableInfo::EK_BlockAddress:
+ OutStreamer->emitValue(MCSymbolRefExpr::create(MBBSym, OutContext),
+ getDataLayout().getPointerSize());
+ break;
+ case MachineJumpTableInfo::EK_GPRel32BlockAddress:
+ // Each entry is a GP-relative value targeting the block symbol.
+ getTargetStreamer().emitGPRel32Value(
+ MCSymbolRefExpr::create(MBBSym, OutContext));
+ break;
+ case MachineJumpTableInfo::EK_GPRel64BlockAddress:
+ getTargetStreamer().emitGPRel64Value(
+ MCSymbolRefExpr::create(MBBSym, OutContext));
+ break;
+ default:
+ llvm_unreachable("");
+ }
+}
+
void MipsAsmPrinter::EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol) {
MCInst I;
I.setOpcode(Mips::JAL);
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.h b/llvm/lib/Target/Mips/MipsAsmPrinter.h
index d53a0f6a39667..060bba6ef65e0 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.h
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.h
@@ -85,6 +85,10 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
const MCSubtargetInfo *EndInfo) const override;
+ void emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
+ const MachineBasicBlock *MBB,
+ unsigned uid) const override;
+
void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol);
void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg);
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index e737c5aeb43c6..bd65431b475d0 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -4475,12 +4475,18 @@ bool MipsTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
}
unsigned MipsTargetLowering::getJumpTableEncoding() const {
-
- // FIXME: For space reasons this should be: EK_GPRel32BlockAddress.
- if (ABI.IsN64() && isPositionIndependent())
+ if (!isPositionIndependent())
+ return MachineJumpTableInfo::EK_BlockAddress;
+ if (ABI.IsN64())
return MachineJumpTableInfo::EK_GPRel64BlockAddress;
+ return MachineJumpTableInfo::EK_GPRel32BlockAddress;
+}
- return TargetLowering::getJumpTableEncoding();
+SDValue MipsTargetLowering::getPICJumpTableRelocBase(SDValue Table,
+ SelectionDAG &DAG) const {
+ if (!isPositionIndependent())
+ return Table;
+ return DAG.getGLOBAL_OFFSET_TABLE(getPointerTy(DAG.getDataLayout()));
}
bool MipsTargetLowering::useSoftFloat() const {
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.h b/llvm/lib/Target/Mips/MipsISelLowering.h
index 1d5f5e663d531..5bd7b09ded45b 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.h
+++ b/llvm/lib/Target/Mips/MipsISelLowering.h
@@ -707,6 +707,8 @@ class TargetRegisterClass;
bool ForCodeSize) const override;
unsigned getJumpTableEncoding() const override;
+ SDValue getPICJumpTableRelocBase(SDValue Table,
+ SelectionDAG &DAG) const override;
bool useSoftFloat() const override;
bool shouldInsertFencesForAtomic(const Instruction *I) const override {
More information about the llvm-commits
mailing list