Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:57

0001 //===- llvm/IR/Comdat.h - Comdat definitions --------------------*- 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 /// @file
0010 /// This file contains the declaration of the Comdat class, which represents a
0011 /// single COMDAT in LLVM.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_IR_COMDAT_H
0016 #define LLVM_IR_COMDAT_H
0017 
0018 #include "llvm-c/Types.h"
0019 #include "llvm/ADT/SmallPtrSet.h"
0020 #include "llvm/Support/CBindingWrapping.h"
0021 
0022 namespace llvm {
0023 
0024 class GlobalObject;
0025 class raw_ostream;
0026 class StringRef;
0027 template <typename ValueTy> class StringMapEntry;
0028 
0029 // This is a Name X SelectionKind pair. The reason for having this be an
0030 // independent object instead of just adding the name and the SelectionKind
0031 // to a GlobalObject is that it is invalid to have two Comdats with the same
0032 // name but different SelectionKind. This structure makes that unrepresentable.
0033 class Comdat {
0034 public:
0035   enum SelectionKind {
0036     Any,           ///< The linker may choose any COMDAT.
0037     ExactMatch,    ///< The data referenced by the COMDAT must be the same.
0038     Largest,       ///< The linker will choose the largest COMDAT.
0039     NoDeduplicate, ///< No deduplication is performed.
0040     SameSize,      ///< The data referenced by the COMDAT must be the same size.
0041   };
0042 
0043   Comdat(const Comdat &) = delete;
0044   Comdat(Comdat &&C);
0045 
0046   SelectionKind getSelectionKind() const { return SK; }
0047   void setSelectionKind(SelectionKind Val) { SK = Val; }
0048   StringRef getName() const;
0049   void print(raw_ostream &OS, bool IsForDebug = false) const;
0050   void dump() const;
0051   const SmallPtrSetImpl<GlobalObject *> &getUsers() const { return Users; }
0052 
0053 private:
0054   friend class Module;
0055   friend class GlobalObject;
0056 
0057   Comdat();
0058   void addUser(GlobalObject *GO);
0059   void removeUser(GlobalObject *GO);
0060 
0061   // Points to the map in Module.
0062   StringMapEntry<Comdat> *Name = nullptr;
0063   SelectionKind SK = Any;
0064   // Globals using this comdat.
0065   SmallPtrSet<GlobalObject *, 2> Users;
0066 };
0067 
0068 // Create wrappers for C Binding types (see CBindingWrapping.h).
0069 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Comdat, LLVMComdatRef)
0070 
0071 inline raw_ostream &operator<<(raw_ostream &OS, const Comdat &C) {
0072   C.print(OS);
0073   return OS;
0074 }
0075 
0076 } // end namespace llvm
0077 
0078 #endif // LLVM_IR_COMDAT_H