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_CODEEXPANSIONS_H
16#define LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H
17namespace llvm {
18class CodeExpansions {
19public:
20 using const_iterator = StringMap<std::string>::const_iterator;
21
22protected:
23 StringMap<std::string> Expansions;
24
25public:
26 void declare(StringRef Name, StringRef Expansion) {
27 // Duplicates are not inserted. The expansion refers to different
28 // MachineOperands using the same virtual register.
29 Expansions.try_emplace(Key: Name, Args&: Expansion);
30 }
31
32 void redeclare(StringRef Name, StringRef Expansion) {
33 Expansions[Name] = Expansion;
34 }
35
36 std::string lookup(StringRef Variable) const {
37 return Expansions.lookup(Key: Variable);
38 }
39
40 const_iterator begin() const { return Expansions.begin(); }
41 const_iterator end() const { return Expansions.end(); }
42 const_iterator find(StringRef Variable) const {
43 return Expansions.find(Key: Variable);
44 }
45};
46} // end namespace llvm
47#endif // ifndef LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H
48