Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Blame | Last modification | View Log | Download | RSS feed

  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.  
  13. #ifndef LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  14. #define LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  15.  
  16. #include "llvm/ADT/FunctionExtras.h"
  17. #include "llvm/ExecutionEngine/JITSymbol.h"
  18. #include "llvm/ExecutionEngine/Orc/Layer.h"
  19. #include <memory>
  20.  
  21. namespace llvm {
  22. namespace orc {
  23.  
  24. /// A layer that applies a transform to emitted modules.
  25. /// The transform function is responsible for locking the ThreadSafeContext
  26. /// before operating on the module.
  27. class IRTransformLayer : public IRLayer {
  28. public:
  29.   using TransformFunction = unique_function<Expected<ThreadSafeModule>(
  30.       ThreadSafeModule, MaterializationResponsibility &R)>;
  31.  
  32.   IRTransformLayer(ExecutionSession &ES, IRLayer &BaseLayer,
  33.                    TransformFunction Transform = identityTransform);
  34.  
  35.   void setTransform(TransformFunction Transform) {
  36.     this->Transform = std::move(Transform);
  37.   }
  38.  
  39.   void emit(std::unique_ptr<MaterializationResponsibility> R,
  40.             ThreadSafeModule TSM) override;
  41.  
  42.   static ThreadSafeModule identityTransform(ThreadSafeModule TSM,
  43.                                             MaterializationResponsibility &R) {
  44.     return TSM;
  45.   }
  46.  
  47. private:
  48.   IRLayer &BaseLayer;
  49.   TransformFunction Transform;
  50. };
  51.  
  52. } // end namespace orc
  53. } // end namespace llvm
  54.  
  55. #endif // LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
  56.