003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/Support
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
Support
/
📁
..
📄
AArch64TargetParser.cpp
(8 KB)
📄
ABIBreak.cpp
(811 B)
📄
AMDGPUMetadata.cpp
(9.37 KB)
📄
APFloat.cpp
(155.26 KB)
📄
APInt.cpp
(98.08 KB)
📄
APSInt.cpp
(1.44 KB)
📄
ARMAttributeParser.cpp
(13.94 KB)
📄
ARMBuildAttrs.cpp
(3.45 KB)
📄
ARMTargetParser.cpp
(18.09 KB)
📄
ARMWinEH.cpp
(1.08 KB)
📄
Allocator.cpp
(1.35 KB)
📄
Atomic.cpp
(1.6 KB)
📄
BinaryStreamError.cpp
(1.76 KB)
📄
BinaryStreamReader.cpp
(5.24 KB)
📄
BinaryStreamRef.cpp
(4.76 KB)
📄
BinaryStreamWriter.cpp
(3.36 KB)
📄
BlockFrequency.cpp
(2.12 KB)
📄
BranchProbability.cpp
(3.44 KB)
📄
BuryPointer.cpp
(1.11 KB)
📄
COM.cpp
(737 B)
📄
COPYRIGHT.regex
(2.65 KB)
📄
CRC.cpp
(5.23 KB)
📄
CachePruning.cpp
(10.33 KB)
📄
Chrono.cpp
(3.17 KB)
📄
CodeGenCoverage.cpp
(3.61 KB)
📄
CommandLine.cpp
(89.06 KB)
📄
Compression.cpp
(3.84 KB)
📄
ConvertUTF.cpp
(27.27 KB)
📄
ConvertUTFWrapper.cpp
(8.66 KB)
📄
CrashRecoveryContext.cpp
(15.45 KB)
📄
DAGDeltaAlgorithm.cpp
(12.47 KB)
📄
DJB.cpp
(2.71 KB)
📄
DataExtractor.cpp
(7.25 KB)
📄
Debug.cpp
(5.64 KB)
📄
DebugCounter.cpp
(4.95 KB)
📄
DeltaAlgorithm.cpp
(3.41 KB)
📄
DynamicLibrary.cpp
(6.25 KB)
📄
ELFAttributeParser.cpp
(7.27 KB)
📄
ELFAttributes.cpp
(1.27 KB)
📄
Errno.cpp
(2.18 KB)
📄
Error.cpp
(4.72 KB)
📄
ErrorHandling.cpp
(11.08 KB)
📄
ExtensibleRTTI.cpp
(446 B)
📄
FileCheck.cpp
(95.77 KB)
📄
FileCheckImpl.h
(34.14 KB)
📄
FileCollector.cpp
(9.01 KB)
📄
FileOutputBuffer.cpp
(6.62 KB)
📄
FileUtilities.cpp
(10.81 KB)
📄
FoldingSet.cpp
(15.89 KB)
📄
FormatVariadic.cpp
(5.17 KB)
📄
FormattedStream.cpp
(5.29 KB)
📄
GlobPattern.cpp
(5 KB)
📄
GraphWriter.cpp
(9.21 KB)
📄
Hashing.cpp
(1.16 KB)
📄
Host.cpp
(51.63 KB)
📄
InitLLVM.cpp
(1.92 KB)
📄
IntEqClasses.cpp
(2.18 KB)
📄
IntervalMap.cpp
(4.4 KB)
📄
ItaniumManglingCanonicalizer.cpp
(10.77 KB)
📄
JSON.cpp
(19.1 KB)
📄
KnownBits.cpp
(3.78 KB)
📄
LEB128.cpp
(1.19 KB)
📄
LineIterator.cpp
(2.61 KB)
📄
Locale.cpp
(377 B)
📄
LockFileManager.cpp
(10.64 KB)
📄
LowLevelType.cpp
(2.09 KB)
📄
MD5.cpp
(8.99 KB)
📄
ManagedStatic.cpp
(2.37 KB)
📄
MathExtras.cpp
(913 B)
📄
MemAlloc.cpp
(1.01 KB)
📄
Memory.cpp
(1.57 KB)
📄
MemoryBuffer.cpp
(18.99 KB)
📄
NativeFormatting.cpp
(7.54 KB)
📄
OptimizedStructLayout.cpp
(16.7 KB)
📄
Optional.cpp
(530 B)
📄
Parallel.cpp
(5.08 KB)
📄
Path.cpp
(36.52 KB)
📄
PluginLoader.cpp
(1.63 KB)
📄
PrettyStackTrace.cpp
(10.33 KB)
📄
Process.cpp
(3.27 KB)
📄
Program.cpp
(3.54 KB)
📄
RISCVAttributeParser.cpp
(2.06 KB)
📄
RISCVAttributes.cpp
(970 B)
📄
RWMutex.cpp
(3.23 KB)
📄
RandomNumberGenerator.cpp
(2.86 KB)
📄
Regex.cpp
(6.38 KB)
📄
SHA1.cpp
(10.43 KB)
📄
ScaledNumber.cpp
(9.09 KB)
📄
ScopedPrinter.cpp
(1.19 KB)
📄
Signals.cpp
(8.35 KB)
📄
Signposts.cpp
(3.24 KB)
📄
SmallPtrSet.cpp
(9.21 KB)
📄
SmallVector.cpp
(3.99 KB)
📄
SourceMgr.cpp
(20.08 KB)
📄
SpecialCaseList.cpp
(7.48 KB)
📄
Statistic.cpp
(8.85 KB)
📄
StringExtras.cpp
(4.34 KB)
📄
StringMap.cpp
(9.31 KB)
📄
StringRef.cpp
(17.41 KB)
📄
StringSaver.cpp
(882 B)
📄
SuffixTree.cpp
(7.23 KB)
📄
SymbolRemappingReader.cpp
(2.94 KB)
📄
SystemUtils.cpp
(1.06 KB)
📄
TarWriter.cpp
(7.23 KB)
📄
TargetParser.cpp
(9.86 KB)
📄
TargetRegistry.cpp
(4.6 KB)
📄
ThreadLocal.cpp
(1.68 KB)
📄
ThreadPool.cpp
(4.4 KB)
📄
Threading.cpp
(4.55 KB)
📄
TimeProfiler.cpp
(11.63 KB)
📄
Timer.cpp
(14.14 KB)
📄
ToolOutputFile.cpp
(1.83 KB)
📄
TrigramIndex.cpp
(3.24 KB)
📄
Triple.cpp
(53.17 KB)
📄
Twine.cpp
(4.6 KB)
📄
Unicode.cpp
(20.14 KB)
📄
UnicodeCaseFold.cpp
(15.32 KB)
📁
Unix
📄
Valgrind.cpp
(1.6 KB)
📄
VersionTuple.cpp
(2.74 KB)
📄
VirtualFileSystem.cpp
(74.17 KB)
📄
Watchdog.cpp
(738 B)
📁
Windows
📄
WithColor.cpp
(4.35 KB)
📄
X86TargetParser.cpp
(27.21 KB)
📄
YAMLParser.cpp
(68.53 KB)
📄
YAMLTraits.cpp
(28.37 KB)
📄
Z3Solver.cpp
(31.44 KB)
📄
circular_raw_ostream.cpp
(1.3 KB)
📄
raw_os_ostream.cpp
(995 B)
📄
raw_ostream.cpp
(28.97 KB)
📄
regcomp.c
(39.42 KB)
📄
regengine.inc
(26.49 KB)
📄
regerror.c
(4.42 KB)
📄
regex2.h
(6.82 KB)
📄
regex_impl.h
(3.63 KB)
📄
regexec.c
(5.71 KB)
📄
regfree.c
(2.49 KB)
📄
regstrlcpy.c
(1.56 KB)
📄
regutils.h
(2.25 KB)
📄
xxhash.cpp
(4.07 KB)
Editing: ItaniumManglingCanonicalizer.cpp
//===----------------- ItaniumManglingCanonicalizer.cpp -------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/Support/ItaniumManglingCanonicalizer.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/StringRef.h" #include "llvm/Demangle/ItaniumDemangle.h" #include "llvm/Support/Allocator.h" using namespace llvm; using llvm::itanium_demangle::ForwardTemplateReference; using llvm::itanium_demangle::Node; using llvm::itanium_demangle::NodeKind; using llvm::itanium_demangle::StringView; namespace { struct FoldingSetNodeIDBuilder { llvm::FoldingSetNodeID &ID; void operator()(const Node *P) { ID.AddPointer(P); } void operator()(StringView Str) { ID.AddString(llvm::StringRef(Str.begin(), Str.size())); } template <typename T> std::enable_if_t<std::is_integral<T>::value || std::is_enum<T>::value> operator()(T V) { ID.AddInteger((unsigned long long)V); } void operator()(itanium_demangle::NodeArray A) { ID.AddInteger(A.size()); for (const Node *N : A) (*this)(N); } }; template<typename ...T> void profileCtor(llvm::FoldingSetNodeID &ID, Node::Kind K, T ...V) { FoldingSetNodeIDBuilder Builder = {ID}; Builder(K); int VisitInOrder[] = { (Builder(V), 0) ..., 0 // Avoid empty array if there are no arguments. }; (void)VisitInOrder; } // FIXME: Convert this to a generic lambda when possible. template<typename NodeT> struct ProfileSpecificNode { FoldingSetNodeID &ID; template<typename ...T> void operator()(T ...V) { profileCtor(ID, NodeKind<NodeT>::Kind, V...); } }; struct ProfileNode { FoldingSetNodeID &ID; template<typename NodeT> void operator()(const NodeT *N) { N->match(ProfileSpecificNode<NodeT>{ID}); } }; template<> void ProfileNode::operator()(const ForwardTemplateReference *N) { llvm_unreachable("should never canonicalize a ForwardTemplateReference"); } void profileNode(llvm::FoldingSetNodeID &ID, const Node *N) { N->visit(ProfileNode{ID}); } class FoldingNodeAllocator { class alignas(alignof(Node *)) NodeHeader : public llvm::FoldingSetNode { public: // 'Node' in this context names the injected-class-name of the base class. itanium_demangle::Node *getNode() { return reinterpret_cast<itanium_demangle::Node *>(this + 1); } void Profile(llvm::FoldingSetNodeID &ID) { profileNode(ID, getNode()); } }; BumpPtrAllocator RawAlloc; llvm::FoldingSet<NodeHeader> Nodes; public: void reset() {} template <typename T, typename... Args> std::pair<Node *, bool> getOrCreateNode(bool CreateNewNodes, Args &&... As) { // FIXME: Don't canonicalize forward template references for now, because // they contain state (the resolved template node) that's not known at their // point of creation. if (std::is_same<T, ForwardTemplateReference>::value) { // Note that we don't use if-constexpr here and so we must still write // this code in a generic form. return {new (RawAlloc.Allocate(sizeof(T), alignof(T))) T(std::forward<Args>(As)...), true}; } llvm::FoldingSetNodeID ID; profileCtor(ID, NodeKind<T>::Kind, As...); void *InsertPos; if (NodeHeader *Existing = Nodes.FindNodeOrInsertPos(ID, InsertPos)) return {static_cast<T*>(Existing->getNode()), false}; if (!CreateNewNodes) return {nullptr, true}; static_assert(alignof(T) <= alignof(NodeHeader), "underaligned node header for specific node kind"); void *Storage = RawAlloc.Allocate(sizeof(NodeHeader) + sizeof(T), alignof(NodeHeader)); NodeHeader *New = new (Storage) NodeHeader; T *Result = new (New->getNode()) T(std::forward<Args>(As)...); Nodes.InsertNode(New, InsertPos); return {Result, true}; } template<typename T, typename... Args> Node *makeNode(Args &&...As) { return getOrCreateNode<T>(true, std::forward<Args>(As)...).first; } void *allocateNodeArray(size_t sz) { return RawAlloc.Allocate(sizeof(Node *) * sz, alignof(Node *)); } }; class CanonicalizerAllocator : public FoldingNodeAllocator { Node *MostRecentlyCreated = nullptr; Node *TrackedNode = nullptr; bool TrackedNodeIsUsed = false; bool CreateNewNodes = true; llvm::SmallDenseMap<Node*, Node*, 32> Remappings; template<typename T, typename ...Args> Node *makeNodeSimple(Args &&...As) { std::pair<Node *, bool> Result = getOrCreateNode<T>(CreateNewNodes, std::forward<Args>(As)...); if (Result.second) { // Node is new. Make a note of that. MostRecentlyCreated = Result.first; } else if (Result.first) { // Node is pre-existing; check if it's in our remapping table. if (auto *N = Remappings.lookup(Result.first)) { Result.first = N; assert(Remappings.find(Result.first) == Remappings.end() && "should never need multiple remap steps"); } if (Result.first == TrackedNode) TrackedNodeIsUsed = true; } return Result.first; } /// Helper to allow makeNode to be partially-specialized on T. template<typename T> struct MakeNodeImpl { CanonicalizerAllocator &Self; template<typename ...Args> Node *make(Args &&...As) { return Self.makeNodeSimple<T>(std::forward<Args>(As)...); } }; public: template<typename T, typename ...Args> Node *makeNode(Args &&...As) { return MakeNodeImpl<T>{*this}.make(std::forward<Args>(As)...); } void reset() { MostRecentlyCreated = nullptr; } void setCreateNewNodes(bool CNN) { CreateNewNodes = CNN; } void addRemapping(Node *A, Node *B) { // Note, we don't need to check whether B is also remapped, because if it // was we would have already remapped it when building it. Remappings.insert(std::make_pair(A, B)); } bool isMostRecentlyCreated(Node *N) const { return MostRecentlyCreated == N; } void trackUsesOf(Node *N) { TrackedNode = N; TrackedNodeIsUsed = false; } bool trackedNodeIsUsed() const { return TrackedNodeIsUsed; } }; /// Convert St3foo to NSt3fooE so that equivalences naming one also affect the /// other. template<> struct CanonicalizerAllocator::MakeNodeImpl< itanium_demangle::StdQualifiedName> { CanonicalizerAllocator &Self; Node *make(Node *Child) { Node *StdNamespace = Self.makeNode<itanium_demangle::NameType>("std"); if (!StdNamespace) return nullptr; return Self.makeNode<itanium_demangle::NestedName>(StdNamespace, Child); } }; // FIXME: Also expand built-in substitutions? using CanonicalizingDemangler = itanium_demangle::ManglingParser<CanonicalizerAllocator>; } struct ItaniumManglingCanonicalizer::Impl { CanonicalizingDemangler Demangler = {nullptr, nullptr}; }; ItaniumManglingCanonicalizer::ItaniumManglingCanonicalizer() : P(new Impl) {} ItaniumManglingCanonicalizer::~ItaniumManglingCanonicalizer() { delete P; } ItaniumManglingCanonicalizer::EquivalenceError ItaniumManglingCanonicalizer::addEquivalence(FragmentKind Kind, StringRef First, StringRef Second) { auto &Alloc = P->Demangler.ASTAllocator; Alloc.setCreateNewNodes(true); auto Parse = [&](StringRef Str) { P->Demangler.reset(Str.begin(), Str.end()); Node *N = nullptr; switch (Kind) { // A <name>, with minor extensions to allow arbitrary namespace and // template names that can't easily be written as <name>s. case FragmentKind::Name: // Very special case: allow "St" as a shorthand for "3std". It's not // valid as a <name> mangling, but is nonetheless the most natural // way to name the 'std' namespace. if (Str.size() == 2 && P->Demangler.consumeIf("St")) N = P->Demangler.make<itanium_demangle::NameType>("std"); // We permit substitutions to name templates without their template // arguments. This mostly just falls out, as almost all template names // are valid as <name>s, but we also want to parse <substitution>s as // <name>s, even though they're not. else if (Str.startswith("S")) // Parse the substitution and optional following template arguments. N = P->Demangler.parseType(); else N = P->Demangler.parseName(); break; // A <type>. case FragmentKind::Type: N = P->Demangler.parseType(); break; // An <encoding>. case FragmentKind::Encoding: N = P->Demangler.parseEncoding(); break; } // If we have trailing junk, the mangling is invalid. if (P->Demangler.numLeft() != 0) N = nullptr; // If any node was created after N, then we cannot safely remap it because // it might already be in use by another node. return std::make_pair(N, Alloc.isMostRecentlyCreated(N)); }; Node *FirstNode, *SecondNode; bool FirstIsNew, SecondIsNew; std::tie(FirstNode, FirstIsNew) = Parse(First); if (!FirstNode) return EquivalenceError::InvalidFirstMangling; Alloc.trackUsesOf(FirstNode); std::tie(SecondNode, SecondIsNew) = Parse(Second); if (!SecondNode) return EquivalenceError::InvalidSecondMangling; // If they're already equivalent, there's nothing to do. if (FirstNode == SecondNode) return EquivalenceError::Success; if (FirstIsNew && !Alloc.trackedNodeIsUsed()) Alloc.addRemapping(FirstNode, SecondNode); else if (SecondIsNew) Alloc.addRemapping(SecondNode, FirstNode); else return EquivalenceError::ManglingAlreadyUsed; return EquivalenceError::Success; } static ItaniumManglingCanonicalizer::Key parseMaybeMangledName(CanonicalizingDemangler &Demangler, StringRef Mangling, bool CreateNewNodes) { Demangler.ASTAllocator.setCreateNewNodes(CreateNewNodes); Demangler.reset(Mangling.begin(), Mangling.end()); // Attempt demangling only for names that look like C++ mangled names. // Otherwise, treat them as extern "C" names. We permit the latter to // be remapped by (eg) // encoding 6memcpy 7memmove // consistent with how they are encoded as local-names inside a C++ mangling. Node *N; if (Mangling.startswith("_Z") || Mangling.startswith("__Z") || Mangling.startswith("___Z") || Mangling.startswith("____Z")) N = Demangler.parse(); else N = Demangler.make<itanium_demangle::NameType>( StringView(Mangling.data(), Mangling.size())); return reinterpret_cast<ItaniumManglingCanonicalizer::Key>(N); } ItaniumManglingCanonicalizer::Key ItaniumManglingCanonicalizer::canonicalize(StringRef Mangling) { return parseMaybeMangledName(P->Demangler, Mangling, true); } ItaniumManglingCanonicalizer::Key ItaniumManglingCanonicalizer::lookup(StringRef Mangling) { return parseMaybeMangledName(P->Demangler, Mangling, false); }
Upload File
Create Folder