Comdat.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef LLVM_IR_COMDAT_H
  16. #define LLVM_IR_COMDAT_H
  17. #include "llvm/ADT/StringRef.h"
  18. #include "llvm/Support/Compiler.h"
  19. namespace llvm {
  20. class raw_ostream;
  21. template <typename ValueTy> class StringMapEntry;
  22. // This is a Name X SelectionKind pair. The reason for having this be an
  23. // independent object instead of just adding the name and the SelectionKind
  24. // to a GlobalObject is that it is invalid to have two Comdats with the same
  25. // name but different SelectionKind. This structure makes that unrepresentable.
  26. class Comdat {
  27. public:
  28. enum SelectionKind {
  29. Any, ///< The linker may choose any COMDAT.
  30. ExactMatch, ///< The data referenced by the COMDAT must be the same.
  31. Largest, ///< The linker will choose the largest COMDAT.
  32. NoDuplicates, ///< No other Module may specify this COMDAT.
  33. SameSize, ///< The data referenced by the COMDAT must be the same size.
  34. };
  35. Comdat(Comdat &&C);
  36. SelectionKind getSelectionKind() const { return SK; }
  37. void setSelectionKind(SelectionKind Val) { SK = Val; }
  38. StringRef getName() const;
  39. void print(raw_ostream &OS) const;
  40. void dump() const;
  41. private:
  42. friend class Module;
  43. Comdat();
  44. Comdat(SelectionKind SK, StringMapEntry<Comdat> *Name);
  45. Comdat(const Comdat &) = delete;
  46. // Points to the map in Module.
  47. StringMapEntry<Comdat> *Name;
  48. SelectionKind SK;
  49. };
  50. inline raw_ostream &operator<<(raw_ostream &OS, const Comdat &C) {
  51. C.print(OS);
  52. return OS;
  53. }
  54. } // end llvm namespace
  55. #endif