• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- llvm/IR/Comdat.h - Comdat definitions -------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// @file
11 /// This file contains the declaration of the Comdat class, which represents a
12 /// single COMDAT in LLVM.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_COMDAT_H
17 #define LLVM_IR_COMDAT_H
18 
19 namespace llvm {
20 
21 class raw_ostream;
22 class StringRef;
23 template <typename ValueTy> class StringMapEntry;
24 
25 // This is a Name X SelectionKind pair. The reason for having this be an
26 // independent object instead of just adding the name and the SelectionKind
27 // to a GlobalObject is that it is invalid to have two Comdats with the same
28 // name but different SelectionKind. This structure makes that unrepresentable.
29 class Comdat {
30 public:
31   enum SelectionKind {
32     Any,          ///< The linker may choose any COMDAT.
33     ExactMatch,   ///< The data referenced by the COMDAT must be the same.
34     Largest,      ///< The linker will choose the largest COMDAT.
35     NoDuplicates, ///< No other Module may specify this COMDAT.
36     SameSize,     ///< The data referenced by the COMDAT must be the same size.
37   };
38 
39   Comdat(Comdat &&C);
getSelectionKind()40   SelectionKind getSelectionKind() const { return SK; }
setSelectionKind(SelectionKind Val)41   void setSelectionKind(SelectionKind Val) { SK = Val; }
42   StringRef getName() const;
43   void print(raw_ostream &OS, bool IsForDebug = false) const;
44   void dump() const;
45 
46 private:
47   friend class Module;
48   Comdat();
49   Comdat(const Comdat &) = delete;
50 
51   // Points to the map in Module.
52   StringMapEntry<Comdat> *Name;
53   SelectionKind SK;
54 };
55 
56 inline raw_ostream &operator<<(raw_ostream &OS, const Comdat &C) {
57   C.print(OS);
58   return OS;
59 }
60 
61 } // end llvm namespace
62 
63 #endif
64