[Hexagon] Wrapping all MCExprs inside MCOperands within HexagonMCExpr to simplify handling and allow flags on the expression.

llvm-svn: 260902
This commit is contained in:
Colin LeMahieu 2016-02-15 18:42:07 +00:00
parent 93cff7fb82
commit 98c8e070b9
8 changed files with 169 additions and 92 deletions

View File

@ -243,7 +243,7 @@ public:
bool CheckImmRange(int immBits, int zeroBits, bool isSigned, bool CheckImmRange(int immBits, int zeroBits, bool isSigned,
bool isRelocatable, bool Extendable) const { bool isRelocatable, bool Extendable) const {
if (Kind == Immediate) { if (Kind == Immediate) {
const MCExpr *myMCExpr = getImm(); const MCExpr *myMCExpr = &HexagonMCInstrInfo::getExpr(*getImm());
if (Imm.MustExtend && !Extendable) if (Imm.MustExtend && !Extendable)
return false; return false;
int64_t Res; int64_t Res;
@ -553,13 +553,15 @@ public:
void adds4_6ImmOperands(MCInst &Inst, unsigned N) const { void adds4_6ImmOperands(MCInst &Inst, unsigned N) const {
assert(N == 1 && "Invalid number of operands!"); assert(N == 1 && "Invalid number of operands!");
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); const MCConstantExpr *CE =
dyn_cast<MCConstantExpr>(&HexagonMCInstrInfo::getExpr(*getImm()));
Inst.addOperand(MCOperand::createImm(CE->getValue() * 64)); Inst.addOperand(MCOperand::createImm(CE->getValue() * 64));
} }
void adds3_6ImmOperands(MCInst &Inst, unsigned N) const { void adds3_6ImmOperands(MCInst &Inst, unsigned N) const {
assert(N == 1 && "Invalid number of operands!"); assert(N == 1 && "Invalid number of operands!");
const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); const MCConstantExpr *CE =
dyn_cast<MCConstantExpr>(&HexagonMCInstrInfo::getExpr(*getImm()));
Inst.addOperand(MCOperand::createImm(CE->getValue() * 64)); Inst.addOperand(MCOperand::createImm(CE->getValue() * 64));
} }
@ -590,6 +592,7 @@ public:
static std::unique_ptr<HexagonOperand> CreateImm(const MCExpr *Val, SMLoc S, static std::unique_ptr<HexagonOperand> CreateImm(const MCExpr *Val, SMLoc S,
SMLoc E) { SMLoc E) {
assert(&HexagonMCInstrInfo::getExpr(*Val) != nullptr);
HexagonOperand *Op = new HexagonOperand(Immediate); HexagonOperand *Op = new HexagonOperand(Immediate);
Op->Imm.Val = Val; Op->Imm.Val = Val;
Op->Imm.MustExtend = false; Op->Imm.MustExtend = false;
@ -765,8 +768,8 @@ void HexagonAsmParser::canonicalizeImmediates(MCInst &MCI) {
if (WarnSignedMismatch) if (WarnSignedMismatch)
Warning (MCI.getLoc(), "Signed/Unsigned mismatch"); Warning (MCI.getLoc(), "Signed/Unsigned mismatch");
} }
NewInst.addOperand(MCOperand::createExpr( NewInst.addOperand(MCOperand::createExpr(HexagonMCExpr::Create(
MCConstantExpr::create(Value, getContext()))); MCConstantExpr::create(Value, getContext()), getContext())));
} }
else else
NewInst.addOperand(I); NewInst.addOperand(I);
@ -916,7 +919,8 @@ bool HexagonAsmParser::ParseDirectiveSubsection(SMLoc L) {
// end of the section. Only legacy hexagon-gcc created assembly code // end of the section. Only legacy hexagon-gcc created assembly code
// used negative subsections. // used negative subsections.
if ((Res < 0) && (Res > -8193)) if ((Res < 0) && (Res > -8193))
Subsection = MCConstantExpr::create(8192 + Res, this->getContext()); Subsection = HexagonMCExpr::Create(
MCConstantExpr::create(8192 + Res, getContext()), getContext());
getStreamer().SubSection(Subsection); getStreamer().SubSection(Subsection);
return false; return false;
@ -1333,11 +1337,12 @@ bool HexagonAsmParser::parseExpressionOrOperand(OperandVector &Operands) {
if (implicitExpressionLocation(Operands)) { if (implicitExpressionLocation(Operands)) {
MCAsmParser &Parser = getParser(); MCAsmParser &Parser = getParser();
SMLoc Loc = Parser.getLexer().getLoc(); SMLoc Loc = Parser.getLexer().getLoc();
std::unique_ptr<HexagonOperand> Expr = MCExpr const *Expr = nullptr;
HexagonOperand::CreateImm(nullptr, Loc, Loc); bool Error = parseExpression(Expr);
MCExpr const *& Val = Expr->Imm.Val; Expr = HexagonMCExpr::Create(Expr, getContext());
Operands.push_back(std::move(Expr)); if (!Error)
return parseExpression(Val); Operands.push_back(HexagonOperand::CreateImm(Expr, Loc, Loc));
return Error;
} }
return parseOperand(Operands); return parseOperand(Operands);
} }
@ -1389,8 +1394,7 @@ bool HexagonAsmParser::parseInstruction(OperandVector &Operands) {
case AsmToken::Hash: { case AsmToken::Hash: {
bool MustNotExtend = false; bool MustNotExtend = false;
bool ImplicitExpression = implicitExpressionLocation(Operands); bool ImplicitExpression = implicitExpressionLocation(Operands);
std::unique_ptr<HexagonOperand> Expr = HexagonOperand::CreateImm( SMLoc ExprLoc = Lexer.getLoc();
nullptr, Lexer.getLoc(), Lexer.getLoc());
if (!ImplicitExpression) if (!ImplicitExpression)
Operands.push_back( Operands.push_back(
HexagonOperand::CreateToken(Token.getString(), Token.getLoc())); HexagonOperand::CreateToken(Token.getString(), Token.getLoc()));
@ -1422,23 +1426,27 @@ bool HexagonAsmParser::parseInstruction(OperandVector &Operands) {
} }
} }
} }
if (parseExpression(Expr->Imm.Val)) MCExpr const *Expr = nullptr;
if (parseExpression(Expr))
return true; return true;
int64_t Value; int64_t Value;
MCContext &Context = Parser.getContext(); MCContext &Context = Parser.getContext();
assert(Expr->Imm.Val != nullptr); assert(Expr != nullptr);
if (Expr->Imm.Val->evaluateAsAbsolute(Value)) { if (Expr->evaluateAsAbsolute(Value)) {
if (HiOnly) if (HiOnly)
Expr->Imm.Val = MCBinaryExpr::createLShr( Expr = MCBinaryExpr::createLShr(
Expr->Imm.Val, MCConstantExpr::create(16, Context), Context); Expr, MCConstantExpr::create(16, Context), Context);
if (HiOnly || LoOnly) if (HiOnly || LoOnly)
Expr->Imm.Val = MCBinaryExpr::createAnd( Expr = MCBinaryExpr::createAnd(Expr,
Expr->Imm.Val, MCConstantExpr::create(0xffff, Context), Context); MCConstantExpr::create(0xffff, Context),
Context);
} }
if (MustNotExtend) Expr = HexagonMCExpr::Create(Expr, Context);
Expr->Imm.Val = HexagonNoExtendOperand::Create(Expr->Imm.Val, Context); HexagonMCInstrInfo::setMustNotExtend(*Expr, MustNotExtend);
Expr->Imm.MustExtend = MustExtend; std::unique_ptr<HexagonOperand> Operand =
Operands.push_back(std::move(Expr)); HexagonOperand::CreateImm(Expr, ExprLoc, ExprLoc);
Operand->Imm.MustExtend = MustExtend;
Operands.push_back(std::move(Operand));
continue; continue;
} }
default: default:
@ -1555,8 +1563,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
case Hexagon::C2_cmpgei: { case Hexagon::C2_cmpgei: {
MCOperand &MO = Inst.getOperand(2); MCOperand &MO = Inst.getOperand(2);
MO.setExpr(MCBinaryExpr::createSub( MO.setExpr(HexagonMCExpr::Create(MCBinaryExpr::createSub(
MO.getExpr(), MCConstantExpr::create(1, Context), Context)); MO.getExpr(), MCConstantExpr::create(1, Context), Context), Context));
Inst.setOpcode(Hexagon::C2_cmpgti); Inst.setOpcode(Hexagon::C2_cmpgti);
break; break;
} }
@ -1577,8 +1585,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
TmpInst.addOperand(Rt); TmpInst.addOperand(Rt);
Inst = TmpInst; Inst = TmpInst;
} else { } else {
MO.setExpr(MCBinaryExpr::createSub( MO.setExpr(HexagonMCExpr::Create(MCBinaryExpr::createSub(
MO.getExpr(), MCConstantExpr::create(1, Context), Context)); MO.getExpr(), MCConstantExpr::create(1, Context), Context), Context));
Inst.setOpcode(Hexagon::C2_cmpgtui); Inst.setOpcode(Hexagon::C2_cmpgtui);
} }
break; break;
@ -1773,7 +1781,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
MCOperand &MO = Inst.getOperand(1); MCOperand &MO = Inst.getOperand(1);
int64_t Value; int64_t Value;
int sVal = (MO.getExpr()->evaluateAsAbsolute(Value) && Value < 0) ? -1 : 0; int sVal = (MO.getExpr()->evaluateAsAbsolute(Value) && Value < 0) ? -1 : 0;
MCOperand imm(MCOperand::createExpr(MCConstantExpr::create(sVal, Context))); MCOperand imm(MCOperand::createExpr(
HexagonMCExpr::Create(MCConstantExpr::create(sVal, Context), Context)));
Inst = makeCombineInst(Hexagon::A2_combineii, Rdd, imm, MO); Inst = makeCombineInst(Hexagon::A2_combineii, Rdd, imm, MO);
break; break;
} }
@ -1788,14 +1797,15 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
signed int s8 = (u64 >> 32) & 0xFFFFFFFF; signed int s8 = (u64 >> 32) & 0xFFFFFFFF;
if (s8 < -128 || s8 > 127) if (s8 < -128 || s8 > 127)
OutOfRange(IDLoc, s8, -128); OutOfRange(IDLoc, s8, -128);
MCOperand imm(MCOperand::createExpr( MCOperand imm(MCOperand::createExpr(HexagonMCExpr::Create(
MCConstantExpr::create(s8, Context))); // upper 32 MCConstantExpr::create(s8, Context), Context))); // upper 32
MCOperand imm2(MCOperand::createExpr( MCOperand imm2(MCOperand::createExpr(HexagonMCExpr::Create(
MCConstantExpr::create(u64 & 0xFFFFFFFF, Context))); // lower 32 MCConstantExpr::create(u64 & 0xFFFFFFFF, Context),
Context))); // lower 32
Inst = makeCombineInst(Hexagon::A4_combineii, Rdd, imm, imm2); Inst = makeCombineInst(Hexagon::A4_combineii, Rdd, imm, imm2);
} else { } else {
MCOperand imm(MCOperand::createExpr( MCOperand imm(MCOperand::createExpr(HexagonMCExpr::Create(
MCConstantExpr::create(0, Context))); // upper 32 MCConstantExpr::create(0, Context), Context))); // upper 32
Inst = makeCombineInst(Hexagon::A4_combineii, Rdd, imm, MO); Inst = makeCombineInst(Hexagon::A4_combineii, Rdd, imm, MO);
} }
break; break;
@ -1843,8 +1853,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
MCOperand &Rs = Inst.getOperand(2); MCOperand &Rs = Inst.getOperand(2);
MCOperand &Imm4 = Inst.getOperand(3); MCOperand &Imm4 = Inst.getOperand(3);
MCOperand &Imm6 = Inst.getOperand(4); MCOperand &Imm6 = Inst.getOperand(4);
Imm6.setExpr(MCBinaryExpr::createSub( Imm6.setExpr(HexagonMCExpr::Create(MCBinaryExpr::createSub(
Imm6.getExpr(), MCConstantExpr::create(1, Context), Context)); Imm6.getExpr(), MCConstantExpr::create(1, Context), Context), Context));
TmpInst.setOpcode(Hexagon::S2_tableidxh); TmpInst.setOpcode(Hexagon::S2_tableidxh);
TmpInst.addOperand(Rx); TmpInst.addOperand(Rx);
TmpInst.addOperand(_dst_); TmpInst.addOperand(_dst_);
@ -1862,8 +1872,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
MCOperand &Rs = Inst.getOperand(2); MCOperand &Rs = Inst.getOperand(2);
MCOperand &Imm4 = Inst.getOperand(3); MCOperand &Imm4 = Inst.getOperand(3);
MCOperand &Imm6 = Inst.getOperand(4); MCOperand &Imm6 = Inst.getOperand(4);
Imm6.setExpr(MCBinaryExpr::createSub( Imm6.setExpr(HexagonMCExpr::Create(MCBinaryExpr::createSub(
Imm6.getExpr(), MCConstantExpr::create(2, Context), Context)); Imm6.getExpr(), MCConstantExpr::create(2, Context), Context), Context));
TmpInst.setOpcode(Hexagon::S2_tableidxw); TmpInst.setOpcode(Hexagon::S2_tableidxw);
TmpInst.addOperand(Rx); TmpInst.addOperand(Rx);
TmpInst.addOperand(_dst_); TmpInst.addOperand(_dst_);
@ -1881,8 +1891,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
MCOperand &Rs = Inst.getOperand(2); MCOperand &Rs = Inst.getOperand(2);
MCOperand &Imm4 = Inst.getOperand(3); MCOperand &Imm4 = Inst.getOperand(3);
MCOperand &Imm6 = Inst.getOperand(4); MCOperand &Imm6 = Inst.getOperand(4);
Imm6.setExpr(MCBinaryExpr::createSub( Imm6.setExpr(HexagonMCExpr::Create(MCBinaryExpr::createSub(
Imm6.getExpr(), MCConstantExpr::create(3, Context), Context)); Imm6.getExpr(), MCConstantExpr::create(3, Context), Context), Context));
TmpInst.setOpcode(Hexagon::S2_tableidxd); TmpInst.setOpcode(Hexagon::S2_tableidxd);
TmpInst.addOperand(Rx); TmpInst.addOperand(Rx);
TmpInst.addOperand(_dst_); TmpInst.addOperand(_dst_);
@ -1908,7 +1918,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
(void)Absolute; (void)Absolute;
if (!MustExtend) { if (!MustExtend) {
if (Value < 0 && Value > -256) { if (Value < 0 && Value > -256) {
Imm.setExpr(MCConstantExpr::create(Value * -1, Context)); Imm.setExpr(HexagonMCExpr::Create(
MCConstantExpr::create(Value * -1, Context), Context));
TmpInst.setOpcode(Hexagon::M2_mpysin); TmpInst.setOpcode(Hexagon::M2_mpysin);
} else if (Value < 256 && Value >= 0) } else if (Value < 256 && Value >= 0)
TmpInst.setOpcode(Hexagon::M2_mpysip); TmpInst.setOpcode(Hexagon::M2_mpysip);
@ -1941,8 +1952,10 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
TmpInst.addOperand(Rd); TmpInst.addOperand(Rd);
TmpInst.addOperand(Rs); TmpInst.addOperand(Rs);
} else { } else {
Imm.setExpr(MCBinaryExpr::createSub( Imm.setExpr(HexagonMCExpr::Create(
Imm.getExpr(), MCConstantExpr::create(1, Context), Context)); MCBinaryExpr::createSub(Imm.getExpr(),
MCConstantExpr::create(1, Context), Context),
Context));
TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd); TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd);
MCOperand &Rd = Inst.getOperand(0); MCOperand &Rd = Inst.getOperand(0);
MCOperand &Rs = Inst.getOperand(1); MCOperand &Rs = Inst.getOperand(1);
@ -1977,8 +1990,10 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
TmpInst.addOperand(MCOperand::createReg(MatchRegisterName(Reg2))); TmpInst.addOperand(MCOperand::createReg(MatchRegisterName(Reg2)));
Inst = TmpInst; Inst = TmpInst;
} else { } else {
Imm.setExpr(MCBinaryExpr::createSub( Imm.setExpr(HexagonMCExpr::Create(
Imm.getExpr(), MCConstantExpr::create(1, Context), Context)); MCBinaryExpr::createSub(Imm.getExpr(),
MCConstantExpr::create(1, Context), Context),
Context));
Inst.setOpcode(Hexagon::S2_asr_i_p_rnd); Inst.setOpcode(Hexagon::S2_asr_i_p_rnd);
} }
break; break;
@ -2097,8 +2112,10 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
if (Value == 0) if (Value == 0)
Inst.setOpcode(Hexagon::S2_vsathub); Inst.setOpcode(Hexagon::S2_vsathub);
else { else {
Imm.setExpr(MCBinaryExpr::createSub( Imm.setExpr(HexagonMCExpr::Create(
Imm.getExpr(), MCConstantExpr::create(1, Context), Context)); MCBinaryExpr::createSub(Imm.getExpr(),
MCConstantExpr::create(1, Context), Context),
Context));
Inst.setOpcode(Hexagon::S5_asrhub_rnd_sat); Inst.setOpcode(Hexagon::S5_asrhub_rnd_sat);
} }
break; break;
@ -2127,8 +2144,10 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
TmpInst.addOperand(MCOperand::createReg(MatchRegisterName(Reg2))); TmpInst.addOperand(MCOperand::createReg(MatchRegisterName(Reg2)));
Inst = TmpInst; Inst = TmpInst;
} else { } else {
Imm.setExpr(MCBinaryExpr::createSub( Imm.setExpr(HexagonMCExpr::Create(
Imm.getExpr(), MCConstantExpr::create(1, Context), Context)); MCBinaryExpr::createSub(Imm.getExpr(),
MCConstantExpr::create(1, Context), Context),
Context));
Inst.setOpcode(Hexagon::S5_vasrhrnd); Inst.setOpcode(Hexagon::S5_vasrhrnd);
} }
break; break;
@ -2140,8 +2159,8 @@ int HexagonAsmParser::processInstruction(MCInst &Inst,
MCOperand &Rs = Inst.getOperand(1); MCOperand &Rs = Inst.getOperand(1);
TmpInst.setOpcode(Hexagon::A2_subri); TmpInst.setOpcode(Hexagon::A2_subri);
TmpInst.addOperand(Rd); TmpInst.addOperand(Rd);
TmpInst.addOperand( TmpInst.addOperand(MCOperand::createExpr(
MCOperand::createExpr(MCConstantExpr::create(-1, Context))); HexagonMCExpr::Create(MCConstantExpr::create(-1, Context), Context)));
TmpInst.addOperand(Rs); TmpInst.addOperand(Rs);
Inst = TmpInst; Inst = TmpInst;
break; break;

View File

@ -297,8 +297,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCOperand &Reg = MappedInst.getOperand(0); MCOperand &Reg = MappedInst.getOperand(0);
TmpInst.setOpcode(Hexagon::L2_loadrigp); TmpInst.setOpcode(Hexagon::L2_loadrigp);
TmpInst.addOperand(Reg); TmpInst.addOperand(Reg);
TmpInst.addOperand(MCOperand::createExpr( TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::Create(
MCSymbolRefExpr::create(Sym, OutContext))); MCSymbolRefExpr::create(Sym, OutContext), OutContext)));
MappedInst = TmpInst; MappedInst = TmpInst;
} }
break; break;
@ -367,7 +367,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
int64_t Imm; int64_t Imm;
MCExpr const *Expr = MO.getExpr(); MCExpr const *Expr = MO.getExpr();
bool Success = Expr->evaluateAsAbsolute(Imm); bool Success = Expr->evaluateAsAbsolute(Imm);
assert (Success && "Expected immediate and none was found");(void)Success; assert (Success && "Expected immediate and none was found");
(void)Success;
MCInst TmpInst; MCInst TmpInst;
if (Imm == 0) { if (Imm == 0) {
TmpInst.setOpcode(Hexagon::S2_vsathub); TmpInst.setOpcode(Hexagon::S2_vsathub);
@ -381,7 +382,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
TmpInst.addOperand(MappedInst.getOperand(1)); TmpInst.addOperand(MappedInst.getOperand(1));
const MCExpr *One = MCConstantExpr::create(1, OutContext); const MCExpr *One = MCConstantExpr::create(1, OutContext);
const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext); const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Sub)); TmpInst.addOperand(
MCOperand::createExpr(HexagonMCExpr::Create(Sub, OutContext)));
MappedInst = TmpInst; MappedInst = TmpInst;
return; return;
} }
@ -391,7 +393,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCExpr const *Expr = MO2.getExpr(); MCExpr const *Expr = MO2.getExpr();
int64_t Imm; int64_t Imm;
bool Success = Expr->evaluateAsAbsolute(Imm); bool Success = Expr->evaluateAsAbsolute(Imm);
assert (Success && "Expected immediate and none was found");(void)Success; assert (Success && "Expected immediate and none was found");
(void)Success;
MCInst TmpInst; MCInst TmpInst;
if (Imm == 0) { if (Imm == 0) {
TmpInst.setOpcode(Hexagon::A2_combinew); TmpInst.setOpcode(Hexagon::A2_combinew);
@ -414,7 +417,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
TmpInst.addOperand(MappedInst.getOperand(1)); TmpInst.addOperand(MappedInst.getOperand(1));
const MCExpr *One = MCConstantExpr::create(1, OutContext); const MCExpr *One = MCConstantExpr::create(1, OutContext);
const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext); const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Sub)); TmpInst.addOperand(
MCOperand::createExpr(HexagonMCExpr::Create(Sub, OutContext)));
MappedInst = TmpInst; MappedInst = TmpInst;
return; return;
} }
@ -424,7 +428,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCExpr const *Expr = MO.getExpr(); MCExpr const *Expr = MO.getExpr();
int64_t Imm; int64_t Imm;
bool Success = Expr->evaluateAsAbsolute(Imm); bool Success = Expr->evaluateAsAbsolute(Imm);
assert (Success && "Expected immediate and none was found");(void)Success; assert (Success && "Expected immediate and none was found");
(void)Success;
MCInst TmpInst; MCInst TmpInst;
if (Imm == 0) { if (Imm == 0) {
TmpInst.setOpcode(Hexagon::A2_tfr); TmpInst.setOpcode(Hexagon::A2_tfr);
@ -438,7 +443,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
TmpInst.addOperand(MappedInst.getOperand(1)); TmpInst.addOperand(MappedInst.getOperand(1));
const MCExpr *One = MCConstantExpr::create(1, OutContext); const MCExpr *One = MCConstantExpr::create(1, OutContext);
const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext); const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Sub)); TmpInst.addOperand(
MCOperand::createExpr(HexagonMCExpr::Create(Sub, OutContext)));
MappedInst = TmpInst; MappedInst = TmpInst;
return; return;
} }
@ -470,10 +476,10 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
bool Success = MO.getExpr()->evaluateAsAbsolute(Imm); bool Success = MO.getExpr()->evaluateAsAbsolute(Imm);
if (Success && Imm < 0) { if (Success && Imm < 0) {
const MCExpr *MOne = MCConstantExpr::create(-1, OutContext); const MCExpr *MOne = MCConstantExpr::create(-1, OutContext);
TmpInst.addOperand(MCOperand::createExpr(MOne)); TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::Create(MOne, OutContext)));
} else { } else {
const MCExpr *Zero = MCConstantExpr::create(0, OutContext); const MCExpr *Zero = MCConstantExpr::create(0, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Zero)); TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::Create(Zero, OutContext)));
} }
TmpInst.addOperand(MO); TmpInst.addOperand(MO);
MappedInst = TmpInst; MappedInst = TmpInst;
@ -523,12 +529,13 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCExpr const *Expr = Imm.getExpr(); MCExpr const *Expr = Imm.getExpr();
int64_t Value; int64_t Value;
bool Success = Expr->evaluateAsAbsolute(Value); bool Success = Expr->evaluateAsAbsolute(Value);
assert(Success);(void)Success; assert(Success);
(void)Success;
if (Value < 0 && Value > -256) { if (Value < 0 && Value > -256) {
MappedInst.setOpcode(Hexagon::M2_mpysin); MappedInst.setOpcode(Hexagon::M2_mpysin);
Imm.setExpr(MCUnaryExpr::createMinus(Expr, OutContext)); Imm.setExpr(HexagonMCExpr::Create(
} MCUnaryExpr::createMinus(Expr, OutContext), OutContext));
else } else
MappedInst.setOpcode(Hexagon::M2_mpysip); MappedInst.setOpcode(Hexagon::M2_mpysip);
return; return;
} }

