From 2e6ca7df3a25468df9849e234968b0e1efff4493 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 8 Sep 2015 12:39:25 +0000 Subject: [PATCH] [WebAssembly] Enable SSA lowering and other pre-regalloc passes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247008 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../WebAssembly/WebAssemblyTargetMachine.cpp | 22 ++++++++++++++++++- test/CodeGen/WebAssembly/phi.ll | 22 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/WebAssembly/phi.ll diff --git a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 25fe846fc7f..4950e3bbea7 100644 --- a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -164,7 +164,27 @@ bool WebAssemblyPassConfig::addILPOpts() { return true; } void WebAssemblyPassConfig::addPreRegAlloc() {} -void WebAssemblyPassConfig::addRegAllocPasses(bool Optimized) {} +void WebAssemblyPassConfig::addRegAllocPasses(bool Optimized) { + // This is list is derived from the regalloc pass list used in + // addFastRegAlloc and addOptimizedRegAlloc in lib/CodeGen/Passes.cpp. We + // don't run the actual register allocator, but we do run the passes which + // lower SSA form, so after these passes are complete, we have non-SSA + // virtual registers. + + if (Optimized) { + addPass(&ProcessImplicitDefsID); + addPass(&LiveVariablesID); + addPass(&MachineLoopInfoID); + } + + addPass(&PHIEliminationID); + addPass(&TwoAddressInstructionPassID, false); + + if (Optimized) { + addPass(&RegisterCoalescerID); + addPass(&MachineSchedulerID); + } +} void WebAssemblyPassConfig::addPostRegAlloc() { // FIXME: the following passes dislike virtual registers. Disable them for now diff --git a/test/CodeGen/WebAssembly/phi.ll b/test/CodeGen/WebAssembly/phi.ll new file mode 100644 index 00000000000..c217cbf3572 --- /dev/null +++ b/test/CodeGen/WebAssembly/phi.ll @@ -0,0 +1,22 @@ +; RUN: llc < %s -asm-verbose=false | FileCheck %s + +; Test that phis are lowered. + +target datalayout = "e-p:32:32-i64:64-v128:8:128-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +; CHECK-LABEL: test0 +; CHECK: (setlocal [[REG:@.*]] (argument 0)) +; CHECK: (setlocal [[REG]] (sdiv [[REG]] {{.*}})) +; CHECK: (return [[REG]]) +define i32 @test0(i32 %p) { +entry: + %t = icmp slt i32 %p, 0 + br i1 %t, label %true, label %done +true: + %a = sdiv i32 %p, 3 + br label %done +done: + %s = phi i32 [ %a, %true ], [ %p, %entry ] + ret i32 %s +} -- 2.34.1