1 //===- CodeExpansions.h - Record expansions for CodeExpander --------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 /// \file Record the expansions to use in a CodeExpander. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/ADT/StringMap.h" 14 15 #ifndef LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H 16 #define LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H 17 18 namespace llvm { 19 class CodeExpansions { 20 public: 21 using const_iterator = StringMap<std::string>::const_iterator; 22 23 protected: 24 StringMap<std::string> Expansions; 25 26 public: 27 void declare(StringRef Name, StringRef Expansion) { 28 // Duplicates are not inserted. The expansion refers to different 29 // MachineOperands using the same virtual register. 30 Expansions.try_emplace(Name, Expansion); 31 } 32 33 void redeclare(StringRef Name, StringRef Expansion) { 34 Expansions[Name] = Expansion; 35 } 36 37 std::string lookup(StringRef Variable) const { 38 return Expansions.lookup(Variable); 39 } 40 41 const_iterator begin() const { return Expansions.begin(); } 42 const_iterator end() const { return Expansions.end(); } 43 const_iterator find(StringRef Variable) const { 44 return Expansions.find(Variable); 45 } 46 }; 47 } // end namespace llvm 48 49 #endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H 50