LLVM  13.0.0git
StatepointLowering.cpp
Go to the documentation of this file.
1 //===- StatepointLowering.cpp - SDAGBuilder's statepoint code -------------===//
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 // This file includes support code use by SelectionDAGBuilder when lowering a
10 // statepoint sequence in SelectionDAG IR.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "StatepointLowering.h"
15 #include "SelectionDAGBuilder.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/None.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallSet.h"
21 #include "llvm/ADT/Statistic.h"
31 #include "llvm/CodeGen/StackMaps.h"
34 #include "llvm/IR/CallingConv.h"
35 #include "llvm/IR/DerivedTypes.h"
36 #include "llvm/IR/Instruction.h"
37 #include "llvm/IR/Instructions.h"
38 #include "llvm/IR/LLVMContext.h"
39 #include "llvm/IR/Statepoint.h"
40 #include "llvm/IR/Type.h"
41 #include "llvm/Support/Casting.h"
46 #include <cassert>
47 #include <cstddef>
48 #include <cstdint>
49 #include <iterator>
50 #include <tuple>
51 #include <utility>
52 
53 using namespace llvm;
54 
55 #define DEBUG_TYPE "statepoint-lowering"
56 
57 STATISTIC(NumSlotsAllocatedForStatepoints,
58  "Number of stack slots allocated for statepoints");
59 STATISTIC(NumOfStatepoints, "Number of statepoint nodes encountered");
60 STATISTIC(StatepointMaxSlotsRequired,
61  "Maximum number of stack slots required for a singe statepoint");
62 
64  "use-registers-for-deopt-values", cl::Hidden, cl::init(false),
65  cl::desc("Allow using registers for non pointer deopt args"));
66 
68  "use-registers-for-gc-values-in-landing-pad", cl::Hidden, cl::init(false),
69  cl::desc("Allow using registers for gc pointer in landing pad"));
70 
72  "max-registers-for-gc-values", cl::Hidden, cl::init(0),
73  cl::desc("Max number of VRegs allowed to pass GC pointer meta args in"));
74 
75 cl::opt<bool> AlwaysSpillBase("statepoint-always-spill-base", cl::Hidden,
76  cl::init(true),
77  cl::desc("Force spilling of base GC pointers"));
78 
80 
82  SelectionDAGBuilder &Builder, uint64_t Value) {
83  SDLoc L = Builder.getCurSDLoc();
84  Ops.push_back(Builder.DAG.getTargetConstant(StackMaps::ConstantOp, L,
85  MVT::i64));
86  Ops.push_back(Builder.DAG.getTargetConstant(Value, L, MVT::i64));
87 }
88 
90  // Consistency check
91  assert(PendingGCRelocateCalls.empty() &&
92  "Trying to visit statepoint before finished processing previous one");
93  Locations.clear();
94  NextSlotToAllocate = 0;
95  // Need to resize this on each safepoint - we need the two to stay in sync and
96  // the clear patterns of a SelectionDAGBuilder have no relation to
97  // FunctionLoweringInfo. Also need to ensure used bits get cleared.
98  AllocatedStackSlots.clear();
99  AllocatedStackSlots.resize(Builder.FuncInfo.StatepointStackSlots.size());
100 }
101 
103  Locations.clear();
104  AllocatedStackSlots.clear();
105  assert(PendingGCRelocateCalls.empty() &&
106  "cleared before statepoint sequence completed");
107 }
108 
109 SDValue
112  NumSlotsAllocatedForStatepoints++;
113  MachineFrameInfo &MFI = Builder.DAG.getMachineFunction().getFrameInfo();
114 
115  unsigned SpillSize = ValueType.getStoreSize();
116  assert((SpillSize * 8) ==
117  (-8u & (7 + ValueType.getSizeInBits())) && // Round up modulo 8.
118  "Size not in bytes?");
119 
120  // First look for a previously created stack slot which is not in
121  // use (accounting for the fact arbitrary slots may already be
122  // reserved), or to create a new stack slot and use it.
123 
124  const size_t NumSlots = AllocatedStackSlots.size();
125  assert(NextSlotToAllocate <= NumSlots && "Broken invariant");
126 
127  assert(AllocatedStackSlots.size() ==
128  Builder.FuncInfo.StatepointStackSlots.size() &&
129  "Broken invariant");
130 
131  for (; NextSlotToAllocate < NumSlots; NextSlotToAllocate++) {
132  if (!AllocatedStackSlots.test(NextSlotToAllocate)) {
133  const int FI = Builder.FuncInfo.StatepointStackSlots[NextSlotToAllocate];
134  if (MFI.getObjectSize(FI) == SpillSize) {
135  AllocatedStackSlots.set(NextSlotToAllocate);
136  // TODO: Is ValueType the right thing to use here?
137  return Builder.DAG.getFrameIndex(FI, ValueType);
138  }
139  }
140  }
141 
142  // Couldn't find a free slot, so create a new one:
143 
144  SDValue SpillSlot = Builder.DAG.CreateStackTemporary(ValueType);
145  const unsigned FI = cast<FrameIndexSDNode>(SpillSlot)->getIndex();
147 
148  Builder.FuncInfo.StatepointStackSlots.push_back(FI);
149  AllocatedStackSlots.resize(AllocatedStackSlots.size()+1, true);
150  assert(AllocatedStackSlots.size() ==
151  Builder.FuncInfo.StatepointStackSlots.size() &&
152  "Broken invariant");
153 
154  StatepointMaxSlotsRequired.updateMax(
155  Builder.FuncInfo.StatepointStackSlots.size());
156 
157  return SpillSlot;
158 }
159 
160 /// Utility function for reservePreviousStackSlotForValue. Tries to find
161 /// stack slot index to which we have spilled value for previous statepoints.
162 /// LookUpDepth specifies maximum DFS depth this function is allowed to look.
165  int LookUpDepth) {
166  // Can not look any further - give up now
167  if (LookUpDepth <= 0)
168  return None;
169 
170  // Spill location is known for gc relocates
171  if (const auto *Relocate = dyn_cast<GCRelocateInst>(Val)) {
172  const auto &RelocationMap =
173  Builder.FuncInfo.StatepointRelocationMaps[Relocate->getStatepoint()];
174 
175  auto It = RelocationMap.find(Relocate->getDerivedPtr());
176  if (It == RelocationMap.end())
177  return None;
178 
179  auto &Record = It->second;
180  if (Record.type != RecordType::Spill)
181  return None;
182 
183  return Record.payload.FI;
184  }
185 
186  // Look through bitcast instructions.
187  if (const BitCastInst *Cast = dyn_cast<BitCastInst>(Val))
188  return findPreviousSpillSlot(Cast->getOperand(0), Builder, LookUpDepth - 1);
189 
190  // Look through phi nodes
191  // All incoming values should have same known stack slot, otherwise result
192  // is unknown.
193  if (const PHINode *Phi = dyn_cast<PHINode>(Val)) {
194  Optional<int> MergedResult = None;
195 
196  for (auto &IncomingValue : Phi->incoming_values()) {
197  Optional<int> SpillSlot =
198  findPreviousSpillSlot(IncomingValue, Builder, LookUpDepth - 1);
199  if (!SpillSlot.hasValue())
200  return None;
201 
202  if (MergedResult.hasValue() && *MergedResult != *SpillSlot)
203  return None;
204 
205  MergedResult = SpillSlot;
206  }
207  return MergedResult;
208  }
209 
210  // TODO: We can do better for PHI nodes. In cases like this:
211  // ptr = phi(relocated_pointer, not_relocated_pointer)
212  // statepoint(ptr)
213  // We will return that stack slot for ptr is unknown. And later we might
214  // assign different stack slots for ptr and relocated_pointer. This limits
215  // llvm's ability to remove redundant stores.
216  // Unfortunately it's hard to accomplish in current infrastructure.
217  // We use this function to eliminate spill store completely, while
218  // in example we still need to emit store, but instead of any location
219  // we need to use special "preferred" location.
220 
221  // TODO: handle simple updates. If a value is modified and the original
222  // value is no longer live, it would be nice to put the modified value in the
223  // same slot. This allows folding of the memory accesses for some
224  // instructions types (like an increment).
225  // statepoint (i)
226  // i1 = i+1
227  // statepoint (i1)
228  // However we need to be careful for cases like this:
229  // statepoint(i)
230  // i1 = i+1
231  // statepoint(i, i1)
232  // Here we want to reserve spill slot for 'i', but not for 'i+1'. If we just
233  // put handling of simple modifications in this function like it's done
234  // for bitcasts we might end up reserving i's slot for 'i+1' because order in
235  // which we visit values is unspecified.
236 
237  // Don't know any information about this instruction
238  return None;
239 }
240 
241 /// Return true if-and-only-if the given SDValue can be lowered as either a
242 /// constant argument or a stack reference. The key point is that the value
243 /// doesn't need to be spilled or tracked as a vreg use.
244 static bool willLowerDirectly(SDValue Incoming) {
245  // We are making an unchecked assumption that the frame size <= 2^16 as that
246  // is the largest offset which can be encoded in the stackmap format.
247  if (isa<FrameIndexSDNode>(Incoming))
248  return true;
249 
250  // The largest constant describeable in the StackMap format is 64 bits.
251  // Potential Optimization: Constants values are sign extended by consumer,
252  // and thus there are many constants of static type > 64 bits whose value
253  // happens to be sext(Con64) and could thus be lowered directly.
254  if (Incoming.getValueType().getSizeInBits() > 64)
255  return false;
256 
257  return (isa<ConstantSDNode>(Incoming) || isa<ConstantFPSDNode>(Incoming) ||
258  Incoming.isUndef());
259 }
260 
261 /// Try to find existing copies of the incoming values in stack slots used for
262 /// statepoint spilling. If we can find a spill slot for the incoming value,
263 /// mark that slot as allocated, and reuse the same slot for this safepoint.
264 /// This helps to avoid series of loads and stores that only serve to reshuffle
265 /// values on the stack between calls.
266 static void reservePreviousStackSlotForValue(const Value *IncomingValue,
268  SDValue Incoming = Builder.getValue(IncomingValue);
269 
270  // If we won't spill this, we don't need to check for previously allocated
271  // stack slots.
272  if (willLowerDirectly(Incoming))
273  return;
274 
275  SDValue OldLocation = Builder.StatepointLowering.getLocation(Incoming);
276  if (OldLocation.getNode())
277  // Duplicates in input
278  return;
279 
280  const int LookUpDepth = 6;
282  findPreviousSpillSlot(IncomingValue, Builder, LookUpDepth);
283  if (!Index.hasValue())
284  return;
285 
286  const auto &StatepointSlots = Builder.FuncInfo.StatepointStackSlots;
287 
288  auto SlotIt = find(StatepointSlots, *Index);
289  assert(SlotIt != StatepointSlots.end() &&
290  "Value spilled to the unknown stack slot");
291 
292  // This is one of our dedicated lowering slots
293  const int Offset = std::distance(StatepointSlots.begin(), SlotIt);
294  if (Builder.StatepointLowering.isStackSlotAllocated(Offset)) {
295  // stack slot already assigned to someone else, can't use it!
296  // TODO: currently we reserve space for gc arguments after doing
297  // normal allocation for deopt arguments. We should reserve for
298  // _all_ deopt and gc arguments, then start allocating. This
299  // will prevent some moves being inserted when vm state changes,
300  // but gc state doesn't between two calls.
301  return;
302  }
303  // Reserve this stack slot
304  Builder.StatepointLowering.reserveStackSlot(Offset);
305 
306  // Cache this slot so we find it when going through the normal
307  // assignment loop.
308  SDValue Loc =
309  Builder.DAG.getTargetFrameIndex(*Index, Builder.getFrameIndexTy());
310  Builder.StatepointLowering.setLocation(Incoming, Loc);
311 }
312 
313 /// Extract call from statepoint, lower it and return pointer to the
314 /// call node. Also update NodeMap so that getValue(statepoint) will
315 /// reference lowered call result
316 static std::pair<SDValue, SDNode *> lowerCallFromStatepointLoweringInfo(
319  SDValue ReturnValue, CallEndVal;
320  std::tie(ReturnValue, CallEndVal) =
321  Builder.lowerInvokable(SI.CLI, SI.EHPadBB);
322  SDNode *CallEnd = CallEndVal.getNode();
323 
324  // Get a call instruction from the call sequence chain. Tail calls are not
325  // allowed. The following code is essentially reverse engineering X86's
326  // LowerCallTo.
327  //
328  // We are expecting DAG to have the following form:
329  //
330  // ch = eh_label (only in case of invoke statepoint)
331  // ch, glue = callseq_start ch
332  // ch, glue = X86::Call ch, glue
333  // ch, glue = callseq_end ch, glue
334  // get_return_value ch, glue
335  //
336  // get_return_value can either be a sequence of CopyFromReg instructions
337  // to grab the return value from the return register(s), or it can be a LOAD
338  // to load a value returned by reference via a stack slot.
339 
340  bool HasDef = !SI.CLI.RetTy->isVoidTy();
341  if (HasDef) {
342  if (CallEnd->getOpcode() == ISD::LOAD)
343  CallEnd = CallEnd->getOperand(0).getNode();
344  else
345  while (CallEnd->getOpcode() == ISD::CopyFromReg)
346  CallEnd = CallEnd->getOperand(0).getNode();
347  }
348 
349  assert(CallEnd->getOpcode() == ISD::CALLSEQ_END && "expected!");
350  return std::make_pair(ReturnValue, CallEnd->getOperand(0).getNode());
351 }
352 
354  FrameIndexSDNode &FI) {
355  auto PtrInfo = MachinePointerInfo::getFixedStack(MF, FI.getIndex());
356  auto MMOFlags = MachineMemOperand::MOStore |
358  auto &MFI = MF.getFrameInfo();
359  return MF.getMachineMemOperand(PtrInfo, MMOFlags,
360  MFI.getObjectSize(FI.getIndex()),
361  MFI.getObjectAlign(FI.getIndex()));
362 }
363 
364 /// Spill a value incoming to the statepoint. It might be either part of
365 /// vmstate
366 /// or gcstate. In both cases unconditionally spill it on the stack unless it
367 /// is a null constant. Return pair with first element being frame index
368 /// containing saved value and second element with outgoing chain from the
369 /// emitted store
370 static std::tuple<SDValue, SDValue, MachineMemOperand*>
373  SDValue Loc = Builder.StatepointLowering.getLocation(Incoming);
374  MachineMemOperand* MMO = nullptr;
375 
376  // Emit new store if we didn't do it for this ptr before
377  if (!Loc.getNode()) {
378  Loc = Builder.StatepointLowering.allocateStackSlot(Incoming.getValueType(),
379  Builder);
380  int Index = cast<FrameIndexSDNode>(Loc)->getIndex();
381  // We use TargetFrameIndex so that isel will not select it into LEA
382  Loc = Builder.DAG.getTargetFrameIndex(Index, Builder.getFrameIndexTy());
383 
384  // Right now we always allocate spill slots that are of the same
385  // size as the value we're about to spill (the size of spillee can
386  // vary since we spill vectors of pointers too). At some point we
387  // can consider allowing spills of smaller values to larger slots
388  // (i.e. change the '==' in the assert below to a '>=').
389  MachineFrameInfo &MFI = Builder.DAG.getMachineFunction().getFrameInfo();
390  assert((MFI.getObjectSize(Index) * 8) ==
391  (-8 & (7 + // Round up modulo 8.
392  (int64_t)Incoming.getValueSizeInBits())) &&
393  "Bad spill: stack slot does not match!");
394 
395  // Note: Using the alignment of the spill slot (rather than the abi or
396  // preferred alignment) is required for correctness when dealing with spill
397  // slots with preferred alignments larger than frame alignment..
398  auto &MF = Builder.DAG.getMachineFunction();
399  auto PtrInfo = MachinePointerInfo::getFixedStack(MF, Index);
400  auto *StoreMMO = MF.getMachineMemOperand(
402  MFI.getObjectAlign(Index));
403  Chain = Builder.DAG.getStore(Chain, Builder.getCurSDLoc(), Incoming, Loc,
404  StoreMMO);
405 
406  MMO = getMachineMemOperand(MF, *cast<FrameIndexSDNode>(Loc));
407 
408  Builder.StatepointLowering.setLocation(Incoming, Loc);
409  }
410 
411  assert(Loc.getNode());
412  return std::make_tuple(Loc, Chain, MMO);
413 }
414 
415 /// Lower a single value incoming to a statepoint node. This value can be
416 /// either a deopt value or a gc value, the handling is the same. We special
417 /// case constants and allocas, then fall back to spilling if required.
418 static void
419 lowerIncomingStatepointValue(SDValue Incoming, bool RequireSpillSlot,
423 
424  if (willLowerDirectly(Incoming)) {
425  if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Incoming)) {
426  // This handles allocas as arguments to the statepoint (this is only
427  // really meaningful for a deopt value. For GC, we'd be trying to
428  // relocate the address of the alloca itself?)
429  assert(Incoming.getValueType() == Builder.getFrameIndexTy() &&
430  "Incoming value is a frame index!");
431  Ops.push_back(Builder.DAG.getTargetFrameIndex(FI->getIndex(),
432  Builder.getFrameIndexTy()));
433 
434  auto &MF = Builder.DAG.getMachineFunction();
435  auto *MMO = getMachineMemOperand(MF, *FI);
436  MemRefs.push_back(MMO);
437  return;
438  }
439 
440  assert(Incoming.getValueType().getSizeInBits() <= 64);
441 
442  if (Incoming.isUndef()) {
443  // Put an easily recognized constant that's unlikely to be a valid
444  // value so that uses of undef by the consumer of the stackmap is
445  // easily recognized. This is legal since the compiler is always
446  // allowed to chose an arbitrary value for undef.
447  pushStackMapConstant(Ops, Builder, 0xFEFEFEFE);
448  return;
449  }
450 
451  // If the original value was a constant, make sure it gets recorded as
452  // such in the stackmap. This is required so that the consumer can
453  // parse any internal format to the deopt state. It also handles null
454  // pointers and other constant pointers in GC states.
455  if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Incoming)) {
456  pushStackMapConstant(Ops, Builder, C->getSExtValue());
457  return;
458  } else if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Incoming)) {
460  C->getValueAPF().bitcastToAPInt().getZExtValue());
461  return;
462  }
463 
464  llvm_unreachable("unhandled direct lowering case");
465  }
466 
467 
468 
469  if (!RequireSpillSlot) {
470  // If this value is live in (not live-on-return, or live-through), we can
471  // treat it the same way patchpoint treats it's "live in" values. We'll
472  // end up folding some of these into stack references, but they'll be
473  // handled by the register allocator. Note that we do not have the notion
474  // of a late use so these values might be placed in registers which are
475  // clobbered by the call. This is fine for live-in. For live-through
476  // fix-up pass should be executed to force spilling of such registers.
477  Ops.push_back(Incoming);
478  } else {
479  // Otherwise, locate a spill slot and explicitly spill it so it can be
480  // found by the runtime later. Note: We know all of these spills are
481  // independent, but don't bother to exploit that chain wise. DAGCombine
482  // will happily do so as needed, so doing it here would be a small compile
483  // time win at most.
484  SDValue Chain = Builder.getRoot();
485  auto Res = spillIncomingStatepointValue(Incoming, Chain, Builder);
486  Ops.push_back(std::get<0>(Res));
487  if (auto *MMO = std::get<2>(Res))
488  MemRefs.push_back(MMO);
489  Chain = std::get<1>(Res);;
490  Builder.DAG.setRoot(Chain);
491  }
492 
493 }
494 
495 /// Return true if value V represents the GC value. The behavior is conservative
496 /// in case it is not sure that value is not GC the function returns true.
497 static bool isGCValue(const Value *V, SelectionDAGBuilder &Builder) {
498  auto *Ty = V->getType();
499  if (!Ty->isPtrOrPtrVectorTy())
500  return false;
501  if (auto *GFI = Builder.GFI)
502  if (auto IsManaged = GFI->getStrategy().isGCManagedPointer(Ty))
503  return *IsManaged;
504  return true; // conservative
505 }
506 
507 /// Lower deopt state and gc pointer arguments of the statepoint. The actual
508 /// lowering is described in lowerIncomingStatepointValue. This function is
509 /// responsible for lowering everything in the right position and playing some
510 /// tricks to avoid redundant stack manipulation where possible. On
511 /// completion, 'Ops' will contain ready to use operands for machine code
512 /// statepoint. The chain nodes will have already been created and the DAG root
513 /// will be set to the last value spilled (if any were).
514 static void
517  SmallVectorImpl<SDValue> &GCPtrs,
518  DenseMap<SDValue, int> &LowerAsVReg,
521  // Lower the deopt and gc arguments for this statepoint. Layout will be:
522  // deopt argument length, deopt arguments.., gc arguments...
523 #ifndef NDEBUG
524  if (auto *GFI = Builder.GFI) {
525  // Check that each of the gc pointer and bases we've gotten out of the
526  // safepoint is something the strategy thinks might be a pointer (or vector
527  // of pointers) into the GC heap. This is basically just here to help catch
528  // errors during statepoint insertion. TODO: This should actually be in the
529  // Verifier, but we can't get to the GCStrategy from there (yet).
530  GCStrategy &S = GFI->getStrategy();
531  for (const Value *V : SI.Bases) {
532  auto Opt = S.isGCManagedPointer(V->getType()->getScalarType());
533  if (Opt.hasValue()) {
534  assert(Opt.getValue() &&
535  "non gc managed base pointer found in statepoint");
536  }
537  }
538  for (const Value *V : SI.Ptrs) {
539  auto Opt = S.isGCManagedPointer(V->getType()->getScalarType());
540  if (Opt.hasValue()) {
541  assert(Opt.getValue() &&
542  "non gc managed derived pointer found in statepoint");
543  }
544  }
545  assert(SI.Bases.size() == SI.Ptrs.size() && "Pointer without base!");
546  } else {
547  assert(SI.Bases.empty() && "No gc specified, so cannot relocate pointers!");
548  assert(SI.Ptrs.empty() && "No gc specified, so cannot relocate pointers!");
549  }
550 #endif
551 
552  // Figure out what lowering strategy we're going to use for each part
553  // Note: Is is conservatively correct to lower both "live-in" and "live-out"
554  // as "live-through". A "live-through" variable is one which is "live-in",
555  // "live-out", and live throughout the lifetime of the call (i.e. we can find
556  // it from any PC within the transitive callee of the statepoint). In
557  // particular, if the callee spills callee preserved registers we may not
558  // be able to find a value placed in that register during the call. This is
559  // fine for live-out, but not for live-through. If we were willing to make
560  // assumptions about the code generator producing the callee, we could
561  // potentially allow live-through values in callee saved registers.
562  const bool LiveInDeopt =
563  SI.StatepointFlags & (uint64_t)StatepointFlags::DeoptLiveIn;
564 
565  // Decide which deriver pointers will go on VRegs
566  unsigned MaxVRegPtrs = MaxRegistersForGCPointers.getValue();
567 
568  // Pointers used on exceptional path of invoke statepoint.
569  // We cannot assing them to VRegs.
570  SmallSet<SDValue, 8> LPadPointers;
572  if (auto *StInvoke = dyn_cast_or_null<InvokeInst>(SI.StatepointInstr)) {
573  LandingPadInst *LPI = StInvoke->getLandingPadInst();
574  for (auto *Relocate : SI.GCRelocates)
575  if (Relocate->getOperand(0) == LPI) {
576  LPadPointers.insert(Builder.getValue(Relocate->getBasePtr()));
577  LPadPointers.insert(Builder.getValue(Relocate->getDerivedPtr()));
578  }
579  }
580 
581  LLVM_DEBUG(dbgs() << "Deciding how to lower GC Pointers:\n");
582 
583  // List of unique lowered GC Pointer values.
584  SmallSetVector<SDValue, 16> LoweredGCPtrs;
585  // Map lowered GC Pointer value to the index in above vector
586  DenseMap<SDValue, unsigned> GCPtrIndexMap;
587 
588  unsigned CurNumVRegs = 0;
589 
590  auto canPassGCPtrOnVReg = [&](SDValue SD) {
591  if (SD.getValueType().isVector())
592  return false;
593  if (LPadPointers.count(SD))
594  return false;
595  return !willLowerDirectly(SD);
596  };
597 
598  auto processGCPtr = [&](const Value *V) {
599  SDValue PtrSD = Builder.getValue(V);
600  if (!LoweredGCPtrs.insert(PtrSD))
601  return; // skip duplicates
602  GCPtrIndexMap[PtrSD] = LoweredGCPtrs.size() - 1;
603 
604  assert(!LowerAsVReg.count(PtrSD) && "must not have been seen");
605  if (LowerAsVReg.size() == MaxVRegPtrs)
606  return;
607  assert(V->getType()->isVectorTy() == PtrSD.getValueType().isVector() &&
608  "IR and SD types disagree");
609  if (!canPassGCPtrOnVReg(PtrSD)) {
610  LLVM_DEBUG(dbgs() << "direct/spill "; PtrSD.dump(&Builder.DAG));
611  return;
612  }
613  LLVM_DEBUG(dbgs() << "vreg "; PtrSD.dump(&Builder.DAG));
614  LowerAsVReg[PtrSD] = CurNumVRegs++;
615  };
616 
617  // Process derived pointers first to give them more chance to go on VReg.
618  for (const Value *V : SI.Ptrs)
619  processGCPtr(V);
620  for (const Value *V : SI.Bases)
621  processGCPtr(V);
622 
623  LLVM_DEBUG(dbgs() << LowerAsVReg.size() << " pointers will go in vregs\n");
624 
625  auto requireSpillSlot = [&](const Value *V) {
626  if (!Builder.DAG.getTargetLoweringInfo().isTypeLegal(
627  Builder.getValue(V).getValueType()))
628  return true;
629  if (isGCValue(V, Builder))
630  return !LowerAsVReg.count(Builder.getValue(V));
631  return !(LiveInDeopt || UseRegistersForDeoptValues);
632  };
633 
634  // Before we actually start lowering (and allocating spill slots for values),
635  // reserve any stack slots which we judge to be profitable to reuse for a
636  // particular value. This is purely an optimization over the code below and
637  // doesn't change semantics at all. It is important for performance that we
638  // reserve slots for both deopt and gc values before lowering either.
639  for (const Value *V : SI.DeoptState) {
640  if (requireSpillSlot(V))
642  }
643 
644  for (const Value *V : SI.Ptrs) {
645  SDValue SDV = Builder.getValue(V);
646  if (!LowerAsVReg.count(SDV))
648  }
649 
650  for (const Value *V : SI.Bases) {
651  SDValue SDV = Builder.getValue(V);
652  if (!LowerAsVReg.count(SDV))
654  }
655 
656  // First, prefix the list with the number of unique values to be
657  // lowered. Note that this is the number of *Values* not the
658  // number of SDValues required to lower them.
659  const int NumVMSArgs = SI.DeoptState.size();
660  pushStackMapConstant(Ops, Builder, NumVMSArgs);
661 
662  // The vm state arguments are lowered in an opaque manner. We do not know
663  // what type of values are contained within.
664  LLVM_DEBUG(dbgs() << "Lowering deopt state\n");
665  for (const Value *V : SI.DeoptState) {
666  SDValue Incoming;
667  // If this is a function argument at a static frame index, generate it as
668  // the frame index.
669  if (const Argument *Arg = dyn_cast<Argument>(V)) {
670  int FI = Builder.FuncInfo.getArgumentFrameIndex(Arg);
671  if (FI != INT_MAX)
672  Incoming = Builder.DAG.getFrameIndex(FI, Builder.getFrameIndexTy());
673  }
674  if (!Incoming.getNode())
675  Incoming = Builder.getValue(V);
676  LLVM_DEBUG(dbgs() << "Value " << *V
677  << " requireSpillSlot = " << requireSpillSlot(V) << "\n");
678  lowerIncomingStatepointValue(Incoming, requireSpillSlot(V), Ops, MemRefs,
679  Builder);
680  }
681 
682  // Finally, go ahead and lower all the gc arguments.
683  pushStackMapConstant(Ops, Builder, LoweredGCPtrs.size());
684  for (SDValue SDV : LoweredGCPtrs)
685  lowerIncomingStatepointValue(SDV, !LowerAsVReg.count(SDV), Ops, MemRefs,
686  Builder);
687 
688  // Copy to out vector. LoweredGCPtrs will be empty after this point.
689  GCPtrs = LoweredGCPtrs.takeVector();
690 
691  // If there are any explicit spill slots passed to the statepoint, record
692  // them, but otherwise do not do anything special. These are user provided
693  // allocas and give control over placement to the consumer. In this case,
694  // it is the contents of the slot which may get updated, not the pointer to
695  // the alloca
696  SmallVector<SDValue, 4> Allocas;
697  for (Value *V : SI.GCArgs) {
698  SDValue Incoming = Builder.getValue(V);
699  if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Incoming)) {
700  // This handles allocas as arguments to the statepoint
701  assert(Incoming.getValueType() == Builder.getFrameIndexTy() &&
702  "Incoming value is a frame index!");
703  Allocas.push_back(Builder.DAG.getTargetFrameIndex(
704  FI->getIndex(), Builder.getFrameIndexTy()));
705 
706  auto &MF = Builder.DAG.getMachineFunction();
707  auto *MMO = getMachineMemOperand(MF, *FI);
708  MemRefs.push_back(MMO);
709  }
710  }
711  pushStackMapConstant(Ops, Builder, Allocas.size());
712  Ops.append(Allocas.begin(), Allocas.end());
713 
714  // Now construct GC base/derived map;
715  pushStackMapConstant(Ops, Builder, SI.Ptrs.size());
716  SDLoc L = Builder.getCurSDLoc();
717  for (unsigned i = 0; i < SI.Ptrs.size(); ++i) {
718  SDValue Base = Builder.getValue(SI.Bases[i]);
719  assert(GCPtrIndexMap.count(Base) && "base not found in index map");
720  Ops.push_back(
721  Builder.DAG.getTargetConstant(GCPtrIndexMap[Base], L, MVT::i64));
722  SDValue Derived = Builder.getValue(SI.Ptrs[i]);
723  assert(GCPtrIndexMap.count(Derived) && "derived not found in index map");
724  Ops.push_back(
725  Builder.DAG.getTargetConstant(GCPtrIndexMap[Derived], L, MVT::i64));
726  }
727 }
728 
731  // The basic scheme here is that information about both the original call and
732  // the safepoint is encoded in the CallInst. We create a temporary call and
733  // lower it, then reverse engineer the calling sequence.
734 
735  NumOfStatepoints++;
736  // Clear state
738  assert(SI.Bases.size() == SI.Ptrs.size());
739 
740  LLVM_DEBUG(dbgs() << "Lowering statepoint " << *SI.StatepointInstr << "\n");
741 #ifndef NDEBUG
742  for (auto *Reloc : SI.GCRelocates)
743  if (Reloc->getParent() == SI.StatepointInstr->getParent())
745 #endif
746 
747  // Lower statepoint vmstate and gcstate arguments
748 
749  // All lowered meta args.
750  SmallVector<SDValue, 10> LoweredMetaArgs;
751  // Lowered GC pointers (subset of above).
752  SmallVector<SDValue, 16> LoweredGCArgs;
754  // Maps derived pointer SDValue to statepoint result of relocated pointer.
755  DenseMap<SDValue, int> LowerAsVReg;
756  lowerStatepointMetaArgs(LoweredMetaArgs, MemRefs, LoweredGCArgs, LowerAsVReg,
757  SI, *this);
758 
759  // Now that we've emitted the spills, we need to update the root so that the
760  // call sequence is ordered correctly.
761  SI.CLI.setChain(getRoot());
762 
763  // Get call node, we will replace it later with statepoint
764  SDValue ReturnVal;
765  SDNode *CallNode;
766  std::tie(ReturnVal, CallNode) =
767  lowerCallFromStatepointLoweringInfo(SI, *this, PendingExports);
768 
769  // Construct the actual GC_TRANSITION_START, STATEPOINT, and GC_TRANSITION_END
770  // nodes with all the appropriate arguments and return values.
771 
772  // Call Node: Chain, Target, {Args}, RegMask, [Glue]
773  SDValue Chain = CallNode->getOperand(0);
774 
775  SDValue Glue;
776  bool CallHasIncomingGlue = CallNode->getGluedNode();
777  if (CallHasIncomingGlue) {
778  // Glue is always last operand
779  Glue = CallNode->getOperand(CallNode->getNumOperands() - 1);
780  }
781 
782  // Build the GC_TRANSITION_START node if necessary.
783  //
784  // The operands to the GC_TRANSITION_{START,END} nodes are laid out in the
785  // order in which they appear in the call to the statepoint intrinsic. If
786  // any of the operands is a pointer-typed, that operand is immediately
787  // followed by a SRCVALUE for the pointer that may be used during lowering
788  // (e.g. to form MachinePointerInfo values for loads/stores).
789  const bool IsGCTransition =
790  (SI.StatepointFlags & (uint64_t)StatepointFlags::GCTransition) ==
792  if (IsGCTransition) {
794 
795  // Add chain
796  TSOps.push_back(Chain);
797 
798  // Add GC transition arguments
799  for (const Value *V : SI.GCTransitionArgs) {
800  TSOps.push_back(getValue(V));
801  if (V->getType()->isPointerTy())
802  TSOps.push_back(DAG.getSrcValue(V));
803  }
804 
805  // Add glue if necessary
806  if (CallHasIncomingGlue)
807  TSOps.push_back(Glue);
808 
810 
811  SDValue GCTransitionStart =
812  DAG.getNode(ISD::GC_TRANSITION_START, getCurSDLoc(), NodeTys, TSOps);
813 
814  Chain = GCTransitionStart.getValue(0);
815  Glue = GCTransitionStart.getValue(1);
816  }
817 
818  // TODO: Currently, all of these operands are being marked as read/write in
819  // PrologEpilougeInserter.cpp, we should special case the VMState arguments
820  // and flags to be read-only.
822 
823  // Add the <id> and <numBytes> constants.
824  Ops.push_back(DAG.getTargetConstant(SI.ID, getCurSDLoc(), MVT::i64));
825  Ops.push_back(
826  DAG.getTargetConstant(SI.NumPatchBytes, getCurSDLoc(), MVT::i32));
827 
828  // Calculate and push starting position of vmstate arguments
829  // Get number of arguments incoming directly into call node
830  unsigned NumCallRegArgs =
831  CallNode->getNumOperands() - (CallHasIncomingGlue ? 4 : 3);
832  Ops.push_back(DAG.getTargetConstant(NumCallRegArgs, getCurSDLoc(), MVT::i32));
833 
834  // Add call target
835  SDValue CallTarget = SDValue(CallNode->getOperand(1).getNode(), 0);
836  Ops.push_back(CallTarget);
837 
838  // Add call arguments
839  // Get position of register mask in the call
840  SDNode::op_iterator RegMaskIt;
841  if (CallHasIncomingGlue)
842  RegMaskIt = CallNode->op_end() - 2;
843  else
844  RegMaskIt = CallNode->op_end() - 1;
845  Ops.insert(Ops.end(), CallNode->op_begin() + 2, RegMaskIt);
846 
847  // Add a constant argument for the calling convention
848  pushStackMapConstant(Ops, *this, SI.CLI.CallConv);
849 
850  // Add a constant argument for the flags
851  uint64_t Flags = SI.StatepointFlags;
852  assert(((Flags & ~(uint64_t)StatepointFlags::MaskAll) == 0) &&
853  "Unknown flag used");
854  pushStackMapConstant(Ops, *this, Flags);
855 
856  // Insert all vmstate and gcstate arguments
857  llvm::append_range(Ops, LoweredMetaArgs);
858 
859  // Add register mask from call node
860  Ops.push_back(*RegMaskIt);
861 
862  // Add chain
863  Ops.push_back(Chain);
864 
865  // Same for the glue, but we add it only if original call had it
866  if (Glue.getNode())
867  Ops.push_back(Glue);
868 
869  // Compute return values. Provide a glue output since we consume one as
870  // input. This allows someone else to chain off us as needed.
871  SmallVector<EVT, 8> NodeTys;
872  for (auto SD : LoweredGCArgs) {
873  if (!LowerAsVReg.count(SD))
874  continue;
875  NodeTys.push_back(SD.getValueType());
876  }
877  LLVM_DEBUG(dbgs() << "Statepoint has " << NodeTys.size() << " results\n");
878  assert(NodeTys.size() == LowerAsVReg.size() && "Inconsistent GC Ptr lowering");
879  NodeTys.push_back(MVT::Other);
880  NodeTys.push_back(MVT::Glue);
881 
882  unsigned NumResults = NodeTys.size();
883  MachineSDNode *StatepointMCNode =
884  DAG.getMachineNode(TargetOpcode::STATEPOINT, getCurSDLoc(), NodeTys, Ops);
885  DAG.setNodeMemRefs(StatepointMCNode, MemRefs);
886 
887  // For values lowered to tied-defs, create the virtual registers. Note that
888  // for simplicity, we *always* create a vreg even within a single block.
890  for (const auto *Relocate : SI.GCRelocates) {
891  Value *Derived = Relocate->getDerivedPtr();
892  SDValue SD = getValue(Derived);
893  if (!LowerAsVReg.count(SD))
894  continue;
895 
896  // Handle multiple gc.relocates of the same input efficiently.
897  if (VirtRegs.count(SD))
898  continue;
899 
900  SDValue Relocated = SDValue(StatepointMCNode, LowerAsVReg[SD]);
901 
902  auto *RetTy = Relocate->getType();
903  Register Reg = FuncInfo.CreateRegs(RetTy);
905  DAG.getDataLayout(), Reg, RetTy, None);
906  SDValue Chain = DAG.getRoot();
907  RFV.getCopyToRegs(Relocated, DAG, getCurSDLoc(), Chain, nullptr);
908  PendingExports.push_back(Chain);
909 
910  VirtRegs[SD] = Reg;
911  }
912 
913  // Record for later use how each relocation was lowered. This is needed to
914  // allow later gc.relocates to mirror the lowering chosen.
915  const Instruction *StatepointInstr = SI.StatepointInstr;
916  auto &RelocationMap = FuncInfo.StatepointRelocationMaps[StatepointInstr];
917  for (const GCRelocateInst *Relocate : SI.GCRelocates) {
918  const Value *V = Relocate->getDerivedPtr();
919  SDValue SDV = getValue(V);
921 
923  if (LowerAsVReg.count(SDV)) {
924  Record.type = RecordType::VReg;
925  assert(VirtRegs.count(SDV));
926  Record.payload.Reg = VirtRegs[SDV];
927  } else if (Loc.getNode()) {
928  Record.type = RecordType::Spill;
929  Record.payload.FI = cast<FrameIndexSDNode>(Loc)->getIndex();
930  } else {
932  // If we didn't relocate a value, we'll essentialy end up inserting an
933  // additional use of the original value when lowering the gc.relocate.
934  // We need to make sure the value is available at the new use, which
935  // might be in another block.
936  if (Relocate->getParent() != StatepointInstr->getParent())
938  }
939  RelocationMap[V] = Record;
940  }
941 
942 
943 
944  SDNode *SinkNode = StatepointMCNode;
945 
946  // Build the GC_TRANSITION_END node if necessary.
947  //
948  // See the comment above regarding GC_TRANSITION_START for the layout of
949  // the operands to the GC_TRANSITION_END node.
950  if (IsGCTransition) {
952 
953  // Add chain
954  TEOps.push_back(SDValue(StatepointMCNode, NumResults - 2));
955 
956  // Add GC transition arguments
957  for (const Value *V : SI.GCTransitionArgs) {
958  TEOps.push_back(getValue(V));
959  if (V->getType()->isPointerTy())
960  TEOps.push_back(DAG.getSrcValue(V));
961  }
962 
963  // Add glue
964  TEOps.push_back(SDValue(StatepointMCNode, NumResults - 1));
965 
967 
968  SDValue GCTransitionStart =
969  DAG.getNode(ISD::GC_TRANSITION_END, getCurSDLoc(), NodeTys, TEOps);
970 
971  SinkNode = GCTransitionStart.getNode();
972  }
973 
974  // Replace original call
975  // Call: ch,glue = CALL ...
976  // Statepoint: [gc relocates],ch,glue = STATEPOINT ...
977  unsigned NumSinkValues = SinkNode->getNumValues();
978  SDValue StatepointValues[2] = {SDValue(SinkNode, NumSinkValues - 2),
979  SDValue(SinkNode, NumSinkValues - 1)};
980  DAG.ReplaceAllUsesWith(CallNode, StatepointValues);
981  // Remove original call node
982  DAG.DeleteNode(CallNode);
983 
984  // Since we always emit CopyToRegs (even for local relocates), we must
985  // update root, so that they are emitted before any local uses.
986  (void)getControlRoot();
987 
988  // TODO: A better future implementation would be to emit a single variable
989  // argument, variable return value STATEPOINT node here and then hookup the
990  // return value of each gc.relocate to the respective output of the
991  // previously emitted STATEPOINT value. Unfortunately, this doesn't appear
992  // to actually be possible today.
993 
994  return ReturnVal;
995 }
996 
997 void
999  const BasicBlock *EHPadBB /*= nullptr*/) {
1000  assert(I.getCallingConv() != CallingConv::AnyReg &&
1001  "anyregcc is not supported on statepoints!");
1002 
1003 #ifndef NDEBUG
1004  // Check that the associated GCStrategy expects to encounter statepoints.
1006  "GCStrategy does not expect to encounter statepoints");
1007 #endif
1008 
1009  SDValue ActualCallee;
1010  SDValue Callee = getValue(I.getActualCalledOperand());
1011 
1012  if (I.getNumPatchBytes() > 0) {
1013  // If we've been asked to emit a nop sequence instead of a call instruction
1014  // for this statepoint then don't lower the call target, but use a constant
1015  // `undef` instead. Not lowering the call target lets statepoint clients
1016  // get away without providing a physical address for the symbolic call
1017  // target at link time.
1018  ActualCallee = DAG.getUNDEF(Callee.getValueType());
1019  } else {
1020  ActualCallee = Callee;
1021  }
1022 
1025  I.getNumCallArgs(), ActualCallee,
1026  I.getActualReturnType(), false /* IsPatchPoint */);
1027 
1028  // There may be duplication in the gc.relocate list; such as two copies of
1029  // each relocation on normal and exceptional path for an invoke. We only
1030  // need to spill once and record one copy in the stackmap, but we need to
1031  // reload once per gc.relocate. (Dedupping gc.relocates is trickier and best
1032  // handled as a CSE problem elsewhere.)
1033  // TODO: There a couple of major stackmap size optimizations we could do
1034  // here if we wished.
1035  // 1) If we've encountered a derived pair {B, D}, we don't need to actually
1036  // record {B,B} if it's seen later.
1037  // 2) Due to rematerialization, actual derived pointers are somewhat rare;
1038  // given that, we could change the format to record base pointer relocations
1039  // separately with half the space. This would require a format rev and a
1040  // fairly major rework of the STATEPOINT node though.
1041  SmallSet<SDValue, 8> Seen;
1042  for (const GCRelocateInst *Relocate : I.getGCRelocates()) {
1043  SI.GCRelocates.push_back(Relocate);
1044 
1045  SDValue DerivedSD = getValue(Relocate->getDerivedPtr());
1046  if (Seen.insert(DerivedSD).second) {
1047  SI.Bases.push_back(Relocate->getBasePtr());
1048  SI.Ptrs.push_back(Relocate->getDerivedPtr());
1049  }
1050  }
1051 
1052  // If we find a deopt value which isn't explicitly added, we need to
1053  // ensure it gets lowered such that gc cycles occurring before the
1054  // deoptimization event during the lifetime of the call don't invalidate
1055  // the pointer we're deopting with. Note that we assume that all
1056  // pointers passed to deopt are base pointers; relaxing that assumption
1057  // would require relatively large changes to how we represent relocations.
1058  for (Value *V : I.deopt_operands()) {
1059  if (!isGCValue(V, *this))
1060  continue;
1061  if (Seen.insert(getValue(V)).second) {
1062  SI.Bases.push_back(V);
1063  SI.Ptrs.push_back(V);
1064  }
1065  }
1066 
1067  SI.GCArgs = ArrayRef<const Use>(I.gc_args_begin(), I.gc_args_end());
1068  SI.StatepointInstr = &I;
1069  SI.ID = I.getID();
1070 
1071  SI.DeoptState = ArrayRef<const Use>(I.deopt_begin(), I.deopt_end());
1072  SI.GCTransitionArgs = ArrayRef<const Use>(I.gc_transition_args_begin(),
1073  I.gc_transition_args_end());
1074 
1075  SI.StatepointFlags = I.getFlags();
1076  SI.NumPatchBytes = I.getNumPatchBytes();
1077  SI.EHPadBB = EHPadBB;
1078 
1079  SDValue ReturnValue = LowerAsSTATEPOINT(SI);
1080 
1081  // Export the result value if needed
1082  const std::pair<bool, bool> GCResultLocality = I.getGCResultLocality();
1083  Type *RetTy = I.getActualReturnType();
1084 
1085  if (RetTy->isVoidTy() ||
1086  (!GCResultLocality.first && !GCResultLocality.second)) {
1087  // The return value is not needed, just generate a poison value.
1089  return;
1090  }
1091 
1092  if (GCResultLocality.first) {
1093  // Result value will be used in a same basic block. Don't export it or
1094  // perform any explicit register copies. The gc_result will simply grab
1095  // this value.
1096  setValue(&I, ReturnValue);
1097  }
1098 
1099  if (!GCResultLocality.second)
1100  return;
1101  // Result value will be used in a different basic block so we need to export
1102  // it now. Default exporting mechanism will not work here because statepoint
1103  // call has a different type than the actual call. It means that by default
1104  // llvm will create export register of the wrong type (always i32 in our
1105  // case). So instead we need to create export register with correct type
1106  // manually.
1107  // TODO: To eliminate this problem we can remove gc.result intrinsics
1108  // completely and make statepoint call to return a tuple.
1109  unsigned Reg = FuncInfo.CreateRegs(RetTy);
1111  DAG.getDataLayout(), Reg, RetTy,
1112  I.getCallingConv());
1113  SDValue Chain = DAG.getEntryNode();
1114 
1115  RFV.getCopyToRegs(ReturnValue, DAG, getCurSDLoc(), Chain, nullptr);
1116  PendingExports.push_back(Chain);
1117  FuncInfo.ValueMap[&I] = Reg;
1118 }
1119 
1121  const CallBase *Call, SDValue Callee, const BasicBlock *EHPadBB,
1122  bool VarArgDisallowed, bool ForceVoidReturnTy) {
1124  unsigned ArgBeginIndex = Call->arg_begin() - Call->op_begin();
1126  SI.CLI, Call, ArgBeginIndex, Call->getNumArgOperands(), Callee,
1127  ForceVoidReturnTy ? Type::getVoidTy(*DAG.getContext()) : Call->getType(),
1128  false);
1129  if (!VarArgDisallowed)
1130  SI.CLI.IsVarArg = Call->getFunctionType()->isVarArg();
1131 
1132  auto DeoptBundle = *Call->getOperandBundle(LLVMContext::OB_deopt);
1133 
1134  unsigned DefaultID = StatepointDirectives::DeoptBundleStatepointID;
1135 
1136  auto SD = parseStatepointDirectivesFromAttrs(Call->getAttributes());
1137  SI.ID = SD.StatepointID.getValueOr(DefaultID);
1138  SI.NumPatchBytes = SD.NumPatchBytes.getValueOr(0);
1139 
1140  SI.DeoptState =
1141  ArrayRef<const Use>(DeoptBundle.Inputs.begin(), DeoptBundle.Inputs.end());
1142  SI.StatepointFlags = static_cast<uint64_t>(StatepointFlags::None);
1143  SI.EHPadBB = EHPadBB;
1144 
1145  // NB! The GC arguments are deliberately left empty.
1146 
1147  if (SDValue ReturnVal = LowerAsSTATEPOINT(SI)) {
1148  ReturnVal = lowerRangeToAssertZExt(DAG, *Call, ReturnVal);
1149  setValue(Call, ReturnVal);
1150  }
1151 }
1152 
1154  const CallBase *Call, SDValue Callee, const BasicBlock *EHPadBB) {
1156  /* VarArgDisallowed = */ false,
1157  /* ForceVoidReturnTy = */ false);
1158 }
1159 
1160 void SelectionDAGBuilder::visitGCResult(const GCResultInst &CI) {
1161  // The result value of the gc_result is simply the result of the actual
1162  // call. We've already emitted this, so just grab the value.
1163  const GCStatepointInst *SI = CI.getStatepoint();
1164 
1165  if (SI->getParent() == CI.getParent()) {
1166  setValue(&CI, getValue(SI));
1167  return;
1168  }
1169  // Statepoint is in different basic block so we should have stored call
1170  // result in a virtual register.
1171  // We can not use default getValue() functionality to copy value from this
1172  // register because statepoint and actual call return types can be
1173  // different, and getValue() will use CopyFromReg of the wrong type,
1174  // which is always i32 in our case.
1175  Type *RetTy = SI->getActualReturnType();
1177 
1178  assert(CopyFromReg.getNode());
1179  setValue(&CI, CopyFromReg);
1180 }
1181 
1182 void SelectionDAGBuilder::visitGCRelocate(const GCRelocateInst &Relocate) {
1183 #ifndef NDEBUG
1184  // Consistency check
1185  // We skip this check for relocates not in the same basic block as their
1186  // statepoint. It would be too expensive to preserve validation info through
1187  // different basic blocks.
1188  if (Relocate.getStatepoint()->getParent() == Relocate.getParent())
1190 
1191  auto *Ty = Relocate.getType()->getScalarType();
1192  if (auto IsManaged = GFI->getStrategy().isGCManagedPointer(Ty))
1193  assert(*IsManaged && "Non gc managed pointer relocated!");
1194 #endif
1195 
1196  const Value *DerivedPtr = Relocate.getDerivedPtr();
1197  auto &RelocationMap =
1199  auto SlotIt = RelocationMap.find(DerivedPtr);
1200  assert(SlotIt != RelocationMap.end() && "Relocating not lowered gc value");
1201  const RecordType &Record = SlotIt->second;
1202 
1203  // If relocation was done via virtual register..
1204  if (Record.type == RecordType::VReg) {
1205  Register InReg = Record.payload.Reg;
1207  DAG.getDataLayout(), InReg, Relocate.getType(),
1208  None); // This is not an ABI copy.
1209  // We generate copy to/from regs even for local uses, hence we must
1210  // chain with current root to ensure proper ordering of copies w.r.t.
1211  // statepoint.
1212  SDValue Chain = DAG.getRoot();
1213  SDValue Relocation = RFV.getCopyFromRegs(DAG, FuncInfo, getCurSDLoc(),
1214  Chain, nullptr, nullptr);
1215  setValue(&Relocate, Relocation);
1216  return;
1217  }
1218 
1219  if (Record.type == RecordType::Spill) {
1220  unsigned Index = Record.payload.FI;
1222 
1223  // All the reloads are independent and are reading memory only modified by
1224  // statepoints (i.e. no other aliasing stores); informing SelectionDAG of
1225  // this this let's CSE kick in for free and allows reordering of
1226  // instructions if possible. The lowering for statepoint sets the root,
1227  // so this is ordering all reloads with the either
1228  // a) the statepoint node itself, or
1229  // b) the entry of the current block for an invoke statepoint.
1230  const SDValue Chain = DAG.getRoot(); // != Builder.getRoot()
1231 
1232  auto &MF = DAG.getMachineFunction();
1233  auto &MFI = MF.getFrameInfo();
1234  auto PtrInfo = MachinePointerInfo::getFixedStack(MF, Index);
1235  auto *LoadMMO = MF.getMachineMemOperand(PtrInfo, MachineMemOperand::MOLoad,
1236  MFI.getObjectSize(Index),
1237  MFI.getObjectAlign(Index));
1238 
1240  Relocate.getType());
1241 
1242  SDValue SpillLoad =
1243  DAG.getLoad(LoadVT, getCurSDLoc(), Chain, SpillSlot, LoadMMO);
1244  PendingLoads.push_back(SpillLoad.getValue(1));
1245 
1246  assert(SpillLoad.getNode());
1247  setValue(&Relocate, SpillLoad);
1248  return;
1249  }
1250 
1252  SDValue SD = getValue(DerivedPtr);
1253 
1254  if (SD.isUndef() && SD.getValueType().getSizeInBits() <= 64) {
1255  // Lowering relocate(undef) as arbitrary constant. Current constant value
1256  // is chosen such that it's unlikely to be a valid pointer.
1257  setValue(&Relocate, DAG.getTargetConstant(0xFEFEFEFE, SDLoc(SD), MVT::i64));
1258  return;
1259  }
1260 
1261  // We didn't need to spill these special cases (constants and allocas).
1262  // See the handling in spillIncomingValueForStatepoint for detail.
1263  setValue(&Relocate, SD);
1264 }
1265 
1267  const auto &TLI = DAG.getTargetLoweringInfo();
1268  SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(RTLIB::DEOPTIMIZE),
1269  TLI.getPointerTy(DAG.getDataLayout()));
1270 
1271  // We don't lower calls to __llvm_deoptimize as varargs, but as a regular
1272  // call. We also do not lower the return value to any virtual register, and
1273  // change the immediately following return to a trap instruction.
1274  LowerCallSiteWithDeoptBundleImpl(CI, Callee, /* EHPadBB = */ nullptr,
1275  /* VarArgDisallowed = */ true,
1276  /* ForceVoidReturnTy = */ true);
1277 }
1278 
1280  // We do not lower the return value from llvm.deoptimize to any virtual
1281  // register, and change the immediately following return to a trap
1282  // instruction.
1284  DAG.setRoot(
1286 }
llvm::SelectionDAGBuilder::LowerStatepoint
void LowerStatepoint(const GCStatepointInst &I, const BasicBlock *EHPadBB=nullptr)
Definition: StatepointLowering.cpp:998
i
i
Definition: README.txt:29
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
llvm::SmallBitVector::set
SmallBitVector & set()
Definition: SmallBitVector.h:363
pushStackMapConstant
static void pushStackMapConstant(SmallVectorImpl< SDValue > &Ops, SelectionDAGBuilder &Builder, uint64_t Value)
Definition: StatepointLowering.cpp:81
llvm::ConstantSDNode
Definition: SelectionDAGNodes.h:1536
llvm::SDValue::dump
void dump() const
Definition: SelectionDAGNodes.h:1165
llvm::SDUse
Represents a use of a SDNode.
Definition: SelectionDAGNodes.h:277
llvm
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
GCMetadata.h
Optional.h
llvm::SDLoc
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Definition: SelectionDAGNodes.h:1078
llvm::GCStrategy
GCStrategy describes a garbage collector algorithm's code generation requirements,...
Definition: GCStrategy.h:66
llvm::StatepointLoweringState::startNewStatepoint
void startNewStatepoint(SelectionDAGBuilder &Builder)
Reset all state tracking for a newly encountered safepoint.
Definition: StatepointLowering.cpp:89
llvm::SelectionDAGBuilder::setValue
void setValue(const Value *V, SDValue NewN)
Definition: SelectionDAGBuilder.h:528
llvm::Type::isPointerTy
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:229
llvm::SelectionDAGBuilder::PendingLoads
SmallVector< SDValue, 8 > PendingLoads
Loads are not emitted to the program immediately.
Definition: SelectionDAGBuilder.h:130
llvm::SDValue::getNode
SDNode * getNode() const
get the SDNode which holds the desired result
Definition: SelectionDAGNodes.h:152
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:77
llvm::BitCastInst
This class represents a no-op cast from one type to another.
Definition: Instructions.h:5136
llvm::Type::getScalarType
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:317
llvm::GCStatepointInst::CallArgsBeginPos
@ CallArgsBeginPos
Definition: Statepoint.h:85
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
Statistic.h
llvm::FunctionLoweringInfo::StatepointRelocationRecord
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
Definition: FunctionLoweringInfo.h:96
llvm::LandingPadInst
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Definition: Instructions.h:2822
llvm::SelectionDAG::getVTList
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
Definition: SelectionDAG.cpp:7967
llvm::MachineFunction::getMachineMemOperand
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, Align base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
Definition: MachineFunction.cpp:430
llvm::MachineSDNode
An SDNode that represents everything that will be needed to construct a MachineInstr.
Definition: SelectionDAGNodes.h:2522
llvm::SelectionDAGBuilder::getValue
SDValue getValue(const Value *V)
getValue - Return an SDValue for the given Value.
Definition: SelectionDAGBuilder.cpp:1452
llvm::SelectionDAG::getRoot
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
Definition: SelectionDAG.h:513
llvm::SDNode
Represents one node in the SelectionDAG.
Definition: SelectionDAGNodes.h:455
llvm::SelectionDAG::ReplaceAllUsesWith
void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
Definition: SelectionDAG.cpp:8839
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:140
llvm::MVT::Glue
@ Glue
Definition: MachineValueType.h:247
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
findPreviousSpillSlot
static Optional< int > findPreviousSpillSlot(const Value *Val, SelectionDAGBuilder &Builder, int LookUpDepth)
Utility function for reservePreviousStackSlotForValue.
Definition: StatepointLowering.cpp:163
llvm::SelectionDAGBuilder::LowerCallSiteWithDeoptBundle
void LowerCallSiteWithDeoptBundle(const CallBase *Call, SDValue Callee, const BasicBlock *EHPadBB)
Definition: StatepointLowering.cpp:1153
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition: MachineMemOperand.h:127
llvm::TargetOptions::TrapUnreachable
unsigned TrapUnreachable
Emit target-specific trap instruction for 'unreachable' IR instructions.
Definition: TargetOptions.h:264
llvm::FunctionLoweringInfo::ValueMap
DenseMap< const Value *, Register > ValueMap
ValueMap - Since we emit code for the function a basic block at a time, we must remember which virtua...
Definition: FunctionLoweringInfo.h:78
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
llvm::GCFunctionInfo::getStrategy
GCStrategy & getStrategy()
getStrategy - Return the GC strategy for the function.
Definition: GCMetadata.h:108
llvm::Optional< int >
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
STLExtras.h
llvm::SmallBitVector::test
bool test(unsigned Idx) const
Definition: SmallBitVector.h:463
llvm::StatepointLoweringState::allocateStackSlot
SDValue allocateStackSlot(EVT ValueType, SelectionDAGBuilder &Builder)
Get a stack slot we can use to store an value of type ValueType.
Definition: StatepointLowering.cpp:110
SelectionDAG.h
llvm::ISD::GC_TRANSITION_END
@ GC_TRANSITION_END
Definition: ISDOpcodes.h:1168
llvm::ISD::CALLSEQ_END
@ CALLSEQ_END
Definition: ISDOpcodes.h:1012
llvm::FunctionLoweringInfo::StatepointRelocationRecord::VReg
@ VReg
Definition: FunctionLoweringInfo.h:104
llvm::SelectionDAG::getContext
LLVMContext * getContext() const
Definition: SelectionDAG.h:447
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:122
llvm::RegsForValue::getCopyToRegs
void getCopyToRegs(SDValue Val, SelectionDAG &DAG, const SDLoc &dl, SDValue &Chain, SDValue *Flag, const Value *V=nullptr, ISD::NodeType PreferredExtendType=ISD::ANY_EXTEND) const
Emit a series of CopyToReg nodes that copies the specified value into the registers specified by this...
Definition: SelectionDAGBuilder.cpp:884
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
MachineValueType.h
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:286
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm::SDNode::op_end
op_iterator op_end() const
Definition: SelectionDAGNodes.h:904
llvm::GCStatepointInst
Represents a gc.statepoint intrinsic call.
Definition: Statepoint.h:63
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:205
llvm::ISD::GC_TRANSITION_START
@ GC_TRANSITION_START
GC_TRANSITION_START/GC_TRANSITION_END - These operators mark the beginning and end of GC transition s...
Definition: ISDOpcodes.h:1167
Instruction.h
CommandLine.h
TargetLowering.h
llvm::SelectionDAG::getLoad
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
Definition: SelectionDAG.cpp:7246
llvm::SDNode::getOpcode
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Definition: SelectionDAGNodes.h:621
llvm::SelectionDAGBuilder::DAG
SelectionDAG & DAG
Definition: SelectionDAGBuilder.h:389
AlwaysSpillBase
cl::opt< bool > AlwaysSpillBase("statepoint-always-spill-base", cl::Hidden, cl::init(true), cl::desc("Force spilling of base GC pointers"))
llvm::SelectionDAG::getTargetFrameIndex
SDValue getTargetFrameIndex(int FI, EVT VT)
Definition: SelectionDAG.h:688
llvm::SDValue::getValueType
EVT getValueType() const
Return the ValueType of the referenced return value.
Definition: SelectionDAGNodes.h:1113
TargetMachine.h
llvm::SelectionDAGBuilder::lowerRangeToAssertZExt
SDValue lowerRangeToAssertZExt(SelectionDAG &DAG, const Instruction &I, SDValue Op)
Definition: SelectionDAGBuilder.cpp:8866
FunctionLoweringInfo.h
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:648
llvm::SelectionDAG::getUNDEF
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
Definition: SelectionDAG.h:947
llvm::SelectionDAG::getTargetLoweringInfo
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:443
llvm::EVT
Extended Value Type.
Definition: ValueTypes.h:35
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::SelectionDAG::getSrcValue
SDValue getSrcValue(const Value *v)
Construct a node to track a Value* through the backend.
Definition: SelectionDAG.cpp:2025
llvm::StatepointDirectives::DeoptBundleStatepointID
static const uint64_t DeoptBundleStatepointID
Definition: Statepoint.h:260
SI
@ SI
Definition: SIInstrInfo.cpp:7342
UseRegistersForGCPointersInLandingPad
cl::opt< bool > UseRegistersForGCPointersInLandingPad("use-registers-for-gc-values-in-landing-pad", cl::Hidden, cl::init(false), cl::desc("Allow using registers for gc pointer in landing pad"))
reservePreviousStackSlotForValue
static void reservePreviousStackSlotForValue(const Value *IncomingValue, SelectionDAGBuilder &Builder)
Try to find existing copies of the incoming values in stack slots used for statepoint spilling.
Definition: StatepointLowering.cpp:266
TargetOpcodes.h
llvm::SelectionDAG::setRoot
const SDValue & setRoot(SDValue N)
Set the current root tag of the SelectionDAG.
Definition: SelectionDAG.h:522
getMachineMemOperand
static MachineMemOperand * getMachineMemOperand(MachineFunction &MF, FrameIndexSDNode &FI)
Definition: StatepointLowering.cpp:353
llvm::Instruction
Definition: Instruction.h:45
MaxRegistersForGCPointers
cl::opt< unsigned > MaxRegistersForGCPointers("max-registers-for-gc-values", cl::Hidden, cl::init(0), cl::desc("Max number of VRegs allowed to pass GC pointer meta args in"))
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::LLVMContext::OB_deopt
@ OB_deopt
Definition: LLVMContext.h:90
llvm::FrameIndexSDNode
Definition: SelectionDAGNodes.h:1718
llvm::SelectionDAGBuilder::LowerDeoptimizeCall
void LowerDeoptimizeCall(const CallInst *CI)
Definition: StatepointLowering.cpp:1266
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:154
llvm::SDValue::getValueSizeInBits
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
Definition: SelectionDAGNodes.h:192
llvm::ISD::CopyFromReg
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
Definition: ISDOpcodes.h:201
llvm::None
const NoneType None
Definition: None.h:23
Statepoint.h
Type.h
llvm::RegsForValue
This struct represents the registers (physical or virtual) that a particular set of values is assigne...
Definition: SelectionDAGBuilder.h:830
llvm::StatepointLoweringState::relocCallVisited
void relocCallVisited(const GCRelocateInst &RelocCall)
Remove this gc_relocate from the list we're expecting to see before the next statepoint.
Definition: StatepointLowering.h:75
llvm::cl::opt< bool >
llvm::StatepointLoweringState::clear
void clear()
Clear the memory usage of this object.
Definition: StatepointLowering.cpp:102
llvm::SmallBitVector::clear
void clear()
Clear all bits.
Definition: SmallBitVector.h:322
llvm::SmallSet::count
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:164
llvm::GCRelocateInst
Represents calls to the gc.relocate intrinsic.
Definition: IntrinsicInst.h:1229
llvm::EVT::getSizeInBits
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:333
llvm::StatepointFlags::None
@ None
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition: MachineFrameInfo.h:451
RuntimeLibcalls.h
llvm::ConstantFPSDNode
Definition: SelectionDAGNodes.h:1579
llvm::find
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1525
llvm::ISD::LOAD
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:906
llvm::SelectionDAG::getIntPtrConstant
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
Definition: SelectionDAG.cpp:1470
willLowerDirectly
static bool willLowerDirectly(SDValue Incoming)
Return true if-and-only-if the given SDValue can be lowered as either a constant argument or a stack ...
Definition: StatepointLowering.cpp:244
llvm::GCRelocateInst::getDerivedPtr
Value * getDerivedPtr() const
Definition: IntrinsicInst.cpp:442
llvm::ISD::TRAP
@ TRAP
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:1073
llvm::DenseMap
Definition: DenseMap.h:714
llvm::SelectionDAGBuilder::getCopyFromRegs
SDValue getCopyFromRegs(const Value *V, Type *Ty)
If there was virtual register allocated for the value V emit CopyFromReg of the specified type Ty.
Definition: SelectionDAGBuilder.cpp:1432
llvm::SDNode::getOperand
const SDValue & getOperand(unsigned Num) const
Definition: SelectionDAGNodes.h:896
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::FrameIndexSDNode::getIndex
int getIndex() const
Definition: SelectionDAGNodes.h:1729
llvm::SelectionDAG::getNode
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
Definition: SelectionDAG.cpp:7732
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition: MachineFrameInfo.h:471
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:440
spillIncomingStatepointValue
static std::tuple< SDValue, SDValue, MachineMemOperand * > spillIncomingStatepointValue(SDValue Incoming, SDValue Chain, SelectionDAGBuilder &Builder)
Spill a value incoming to the statepoint.
Definition: StatepointLowering.cpp:371
ArrayRef.h
llvm::SelectionDAGBuilder::LowerAsSTATEPOINT
SDValue LowerAsSTATEPOINT(StatepointLoweringInfo &SI)
Lower SLI into a STATEPOINT instruction.
Definition: StatepointLowering.cpp:729
llvm::SelectionDAGBuilder::StatepointLowering
StatepointLoweringState StatepointLowering
State used while lowering a statepoint sequence (gc_statepoint, gc_relocate, and gc_result).
Definition: SelectionDAGBuilder.h:134
llvm::SDValue::getValue
SDValue getValue(unsigned R) const
Definition: SelectionDAGNodes.h:172
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:115
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MVT::Other
@ Other
Definition: MachineValueType.h:39
llvm::SelectionDAGBuilder::getFrameIndexTy
MVT getFrameIndexTy()
Returns the type of FrameIndex and TargetFrameIndex nodes.
Definition: SelectionDAGBuilder.h:640
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:571
llvm::FunctionLoweringInfo::CreateRegs
Register CreateRegs(const Value *V)
Definition: FunctionLoweringInfo.cpp:406
llvm::SelectionDAG::getMachineNode
MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
Definition: SelectionDAG.cpp:8405
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
llvm::Record
Definition: Record.h:1472
llvm::SelectionDAG::setNodeMemRefs
void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
Definition: SelectionDAG.cpp:8173
llvm::SmallBitVector::resize
void resize(unsigned N, bool t=false)
Grow or shrink the bitvector.
Definition: SmallBitVector.h:329
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:649
llvm::SelectionDAGBuilder::StatepointLoweringInfo
Describes a gc.statepoint or a gc.statepoint like thing for the purposes of lowering into a STATEPOIN...
Definition: SelectionDAGBuilder.h:578
llvm::MachineFunction
Definition: MachineFunction.h:227
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
llvm::StatepointLoweringState::getLocation
SDValue getLocation(SDValue Val)
Returns the spill location of a value incoming to the current statepoint.
Definition: StatepointLowering.h:50
TargetOptions.h
StatepointLowering.h
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:33
llvm::EVT::isVector
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:149
None.h
llvm::MVT::i64
@ i64
Definition: MachineValueType.h:44
llvm::SelectionDAGBuilder
SelectionDAGBuilder - This is the common target-independent lowering implementation that is parameter...
Definition: SelectionDAGBuilder.h:93
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
llvm::GCResultInst
Represents calls to the gc.result intrinsic.
Definition: IntrinsicInst.h:1257
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1690
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::SelectionDAGBuilder::getCurSDLoc
SDLoc getCurSDLoc() const
Definition: SelectionDAGBuilder.h:477
llvm::SmallSet::insert
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:180
llvm::FunctionLoweringInfo::StatepointRelocationMaps
DenseMap< const Instruction *, StatepointSpillMapTy > StatepointRelocationMaps
Definition: FunctionLoweringInfo.h:120
llvm::StatepointFlags::GCTransition
@ GCTransition
Indicates that this statepoint is a transition from GC-aware code to code that is not GC-aware.
llvm::SDVTList
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
Definition: SelectionDAGNodes.h:79
llvm::MachineMemOperand::MOVolatile
@ MOVolatile
The memory access is volatile.
Definition: MachineMemOperand.h:138
lowerIncomingStatepointValue
static void lowerIncomingStatepointValue(SDValue Incoming, bool RequireSpillSlot, SmallVectorImpl< SDValue > &Ops, SmallVectorImpl< MachineMemOperand * > &MemRefs, SelectionDAGBuilder &Builder)
Lower a single value incoming to a statepoint node.
Definition: StatepointLowering.cpp:419
llvm::MachineMemOperand::MOLoad
@ MOLoad
The memory access reads data.
Definition: MachineMemOperand.h:134
llvm::PointerUnion< const Value *, const PseudoSourceValue * >
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:205
llvm::GCStrategy::isGCManagedPointer
virtual Optional< bool > isGCManagedPointer(const Type *Ty) const
If the type specified can be reliably distinguished, returns true for pointers to GC managed location...
Definition: GCStrategy.h:99
CallingConv.h
isGCValue
static bool isGCValue(const Value *V, SelectionDAGBuilder &Builder)
Return true if value V represents the GC value.
Definition: StatepointLowering.cpp:497
llvm::SDNode::getNumOperands
unsigned getNumOperands() const
Return the number of values used by this operation.
Definition: SelectionDAGNodes.h:883
llvm::FunctionLoweringInfo::StatepointRelocationRecord::Spill
@ Spill
Definition: FunctionLoweringInfo.h:101
MachineFrameInfo.h
llvm::SelectionDAG::getEntryNode
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:516
llvm::SelectionDAG::getDataLayout
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:440
ISDOpcodes.h
lowerCallFromStatepointLoweringInfo
static std::pair< SDValue, SDNode * > lowerCallFromStatepointLoweringInfo(SelectionDAGBuilder::StatepointLoweringInfo &SI, SelectionDAGBuilder &Builder, SmallVectorImpl< SDValue > &PendingExports)
Extract call from statepoint, lower it and return pointer to the call node.
Definition: StatepointLowering.cpp:316
Casting.h
llvm::SelectionDAGBuilder::FuncInfo
FunctionLoweringInfo & FuncInfo
Information about the function as a whole.
Definition: SelectionDAGBuilder.h:422
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::size
unsigned size() const
Definition: DenseMap.h:100
llvm::MVT::i32
@ i32
Definition: MachineValueType.h:43
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition: SelectionDAGNodes.h:138
StackMaps.h
llvm::SDNode::getNumValues
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
Definition: SelectionDAGNodes.h:955
llvm::SelectionDAGBuilder::LowerCallSiteWithDeoptBundleImpl
void LowerCallSiteWithDeoptBundleImpl(const CallBase *Call, SDValue Callee, const BasicBlock *EHPadBB, bool VarArgDisallowed, bool ForceVoidReturnTy)
Definition: StatepointLowering.cpp:1120
llvm::MachineMemOperand::MOStore
@ MOStore
The memory access writes data.
Definition: MachineMemOperand.h:136
llvm::SDValue::isUndef
bool isUndef() const
Definition: SelectionDAGNodes.h:1149
SelectionDAGBuilder.h
llvm::FunctionLoweringInfo::StatepointRelocationRecord::NoRelocate
@ NoRelocate
Definition: FunctionLoweringInfo.h:99
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:187
llvm::SDNode::op_begin
op_iterator op_begin() const
Definition: SelectionDAGNodes.h:903
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:107
llvm::StatepointLoweringState::scheduleRelocCall
void scheduleRelocCall(const GCRelocateInst &RelocCall)
Record the fact that we expect to encounter a given gc_relocate before the next statepoint.
Definition: StatepointLowering.h:66
Instructions.h
llvm::GCStrategy::useStatepoints
bool useStatepoints() const
Returns true if this strategy is expecting the use of gc.statepoints, and false otherwise.
Definition: GCStrategy.h:90
llvm::parseStatepointDirectivesFromAttrs
StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS)
Parse out statepoint directives from the function attributes present in AS.
Definition: Statepoint.cpp:26
llvm::MachinePointerInfo::getFixedStack
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Definition: MachineOperand.cpp:995
UseRegistersForDeoptValues
cl::opt< bool > UseRegistersForDeoptValues("use-registers-for-deopt-values", cl::Hidden, cl::init(false), cl::desc("Allow using registers for non pointer deopt args"))
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:94
llvm::CallingConv::AnyReg
@ AnyReg
Definition: CallingConv.h:62
llvm::SelectionDAGBuilder::LowerDeoptimizingReturn
void LowerDeoptimizingReturn()
Definition: StatepointLowering.cpp:1279
llvm::MachineFrameInfo::markAsStatepointSpillSlotObjectIndex
void markAsStatepointSpillSlotObjectIndex(int ObjectIdx)
Definition: MachineFrameInfo.h:748
llvm::PHINode
Definition: Instructions.h:2572
MachineMemOperand.h
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1164
llvm::SelectionDAG::getTargetConstant
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
Definition: SelectionDAG.h:637
DerivedTypes.h
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:307
llvm::StatepointFlags::DeoptLiveIn
@ DeoptLiveIn
Mark the deopt arguments associated with the statepoint as only being "live-in".
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1450
llvm::SelectionDAG::DeleteNode
void DeleteNode(SDNode *N)
Remove the specified node from the system.
Definition: SelectionDAG.cpp:865
llvm::SelectionDAG::getMachineFunction
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:437
llvm::SelectionDAG::getExternalSymbol
SDValue getExternalSymbol(const char *Sym, EVT VT)
Definition: SelectionDAG.cpp:1710
LLVMContext.h
llvm::SmallBitVector::size
size_t size() const
Returns the number of bits in this bitvector.
Definition: SmallBitVector.h:192
llvm::cl::desc
Definition: CommandLine.h:411
llvm::StatepointFlags::MaskAll
@ MaskAll
A bitmask that includes all valid flags.
llvm::TargetLoweringBase::getValueType
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
Definition: TargetLowering.h:1382
MachineFunction.h
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::SelectionDAG::getTarget
const TargetMachine & getTarget() const
Definition: SelectionDAG.h:441
llvm::SelectionDAGBuilder::getRoot
SDValue getRoot()
Similar to getMemoryRoot, but also flushes PendingConstrainedFP(Strict) items.
Definition: SelectionDAGBuilder.cpp:1069
llvm::SelectionDAGBuilder::ExportFromCurrentBlock
void ExportFromCurrentBlock(const Value *V)
ExportFromCurrentBlock - If this condition isn't known to be exported from the current basic block,...
Definition: SelectionDAGBuilder.cpp:2039
llvm::SelectionDAGBuilder::populateCallLoweringInfo
void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI, const CallBase *Call, unsigned ArgIdx, unsigned NumArgs, SDValue Callee, Type *ReturnTy, bool IsPatchPoint)
Populate a CallLowerinInfo (into CLI) based on the properties of the call being lowered.
Definition: SelectionDAGBuilder.cpp:8910
llvm::GCProjectionInst::getStatepoint
const GCStatepointInst * getStatepoint() const
The statepoint with which this gc.relocate is associated.
Definition: IntrinsicInst.cpp:417
llvm::SDNode::getGluedNode
SDNode * getGluedNode() const
If this node has a glue operand, return the node to which the glue operand points.
Definition: SelectionDAGNodes.h:931
llvm::SelectionDAGBuilder::getControlRoot
SDValue getControlRoot()
Similar to getRoot, but instead of flushing all the PendingLoad items, flush all the PendingExports (...
Definition: SelectionDAGBuilder.cpp:1085
SmallSet.h
lowerStatepointMetaArgs
static void lowerStatepointMetaArgs(SmallVectorImpl< SDValue > &Ops, SmallVectorImpl< MachineMemOperand * > &MemRefs, SmallVectorImpl< SDValue > &GCPtrs, DenseMap< SDValue, int > &LowerAsVReg, SelectionDAGBuilder::StatepointLoweringInfo &SI, SelectionDAGBuilder &Builder)
Lower deopt state and gc pointer arguments of the statepoint.
Definition: StatepointLowering.cpp:515
GCStrategy.h
RecordType
FunctionLoweringInfo::StatepointRelocationRecord RecordType
Definition: StatepointLowering.cpp:79
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:773
llvm::SelectionDAGBuilder::GFI
GCFunctionInfo * GFI
Garbage collection metadata for the function.
Definition: SelectionDAGBuilder.h:428