1 //===- CodeExpansions.h - Record expansions for CodeExpander --------------===//
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
7 //===----------------------------------------------------------------------===//
9 /// \file Record the expansions to use in a CodeExpander.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/StringMap.h"
15 #ifndef LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H
16 #define LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H
19 class CodeExpansions
{
21 using const_iterator
= StringMap
<std::string
>::const_iterator
;
24 StringMap
<std::string
> Expansions
;
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
);
33 void redeclare(StringRef Name
, StringRef Expansion
) {
34 Expansions
[Name
] = Expansion
;
37 std::string
lookup(StringRef Variable
) const {
38 return Expansions
.lookup(Variable
);
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
);
47 } // end namespace llvm
49 #endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H