Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:53

0001 //===- IRTransformLayer.h - Run all IR through a functor --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Run all IR passed in through a user supplied functor.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
0014 #define LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
0015 
0016 #include "llvm/ADT/FunctionExtras.h"
0017 #include "llvm/ExecutionEngine/JITSymbol.h"
0018 #include "llvm/ExecutionEngine/Orc/Layer.h"
0019 #include <memory>
0020 
0021 namespace llvm {
0022 namespace orc {
0023 
0024 /// A layer that applies a transform to emitted modules.
0025 /// The transform function is responsible for locking the ThreadSafeContext
0026 /// before operating on the module.
0027 class IRTransformLayer : public IRLayer {
0028 public:
0029   using TransformFunction = unique_function<Expected<ThreadSafeModule>(
0030       ThreadSafeModule, MaterializationResponsibility &R)>;
0031 
0032   IRTransformLayer(ExecutionSession &ES, IRLayer &BaseLayer,
0033                    TransformFunction Transform = identityTransform);
0034 
0035   void setTransform(TransformFunction Transform) {
0036     this->Transform = std::move(Transform);
0037   }
0038 
0039   void emit(std::unique_ptr<MaterializationResponsibility> R,
0040             ThreadSafeModule TSM) override;
0041 
0042   static ThreadSafeModule identityTransform(ThreadSafeModule TSM,
0043                                             MaterializationResponsibility &R) {
0044     return TSM;
0045   }
0046 
0047 private:
0048   IRLayer &BaseLayer;
0049   TransformFunction Transform;
0050 };
0051 
0052 } // end namespace orc
0053 } // end namespace llvm
0054 
0055 #endif // LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H