Hi,
Having recently enabled IAS by default for the MIPS O32 ABI, I'm now trying to do the same thing for the MIPS N64 ABI. Unfortunately, it is not currently possible to enable IAS by default for the N64 ABI without also enabling it for the N32 ABI because this information is not reflected in the triple and that's the only information MipsMCAsmInfo has. This would be fine if it N32 was also in a good state but the current N32 ABI support for IAS is badly broken and will likely take considerable effort to fix (and fixing it also requires solving the same key problem as enabling IAS for just N64). I therefore want to separate the two ABI's so that I can finish off N64 and then fix N32 afterwards.
I've posted a series of patches that allow us to distinguish N32 and N64 so that we can enable IAS for only N64 (D21465, D21467, D21069 for LLVM along with D21070, D21072 for clang). During the review of D21467, Rafael asked me to explain my approach here. I'm hoping that people will agree that this is an acceptable approach to take and that it's no different from how other targets handle certain ABI's and how we already handle -m32/-m64/-EL/-EB/etc.
The approach I'm using is to encode the ABI information into the triple in the same way that ARM does for EABI and hardfloat, and the same way that X86 does for X32. These targets define variants of Triple::GNU for each of these ABI's in the form of the Triple::GNUEABI, Triple::GNUEABIHF, and Triple::GNUX32 values of the environment component of the triple and it's up to the frontend and/or API-user to pass the right thing to the backend.
For MIPS, I'm defining Triple::GNUABI32, Triple::GNUABIN32, and Triple::GNUABI64. All three of these are supported by tools like binutils (by virtue of a wildcard match '*linux-gnu*') and of these three, Triple::GNUABI32 is not in general use, Triple::GNUABIN32 will be used by Debian if/when we do an N32 port, and Triple::GNUABI64 is currently used by Debian for our N64 port. Once the ABI is in our backend triples, it can be used by MipsMCAsmInfo to enable IAS by default for N64 without also enabling it for N32. In later patches, such as D1292 this same information will also be used to fix the N32 support for IAS.
At this point, you may be wondering what happens to Triple::GNU for triples like mips-linux-gnu and mips64-linux-gnu. The answer to this is that the API-user (e.g. clang) is expected to normalize such triples down to one of Triple::GNUABI32/GNUABIN32/GNUABI64. This can be as simple as adding:
Triple ABITriple = TT.getABIVariant(ABIName); // ABIName can be the empty string to get the default ABI.
if (ABITriple.getArch() != Triple::UnknownArch) {
TT = ABITriple;
ABIName = ""; // <- Only needed if this would end up in MCTargetOptions::ABIName.
}
to the appropriate place in the caller. This is the same way clang handles the -m32, -m64, -EL, and -EB options with those options using get32BitArchVariant(), get64BitArchVariant(), getLittleEndianArchVariant(), and getBigEndianArchVariant() respectively to transform the triple for the backend.
In summary, human end users of tools such as clang will continue using the same triples as they always have. These tools will then resolve them down to the effective triple (for example, in functions like clang's ComputeEffectiveClangTriple(), ComputeLLVMTriple(), and computeTargetTriple()). The MIPS backend will only see the triples that have a specific known ABI. I'd like to stress that this process is the same as the one we already use today for other options. For example 'x86_64-linux-gnu-clang -m32' transforms the triple with get32BitArchVariant() and passes 'i386-linux-gnu' to the backend.
So far I've only been talking about Linux/GNU but the patch series also covers Linux/Musl, Linux/Android, and FreeBSD. I haven't talked about those because they are handled in the same way as the Linux/GNU case described above except that they use Triple::ABI32/ABIN32/ABI64 (or Android32/Android64 in the case of Android) instead of Triple::GNUABI32/GNUABIN32/GNUABI64.
Why is the Triple approach better for MIPS than MCTargetOptions::ABIName?