[PATCH] [mips] [IAS] Fix creation of MCSymbolRefExpr's of $tmp symbols in evaluateRelocExpr().
Toma Tabacu
toma.tabacu at imgtec.com
Fri May 22 07:56:23 PDT 2015
Hi dsanders,
Previously, MCSymbolRefExpr::Create() was called with a StringRef of the symbol name, which it would then search for in the Symbols StringMap (from MCContext).
However, $tmp symbols are (apparently) not stored in the Symbols StringMap, so we end up creating a new $tmp symbol ($tmp00, $tmp10 etc.) each time we create
an MCSymbolRefExpr by passing in the symbol name as a StringRef.
Fortunately, there is a version of MCSymbolRefExpr::Create() which takes an MCSymbol* and we already have an MCSymbol* at that point in evaluateRelocExpr(),
so we can just pass that in instead of the StringRef.
I also replaced the bad manual calls to MCSymbolRefExpr::Create() from expandMemInst() with calls to evaluateRelocExpr().
At the moment, expandLoadAddressSym() also has bad manual calls to MCSymbolRefExpr::Create(), but I didn't fix those because they're going to be
changed to evaluateRelocExpr() soon anyway (by D9344).
http://reviews.llvm.org/D9938
Files:
lib/Target/Mips/AsmParser/MipsAsmParser.cpp
test/MC/Mips/mips-expansions.s
Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp
===================================================================
--- lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -2029,7 +2029,6 @@
void MipsAsmParser::expandMemInst(MCInst &Inst, SMLoc IDLoc,
SmallVectorImpl<MCInst> &Instructions,
bool isLoad, bool isImmOpnd) {
- const MCSymbolRefExpr *SR;
MCInst TempInst;
unsigned ImmOffset, HiOffset, LoOffset;
const MCExpr *ExprOffset;
@@ -2096,16 +2095,8 @@
if (isImmOpnd)
TempInst.addOperand(MCOperand::createImm(HiOffset));
else {
- if (ExprOffset->getKind() == MCExpr::SymbolRef) {
- SR = static_cast<const MCSymbolRefExpr *>(ExprOffset);
- const MCSymbolRefExpr *HiExpr = MCSymbolRefExpr::Create(
- SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_HI,
- getContext());
- TempInst.addOperand(MCOperand::createExpr(HiExpr));
- } else {
- const MCExpr *HiExpr = evaluateRelocExpr(ExprOffset, "hi");
- TempInst.addOperand(MCOperand::createExpr(HiExpr));
- }
+ const MCExpr *HiExpr = evaluateRelocExpr(ExprOffset, "hi");
+ TempInst.addOperand(MCOperand::createExpr(HiExpr));
}
// Add the instruction to the list.
Instructions.push_back(TempInst);
@@ -2128,15 +2119,8 @@
if (isImmOpnd)
TempInst.addOperand(MCOperand::createImm(LoOffset));
else {
- if (ExprOffset->getKind() == MCExpr::SymbolRef) {
- const MCSymbolRefExpr *LoExpr = MCSymbolRefExpr::Create(
- SR->getSymbol().getName(), MCSymbolRefExpr::VK_Mips_ABS_LO,
- getContext());
- TempInst.addOperand(MCOperand::createExpr(LoExpr));
- } else {
- const MCExpr *LoExpr = evaluateRelocExpr(ExprOffset, "lo");
- TempInst.addOperand(MCOperand::createExpr(LoExpr));
- }
+ const MCExpr *LoExpr = evaluateRelocExpr(ExprOffset, "lo");
+ TempInst.addOperand(MCOperand::createExpr(LoExpr));
}
Instructions.push_back(TempInst);
TempInst.clear();
@@ -2566,7 +2550,7 @@
if (const MCSymbolRefExpr *MSRE = dyn_cast<MCSymbolRefExpr>(Expr)) {
// It's a symbol, create a symbolic expression from the symbol.
- StringRef Symbol = MSRE->getSymbol().getName();
+ const MCSymbol *Symbol = &MSRE->getSymbol();
MCSymbolRefExpr::VariantKind VK = getVariantKind(RelocStr);
Res = MCSymbolRefExpr::Create(Symbol, VK, getContext());
return Res;
Index: test/MC/Mips/mips-expansions.s
===================================================================
--- test/MC/Mips/mips-expansions.s
+++ test/MC/Mips/mips-expansions.s
@@ -35,6 +35,10 @@
# CHECK: addu $1, $1, $9 # encoding: [0x21,0x08,0x29,0x00]
# CHECK: sw $10, %lo(symbol)($1) # encoding: [A,A,0x2a,0xac]
# CHECK: # fixup A - offset: 0, value: symbol at ABS_LO, kind: fixup_Mips_LO16
+# CHECK: lui $8, %hi($tmp0) # encoding: [A,A,0x08,0x3c]
+# CHECK: # fixup A - offset: 0, value: ($tmp0)@ABS_HI, kind: fixup_Mips_HI16
+# CHECK: lw $8, %lo($tmp0)($8) # encoding: [A,A,0x08,0x8d]
+# CHECK: # fixup A - offset: 0, value: ($tmp0)@ABS_LO, kind: fixup_Mips_LO16
# CHECK: lui $10, 10 # encoding: [0x0a,0x00,0x0a,0x3c]
# CHECK: addu $10, $10, $4 # encoding: [0x21,0x50,0x44,0x01]
# CHECK: lw $10, 123($10) # encoding: [0x7b,0x00,0x4a,0x8d]
@@ -76,11 +80,16 @@
.set at
sw $t2, symbol($t1)
+ lw $8, 1f
+
lw $t2, 655483($a0)
sw $t2, 123456($t1)
lw $8, symbol
sw $8, symbol
ldc1 $f0, symbol
sdc1 $f0, symbol
+
+1:
+ add $4, $4, $4
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9938.26323.patch
Type: text/x-patch
Size: 3773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150522/00a2bc9d/attachment.bin>
More information about the llvm-commits
mailing list