Comdat.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/IR/Comdat.h - Comdat definitions --------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// @file
  15. /// This file contains the declaration of the Comdat class, which represents a
  16. /// single COMDAT in LLVM.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_IR_COMDAT_H
  20. #define LLVM_IR_COMDAT_H
  21. #include "llvm-c/Types.h"
  22. #include "llvm/ADT/SmallPtrSet.h"
  23. #include "llvm/Support/CBindingWrapping.h"
  24. namespace llvm {
  25. class GlobalObject;
  26. class raw_ostream;
  27. class StringRef;
  28. template <typename ValueTy> class StringMapEntry;
  29. // This is a Name X SelectionKind pair. The reason for having this be an
  30. // independent object instead of just adding the name and the SelectionKind
  31. // to a GlobalObject is that it is invalid to have two Comdats with the same
  32. // name but different SelectionKind. This structure makes that unrepresentable.
  33. class Comdat {
  34. public:
  35. enum SelectionKind {
  36. Any, ///< The linker may choose any COMDAT.
  37. ExactMatch, ///< The data referenced by the COMDAT must be the same.
  38. Largest, ///< The linker will choose the largest COMDAT.
  39. NoDeduplicate, ///< No deduplication is performed.
  40. SameSize, ///< The data referenced by the COMDAT must be the same size.
  41. };
  42. Comdat(const Comdat &) = delete;
  43. Comdat(Comdat &&C);
  44. SelectionKind getSelectionKind() const { return SK; }
  45. void setSelectionKind(SelectionKind Val) { SK = Val; }
  46. StringRef getName() const;
  47. void print(raw_ostream &OS, bool IsForDebug = false) const;
  48. void dump() const;
  49. const SmallPtrSetImpl<GlobalObject *> &getUsers() const { return Users; }
  50. private:
  51. friend class Module;
  52. friend class GlobalObject;
  53. Comdat();
  54. void addUser(GlobalObject *GO);
  55. void removeUser(GlobalObject *GO);
  56. // Points to the map in Module.
  57. StringMapEntry<Comdat> *Name = nullptr;
  58. SelectionKind SK = Any;
  59. // Globals using this comdat.
  60. SmallPtrSet<GlobalObject *, 2> Users;
  61. };
  62. // Create wrappers for C Binding types (see CBindingWrapping.h).
  63. DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Comdat, LLVMComdatRef)
  64. inline raw_ostream &operator<<(raw_ostream &OS, const Comdat &C) {
  65. C.print(OS);
  66. return OS;
  67. }
  68. } // end namespace llvm
  69. #endif // LLVM_IR_COMDAT_H
  70. #ifdef __GNUC__
  71. #pragma GCC diagnostic pop
  72. #endif