IRTransformLayer.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //===- IRTransformLayer.h - Run all IR through a functor --------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Run all IR passed in through a user supplied functor.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  13. #define LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  14. #include "llvm/ADT/FunctionExtras.h"
  15. #include "llvm/ExecutionEngine/JITSymbol.h"
  16. #include "llvm/ExecutionEngine/Orc/Layer.h"
  17. #include <memory>
  18. #include <string>
  19. namespace llvm {
  20. class Module;
  21. namespace orc {
  22. /// A layer that applies a transform to emitted modules.
  23. /// The transform function is responsible for locking the ThreadSafeContext
  24. /// before operating on the module.
  25. class IRTransformLayer : public IRLayer {
  26. public:
  27. using TransformFunction = unique_function<Expected<ThreadSafeModule>(
  28. ThreadSafeModule, MaterializationResponsibility &R)>;
  29. IRTransformLayer(ExecutionSession &ES, IRLayer &BaseLayer,
  30. TransformFunction Transform = identityTransform);
  31. void setTransform(TransformFunction Transform) {
  32. this->Transform = std::move(Transform);
  33. }
  34. void emit(std::unique_ptr<MaterializationResponsibility> R,
  35. ThreadSafeModule TSM) override;
  36. static ThreadSafeModule identityTransform(ThreadSafeModule TSM,
  37. MaterializationResponsibility &R) {
  38. return TSM;
  39. }
  40. private:
  41. IRLayer &BaseLayer;
  42. TransformFunction Transform;
  43. };
  44. } // end namespace orc
  45. } // end namespace llvm
  46. #endif // LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H