[llvm] r212846 - Move the API and implementation of clang::driver::getARMCPUForMArch() to llvm::Triple::getARMCPUForArch().
Jim Grosbach
grosbach at apple.com
Fri Jul 11 14:58:18 PDT 2014
Thanks, Argyrios. This may be very handy for some upcoming MCJIT related work.
-Jim
> On Jul 11, 2014, at 2:44 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
>
> Author: akirtzidis
> Date: Fri Jul 11 16:44:54 2014
> New Revision: 212846
>
> URL: http://llvm.org/viewvc/llvm-project?rev=212846&view=rev
> Log:
> Move the API and implementation of clang::driver::getARMCPUForMArch() to llvm::Triple::getARMCPUForArch().
>
> Suggested by Eric Christopher.
>
> Modified:
> llvm/trunk/include/llvm/ADT/Triple.h
> llvm/trunk/lib/Support/Triple.cpp
> llvm/trunk/unittests/ADT/TripleTest.cpp
>
> Modified: llvm/trunk/include/llvm/ADT/Triple.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Triple.h?rev=212846&r1=212845&r2=212846&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/Triple.h (original)
> +++ llvm/trunk/include/llvm/ADT/Triple.h Fri Jul 11 16:44:54 2014
> @@ -477,6 +477,12 @@ public:
> /// architecture if no such variant can be found.
> llvm::Triple get64BitArchVariant() const;
>
> + /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
> + ///
> + /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
> + /// string then the triple's arch name is used.
> + const char* getARMCPUForArch(StringRef Arch = StringRef()) const;
> +
> /// @}
> /// @name Static helpers for IDs.
> /// @{
>
> Modified: llvm/trunk/lib/Support/Triple.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Triple.cpp?rev=212846&r1=212845&r2=212846&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Triple.cpp (original)
> +++ llvm/trunk/lib/Support/Triple.cpp Fri Jul 11 16:44:54 2014
> @@ -930,3 +930,85 @@ Triple Triple::get64BitArchVariant() con
> }
> return T;
> }
> +
> +// FIXME: tblgen this.
> +const char *Triple::getARMCPUForArch(StringRef MArch) const {
> + if (MArch.empty())
> + MArch = getArchName();
> +
> + switch (getOS()) {
> + case llvm::Triple::NetBSD:
> + if (MArch == "armv6")
> + return "arm1176jzf-s";
> + break;
> + case llvm::Triple::Win32:
> + // FIXME: this is invalid for WindowsCE
> + return "cortex-a9";
> + default:
> + break;
> + }
> +
> + const char *result = nullptr;
> + size_t offset = StringRef::npos;
> + if (MArch.startswith("arm"))
> + offset = 3;
> + if (MArch.startswith("thumb"))
> + offset = 5;
> + if (offset != StringRef::npos && MArch.substr(offset, 2) == "eb")
> + offset += 2;
> + if (offset != StringRef::npos)
> + result = llvm::StringSwitch<const char *>(MArch.substr(offset))
> + .Cases("v2", "v2a", "arm2")
> + .Case("v3", "arm6")
> + .Case("v3m", "arm7m")
> + .Case("v4", "strongarm")
> + .Case("v4t", "arm7tdmi")
> + .Cases("v5", "v5t", "arm10tdmi")
> + .Cases("v5e", "v5te", "arm1022e")
> + .Case("v5tej", "arm926ej-s")
> + .Cases("v6", "v6k", "arm1136jf-s")
> + .Case("v6j", "arm1136j-s")
> + .Cases("v6z", "v6zk", "arm1176jzf-s")
> + .Case("v6t2", "arm1156t2-s")
> + .Cases("v6m", "v6-m", "cortex-m0")
> + .Cases("v7", "v7a", "v7-a", "v7l", "v7-l", "cortex-a8")
> + .Cases("v7s", "v7-s", "swift")
> + .Cases("v7r", "v7-r", "cortex-r4")
> + .Cases("v7m", "v7-m", "cortex-m3")
> + .Cases("v7em", "v7e-m", "cortex-m4")
> + .Cases("v8", "v8a", "v8-a", "cortex-a53")
> + .Default(nullptr);
> + else
> + result = llvm::StringSwitch<const char *>(MArch)
> + .Case("ep9312", "ep9312")
> + .Case("iwmmxt", "iwmmxt")
> + .Case("xscale", "xscale")
> + .Default(nullptr);
> +
> + if (result)
> + return result;
> +
> + // If all else failed, return the most base CPU with thumb interworking
> + // supported by LLVM.
> + // FIXME: Should warn once that we're falling back.
> + switch (getOS()) {
> + case llvm::Triple::NetBSD:
> + switch (getEnvironment()) {
> + case llvm::Triple::GNUEABIHF:
> + case llvm::Triple::GNUEABI:
> + case llvm::Triple::EABIHF:
> + case llvm::Triple::EABI:
> + return "arm926ej-s";
> + default:
> + return "strongarm";
> + }
> + default:
> + switch (getEnvironment()) {
> + case llvm::Triple::EABIHF:
> + case llvm::Triple::GNUEABIHF:
> + return "arm1176jzf-s";
> + default:
> + return "arm7tdmi";
> + }
> + }
> +}
>
> Modified: llvm/trunk/unittests/ADT/TripleTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/TripleTest.cpp?rev=212846&r1=212845&r2=212846&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/ADT/TripleTest.cpp (original)
> +++ llvm/trunk/unittests/ADT/TripleTest.cpp Fri Jul 11 16:44:54 2014
> @@ -564,4 +564,16 @@ TEST(TripleTest, NormalizeWindows) {
>
> EXPECT_EQ("i686-pc-windows-elf", Triple::normalize("i686-pc-windows-elf-elf"));
> }
> +
> +TEST(TripleTest, getARMCPUForArch) {
> + {
> + llvm::Triple Triple("armv7s-apple-ios7");
> + EXPECT_STREQ("swift", Triple.getARMCPUForArch());
> + }
> + {
> + llvm::Triple Triple("armv7-apple-ios7");
> + EXPECT_STREQ("cortex-a8", Triple.getARMCPUForArch());
> + EXPECT_STREQ("swift", Triple.getARMCPUForArch("armv7s"));
> + }
> +}
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list