diff options
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()) { |