View File

@ -66,7 +66,7 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
ME = MCBinaryExpr::createAdd(ME, MCConstantExpr::create(MO.getOffset(), MC), ME = MCBinaryExpr::createAdd(ME, MCConstantExpr::create(MO.getOffset(), MC),
MC); MC);
return MCOperand::createExpr(ME); return MCOperand::createExpr(HexagonMCExpr::Create(ME, MC));
} }
// Create an MCInst from a MachineInstr // Create an MCInst from a MachineInstr
@ -106,18 +106,18 @@ void llvm::HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
// FP immediates are used only when setting GPRs, so they may be dealt // FP immediates are used only when setting GPRs, so they may be dealt
// with like regular immediates from this point on. // with like regular immediates from this point on.
MCO = MCOperand::createExpr( MCO = MCOperand::createExpr(
MCConstantExpr::create(*Val.bitcastToAPInt().getRawData(), HexagonMCExpr::Create(MCConstantExpr::create(*Val.bitcastToAPInt().getRawData(),
AP.OutContext)); AP.OutContext), AP.OutContext));
break; break;
} }
case MachineOperand::MO_Immediate: case MachineOperand::MO_Immediate:
MCO = MCOperand::createExpr( MCO = MCOperand::createExpr(
MCConstantExpr::create(MO.getImm(), AP.OutContext)); HexagonMCExpr::Create(MCConstantExpr::create(MO.getImm(), AP.OutContext), AP.OutContext));
break; break;
case MachineOperand::MO_MachineBasicBlock: case MachineOperand::MO_MachineBasicBlock:
MCO = MCOperand::createExpr MCO = MCOperand::createExpr
(MCSymbolRefExpr::create(MO.getMBB()->getSymbol(), (HexagonMCExpr::Create(MCSymbolRefExpr::create(MO.getMBB()->getSymbol(),
AP.OutContext)); AP.OutContext), AP.OutContext));
break; break;
case MachineOperand::MO_GlobalAddress: case MachineOperand::MO_GlobalAddress:
MCO = GetSymbolRef(MO, AP.getSymbol(MO.getGlobal()), AP); MCO = GetSymbolRef(MO, AP.getSymbol(MO.getGlobal()), AP);

