Skip to content

Commit ed2f89f

Browse files
committed
Simplify R_SPARC_WDISP30 and R_SPARC_WPLT30 handling
Instead of determining the relocation type during SparcMCExpr construction (in AsmParser or AsmPrinter), use fixup_sparc_call30 and expand it to either R_SPARC_WDISP30 or R_SPARC_WPLT30.
1 parent 26d71f9 commit ed2f89f

File tree

9 files changed

+11
-32
lines changed

9 files changed

+11
-32
lines changed

llvm/lib/Target/Sparc/AsmParser/SparcAsmParser.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,12 +1322,7 @@ ParseStatus SparcAsmParser::parseCallTarget(OperandVector &Operands) {
13221322
if (getParser().parseExpression(DestValue))
13231323
return ParseStatus::NoMatch;
13241324

1325-
bool IsPic = getContext().getObjectFileInfo()->isPositionIndependent();
1326-
SparcMCExpr::Specifier Kind =
1327-
IsPic ? SparcMCExpr::VK_WPLT30 : SparcMCExpr::VK_WDISP30;
1328-
1329-
const MCExpr *DestExpr = SparcMCExpr::create(Kind, DestValue, getContext());
1330-
Operands.push_back(SparcOperand::CreateImm(DestExpr, S, E));
1325+
Operands.push_back(SparcOperand::CreateImm(DestValue, S, E));
13311326
return ParseStatus::Success;
13321327
}
13331328

llvm/lib/Target/Sparc/MCTargetDesc/SparcAsmBackend.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
3131
case FK_Data_8:
3232
return Value;
3333

34-
case Sparc::fixup_sparc_wplt30:
3534
case Sparc::fixup_sparc_call30:
3635
return (Value >> 2) & 0x3fffffff;
3736

@@ -150,7 +149,6 @@ namespace {
150149
{ "fixup_sparc_lm", 10, 22, 0 },
151150
{ "fixup_sparc_pc22", 10, 22, MCFixupKindInfo::FKF_IsPCRel },
152151
{ "fixup_sparc_pc10", 22, 10, MCFixupKindInfo::FKF_IsPCRel },
153-
{ "fixup_sparc_wplt30", 2, 30, MCFixupKindInfo::FKF_IsPCRel },
154152
{ "fixup_sparc_hix22", 10, 22, 0 },
155153
{ "fixup_sparc_lox10", 19, 13, 0 },
156154
};
@@ -172,7 +170,6 @@ namespace {
172170
{ "fixup_sparc_lm", 0, 22, 0 },
173171
{ "fixup_sparc_pc22", 0, 22, MCFixupKindInfo::FKF_IsPCRel },
174172
{ "fixup_sparc_pc10", 0, 10, MCFixupKindInfo::FKF_IsPCRel },
175-
{ "fixup_sparc_wplt30", 0, 30, MCFixupKindInfo::FKF_IsPCRel },
176173
{ "fixup_sparc_hix22", 0, 22, 0 },
177174
{ "fixup_sparc_lox10", 0, 13, 0 },
178175
};

llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ unsigned SparcELFObjectWriter::getRelocType(MCContext &Ctx,
8787
case FK_Data_2: return ELF::R_SPARC_DISP16;
8888
case FK_Data_4: return ELF::R_SPARC_DISP32;
8989
case FK_Data_8: return ELF::R_SPARC_DISP64;
90-
case Sparc::fixup_sparc_call30: return ELF::R_SPARC_WDISP30;
90+
case Sparc::fixup_sparc_call30:
91+
if (Ctx.getObjectFileInfo()->isPositionIndependent())
92+
return ELF::R_SPARC_WPLT30;
93+
return ELF::R_SPARC_WDISP30;
9194
case Sparc::fixup_sparc_br22: return ELF::R_SPARC_WDISP22;
9295
case Sparc::fixup_sparc_br19: return ELF::R_SPARC_WDISP19;
9396
case Sparc::fixup_sparc_br16:
9497
return ELF::R_SPARC_WDISP16;
9598
case Sparc::fixup_sparc_pc22: return ELF::R_SPARC_PC22;
9699
case Sparc::fixup_sparc_pc10: return ELF::R_SPARC_PC10;
97-
case Sparc::fixup_sparc_wplt30: return ELF::R_SPARC_WPLT30;
98100
}
99101
}
100102

