| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef LLVM_IR_STATEPOINT_H |
| 17 |
#define LLVM_IR_STATEPOINT_H |
| 18 |
|
| 19 |
#include "llvm/ADT/Optional.h" |
| 20 |
#include "llvm/ADT/iterator_range.h" |
| 21 |
#include "llvm/IR/Attributes.h" |
| 22 |
#include "llvm/IR/Constants.h" |
| 23 |
#include "llvm/IR/Function.h" |
| 24 |
#include "llvm/IR/InstrTypes.h" |
| 25 |
#include "llvm/IR/Instructions.h" |
| 26 |
#include "llvm/IR/IntrinsicInst.h" |
| 27 |
#include "llvm/IR/Intrinsics.h" |
| 28 |
#include "llvm/Support/Casting.h" |
| 29 |
#include "llvm/Support/MathExtras.h" |
| 30 |
#include <cassert> |
| 31 |
#include <cstddef> |
| 32 |
#include <cstdint> |
| 33 |
#include <vector> |
| 34 |
|
| 35 |
namespace llvm { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
enum class StatepointFlags { |
| 40 |
None = 0, |
| 41 |
GCTransition = 1, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
DeoptLiveIn = 2, |
| 50 |
|
| 51 |
MaskAll = 3 |
| 52 |
}; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
class GCRelocateInst; |
| 57 |
class GCResultInst; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
class GCStatepointInst : public CallBase { |
| 63 |
public: |
| 64 |
GCStatepointInst() = delete; |
| 65 |
GCStatepointInst(const GCStatepointInst &) = delete; |
| 66 |
GCStatepointInst &operator=(const GCStatepointInst &) = delete; |
| 67 |
|
| 68 |
static bool classof(const CallBase *I) { |
| 69 |
if (const Function *CF = I->getCalledFunction()) |
| 70 |
return CF->getIntrinsicID() == Intrinsic::experimental_gc_statepoint; |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
static bool classof(const Value *V) { |
| 75 |
return isa<CallBase>(V) && classof(cast<CallBase>(V)); |
| 76 |
} |
| 77 |
|
| 78 |
enum { |
| 79 |
IDPos = 0, |
| 80 |
NumPatchBytesPos = 1, |
| 81 |
CalledFunctionPos = 2, |
| 82 |
NumCallArgsPos = 3, |
| 83 |
FlagsPos = 4, |
| 84 |
CallArgsBeginPos = 5, |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
uint64_t getID() const { |
| 89 |
return cast<ConstantInt>(getArgOperand(IDPos))->getZExtValue(); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
uint32_t getNumPatchBytes() const { |
| 94 |
const Value *NumPatchBytesVal = getArgOperand(NumPatchBytesPos); |
| 95 |
uint64_t NumPatchBytes = |
| 96 |
cast<ConstantInt>(NumPatchBytesVal)->getZExtValue(); |
| 97 |
assert(isInt<32>(NumPatchBytes) && "should fit in 32 bits!"); |
| 98 |
return NumPatchBytes; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
int getNumCallArgs() const { |
| 103 |
return cast<ConstantInt>(getArgOperand(NumCallArgsPos))->getZExtValue(); |
| 104 |
} |
| 105 |
|
| 106 |
uint64_t getFlags() const { |
| 107 |
return cast<ConstantInt>(getArgOperand(FlagsPos))->getZExtValue(); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
Value *getActualCalledOperand() const { |
| 112 |
return getArgOperand(CalledFunctionPos); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
Function *getActualCalledFunction() const { |
| 118 |
return dyn_cast_or_null<Function>(getActualCalledOperand()); |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
Type *getActualReturnType() const { |
| 124 |
auto *CalleeTy = |
| 125 |
getActualCalledOperand()->getType()->getPointerElementType(); |
| 126 |
return cast<FunctionType>(CalleeTy)->getReturnType(); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
size_t actual_arg_size() const { return getNumCallArgs(); } |
| 132 |
|
| 133 |
const_op_iterator actual_arg_begin() const { |
| 134 |
assert(CallArgsBeginPos <= (int)arg_size()); |
| 135 |
return arg_begin() + CallArgsBeginPos; |
| 136 |
} |
| 137 |
|
| 138 |
const_op_iterator actual_arg_end() const { |
| 139 |
auto I = actual_arg_begin() + actual_arg_size(); |
| 140 |
assert((arg_end() - I) == 2); |
| 141 |
return I; |
| 142 |
} |
| 143 |
|
| 144 |
iterator_range<const_op_iterator> actual_args() const { |
| 145 |
return make_range(actual_arg_begin(), actual_arg_end()); |
| 146 |
} |
| 147 |
|
| 148 |
const_op_iterator gc_transition_args_begin() const { |
| 149 |
if (auto Opt = getOperandBundle(LLVMContext::OB_gc_transition)) |
| 150 |
return Opt->Inputs.begin(); |
| 151 |
return arg_end(); |
| 152 |
} |
| 153 |
const_op_iterator gc_transition_args_end() const { |
| 154 |
if (auto Opt = getOperandBundle(LLVMContext::OB_gc_transition)) |
| 155 |
return Opt->Inputs.end(); |
| 156 |
return arg_end(); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
iterator_range<const_op_iterator> gc_transition_args() const { |
| 161 |
return make_range(gc_transition_args_begin(), gc_transition_args_end()); |
| 162 |
} |
| 163 |
|
| 164 |
const_op_iterator deopt_begin() const { |
| 165 |
if (auto Opt = getOperandBundle(LLVMContext::OB_deopt)) |
| 166 |
return Opt->Inputs.begin(); |
| 167 |
return arg_end(); |
| 168 |
} |
| 169 |
const_op_iterator deopt_end() const { |
| 170 |
if (auto Opt = getOperandBundle(LLVMContext::OB_deopt)) |
| 171 |
return Opt->Inputs.end(); |
| 172 |
return arg_end(); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
iterator_range<const_op_iterator> deopt_operands() const { |
| 177 |
return make_range(deopt_begin(), deopt_end()); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
const_op_iterator gc_args_begin() const { |
| 183 |
if (auto Opt = getOperandBundle(LLVMContext::OB_gc_live)) |
| 184 |
return Opt->Inputs.begin(); |
| 185 |
return arg_end(); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
const_op_iterator gc_args_end() const { |
| 190 |
if (auto Opt = getOperandBundle(LLVMContext::OB_gc_live)) |
| 191 |
return Opt->Inputs.end(); |
| 192 |
return arg_end(); |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
iterator_range<const_op_iterator> gc_args() const { |
| 197 |
return make_range(gc_args_begin(), gc_args_end()); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
inline std::vector<const GCRelocateInst *> getGCRelocates() const; |
| 206 |
}; |
| 207 |
|
| 208 |
std::vector<const GCRelocateInst *> GCStatepointInst::getGCRelocates() const { |
| 209 |
std::vector<const GCRelocateInst *> Result; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
for (const User *U : users()) |
| 215 |
if (auto *Relocate = dyn_cast<GCRelocateInst>(U)) |
| 216 |
Result.push_back(Relocate); |
| 217 |
|
| 218 |
auto *StatepointInvoke = dyn_cast<InvokeInst>(this); |
| 219 |
if (!StatepointInvoke) |
| 220 |
return Result; |
| 221 |
|
| 222 |
|
| 223 |
LandingPadInst *LandingPad = StatepointInvoke->getLandingPadInst(); |
| 224 |
|
| 225 |
|
| 226 |
for (const User *LandingPadUser : LandingPad->users()) { |
| 227 |
if (auto *Relocate = dyn_cast<GCRelocateInst>(LandingPadUser)) |
| 228 |
Result.push_back(Relocate); |
| 229 |
} |
| 230 |
return Result; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
struct StatepointDirectives { |
| 238 |
Optional<uint32_t> NumPatchBytes; |
| 239 |
Optional<uint64_t> StatepointID; |
| 240 |
|
| 241 |
static const uint64_t DefaultStatepointID = 0xABCDEF00; |
| 242 |
static const uint64_t DeoptBundleStatepointID = 0xABCDEF0F; |
| 243 |
}; |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS); |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
bool isStatepointDirectiveAttr(Attribute Attr); |
| 252 |
|
| 253 |
} |
| 254 |
|
| 255 |
#endif |