[llvm] r253634 - [WebAssemby] Enforce FIFO ordering for instructions using stackified registers.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 19 18:19:12 PST 2015
Author: djg
Date: Thu Nov 19 20:19:12 2015
New Revision: 253634
URL: http://llvm.org/viewvc/llvm-project?rev=253634&view=rev
Log:
[WebAssemby] Enforce FIFO ordering for instructions using stackified registers.
Modified:
llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp?rev=253634&r1=253633&r2=253634&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp Thu Nov 19 20:19:12 2015
@@ -58,6 +58,18 @@ FunctionPass *llvm::createWebAssemblyReg
return new WebAssemblyRegStackify();
}
+// Decorate the given instruction with implicit operands that enforce the
+// expression stack ordering constraints.
+static void ImposeStackOrdering(MachineInstr *MI) {
+ // Read and write the opaque EXPR_STACK register.
+ MI->addOperand(MachineOperand::CreateReg(WebAssembly::EXPR_STACK,
+ /*isDef=*/true,
+ /*isImp=*/true));
+ MI->addOperand(MachineOperand::CreateReg(WebAssembly::EXPR_STACK,
+ /*isDef=*/false,
+ /*isImp=*/true));
+}
+
bool WebAssemblyRegStackify::runOnMachineFunction(MachineFunction &MF) {
DEBUG(dbgs() << "********** Register Stackifying **********\n"
"********** Function: "
@@ -80,6 +92,7 @@ bool WebAssemblyRegStackify::runOnMachin
// Iterate through the inputs in reverse order, since we'll be pulling
// operands off the stack in FIFO order.
+ bool AnyStackified = false;
for (MachineOperand &Op : reverse(Insert->uses())) {
// We're only interested in explicit virtual register operands.
if (!Op.isReg() || Op.isImplicit())
@@ -128,11 +141,13 @@ bool WebAssemblyRegStackify::runOnMachin
continue;
Changed = true;
+ AnyStackified = true;
if (OneUse) {
// Move the def down and nest it in the current instruction.
MBB.insert(MachineBasicBlock::instr_iterator(Insert),
Def->removeFromParent());
MFI.stackifyVReg(Reg);
+ ImposeStackOrdering(Def);
Insert = Def;
} else {
// Clone the def down and nest it in the current instruction.
@@ -145,11 +160,22 @@ bool WebAssemblyRegStackify::runOnMachin
Clone->getOperand(0).setReg(NewReg);
MBB.insert(MachineBasicBlock::instr_iterator(Insert), Clone);
MFI.stackifyVReg(Reg);
+ ImposeStackOrdering(Clone);
Insert = Clone;
}
}
+ if (AnyStackified)
+ ImposeStackOrdering(&MI);
}
}
+ // If we used EXPR_STACK anywhere, add it to the live-in sets everywhere
+ // so that it never looks like a use-before-def.
+ if (Changed) {
+ MF.getRegInfo().addLiveIn(WebAssembly::EXPR_STACK);
+ for (MachineBasicBlock &MBB : MF)
+ MBB.addLiveIn(WebAssembly::EXPR_STACK);
+ }
+
return Changed;
}
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td?rev=253634&r1=253633&r2=253634&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyRegisterInfo.td Thu Nov 19 20:19:12 2015
@@ -39,6 +39,10 @@ def SP64 : WebAssemblyReg<"%SP64">;
def F32_0 : WebAssemblyReg<"%f32.0">;
def F64_0 : WebAssemblyReg<"%f64.0">;
+// The expression stack "register". This is an opaque entity which serves to
+// order uses and defs that must remain in FIFO order.
+def EXPR_STACK : WebAssemblyReg<"STACK">;
+
//===----------------------------------------------------------------------===//
// Register classes
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list