@@ -1815,6 +1815,37 @@ static bool isEvaluated(const MCExpr *Expr) {
1815
1815
return false ;
1816
1816
}
1817
1817
1818
+ static bool needsExpandMemInst (MCInst &Inst) {
1819
+ const MCInstrDesc &MCID = getInstDesc (Inst.getOpcode ());
1820
+
1821
+ unsigned NumOp = MCID.getNumOperands ();
1822
+ if (NumOp != 3 && NumOp != 4 )
1823
+ return false ;
1824
+
1825
+ const MCOperandInfo &OpInfo = MCID.OpInfo [NumOp - 1 ];
1826
+ if (OpInfo.OperandType != MCOI::OPERAND_MEMORY &&
1827
+ OpInfo.OperandType != MCOI::OPERAND_UNKNOWN)
1828
+ return false ;
1829
+
1830
+ MCOperand &Op = Inst.getOperand (NumOp - 1 );
1831
+ if (Op.isImm ()) {
1832
+ // Offset can't exceed 16bit value.
1833
+ return !isInt<16 >(Op.getImm ());
1834
+ }
1835
+
1836
+ if (Op.isExpr ()) {
1837
+ const MCExpr *Expr = Op.getExpr ();
1838
+ if (Expr->getKind () != MCExpr::SymbolRef)
1839
+ return !isEvaluated (Expr);
1840
+
1841
+ // Expand symbol.
1842
+ const MCSymbolRefExpr *SR = static_cast <const MCSymbolRefExpr *>(Expr);
1843
+ return SR->getKind () == MCSymbolRefExpr::VK_None;
1844
+ }
1845
+
1846
+ return false ;
1847
+ }
1848
+
1818
1849
bool MipsAsmParser::processInstruction (MCInst &Inst, SMLoc IDLoc,
1819
1850
MCStreamer &Out,
1820
1851
const MCSubtargetInfo *STI) {
@@ -2102,35 +2133,11 @@ bool MipsAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
2102
2133
if ((MCID.mayLoad () || MCID.mayStore ()) && !IsPCRelativeLoad) {
2103
2134
// Check the offset of memory operand, if it is a symbol
2104
2135
// reference or immediate we may have to expand instructions.
2105
- for (unsigned i = 0 ; i < MCID.getNumOperands (); i++) {
2106
- const MCOperandInfo &OpInfo = MCID.OpInfo [i];
2107
- if ((OpInfo.OperandType == MCOI::OPERAND_MEMORY) ||
2108
- (OpInfo.OperandType == MCOI::OPERAND_UNKNOWN)) {
2109
- MCOperand &Op = Inst.getOperand (i);
2110
- if (Op.isImm ()) {
2111
- if (!isInt<16 >(Op.getImm ())) {
2112
- // Offset can't exceed 16bit value.
2113
- expandMemInst (Inst, IDLoc, Out, STI, MCID.mayLoad ());
2114
- return getParser ().hasPendingError ();
2115
- }
2116
- } else if (Op.isExpr ()) {
2117
- const MCExpr *Expr = Op.getExpr ();
2118
- if (Expr->getKind () == MCExpr::SymbolRef) {
2119
- const MCSymbolRefExpr *SR =
2120
- static_cast <const MCSymbolRefExpr *>(Expr);
2121
- if (SR->getKind () == MCSymbolRefExpr::VK_None) {
2122
- // Expand symbol.
2123
- expandMemInst (Inst, IDLoc, Out, STI, MCID.mayLoad ());
2124
- return getParser ().hasPendingError ();
2125
- }
2126
- } else if (!isEvaluated (Expr)) {
2127
- expandMemInst (Inst, IDLoc, Out, STI, MCID.mayLoad ());
2128
- return getParser ().hasPendingError ();
2129
- }
2130
- }
2131
- }
2132
- } // for
2133
- } // if load/store
2136
+ if (needsExpandMemInst (Inst)) {
2137
+ expandMemInst (Inst, IDLoc, Out, STI, MCID.mayLoad ());
2138
+ return getParser ().hasPendingError ();
2139
+ }
2140
+ }
2134
2141
2135
2142
if (inMicroMipsMode ()) {
2136
2143
if (MCID.mayLoad () && Opcode != Mips::LWP_MM) {
0 commit comments