View File

@ -418,9 +418,8 @@ unsigned HexagonMCCodeEmitter::getExprOpValue(const MCInst &MI,
const MCSubtargetInfo &STI) const const MCSubtargetInfo &STI) const
{ {
auto Wrapper = dyn_cast<HexagonNoExtendOperand>(ME); if (isa<HexagonMCExpr>(ME))
if (Wrapper != nullptr) ME = &HexagonMCInstrInfo::getExpr(*ME);
ME = Wrapper->getExpr();
int64_t Value; int64_t Value;
if (ME->evaluateAsAbsolute(Value)) if (ME->evaluateAsAbsolute(Value))
return Value; return Value;

View File

@ -10,6 +10,7 @@
#include "HexagonMCExpr.h" #include "HexagonMCExpr.h"
#include "llvm/MC/MCContext.h" #include "llvm/MC/MCContext.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCValue.h" #include "llvm/MC/MCValue.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
@ -17,33 +18,47 @@ using namespace llvm;
#define DEBUG_TYPE "hexagon-mcexpr" #define DEBUG_TYPE "hexagon-mcexpr"
HexagonNoExtendOperand *HexagonNoExtendOperand::Create(MCExpr const *Expr, HexagonMCExpr *HexagonMCExpr::Create(MCExpr const *Expr, MCContext &Ctx) {
MCContext &Ctx) { return new (Ctx) HexagonMCExpr(Expr);
return new (Ctx) HexagonNoExtendOperand(Expr);
} }
bool HexagonNoExtendOperand::evaluateAsRelocatableImpl( bool HexagonMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
MCValue &Res, MCAsmLayout const *Layout, MCFixup const *Fixup) const { MCAsmLayout const *Layout,
MCFixup const *Fixup) const {
return Expr->evaluateAsRelocatable(Res, Layout, Fixup); return Expr->evaluateAsRelocatable(Res, Layout, Fixup);
} }
void HexagonNoExtendOperand::visitUsedExpr(MCStreamer &Streamer) const {} void HexagonMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
Streamer.visitUsedExpr(*Expr);
}
MCFragment *llvm::HexagonNoExtendOperand::findAssociatedFragment() const { MCFragment *llvm::HexagonMCExpr::findAssociatedFragment() const {
return Expr->findAssociatedFragment(); return Expr->findAssociatedFragment();
} }
void HexagonNoExtendOperand::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {} void HexagonMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {}
MCExpr const *HexagonNoExtendOperand::getExpr() const { return Expr; } MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
bool HexagonNoExtendOperand::classof(MCExpr const *E) { void HexagonMCExpr::setMustExtend(bool Val) {
assert((!Val || !MustNotExtend) && "Extension contradiction");
MustExtend = Val;
}
bool HexagonMCExpr::mustExtend() const { return MustExtend; }
void HexagonMCExpr::setMustNotExtend(bool Val) {
assert((!Val || !MustExtend) && "Extension contradiction");
MustNotExtend = Val;
}
bool HexagonMCExpr::mustNotExtend() const { return MustNotExtend; }
bool HexagonMCExpr::classof(MCExpr const *E) {
return E->getKind() == MCExpr::Target; return E->getKind() == MCExpr::Target;
} }
HexagonNoExtendOperand::HexagonNoExtendOperand(MCExpr const *Expr) HexagonMCExpr::HexagonMCExpr(MCExpr const *Expr)
: Expr(Expr) {} : Expr(Expr), MustNotExtend(false), MustExtend(false) {}
void HexagonNoExtendOperand::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { void HexagonMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
Expr->print(OS, MAI); Expr->print(OS, MAI);
} }

