[PATCH] D12002: Initial WebAssembly support in clang
sunfish created this revision. sunfish added subscribers: cfe-commits, jfb. sunfish set the repository for this revision to rL LLVM. This patch adds initial WebAssembly support in clang. The WebAssembly target is currently experimental. Repository: rL LLVM http://reviews.llvm.org/D12002 Files: include/clang/Basic/BuiltinsWebAssembly.def include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetCXXABI.h include/clang/module.modulemap lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp lib/CodeGen/TargetInfo.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/builtins-wasm.c test/CodeGen/target-data.c test/CodeGen/wasm-arguments.c test/CodeGen/wasm-regparm.c test/CodeGenCXX/member-alignment.cpp test/CodeGenCXX/member-function-pointers.cpp test/CodeGenCXX/static-init-wasm.cpp test/Driver/wasm32-unknown-unknown.cpp test/Driver/wasm64-unknown-unknown.cpp test/Preprocessor/init.c Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -8418,3 +8418,601 @@ // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // XCORE:#define __LITTLE_ENDIAN__ 1 // XCORE:#define __XS1B__ 1 +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown < /dev/null | FileCheck -check-prefix=WEBASSEMBLY32 %s +// +// WEBASSEMBLY32:#define _ILP32 1 +// WEBASSEMBLY32-NOT:#define _LP64 +// WEBASSEMBLY32:#define __ATOMIC_ACQUIRE 2 +// WEBASSEMBLY32:#define __ATOMIC_ACQ_REL 4 +// WEBASSEMBLY32:#define __ATOMIC_CONSUME 1 +// WEBASSEMBLY32:#define __ATOMIC_RELAXED 0 +// WEBASSEMBLY32:#define __ATOMIC_RELEASE 3 +// WEBASSEMBLY32:#define __ATOMIC_SEQ_CST 5 +// WEBASSEMBLY32:#define __BIGGEST_ALIGNMENT__ 16 +// WEBASSEMBLY32:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +// WEBASSEMBLY32:#define __CHAR16_TYPE__ unsigned short +// WEBASSEMBLY32:#define __CHAR32_TYPE__ unsigned int +// WEBASSEMBLY32:#define __CHAR_BIT__ 8 +// WEBASSEMBLY32:#define __CONSTANT_CFSTRINGS__ 1 +// WEBASSEMBLY32:#define __DBL_DECIMAL_DIG__ 17 +// WEBASSEMBLY32:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 +// WEBASSEMBLY32:#define __DBL_DIG__ 15 +// WEBASSEMBLY32:#define __DBL_EPSILON__ 2.2204460492503131e-16 +// WEBASSEMBLY32:#define __DBL_HAS_DENORM__ 1 +// WEBASSEMBLY32:#define __DBL_HAS_INFINITY__ 1 +// WEBASSEMBLY32:#define __DBL_HAS_QUIET_NAN__ 1 +// WEBASSEMBLY32:#define __DBL_MANT_DIG__ 53 +// WEBASSEMBLY32:#define __DBL_MAX_10_EXP__ 308 +// WEBASSEMBLY32:#define __DBL_MAX_EXP__ 1024 +// WEBASSEMBLY32:#define __DBL_MAX__ 1.7976931348623157e+308 +// WEBASSEMBLY32:#define __DBL_MIN_10_EXP__ (-307) +// WEBASSEMBLY32:#define __DBL_MIN_EXP__ (-1021) +// WEBASSEMBLY32:#define __DBL_MIN__ 2.2250738585072014e-308 +// WEBASSEMBLY32:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ +// WEBASSEMBLY32:#define __FINITE_MATH_ONLY__ 0 +// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9 +// WEBASSEMBLY32:#define __FLT_DENORM_MIN__ 1.40129846e-45F +// WEBASSEMBLY32:#define __FLT_DIG__ 6 +// WEBASSEMBLY32:#define __FLT_EPSILON__ 1.19209290e-7F +// WEBASSEMBLY32:#define __FLT_EVAL_METHOD__ 0 +// WEBASSEMBLY32:#define __FLT_HAS_DENORM__ 1 +// WEBASSEMBLY32:#define __FLT_HAS_INFINITY__ 1 +// WEBASSEMBLY32:#define __FLT_HAS_QUIET_NAN__ 1 +// WEBASSEMBLY32:#define __FLT_MANT_DIG__ 24 +// WEBASSEMBLY32:#define __FLT_MAX_10_EXP__ 38 +// WEBASSEMBLY32:#define __FLT_MAX_EXP__ 128 +// WEBASSEMBLY32:#define __FLT_MAX__ 3.40282347e+38F +// WEBASSEMBLY32:#define __FLT_MIN_10_EXP__ (-37) +// WEBASSEMBLY32:#define __FLT_MIN_EXP__ (-125) +// WEBASSEMBLY32:#define __FLT_MIN__ 1.17549435e-38F +// WEBASSEMBLY32:#define __FLT_RADIX__ 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_BOOL_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_INT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1 +// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +// WEBASSEMBLY32:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GNUC_MINOR__ +// WEBASSEMBLY32:#define __GNUC_PATCHLEVEL__ +// WEBASSEMBLY32:#define __GNUC_STDC_INLINE__ 1 +// WEBASSEMBLY32:#define __GNUC__ +// WEBASSEMBLY32:#define __GXX_ABI_VERSION 1002 +// WEBASSEMBLY32:#define __GXX_RTTI 1 +// WEBASSEMBLY32:#define __ILP32__ 1 +// WEBASSEMBLY32:#define __INT16_C_SUFFIX__ {{$}} +// WEBASSEMBLY32:#define __INT16_FMTd__ "hd" +// WEBASSEMBLY32:#define __INT16_FMTi__ "hi" +// WEBASSEMBLY32:#define __INT16_MAX__ 32767 +// WEBASSEMBLY32:#define __INT16_TYPE__ short +// WEBASSEMBLY32:#de
Re: [PATCH] D12002: Initial WebAssembly support in clang
jfb added a subscriber: rengolin. Comment at: include/clang/Basic/TargetCXXABI.h:166 @@ +165,3 @@ +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 @rengolin: FYI. Comment at: lib/Basic/Targets.cpp:6935 @@ +6934,3 @@ +NoAsmVariants = true; +LongDoubleWidth = LongDoubleAlign = 64; +SuitableAlign = 128; That's already the default? Comment at: lib/Basic/Targets.cpp:6937 @@ +6936,3 @@ +SuitableAlign = 128; +RegParmMax = 0; // Disallow regparm + } Already the default? Comment at: lib/Basic/Targets.cpp:6938 @@ +6937,3 @@ +RegParmMax = 0; // Disallow regparm + } + `TLSSupported = false` for now. Comment at: lib/Basic/Targets.cpp:6941 @@ +6940,3 @@ + void + getDefaultFeatures(llvm::StringMap &Features) const override final {} + bool setCPU(const std::string &Name) override final { Not needed, since that's the default impl? Comment at: lib/Basic/Targets.cpp:6956 @@ +6955,3 @@ + +Builder.defineMacro("__REGISTER_PREFIX__", ""); + } I'm not sure we need this. Does it just make porting easier? Comment at: lib/Basic/Targets.cpp:6983 @@ +6982,3 @@ + const char *getClobbers() const override { return ""; } + bool isCLZForZeroUndef() const override { return false; } +}; `final` for these two. Comment at: lib/Basic/Targets.cpp:6994 @@ +6993,3 @@ + +class WebAssembly32TargetInfo : public WebAssemblyTargetInfo { +public: `final` Comment at: lib/Basic/Targets.cpp:7015 @@ +7014,3 @@ + +class WebAssembly64TargetInfo : public WebAssemblyTargetInfo { +public: `final` Comment at: lib/Driver/Tools.cpp:1559 @@ -1558,1 +1558,3 @@ +/// getWebAssemblyTargetCPU - Get the (LLVM) name of the WebAssembly cpu we are +/// targeting. New comment style without `name -`. Comment at: test/CodeGen/wasm-arguments.c:91 @@ +90,2 @@ +// WEBASSEMBLY64: define void @f10(%struct.bitfield1* byval align 4 %bf1) +void f10(bitfield1 bf1) {} TODO for vararg test? Comment at: test/Driver/wasm32-unknown-unknown.cpp:51 @@ +50,3 @@ +void __wasm__defined() {} +#endif + Also test `__wasm32__` (and 64 in the other file). Comment at: test/Driver/wasm32-unknown-unknown.cpp:64 @@ +63,3 @@ +void _REENTRANTundefined() {} +#endif + Test `__REGISTER_PREFIX__` if we do keep it. Comment at: test/Preprocessor/init.c:8478 @@ +8477,3 @@ +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 `ATOMIC_*_LOCK_FREE` should always be `1` for "maybe". Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish planned changes to this revision. sunfish marked 3 inline comments as done. Comment at: lib/Basic/Targets.cpp:6935 @@ +6934,3 @@ +NoAsmVariants = true; +LongDoubleWidth = LongDoubleAlign = 64; +SuitableAlign = 128; jfb wrote: > That's already the default? I thought I'd leave it in while we discuss whether this is really what we want. Comment at: lib/Basic/Targets.cpp:6937 @@ +6936,3 @@ +SuitableAlign = 128; +RegParmMax = 0; // Disallow regparm + } jfb wrote: > Already the default? Right. Comment at: lib/Basic/Targets.cpp:6938 @@ +6937,3 @@ +RegParmMax = 0; // Disallow regparm + } + jfb wrote: > `TLSSupported = false` for now. Since the MVP doesn't have threads at all, all variables are TLS :-). And after the MVP, we'll add threads with TLS. Is there a downside to leaving this on for now? It'll make the thread prototyping work easier. Comment at: lib/Basic/Targets.cpp:6941 @@ +6940,3 @@ + void + getDefaultFeatures(llvm::StringMap &Features) const override final {} + bool setCPU(const std::string &Name) override final { jfb wrote: > Not needed, since that's the default impl? We're going to put code in there before long anyway, so there's no harm in getting it ready. Comment at: lib/Basic/Targets.cpp:6956 @@ +6955,3 @@ + +Builder.defineMacro("__REGISTER_PREFIX__", ""); + } jfb wrote: > I'm not sure we need this. Does it just make porting easier? I don't know if we specifically need it; I just included it because lots of other popular targets have it. Comment at: lib/Basic/Targets.cpp:6983 @@ +6982,3 @@ + const char *getClobbers() const override { return ""; } + bool isCLZForZeroUndef() const override { return false; } +}; jfb wrote: > `final` for these two. Right. Comment at: lib/Basic/Targets.cpp:6994 @@ +6993,3 @@ + +class WebAssembly32TargetInfo : public WebAssemblyTargetInfo { +public: jfb wrote: > `final` This class is subclassed. Comment at: lib/Basic/Targets.cpp:7015 @@ +7014,3 @@ + +class WebAssembly64TargetInfo : public WebAssemblyTargetInfo { +public: jfb wrote: > `final` This one is too. Comment at: lib/Driver/Tools.cpp:1559 @@ -1558,1 +1558,3 @@ +/// getWebAssemblyTargetCPU - Get the (LLVM) name of the WebAssembly cpu we are +/// targeting. jfb wrote: > New comment style without `name -`. Right. Comment at: test/CodeGen/wasm-arguments.c:91 @@ +90,2 @@ +// WEBASSEMBLY64: define void @f10(%struct.bitfield1* byval align 4 %bf1) +void f10(bitfield1 bf1) {} jfb wrote: > TODO for vararg test? There's a TODO for "implement va_list properly" elsewhere, so we can add tests when we actually implement it. Comment at: test/Driver/wasm32-unknown-unknown.cpp:51 @@ +50,3 @@ +void __wasm__defined() {} +#endif + jfb wrote: > Also test `__wasm32__` (and 64 in the other file). test/Preprocessor/init.c covers this. Comment at: test/Driver/wasm32-unknown-unknown.cpp:64 @@ +63,3 @@ +void _REENTRANTundefined() {} +#endif + jfb wrote: > Test `__REGISTER_PREFIX__` if we do keep it. test/Preprocessor/init.c covers this. Comment at: test/Preprocessor/init.c:8478 @@ +8477,3 @@ +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 jfb wrote: > `ATOMIC_*_LOCK_FREE` should always be `1` for "maybe". Clang is setting these automatically based on the value of MaxAtomicInlineWidth. Are you saying 32 is the wrong value for wasm32? This is perhaps a discussion to be had on the spec side. The value for wasm64 is also an interesting topic for the spec side. Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish updated this revision to Diff 32025. sunfish marked 3 inline comments as done. sunfish added a comment. Minor changes to address review comments. Repository: rL LLVM http://reviews.llvm.org/D12002 Files: include/clang/Basic/BuiltinsWebAssembly.def include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetCXXABI.h include/clang/module.modulemap lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp lib/CodeGen/TargetInfo.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/builtins-wasm.c test/CodeGen/target-data.c test/CodeGen/wasm-arguments.c test/CodeGen/wasm-regparm.c test/CodeGenCXX/member-alignment.cpp test/CodeGenCXX/member-function-pointers.cpp test/CodeGenCXX/static-init-wasm.cpp test/Driver/wasm32-unknown-unknown.cpp test/Driver/wasm64-unknown-unknown.cpp test/Preprocessor/init.c Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -8418,3 +8418,601 @@ // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // XCORE:#define __LITTLE_ENDIAN__ 1 // XCORE:#define __XS1B__ 1 +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown < /dev/null | FileCheck -check-prefix=WEBASSEMBLY32 %s +// +// WEBASSEMBLY32:#define _ILP32 1 +// WEBASSEMBLY32-NOT:#define _LP64 +// WEBASSEMBLY32:#define __ATOMIC_ACQUIRE 2 +// WEBASSEMBLY32:#define __ATOMIC_ACQ_REL 4 +// WEBASSEMBLY32:#define __ATOMIC_CONSUME 1 +// WEBASSEMBLY32:#define __ATOMIC_RELAXED 0 +// WEBASSEMBLY32:#define __ATOMIC_RELEASE 3 +// WEBASSEMBLY32:#define __ATOMIC_SEQ_CST 5 +// WEBASSEMBLY32:#define __BIGGEST_ALIGNMENT__ 16 +// WEBASSEMBLY32:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +// WEBASSEMBLY32:#define __CHAR16_TYPE__ unsigned short +// WEBASSEMBLY32:#define __CHAR32_TYPE__ unsigned int +// WEBASSEMBLY32:#define __CHAR_BIT__ 8 +// WEBASSEMBLY32:#define __CONSTANT_CFSTRINGS__ 1 +// WEBASSEMBLY32:#define __DBL_DECIMAL_DIG__ 17 +// WEBASSEMBLY32:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 +// WEBASSEMBLY32:#define __DBL_DIG__ 15 +// WEBASSEMBLY32:#define __DBL_EPSILON__ 2.2204460492503131e-16 +// WEBASSEMBLY32:#define __DBL_HAS_DENORM__ 1 +// WEBASSEMBLY32:#define __DBL_HAS_INFINITY__ 1 +// WEBASSEMBLY32:#define __DBL_HAS_QUIET_NAN__ 1 +// WEBASSEMBLY32:#define __DBL_MANT_DIG__ 53 +// WEBASSEMBLY32:#define __DBL_MAX_10_EXP__ 308 +// WEBASSEMBLY32:#define __DBL_MAX_EXP__ 1024 +// WEBASSEMBLY32:#define __DBL_MAX__ 1.7976931348623157e+308 +// WEBASSEMBLY32:#define __DBL_MIN_10_EXP__ (-307) +// WEBASSEMBLY32:#define __DBL_MIN_EXP__ (-1021) +// WEBASSEMBLY32:#define __DBL_MIN__ 2.2250738585072014e-308 +// WEBASSEMBLY32:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ +// WEBASSEMBLY32:#define __FINITE_MATH_ONLY__ 0 +// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9 +// WEBASSEMBLY32:#define __FLT_DENORM_MIN__ 1.40129846e-45F +// WEBASSEMBLY32:#define __FLT_DIG__ 6 +// WEBASSEMBLY32:#define __FLT_EPSILON__ 1.19209290e-7F +// WEBASSEMBLY32:#define __FLT_EVAL_METHOD__ 0 +// WEBASSEMBLY32:#define __FLT_HAS_DENORM__ 1 +// WEBASSEMBLY32:#define __FLT_HAS_INFINITY__ 1 +// WEBASSEMBLY32:#define __FLT_HAS_QUIET_NAN__ 1 +// WEBASSEMBLY32:#define __FLT_MANT_DIG__ 24 +// WEBASSEMBLY32:#define __FLT_MAX_10_EXP__ 38 +// WEBASSEMBLY32:#define __FLT_MAX_EXP__ 128 +// WEBASSEMBLY32:#define __FLT_MAX__ 3.40282347e+38F +// WEBASSEMBLY32:#define __FLT_MIN_10_EXP__ (-37) +// WEBASSEMBLY32:#define __FLT_MIN_EXP__ (-125) +// WEBASSEMBLY32:#define __FLT_MIN__ 1.17549435e-38F +// WEBASSEMBLY32:#define __FLT_RADIX__ 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_BOOL_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_INT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1 +// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +// WEBASSEMBLY32:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GNUC_MINOR__ +// WEBASSEMBLY32:#define __GNUC_PATCHLEVEL__ +// WEBASSEMBLY32:#define __GNUC_STDC_INLINE__ 1 +// WEBASSEMBLY32:#define __GNUC__ +// WEBASSEMBLY32:#define __GXX_ABI_VERSION 1002 +// WEBASSEMBLY32:#define __GXX_RTTI 1 +// WEBASSEMBLY32:#define __ILP32__ 1 +// WEBASSEMBLY32:#define __INT16_C_SUFFIX__ {{$}} +// WEBASSEMBLY32:#define __INT16_FMTd__ "hd" +// WEBASSEMBLY32:#define __INT16_FMTi__ "hi" +// WEBASSEMBLY32:#define __INT16_MAX__ 32767 +// WEBASSEMBLY32:#define __INT16_TYPE__ short +// WEBASSEMBLY32:#define __INT32_C_SUFFIX__ {{$}} +// WEBASSEMBLY32:#define __INT32_FMTd__ "d" +// WEBA
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish updated this revision to Diff 32109. sunfish added a comment. - use more default values in WebAssemblyTargetInfo etc. - add a comment about using ARM-C++-ABI-style guard variables (for now) - fix diff to include context for Phabricator Repository: rL LLVM http://reviews.llvm.org/D12002 Files: include/clang/Basic/BuiltinsWebAssembly.def include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetCXXABI.h include/clang/module.modulemap lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp lib/CodeGen/TargetInfo.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/builtins-wasm.c test/CodeGen/target-data.c test/CodeGen/wasm-arguments.c test/CodeGen/wasm-regparm.c test/CodeGenCXX/member-alignment.cpp test/CodeGenCXX/member-function-pointers.cpp test/CodeGenCXX/static-init-wasm.cpp test/Driver/wasm32-unknown-unknown.cpp test/Driver/wasm64-unknown-unknown.cpp test/Preprocessor/init.c Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -8419,3 +8419,603 @@ // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // XCORE:#define __LITTLE_ENDIAN__ 1 // XCORE:#define __XS1B__ 1 +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown < /dev/null | FileCheck -check-prefix=WEBASSEMBLY32 %s +// +// WEBASSEMBLY32:#define _ILP32 1 +// WEBASSEMBLY32-NOT:#define _LP64 +// WEBASSEMBLY32:#define __ATOMIC_ACQUIRE 2 +// WEBASSEMBLY32:#define __ATOMIC_ACQ_REL 4 +// WEBASSEMBLY32:#define __ATOMIC_CONSUME 1 +// WEBASSEMBLY32:#define __ATOMIC_RELAXED 0 +// WEBASSEMBLY32:#define __ATOMIC_RELEASE 3 +// WEBASSEMBLY32:#define __ATOMIC_SEQ_CST 5 +// WEBASSEMBLY32:#define __BIGGEST_ALIGNMENT__ 16 +// WEBASSEMBLY32:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +// WEBASSEMBLY32:#define __CHAR16_TYPE__ unsigned short +// WEBASSEMBLY32:#define __CHAR32_TYPE__ unsigned int +// WEBASSEMBLY32:#define __CHAR_BIT__ 8 +// WEBASSEMBLY32:#define __CONSTANT_CFSTRINGS__ 1 +// WEBASSEMBLY32:#define __DBL_DECIMAL_DIG__ 17 +// WEBASSEMBLY32:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 +// WEBASSEMBLY32:#define __DBL_DIG__ 15 +// WEBASSEMBLY32:#define __DBL_EPSILON__ 2.2204460492503131e-16 +// WEBASSEMBLY32:#define __DBL_HAS_DENORM__ 1 +// WEBASSEMBLY32:#define __DBL_HAS_INFINITY__ 1 +// WEBASSEMBLY32:#define __DBL_HAS_QUIET_NAN__ 1 +// WEBASSEMBLY32:#define __DBL_MANT_DIG__ 53 +// WEBASSEMBLY32:#define __DBL_MAX_10_EXP__ 308 +// WEBASSEMBLY32:#define __DBL_MAX_EXP__ 1024 +// WEBASSEMBLY32:#define __DBL_MAX__ 1.7976931348623157e+308 +// WEBASSEMBLY32:#define __DBL_MIN_10_EXP__ (-307) +// WEBASSEMBLY32:#define __DBL_MIN_EXP__ (-1021) +// WEBASSEMBLY32:#define __DBL_MIN__ 2.2250738585072014e-308 +// WEBASSEMBLY32:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ +// WEBASSEMBLY32:#define __FINITE_MATH_ONLY__ 0 +// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9 +// WEBASSEMBLY32:#define __FLT_DENORM_MIN__ 1.40129846e-45F +// WEBASSEMBLY32:#define __FLT_DIG__ 6 +// WEBASSEMBLY32:#define __FLT_EPSILON__ 1.19209290e-7F +// WEBASSEMBLY32:#define __FLT_EVAL_METHOD__ 0 +// WEBASSEMBLY32:#define __FLT_HAS_DENORM__ 1 +// WEBASSEMBLY32:#define __FLT_HAS_INFINITY__ 1 +// WEBASSEMBLY32:#define __FLT_HAS_QUIET_NAN__ 1 +// WEBASSEMBLY32:#define __FLT_MANT_DIG__ 24 +// WEBASSEMBLY32:#define __FLT_MAX_10_EXP__ 38 +// WEBASSEMBLY32:#define __FLT_MAX_EXP__ 128 +// WEBASSEMBLY32:#define __FLT_MAX__ 3.40282347e+38F +// WEBASSEMBLY32:#define __FLT_MIN_10_EXP__ (-37) +// WEBASSEMBLY32:#define __FLT_MIN_EXP__ (-125) +// WEBASSEMBLY32:#define __FLT_MIN__ 1.17549435e-38F +// WEBASSEMBLY32:#define __FLT_RADIX__ 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_BOOL_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_INT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1 +// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +// WEBASSEMBLY32:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GNUC_MINOR__ +// WEBASSEMBLY32:#define __GNUC_PATCHLEVEL__ +// WEBASSEMBLY32:#define __GNUC_STDC_INLINE__ 1 +// WEBASSEMBLY32:#define __GNUC__ +// WEBASSEMBLY32:#define __GXX_ABI_VERSION 1002 +// WEBASSEMBLY32:#define __GXX_RTTI 1 +// WEBASSEMBLY32:#define __ILP32__ 1 +// WEBASSEMBLY32:#define __INT16_C_SUFFIX__ {{$}} +// WEBASSEMBLY32:#define __INT16_FMTd__ "hd" +// WEBASSEMBLY32:#define __INT16_FMTi__ "hi" +// WEBASSEMBLY32:#define __INT16_MAX__ 32767 +// WEBASSEMBLY32:#define __INT16_TYPE__ short +// WEBASSEMBL
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish marked 2 inline comments as done. Comment at: lib/Basic/Targets.cpp:6935 @@ +6934,3 @@ + +public: + explicit WebAssemblyTargetInfo(const llvm::Triple &T) : TargetInfo(T) { I've now removed this (for now; we can discuss what to do in a later patch). Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
jfb added inline comments. Comment at: lib/Basic/Targets.cpp:6938 @@ +6937,3 @@ +BigEndian = false; +NoAsmVariants = true; +SuitableAlign = 128; True, leaving it as is sgtm. Comment at: lib/Basic/Targets.cpp:6994 @@ +6993,3 @@ +#include "clang/Basic/BuiltinsWebAssembly.def" +}; + Weird, the comment moved around. I put it on `WebAssembly32TargetInfo` which doesn't seem subclassed? Same for 64. Or is that going to be on the LLVM side? `final` on `getTargetDefines` instead? Comment at: test/Preprocessor/init.c:8478 @@ +8477,3 @@ +// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2 +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2 Yes, we don't know yet whether we guarantee atomicity so returning "maybe" is the conservative thing (which we can change in the future). We can discuss what we guarantee on the spec side, but for now the conservative thing is better IMO (and changing it isn't a problem, whereas changing "always" is a problem). FWIW [N4509](http://wg21.link/n4509) is relevant. Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish updated this revision to Diff 32192. sunfish marked an inline comment as done. sunfish added a comment. - set MaxAtomicInlineWidth to 0 for now (sets *_ATOMIC_*_LOCK_FREE to 1) - enable LargeArrayAlign - enable __int128 - various cleanups Repository: rL LLVM http://reviews.llvm.org/D12002 Files: include/clang/Basic/BuiltinsWebAssembly.def include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetCXXABI.h include/clang/module.modulemap lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp lib/CodeGen/TargetInfo.cpp lib/Driver/Driver.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/align-wasm.c test/CodeGen/builtins-wasm.c test/CodeGen/target-data.c test/CodeGen/wasm-arguments.c test/CodeGen/wasm-regparm.c test/CodeGenCXX/member-alignment.cpp test/CodeGenCXX/member-function-pointers.cpp test/CodeGenCXX/static-init-wasm.cpp test/Driver/wasm32-unknown-unknown.cpp test/Driver/wasm64-unknown-unknown.cpp test/Preprocessor/init.c Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -8419,3 +8419,607 @@ // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // XCORE:#define __LITTLE_ENDIAN__ 1 // XCORE:#define __XS1B__ 1 +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown < /dev/null | FileCheck -check-prefix=WEBASSEMBLY32 %s +// +// WEBASSEMBLY32:#define _ILP32 1{{$}} +// WEBASSEMBLY32-NOT:#define _LP64 +// WEBASSEMBLY32:#define __ATOMIC_ACQUIRE 2{{$}} +// WEBASSEMBLY32:#define __ATOMIC_ACQ_REL 4{{$}} +// WEBASSEMBLY32:#define __ATOMIC_CONSUME 1{{$}} +// WEBASSEMBLY32:#define __ATOMIC_RELAXED 0{{$}} +// WEBASSEMBLY32:#define __ATOMIC_RELEASE 3{{$}} +// WEBASSEMBLY32:#define __ATOMIC_SEQ_CST 5{{$}} +// WEBASSEMBLY32:#define __BIGGEST_ALIGNMENT__ 16{{$}} +// WEBASSEMBLY32:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__{{$}} +// WEBASSEMBLY32:#define __CHAR16_TYPE__ unsigned short{{$}} +// WEBASSEMBLY32:#define __CHAR32_TYPE__ unsigned int{{$}} +// WEBASSEMBLY32:#define __CHAR_BIT__ 8{{$}} +// WEBASSEMBLY32:#define __CONSTANT_CFSTRINGS__ 1{{$}} +// WEBASSEMBLY32:#define __DBL_DECIMAL_DIG__ 17{{$}} +// WEBASSEMBLY32:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324{{$}} +// WEBASSEMBLY32:#define __DBL_DIG__ 15{{$}} +// WEBASSEMBLY32:#define __DBL_EPSILON__ 2.2204460492503131e-16{{$}} +// WEBASSEMBLY32:#define __DBL_HAS_DENORM__ 1{{$}} +// WEBASSEMBLY32:#define __DBL_HAS_INFINITY__ 1{{$}} +// WEBASSEMBLY32:#define __DBL_HAS_QUIET_NAN__ 1{{$}} +// WEBASSEMBLY32:#define __DBL_MANT_DIG__ 53{{$}} +// WEBASSEMBLY32:#define __DBL_MAX_10_EXP__ 308{{$}} +// WEBASSEMBLY32:#define __DBL_MAX_EXP__ 1024{{$}} +// WEBASSEMBLY32:#define __DBL_MAX__ 1.7976931348623157e+308{{$}} +// WEBASSEMBLY32:#define __DBL_MIN_10_EXP__ (-307){{$}} +// WEBASSEMBLY32:#define __DBL_MIN_EXP__ (-1021){{$}} +// WEBASSEMBLY32:#define __DBL_MIN__ 2.2250738585072014e-308{{$}} +// WEBASSEMBLY32:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__{{$}} +// WEBASSEMBLY32:#define __FINITE_MATH_ONLY__ 0{{$}} +// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9{{$}} +// WEBASSEMBLY32:#define __FLT_DENORM_MIN__ 1.40129846e-45F{{$}} +// WEBASSEMBLY32:#define __FLT_DIG__ 6{{$}} +// WEBASSEMBLY32:#define __FLT_EPSILON__ 1.19209290e-7F{{$}} +// WEBASSEMBLY32:#define __FLT_EVAL_METHOD__ 0{{$}} +// WEBASSEMBLY32:#define __FLT_HAS_DENORM__ 1{{$}} +// WEBASSEMBLY32:#define __FLT_HAS_INFINITY__ 1{{$}} +// WEBASSEMBLY32:#define __FLT_HAS_QUIET_NAN__ 1{{$}} +// WEBASSEMBLY32:#define __FLT_MANT_DIG__ 24{{$}} +// WEBASSEMBLY32:#define __FLT_MAX_10_EXP__ 38{{$}} +// WEBASSEMBLY32:#define __FLT_MAX_EXP__ 128{{$}} +// WEBASSEMBLY32:#define __FLT_MAX__ 3.40282347e+38F{{$}} +// WEBASSEMBLY32:#define __FLT_MIN_10_EXP__ (-37){{$}} +// WEBASSEMBLY32:#define __FLT_MIN_EXP__ (-125){{$}} +// WEBASSEMBLY32:#define __FLT_MIN__ 1.17549435e-38F{{$}} +// WEBASSEMBLY32:#define __FLT_RADIX__ 2{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_BOOL_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_INT_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GNUC_MINOR__ +// WEBASSEMBLY32:#define __GNUC_PATCHLEVEL__ +// WEBASSEMBLY32:#define __GNUC_STDC_INLINE__ 1{{$}} +// WEBASSEMBLY32:#define __GNUC__ +// WEBA
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish added inline comments. Comment at: lib/Basic/Targets.cpp:7010 @@ +7009,3 @@ + { #ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr }, +#include "clang/Basic/BuiltinsWebAssembly.def" +}; WebAssembly32TargetInfo is subclassed in LLVM code, and getTargetDefines is overridden. Comment at: test/Preprocessor/init.c:8478 @@ +8477,3 @@ +// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 1{{$}} Ok, I've set MaxAtomicInlineWidth to 0 for now so that we don't block the rest of the patch on this issue. N4509 is just about exposing the same information via a different interface. Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
jfb accepted this revision. jfb added a comment. This revision is now accepted and ready to land. lgtm Comment at: lib/Basic/Targets.cpp:7002 @@ +7001,3 @@ + bool isCLZForZeroUndef() const override final { return false; } + bool hasInt128Type() const override final { return true; } +}; Does int 128 get expanded in legalization? Seems good. Comment at: test/Preprocessor/init.c:8478 @@ +8477,3 @@ +// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 1{{$}} +// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 1{{$}} sunfish wrote: > Ok, I've set MaxAtomicInlineWidth to 0 for now so that we don't block the > rest of the patch on this issue. > > N4509 is just about exposing the same information via a different interface. `constexpr` makes a world of difference I'm told :-) Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish updated this revision to Diff 32485. sunfish marked an inline comment as done. sunfish added a comment. The patch evolved enough to prompt posting one more new version; major changes: - make constructors and destructors return this - enable -fuse-init-array - enable -fno-common - disable -mdisable-fp-elim - put static init code in ".text.__startup" - define a "+simd128" feature, -msimd128 option, __wasm_simd128__ macro - ignore empty struct arguments and return values - more tests Repository: rL LLVM http://reviews.llvm.org/D12002 Files: include/clang/Basic/BuiltinsWebAssembly.def include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetCXXABI.h include/clang/Driver/Options.td include/clang/module.modulemap lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp lib/CodeGen/TargetInfo.cpp lib/Driver/Driver.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/align-wasm.c test/CodeGen/builtins-wasm.c test/CodeGen/target-data.c test/CodeGen/wasm-arguments.c test/CodeGen/wasm-regparm.c test/CodeGenCXX/constructor-destructor-return-this.cpp test/CodeGenCXX/member-alignment.cpp test/CodeGenCXX/member-function-pointers.cpp test/CodeGenCXX/static-init-wasm.cpp test/CodeGenCXX/wasm-args-returns.cpp test/Driver/wasm32-unknown-unknown.cpp test/Driver/wasm64-unknown-unknown.cpp test/Preprocessor/init.c test/Preprocessor/wasm-target-features.c Index: test/Preprocessor/wasm-target-features.c === --- test/Preprocessor/wasm-target-features.c +++ test/Preprocessor/wasm-target-features.c @@ -0,0 +1,35 @@ +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -msimd128 \ +// RUN: | FileCheck %s -check-prefix=SIMD128 +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -msimd128 \ +// RUN: | FileCheck %s -check-prefix=SIMD128 +// +// SIMD128:#define __wasm_simd128__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=mvp \ +// RUN: | FileCheck %s -check-prefix=MVP +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=mvp \ +// RUN: | FileCheck %s -check-prefix=MVP +// +// MVP-NOT:#define __wasm_simd128__ +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// +// BLEEDING_EDGE:#define __wasm_simd128__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// +// BLEEDING_EDGE_NO_SIMD128-NOT:#define __wasm_simd128__ Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -8419,3 +8419,623 @@ // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // XCORE:#define __LITTLE_ENDIAN__ 1 // XCORE:#define __XS1B__ 1 +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown \ +// RUN: < /dev/null \ +// RUN: | FileCheck -check-prefix=WEBASSEMBLY32 %s +// +// WEBASSEMBLY32:#define _ILP32 1{{$}} +// WEBASSEMBLY32-NOT:#define _LP64 +// WEBASSEMBLY32-NEXT:#define __ATOMIC_ACQUIRE 2{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_ACQ_REL 4{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_CONSUME 1{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_RELAXED 0{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_RELEASE 3{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_SEQ_CST 5{{$}} +// WEBASSEMBLY32-NEXT:#define __BIGGEST_ALIGNMENT__ 16{{$}} +// WEBASSEMBLY32-NEXT:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR16_TYPE__ unsigned short{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR32_TYPE__ unsigned int{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR_BIT__ 8{{$}} +// WEBASSEMBLY32-NEXT:#define __CONSTANT_CFSTRINGS__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DECIMAL_DIG__ 17{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DIG__ 15{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_EPSILON__ 2.2204460492503131e-16{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_DENORM__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_INFINITY__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_QUIET_NAN__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MANT_DIG__
Re: [PATCH] D12002: Initial WebAssembly support in clang
jfb added a comment. Still lgtm, with minor comments. Comment at: lib/CodeGen/ItaniumCXXABI.cpp:364 @@ +363,3 @@ +ItaniumCXXABI(CGM, /* UseARMMethodPtrABI = */ true, + /* UseARMGuardVarABI = */ true) {} + It's more common to have no spaces for these comments: `/*UseARMMethodPtrABI=*/true,`. Comment at: lib/Driver/Tools.cpp:1567 @@ +1566,3 @@ + +#ifdef __wasm__ +// Handle "native" by examining the host. Could you expand a bit on why "native" doesn't make sense if LLVM itself wasn't compiled for wasm? Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish marked 2 inline comments as done. Comment at: lib/CodeGen/ItaniumCXXABI.cpp:364 @@ +363,3 @@ +ItaniumCXXABI(CGM, /* UseARMMethodPtrABI = */ true, + /* UseARMGuardVarABI = */ true) {} + jfb wrote: > It's more common to have no spaces for these comments: > `/*UseARMMethodPtrABI=*/true,`. Ok. I updated this in my local patch. Comment at: lib/Driver/Tools.cpp:1567 @@ +1566,3 @@ + +#ifdef __wasm__ +// Handle "native" by examining the host. jfb wrote: > Could you expand a bit on why "native" doesn't make sense if LLVM itself > wasn't compiled for wasm? Ok. I added a comment to my local patch that says: "native" isn't meaningful when cross compiling, so only support this when the host is also WebAssembly. Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish updated this revision to Diff 33611. sunfish marked 2 inline comments as done. sunfish added a comment. Herald added a subscriber: dschuff. Minor updates to keep the patch building and working as code changes around it. Also enabled -mthread-model. Repository: rL LLVM http://reviews.llvm.org/D12002 Files: include/clang/Basic/BuiltinsWebAssembly.def include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetCXXABI.h include/clang/Driver/Options.td include/clang/module.modulemap lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp lib/CodeGen/TargetInfo.cpp lib/Driver/Driver.cpp lib/Driver/ToolChain.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/align-wasm.c test/CodeGen/builtins-wasm.c test/CodeGen/target-data.c test/CodeGen/wasm-arguments.c test/CodeGen/wasm-regparm.c test/CodeGenCXX/constructor-destructor-return-this.cpp test/CodeGenCXX/member-alignment.cpp test/CodeGenCXX/member-function-pointers.cpp test/CodeGenCXX/static-init-wasm.cpp test/CodeGenCXX/wasm-args-returns.cpp test/Driver/thread-model.c test/Driver/wasm32-unknown-unknown.cpp test/Driver/wasm64-unknown-unknown.cpp test/Preprocessor/init.c test/Preprocessor/wasm-target-features.c Index: test/Preprocessor/wasm-target-features.c === --- test/Preprocessor/wasm-target-features.c +++ test/Preprocessor/wasm-target-features.c @@ -0,0 +1,35 @@ +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -msimd128 \ +// RUN: | FileCheck %s -check-prefix=SIMD128 +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -msimd128 \ +// RUN: | FileCheck %s -check-prefix=SIMD128 +// +// SIMD128:#define __wasm_simd128__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=mvp \ +// RUN: | FileCheck %s -check-prefix=MVP +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=mvp \ +// RUN: | FileCheck %s -check-prefix=MVP +// +// MVP-NOT:#define __wasm_simd128__ +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// +// BLEEDING_EDGE:#define __wasm_simd128__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// +// BLEEDING_EDGE_NO_SIMD128-NOT:#define __wasm_simd128__ Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -8419,3 +8419,635 @@ // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // XCORE:#define __LITTLE_ENDIAN__ 1 // XCORE:#define __XS1B__ 1 +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown \ +// RUN: < /dev/null \ +// RUN: | FileCheck -check-prefix=WEBASSEMBLY32 %s +// +// WEBASSEMBLY32:#define _ILP32 1{{$}} +// WEBASSEMBLY32-NOT:#define _LP64 +// WEBASSEMBLY32-NEXT:#define __ATOMIC_ACQUIRE 2{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_ACQ_REL 4{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_CONSUME 1{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_RELAXED 0{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_RELEASE 3{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_SEQ_CST 5{{$}} +// WEBASSEMBLY32-NEXT:#define __BIGGEST_ALIGNMENT__ 16{{$}} +// WEBASSEMBLY32-NEXT:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR16_TYPE__ unsigned short{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR32_TYPE__ unsigned int{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR_BIT__ 8{{$}} +// WEBASSEMBLY32-NOT:#define __CHAR_UNSIGNED__ +// WEBASSEMBLY32-NEXT:#define __CONSTANT_CFSTRINGS__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DECIMAL_DIG__ 17{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DIG__ 15{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_EPSILON__ 2.2204460492503131e-16{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_DENORM__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_INFINITY__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_QUIET_NAN__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MANT_DIG__ 53{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MAX_10_EXP__ 308{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MAX_EXP__ 1024{{$}} +// WEBAS
Re: [PATCH] D12002: Initial WebAssembly support in clang
echristo added a subscriber: echristo. echristo added a comment. Some inline comments. Thanks! -eric Comment at: include/clang/Basic/TargetCXXABI.h:166 @@ -148,1 +165,3 @@ + /// \brief Are member functions differently aligned? + bool areMemberFunctionsAligned() const { Can you elaborate on the comment here as to what the alignment here means or something? It looks incomplete otherwise. Comment at: lib/Basic/Targets.cpp:6935-6941 @@ +6934,9 @@ + if (Feature == "+simd128") { +SIMDLevel = std::max(SIMDLevel, SIMD128); +continue; + } + if (Feature == "-simd128") { +SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1)); +continue; + } + Might make sense to copy the x86 bits here? Comment at: lib/Basic/Targets.cpp:7633-7658 @@ -7464,1 +7632,28 @@ } + case llvm::Triple::wasm32: { +// Until specific variations are defined, don't permit any. +if (Triple.getSubArch() != llvm::Triple::NoSubArch || +Triple.getVendor() != llvm::Triple::UnknownVendor || +Triple.getOS() != llvm::Triple::UnknownOS || +Triple.getEnvironment() != llvm::Triple::UnknownEnvironment || +Triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); + } + case llvm::Triple::wasm64: { +// Until specific variations are defined, don't permit any. +if (Triple.getSubArch() != llvm::Triple::NoSubArch || +Triple.getVendor() != llvm::Triple::UnknownVendor || +Triple.getOS() != llvm::Triple::UnknownOS || +Triple.getEnvironment() != llvm::Triple::UnknownEnvironment || +Triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); Seems overly complicated? Maybe just a positive test? Comment at: lib/CodeGen/CodeGenModule.cpp:824 @@ +823,3 @@ + if (getTarget().getCXXABI().areMemberFunctionsAligned()) { +// C++ ABI requires 2-byte alignment for member functions. +if (F->getAlignment() < 2 && isa(D)) Update the comment? Comment at: lib/Driver/ToolChains.cpp:3853-3873 @@ +3852,23 @@ + +bool WebAssembly::IsMathErrnoDefault() const { return false; } + +bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } + +bool WebAssembly::UseObjCMixedDispatch() const { return true; } + +bool WebAssembly::isPICDefault() const { return false; } + +bool WebAssembly::isPIEDefault() const { return false; } + +bool WebAssembly::isPICDefaultForced() const { return false; } + +bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } + +// TODO: Support Objective C stuff. +bool WebAssembly::SupportsObjCGC() const { return false; } + +bool WebAssembly::hasBlocksRuntime() const { return false; } + +// TODO: Support profiling. +bool WebAssembly::SupportsProfiling() const { return false; } + No generic defaults here? Might also make sense to have these all inline if they're just return true/return false. Comment at: lib/Driver/Tools.cpp:1564-1569 @@ +1563,8 @@ + +#ifdef __wasm__ +// Handle "native" by examining the host. "native" isn't meaningful when +// cross compiling, so only support this when the host is also WebAssembly. +if (CPU == "native") + return llvm::sys::getHostCPUName(); +#endif + I really dislike the idea of an ifdef here for this behavior. Can you explain some more? :) Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish added a comment. Thanks for the review! Comment at: include/clang/Basic/TargetCXXABI.h:166 @@ -148,1 +165,3 @@ + /// \brief Are member functions differently aligned? + bool areMemberFunctionsAligned() const { echristo wrote: > Can you elaborate on the comment here as to what the alignment here means or > something? It looks incomplete otherwise. Ok, I'll add a longer comment. Comment at: lib/Basic/Targets.cpp:6935-6941 @@ +6934,9 @@ + if (Feature == "+simd128") { +SIMDLevel = std::max(SIMDLevel, SIMD128); +continue; + } + if (Feature == "-simd128") { +SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1)); +continue; + } + echristo wrote: > Might make sense to copy the x86 bits here? The x86 bits don't handle "-" attributes, so it's not directly applicable. Comment at: lib/Basic/Targets.cpp:7633-7658 @@ -7464,1 +7632,28 @@ } + case llvm::Triple::wasm32: { +// Until specific variations are defined, don't permit any. +if (Triple.getSubArch() != llvm::Triple::NoSubArch || +Triple.getVendor() != llvm::Triple::UnknownVendor || +Triple.getOS() != llvm::Triple::UnknownOS || +Triple.getEnvironment() != llvm::Triple::UnknownEnvironment || +Triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); + } + case llvm::Triple::wasm64: { +// Until specific variations are defined, don't permit any. +if (Triple.getSubArch() != llvm::Triple::NoSubArch || +Triple.getVendor() != llvm::Triple::UnknownVendor || +Triple.getOS() != llvm::Triple::UnknownOS || +Triple.getEnvironment() != llvm::Triple::UnknownEnvironment || +Triple.getObjectFormat() != llvm::Triple::UnknownObjectFormat || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); echristo wrote: > Seems overly complicated? Maybe just a positive test? Good idea. I'll do that. Comment at: lib/CodeGen/CodeGenModule.cpp:824 @@ +823,3 @@ + if (getTarget().getCXXABI().areMemberFunctionsAligned()) { +// C++ ABI requires 2-byte alignment for member functions. +if (F->getAlignment() < 2 && isa(D)) echristo wrote: > Update the comment? Ok, I'll write a bit more here. Comment at: lib/Driver/ToolChains.cpp:3853-3873 @@ +3852,23 @@ + +bool WebAssembly::IsMathErrnoDefault() const { return false; } + +bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; } + +bool WebAssembly::UseObjCMixedDispatch() const { return true; } + +bool WebAssembly::isPICDefault() const { return false; } + +bool WebAssembly::isPIEDefault() const { return false; } + +bool WebAssembly::isPICDefaultForced() const { return false; } + +bool WebAssembly::IsIntegratedAssemblerDefault() const { return true; } + +// TODO: Support Objective C stuff. +bool WebAssembly::SupportsObjCGC() const { return false; } + +bool WebAssembly::hasBlocksRuntime() const { return false; } + +// TODO: Support profiling. +bool WebAssembly::SupportsProfiling() const { return false; } + echristo wrote: > No generic defaults here? Might also make sense to have these all inline if > they're just return true/return false. All these functions are returning non-default values or are overriding pure virtual functions. And they're outline because they're virtual overrides, so there's little optimization advantage to defining them in the header. And it's what most of the other toolchain definitions do most of the time. Comment at: lib/Driver/Tools.cpp:1564-1569 @@ +1563,8 @@ + +#ifdef __wasm__ +// Handle "native" by examining the host. "native" isn't meaningful when +// cross compiling, so only support this when the host is also WebAssembly. +if (CPU == "native") + return llvm::sys::getHostCPUName(); +#endif + echristo wrote: > I really dislike the idea of an ifdef here for this behavior. Can you explain > some more? :) As we discussed on IRC, I'll remove this code for now. Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfish updated this revision to Diff 33637. sunfish added a comment. Updated to address review comments: - added comments - simplified Triple validation code - removed -mcpu="native" code Repository: rL LLVM http://reviews.llvm.org/D12002 Files: include/clang/Basic/BuiltinsWebAssembly.def include/clang/Basic/TargetBuiltins.h include/clang/Basic/TargetCXXABI.h include/clang/Driver/Options.td include/clang/module.modulemap lib/AST/ASTContext.cpp lib/Basic/Targets.cpp lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/ItaniumCXXABI.cpp lib/CodeGen/TargetInfo.cpp lib/Driver/Driver.cpp lib/Driver/ToolChain.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/align-wasm.c test/CodeGen/builtins-wasm.c test/CodeGen/target-data.c test/CodeGen/wasm-arguments.c test/CodeGen/wasm-regparm.c test/CodeGenCXX/constructor-destructor-return-this.cpp test/CodeGenCXX/member-alignment.cpp test/CodeGenCXX/member-function-pointers.cpp test/CodeGenCXX/static-init-wasm.cpp test/CodeGenCXX/wasm-args-returns.cpp test/Driver/thread-model.c test/Driver/wasm32-unknown-unknown.cpp test/Driver/wasm64-unknown-unknown.cpp test/Preprocessor/init.c test/Preprocessor/wasm-target-features.c Index: test/Preprocessor/wasm-target-features.c === --- test/Preprocessor/wasm-target-features.c +++ test/Preprocessor/wasm-target-features.c @@ -0,0 +1,35 @@ +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -msimd128 \ +// RUN: | FileCheck %s -check-prefix=SIMD128 +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -msimd128 \ +// RUN: | FileCheck %s -check-prefix=SIMD128 +// +// SIMD128:#define __wasm_simd128__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=mvp \ +// RUN: | FileCheck %s -check-prefix=MVP +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=mvp \ +// RUN: | FileCheck %s -check-prefix=MVP +// +// MVP-NOT:#define __wasm_simd128__ +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE +// +// BLEEDING_EDGE:#define __wasm_simd128__ 1{{$}} +// +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm32-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// RUN: %clang -E -dM %s -o - 2>&1 \ +// RUN: -target wasm64-unknown-unknown -mcpu=bleeding-edge -mno-simd128 \ +// RUN: | FileCheck %s -check-prefix=BLEEDING_EDGE_NO_SIMD128 +// +// BLEEDING_EDGE_NO_SIMD128-NOT:#define __wasm_simd128__ Index: test/Preprocessor/init.c === --- test/Preprocessor/init.c +++ test/Preprocessor/init.c @@ -8419,3 +8419,635 @@ // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ // XCORE:#define __LITTLE_ENDIAN__ 1 // XCORE:#define __XS1B__ 1 +// +// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown \ +// RUN: < /dev/null \ +// RUN: | FileCheck -check-prefix=WEBASSEMBLY32 %s +// +// WEBASSEMBLY32:#define _ILP32 1{{$}} +// WEBASSEMBLY32-NOT:#define _LP64 +// WEBASSEMBLY32-NEXT:#define __ATOMIC_ACQUIRE 2{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_ACQ_REL 4{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_CONSUME 1{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_RELAXED 0{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_RELEASE 3{{$}} +// WEBASSEMBLY32-NEXT:#define __ATOMIC_SEQ_CST 5{{$}} +// WEBASSEMBLY32-NEXT:#define __BIGGEST_ALIGNMENT__ 16{{$}} +// WEBASSEMBLY32-NEXT:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR16_TYPE__ unsigned short{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR32_TYPE__ unsigned int{{$}} +// WEBASSEMBLY32-NEXT:#define __CHAR_BIT__ 8{{$}} +// WEBASSEMBLY32-NOT:#define __CHAR_UNSIGNED__ +// WEBASSEMBLY32-NEXT:#define __CONSTANT_CFSTRINGS__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DECIMAL_DIG__ 17{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_DIG__ 15{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_EPSILON__ 2.2204460492503131e-16{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_DENORM__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_INFINITY__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_HAS_QUIET_NAN__ 1{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MANT_DIG__ 53{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MAX_10_EXP__ 308{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MAX_EXP__ 1024{{$}} +// WEBASSEMBLY32-NEXT:#define __DBL_MAX__ 1.7976931348623157e+308{{$}} +// W
Re: [PATCH] D12002: Initial WebAssembly support in clang
echristo accepted this revision. echristo added a reviewer: echristo. echristo added a comment. A couple things inline that need changing, but feel free to commit after without a repost. -eric Comment at: lib/Basic/Targets.cpp:6943-6944 @@ +6942,4 @@ + + Diags.Report(diag::err_opt_not_valid_with_opt) << Feature + << "-target-feature"; + return false; The backend should handle any weirdness here with missing features especially as this will report an error based on -cc1 compilation and not the main command line. I.e. it's not necessary, that said if you feel wedded to it there's no problem either. Comment at: lib/Basic/Targets.cpp:7635-7639 @@ +7634,7 @@ +// Until specific variations are defined, don't permit any. +if (!(Triple == llvm::Triple("wasm32-unknown-unknown")) || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; Why not just a positive test? Comment at: lib/Basic/Targets.cpp:7643-7649 @@ +7642,9 @@ + case llvm::Triple::wasm64: +// Until specific variations are defined, don't permit any. +if (!(Triple == llvm::Triple("wasm64-unknown-unknown")) || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); Ditto. (I said this just below, but it seems to have gotten munged in the newer version) Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfishcode added a subscriber: sunfishcode. Comment at: lib/Basic/Targets.cpp:6943-6944 @@ +6942,4 @@ + + Diags.Report(diag::err_opt_not_valid_with_opt) << Feature + << "-target-feature"; + return false; echristo wrote: > The backend should handle any weirdness here with missing features especially > as this will report an error based on -cc1 compilation and not the main > command line. > > I.e. it's not necessary, that said if you feel wedded to it there's no > problem either. I do feel more comfortable rejecting anything that I'm not specifically expecting in this area. Comment at: lib/Basic/Targets.cpp:7643-7649 @@ +7642,9 @@ + case llvm::Triple::wasm64: +// Until specific variations are defined, don't permit any. +if (!(Triple == llvm::Triple("wasm64-unknown-unknown")) || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); echristo wrote: > Ditto. > > (I said this just below, but it seems to have gotten munged in the newer > version) I actually did see your comment and updated the code accordingly. It now does a positive test, `Triple == llvm::Triple("wasm64-unknown-unknown")`, which is simpler than what it did before. However, it's also doing additional tests, because the Triple class's operator== doesn't distinguish between an Unknown that was actually "unknown" or an unknown that was some other string. Until we figure out what "vendor", "OS", and "environment" variations of wasm make sense (if any), we want to avoid dealing with accidental alternate triples. Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
echristo added inline comments. Comment at: lib/Basic/Targets.cpp:7643-7649 @@ +7642,9 @@ + case llvm::Triple::wasm64: +// Until specific variations are defined, don't permit any. +if (!(Triple == llvm::Triple("wasm64-unknown-unknown")) || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); sunfishcode wrote: > echristo wrote: > > Ditto. > > > > (I said this just below, but it seems to have gotten munged in the newer > > version) > I actually did see your comment and updated the code accordingly. It now does > a positive test, `Triple == llvm::Triple("wasm64-unknown-unknown")`, which is > simpler than what it did before. > > However, it's also doing additional tests, because the Triple class's > operator== doesn't distinguish between an Unknown that was actually "unknown" > or an unknown that was some other string. Until we figure out what "vendor", > "OS", and "environment" variations of wasm make sense (if any), we want to > avoid dealing with accidental alternate triples. I think this is a lot of overkill here, no other target cares about this so why should the wasm target? If it's that important maybe fix Triple? Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12002: Initial WebAssembly support in clang
This revision was automatically updated to reflect the committed changes. Closed by commit rL246814: [WebAssembly] Initial WebAssembly support in clang (authored by djg). Changed prior to commit: http://reviews.llvm.org/D12002?vs=33637&id=33985#toc Repository: rL LLVM http://reviews.llvm.org/D12002 Files: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def cfe/trunk/include/clang/Basic/TargetBuiltins.h cfe/trunk/include/clang/Basic/TargetCXXABI.h cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/module.modulemap cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/Basic/Targets.cpp cfe/trunk/lib/CodeGen/CGBuiltin.cpp cfe/trunk/lib/CodeGen/CodeGenFunction.h cfe/trunk/lib/CodeGen/CodeGenModule.cpp cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/lib/CodeGen/TargetInfo.cpp cfe/trunk/lib/Driver/Driver.cpp cfe/trunk/lib/Driver/ToolChain.cpp cfe/trunk/lib/Driver/ToolChains.cpp cfe/trunk/lib/Driver/ToolChains.h cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/CodeGen/align-wasm.c cfe/trunk/test/CodeGen/builtins-wasm.c cfe/trunk/test/CodeGen/target-data.c cfe/trunk/test/CodeGen/wasm-arguments.c cfe/trunk/test/CodeGen/wasm-regparm.c cfe/trunk/test/CodeGenCXX/constructor-destructor-return-this.cpp cfe/trunk/test/CodeGenCXX/member-alignment.cpp cfe/trunk/test/CodeGenCXX/member-function-pointers.cpp cfe/trunk/test/CodeGenCXX/static-init-wasm.cpp cfe/trunk/test/CodeGenCXX/wasm-args-returns.cpp cfe/trunk/test/Driver/thread-model.c cfe/trunk/test/Driver/wasm32-unknown-unknown.cpp cfe/trunk/test/Driver/wasm64-unknown-unknown.cpp cfe/trunk/test/Preprocessor/init.c cfe/trunk/test/Preprocessor/wasm-target-features.c Index: cfe/trunk/include/clang/Basic/TargetBuiltins.h === --- cfe/trunk/include/clang/Basic/TargetBuiltins.h +++ cfe/trunk/include/clang/Basic/TargetBuiltins.h @@ -185,6 +185,17 @@ 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 Index: cfe/trunk/include/clang/Basic/TargetCXXABI.h === --- cfe/trunk/include/clang/Basic/TargetCXXABI.h +++ cfe/trunk/include/clang/Basic/TargetCXXABI.h @@ -85,6 +85,21 @@ /// - 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 @@ case iOS: case iOS64: case GenericMIPS: +case WebAssembly: return true; case Microsoft: @@ -138,14 +154,44 @@ case iOS: case iOS64: case GenericMIPS: +case WebAssembly: return false; case Microsoft: return true; } 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: +
Re: [PATCH] D12002: Initial WebAssembly support in clang
sunfishcode added inline comments. Comment at: lib/Basic/Targets.cpp:7643-7649 @@ +7642,9 @@ + case llvm::Triple::wasm64: +// Until specific variations are defined, don't permit any. +if (!(Triple == llvm::Triple("wasm64-unknown-unknown")) || +(!Triple.getVendorName().empty() && + Triple.getVendorName() != "unknown") || +(!Triple.getOSName().empty() && Triple.getOSName() != "unknown") || +(Triple.hasEnvironment() && Triple.getEnvironmentName() != "unknown")) + return nullptr; +return new WebAssemblyOSTargetInfo(Triple); echristo wrote: > sunfishcode wrote: > > echristo wrote: > > > Ditto. > > > > > > (I said this just below, but it seems to have gotten munged in the newer > > > version) > > I actually did see your comment and updated the code accordingly. It now > > does a positive test, `Triple == llvm::Triple("wasm64-unknown-unknown")`, > > which is simpler than what it did before. > > > > However, it's also doing additional tests, because the Triple class's > > operator== doesn't distinguish between an Unknown that was actually > > "unknown" or an unknown that was some other string. Until we figure out > > what "vendor", "OS", and "environment" variations of wasm make sense (if > > any), we want to avoid dealing with accidental alternate triples. > I think this is a lot of overkill here, no other target cares about this so > why should the wasm target? If it's that important maybe fix Triple? This Triple issue is not important enough to hold up the rest of the patch for, so I just removed it. Thanks for the review! Repository: rL LLVM http://reviews.llvm.org/D12002 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits