How to query for active subtarget features?

Hi all!

In my compiler I like to define some identifiers based on subtarget features. E.g. for the MIPS platform: if the user wants to compile for N32 (-mattr=+n32), then I want to define the identifier MIPS_N32.
This is the simple case because I can parse the command line. But if the user specifies nothing, then the MIPS target defaults to N64. How can I determine this default value?

I think the solution would be if there is a way to enumerate the subtarget features which are active right now. Can this be done currently? I found no way but I may miss something here.


I'm not aware of a way to obtain defaults from the backend. In the case of your example Clang currently overrides the backend default in all cases and has its own default value. It then uses its own opinion of the ABI to define __mips_n32, etc.

The relevant code is in tools/clang/lib/Basic/Targets.cpp:
  void getDefaultFeatures(llvm::StringMap<bool> &Features) const override {
    // The backend enables certain ABI's by default according to the
    // architecture.
    // Disable both possible defaults so that we don't end up with multiple
    // ABI's selected and trigger an assertion.
    Features["o32"] = false;
    Features["n64"] = false;
    Features[ABI] = true;
    Features[CPU] = true;