1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[WebAssembly] Rename StoreResults to MemIntrinsicResults

Summary:
StoreResults pass does not optimize store instructions anymore because
store instructions don't return results values anymore. Now this pass is
used solely for memory intrinsics, so update the pass name accordingly
and fix outdated pass descriptions as well.

This patch does not change any meaningful behavior, but not marked as
NFC because it changes a comment check line in a test case.

Reviewers: dschuff

Subscribers: mgorny, sbc100, jgravelle-google, sunfiish, llvm-commits

Differential Revision: https://reviews.llvm.org/D56093

llvm-svn: 350669
This commit is contained in:
Heejin Ahn 2019-01-08 22:35:18 +00:00
parent 6eb79ffd3a
commit a681962bae
6 changed files with 47 additions and 39 deletions

View File

@ -47,7 +47,7 @@ add_llvm_target(WebAssemblyCodeGen
WebAssemblyRuntimeLibcallSignatures.cpp WebAssemblyRuntimeLibcallSignatures.cpp
WebAssemblySelectionDAGInfo.cpp WebAssemblySelectionDAGInfo.cpp
WebAssemblySetP2AlignOperands.cpp WebAssemblySetP2AlignOperands.cpp
WebAssemblyStoreResults.cpp WebAssemblyMemIntrinsicResults.cpp
WebAssemblySubtarget.cpp WebAssemblySubtarget.cpp
WebAssemblyTargetMachine.cpp WebAssemblyTargetMachine.cpp
WebAssemblyTargetObjectFile.cpp WebAssemblyTargetObjectFile.cpp

View File

@ -94,10 +94,10 @@ WebAssemblyTargetLowering.
//===---------------------------------------------------------------------===// //===---------------------------------------------------------------------===//
Instead of the OptimizeReturned pass, which should consider preserving the Instead of the OptimizeReturned pass, which should consider preserving the
"returned" attribute through to MachineInstrs and extending the StoreResults "returned" attribute through to MachineInstrs and extending the
pass to do this optimization on calls too. That would also let the MemIntrinsicResults pass to do this optimization on calls too. That would also
WebAssemblyPeephole pass clean up dead defs for such calls, as it does for let the WebAssemblyPeephole pass clean up dead defs for such calls, as it does
stores. for stores.
//===---------------------------------------------------------------------===// //===---------------------------------------------------------------------===//

View File

@ -43,7 +43,7 @@ FunctionPass *createWebAssemblyEHRestoreStackPointer();
FunctionPass *createWebAssemblyReplacePhysRegs(); FunctionPass *createWebAssemblyReplacePhysRegs();
FunctionPass *createWebAssemblyPrepareForLiveIntervals(); FunctionPass *createWebAssemblyPrepareForLiveIntervals();
FunctionPass *createWebAssemblyOptimizeLiveIntervals(); FunctionPass *createWebAssemblyOptimizeLiveIntervals();
FunctionPass *createWebAssemblyStoreResults(); FunctionPass *createWebAssemblyMemIntrinsicResults();
FunctionPass *createWebAssemblyRegStackify(); FunctionPass *createWebAssemblyRegStackify();
FunctionPass *createWebAssemblyRegColoring(); FunctionPass *createWebAssemblyRegColoring();
FunctionPass *createWebAssemblyExplicitLocals(); FunctionPass *createWebAssemblyExplicitLocals();
@ -68,7 +68,7 @@ void initializeWebAssemblyEHRestoreStackPointerPass(PassRegistry &);
void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &); void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &);
void initializeWebAssemblyPrepareForLiveIntervalsPass(PassRegistry &); void initializeWebAssemblyPrepareForLiveIntervalsPass(PassRegistry &);
void initializeWebAssemblyOptimizeLiveIntervalsPass(PassRegistry &); void initializeWebAssemblyOptimizeLiveIntervalsPass(PassRegistry &);
void initializeWebAssemblyStoreResultsPass(PassRegistry &); void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &);
void initializeWebAssemblyRegStackifyPass(PassRegistry &); void initializeWebAssemblyRegStackifyPass(PassRegistry &);
void initializeWebAssemblyRegColoringPass(PassRegistry &); void initializeWebAssemblyRegColoringPass(PassRegistry &);
void initializeWebAssemblyExplicitLocalsPass(PassRegistry &); void initializeWebAssemblyExplicitLocalsPass(PassRegistry &);

