LLVM  13.0.0git
TargetProcessControlTypes.h
Go to the documentation of this file.
1 //===--- TargetProcessControlTypes.h -- Shared Core/TPC types ---*- 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 // TargetProcessControl types that are used by both the Orc and
10 // OrcTargetProcess libraries.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
15 #define LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/StringRef.h"
20 
21 #include <vector>
22 
23 namespace llvm {
24 namespace orc {
25 namespace tpctypes {
26 
27 template <typename T> struct UIntWrite {
28  UIntWrite() = default;
30  : Address(Address), Value(Value) {}
31 
33  T Value = 0;
34 };
35 
36 /// Describes a write to a uint8_t.
38 
39 /// Describes a write to a uint16_t.
41 
42 /// Describes a write to a uint32_t.
44 
45 /// Describes a write to a uint64_t.
47 
48 /// Describes a write to a buffer.
49 /// For use with TargetProcessControl::MemoryAccess objects.
50 struct BufferWrite {
51  BufferWrite() = default;
54 
57 };
58 
59 /// A handle used to represent a loaded dylib in the target process.
61 
62 using LookupResult = std::vector<JITTargetAddress>;
63 
64 /// Either a uint8_t array or a uint8_t*.
66  uint8_t Value[8];
67  uint8_t *ValuePtr;
68 };
69 
70 /// C ABI compatible wrapper function result.
71 ///
72 /// This can be safely returned from extern "C" functions, but should be used
73 /// to construct a WrapperFunctionResult for safety.
75  uint64_t Size;
78 };
79 
80 /// C++ wrapper function result: Same as CWrapperFunctionResult but
81 /// auto-releases memory.
83 public:
84  /// Create a default WrapperFunctionResult.
85  WrapperFunctionResult() { zeroInit(R); }
86 
87  /// Create a WrapperFunctionResult from a CWrapperFunctionResult. This
88  /// instance takes ownership of the result object and will automatically
89  /// call the Destroy member upon destruction.
91 
94 
96  zeroInit(R);
97  std::swap(R, Other.R);
98  }
99 
102  zeroInit(Tmp);
103  std::swap(Tmp, Other.R);
104  std::swap(R, Tmp);
105  return *this;
106  }
107 
109  if (R.Destroy)
110  R.Destroy(R.Data, R.Size);
111  }
112 
113  /// Relinquish ownership of and return the CWrapperFunctionResult.
116  zeroInit(Tmp);
117  std::swap(R, Tmp);
118  return Tmp;
119  }
120 
121  /// Get an ArrayRef covering the data in the result.
123  if (R.Size <= 8)
124  return ArrayRef<uint8_t>(R.Data.Value, R.Size);
125  return ArrayRef<uint8_t>(R.Data.ValuePtr, R.Size);
126  }
127 
128  /// Create a WrapperFunctionResult from the given integer, provided its
129  /// size is no greater than 64 bits.
130  template <typename T,
131  typename _ = std::enable_if_t<std::is_integral<T>::value &&
132  sizeof(T) <= sizeof(uint64_t)>>
133  static WrapperFunctionResult from(T Value) {
135  R.Size = sizeof(T);
136  memcpy(&R.Data.Value, Value, R.Size);
137  R.Destroy = nullptr;
138  return R;
139  }
140 
141  /// Create a WrapperFunctionResult from the given string.
142  static WrapperFunctionResult from(StringRef S);
143 
144  /// Always free Data.ValuePtr by calling free on it.
145  static void destroyWithFree(CWrapperFunctionResultData Data, uint64_t Size);
146 
147  /// Always free Data.ValuePtr by calling delete[] on it.
148  static void destroyWithDeleteArray(CWrapperFunctionResultData Data,
149  uint64_t Size);
150 
151 private:
152  static void zeroInit(CWrapperFunctionResult &R) {
153  R.Size = 0;
154  R.Data.ValuePtr = nullptr;
155  R.Destroy = nullptr;
156  }
157 
158  CWrapperFunctionResult R;
159 };
160 
161 } // end namespace tpctypes
162 } // end namespace orc
163 } // end namespace llvm
164 
165 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::orc::tpctypes::WrapperFunctionResult::~WrapperFunctionResult
~WrapperFunctionResult()
Definition: TargetProcessControlTypes.h:108
llvm
Definition: AllocatorList.h:23
JITSymbol.h
StringRef.h
llvm::orc::tpctypes::WrapperFunctionResult::WrapperFunctionResult
WrapperFunctionResult(CWrapperFunctionResult R)
Create a WrapperFunctionResult from a CWrapperFunctionResult.
Definition: TargetProcessControlTypes.h:90
llvm::orc::tpctypes::UIntWrite::UIntWrite
UIntWrite(JITTargetAddress Address, T Value)
Definition: TargetProcessControlTypes.h:29
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::tpctypes::CWrapperFunctionResult::Destroy
void(* Destroy)(CWrapperFunctionResultData Data, uint64_t Size)
Definition: TargetProcessControlTypes.h:77
llvm::orc::tpctypes::UIntWrite::UIntWrite
UIntWrite()=default
llvm::orc::tpctypes::WrapperFunctionResult::getData
ArrayRef< uint8_t > getData() const
Get an ArrayRef covering the data in the result.
Definition: TargetProcessControlTypes.h:122
llvm::orc::tpctypes::BufferWrite::Address
JITTargetAddress Address
Definition: TargetProcessControlTypes.h:55
llvm::orc::tpctypes::LookupResult
std::vector< JITTargetAddress > LookupResult
Definition: TargetProcessControlTypes.h:62
llvm::orc::tpctypes::WrapperFunctionResult::WrapperFunctionResult
WrapperFunctionResult()
Create a default WrapperFunctionResult.
Definition: TargetProcessControlTypes.h:85
llvm::orc::tpctypes::WrapperFunctionResult::release
CWrapperFunctionResult release()
Relinquish ownership of and return the CWrapperFunctionResult.
Definition: TargetProcessControlTypes.h:114
llvm::orc::tpctypes::DylibHandle
JITTargetAddress DylibHandle
A handle used to represent a loaded dylib in the target process.
Definition: TargetProcessControlTypes.h:60
llvm::orc::tpctypes::UIntWrite::Address
JITTargetAddress Address
Definition: TargetProcessControlTypes.h:32
llvm::orc::tpctypes::BufferWrite
Describes a write to a buffer.
Definition: TargetProcessControlTypes.h:50
llvm::orc::tpctypes::WrapperFunctionResult::operator=
WrapperFunctionResult & operator=(const WrapperFunctionResult &)=delete
llvm::orc::tpctypes::WrapperFunctionResult::operator=
WrapperFunctionResult & operator=(WrapperFunctionResult &&Other)
Definition: TargetProcessControlTypes.h:100
llvm::orc::tpctypes::BufferWrite::Buffer
StringRef Buffer
Definition: TargetProcessControlTypes.h:56
llvm::orc::tpctypes::BufferWrite::BufferWrite
BufferWrite()=default
llvm::orc::tpctypes::CWrapperFunctionResult::Data
CWrapperFunctionResultData Data
Definition: TargetProcessControlTypes.h:76
ArrayRef.h
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:840
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::orc::tpctypes::CWrapperFunctionResult::Size
uint64_t Size
Definition: TargetProcessControlTypes.h:75
llvm::orc::tpctypes::CWrapperFunctionResultData::ValuePtr
uint8_t * ValuePtr
Definition: TargetProcessControlTypes.h:67
_
#define _
Definition: HexagonMCCodeEmitter.cpp:47
llvm::orc::tpctypes::UIntWrite
Definition: TargetProcessControlTypes.h:27
llvm::ArrayRef< uint8_t >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::orc::tpctypes::WrapperFunctionResult::WrapperFunctionResult
WrapperFunctionResult(WrapperFunctionResult &&Other)
Definition: TargetProcessControlTypes.h:95
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::orc::tpctypes::CWrapperFunctionResult
C ABI compatible wrapper function result.
Definition: TargetProcessControlTypes.h:74
llvm::JITTargetAddress
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Definition: JITSymbol.h:42
llvm::orc::tpctypes::BufferWrite::BufferWrite
BufferWrite(JITTargetAddress Address, StringRef Buffer)
Definition: TargetProcessControlTypes.h:52
llvm::orc::tpctypes::WrapperFunctionResult
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
Definition: TargetProcessControlTypes.h:82
llvm::orc::tpctypes::CWrapperFunctionResultData
Either a uint8_t array or a uint8_t*.
Definition: TargetProcessControlTypes.h:65
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1169