Mangler.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===-- llvm/IR/Mangler.h - Self-contained name mangler ---------*- 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. // Unified name mangler for various backends.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_IR_MANGLER_H
  14. #define LLVM_IR_MANGLER_H
  15. #include "llvm/ADT/DenseMap.h"
  16. #include "llvm/Support/raw_ostream.h"
  17. namespace llvm {
  18. class DataLayout;
  19. class GlobalValue;
  20. template <typename T> class SmallVectorImpl;
  21. class Twine;
  22. class Mangler {
  23. /// We need to give global values the same name every time they are mangled.
  24. /// This keeps track of the number we give to anonymous ones.
  25. mutable DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
  26. /// This simple counter is used to unique value names.
  27. mutable unsigned NextAnonGlobalID;
  28. public:
  29. Mangler() : NextAnonGlobalID(1) {}
  30. /// Print the appropriate prefix and the specified global variable's name.
  31. /// If the global variable doesn't have a name, this fills in a unique name
  32. /// for the global.
  33. void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
  34. bool CannotUsePrivateLabel) const;
  35. void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
  36. bool CannotUsePrivateLabel) const;
  37. /// Print the appropriate prefix and the specified name as the global variable
  38. /// name. GVName must not be empty.
  39. static void getNameWithPrefix(raw_ostream &OS, const Twine &GVName,
  40. const DataLayout &DL);
  41. static void getNameWithPrefix(SmallVectorImpl<char> &OutName,
  42. const Twine &GVName, const DataLayout &DL);
  43. };
  44. } // End llvm namespace
  45. #endif