Mangling.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===------ Mangling.h -- Name Mangling Utilities for ORC -------*- 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. // Name mangling utilities for ORC.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_ORC_MANGLING_H
  18. #define LLVM_EXECUTIONENGINE_ORC_MANGLING_H
  19. #include "llvm/ExecutionEngine/Orc/Core.h"
  20. #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
  21. #include "llvm/IR/Module.h"
  22. #include "llvm/Support/MemoryBuffer.h"
  23. namespace llvm {
  24. namespace orc {
  25. /// Mangles symbol names then uniques them in the context of an
  26. /// ExecutionSession.
  27. class MangleAndInterner {
  28. public:
  29. MangleAndInterner(ExecutionSession &ES, const DataLayout &DL);
  30. SymbolStringPtr operator()(StringRef Name);
  31. private:
  32. ExecutionSession &ES;
  33. const DataLayout &DL;
  34. };
  35. /// Maps IR global values to their linker symbol names / flags.
  36. ///
  37. /// This utility can be used when adding new IR globals in the JIT.
  38. class IRSymbolMapper {
  39. public:
  40. struct ManglingOptions {
  41. bool EmulatedTLS = false;
  42. };
  43. using SymbolNameToDefinitionMap = std::map<SymbolStringPtr, GlobalValue *>;
  44. /// Add mangled symbols for the given GlobalValues to SymbolFlags.
  45. /// If a SymbolToDefinitionMap pointer is supplied then it will be populated
  46. /// with Name-to-GlobalValue* mappings. Note that this mapping is not
  47. /// necessarily one-to-one: thread-local GlobalValues, for example, may
  48. /// produce more than one symbol, in which case the map will contain duplicate
  49. /// values.
  50. static void add(ExecutionSession &ES, const ManglingOptions &MO,
  51. ArrayRef<GlobalValue *> GVs, SymbolFlagsMap &SymbolFlags,
  52. SymbolNameToDefinitionMap *SymbolToDefinition = nullptr);
  53. };
  54. /// Returns a SymbolFlagsMap for the object file represented by the given
  55. /// buffer, or an error if the buffer does not contain a valid object file.
  56. Expected<std::pair<SymbolFlagsMap, SymbolStringPtr>>
  57. getObjectSymbolInfo(ExecutionSession &ES, MemoryBufferRef ObjBuffer);
  58. } // End namespace orc
  59. } // End namespace llvm
  60. #endif // LLVM_EXECUTIONENGINE_ORC_MANGLING_H
  61. #ifdef __GNUC__
  62. #pragma GCC diagnostic pop
  63. #endif