diff options
author | Dan Gohman <dan433584@gmail.com> | 2015-09-03 22:51:53 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2015-09-03 22:51:53 +0000 |
commit | ff7b95746431d69b88402ef1dd27279d1e3606c3 (patch) | |
tree | 4fd15375eae14fdd78359aabf0dee042112712d4 /include/clang | |
parent | d40851784c38246462105689e66db48448817cb7 (diff) |
[WebAssembly] Initial WebAssembly support in clang
This implements basic support for compiling (though not yet assembling
or linking) for a WebAssembly target. Note that ABI details are not yet
finalized, and may change.
Differential Revision: http://reviews.llvm.org/D12002
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246814 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Basic/BuiltinsWebAssembly.def | 21 | ||||
-rw-r--r-- | include/clang/Basic/TargetBuiltins.h | 11 | ||||
-rw-r--r-- | include/clang/Basic/TargetCXXABI.h | 54 | ||||
-rw-r--r-- | include/clang/Driver/Options.td | 5 | ||||
-rw-r--r-- | include/clang/module.modulemap | 1 |
5 files changed, 89 insertions, 3 deletions
diff --git a/include/clang/Basic/BuiltinsWebAssembly.def b/include/clang/Basic/BuiltinsWebAssembly.def new file mode 100644 index 0000000000..5c67bdfbb4 --- /dev/null +++ b/include/clang/Basic/BuiltinsWebAssembly.def @@ -0,0 +1,21 @@ +// BuiltinsWebAssembly.def - WebAssembly builtin function database -*- C++ -*-// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// \brief This file defines the WebAssembly-specific builtin function database. +/// Users of this file must define the BUILTIN macro to make use of this +/// information. +/// +//===----------------------------------------------------------------------===// + +// The format of this database matches clang/Basic/Builtins.def. + +BUILTIN(__builtin_wasm_page_size, "z", "nc") + +#undef BUILTIN diff --git a/include/clang/Basic/TargetBuiltins.h b/include/clang/Basic/TargetBuiltins.h index b4740c5952..623c0b64db 100644 --- a/include/clang/Basic/TargetBuiltins.h +++ b/include/clang/Basic/TargetBuiltins.h @@ -185,6 +185,17 @@ namespace clang { LastTSBuiltin }; } + + /// \brief WebAssembly builtins + namespace WebAssembly { + enum { + LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1, +#define BUILTIN(ID, TYPE, ATTRS) BI##ID, +#include "clang/Basic/BuiltinsWebAssembly.def" + LastTSBuiltin + }; + } + } // end namespace clang. #endif diff --git a/include/clang/Basic/TargetCXXABI.h b/include/clang/Basic/TargetCXXABI.h index 6921750b84..46243beb46 100644 --- a/include/clang/Basic/TargetCXXABI.h +++ b/include/clang/Basic/TargetCXXABI.h @@ -85,6 +85,21 @@ public: /// - representation of member function pointers adjusted as in ARM. GenericMIPS, + /// The WebAssembly ABI is a modified version of the Itanium ABI. + /// + /// The changes from the Itanium ABI are: + /// - representation of member function pointers is adjusted, as in ARM; + /// - member functions are not specially aligned; + /// - constructors and destructors return 'this', as in ARM; + /// - guard variables are 32-bit on wasm32, as in ARM; + /// - unused bits of guard variables are reserved, as in ARM; + /// - inline functions are never key functions, as in ARM; + /// - C++11 POD rules are used for tail padding, as in iOS64. + /// + /// TODO: At present the WebAssembly ABI is not considered stable, so none + /// of these details is necessarily final yet. + WebAssembly, + /// The Microsoft ABI is the ABI used by Microsoft Visual Studio (and /// compatible compilers). /// @@ -121,6 +136,7 @@ public: case iOS: case iOS64: case GenericMIPS: + case WebAssembly: return true; case Microsoft: @@ -138,6 +154,7 @@ public: case iOS: case iOS64: case GenericMIPS: + case WebAssembly: return false; case Microsoft: @@ -146,6 +163,35 @@ public: llvm_unreachable("bad ABI kind"); } + /// \brief Are member functions differently aligned? + /// + /// Many Itanium-style C++ ABIs require member functions to be aligned, so + /// that a pointer to such a function is guaranteed to have a zero in the + /// least significant bit, so that pointers to member functions can use that + /// bit to distinguish between virtual and non-virtual functions. However, + /// some Itanium-style C++ ABIs differentiate between virtual and non-virtual + /// functions via other means, and consequently don't require that member + /// functions be aligned. + bool areMemberFunctionsAligned() const { + switch (getKind()) { + case WebAssembly: + // WebAssembly doesn't require any special alignment for member functions. + return false; + case GenericARM: + case GenericAArch64: + case GenericMIPS: + // TODO: ARM-style pointers to member functions put the discriminator in + // the this adjustment, so they don't require functions to have any + // special alignment and could therefore also return false. + case GenericItanium: + case iOS: + case iOS64: + case Microsoft: + return true; + } + llvm_unreachable("bad ABI kind"); + } + /// \brief Is the default C++ member function calling convention /// the same as the default calling convention? bool isMemberFunctionCCDefault() const { @@ -214,6 +260,7 @@ public: switch (getKind()) { case GenericARM: case iOS64: + case WebAssembly: return false; case GenericAArch64: @@ -261,7 +308,7 @@ public: switch (getKind()) { // To preserve binary compatibility, the generic Itanium ABI has // permanently locked the definition of POD to the rules of C++ TR1, - // and that trickles down to all the derived ABIs. + // and that trickles down to derived ABIs. case GenericItanium: case GenericAArch64: case GenericARM: @@ -269,9 +316,10 @@ public: case GenericMIPS: return UseTailPaddingUnlessPOD03; - // iOS on ARM64 uses the C++11 POD rules. It does not honor the - // Itanium exception about classes with over-large bitfields. + // iOS on ARM64 and WebAssembly use the C++11 POD rules. They do not honor + // the Itanium exception about classes with over-large bitfields. case iOS64: + case WebAssembly: return UseTailPaddingUnlessPOD11; // MSVC always allocates fields in the tail-padding of a base class diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index abea885114..8f69c5b88d 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -80,6 +80,8 @@ def m_hexagon_Features_Group : OptionGroup<"<m hexagon features group>">, Group def m_arm_Features_Group : OptionGroup<"<m arm features group>">, Group<m_Group>; def m_aarch64_Features_Group : OptionGroup<"<m aarch64 features group>">, Group<m_Group>; def m_ppc_Features_Group : OptionGroup<"<m ppc features group>">, Group<m_Group>; +def m_wasm_Features_Group : OptionGroup<"<m wasm features group>">, + Group<m_Group>; def m_libc_Group : OptionGroup<"<m libc group>">, Group<m_Group>; def u_Group : OptionGroup<"<u group>">; @@ -1334,6 +1336,9 @@ def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">, def ffixed_x18 : Flag<["-"], "ffixed-x18">, Group<m_aarch64_Features_Group>, HelpText<"Reserve the x18 register (AArch64 only)">; +def msimd128 : Flag<["-"], "msimd128">, Group<m_wasm_Features_Group>; +def mno_simd128 : Flag<["-"], "mno-simd128">, Group<m_wasm_Features_Group>; + def mvsx : Flag<["-"], "mvsx">, Group<m_ppc_Features_Group>; def mno_vsx : Flag<["-"], "mno-vsx">, Group<m_ppc_Features_Group>; def mpower8_vector : Flag<["-"], "mpower8-vector">, diff --git a/include/clang/module.modulemap b/include/clang/module.modulemap index 6b77adb002..cd509efc74 100644 --- a/include/clang/module.modulemap +++ b/include/clang/module.modulemap @@ -35,6 +35,7 @@ module Clang_Basic { textual header "Basic/BuiltinsPPC.def" textual header "Basic/BuiltinsR600.def" textual header "Basic/BuiltinsSystemZ.def" + textual header "Basic/BuiltinsWebAssembly.def" textual header "Basic/BuiltinsX86.def" textual header "Basic/BuiltinsXCore.def" textual header "Basic/DiagnosticOptions.def" |