llvm/lib/Target/Sparc/MCTargetDesc/SparcFixupKinds.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ namespace llvm {
6363
/// fixup_sparc_pc10 - 10-bit fixup corresponding to %pc10(foo)
6464
fixup_sparc_pc10,
6565

66-
/// fixup_sparc_wplt30
67-
fixup_sparc_wplt30,
68-
6966
/// 22-bit fixup corresponding to %hix(foo)
7067
fixup_sparc_hix22,
7168
/// 13-bit fixup corresponding to %lox(foo)

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCCodeEmitter.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ getCallTargetOpValue(const MCInst &MI, unsigned OpNo,
178178
}
179179

180180
const MCOperand &MO = MI.getOperand(OpNo);
181-
const MCExpr *Expr = MO.getExpr();
182-
auto *SExpr = cast<SparcMCExpr>(Expr);
183-
Fixups.push_back(MCFixup::create(0, Expr, SExpr->getFixupKind()));
181+
Fixups.push_back(MCFixup::create(0, MO.getExpr(), Sparc::fixup_sparc_call30));
184182
return 0;
185183
}
186184

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ StringRef SparcMCExpr::getSpecifierName(SparcMCExpr::Specifier S) {
5656
case VK_GOT22: return "hi";
5757
case VK_GOT10: return "lo";
5858
case VK_GOT13: return {};
59-
case VK_WDISP30: return {};
60-
case VK_WPLT30: return {};
6159
case VK_R_DISP32: return "r_disp32";
6260
case VK_TLS_GD_HI22: return "tgd_hi22";
6361
case VK_TLS_GD_LO10: return "tgd_lo10";
@@ -148,8 +146,6 @@ uint16_t SparcMCExpr::getFixupKind() const {
148146
case VK_GOT22: return ELF::R_SPARC_GOT22;
149147
case VK_GOT10: return ELF::R_SPARC_GOT10;
150148
case VK_GOT13: return ELF::R_SPARC_GOT13;
151-
case VK_WPLT30: return Sparc::fixup_sparc_wplt30;
152-
case VK_WDISP30: return Sparc::fixup_sparc_call30;
153149
case VK_TLS_GD_HI22: return ELF::R_SPARC_TLS_GD_HI22;
154150
case VK_TLS_GD_LO10: return ELF::R_SPARC_TLS_GD_LO10;
155151
case VK_TLS_GD_ADD: return ELF::R_SPARC_TLS_GD_ADD;

llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class SparcMCExpr : public MCTargetExpr {
3737
VK_GOT22,
3838
VK_GOT10,
3939
VK_GOT13,
40-
VK_WPLT30,
41-
VK_WDISP30,
4240
VK_R_DISP32,
4341
VK_TLS_GD_HI22,
4442
VK_TLS_GD_LO10,

llvm/lib/Target/Sparc/SparcAsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static MCOperand createSparcMCOperand(SparcMCExpr::Specifier Kind,
8484
}
8585
static MCOperand createPCXCallOP(MCSymbol *Label,
8686
MCContext &OutContext) {
87-
return createSparcMCOperand(SparcMCExpr::VK_WDISP30, Label, OutContext);
87+
return MCOperand::createExpr(MCSymbolRefExpr::create(Label, OutContext));
8888
}
8989

9090
static MCOperand createPCXRelExprOp(SparcMCExpr::Specifier Kind,

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,12 +1056,10 @@ SparcTargetLowering::LowerCall_32(TargetLowering::CallLoweringInfo &CLI,
10561056
// If the callee is a GlobalAddress node (quite common, every direct call is)
10571057
// turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
10581058
// Likewise ExternalSymbol -> TargetExternalSymbol.
1059-
unsigned TF = isPositionIndependent() ? SparcMCExpr::VK_WPLT30
1060-
: SparcMCExpr::VK_WDISP30;
10611059
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
1062-
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i32, 0, TF);
1060+
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i32, 0);
10631061
else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
1064-
Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32, TF);
1062+
Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32);
10651063

10661064
// Returns a chain & a flag for retval copy to use
10671065
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
@@ -1390,12 +1388,10 @@ SparcTargetLowering::LowerCall_64(TargetLowering::CallLoweringInfo &CLI,
13901388
// Likewise ExternalSymbol -> TargetExternalSymbol.
13911389
SDValue Callee = CLI.Callee;
13921390
bool hasReturnsTwice = hasReturnsTwiceAttr(DAG, Callee, CLI.CB);
1393-
unsigned TF = isPositionIndependent() ? SparcMCExpr::VK_WPLT30
1394-
: SparcMCExpr::VK_WDISP30;
13951391
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
1396-
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, PtrVT, 0, TF);
1392+
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), DL, PtrVT, 0);
13971393
else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
1398-
Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT, TF);
1394+
Callee = DAG.getTargetExternalSymbol(E->getSymbol(), PtrVT);
13991395

14001396
// Build the operands for the call instruction itself.
14011397
SmallVector<SDValue, 8> Ops;

0 commit comments

Comments
 (0)