summaryrefslogtreecommitdiffstats
path: root/include/clang/Basic
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2015-09-03 22:51:53 +0000
committerDan Gohman <dan433584@gmail.com>2015-09-03 22:51:53 +0000
commitff7b95746431d69b88402ef1dd27279d1e3606c3 (patch)
tree4fd15375eae14fdd78359aabf0dee042112712d4 /include/clang/Basic
parentd40851784c38246462105689e66db48448817cb7 (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/Basic')
-rw-r--r--include/clang/Basic/BuiltinsWebAssembly.def21
-rw-r--r--include/clang/Basic/TargetBuiltins.h11
-rw-r--r--include/clang/Basic/TargetCXXABI.h54
3 files changed, 83 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