[llvm] 6048629 - [MC] Move MIPS-specific gprel/tprel/dtprel from MCStreamer to MipsTargetStreamer
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 2 14:59:27 PST 2025
Author: Fangrui Song
Date: 2025-03-02T14:59:21-08:00
New Revision: 60486292b79885b7800b082754153202bef5b1f0
URL: https://github.com/llvm/llvm-project/commit/60486292b79885b7800b082754153202bef5b1f0
DIFF: https://github.com/llvm/llvm-project/commit/60486292b79885b7800b082754153202bef5b1f0.diff
LOG: [MC] Move MIPS-specific gprel/tprel/dtprel from MCStreamer to MipsTargetStreamer
https://reviews.llvm.org/D23669 inappropriately added MIPS-specific
dtprel/tprel directives to MCStreamer. In addition,
llvm-mc -filetype=null parsing these directives will crash.
This patch moves these functions to MipsTargetStreamer and fixes
-filetype=null.
gprel32 and gprel64, called by AsmPrinter, are moved to
MCTargetStreamer.
Added:
Modified:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/MC/MCFixup.h
llvm/include/llvm/MC/MCObjectStreamer.h
llvm/include/llvm/MC/MCStreamer.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/MC/MCAsmBackend.cpp
llvm/lib/MC/MCAsmStreamer.cpp
llvm/lib/MC/MCNullStreamer.cpp
llvm/lib/MC/MCObjectStreamer.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h
llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
llvm/lib/Target/Mips/MipsAsmPrinter.cpp
llvm/test/MC/Mips/relocation.s
llvm/tools/llvm-mca/CodeRegionGenerator.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 57def4d67ad52..87914d056714b 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -241,24 +241,11 @@ 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 64-bit GP-relative offset, e.g. .gpdword on Mips. Defaults
- /// to nullptr.
- const char *GPRel64Directive = nullptr;
-
/// 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;
- /// If non-null, directives that are used to emit a word/dword which should
- /// be relocated as a 32/64-bit DTP/TP-relative offset, e.g. .dtprelword/
- /// .dtpreldword/.tprelword/.tpreldword on Mips.
- const char *DTPRel32Directive = nullptr;
- const char *DTPRel64Directive = nullptr;
- const char *TPRel32Directive = nullptr;
- const char *TPRel64Directive = 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.
@@ -463,12 +450,7 @@ class MCAsmInfo {
const char *getData32bitsDirective() const { return Data32bitsDirective; }
const char *getData64bitsDirective() const { return Data64bitsDirective; }
bool supportsSignedData() const { return SupportsSignedData; }
- const char *getGPRel64Directive() const { return GPRel64Directive; }
const char *getGPRel32Directive() const { return GPRel32Directive; }
- const char *getDTPRel64Directive() const { return DTPRel64Directive; }
- const char *getDTPRel32Directive() const { return DTPRel32Directive; }
- const char *getTPRel64Directive() const { return TPRel64Directive; }
- const char *getTPRel32Directive() const { return TPRel32Directive; }
/// 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/MCFixup.h b/llvm/include/llvm/MC/MCFixup.h
index a0ed36d62ce9d..7cf8ac2e39092 100644
--- a/llvm/include/llvm/MC/MCFixup.h
+++ b/llvm/include/llvm/MC/MCFixup.h
@@ -29,14 +29,6 @@ enum MCFixupKind {
FK_PCRel_2, ///< A two-byte pc relative fixup.
FK_PCRel_4, ///< A four-byte pc relative fixup.
FK_PCRel_8, ///< A eight-byte pc relative fixup.
- FK_GPRel_1, ///< A one-byte gp relative fixup.
- FK_GPRel_2, ///< A two-byte gp relative fixup.
- FK_GPRel_4, ///< A four-byte gp relative fixup.
- FK_GPRel_8, ///< A eight-byte gp relative fixup.
- FK_DTPRel_4, ///< A four-byte dtp relative fixup.
- FK_DTPRel_8, ///< A eight-byte dtp relative fixup.
- FK_TPRel_4, ///< A four-byte tp relative fixup.
- FK_TPRel_8, ///< A eight-byte tp relative fixup.
FK_SecRel_1, ///< A one-byte section relative fixup.
FK_SecRel_2, ///< A two-byte section relative fixup.
FK_SecRel_4, ///< A four-byte section relative fixup.
diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
index 2e3ef417ce89a..d6a957322ea11 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -166,12 +166,6 @@ class MCObjectStreamer : public MCStreamer {
void emitCVStringTableDirective() override;
void emitCVFileChecksumsDirective() override;
void emitCVFileChecksumOffsetDirective(unsigned FileNo) override;
- void emitDTPRel32Value(const MCExpr *Value) override;
- void emitDTPRel64Value(const MCExpr *Value) override;
- void emitTPRel32Value(const MCExpr *Value) override;
- void emitTPRel64Value(const MCExpr *Value) override;
- void emitGPRel32Value(const MCExpr *Value) override;
- void emitGPRel64Value(const MCExpr *Value) override;
std::optional<std::pair<bool, std::string>>
emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
SMLoc Loc, const MCSubtargetInfo &STI) override;
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index e0178b2392e05..1192e5dbd9454 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -130,6 +130,10 @@ 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
@@ -762,48 +766,6 @@ class MCStreamer {
void emitSymbolValue(const MCSymbol *Sym, unsigned Size,
bool IsSectionRelative = false);
- /// Emit the expression \p Value into the output as a dtprel
- /// (64-bit DTP relative) value.
- ///
- /// This is used to implement assembler directives such as .dtpreldword on
- /// targets that support them.
- virtual void emitDTPRel64Value(const MCExpr *Value);
-
- /// Emit the expression \p Value into the output as a dtprel
- /// (32-bit DTP relative) value.
- ///
- /// This is used to implement assembler directives such as .dtprelword on
- /// targets that support them.
- virtual void emitDTPRel32Value(const MCExpr *Value);
-
- /// Emit the expression \p Value into the output as a tprel
- /// (64-bit TP relative) value.
- ///
- /// This is used to implement assembler directives such as .tpreldword on
- /// targets that support them.
- virtual void emitTPRel64Value(const MCExpr *Value);
-
- /// Emit the expression \p Value into the output as a tprel
- /// (32-bit TP relative) value.
- ///
- /// This is used to implement assembler directives such as .tprelword on
- /// targets that support them.
- virtual void emitTPRel32Value(const MCExpr *Value);
-
- /// Emit the expression \p Value into the output as a gprel64 (64-bit
- /// GP relative) value.
- ///
- /// This is used to implement assembler directives such as .gpdword on
- /// targets that support them.
- virtual void emitGPRel64Value(const MCExpr *Value);
-
- /// Emit the expression \p Value into the output as a gprel32 (32-bit
- /// GP relative) value.
- ///
- /// This is used to implement assembler directives such as .gprel32 on
- /// targets that support them.
- virtual void emitGPRel32Value(const MCExpr *Value);
-
/// Emit NumBytes bytes worth of the value specified by FillValue.
/// This implements directives such as '.space'.
void emitFill(uint64_t NumBytes, uint8_t FillValue);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3c4280333e76d..798de0e919424 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3043,7 +3043,8 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
// with a relocation as gp-relative, e.g.:
// .gprel32 LBB123
MCSymbol *MBBSym = MBB->getSymbol();
- OutStreamer->emitGPRel32Value(MCSymbolRefExpr::create(MBBSym, OutContext));
+ OutStreamer->getTargetStreamer()->emitGPRel32Value(
+ MCSymbolRefExpr::create(MBBSym, OutContext));
return;
}
@@ -3052,7 +3053,8 @@ void AsmPrinter::emitJumpTableEntry(const MachineJumpTableInfo &MJTI,
// with a relocation as gp-relative, e.g.:
// .gpdword LBB123
MCSymbol *MBBSym = MBB->getSymbol();
- OutStreamer->emitGPRel64Value(MCSymbolRefExpr::create(MBBSym, OutContext));
+ OutStreamer->getTargetStreamer()->emitGPRel64Value(
+ MCSymbolRefExpr::create(MBBSym, OutContext));
return;
}
diff --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index 9640e249d7680..b5a0766988e14 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -99,14 +99,6 @@ const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
{"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
{"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
{"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
- {"FK_GPRel_1", 0, 8, 0},
- {"FK_GPRel_2", 0, 16, 0},
- {"FK_GPRel_4", 0, 32, 0},
- {"FK_GPRel_8", 0, 64, 0},
- {"FK_DTPRel_4", 0, 32, 0},
- {"FK_DTPRel_8", 0, 64, 0},
- {"FK_TPRel_4", 0, 32, 0},
- {"FK_TPRel_8", 0, 64, 0},
{"FK_SecRel_1", 0, 8, 0},
{"FK_SecRel_2", 0, 16, 0},
{"FK_SecRel_4", 0, 32, 0},
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 4db405051f7f3..f1b34ca65abd9 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -259,15 +259,6 @@ class MCAsmStreamer final : public MCStreamer {
void emitSLEB128Value(const MCExpr *Value) override;
- void emitDTPRel32Value(const MCExpr *Value) override;
- void emitDTPRel64Value(const MCExpr *Value) override;
- void emitTPRel32Value(const MCExpr *Value) override;
- void emitTPRel64Value(const MCExpr *Value) override;
-
- void emitGPRel64Value(const MCExpr *Value) override;
-
- void emitGPRel32Value(const MCExpr *Value) override;
-
void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
SMLoc Loc = SMLoc()) override;
@@ -1432,48 +1423,6 @@ void MCAsmStreamer::emitSLEB128Value(const MCExpr *Value) {
EmitEOL();
}
-void MCAsmStreamer::emitDTPRel64Value(const MCExpr *Value) {
- assert(MAI->getDTPRel64Directive() != nullptr);
- OS << MAI->getDTPRel64Directive();
- Value->print(OS, MAI);
- EmitEOL();
-}
-
-void MCAsmStreamer::emitDTPRel32Value(const MCExpr *Value) {
- assert(MAI->getDTPRel32Directive() != nullptr);
- OS << MAI->getDTPRel32Directive();
- Value->print(OS, MAI);
- EmitEOL();
-}
-
-void MCAsmStreamer::emitTPRel64Value(const MCExpr *Value) {
- assert(MAI->getTPRel64Directive() != nullptr);
- OS << MAI->getTPRel64Directive();
- Value->print(OS, MAI);
- EmitEOL();
-}
-
-void MCAsmStreamer::emitTPRel32Value(const MCExpr *Value) {
- assert(MAI->getTPRel32Directive() != nullptr);
- OS << MAI->getTPRel32Directive();
- Value->print(OS, MAI);
- EmitEOL();
-}
-
-void MCAsmStreamer::emitGPRel64Value(const MCExpr *Value) {
- assert(MAI->getGPRel64Directive() != nullptr);
- OS << MAI->getGPRel64Directive();
- Value->print(OS, MAI);
- EmitEOL();
-}
-
-void MCAsmStreamer::emitGPRel32Value(const MCExpr *Value) {
- assert(MAI->getGPRel32Directive() != nullptr);
- OS << MAI->getGPRel32Directive();
- Value->print(OS, MAI);
- EmitEOL();
-}
-
void MCAsmStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
SMLoc Loc) {
int64_t IntNumBytes;
diff --git a/llvm/lib/MC/MCNullStreamer.cpp b/llvm/lib/MC/MCNullStreamer.cpp
index 7d5a823b389ab..dd2a24d175ab6 100644
--- a/llvm/lib/MC/MCNullStreamer.cpp
+++ b/llvm/lib/MC/MCNullStreamer.cpp
@@ -41,7 +41,6 @@ namespace {
void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
uint64_t Size = 0, Align ByteAlignment = Align(1),
SMLoc Loc = SMLoc()) override {}
- void emitGPRel32Value(const MCExpr *Value) override {}
void beginCOFFSymbolDef(const MCSymbol *Symbol) override {}
void emitCOFFSymbolStorageClass(int StorageClass) override {}
void emitCOFFSymbolType(int Type) override {}
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index fff30955b2576..9aee1abcd0d67 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -581,54 +581,6 @@ void MCObjectStreamer::emitValueToOffset(const MCExpr *Offset,
insert(getContext().allocFragment<MCOrgFragment>(*Offset, Value, Loc));
}
-// Associate DTPRel32 fixup with data and resize data area
-void MCObjectStreamer::emitDTPRel32Value(const MCExpr *Value) {
- MCDataFragment *DF = getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
- Value, FK_DTPRel_4));
- DF->appendContents(4, 0);
-}
-
-// Associate DTPRel64 fixup with data and resize data area
-void MCObjectStreamer::emitDTPRel64Value(const MCExpr *Value) {
- MCDataFragment *DF = getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
- Value, FK_DTPRel_8));
- DF->appendContents(8, 0);
-}
-
-// Associate TPRel32 fixup with data and resize data area
-void MCObjectStreamer::emitTPRel32Value(const MCExpr *Value) {
- MCDataFragment *DF = getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
- Value, FK_TPRel_4));
- DF->appendContents(4, 0);
-}
-
-// Associate TPRel64 fixup with data and resize data area
-void MCObjectStreamer::emitTPRel64Value(const MCExpr *Value) {
- MCDataFragment *DF = getOrCreateDataFragment();
- DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
- Value, FK_TPRel_8));
- DF->appendContents(8, 0);
-}
-
-// Associate GPRel32 fixup with data and resize data area
-void MCObjectStreamer::emitGPRel32Value(const MCExpr *Value) {
- MCDataFragment *DF = getOrCreateDataFragment();
- DF->getFixups().push_back(
- MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
- DF->appendContents(4, 0);
-}
-
-// Associate GPRel64 fixup with data and resize data area
-void MCObjectStreamer::emitGPRel64Value(const MCExpr *Value) {
- MCDataFragment *DF = getOrCreateDataFragment();
- DF->getFixups().push_back(
- MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
- DF->appendContents(8, 0);
-}
-
static std::optional<std::pair<bool, std::string>>
getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset,
MCDataFragment *&DF) {
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index dd04e1e30720a..16658bed381d0 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -90,6 +90,14 @@ 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) {
@@ -191,30 +199,6 @@ void MCStreamer::emitSymbolValue(const MCSymbol *Sym, unsigned Size,
emitCOFFSecRel32(Sym, /*Offset=*/0);
}
-void MCStreamer::emitDTPRel64Value(const MCExpr *Value) {
- report_fatal_error("unsupported directive in streamer");
-}
-
-void MCStreamer::emitDTPRel32Value(const MCExpr *Value) {
- report_fatal_error("unsupported directive in streamer");
-}
-
-void MCStreamer::emitTPRel64Value(const MCExpr *Value) {
- report_fatal_error("unsupported directive in streamer");
-}
-
-void MCStreamer::emitTPRel32Value(const MCExpr *Value) {
- report_fatal_error("unsupported directive in streamer");
-}
-
-void MCStreamer::emitGPRel64Value(const MCExpr *Value) {
- report_fatal_error("unsupported directive in streamer");
-}
-
-void MCStreamer::emitGPRel32Value(const MCExpr *Value) {
- report_fatal_error("unsupported directive in streamer");
-}
-
/// Emit NumBytes bytes worth of the value specified by FillValue.
/// This implements directives such as '.space'.
void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
index fbed25157a44e..27bd09e7ce908 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
@@ -360,10 +360,6 @@ void AVRAsmBackend::adjustFixupValue(const MCFixup &Fixup,
case FK_Data_4:
case FK_Data_8:
break;
-
- case FK_GPRel_4:
- llvm_unreachable("don't know how to adjust this fixup");
- break;
}
}
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 63920399f5e5c..62f17675f8230 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -8072,109 +8072,61 @@ bool MipsAsmParser::parseDirectiveSet() {
/// parseDirectiveGpWord
/// ::= .gpword local_sym
bool MipsAsmParser::parseDirectiveGpWord() {
- MCAsmParser &Parser = getParser();
const MCExpr *Value;
- // EmitGPRel32Value requires an expression, so we are using base class
- // method to evaluate the expression.
if (getParser().parseExpression(Value))
return true;
- getParser().getStreamer().emitGPRel32Value(Value);
-
- if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getLoc(),
- "unexpected token, expected end of statement");
- Parser.Lex(); // Eat EndOfStatement token.
- return false;
+ getTargetStreamer().emitGPRel32Value(Value);
+ return parseEOL();
}
/// parseDirectiveGpDWord
/// ::= .gpdword local_sym
bool MipsAsmParser::parseDirectiveGpDWord() {
- MCAsmParser &Parser = getParser();
const MCExpr *Value;
- // EmitGPRel64Value requires an expression, so we are using base class
- // method to evaluate the expression.
if (getParser().parseExpression(Value))
return true;
- getParser().getStreamer().emitGPRel64Value(Value);
-
- if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getLoc(),
- "unexpected token, expected end of statement");
- Parser.Lex(); // Eat EndOfStatement token.
- return false;
+ getTargetStreamer().emitGPRel64Value(Value);
+ return parseEOL();
}
/// parseDirectiveDtpRelWord
/// ::= .dtprelword tls_sym
bool MipsAsmParser::parseDirectiveDtpRelWord() {
- MCAsmParser &Parser = getParser();
const MCExpr *Value;
- // EmitDTPRel32Value requires an expression, so we are using base class
- // method to evaluate the expression.
if (getParser().parseExpression(Value))
return true;
- getParser().getStreamer().emitDTPRel32Value(Value);
-
- if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getLoc(),
- "unexpected token, expected end of statement");
- Parser.Lex(); // Eat EndOfStatement token.
- return false;
+ getTargetStreamer().emitDTPRel32Value(Value);
+ return parseEOL();
}
/// parseDirectiveDtpRelDWord
/// ::= .dtpreldword tls_sym
bool MipsAsmParser::parseDirectiveDtpRelDWord() {
- MCAsmParser &Parser = getParser();
const MCExpr *Value;
- // EmitDTPRel64Value requires an expression, so we are using base class
- // method to evaluate the expression.
if (getParser().parseExpression(Value))
return true;
- getParser().getStreamer().emitDTPRel64Value(Value);
-
- if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getLoc(),
- "unexpected token, expected end of statement");
- Parser.Lex(); // Eat EndOfStatement token.
- return false;
+ getTargetStreamer().emitDTPRel64Value(Value);
+ return parseEOL();
}
/// parseDirectiveTpRelWord
/// ::= .tprelword tls_sym
bool MipsAsmParser::parseDirectiveTpRelWord() {
- MCAsmParser &Parser = getParser();
const MCExpr *Value;
- // EmitTPRel32Value requires an expression, so we are using base class
- // method to evaluate the expression.
if (getParser().parseExpression(Value))
return true;
- getParser().getStreamer().emitTPRel32Value(Value);
-
- if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getLoc(),
- "unexpected token, expected end of statement");
- Parser.Lex(); // Eat EndOfStatement token.
- return false;
+ getTargetStreamer().emitTPRel32Value(Value);
+ return parseEOL();
}
/// parseDirectiveTpRelDWord
/// ::= .tpreldword tls_sym
bool MipsAsmParser::parseDirectiveTpRelDWord() {
- MCAsmParser &Parser = getParser();
const MCExpr *Value;
- // EmitTPRel64Value requires an expression, so we are using base class
- // method to evaluate the expression.
if (getParser().parseExpression(Value))
return true;
- getParser().getStreamer().emitTPRel64Value(Value);
-
- if (getLexer().isNot(AsmToken::EndOfStatement))
- return Error(getLexer().getLoc(),
- "unexpected token, expected end of statement");
- Parser.Lex(); // Eat EndOfStatement token.
- return false;
+ getTargetStreamer().emitTPRel64Value(Value);
+ return parseEOL();
}
bool MipsAsmParser::parseDirectiveOption() {
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
index a06794c1f783d..0ea7f4194b8c4 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
@@ -65,11 +65,11 @@ static unsigned adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
Ctx.reportError(Fixup.getLoc(),
"fixup value out of range [-32768, 65535]");
break;
- case FK_DTPRel_4:
- case FK_DTPRel_8:
- case FK_TPRel_4:
- case FK_TPRel_8:
- case FK_GPRel_4:
+ case Mips::fixup_Mips_GPREL32:
+ case Mips::fixup_Mips_DTPREL32:
+ case Mips::fixup_Mips_DTPREL64:
+ case Mips::fixup_Mips_TPREL32:
+ case Mips::fixup_Mips_TPREL64:
case FK_Data_4:
case FK_Data_8:
case Mips::fixup_Mips_SUB:
@@ -364,6 +364,11 @@ getFixupKindInfo(MCFixupKind Kind) const {
{ "fixup_Mips_16", 0, 16, 0 },
{ "fixup_Mips_32", 0, 32, 0 },
{ "fixup_Mips_REL32", 0, 32, 0 },
+ { "fixup_Mips_GPREL32", 0, 32, 0 },
+ { "fixup_Mips_DTPREL32", 0, 32, 0 },
+ { "fixup_Mips_DTPREL64", 0, 64, 0 },
+ { "fixup_Mips_TPREL32", 0, 32, 0 },
+ { "fixup_Mips_TPREL64", 0, 64, 0 },
{ "fixup_Mips_26", 0, 26, 0 },
{ "fixup_Mips_HI16", 0, 16, 0 },
{ "fixup_Mips_LO16", 0, 16, 0 },
@@ -373,7 +378,6 @@ getFixupKindInfo(MCFixupKind Kind) const {
{ "fixup_Mips_GOT", 0, 16, 0 },
{ "fixup_Mips_PC16", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
{ "fixup_Mips_CALL16", 0, 16, 0 },
- { "fixup_Mips_GPREL32", 0, 32, 0 },
{ "fixup_Mips_SHIFT5", 6, 5, 0 },
{ "fixup_Mips_SHIFT6", 6, 5, 0 },
{ "fixup_Mips_64", 0, 64, 0 },
@@ -446,6 +450,11 @@ getFixupKindInfo(MCFixupKind Kind) const {
{ "fixup_Mips_16", 16, 16, 0 },
{ "fixup_Mips_32", 0, 32, 0 },
{ "fixup_Mips_REL32", 0, 32, 0 },
+ { "fixup_Mips_GPREL32", 0, 32, 0 },
+ { "fixup_Mips_DTPREL32", 0, 32, 0 },
+ { "fixup_Mips_DTPREL64", 0, 64, 0 },
+ { "fixup_Mips_TPREL32", 0, 32, 0 },
+ { "fixup_Mips_TPREL64", 0, 64, 0 },
{ "fixup_Mips_26", 6, 26, 0 },
{ "fixup_Mips_HI16", 16, 16, 0 },
{ "fixup_Mips_LO16", 16, 16, 0 },
@@ -455,7 +464,6 @@ getFixupKindInfo(MCFixupKind Kind) const {
{ "fixup_Mips_GOT", 16, 16, 0 },
{ "fixup_Mips_PC16", 16, 16, MCFixupKindInfo::FKF_IsPCRel },
{ "fixup_Mips_CALL16", 16, 16, 0 },
- { "fixup_Mips_GPREL32", 0, 32, 0 },
{ "fixup_Mips_SHIFT5", 21, 5, 0 },
{ "fixup_Mips_SHIFT6", 21, 5, 0 },
{ "fixup_Mips_64", 0, 64, 0 },
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index b60b336422ed5..6bef51806fddb 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -218,15 +218,15 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
}
switch (Kind) {
- case FK_DTPRel_4:
+ case Mips::fixup_Mips_DTPREL32:
return ELF::R_MIPS_TLS_DTPREL32;
- case FK_DTPRel_8:
+ case Mips::fixup_Mips_DTPREL64:
return ELF::R_MIPS_TLS_DTPREL64;
- case FK_TPRel_4:
+ case Mips::fixup_Mips_TPREL32:
return ELF::R_MIPS_TLS_TPREL32;
- case FK_TPRel_8:
+ case Mips::fixup_Mips_TPREL64:
return ELF::R_MIPS_TLS_TPREL64;
- case FK_GPRel_4:
+ case Mips::fixup_Mips_GPREL32:
return setRTypes(ELF::R_MIPS_GPREL32,
is64Bit() ? ELF::R_MIPS_64 : ELF::R_MIPS_NONE,
ELF::R_MIPS_NONE);
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h
index b9b6782a46ca2..b6ea56377d97a 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h
@@ -31,6 +31,12 @@ enum Fixups {
// Full 32 bit data relative data fixup resulting in - R_MIPS_REL32.
fixup_Mips_REL32,
+ fixup_Mips_GPREL32, // R_MIPS_GPREL32
+ fixup_Mips_DTPREL32, // R_MIPS_TLS_DTPREL32
+ fixup_Mips_DTPREL64, // R_MIPS_TLS_DTPREL64
+ fixup_Mips_TPREL32, // R_MIPS_TLS_TPREL32
+ fixup_Mips_TPREL64, // R_MIPS_TLS_TPREL64
+
// Jump 26 bit fixup resulting in - R_MIPS_26.
fixup_Mips_26,
@@ -58,9 +64,6 @@ enum Fixups {
// resulting in - R_MIPS_CALL16.
fixup_Mips_CALL16,
- // resulting in - R_MIPS_GPREL32.
- fixup_Mips_GPREL32,
-
// resulting in - R_MIPS_SHIFT5.
fixup_Mips_SHIFT5,
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
index 3d175e163eacd..eddf1115e33a2 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCAsmInfo.cpp
@@ -40,11 +40,6 @@ MipsELFMCAsmInfo::MipsELFMCAsmInfo(const Triple &TheTriple,
CommentString = "#";
ZeroDirective = "\t.space\t";
GPRel32Directive = "\t.gpword\t";
- GPRel64Directive = "\t.gpdword\t";
- DTPRel32Directive = "\t.dtprelword\t";
- DTPRel64Directive = "\t.dtpreldword\t";
- TPRel32Directive = "\t.tprelword\t";
- TPRel64Directive = "\t.tpreldword\t";
UseAssignmentForEHBegin = true;
SupportsDebugInformation = true;
ExceptionsType = ExceptionHandling::DwarfCFI;
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
index 670dc71b00e5f..a2ca90c35bad3 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
@@ -12,11 +12,13 @@
#include "MipsTargetStreamer.h"
#include "MCTargetDesc/MipsABIInfo.h"
+#include "MipsBaseInfo.h"
#include "MipsELFStreamer.h"
#include "MipsInstPrinter.h"
#include "MipsMCExpr.h"
#include "MipsMCTargetDesc.h"
#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELFObjectWriter.h"
@@ -49,6 +51,13 @@ MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S)
: MCTargetStreamer(S), GPReg(Mips::GP), ModuleDirectiveAllowed(true) {
GPRInfoSet = FPRInfoSet = FrameInfoSet = false;
}
+
+void MipsTargetStreamer::emitGPRel32Value(const MCExpr *) {}
+void MipsTargetStreamer::emitGPRel64Value(const MCExpr *) {}
+void MipsTargetStreamer::emitDTPRel32Value(const MCExpr *) {}
+void MipsTargetStreamer::emitDTPRel64Value(const MCExpr *) {}
+void MipsTargetStreamer::emitTPRel32Value(const MCExpr *) {}
+void MipsTargetStreamer::emitTPRel64Value(const MCExpr *) {}
void MipsTargetStreamer::emitDirectiveSetMicroMips() {}
void MipsTargetStreamer::emitDirectiveSetNoMicroMips() {}
void MipsTargetStreamer::setUsesMicroMips() {}
@@ -386,6 +395,48 @@ MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
formatted_raw_ostream &OS)
: MipsTargetStreamer(S), OS(OS) {}
+void MipsTargetAsmStreamer::emitDTPRel32Value(const MCExpr *Value) {
+ auto *MAI = getStreamer().getContext().getAsmInfo();
+ OS << "\t.dtprelword\t";
+ Value->print(OS, MAI);
+ OS << '\n';
+}
+
+void MipsTargetAsmStreamer::emitDTPRel64Value(const MCExpr *Value) {
+ auto *MAI = getStreamer().getContext().getAsmInfo();
+ OS << "\t.dtpreldword\t";
+ Value->print(OS, MAI);
+ OS << '\n';
+}
+
+void MipsTargetAsmStreamer::emitTPRel32Value(const MCExpr *Value) {
+ auto *MAI = getStreamer().getContext().getAsmInfo();
+ OS << "\t.tprelword\t";
+ Value->print(OS, MAI);
+ OS << '\n';
+}
+
+void MipsTargetAsmStreamer::emitTPRel64Value(const MCExpr *Value) {
+ auto *MAI = getStreamer().getContext().getAsmInfo();
+ OS << "\t.tpreldword\t";
+ Value->print(OS, MAI);
+ OS << '\n';
+}
+
+void MipsTargetAsmStreamer::emitGPRel32Value(const MCExpr *Value) {
+ auto *MAI = getStreamer().getContext().getAsmInfo();
+ OS << "\t.gpword\t";
+ Value->print(OS, MAI);
+ OS << '\n';
+}
+
+void MipsTargetAsmStreamer::emitGPRel64Value(const MCExpr *Value) {
+ auto *MAI = getStreamer().getContext().getAsmInfo();
+ OS << "\t.gpdword\t";
+ Value->print(OS, MAI);
+ OS << '\n';
+}
+
void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
OS << "\t.set\tmicromips\n";
forbidModuleDirective();
@@ -981,6 +1032,48 @@ MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
return static_cast<MCELFStreamer &>(Streamer);
}
+void MipsTargetELFStreamer::emitGPRel32Value(const MCExpr *Value) {
+ MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
+ DF->getFixups().push_back(MCFixup::create(
+ DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_GPREL32)));
+ DF->appendContents(4, 0);
+}
+
+void MipsTargetELFStreamer::emitGPRel64Value(const MCExpr *Value) {
+ MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
+ DF->getFixups().push_back(MCFixup::create(
+ DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_GPREL32)));
+ DF->appendContents(8, 0);
+}
+
+void MipsTargetELFStreamer::emitDTPRel32Value(const MCExpr *Value) {
+ MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
+ DF->getFixups().push_back(MCFixup::create(
+ DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_DTPREL32)));
+ DF->appendContents(4, 0);
+}
+
+void MipsTargetELFStreamer::emitDTPRel64Value(const MCExpr *Value) {
+ MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
+ DF->getFixups().push_back(MCFixup::create(
+ DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_DTPREL64)));
+ DF->appendContents(8, 0);
+}
+
+void MipsTargetELFStreamer::emitTPRel32Value(const MCExpr *Value) {
+ MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
+ DF->getFixups().push_back(MCFixup::create(
+ DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_TPREL32)));
+ DF->appendContents(4, 0);
+}
+
+void MipsTargetELFStreamer::emitTPRel64Value(const MCExpr *Value) {
+ MCDataFragment *DF = getStreamer().getOrCreateDataFragment();
+ DF->getFixups().push_back(MCFixup::create(
+ DF->getContents().size(), Value, MCFixupKind(Mips::fixup_Mips_TPREL64)));
+ DF->appendContents(8, 0);
+}
+
void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
MicroMipsEnabled = true;
forbidModuleDirective();
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
index c73013baa4f05..581f834f84026 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.h
@@ -24,6 +24,13 @@ class MipsTargetStreamer : public MCTargetStreamer {
public:
MipsTargetStreamer(MCStreamer &S);
+ void emitGPRel32Value(const MCExpr *) override;
+ void emitGPRel64Value(const MCExpr *) override;
+ virtual void emitDTPRel32Value(const MCExpr *);
+ virtual void emitDTPRel64Value(const MCExpr *);
+ virtual void emitTPRel32Value(const MCExpr *);
+ virtual void emitTPRel64Value(const MCExpr *);
+
virtual void setPic(bool Value) {}
virtual void emitDirectiveSetMicroMips();
@@ -211,6 +218,14 @@ class MipsTargetAsmStreamer : public MipsTargetStreamer {
public:
MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
+
+ void emitGPRel32Value(const MCExpr *) override;
+ void emitGPRel64Value(const MCExpr *) override;
+ void emitDTPRel32Value(const MCExpr *) override;
+ void emitDTPRel64Value(const MCExpr *) override;
+ void emitTPRel32Value(const MCExpr *) override;
+ void emitTPRel64Value(const MCExpr *) override;
+
void emitDirectiveSetMicroMips() override;
void emitDirectiveSetNoMicroMips() override;
void emitDirectiveSetMips16() override;
@@ -327,6 +342,13 @@ class MipsTargetELFStreamer : public MipsTargetStreamer {
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
void finish() override;
+ void emitGPRel32Value(const MCExpr *) override;
+ void emitGPRel64Value(const MCExpr *) override;
+ void emitDTPRel32Value(const MCExpr *) override;
+ void emitDTPRel64Value(const MCExpr *) override;
+ void emitTPRel32Value(const MCExpr *) override;
+ void emitTPRel64Value(const MCExpr *) override;
+
void emitDirectiveSetMicroMips() override;
void emitDirectiveSetNoMicroMips() override;
void setUsesMicroMips() override;
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index e06a9b36bfe4f..ee642117095ce 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -1226,10 +1226,10 @@ void MipsAsmPrinter::emitDebugValue(const MCExpr *Value, unsigned Size) const {
if (MipsExpr && MipsExpr->getKind() == MipsMCExpr::MEK_DTPREL) {
switch (Size) {
case 4:
- OutStreamer->emitDTPRel32Value(MipsExpr->getSubExpr());
+ getTargetStreamer().emitDTPRel32Value(MipsExpr->getSubExpr());
break;
case 8:
- OutStreamer->emitDTPRel64Value(MipsExpr->getSubExpr());
+ getTargetStreamer().emitDTPRel64Value(MipsExpr->getSubExpr());
break;
default:
llvm_unreachable("Unexpected size of expression value.");
diff --git a/llvm/test/MC/Mips/relocation.s b/llvm/test/MC/Mips/relocation.s
index a92c62744fcaa..d181a246d3d59 100644
--- a/llvm/test/MC/Mips/relocation.s
+++ b/llvm/test/MC/Mips/relocation.s
@@ -8,6 +8,9 @@
// RUN: | llvm-readobj --sections --section-data - \
// RUN: | FileCheck -check-prefix=DATA %s
+/// MCNullStreamer can handle directives like .tprelword .dtprelword
+// RUN: llvm-mc -triple mips -filetype=null %s
+
// Test that we produce the correct relocation.
// FIXME: move more relocation only tests here.
diff --git a/llvm/tools/llvm-mca/CodeRegionGenerator.h b/llvm/tools/llvm-mca/CodeRegionGenerator.h
index 12261e7656a42..019f9d371fea3 100644
--- a/llvm/tools/llvm-mca/CodeRegionGenerator.h
+++ b/llvm/tools/llvm-mca/CodeRegionGenerator.h
@@ -106,7 +106,6 @@ class MCStreamerWrapper : public MCStreamer {
void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
uint64_t Size = 0, Align ByteAlignment = Align(1),
SMLoc Loc = SMLoc()) override {}
- void emitGPRel32Value(const MCExpr *Value) override {}
void beginCOFFSymbolDef(const MCSymbol *Symbol) override {}
void emitCOFFSymbolStorageClass(int StorageClass) override {}
void emitCOFFSymbolType(int Type) override {}
More information about the llvm-commits
mailing list