View File

@ -14,9 +14,9 @@
namespace llvm { namespace llvm {
class MCInst; class MCInst;
class HexagonNoExtendOperand : public MCTargetExpr { class HexagonMCExpr : public MCTargetExpr {
public: public:
static HexagonNoExtendOperand *Create(MCExpr const *Expr, MCContext &Ctx); static HexagonMCExpr *Create(MCExpr const *Expr, MCContext &Ctx);
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
const MCFixup *Fixup) const override; const MCFixup *Fixup) const override;
@ -25,10 +25,16 @@ public:
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override; void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
static bool classof(MCExpr const *E); static bool classof(MCExpr const *E);
MCExpr const *getExpr() const; MCExpr const *getExpr() const;
void setMustExtend(bool Val = true);
bool mustExtend() const;
void setMustNotExtend(bool Val = true);
bool mustNotExtend() const;
private: private:
HexagonNoExtendOperand(MCExpr const *Expr); HexagonMCExpr(MCExpr const *Expr);
MCExpr const *Expr; MCExpr const *Expr;
bool MustNotExtend;
bool MustExtend;
}; };
} // end namespace llvm } // end namespace llvm

View File

@ -99,7 +99,8 @@ void HexagonMCInstrInfo::clampExtended(MCInstrInfo const &MCII,
int64_t Value; int64_t Value;
if (exOp.getExpr()->evaluateAsAbsolute(Value)) { if (exOp.getExpr()->evaluateAsAbsolute(Value)) {
unsigned Shift = HexagonMCInstrInfo::getExtentAlignment(MCII, MCI); unsigned Shift = HexagonMCInstrInfo::getExtentAlignment(MCII, MCI);
exOp.setExpr(MCConstantExpr::create((Value & 0x3f) << Shift, Context)); exOp.setExpr(HexagonMCExpr::Create(
MCConstantExpr::create((Value & 0x3f) << Shift, Context), Context));
} }
} }
@ -190,6 +191,11 @@ MCInstrDesc const &HexagonMCInstrInfo::getDesc(MCInstrInfo const &MCII,
return (MCII.get(MCI.getOpcode())); return (MCII.get(MCI.getOpcode()));
} }
MCExpr const &HexagonMCInstrInfo::getExpr(MCExpr const &Expr) {
HexagonMCExpr const &HExpr = *llvm::cast<HexagonMCExpr>(&Expr);
return *HExpr.getExpr();
}
unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII, unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII,
MCInst const &MCI) { MCInst const &MCI) {
const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags; const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
@ -575,6 +581,25 @@ int64_t HexagonMCInstrInfo::minConstant(MCInst const &MCI, size_t Index) {
return Value; return Value;
} }
void HexagonMCInstrInfo::setMustExtend(MCExpr &Expr, bool Val) {
HexagonMCExpr &HExpr = *llvm::cast<HexagonMCExpr>(&Expr);
HExpr.setMustExtend(Val);
}
bool HexagonMCInstrInfo::mustExtend(MCExpr const &Expr) {
HexagonMCExpr const &HExpr = *llvm::cast<HexagonMCExpr>(&Expr);
return HExpr.mustExtend();
}
void HexagonMCInstrInfo::setMustNotExtend(MCExpr const &Expr, bool Val) {
HexagonMCExpr &HExpr =
const_cast<HexagonMCExpr &>(*llvm::cast<HexagonMCExpr>(&Expr));
HExpr.setMustNotExtend(Val);
}
bool HexagonMCInstrInfo::mustNotExtend(MCExpr const &Expr) {
HexagonMCExpr const &HExpr = *llvm::cast<HexagonMCExpr>(&Expr);
return HExpr.mustNotExtend();
}
void HexagonMCInstrInfo::padEndloop(MCContext &Context, MCInst &MCB) { void HexagonMCInstrInfo::padEndloop(MCContext &Context, MCInst &MCB) {
MCInst Nop; MCInst Nop;
Nop.setOpcode(Hexagon::A2_nop); Nop.setOpcode(Hexagon::A2_nop);

View File

@ -108,6 +108,8 @@ unsigned getDuplexCandidateGroup(MCInst const &MI);
SmallVector<DuplexCandidate, 8> getDuplexPossibilties(MCInstrInfo const &MCII, SmallVector<DuplexCandidate, 8> getDuplexPossibilties(MCInstrInfo const &MCII,
MCInst const &MCB); MCInst const &MCB);
MCExpr const &getExpr(MCExpr const &Expr);
// Return the index of the extendable operand // Return the index of the extendable operand
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI); unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI);
@ -261,6 +263,8 @@ bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI);
/// Return whether the insn can be packaged only with an A-type insn in slot #1. /// Return whether the insn can be packaged only with an A-type insn in slot #1.
bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI); bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI);
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI); bool isVector(MCInstrInfo const &MCII, MCInst const &MCI);
bool mustExtend(MCExpr const &Expr);
bool mustNotExtend(MCExpr const &Expr);
// Pad the bundle with nops to satisfy endloop requirements // Pad the bundle with nops to satisfy endloop requirements
void padEndloop(MCContext &Context, MCInst &MCI); void padEndloop(MCContext &Context, MCInst &MCI);
@ -274,6 +278,8 @@ void replaceDuplex(MCContext &Context, MCInst &MCB, DuplexCandidate Candidate);
void setInnerLoop(MCInst &MCI); void setInnerLoop(MCInst &MCI);
void setMemReorderDisabled(MCInst &MCI); void setMemReorderDisabled(MCInst &MCI);
void setMemStoreReorderEnabled(MCInst &MCI); void setMemStoreReorderEnabled(MCInst &MCI);
void setMustExtend(MCExpr &Expr, bool Val = true);
void setMustNotExtend(MCExpr const &Expr, bool Val = true);
// Marks a bundle as endloop1 // Marks a bundle as endloop1
void setOuterLoop(MCInst &MCI); void setOuterLoop(MCInst &MCI);