From 1ff585db47087b5df032b6cf819e71b1fd1fe25e Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Wed, 1 Jul 2015 23:41:25 +0000 Subject: [PATCH] WebAssembly: start instructions Summary: * Add 64-bit address space feature. * Rename SIMD feature to SIMD128. * Handle single-thread model with an IR pass (same way ARM does). * Rename generic processor to MVP, to follow design's lead. * Add bleeding-edge processors, with all features included. * Fix a few DEBUG_TYPE to match other backends. Test Plan: ninja check Reviewers: sunfish Subscribers: jfb, llvm-commits Differential Revision: http://reviews.llvm.org/D10880 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241211 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/WebAssembly/WebAssembly.td | 10 +++++++--- lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp | 2 +- lib/Target/WebAssembly/WebAssemblyInstrAtomics.td | 2 ++ lib/Target/WebAssembly/WebAssemblyInstrInfo.td | 5 +++++ lib/Target/WebAssembly/WebAssemblyInstrSIMD.td | 2 +- lib/Target/WebAssembly/WebAssemblySubtarget.cpp | 6 +++--- lib/Target/WebAssembly/WebAssemblySubtarget.h | 5 +++-- lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 12 +++++++++--- 8 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lib/Target/WebAssembly/WebAssembly.td b/lib/Target/WebAssembly/WebAssembly.td index f5e2564b165..a123bf6f66b 100644 --- a/lib/Target/WebAssembly/WebAssembly.td +++ b/lib/Target/WebAssembly/WebAssembly.td @@ -22,8 +22,8 @@ include "llvm/Target/Target.td" // WebAssembly Subtarget features. //===----------------------------------------------------------------------===// -def FeatureSIMD : SubtargetFeature<"simd", "HasSIMD", "true", - "Enable SIMD">; +def FeatureSIMD128 : SubtargetFeature<"simd128", "HasSIMD128", "false", + "Enable 128-bit SIMD">; //===----------------------------------------------------------------------===// // Architectures. @@ -47,7 +47,11 @@ def WebAssemblyInstrInfo : InstrInfo; // WebAssembly Processors supported. //===----------------------------------------------------------------------===// -def : ProcessorModel<"generic", NoSchedModel, [FeatureSIMD]>; +// Minimal Viable Product. +def : ProcessorModel<"mvp", NoSchedModel, []>; + +// Latest and greatest experimental version of WebAssembly. Bugs included! +def : ProcessorModel<"bleeding-edge", NoSchedModel, [FeatureSIMD128]>; //===----------------------------------------------------------------------===// // Target Declaration diff --git a/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp b/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp index 330695e9f67..e4ca82e963c 100644 --- a/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ b/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -32,7 +32,7 @@ #include "llvm/Support/Debug.h" using namespace llvm; -#define DEBUG_TYPE "frame-info" +#define DEBUG_TYPE "wasm-frame-info" // TODO: Implement a red zone? diff --git a/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td b/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td index 90cb2fcb274..35e88eec857 100644 --- a/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td +++ b/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td @@ -11,6 +11,8 @@ // //===----------------------------------------------------------------------===// +// TODO: Implement atomic instructions. + //===----------------------------------------------------------------------===// // Atomic fences //===----------------------------------------------------------------------===// diff --git a/lib/Target/WebAssembly/WebAssemblyInstrInfo.td b/lib/Target/WebAssembly/WebAssemblyInstrInfo.td index 53681a8ad07..142eccfbcaa 100644 --- a/lib/Target/WebAssembly/WebAssemblyInstrInfo.td +++ b/lib/Target/WebAssembly/WebAssemblyInstrInfo.td @@ -15,6 +15,11 @@ // WebAssembly Instruction Predicate Definitions. //===----------------------------------------------------------------------===// +def HasAddr32 : Predicate<"!Subtarget->hasAddr64()">; +def HasAddr64 : Predicate<"Subtarget->hasAddr64()">; +def HasSIMD128 : Predicate<"Subtarget->hasSIMD128()">, + AssemblerPredicate<"FeatureSIMD128", "simd128">; + //===----------------------------------------------------------------------===// // WebAssembly-specific DAG Node Types. //===----------------------------------------------------------------------===// diff --git a/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td b/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td index 901981df9b4..e25483ad3f7 100644 --- a/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td +++ b/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td @@ -12,4 +12,4 @@ //===----------------------------------------------------------------------===// // TODO: Implement SIMD instructions. -// Note: use Requires<[HasSIMD]>. +// Note: use Requires<[HasSIMD128]>. diff --git a/lib/Target/WebAssembly/WebAssemblySubtarget.cpp b/lib/Target/WebAssembly/WebAssemblySubtarget.cpp index f1415ee59cc..addea8e3cc3 100644 --- a/lib/Target/WebAssembly/WebAssemblySubtarget.cpp +++ b/lib/Target/WebAssembly/WebAssemblySubtarget.cpp @@ -19,7 +19,7 @@ #include "llvm/Support/TargetRegistry.h" using namespace llvm; -#define DEBUG_TYPE "subtarget" +#define DEBUG_TYPE "wasm-subtarget" #define GET_SUBTARGETINFO_CTOR #define GET_SUBTARGETINFO_TARGET_DESC @@ -40,8 +40,8 @@ WebAssemblySubtarget::WebAssemblySubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const TargetMachine &TM) - : WebAssemblyGenSubtargetInfo(TT, CPU, FS), HasSIMD(true), CPUString(CPU), - TargetTriple(TT), FrameLowering(), + : WebAssemblyGenSubtargetInfo(TT, CPU, FS), HasSIMD128(false), + CPUString(CPU), TargetTriple(TT), FrameLowering(), InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(TM.getDataLayout()), TLInfo(TM, *this) {} diff --git a/lib/Target/WebAssembly/WebAssemblySubtarget.h b/lib/Target/WebAssembly/WebAssemblySubtarget.h index 5e4ef9bf575..6f176194093 100644 --- a/lib/Target/WebAssembly/WebAssemblySubtarget.h +++ b/lib/Target/WebAssembly/WebAssemblySubtarget.h @@ -29,7 +29,7 @@ namespace llvm { class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo { - bool HasSIMD; + bool HasSIMD128; /// String name of used CPU. std::string CPUString; @@ -66,7 +66,8 @@ public: bool useAA() const override { return true; } // Predicates used by WebAssemblyInstrInfo.td. - bool hasSIMD() const { return HasSIMD; } + bool hasAddr64() const { return TargetTriple.isArch64Bit(); } + bool hasSIMD128() const { return HasSIMD128; } /// Parses features string setting specified subtarget options. Definition of /// function is auto generated by tblgen. diff --git a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 54ab02848b0..6f93248bd13 100644 --- a/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Target/TargetOptions.h" +#include "llvm/Transforms/Scalar.h" using namespace llvm; #define DEBUG_TYPE "wasm" @@ -139,9 +140,14 @@ void WebAssemblyPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) { //===----------------------------------------------------------------------===// void WebAssemblyPassConfig::addIRPasses() { - // Expand some atomic operations. WebAssemblyTargetLowering has hooks which - // control specifically what gets lowered. - addPass(createAtomicExpandPass(&getTM())); + // FIXME: the default for this option is currently POSIX, whereas + // WebAssembly's MVP should default to Single. + if (TM->Options.ThreadModel == ThreadModel::Single) + addPass(createLowerAtomicPass()); + else + // Expand some atomic operations. WebAssemblyTargetLowering has hooks which + // control specifically what gets lowered. + addPass(createAtomicExpandPass(TM)); TargetPassConfig::addIRPasses(); } -- 2.34.1