diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Driver/ToolChains/Arch/AArch64.cpp | 81 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Arch/ARM.cpp | 20 |
2 files changed, 101 insertions, 0 deletions
diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp index c76a31a315c..1dc516b9638 100644 --- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp +++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp @@ -219,6 +219,87 @@ fp16_fml_fallthrough: Features.push_back("+fullfp16"); } + // FIXME: this needs reimplementation too after the TargetParser rewrite + // + // Context sensitive meaning of Crypto: + // 1) For Arch >= ARMv8.4a: crypto = sm4 + sha3 + sha2 + aes + // 2) For Arch <= ARMv8.3a: crypto = sha2 + aes + const auto ItBegin = Features.begin(); + const auto ItEnd = Features.end(); + const auto ItRBegin = Features.rbegin(); + const auto ItREnd = Features.rend(); + const auto ItRCrypto = std::find(ItRBegin, ItREnd, "+crypto"); + const auto ItRNoCrypto = std::find(ItRBegin, ItREnd, "-crypto"); + const auto HasCrypto = ItRCrypto != ItREnd; + const auto HasNoCrypto = ItRNoCrypto != ItREnd; + const ptrdiff_t PosCrypto = ItRCrypto - ItRBegin; + const ptrdiff_t PosNoCrypto = ItRNoCrypto - ItRBegin; + + bool NoCrypto = false; + if (HasCrypto && HasNoCrypto) { + if (PosNoCrypto < PosCrypto) + NoCrypto = true; + } + + if (std::find(ItBegin, ItEnd, "+v8.4a") != ItEnd) { + if (HasCrypto && !NoCrypto) { + // Check if we have NOT disabled an algorithm with something like: + // +crypto, -algorithm + // And if "-algorithm" does not occur, we enable that crypto algorithm. + const bool HasSM4 = (std::find(ItBegin, ItEnd, "-sm4") == ItEnd); + const bool HasSHA3 = (std::find(ItBegin, ItEnd, "-sha3") == ItEnd); + const bool HasSHA2 = (std::find(ItBegin, ItEnd, "-sha2") == ItEnd); + const bool HasAES = (std::find(ItBegin, ItEnd, "-aes") == ItEnd); + if (HasSM4) + Features.push_back("+sm4"); + if (HasSHA3) + Features.push_back("+sha3"); + if (HasSHA2) + Features.push_back("+sha2"); + if (HasAES) + Features.push_back("+aes"); + } else if (HasNoCrypto) { + // Check if we have NOT enabled a crypto algorithm with something like: + // -crypto, +algorithm + // And if "+algorithm" does not occur, we disable that crypto algorithm. + const bool HasSM4 = (std::find(ItBegin, ItEnd, "+sm4") != ItEnd); + const bool HasSHA3 = (std::find(ItBegin, ItEnd, "+sha3") != ItEnd); + const bool HasSHA2 = (std::find(ItBegin, ItEnd, "+sha2") != ItEnd); + const bool HasAES = (std::find(ItBegin, ItEnd, "+aes") != ItEnd); + if (!HasSM4) + Features.push_back("-sm4"); + if (!HasSHA3) + Features.push_back("-sha3"); + if (!HasSHA2) + Features.push_back("-sha2"); + if (!HasAES) + Features.push_back("-aes"); + } + } else { + if (HasCrypto && !NoCrypto) { + const bool HasSHA2 = (std::find(ItBegin, ItEnd, "-sha2") == ItEnd); + const bool HasAES = (std::find(ItBegin, ItEnd, "-aes") == ItEnd); + if (HasSHA2) + Features.push_back("+sha2"); + if (HasAES) + Features.push_back("+aes"); + } else if (HasNoCrypto) { + const bool HasSHA2 = (std::find(ItBegin, ItEnd, "+sha2") != ItEnd); + const bool HasAES = (std::find(ItBegin, ItEnd, "+aes") != ItEnd); + const bool HasV82a = (std::find(ItBegin, ItEnd, "+v8.2a") != ItEnd); + const bool HasV83a = (std::find(ItBegin, ItEnd, "+v8.3a") != ItEnd); + const bool HasV84a = (std::find(ItBegin, ItEnd, "+v8.4a") != ItEnd); + if (!HasSHA2) + Features.push_back("-sha2"); + if (!HasAES) + Features.push_back("-aes"); + if (HasV82a || HasV83a || HasV84a) { + Features.push_back("-sm4"); + Features.push_back("-sha3"); + } + } + } + if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) if (A->getOption().matches(options::OPT_mno_unaligned_access)) diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp index e8c8250ed9c..1ff73ea4fd7 100644 --- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp +++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp @@ -444,6 +444,26 @@ fp16_fml_fallthrough: Features.push_back("-crc"); } + // For Arch >= ARMv8.0: crypto = sha2 + aes + // FIXME: this needs reimplementation after the TargetParser rewrite + if (ArchName.find_lower("armv8a") != StringRef::npos || + ArchName.find_lower("armv8.1a") != StringRef::npos || + ArchName.find_lower("armv8.2a") != StringRef::npos || + ArchName.find_lower("armv8.3a") != StringRef::npos || + ArchName.find_lower("armv8.4a") != StringRef::npos) { + if (ArchName.find_lower("+crypto") != StringRef::npos) { + if (ArchName.find_lower("+nosha2") == StringRef::npos) + Features.push_back("+sha2"); + if (ArchName.find_lower("+noaes") == StringRef::npos) + Features.push_back("+aes"); + } else if (ArchName.find_lower("-crypto") != StringRef::npos) { + if (ArchName.find_lower("+sha2") == StringRef::npos) + Features.push_back("-sha2"); + if (ArchName.find_lower("+aes") == StringRef::npos) + Features.push_back("-aes"); + } + } + // Look for the last occurrence of -mlong-calls or -mno-long-calls. If // neither options are specified, see if we are compiling for kernel/kext and // decide whether to pass "+long-calls" based on the OS and its version. |