Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/backend/pass/emit/x86/x86_emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ namespace rat {

MachineInstr& X86LowerPass::put(
X86Op op, List<MachineOperand> defs, List<MachineOperand> uses, I64 imm, I64 imm2) {
MachineInstr m;
MachineInstr& m = mb->insts.emplace_back();
m.op = (MachineOpcode)op;
m.regClass = x86OpInfo(op).cls;
m.defs = std::move(defs);
m.uses = std::move(uses);
m.imm = imm;
m.imm2 = imm2;
mb->insts.push_back(std::move(m));
return mb->insts.back();
return m;
}

// data movement
Expand Down
27 changes: 17 additions & 10 deletions src/backend/pass/emit/x86/x86_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ namespace rat {

B32 isBlockRef(const MachineOperand& o) { return o.kind == MachineOperand::Kind::Block; }

B32 isBranch(const MachineInstr& in) {
X86Op op = (X86Op)in.op;
return op == X86Op::Jmp || op == X86Op::Br || op == X86Op::SwitchJump;
}

I32 resolveJump(const MachineFunc& mf, I32 id) {
U32 hops = 0;
while(hops++ < 16) {
Expand All @@ -80,14 +85,15 @@ namespace rat {
if(b.id < 0)
continue;
for(MachineInstr& in : b.insts)
for(MachineOperand& u : in.uses)
if(isBlockRef(u)) {
I32 r = resolveJump(mf, u.block);
if(r != u.block) {
u.block = r;
++changed;
if(isBranch(in))
for(MachineOperand& u : in.uses)
if(isBlockRef(u)) {
I32 r = resolveJump(mf, u.block);
if(r != u.block) {
u.block = r;
++changed;
}
}
}
}
return changed;
}
Expand Down Expand Up @@ -124,9 +130,10 @@ namespace rat {
continue;
blockAt[(U32)b.id] = i;
for(const MachineInstr& in : b.insts)
for(const MachineOperand& u : in.uses)
if(isBlockRef(u))
succ[(U32)b.id].push_back(u.block);
if(isBranch(in))
for(const MachineOperand& u : in.uses)
if(isBlockRef(u))
succ[(U32)b.id].push_back(u.block);
}

I32 entry = -1;
Expand Down
2 changes: 2 additions & 0 deletions src/backend/pass/emit/x86/x86_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
namespace rat {
struct MachineBlock;
struct MachineFunc;
struct MachineInstr;
struct MachineOperand;

namespace detail {
B32 isPureTestBlock(const MachineBlock& b);
U32 duplicateTestBlocks(MachineFunc& mf);
B32 isBlockRef(const MachineOperand& o);
B32 isBranch(const MachineInstr& in);
I32 resolveJump(const MachineFunc& mf, I32 id);
U32 forwardJumpChains(MachineFunc& mf);
List<B32> reachableFrom(const List<List<I32>>& succ, I32 entry);
Expand Down
1 change: 1 addition & 0 deletions src/backend/pass/emit/x86/x86_lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ namespace rat {
MachineBlock& block = out->blocks[b];
block.id = b;
block.loopDepth = sched->block(b).loopDepth;
block.insts.reserve(sched->block(b).nodes.size() * 2 + 4);
mb = &block;
if(i == 0)
emitPrologue();
Expand Down
Loading
Loading