IRTransformLayer.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IRTransformLayer.h - Run all IR through a functor --------*- 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. // Run all IR passed in through a user supplied functor.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  18. #define LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  19. #include "llvm/ADT/FunctionExtras.h"
  20. #include "llvm/ExecutionEngine/JITSymbol.h"
  21. #include "llvm/ExecutionEngine/Orc/Layer.h"
  22. #include <memory>
  23. namespace llvm {
  24. namespace orc {
  25. /// A layer that applies a transform to emitted modules.
  26. /// The transform function is responsible for locking the ThreadSafeContext
  27. /// before operating on the module.
  28. class IRTransformLayer : public IRLayer {
  29. public:
  30. using TransformFunction = unique_function<Expected<ThreadSafeModule>(
  31. ThreadSafeModule, MaterializationResponsibility &R)>;
  32. IRTransformLayer(ExecutionSession &ES, IRLayer &BaseLayer,
  33. TransformFunction Transform = identityTransform);
  34. void setTransform(TransformFunction Transform) {
  35. this->Transform = std::move(Transform);
  36. }
  37. void emit(std::unique_ptr<MaterializationResponsibility> R,
  38. ThreadSafeModule TSM) override;
  39. static ThreadSafeModule identityTransform(ThreadSafeModule TSM,
  40. MaterializationResponsibility &R) {
  41. return TSM;
  42. }
  43. private:
  44. IRLayer &BaseLayer;
  45. TransformFunction Transform;
  46. };
  47. } // end namespace orc
  48. } // end namespace llvm
  49. #endif // LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  50. #ifdef __GNUC__
  51. #pragma GCC diagnostic pop
  52. #endif