[clang] [llvm] [AArch64] Add ability to list extensions enabled for a target (PR #95805)

Lucas Duarte Prates via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 07:50:48 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);
----------------
pratlucas wrote:

Unfortunately `llvm::SubtargetFeatureKV` doesn't hold a lot of information and semantics of its contents is even less clear the what's capture here. I'll add a comment to this block clarifying what's being captured. 

https://github.com/llvm/llvm-project/pull/95805


More information about the llvm-commits mailing list