aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp')
-rw-r--r--lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp92
1 files changed, 61 insertions, 31 deletions
diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
index 30a811a36406..5fe638a9996b 100644
--- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
+++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCInstrInfo.cpp
@@ -22,6 +22,49 @@
#include "llvm/MC/MCSubtargetInfo.h"
namespace llvm {
+
+Hexagon::PacketIterator::PacketIterator(MCInstrInfo const &MCII,
+ MCInst const &Inst)
+ : MCII(MCII), BundleCurrent(Inst.begin() +
+ HexagonMCInstrInfo::bundleInstructionsOffset),
+ BundleEnd(Inst.end()), DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
+
+Hexagon::PacketIterator::PacketIterator(MCInstrInfo const &MCII,
+ MCInst const &Inst, std::nullptr_t)
+ : MCII(MCII), BundleCurrent(Inst.end()), BundleEnd(Inst.end()),
+ DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
+
+Hexagon::PacketIterator &Hexagon::PacketIterator::operator++() {
+ if (DuplexCurrent != DuplexEnd) {
+ ++DuplexCurrent;
+ if (DuplexCurrent == DuplexEnd) {
+ DuplexCurrent = BundleEnd;
+ DuplexEnd = BundleEnd;
+ }
+ return *this;
+ }
+ ++BundleCurrent;
+ if (BundleCurrent != BundleEnd) {
+ MCInst const &Inst = *BundleCurrent->getInst();
+ if (HexagonMCInstrInfo::isDuplex(MCII, Inst)) {
+ DuplexCurrent = Inst.begin();
+ DuplexEnd = Inst.end();
+ }
+ }
+ return *this;
+}
+
+MCInst const &Hexagon::PacketIterator::operator*() const {
+ if (DuplexCurrent != DuplexEnd)
+ return *DuplexCurrent->getInst();
+ return *BundleCurrent->getInst();
+}
+
+bool Hexagon::PacketIterator::operator==(PacketIterator const &Other) const {
+ return BundleCurrent == Other.BundleCurrent && BundleEnd == Other.BundleEnd &&
+ DuplexCurrent == Other.DuplexCurrent && DuplexEnd == Other.DuplexEnd;
+}
+
void HexagonMCInstrInfo::addConstant(MCInst &MI, uint64_t Value,
MCContext &Context) {
MI.addOperand(MCOperand::createExpr(MCConstantExpr::create(Value, Context)));
@@ -41,6 +84,14 @@ void HexagonMCInstrInfo::addConstExtender(MCContext &Context,
MCB.addOperand(MCOperand::createInst(XMCI));
}
+iterator_range<Hexagon::PacketIterator>
+HexagonMCInstrInfo::bundleInstructions(MCInstrInfo const &MCII,
+ MCInst const &MCI) {
+ assert(isBundle(MCI));
+ return make_range(Hexagon::PacketIterator(MCII, MCI),
+ Hexagon::PacketIterator(MCII, MCI, nullptr));
+}
+
iterator_range<MCInst::const_iterator>
HexagonMCInstrInfo::bundleInstructions(MCInst const &MCI) {
assert(isBundle(MCI));
@@ -292,7 +343,7 @@ int HexagonMCInstrInfo::getMinValue(MCInstrInfo const &MCII,
}
StringRef HexagonMCInstrInfo::getName(MCInstrInfo const &MCII,
- MCInst const &MCI) {
+ MCInst const &MCI) {
return MCII.getName(MCI.getOpcode());
}
@@ -339,25 +390,6 @@ unsigned HexagonMCInstrInfo::getType(MCInstrInfo const &MCII,
return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
}
-int HexagonMCInstrInfo::getSubTarget(MCInstrInfo const &MCII,
- MCInst const &MCI) {
- const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
-
- HexagonII::SubTarget Target = static_cast<HexagonII::SubTarget>(
- (F >> HexagonII::validSubTargetPos) & HexagonII::validSubTargetMask);
-
- switch (Target) {
- default:
- return Hexagon::ArchV4;
- case HexagonII::HasV5SubT:
- return Hexagon::ArchV5;
- case HexagonII::HasV55SubT:
- return Hexagon::ArchV55;
- case HexagonII::HasV60SubT:
- return Hexagon::ArchV60;
- }
-}
-
/// Return the slots this instruction can execute out of
unsigned HexagonMCInstrInfo::getUnits(MCInstrInfo const &MCII,
MCSubtargetInfo const &STI,
@@ -397,9 +429,8 @@ bool HexagonMCInstrInfo::hasDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
if (!HexagonMCInstrInfo::isBundle(MCI))
return false;
- for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
- auto MI = I.getInst();
- if (HexagonMCInstrInfo::isDuplex(MCII, *MI))
+ for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCI)) {
+ if (HexagonMCInstrInfo::isDuplex(MCII, I))
return true;
}
@@ -410,13 +441,12 @@ bool HexagonMCInstrInfo::hasExtenderForIndex(MCInst const &MCB, size_t Index) {
return extenderForIndex(MCB, Index) != nullptr;
}
-bool HexagonMCInstrInfo::hasImmExt(MCInst const &MCI) {
+bool HexagonMCInstrInfo::hasImmExt( MCInst const &MCI) {
if (!HexagonMCInstrInfo::isBundle(MCI))
return false;
for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
- auto MI = I.getInst();
- if (isImmext(*MI))
+ if (isImmext(*I.getInst()))
return true;
}
@@ -737,16 +767,16 @@ bool HexagonMCInstrInfo::mustNotExtend(MCExpr const &Expr) {
HexagonMCExpr const &HExpr = cast<HexagonMCExpr>(Expr);
return HExpr.mustNotExtend();
}
-void HexagonMCInstrInfo::setS23_2_reloc(MCExpr const &Expr, bool Val) {
+void HexagonMCInstrInfo::setS27_2_reloc(MCExpr const &Expr, bool Val) {
HexagonMCExpr &HExpr =
const_cast<HexagonMCExpr &>(*llvm::cast<HexagonMCExpr>(&Expr));
- HExpr.setS23_2_reloc(Val);
+ HExpr.setS27_2_reloc(Val);
}
-bool HexagonMCInstrInfo::s23_2_reloc(MCExpr const &Expr) {
+bool HexagonMCInstrInfo::s27_2_reloc(MCExpr const &Expr) {
HexagonMCExpr const *HExpr = llvm::dyn_cast<HexagonMCExpr>(&Expr);
if (!HExpr)
return false;
- return HExpr->s23_2_reloc();
+ return HExpr->s27_2_reloc();
}
void HexagonMCInstrInfo::padEndloop(MCInst &MCB, MCContext &Context) {
@@ -818,4 +848,4 @@ unsigned HexagonMCInstrInfo::SubregisterBit(unsigned Consumer,
return 0x1;
return 0;
}
-}
+} // namespace llvm