Comdat.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/Support/CBindingWrapping.h"
  23. namespace llvm {
  24. class raw_ostream;
  25. class StringRef;
  26. template <typename ValueTy> class StringMapEntry;
  27. // This is a Name X SelectionKind pair. The reason for having this be an
  28. // independent object instead of just adding the name and the SelectionKind
  29. // to a GlobalObject is that it is invalid to have two Comdats with the same
  30. // name but different SelectionKind. This structure makes that unrepresentable.
  31. class Comdat {
  32. public:
  33. enum SelectionKind {
  34. Any, ///< The linker may choose any COMDAT.
  35. ExactMatch, ///< The data referenced by the COMDAT must be the same.
  36. Largest, ///< The linker will choose the largest COMDAT.
  37. NoDuplicates, ///< No other Module may specify this COMDAT.
  38. SameSize, ///< The data referenced by the COMDAT must be the same size.
  39. };
  40. Comdat(const Comdat &) = delete;
  41. Comdat(Comdat &&C);
  42. SelectionKind getSelectionKind() const { return SK; }
  43. void setSelectionKind(SelectionKind Val) { SK = Val; }
  44. StringRef getName() const;
  45. void print(raw_ostream &OS, bool IsForDebug = false) const;
  46. void dump() const;
  47. private:
  48. friend class Module;
  49. Comdat();
  50. // Points to the map in Module.
  51. StringMapEntry<Comdat> *Name = nullptr;
  52. SelectionKind SK = Any;
  53. };
  54. // Create wrappers for C Binding types (see CBindingWrapping.h).
  55. DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Comdat, LLVMComdatRef)
  56. inline raw_ostream &operator<<(raw_ostream &OS, const Comdat &C) {
  57. C.print(OS);
  58. return OS;
  59. }
  60. } // end namespace llvm
  61. #endif // LLVM_IR_COMDAT_H
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif