|
45 | 45 | #include "llvm/Support/Timer.h" |
46 | 46 | #include "llvm/Support/raw_ostream.h" |
47 | 47 | #include "llvm/Target/TargetMachine.h" |
| 48 | +#include "llvm/TargetParser/AArch64TargetParser.h" |
48 | 49 | #include <cstdio> |
49 | 50 |
|
50 | 51 | #ifdef CLANG_HAVE_RLIMITS |
@@ -183,6 +184,34 @@ static int PrintSupportedCPUs(std::string TargetStr) { |
183 | 184 | return 0; |
184 | 185 | } |
185 | 186 |
|
| 187 | +static int PrintSupportedExtensions(std::string TargetStr) { |
| 188 | + std::string Error; |
| 189 | + const llvm::Target *TheTarget = |
| 190 | + llvm::TargetRegistry::lookupTarget(TargetStr, Error); |
| 191 | + if (!TheTarget) { |
| 192 | + llvm::errs() << Error; |
| 193 | + return 1; |
| 194 | + } |
| 195 | + |
| 196 | + llvm::TargetOptions Options; |
| 197 | + std::unique_ptr<llvm::TargetMachine> TheTargetMachine( |
| 198 | + TheTarget->createTargetMachine(TargetStr, "", "", Options, std::nullopt)); |
| 199 | + const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple(); |
| 200 | + |
| 201 | + if (MachineTriple.isRISCV()) |
| 202 | + llvm::riscvExtensionsHelp(); |
| 203 | + else if (MachineTriple.isAArch64()) |
| 204 | + llvm::AArch64::PrintSupportedExtensions(); |
| 205 | + else { |
| 206 | + // The option was already checked in Driver::HandleImmediateArgs, |
| 207 | + // so we do not expect to get here if we are not a supported architecture. |
| 208 | + assert(0 && "Unhandled triple for --print-supported-extensions option."); |
| 209 | + return 1; |
| 210 | + } |
| 211 | + |
| 212 | + return 0; |
| 213 | +} |
| 214 | + |
186 | 215 | int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
187 | 216 | ensureSufficientStack(); |
188 | 217 |
|
@@ -224,7 +253,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
224 | 253 |
|
225 | 254 | // --print-supported-extensions takes priority over the actual compilation. |
226 | 255 | if (Clang->getFrontendOpts().PrintSupportedExtensions) |
227 | | - return llvm::riscvExtensionsHelp(), 0; |
| 256 | + return PrintSupportedExtensions(Clang->getTargetOpts().Triple); |
228 | 257 |
|
229 | 258 | // Infer the builtin include path if unspecified. |
230 | 259 | if (Clang->getHeaderSearchOpts().UseBuiltinIncludes && |
|
0 commit comments