Modified: trunk/Source/_javascript_Core/b3/air/AirFixObviousSpills.cpp (216026 => 216027)
--- trunk/Source/_javascript_Core/b3/air/AirFixObviousSpills.cpp 2017-05-01 21:15:22 UTC (rev 216026)
+++ trunk/Source/_javascript_Core/b3/air/AirFixObviousSpills.cpp 2017-05-01 21:17:24 UTC (rev 216027)
@@ -105,39 +105,27 @@
}
}
}
-
- void executeInst()
+
+ template<typename Func>
+ void forAllAliases(const Func& func)
{
Inst& inst = m_block->at(m_instIndex);
- if (verbose)
- dataLog(" Executing ", inst, ": ", m_state, "\n");
-
- Inst::forEachDefWithExtraClobberedRegs<Arg>(
- &inst, &inst,
- [&] (const Arg& arg, Arg::Role, Bank, Width) {
- if (verbose)
- dataLog(" Clobbering ", arg, "\n");
- m_state.clobber(arg);
- });
-
switch (inst.kind.opcode) {
case Move:
if (inst.args[0].isSomeImm()) {
if (inst.args[1].isReg())
- m_state.addAlias(RegConst(inst.args[1].reg(), inst.args[0].value()));
+ func(RegConst(inst.args[1].reg(), inst.args[0].value()));
else if (isSpillSlot(inst.args[1]))
- m_state.addAlias(SlotConst(inst.args[1].stackSlot(), inst.args[0].value()));
+ func(SlotConst(inst.args[1].stackSlot(), inst.args[0].value()));
} else if (isSpillSlot(inst.args[0]) && inst.args[1].isReg()) {
if (std::optional<int64_t> constant = m_state.constantFor(inst.args[0]))
- m_state.addAlias(RegConst(inst.args[1].reg(), *constant));
- m_state.addAlias(
- RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::AllBits));
+ func(RegConst(inst.args[1].reg(), *constant));
+ func(RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::AllBits));
} else if (inst.args[0].isReg() && isSpillSlot(inst.args[1])) {
if (std::optional<int64_t> constant = m_state.constantFor(inst.args[0]))
- m_state.addAlias(SlotConst(inst.args[1].stackSlot(), *constant));
- m_state.addAlias(
- RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::AllBits));
+ func(SlotConst(inst.args[1].stackSlot(), *constant));
+ func(RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::AllBits));
}
break;
@@ -144,47 +132,60 @@
case Move32:
if (inst.args[0].isSomeImm()) {
if (inst.args[1].isReg())
- m_state.addAlias(RegConst(inst.args[1].reg(), static_cast<uint32_t>(inst.args[0].value())));
+ func(RegConst(inst.args[1].reg(), static_cast<uint32_t>(inst.args[0].value())));
else if (isSpillSlot(inst.args[1]))
- m_state.addAlias(SlotConst(inst.args[1].stackSlot(), static_cast<uint32_t>(inst.args[0].value())));
+ func(SlotConst(inst.args[1].stackSlot(), static_cast<uint32_t>(inst.args[0].value())));
} else if (isSpillSlot(inst.args[0]) && inst.args[1].isReg()) {
if (std::optional<int64_t> constant = m_state.constantFor(inst.args[0]))
- m_state.addAlias(RegConst(inst.args[1].reg(), static_cast<uint32_t>(*constant)));
- m_state.addAlias(
- RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::ZExt32));
+ func(RegConst(inst.args[1].reg(), static_cast<uint32_t>(*constant)));
+ func(RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::ZExt32));
} else if (inst.args[0].isReg() && isSpillSlot(inst.args[1])) {
if (std::optional<int64_t> constant = m_state.constantFor(inst.args[0]))
- m_state.addAlias(SlotConst(inst.args[1].stackSlot(), static_cast<int32_t>(*constant)));
- m_state.addAlias(
- RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::Match32));
+ func(SlotConst(inst.args[1].stackSlot(), static_cast<int32_t>(*constant)));
+ func(RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::Match32));
}
break;
case MoveFloat:
- if (isSpillSlot(inst.args[0]) && inst.args[1].isReg()) {
- m_state.addAlias(
- RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::Match32));
- } else if (inst.args[0].isReg() && isSpillSlot(inst.args[1])) {
- m_state.addAlias(
- RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::Match32));
- }
+ if (isSpillSlot(inst.args[0]) && inst.args[1].isReg())
+ func(RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::Match32));
+ else if (inst.args[0].isReg() && isSpillSlot(inst.args[1]))
+ func(RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::Match32));
break;
case MoveDouble:
- if (isSpillSlot(inst.args[0]) && inst.args[1].isReg()) {
- m_state.addAlias(
- RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::AllBits));
- } else if (inst.args[0].isReg() && isSpillSlot(inst.args[1])) {
- m_state.addAlias(
- RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::AllBits));
- }
+ if (isSpillSlot(inst.args[0]) && inst.args[1].isReg())
+ func(RegSlot(inst.args[1].reg(), inst.args[0].stackSlot(), RegSlot::AllBits));
+ else if (inst.args[0].isReg() && isSpillSlot(inst.args[1]))
+ func(RegSlot(inst.args[0].reg(), inst.args[1].stackSlot(), RegSlot::AllBits));
break;
-
+
default:
break;
}
}
+ void executeInst()
+ {
+ Inst& inst = m_block->at(m_instIndex);
+
+ if (verbose)
+ dataLog(" Executing ", inst, ": ", m_state, "\n");
+
+ Inst::forEachDefWithExtraClobberedRegs<Arg>(
+ &inst, &inst,
+ [&] (const Arg& arg, Arg::Role, Bank, Width) {
+ if (verbose)
+ dataLog(" Clobbering ", arg, "\n");
+ m_state.clobber(arg);
+ });
+
+ forAllAliases(
+ [&] (const auto& alias) {
+ m_state.addAlias(alias);
+ });
+ }
+
void fixInst()
{
Inst& inst = m_block->at(m_instIndex);
@@ -192,6 +193,17 @@
if (verbose)
dataLog("Fixing inst ", inst, ": ", m_state, "\n");
+ // Check if alias analysis says that this is unnecessary.
+ bool shouldLive = true;
+ forAllAliases(
+ [&] (const auto& alias) {
+ shouldLive &= !m_state.contains(alias);
+ });
+ if (!shouldLive) {
+ inst = Inst();
+ return;
+ }
+
// First handle some special instructions.
switch (inst.kind.opcode) {
case Move: {
@@ -227,6 +239,10 @@
default:
break;
}
+
+ // FIXME: This code should be taught how to simplify the spill-to-spill move
+ // instruction. Basically it needs to know to remove the scratch arg.
+ // https://bugs.webkit.org/show_bug.cgi?id=171133
// Create a copy in case we invalidate the instruction. That doesn't happen often.
Inst instCopy = inst;
@@ -316,6 +332,12 @@
{
return !!reg;
}
+
+ bool operator==(const RegConst& other) const
+ {
+ return reg == other.reg
+ && constant == other.constant;
+ }
void dump(PrintStream& out) const
{
@@ -348,6 +370,13 @@
{
return slot && reg;
}
+
+ bool operator==(const RegSlot& other) const
+ {
+ return slot == other.slot
+ && reg == other.reg
+ && mode == other.mode;
+ }
void dump(PrintStream& out) const
{
@@ -385,6 +414,12 @@
{
return slot;
}
+
+ bool operator==(const SlotConst& other) const
+ {
+ return slot == other.slot
+ && constant == other.constant;
+ }
void dump(PrintStream& out) const
{
@@ -398,16 +433,29 @@
struct State {
void addAlias(const RegConst& newAlias)
{
- regConst.append(newAlias);
+ return regConst.append(newAlias);
}
void addAlias(const RegSlot& newAlias)
{
- regSlot.append(newAlias);
+ return regSlot.append(newAlias);
}
void addAlias(const SlotConst& newAlias)
{
- slotConst.append(newAlias);
+ return slotConst.append(newAlias);
}
+
+ bool contains(const RegConst& alias)
+ {
+ return regConst.contains(alias);
+ }
+ bool contains(const RegSlot& alias)
+ {
+ return regSlot.contains(alias);
+ }
+ bool contains(const SlotConst& alias)
+ {
+ return slotConst.contains(alias);
+ }
const RegConst* getRegConst(Reg reg) const
{