50 lines · c
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-exception6//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_H16#define LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H17 18namespace llvm {19class CodeExpansions {20public:21 using const_iterator = StringMap<std::string>::const_iterator;22 23protected:24 StringMap<std::string> Expansions;25 26public:27 void declare(StringRef Name, StringRef Expansion) {28 // Duplicates are not inserted. The expansion refers to different29 // 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 llvm48 49#endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CODEEXPANSIONS_H50