[clang] [llvm] [AArch64] Add ability to list extensions enabled for a target (PR #95805)
Tomas Matheson via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 24 06:57:23 PDT 2024
================
@@ -161,6 +162,39 @@ static int PrintSupportedExtensions(std::string TargetStr) {
return 0;
}
+static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
+ std::string Error;
+ const llvm::Target *TheTarget =
+ llvm::TargetRegistry::lookupTarget(TargetOpts.Triple, Error);
+ if (!TheTarget) {
+ llvm::errs() << Error;
+ return 1;
+ }
+
+ llvm::TargetOptions BackendOptions;
+ std::string FeaturesStr = llvm::join(TargetOpts.FeaturesAsWritten, ",");
+ std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
+ TheTarget->createTargetMachine(TargetOpts.Triple, TargetOpts.CPU, FeaturesStr, BackendOptions, std::nullopt));
+ const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
+ const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
+ const std::vector<llvm::SubtargetFeatureKV> Features =
+ MCInfo->getEnabledProcessorFeatures();
+
+ std::vector<llvm::StringRef> EnabledFeatureNames;
+ for (const llvm::SubtargetFeatureKV &feature : Features)
+ EnabledFeatureNames.push_back(feature.Key);
----------------
tmatheson-arm wrote:
Maybe we shouldn't throw away the type information in `llvm::SubtargetFeatureKV` before `printEnabledExtensions`. It is not clear what `EnabledFeatureNames` contains, since it is just a vector of strings. i.e. are they internal names, extension names, subtarget feature names, etc.
https://github.com/llvm/llvm-project/pull/95805
More information about the cfe-commits
mailing list