xref: /freebsd/contrib/llvm-project/compiler-rt/lib/orc/jit_dispatch.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===------ jit_dispatch.h - Call back to an ORC controller -----*- C++ -*-===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
8*700637cbSDimitry Andric //
9*700637cbSDimitry Andric // This file is a part of the ORC runtime support library.
10*700637cbSDimitry Andric //
11*700637cbSDimitry Andric //===----------------------------------------------------------------------===//
12*700637cbSDimitry Andric 
13*700637cbSDimitry Andric #ifndef ORC_RT_JIT_DISPATCH_H
14*700637cbSDimitry Andric #define ORC_RT_JIT_DISPATCH_H
15*700637cbSDimitry Andric 
16*700637cbSDimitry Andric #include "common.h"
17*700637cbSDimitry Andric #include "wrapper_function_utils.h"
18*700637cbSDimitry Andric 
19*700637cbSDimitry Andric namespace orc_rt {
20*700637cbSDimitry Andric 
21*700637cbSDimitry Andric class JITDispatch {
22*700637cbSDimitry Andric public:
JITDispatch(const void * FnTag)23*700637cbSDimitry Andric   JITDispatch(const void *FnTag) : FnTag(FnTag) {}
24*700637cbSDimitry Andric 
operator()25*700637cbSDimitry Andric   WrapperFunctionResult operator()(const char *ArgData, size_t ArgSize) {
26*700637cbSDimitry Andric     // Since the functions cannot be zero/unresolved on Windows, the following
27*700637cbSDimitry Andric     // reference taking would always be non-zero, thus generating a compiler
28*700637cbSDimitry Andric     // warning otherwise.
29*700637cbSDimitry Andric #if !defined(_WIN32)
30*700637cbSDimitry Andric     if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch_ctx))
31*700637cbSDimitry Andric       return WrapperFunctionResult::createOutOfBandError(
32*700637cbSDimitry Andric                  "__orc_rt_jit_dispatch_ctx not set")
33*700637cbSDimitry Andric           .release();
34*700637cbSDimitry Andric     if (ORC_RT_UNLIKELY(!&__orc_rt_jit_dispatch))
35*700637cbSDimitry Andric       return WrapperFunctionResult::createOutOfBandError(
36*700637cbSDimitry Andric                  "__orc_rt_jit_dispatch not set")
37*700637cbSDimitry Andric           .release();
38*700637cbSDimitry Andric #endif
39*700637cbSDimitry Andric 
40*700637cbSDimitry Andric     return __orc_rt_jit_dispatch(&__orc_rt_jit_dispatch_ctx, FnTag, ArgData,
41*700637cbSDimitry Andric                                  ArgSize);
42*700637cbSDimitry Andric   }
43*700637cbSDimitry Andric 
44*700637cbSDimitry Andric private:
45*700637cbSDimitry Andric   const void *FnTag;
46*700637cbSDimitry Andric };
47*700637cbSDimitry Andric 
48*700637cbSDimitry Andric } // namespace orc_rt
49*700637cbSDimitry Andric 
50*700637cbSDimitry Andric #endif // ORC_RT_JIT_DISPATCH_H
51