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