View File

@ -1,4 +1,4 @@
//===-- WebAssemblyStoreResults.cpp - Optimize using store result values --===// //== WebAssemblyMemIntrinsicResults.cpp - Optimize memory intrinsic results ==//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -8,19 +8,22 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// ///
/// \file /// \file
/// This file implements an optimization pass using store result values. /// This file implements an optimization pass using memory intrinsic results.
/// ///
/// WebAssembly's store instructions return the stored value. This is to enable /// Calls to memory intrinsics (memcpy, memmove, memset) return the destination
/// an optimization wherein uses of the stored value can be replaced by uses of /// address. They are in the form of
/// the store's result value, making the stored value register more likely to /// %dst_new = call @memcpy %dst, %src, %len
/// be single-use, thus more likely to be useful to register stackifying, and /// where %dst and %dst_new registers contain the same value.
/// potentially also exposing the store to register stackifying. These both can
/// reduce local.get/local.set traffic.
/// ///
/// This pass also performs this optimization for memcpy, memmove, and memset /// This is to enable an optimization wherein uses of the %dst register used in
/// calls, since the LLVM intrinsics for these return void so they can't use the /// the parameter can be replaced by uses of the %dst_new register used in the
/// returned attribute and consequently aren't handled by the OptimizeReturned /// result, making the %dst register more likely to be single-use, thus more
/// pass. /// likely to be useful to register stackifying, and potentially also exposing
/// the call instruction itself to register stackifying. These both can reduce
/// local.get/local.set traffic.
///
/// The LLVM intrinsics for these return void so they can't use the returned
/// attribute and consequently aren't handled by the OptimizeReturned pass.
/// ///
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -38,15 +41,17 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
#define DEBUG_TYPE "wasm-store-results" #define DEBUG_TYPE "wasm-mem-intrinsic-results"
namespace { namespace {
class WebAssemblyStoreResults final : public MachineFunctionPass { class WebAssemblyMemIntrinsicResults final : public MachineFunctionPass {
public: public:
static char ID; // Pass identification, replacement for typeid static char ID; // Pass identification, replacement for typeid
WebAssemblyStoreResults() : MachineFunctionPass(ID) {} WebAssemblyMemIntrinsicResults() : MachineFunctionPass(ID) {}
StringRef getPassName() const override { return "WebAssembly Store Results"; } StringRef getPassName() const override {
return "WebAssembly Memory Intrinsic Results";
}
void getAnalysisUsage(AnalysisUsage &AU) const override { void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesCFG(); AU.setPreservesCFG();
@ -67,12 +72,13 @@ private:
}; };
} // end anonymous namespace } // end anonymous namespace
char WebAssemblyStoreResults::ID = 0; char WebAssemblyMemIntrinsicResults::ID = 0;
INITIALIZE_PASS(WebAssemblyStoreResults, DEBUG_TYPE, INITIALIZE_PASS(WebAssemblyMemIntrinsicResults, DEBUG_TYPE,
"Optimize store result values for WebAssembly", false, false) "Optimize memory intrinsic result values for WebAssembly",
false, false)
FunctionPass *llvm::createWebAssemblyStoreResults() { FunctionPass *llvm::createWebAssemblyMemIntrinsicResults() {
return new WebAssemblyStoreResults(); return new WebAssemblyMemIntrinsicResults();
} }
// Replace uses of FromReg with ToReg if they are dominated by MI. // Replace uses of FromReg with ToReg if they are dominated by MI.
@ -164,14 +170,14 @@ static bool optimizeCall(MachineBasicBlock &MBB, MachineInstr &MI,
unsigned FromReg = MI.getOperand(2).getReg(); unsigned FromReg = MI.getOperand(2).getReg();
unsigned ToReg = MI.getOperand(0).getReg(); unsigned ToReg = MI.getOperand(0).getReg();
if (MRI.getRegClass(FromReg) != MRI.getRegClass(ToReg)) if (MRI.getRegClass(FromReg) != MRI.getRegClass(ToReg))
report_fatal_error("Store results: call to builtin function with wrong " report_fatal_error("Memory Intrinsic results: call to builtin function "
"signature, from/to mismatch"); "with wrong signature, from/to mismatch");
return ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT, LIS); return ReplaceDominatedUses(MBB, MI, FromReg, ToReg, MRI, MDT, LIS);
} }
bool WebAssemblyStoreResults::runOnMachineFunction(MachineFunction &MF) { bool WebAssemblyMemIntrinsicResults::runOnMachineFunction(MachineFunction &MF) {
LLVM_DEBUG({ LLVM_DEBUG({
dbgs() << "********** Store Results **********\n" dbgs() << "********** Memory Intrinsic Results **********\n"
<< "********** Function: " << MF.getName() << '\n'; << "********** Function: " << MF.getName() << '\n';
}); });
@ -186,7 +192,8 @@ bool WebAssemblyStoreResults::runOnMachineFunction(MachineFunction &MF) {
// We don't preserve SSA form. // We don't preserve SSA form.
MRI.leaveSSA(); MRI.leaveSSA();
assert(MRI.tracksLiveness() && "StoreResults expects liveness tracking"); assert(MRI.tracksLiveness() &&
"MemIntrinsicResults expects liveness tracking");
for (auto &MBB : MF) { for (auto &MBB : MF) {
LLVM_DEBUG(dbgs() << "Basic Block: " << MBB.getName() << '\n'); LLVM_DEBUG(dbgs() << "Basic Block: " << MBB.getName() << '\n');

View File

@ -62,7 +62,7 @@ extern "C" void LLVMInitializeWebAssemblyTarget() {
initializeWebAssemblyReplacePhysRegsPass(PR); initializeWebAssemblyReplacePhysRegsPass(PR);
initializeWebAssemblyPrepareForLiveIntervalsPass(PR); initializeWebAssemblyPrepareForLiveIntervalsPass(PR);
initializeWebAssemblyOptimizeLiveIntervalsPass(PR); initializeWebAssemblyOptimizeLiveIntervalsPass(PR);
initializeWebAssemblyStoreResultsPass(PR); initializeWebAssemblyMemIntrinsicResultsPass(PR);
initializeWebAssemblyRegStackifyPass(PR); initializeWebAssemblyRegStackifyPass(PR);
initializeWebAssemblyRegColoringPass(PR); initializeWebAssemblyRegColoringPass(PR);
initializeWebAssemblyExplicitLocalsPass(PR); initializeWebAssemblyExplicitLocalsPass(PR);
@ -311,13 +311,14 @@ void WebAssemblyPassConfig::addPreEmitPass() {
// Depend on LiveIntervals and perform some optimizations on it. // Depend on LiveIntervals and perform some optimizations on it.
addPass(createWebAssemblyOptimizeLiveIntervals()); addPass(createWebAssemblyOptimizeLiveIntervals());
// Prepare store instructions for register stackifying. // Prepare memory intrinsic calls for register stackifying.
addPass(createWebAssemblyStoreResults()); addPass(createWebAssemblyMemIntrinsicResults());
// Mark registers as representing wasm's value stack. This is a key // Mark registers as representing wasm's value stack. This is a key
// code-compression technique in WebAssembly. We run this pass (and // code-compression technique in WebAssembly. We run this pass (and
// StoreResults above) very late, so that it sees as much code as possible, // MemIntrinsicResults above) very late, so that it sees as much code as
// including code emitted by PEI and expanded by late tail duplication. // possible, including code emitted by PEI and expanded by late tail
// duplication.
addPass(createWebAssemblyRegStackify()); addPass(createWebAssemblyRegStackify());
// Run the register coloring pass to reduce the total number of registers. // Run the register coloring pass to reduce the total number of registers.

View File

@ -4,7 +4,7 @@
; CHECK: bb.3.for.body.for.body_crit_edge: ; CHECK: bb.3.for.body.for.body_crit_edge:
; CHECK: [[REG:%[0-9]+]]:i32 = nsw ADD_I32 {{.*}} fib.c:7:7 ; CHECK: [[REG:%[0-9]+]]:i32 = nsw ADD_I32 {{.*}} fib.c:7:7
; CHECK: DBG_VALUE [[REG]]:i32, $noreg, !"a", {{.*}} fib.c:5:13 ; CHECK: DBG_VALUE [[REG]]:i32, $noreg, !"a", {{.*}} fib.c:5:13
; CHECK: After WebAssembly Store Results: ; CHECK: After WebAssembly Memory Intrinsic Results:
; ModuleID = 'fib.bc' ; ModuleID = 'fib.bc'
source_filename = "fib.c" source_filename = "fib.c"