Index: llvm/utils/TableGen/CodeGenTarget.h =================================================================== --- llvm/utils/TableGen/CodeGenTarget.h +++ llvm/utils/TableGen/CodeGenTarget.h @@ -60,6 +60,7 @@ mutable std::unique_ptr SchedModels; + mutable StringRef InstNamespace; mutable std::vector 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 {