2015-06-30 07:51:55 +08:00
|
|
|
//===- WebAssemblyTargetMachine.cpp - Define TargetMachine for WebAssembly -==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This file defines the WebAssembly-specific subclass of TargetMachine.
|
2015-06-30 07:51:55 +08:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "WebAssemblyTargetMachine.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
|
|
|
#include "WebAssembly.h"
|
2015-12-17 12:55:44 +08:00
|
|
|
#include "WebAssemblyTargetObjectFile.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
#include "WebAssemblyTargetTransformInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/CodeGen/RegAllocRegistry.h"
|
2016-05-10 11:21:59 +08:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2015-07-02 07:41:25 +08:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2018-03-29 01:44:36 +08:00
|
|
|
#include "llvm/Transforms/Utils.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "wasm"
|
|
|
|
|
2016-08-02 05:34:04 +08:00
|
|
|
// Emscripten's asm.js-style exception handling
|
2016-08-18 23:27:25 +08:00
|
|
|
static cl::opt<bool> EnableEmException(
|
2016-08-09 08:29:55 +08:00
|
|
|
"enable-emscripten-cxx-exceptions",
|
2016-08-02 05:34:04 +08:00
|
|
|
cl::desc("WebAssembly Emscripten-style exception handling"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2016-08-18 23:27:25 +08:00
|
|
|
// Emscripten's asm.js-style setjmp/longjmp handling
|
|
|
|
static cl::opt<bool> EnableEmSjLj(
|
|
|
|
"enable-emscripten-sjlj",
|
|
|
|
cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
extern "C" void LLVMInitializeWebAssemblyTarget() {
|
|
|
|
// Register the target.
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterTargetMachine<WebAssemblyTargetMachine> X(
|
|
|
|
getTheWebAssemblyTarget32());
|
|
|
|
RegisterTargetMachine<WebAssemblyTargetMachine> Y(
|
|
|
|
getTheWebAssemblyTarget64());
|
2016-08-02 05:34:04 +08:00
|
|
|
|
2018-03-31 04:36:58 +08:00
|
|
|
// Register backend passes
|
|
|
|
auto &PR = *PassRegistry::getPassRegistry();
|
2018-07-11 12:29:36 +08:00
|
|
|
initializeWebAssemblyAddMissingPrototypesPass(PR);
|
2018-03-31 04:36:58 +08:00
|
|
|
initializeWebAssemblyLowerEmscriptenEHSjLjPass(PR);
|
|
|
|
initializeLowerGlobalDtorsPass(PR);
|
|
|
|
initializeFixFunctionBitcastsPass(PR);
|
|
|
|
initializeOptimizeReturnedPass(PR);
|
|
|
|
initializeWebAssemblyArgumentMovePass(PR);
|
|
|
|
initializeWebAssemblySetP2AlignOperandsPass(PR);
|
2018-08-22 05:23:07 +08:00
|
|
|
initializeWebAssemblyEHRestoreStackPointerPass(PR);
|
2018-03-31 04:36:58 +08:00
|
|
|
initializeWebAssemblyReplacePhysRegsPass(PR);
|
|
|
|
initializeWebAssemblyPrepareForLiveIntervalsPass(PR);
|
|
|
|
initializeWebAssemblyOptimizeLiveIntervalsPass(PR);
|
|
|
|
initializeWebAssemblyStoreResultsPass(PR);
|
|
|
|
initializeWebAssemblyRegStackifyPass(PR);
|
|
|
|
initializeWebAssemblyRegColoringPass(PR);
|
|
|
|
initializeWebAssemblyExplicitLocalsPass(PR);
|
|
|
|
initializeWebAssemblyFixIrreducibleControlFlowPass(PR);
|
2018-06-25 09:07:11 +08:00
|
|
|
initializeWebAssemblyLateEHPreparePass(PR);
|
2018-06-25 09:20:21 +08:00
|
|
|
initializeWebAssemblyExceptionInfoPass(PR);
|
2018-03-31 04:36:58 +08:00
|
|
|
initializeWebAssemblyCFGSortPass(PR);
|
|
|
|
initializeWebAssemblyCFGStackifyPass(PR);
|
|
|
|
initializeWebAssemblyLowerBrUnlessPass(PR);
|
|
|
|
initializeWebAssemblyRegNumberingPass(PR);
|
|
|
|
initializeWebAssemblyPeepholePass(PR);
|
|
|
|
initializeWebAssemblyCallIndirectFixupPass(PR);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// WebAssembly Lowering public interface.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-05-19 11:00:05 +08:00
|
|
|
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
|
2018-11-17 02:59:51 +08:00
|
|
|
if (!RM.hasValue()) {
|
|
|
|
// Default to static relocation model. This should always be more optimial
|
|
|
|
// than PIC since the static linker can determine all global addresses and
|
|
|
|
// assume direct function calls.
|
|
|
|
return Reloc::Static;
|
|
|
|
}
|
2016-05-19 11:00:05 +08:00
|
|
|
return *RM;
|
|
|
|
}
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
/// Create an WebAssembly architecture model.
|
|
|
|
///
|
|
|
|
WebAssemblyTargetMachine::WebAssemblyTargetMachine(
|
|
|
|
const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
|
2016-05-19 11:00:05 +08:00
|
|
|
const TargetOptions &Options, Optional<Reloc::Model> RM,
|
2017-08-03 13:15:53 +08:00
|
|
|
Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT)
|
2017-10-13 06:57:28 +08:00
|
|
|
: LLVMTargetMachine(T,
|
|
|
|
TT.isArch64Bit() ? "e-m:e-p:64:64-i64:64-n32:64-S128"
|
|
|
|
: "e-m:e-p:32:32-i64:64-n32:64-S128",
|
|
|
|
TT, CPU, FS, Options, getEffectiveRelocModel(RM),
|
2018-12-07 20:10:23 +08:00
|
|
|
getEffectiveCodeModel(CM, CodeModel::Large), OL),
|
2018-07-17 07:09:29 +08:00
|
|
|
TLOF(new WebAssemblyTargetObjectFile()) {
|
2016-10-04 06:43:53 +08:00
|
|
|
// WebAssembly type-checks instructions, but a noreturn function with a return
|
2015-11-10 08:30:57 +08:00
|
|
|
// type that doesn't match the context will cause a check failure. So we lower
|
|
|
|
// LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
|
2016-10-04 06:43:53 +08:00
|
|
|
// 'unreachable' instructions which is meant for that case.
|
2015-11-10 08:30:57 +08:00
|
|
|
this->Options.TrapUnreachable = true;
|
|
|
|
|
2017-02-25 07:18:00 +08:00
|
|
|
// WebAssembly treats each function as an independent unit. Force
|
|
|
|
// -ffunction-sections, effectively, so that we can emit them independently.
|
2018-07-17 07:09:29 +08:00
|
|
|
this->Options.FunctionSections = true;
|
|
|
|
this->Options.DataSections = true;
|
|
|
|
this->Options.UniqueSectionNames = true;
|
2017-02-25 07:18:00 +08:00
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
initAsmInfo();
|
|
|
|
|
2016-02-18 14:32:53 +08:00
|
|
|
// Note that we don't use setRequiresStructuredCFG(true). It disables
|
|
|
|
// optimizations than we're ok with, and want, such as critical edge
|
|
|
|
// splitting and tail merging.
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
WebAssemblyTargetMachine::~WebAssemblyTargetMachine() {}
|
|
|
|
|
|
|
|
const WebAssemblySubtarget *
|
|
|
|
WebAssemblyTargetMachine::getSubtargetImpl(const Function &F) const {
|
|
|
|
Attribute CPUAttr = F.getFnAttribute("target-cpu");
|
|
|
|
Attribute FSAttr = F.getFnAttribute("target-features");
|
|
|
|
|
|
|
|
std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
|
|
|
|
? CPUAttr.getValueAsString().str()
|
|
|
|
: TargetCPU;
|
|
|
|
std::string FS = !FSAttr.hasAttribute(Attribute::None)
|
|
|
|
? FSAttr.getValueAsString().str()
|
|
|
|
: TargetFS;
|
|
|
|
|
|
|
|
auto &I = SubtargetMap[CPU + FS];
|
|
|
|
if (!I) {
|
|
|
|
// This needs to be done before we create a new subtarget since any
|
|
|
|
// creation will depend on the TM and the code generation flags on the
|
|
|
|
// function that reside in TargetOptions.
|
|
|
|
resetTargetOptions(F);
|
2015-08-12 02:11:17 +08:00
|
|
|
I = llvm::make_unique<WebAssemblySubtarget>(TargetTriple, CPU, FS, *this);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
return I.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2018-03-21 06:01:32 +08:00
|
|
|
class StripThreadLocal final : public ModulePass {
|
|
|
|
// The default thread model for wasm is single, where thread-local variables
|
|
|
|
// are identical to regular globals and should be treated the same. So this
|
|
|
|
// pass just converts all GlobalVariables to NotThreadLocal
|
|
|
|
static char ID;
|
|
|
|
|
2018-09-05 09:27:38 +08:00
|
|
|
public:
|
2018-03-21 06:01:32 +08:00
|
|
|
StripThreadLocal() : ModulePass(ID) {}
|
|
|
|
bool runOnModule(Module &M) override {
|
|
|
|
for (auto &GV : M.globals())
|
|
|
|
GV.setThreadLocalMode(GlobalValue::ThreadLocalMode::NotThreadLocal);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
char StripThreadLocal::ID = 0;
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
/// WebAssembly Code Generator Pass Configuration Options.
|
|
|
|
class WebAssemblyPassConfig final : public TargetPassConfig {
|
|
|
|
public:
|
2017-05-31 05:36:41 +08:00
|
|
|
WebAssemblyPassConfig(WebAssemblyTargetMachine &TM, PassManagerBase &PM)
|
2015-06-30 07:51:55 +08:00
|
|
|
: TargetPassConfig(TM, PM) {}
|
|
|
|
|
|
|
|
WebAssemblyTargetMachine &getWebAssemblyTargetMachine() const {
|
|
|
|
return getTM<WebAssemblyTargetMachine>();
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionPass *createTargetRegisterAllocator(bool) override;
|
|
|
|
|
|
|
|
void addIRPasses() override;
|
|
|
|
bool addInstSelector() override;
|
|
|
|
void addPostRegAlloc() override;
|
2016-03-29 01:05:30 +08:00
|
|
|
bool addGCPasses() override { return false; }
|
2015-06-30 07:51:55 +08:00
|
|
|
void addPreEmitPass() override;
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
(Re-landing) Expose a TargetMachine::getTargetTransformInfo function
Re-land r321234. It had to be reverted because it broke the shared
library build. The shared library build broke because there was a
missing LLVMBuild dependency from lib/Passes (which calls
TargetMachine::getTargetIRAnalysis) to lib/Target. As far as I can
tell, this problem was always there but was somehow masked
before (perhaps because TargetMachine::getTargetIRAnalysis was a
virtual function).
Original commit message:
This makes the TargetMachine interface a bit simpler. We still need
the std::function in TargetIRAnalysis to avoid having to add a
dependency from Analysis to Target.
See discussion:
http://lists.llvm.org/pipermail/llvm-dev/2017-December/119749.html
I avoided adding all of the backend owners to this review since the
change is simple, but let me know if you feel differently about this.
Reviewers: echristo, MatzeB, hfinkel
Reviewed By: hfinkel
Subscribers: jholewinski, jfb, arsenm, dschuff, mcrosier, sdardis, nemanjai, nhaehnle, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, llvm-commits
Differential Revision: https://reviews.llvm.org/D41464
llvm-svn: 321375
2017-12-23 02:21:59 +08:00
|
|
|
TargetTransformInfo
|
|
|
|
WebAssemblyTargetMachine::getTargetTransformInfo(const Function &F) {
|
|
|
|
return TargetTransformInfo(WebAssemblyTTIImpl(this, F));
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetPassConfig *
|
|
|
|
WebAssemblyTargetMachine::createPassConfig(PassManagerBase &PM) {
|
2017-05-31 05:36:41 +08:00
|
|
|
return new WebAssemblyPassConfig(*this, PM);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
|
|
|
|
return nullptr; // No reg alloc
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// The following functions are called from lib/CodeGen/Passes.cpp to modify
|
|
|
|
// the CodeGen pass sequence.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void WebAssemblyPassConfig::addIRPasses() {
|
2018-03-21 06:01:32 +08:00
|
|
|
if (TM->Options.ThreadModel == ThreadModel::Single) {
|
2015-11-26 02:13:18 +08:00
|
|
|
// In "single" mode, atomics get lowered to non-atomics.
|
2015-07-02 07:41:25 +08:00
|
|
|
addPass(createLowerAtomicPass());
|
2018-03-21 06:01:32 +08:00
|
|
|
addPass(new StripThreadLocal());
|
|
|
|
} else {
|
2015-07-02 07:41:25 +08:00
|
|
|
// Expand some atomic operations. WebAssemblyTargetLowering has hooks which
|
|
|
|
// control specifically what gets lowered.
|
2017-05-19 01:21:13 +08:00
|
|
|
addPass(createAtomicExpandPass());
|
2018-03-21 06:01:32 +08:00
|
|
|
}
|
2015-06-30 07:51:55 +08:00
|
|
|
|
2018-07-11 12:29:36 +08:00
|
|
|
// Add signatures to prototype-less function declarations
|
|
|
|
addPass(createWebAssemblyAddMissingPrototypes());
|
|
|
|
|
2017-12-15 08:17:10 +08:00
|
|
|
// Lower .llvm.global_dtors into .llvm_global_ctors with __cxa_atexit calls.
|
|
|
|
addPass(createWebAssemblyLowerGlobalDtors());
|
|
|
|
|
2017-01-07 08:34:54 +08:00
|
|
|
// Fix function bitcasts, as WebAssembly requires caller and callee signatures
|
|
|
|
// to match.
|
|
|
|
addPass(createWebAssemblyFixFunctionBitcasts());
|
|
|
|
|
2015-11-26 00:55:01 +08:00
|
|
|
// Optimize "returned" function attributes.
|
2016-01-19 22:55:02 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
|
|
|
addPass(createWebAssemblyOptimizeReturned());
|
2015-11-26 00:55:01 +08:00
|
|
|
|
2016-09-02 05:05:15 +08:00
|
|
|
// If exception handling is not enabled and setjmp/longjmp handling is
|
|
|
|
// enabled, we lower invokes into calls and delete unreachable landingpad
|
|
|
|
// blocks. Lowering invokes when there is no EH support is done in
|
|
|
|
// TargetPassConfig::addPassesToHandleExceptions, but this runs after this
|
|
|
|
// function and SjLj handling expects all invokes to be lowered before.
|
2018-02-24 08:40:50 +08:00
|
|
|
if (!EnableEmException &&
|
|
|
|
TM->Options.ExceptionModel == ExceptionHandling::None) {
|
2016-09-02 05:05:15 +08:00
|
|
|
addPass(createLowerInvokePass());
|
|
|
|
// The lower invoke pass may create unreachable code. Remove it in order not
|
|
|
|
// to process dead blocks in setjmp/longjmp handling.
|
|
|
|
addPass(createUnreachableBlockEliminationPass());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle exceptions and setjmp/longjmp if enabled.
|
2016-08-18 23:27:25 +08:00
|
|
|
if (EnableEmException || EnableEmSjLj)
|
|
|
|
addPass(createWebAssemblyLowerEmscriptenEHSjLj(EnableEmException,
|
|
|
|
EnableEmSjLj));
|
2016-08-02 05:34:04 +08:00
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
TargetPassConfig::addIRPasses();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAssemblyPassConfig::addInstSelector() {
|
2015-12-06 03:24:17 +08:00
|
|
|
(void)TargetPassConfig::addInstSelector();
|
2015-06-30 07:51:55 +08:00
|
|
|
addPass(
|
|
|
|
createWebAssemblyISelDag(getWebAssemblyTargetMachine(), getOptLevel()));
|
2015-12-10 00:23:59 +08:00
|
|
|
// Run the argument-move pass immediately after the ScheduleDAG scheduler
|
|
|
|
// so that we can fix up the ARGUMENT instructions before anything else
|
|
|
|
// sees them in the wrong place.
|
|
|
|
addPass(createWebAssemblyArgumentMove());
|
2016-01-26 11:39:31 +08:00
|
|
|
// Set the p2align operands. This information is present during ISel, however
|
|
|
|
// it's inconvenient to collect. Collect it now, and update the immediate
|
|
|
|
// operands.
|
|
|
|
addPass(createWebAssemblySetP2AlignOperands());
|
2015-06-30 07:51:55 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-01 01:53:38 +08:00
|
|
|
void WebAssemblyPassConfig::addPostRegAlloc() {
|
2015-11-26 02:13:18 +08:00
|
|
|
// TODO: The following CodeGen passes don't currently support code containing
|
|
|
|
// virtual registers. Consider removing their restrictions and re-enabling
|
|
|
|
// them.
|
2016-03-29 01:05:30 +08:00
|
|
|
|
2016-08-25 09:27:13 +08:00
|
|
|
// These functions all require the NoVRegs property.
|
2015-08-01 01:53:38 +08:00
|
|
|
disablePass(&MachineCopyPropagationID);
|
[CodeGen]Add NoVRegs property on PostRASink and ShrinkWrap
Summary:
This change declare that PostRAMachineSinking and ShrinkWrap require NoVRegs
property, so now the MachineFunctionPass can enforce this check.
These passes are disabled in NVPTX & WebAssembly.
Reviewers: dschuff, jlebar, tra, jgravelle-google, MatzeB, sebpop, thegameg, mcrosier
Reviewed By: dschuff, thegameg
Subscribers: jholewinski, jfb, sbc100, aheejin, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D45183
llvm-svn: 329095
2018-04-04 02:17:34 +08:00
|
|
|
disablePass(&PostRAMachineSinkingID);
|
2016-03-29 06:52:20 +08:00
|
|
|
disablePass(&PostRASchedulerID);
|
|
|
|
disablePass(&FuncletLayoutID);
|
|
|
|
disablePass(&StackMapLivenessID);
|
|
|
|
disablePass(&LiveDebugValuesID);
|
2016-04-19 14:24:58 +08:00
|
|
|
disablePass(&PatchableFunctionID);
|
[CodeGen]Add NoVRegs property on PostRASink and ShrinkWrap
Summary:
This change declare that PostRAMachineSinking and ShrinkWrap require NoVRegs
property, so now the MachineFunctionPass can enforce this check.
These passes are disabled in NVPTX & WebAssembly.
Reviewers: dschuff, jlebar, tra, jgravelle-google, MatzeB, sebpop, thegameg, mcrosier
Reviewed By: dschuff, thegameg
Subscribers: jholewinski, jfb, sbc100, aheejin, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D45183
llvm-svn: 329095
2018-04-04 02:17:34 +08:00
|
|
|
disablePass(&ShrinkWrapID);
|
2015-09-17 00:51:30 +08:00
|
|
|
|
2015-12-06 03:24:17 +08:00
|
|
|
TargetPassConfig::addPostRegAlloc();
|
2015-08-01 01:53:38 +08:00
|
|
|
}
|
2015-06-30 07:51:55 +08:00
|
|
|
|
2015-09-17 00:51:30 +08:00
|
|
|
void WebAssemblyPassConfig::addPreEmitPass() {
|
2015-12-06 03:24:17 +08:00
|
|
|
TargetPassConfig::addPreEmitPass();
|
2015-12-17 09:39:00 +08:00
|
|
|
|
2018-08-22 05:23:07 +08:00
|
|
|
// Restore __stack_pointer global after an exception is thrown.
|
|
|
|
addPass(createWebAssemblyEHRestoreStackPointer());
|
|
|
|
|
2016-05-10 12:24:02 +08:00
|
|
|
// Now that we have a prologue and epilogue and all frame indices are
|
|
|
|
// rewritten, eliminate SP and FP. This allows them to be stackified,
|
|
|
|
// colored, and numbered with the rest of the registers.
|
|
|
|
addPass(createWebAssemblyReplacePhysRegs());
|
|
|
|
|
2016-10-22 00:38:07 +08:00
|
|
|
// Rewrite pseudo call_indirect instructions as real instructions.
|
|
|
|
// This needs to run before register stackification, because we change the
|
|
|
|
// order of the arguments.
|
|
|
|
addPass(createWebAssemblyCallIndirectFixup());
|
|
|
|
|
2019-01-08 09:25:12 +08:00
|
|
|
// Eliminate multiple-entry loops.
|
|
|
|
addPass(createWebAssemblyFixIrreducibleControlFlow());
|
|
|
|
|
|
|
|
// Do various transformations for exception handling.
|
|
|
|
addPass(createWebAssemblyLateEHPrepare());
|
|
|
|
|
2016-05-10 12:24:02 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None) {
|
|
|
|
// LiveIntervals isn't commonly run this late. Re-establish preconditions.
|
|
|
|
addPass(createWebAssemblyPrepareForLiveIntervals());
|
|
|
|
|
|
|
|
// Depend on LiveIntervals and perform some optimizations on it.
|
|
|
|
addPass(createWebAssemblyOptimizeLiveIntervals());
|
|
|
|
|
|
|
|
// Prepare store instructions for register stackifying.
|
|
|
|
addPass(createWebAssemblyStoreResults());
|
|
|
|
|
2016-10-04 06:43:53 +08:00
|
|
|
// Mark registers as representing wasm's value stack. This is a key
|
2016-05-10 12:24:02 +08:00
|
|
|
// code-compression technique in WebAssembly. We run this pass (and
|
|
|
|
// StoreResults above) very late, so that it sees as much code as possible,
|
|
|
|
// including code emitted by PEI and expanded by late tail duplication.
|
|
|
|
addPass(createWebAssemblyRegStackify());
|
|
|
|
|
|
|
|
// Run the register coloring pass to reduce the total number of registers.
|
|
|
|
// This runs after stackification so that it doesn't consider registers
|
|
|
|
// that become stackified.
|
|
|
|
addPass(createWebAssemblyRegColoring());
|
|
|
|
}
|
|
|
|
|
2019-01-08 14:25:55 +08:00
|
|
|
// Insert explicit local.get and local.set operators.
|
2018-08-14 07:12:49 +08:00
|
|
|
addPass(createWebAssemblyExplicitLocals());
|
|
|
|
|
2017-02-28 06:38:58 +08:00
|
|
|
// Sort the blocks of the CFG into topological order, a prerequisite for
|
|
|
|
// BLOCK and LOOP markers.
|
|
|
|
addPass(createWebAssemblyCFGSort());
|
|
|
|
|
|
|
|
// Insert BLOCK and LOOP markers.
|
2015-09-17 00:51:30 +08:00
|
|
|
addPass(createWebAssemblyCFGStackify());
|
2015-11-26 05:32:06 +08:00
|
|
|
|
2015-12-05 11:03:35 +08:00
|
|
|
// Lower br_unless into br_if.
|
|
|
|
addPass(createWebAssemblyLowerBrUnless());
|
|
|
|
|
2015-11-26 05:32:06 +08:00
|
|
|
// Perform the very last peephole optimizations on the code.
|
2016-01-19 22:55:02 +08:00
|
|
|
if (getOptLevel() != CodeGenOpt::None)
|
|
|
|
addPass(createWebAssemblyPeephole());
|
2016-05-21 08:21:56 +08:00
|
|
|
|
|
|
|
// Create a mapping from LLVM CodeGen virtual registers to wasm registers.
|
|
|
|
addPass(createWebAssemblyRegNumbering());
|
2015-09-17 00:51:30 +08:00
|
|
|
}
|