LLVM 22.0.0git
Mangler.h
Go to the documentation of this file.
1//===-- llvm/IR/Mangler.h - Self-contained name mangler ---------*- C++ -*-===//
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// Unified name mangler for various backends.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_IR_MANGLER_H
14#define LLVM_IR_MANGLER_H
15
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/StringRef.h"
19
20namespace llvm {
21
22class DataLayout;
23class GlobalValue;
24template <typename T> class SmallVectorImpl;
25class Triple;
26class Twine;
27class raw_ostream;
28
29// TODO: The weird assignment of HybridPatchableTargetSuffix below is a
30// temporary workaround for a linker failure that is only hit when compiling
31// llvm for arm64ec on windows. The description and context of the issue is at
32// https://github.com/llvm/llvm-project/issues/143575.
33// An upstream MSVC bug is filed at
34// https://developercommunity.visualstudio.com/t/MSVC-Linker-Issue-When-Cross-
35// Compiling-L/10920141.
36constexpr char HybridPatchableTargetSuffixArr[] = "$hp_target";
37constexpr std::string_view HybridPatchableTargetSuffix =
39
40class Mangler {
41 /// We need to give global values the same name every time they are mangled.
42 /// This keeps track of the number we give to anonymous ones.
43 mutable DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
44
45public:
46 /// Print the appropriate prefix and the specified global variable's name.
47 /// If the global variable doesn't have a name, this fills in a unique name
48 /// for the global.
50 bool CannotUsePrivateLabel) const;
52 const GlobalValue *GV,
53 bool CannotUsePrivateLabel) const;
54
55 /// Print the appropriate prefix and the specified name as the global variable
56 /// name. GVName must not be empty.
57 LLVM_ABI static void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
58 const DataLayout &DL);
60 const Twine &GVName,
61 const DataLayout &DL);
62};
63
65 const GlobalValue *GV,
66 const Triple &TT, Mangler &Mangler);
67
69 const Triple &T, Mangler &M);
70
71/// Returns the ARM64EC mangled function name unless the input is already
72/// mangled.
73LLVM_ABI std::optional<std::string>
75
76/// Returns the ARM64EC demangled function name, unless the input is not
77/// mangled.
78LLVM_ABI std::optional<std::string>
80
81/// Check if an ARM64EC function name is mangled.
83 return Name[0] == '#' ||
84 (Name[0] == '?' && Name.find("@$$h") != StringRef::npos);
85}
86
87} // End llvm namespace
88
89#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
#define T
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
LLVM_ABI void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition Mangler.cpp:121
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
static constexpr size_t npos
Definition StringRef.h:57
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::optional< std::string > getArm64ECMangledFunctionName(StringRef Name)
Returns the ARM64EC mangled function name unless the input is already mangled.
Definition Mangler.cpp:294
constexpr char HybridPatchableTargetSuffixArr[]
Definition Mangler.h:36
bool isArm64ECMangledFunctionName(StringRef Name)
Check if an ARM64EC function name is mangled.
Definition Mangler.h:82
LLVM_ABI std::optional< std::string > getArm64ECDemangledFunctionName(StringRef Name)
Returns the ARM64EC demangled function name, unless the input is not mangled.
Definition Mangler.cpp:320
LLVM_ABI void emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &T, Mangler &M)
Definition Mangler.cpp:280
constexpr std::string_view HybridPatchableTargetSuffix
Definition Mangler.h:37
LLVM_ABI void emitLinkerFlagsForGlobalCOFF(raw_ostream &OS, const GlobalValue *GV, const Triple &TT, Mangler &Mangler)
Definition Mangler.cpp:214