[PATCH] D92722: [TableGen] [CodeGenTarget] Cache the target's instruction namespace

Paul C. Anagnostopoulos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 5 07:38:56 PST 2020


Paul-C-Anagnostopoulos created this revision.
Paul-C-Anagnostopoulos added reviewers: lattner, nhaehnle, dblaikie, madhur13490, craig.topper.
Paul-C-Anagnostopoulos requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This revision caches the target machine's instruction namespace in CodeGenTarget. The namespace is requested multiple times by backends and involves a linear scan of the vector of records inheriting from Instruction.

I've separated this revision from https://reviews.llvm.org/D92674 and will remove it from that revision.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92722

Files:
  llvm/utils/TableGen/CodeGenTarget.cpp
  llvm/utils/TableGen/CodeGenTarget.h


Index: llvm/utils/TableGen/CodeGenTarget.h
===================================================================
--- llvm/utils/TableGen/CodeGenTarget.h
+++ llvm/utils/TableGen/CodeGenTarget.h
@@ -60,6 +60,7 @@
 
   mutable std::unique_ptr<CodeGenSchedModels> SchedModels;
 
+  mutable StringRef InstNamespace = StringRef();
   mutable std::vector<const CodeGenInstruction*> InstrsByEnum;
   mutable unsigned NumPseudoInstructions = 0;
 public:
Index: llvm/utils/TableGen/CodeGenTarget.cpp
===================================================================
--- llvm/utils/TableGen/CodeGenTarget.cpp
+++ llvm/utils/TableGen/CodeGenTarget.cpp
@@ -264,15 +264,20 @@
   return TargetRec->getName();
 }
 
+/// getInstNamespace - Find and return the target machine's instruction
+/// namespace. The namespace is cached because it is requested multiple times.
 StringRef CodeGenTarget::getInstNamespace() const {
-  for (const CodeGenInstruction *Inst : getInstructionsByEnumValue()) {
-    // Make sure not to pick up "TargetOpcode" by accidentally getting
-    // the namespace off the PHI instruction or something.
-    if (Inst->Namespace != "TargetOpcode")
-      return Inst->Namespace;
+  if (InstNamespace.empty()) {
+    for (const CodeGenInstruction *Inst : getInstructionsByEnumValue()) {
+      // We are not interested in the "TargetOpcode" namespace.
+      if (Inst->Namespace != "TargetOpcode") {
+        InstNamespace = Inst->Namespace;
+        break;
+      }
+    }
   }
 
-  return "";
+  return InstNamespace;
 }
 
 StringRef CodeGenTarget::getRegNamespace() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92722.309739.patch
Type: text/x-patch
Size: 1582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201205/8fc402ef/attachment.bin>


More information about the llvm-commits mailing list