CodeExpansions.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "llvm/ADT/StringMap.h"
  13. #ifndef LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H
  14. #define LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H
  15. namespace llvm {
  16. class CodeExpansions {
  17. public:
  18. using const_iterator = StringMap<std::string>::const_iterator;
  19. protected:
  20. StringMap<std::string> Expansions;
  21. public:
  22. void declare(StringRef Name, StringRef Expansion) {
  23. // Duplicates are not inserted. The expansion refers to different
  24. // MachineOperands using the same virtual register.
  25. Expansions.try_emplace(Name, Expansion);
  26. }
  27. std::string lookup(StringRef Variable) const {
  28. return Expansions.lookup(Variable);
  29. }
  30. const_iterator begin() const { return Expansions.begin(); }
  31. const_iterator end() const { return Expansions.end(); }
  32. const_iterator find(StringRef Variable) const {
  33. return Expansions.find(Variable);
  34. }
  35. };
  36. } // end namespace llvm
  37. #endif // ifndef LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H