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 | c285307e1457c4db2346443a4336e672d7487111 (patch) | |
tree | c802922c6e228f80d4ca3cfd6fbdfd16c6179f0f /clang/lib/Driver/Tools.cpp | |
parent | e6702ca0e24fd6674770f3cac7e2b0e590e095bb (diff) | |
download | bcm5719-llvm-c285307e1457c4db2346443a4336e672d7487111.tar.gz bcm5719-llvm-c285307e1457c4db2346443a4336e672d7487111.zip |
[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
llvm-svn: 246814
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index eb245b38e09..fdb1b1815c4 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -484,6 +484,8 @@ static bool isNoCommonDefault(const llvm::Triple &Triple) { return false; case llvm::Triple::xcore: + case llvm::Triple::wasm32: + case llvm::Triple::wasm64: return true; } } @@ -1553,6 +1555,25 @@ static const char *getX86TargetCPU(const ArgList &Args, } } +/// Get the (LLVM) name of the WebAssembly cpu we are targeting. +static StringRef getWebAssemblyTargetCPU(const ArgList &Args) { + // If we have -mcpu=, use that. + if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) { + StringRef CPU = A->getValue(); + +#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 + + return CPU; + } + + return "generic"; +} + static std::string getCPUName(const ArgList &Args, const llvm::Triple &T, bool FromAs = false) { switch (T.getArch()) { @@ -1625,6 +1646,10 @@ static std::string getCPUName(const ArgList &Args, const llvm::Triple &T, case llvm::Triple::r600: case llvm::Triple::amdgcn: return getR600TargetGPU(Args); + + case llvm::Triple::wasm32: + case llvm::Triple::wasm64: + return getWebAssemblyTargetCPU(Args); } } @@ -2074,6 +2099,24 @@ static void getAArch64TargetFeatures(const Driver &D, Features.push_back("+reserve-x18"); } +static void getWebAssemblyTargetFeatures(const ArgList &Args, + std::vector<const char *> &Features) { + for (const Arg *A : Args.filtered(options::OPT_m_wasm_Features_Group)) { + StringRef Name = A->getOption().getName(); + A->claim(); + + // Skip over "-m". + assert(Name.startswith("m") && "Invalid feature name."); + Name = Name.substr(1); + + bool IsNegative = Name.startswith("no-"); + if (IsNegative) + Name = Name.substr(3); + + Features.push_back(Args.MakeArgString((IsNegative ? "-" : "+") + Name)); + } +} + static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, ArgStringList &CmdArgs, bool ForAS) { @@ -2111,6 +2154,10 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, case llvm::Triple::x86_64: getX86TargetFeatures(D, Triple, Args, Features); break; + case llvm::Triple::wasm32: + case llvm::Triple::wasm64: + getWebAssemblyTargetFeatures(Args, Features); + break; } // Find the last of each feature. @@ -2590,9 +2637,15 @@ static bool areOptimizationsEnabled(const ArgList &Args) { static bool shouldUseFramePointerForTarget(const ArgList &Args, const llvm::Triple &Triple) { - // XCore never wants frame pointers, regardless of OS. - if (Triple.getArch() == llvm::Triple::xcore) { + switch (Triple.getArch()) { + case llvm::Triple::xcore: + case llvm::Triple::wasm32: + case llvm::Triple::wasm64: + // XCore never wants frame pointers, regardless of OS. + // WebAssembly never wants frame pointers. return false; + default: + break; } if (Triple.isOSLinux()) { |