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

View File

@ -297,8 +297,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCOperand &Reg = MappedInst.getOperand(0);
TmpInst.setOpcode(Hexagon::L2_loadrigp);
TmpInst.addOperand(Reg);
TmpInst.addOperand(MCOperand::createExpr(
MCSymbolRefExpr::create(Sym, OutContext)));
TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::Create(
MCSymbolRefExpr::create(Sym, OutContext), OutContext)));
MappedInst = TmpInst;
}
break;
@ -367,7 +367,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
int64_t Imm;
MCExpr const *Expr = MO.getExpr();
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;
if (Imm == 0) {
TmpInst.setOpcode(Hexagon::S2_vsathub);
@ -381,7 +382,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
TmpInst.addOperand(MappedInst.getOperand(1));
const MCExpr *One = MCConstantExpr::create(1, OutContext);
const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Sub));
TmpInst.addOperand(
MCOperand::createExpr(HexagonMCExpr::Create(Sub, OutContext)));
MappedInst = TmpInst;
return;
}
@ -391,7 +393,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCExpr const *Expr = MO2.getExpr();
int64_t 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;
if (Imm == 0) {
TmpInst.setOpcode(Hexagon::A2_combinew);
@ -414,7 +417,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
TmpInst.addOperand(MappedInst.getOperand(1));
const MCExpr *One = MCConstantExpr::create(1, OutContext);
const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Sub));
TmpInst.addOperand(
MCOperand::createExpr(HexagonMCExpr::Create(Sub, OutContext)));
MappedInst = TmpInst;
return;
}
@ -424,7 +428,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCExpr const *Expr = MO.getExpr();
int64_t 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;
if (Imm == 0) {
TmpInst.setOpcode(Hexagon::A2_tfr);
@ -438,7 +443,8 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
TmpInst.addOperand(MappedInst.getOperand(1));
const MCExpr *One = MCConstantExpr::create(1, OutContext);
const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Sub));
TmpInst.addOperand(
MCOperand::createExpr(HexagonMCExpr::Create(Sub, OutContext)));
MappedInst = TmpInst;
return;
}
@ -470,10 +476,10 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
bool Success = MO.getExpr()->evaluateAsAbsolute(Imm);
if (Success && Imm < 0) {
const MCExpr *MOne = MCConstantExpr::create(-1, OutContext);
TmpInst.addOperand(MCOperand::createExpr(MOne));
TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::Create(MOne, OutContext)));
} else {
const MCExpr *Zero = MCConstantExpr::create(0, OutContext);
TmpInst.addOperand(MCOperand::createExpr(Zero));
TmpInst.addOperand(MCOperand::createExpr(HexagonMCExpr::Create(Zero, OutContext)));
}
TmpInst.addOperand(MO);
MappedInst = TmpInst;
@ -523,12 +529,13 @@ void HexagonAsmPrinter::HexagonProcessInstruction(MCInst &Inst,
MCExpr const *Expr = Imm.getExpr();
int64_t Value;
bool Success = Expr->evaluateAsAbsolute(Value);
assert(Success);(void)Success;
assert(Success);
(void)Success;
if (Value < 0 && Value > -256) {
MappedInst.setOpcode(Hexagon::M2_mpysin);
Imm.setExpr(MCUnaryExpr::createMinus(Expr, OutContext));
}
else
Imm.setExpr(HexagonMCExpr::Create(
MCUnaryExpr::createMinus(Expr, OutContext), OutContext));
} else
MappedInst.setOpcode(Hexagon::M2_mpysip);
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),
MC);
return MCOperand::createExpr(ME);
return MCOperand::createExpr(HexagonMCExpr::Create(ME, MC));
}
// 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
// with like regular immediates from this point on.
MCO = MCOperand::createExpr(
MCConstantExpr::create(*Val.bitcastToAPInt().getRawData(),
AP.OutContext));
HexagonMCExpr::Create(MCConstantExpr::create(*Val.bitcastToAPInt().getRawData(),
AP.OutContext), AP.OutContext));
break;
}
case MachineOperand::MO_Immediate:
MCO = MCOperand::createExpr(
MCConstantExpr::create(MO.getImm(), AP.OutContext));
HexagonMCExpr::Create(MCConstantExpr::create(MO.getImm(), AP.OutContext), AP.OutContext));
break;
case MachineOperand::MO_MachineBasicBlock:
MCO = MCOperand::createExpr
(MCSymbolRefExpr::create(MO.getMBB()->getSymbol(),
AP.OutContext));
(HexagonMCExpr::Create(MCSymbolRefExpr::create(MO.getMBB()->getSymbol(),
AP.OutContext), AP.OutContext));
break;
case MachineOperand::MO_GlobalAddress:
MCO = GetSymbolRef(MO, AP.getSymbol(MO.getGlobal()), AP);

