[MCA] Support multiple comma-separated -mattr features
authorCullen Rhodes <cullen.rhodes@arm.com>
Tue, 12 Jul 2022 07:55:55 +0000 (07:55 +0000)
committerCullen Rhodes <cullen.rhodes@arm.com>
Tue, 12 Jul 2022 08:20:11 +0000 (08:20 +0000)
Reviewed By: myhsu

Differential Revision: https://reviews.llvm.org/D129479

llvm/test/tools/llvm-mca/AArch64/Neoverse/N2-sve-instructions.s
llvm/tools/llvm-mca/llvm-mca.cpp

index 053382f..62db90a 100644 (file)
@@ -1,10 +1,5 @@
 # NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
-# RUN: llvm-mca -mtriple=aarch64 -mcpu=neoverse-n2 -mattr=+sve2-aes -instruction-tables < %s | FileCheck %s
-
-# NOTE: Only 1 feature can be passed to llvm-mca via -mattr, enable other
-# features with directive.
-.arch_extension sve2-sha3
-.arch_extension sve2-sm4
+# RUN: llvm-mca -mtriple=aarch64 -mcpu=neoverse-n2 -mattr=+sve2-aes,+sve2-sha3,+sve2-sm4 -instruction-tables < %s | FileCheck %s
 
 abs    z0.b, p0/m, z0.b
 abs    z0.d, p0/m, z0.d
index 409de28..6f7b74f 100644 (file)
@@ -92,9 +92,10 @@ static cl::opt<std::string>
          cl::desc("Target a specific cpu type (-mcpu=help for details)"),
          cl::value_desc("cpu-name"), cl::cat(ToolOptions), cl::init("native"));
 
-static cl::opt<std::string> MATTR("mattr",
-                                  cl::desc("Additional target features."),
-                                  cl::cat(ToolOptions));
+static cl::list<std::string>
+    MATTRS("mattr", cl::CommaSeparated,
+           cl::desc("Target specific attributes (-mattr=help for details)"),
+           cl::value_desc("a1,+a2,-a3,..."), cl::cat(ToolOptions));
 
 static cl::opt<bool> PrintJson("json",
                                cl::desc("Print the output in json format"),
@@ -346,8 +347,17 @@ int main(int argc, char **argv) {
   if (MCPU == "native")
     MCPU = std::string(llvm::sys::getHostCPUName());
 
+  // Package up features to be passed to target/subtarget
+  std::string FeaturesStr;
+  if (MATTRS.size()) {
+    SubtargetFeatures Features;
+    for (std::string &MAttr : MATTRS)
+      Features.AddFeature(MAttr);
+    FeaturesStr = Features.getString();
+  }
+
   std::unique_ptr<MCSubtargetInfo> STI(
-      TheTarget->createMCSubtargetInfo(TripleName, MCPU, MATTR));
+      TheTarget->createMCSubtargetInfo(TripleName, MCPU, FeaturesStr));
   assert(STI && "Unable to create subtarget info!");
   if (!STI->isCPUStringValid(MCPU))
     return 1;