Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:07

0001 //===-- llvm/IR/Mangler.h - Self-contained name mangler ---------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Unified name mangler for various backends.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_IR_MANGLER_H
0014 #define LLVM_IR_MANGLER_H
0015 
0016 #include "llvm/ADT/DenseMap.h"
0017 #include "llvm/ADT/StringRef.h"
0018 
0019 namespace llvm {
0020 
0021 class DataLayout;
0022 class GlobalValue;
0023 template <typename T> class SmallVectorImpl;
0024 class Triple;
0025 class Twine;
0026 class raw_ostream;
0027 
0028 class Mangler {
0029   /// We need to give global values the same name every time they are mangled.
0030   /// This keeps track of the number we give to anonymous ones.
0031   mutable DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
0032 
0033 public:
0034   /// Print the appropriate prefix and the specified global variable's name.
0035   /// If the global variable doesn't have a name, this fills in a unique name
0036   /// for the global.
0037   void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
0038                          bool CannotUsePrivateLabel) const;
0039   void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
0040                          bool CannotUsePrivateLabel) const;
0041 
0042   /// Print the appropriate prefix and the specified name as the global variable
0043   /// name. GVName must not be empty.
0044   static void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
0045                                 const DataLayout &DL);
0046   static void getNameWithPrefix(SmallVectorImpl<char> &OutName,
0047                                 const Twine &GVName, const DataLayout &DL);
0048 };
0049 
0050 void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV,
0051                                   const Triple &TT, Mangler &Mangler);
0052 
0053 void emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV,
0054                                 const Triple &T, Mangler &M);
0055 
0056 /// Returns the ARM64EC mangled function name unless the input is already
0057 /// mangled.
0058 std::optional<std::string> getArm64ECMangledFunctionName(StringRef Name);
0059 
0060 /// Returns the ARM64EC demangled function name, unless the input is not
0061 /// mangled.
0062 std::optional<std::string> getArm64ECDemangledFunctionName(StringRef Name);
0063 
0064 /// Check if an ARM64EC function name is mangled.
0065 bool inline isArm64ECMangledFunctionName(StringRef Name) {
0066   return Name[0] == '#' ||
0067          (Name[0] == '?' && Name.find("@$$h") != StringRef::npos);
0068 }
0069 
0070 } // End llvm namespace
0071 
0072 #endif