View File

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

View File

@ -10,6 +10,7 @@
#include "HexagonMCExpr.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/raw_ostream.h"
@ -17,33 +18,47 @@ using namespace llvm;
#define DEBUG_TYPE "hexagon-mcexpr"
HexagonNoExtendOperand *HexagonNoExtendOperand::Create(MCExpr const *Expr,
MCContext &Ctx) {
return new (Ctx) HexagonNoExtendOperand(Expr);
HexagonMCExpr *HexagonMCExpr::Create(MCExpr const *Expr, MCContext &Ctx) {
return new (Ctx) HexagonMCExpr(Expr);
}
bool HexagonNoExtendOperand::evaluateAsRelocatableImpl(
MCValue &Res, MCAsmLayout const *Layout, MCFixup const *Fixup) const {
bool HexagonMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
MCAsmLayout const *Layout,
MCFixup const *Fixup) const {
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();
}
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;
}
HexagonNoExtendOperand::HexagonNoExtendOperand(MCExpr const *Expr)
: Expr(Expr) {}
HexagonMCExpr::HexagonMCExpr(MCExpr const *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);
}

View File

@ -14,9 +14,9 @@
namespace llvm {
class MCInst;
class HexagonNoExtendOperand : public MCTargetExpr {
class HexagonMCExpr : public MCTargetExpr {
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;
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
const MCFixup *Fixup) const override;
@ -25,10 +25,16 @@ public:
void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
static bool classof(MCExpr const *E);
MCExpr const *getExpr() const;
void setMustExtend(bool Val = true);
bool mustExtend() const;
void setMustNotExtend(bool Val = true);
bool mustNotExtend() const;
private:
HexagonNoExtendOperand(MCExpr const *Expr);
HexagonMCExpr(MCExpr const *Expr);
MCExpr const *Expr;
bool MustNotExtend;
bool MustExtend;
};
} // end namespace llvm

View File

@ -99,7 +99,8 @@ void HexagonMCInstrInfo::clampExtended(MCInstrInfo const &MCII,
int64_t Value;
if (exOp.getExpr()->evaluateAsAbsolute(Value)) {
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()));
}
MCExpr const &HexagonMCInstrInfo::getExpr(MCExpr const &Expr) {
HexagonMCExpr const &HExpr = *llvm::cast<HexagonMCExpr>(&Expr);
return *HExpr.getExpr();
}
unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII,
MCInst const &MCI) {
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;
}
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) {
MCInst Nop;
Nop.setOpcode(Hexagon::A2_nop);

View File

@ -108,6 +108,8 @@ unsigned getDuplexCandidateGroup(MCInst const &MI);
SmallVector<DuplexCandidate, 8> getDuplexPossibilties(MCInstrInfo const &MCII,
MCInst const &MCB);
MCExpr const &getExpr(MCExpr const &Expr);
// Return the index of the extendable operand
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.
bool isSoloAin1(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
void padEndloop(MCContext &Context, MCInst &MCI);
@ -274,6 +278,8 @@ void replaceDuplex(MCContext &Context, MCInst &MCB, DuplexCandidate Candidate);
void setInnerLoop(MCInst &MCI);
void setMemReorderDisabled(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
void setOuterLoop(MCInst &MCI);