LLVM  10.0.0
FunctionLoweringInfo.cpp
Go to the documentation of this file.
1 //===-- FunctionLoweringInfo.cpp ------------------------------------------===//
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 implements routines for translating functions from LLVM IR into
10 // Machine IR.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "llvm/CodeGen/Analysis.h"
28 #include "llvm/IR/DataLayout.h"
29 #include "llvm/IR/DerivedTypes.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/Instructions.h"
32 #include "llvm/IR/IntrinsicInst.h"
33 #include "llvm/IR/LLVMContext.h"
34 #include "llvm/IR/Module.h"
35 #include "llvm/Support/Debug.h"
40 #include <algorithm>
41 using namespace llvm;
42 
43 #define DEBUG_TYPE "function-lowering-info"
44 
45 /// isUsedOutsideOfDefiningBlock - Return true if this instruction is used by
46 /// PHI nodes or outside of the basic block that defines it, or used by a
47 /// switch or atomic instruction, which may expand to multiple basic blocks.
49  if (I->use_empty()) return false;
50  if (isa<PHINode>(I)) return true;
51  const BasicBlock *BB = I->getParent();
52  for (const User *U : I->users())
53  if (cast<Instruction>(U)->getParent() != BB || isa<PHINode>(U))
54  return true;
55 
56  return false;
57 }
58 
60  // For the users of the source value being used for compare instruction, if
61  // the number of signed predicate is greater than unsigned predicate, we
62  // prefer to use SIGN_EXTEND.
63  //
64  // With this optimization, we would be able to reduce some redundant sign or
65  // zero extension instruction, and eventually more machine CSE opportunities
66  // can be exposed.
67  ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
68  unsigned NumOfSigned = 0, NumOfUnsigned = 0;
69  for (const User *U : V->users()) {
70  if (const auto *CI = dyn_cast<CmpInst>(U)) {
71  NumOfSigned += CI->isSigned();
72  NumOfUnsigned += CI->isUnsigned();
73  }
74  }
75  if (NumOfSigned > NumOfUnsigned)
76  ExtendKind = ISD::SIGN_EXTEND;
77 
78  return ExtendKind;
79 }
80 
82  SelectionDAG *DAG) {
83  Fn = &fn;
84  MF = &mf;
86  RegInfo = &MF->getRegInfo();
88  unsigned StackAlign = TFI->getStackAlignment();
89  DA = DAG->getDivergenceAnalysis();
90 
91  // Check whether the function can return without sret-demotion.
94 
95  GetReturnInfo(CC, Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI,
96  mf.getDataLayout());
98  TLI->CanLowerReturn(CC, *MF, Fn->isVarArg(), Outs, Fn->getContext());
99 
100  // If this personality uses funclets, we need to do a bit more work.
102  EHPersonality Personality = classifyEHPersonality(
103  Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr);
104  if (isFuncletEHPersonality(Personality)) {
105  // Calculate state numbers if we haven't already.
106  WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
107  if (Personality == EHPersonality::MSVC_CXX)
108  calculateWinCXXEHStateNumbers(&fn, EHInfo);
109  else if (isAsynchronousEHPersonality(Personality))
110  calculateSEHStateNumbers(&fn, EHInfo);
111  else if (Personality == EHPersonality::CoreCLR)
112  calculateClrEHStateNumbers(&fn, EHInfo);
113 
114  // Map all BB references in the WinEH data to MBBs.
115  for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
116  for (WinEHHandlerType &H : TBME.HandlerArray) {
117  if (const AllocaInst *AI = H.CatchObj.Alloca)
118  CatchObjects.insert({AI, {}}).first->second.push_back(
119  &H.CatchObj.FrameIndex);
120  else
121  H.CatchObj.FrameIndex = INT_MAX;
122  }
123  }
124  }
125  if (Personality == EHPersonality::Wasm_CXX) {
126  WasmEHFuncInfo &EHInfo = *MF->getWasmEHFuncInfo();
127  calculateWasmEHInfo(&fn, EHInfo);
128  }
129 
130  // Initialize the mapping of values to registers. This is only set up for
131  // instruction values that are used outside of the block that defines
132  // them.
133  for (const BasicBlock &BB : *Fn) {
134  for (const Instruction &I : BB) {
135  if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
136  Type *Ty = AI->getAllocatedType();
137  unsigned Align =
139  AI->getAlignment());
140 
141  // Static allocas can be folded into the initial stack frame
142  // adjustment. For targets that don't realign the stack, don't
143  // do this if there is an extra alignment requirement.
144  if (AI->isStaticAlloca() &&
145  (TFI->isStackRealignable() || (Align <= StackAlign))) {
146  const ConstantInt *CUI = cast<ConstantInt>(AI->getArraySize());
147  uint64_t TySize =
149 
150  TySize *= CUI->getZExtValue(); // Get total allocated size.
151  if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects.
152  int FrameIndex = INT_MAX;
153  auto Iter = CatchObjects.find(AI);
154  if (Iter != CatchObjects.end() && TLI->needsFixedCatchObjects()) {
155  FrameIndex = MF->getFrameInfo().CreateFixedObject(
156  TySize, 0, /*IsImmutable=*/false, /*isAliased=*/true);
157  MF->getFrameInfo().setObjectAlignment(FrameIndex, Align);
158  } else {
159  FrameIndex =
160  MF->getFrameInfo().CreateStackObject(TySize, Align, false, AI);
161  }
162 
163  // Scalable vectors may need a special StackID to distinguish
164  // them from other (fixed size) stack objects.
165  if (Ty->isVectorTy() && Ty->getVectorIsScalable())
166  MF->getFrameInfo().setStackID(FrameIndex,
168 
170  // Update the catch handler information.
171  if (Iter != CatchObjects.end()) {
172  for (int *CatchObjPtr : Iter->second)
173  *CatchObjPtr = FrameIndex;
174  }
175  } else {
176  // FIXME: Overaligned static allocas should be grouped into
177  // a single dynamic allocation instead of using a separate
178  // stack allocation for each one.
179  if (Align <= StackAlign)
180  Align = 0;
181  // Inform the Frame Information that we have variable-sized objects.
182  MF->getFrameInfo().CreateVariableSizedObject(Align ? Align : 1, AI);
183  }
184  }
185 
186  // Look for inline asm that clobbers the SP register.
187  if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
188  ImmutableCallSite CS(&I);
189  if (isa<InlineAsm>(CS.getCalledValue())) {
190  unsigned SP = TLI->getStackPointerRegisterToSaveRestore();
192  std::vector<TargetLowering::AsmOperandInfo> Ops =
193  TLI->ParseConstraints(Fn->getParent()->getDataLayout(), TRI, CS);
194  for (TargetLowering::AsmOperandInfo &Op : Ops) {
195  if (Op.Type == InlineAsm::isClobber) {
196  // Clobbers don't have SDValue operands, hence SDValue().
197  TLI->ComputeConstraintToUse(Op, SDValue(), DAG);
198  std::pair<unsigned, const TargetRegisterClass *> PhysReg =
199  TLI->getRegForInlineAsmConstraint(TRI, Op.ConstraintCode,
200  Op.ConstraintVT);
201  if (PhysReg.first == SP)
203  }
204  }
205  }
206  }
207 
208  // Look for calls to the @llvm.va_start intrinsic. We can omit some
209  // prologue boilerplate for variadic functions that don't examine their
210  // arguments.
211  if (const auto *II = dyn_cast<IntrinsicInst>(&I)) {
212  if (II->getIntrinsicID() == Intrinsic::vastart)
213  MF->getFrameInfo().setHasVAStart(true);
214  }
215 
216  // If we have a musttail call in a variadic function, we need to ensure we
217  // forward implicit register parameters.
218  if (const auto *CI = dyn_cast<CallInst>(&I)) {
219  if (CI->isMustTailCall() && Fn->isVarArg())
221  }
222 
223  // Mark values used outside their block as exported, by allocating
224  // a virtual register for them.
226  if (!isa<AllocaInst>(I) || !StaticAllocaMap.count(cast<AllocaInst>(&I)))
228 
229  // Decide the preferred extend type for a value.
231  }
232  }
233 
234  // Create an initial MachineBasicBlock for each LLVM BasicBlock in F. This
235  // also creates the initial PHI MachineInstrs, though none of the input
236  // operands are populated.
237  for (const BasicBlock &BB : *Fn) {
238  // Don't create MachineBasicBlocks for imaginary EH pad blocks. These blocks
239  // are really data, and no instructions can live here.
240  if (BB.isEHPad()) {
241  const Instruction *PadInst = BB.getFirstNonPHI();
242  // If this is a non-landingpad EH pad, mark this function as using
243  // funclets.
244  // FIXME: SEH catchpads do not create EH scope/funclets, so we could avoid
245  // setting this in such cases in order to improve frame layout.
246  if (!isa<LandingPadInst>(PadInst)) {
247  MF->setHasEHScopes(true);
248  MF->setHasEHFunclets(true);
250  }
251  if (isa<CatchSwitchInst>(PadInst)) {
252  assert(&*BB.begin() == PadInst &&
253  "WinEHPrepare failed to remove PHIs from imaginary BBs");
254  continue;
255  }
256  if (isa<FuncletPadInst>(PadInst))
257  assert(&*BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs");
258  }
259 
261  MBBMap[&BB] = MBB;
262  MF->push_back(MBB);
263 
264  // Transfer the address-taken flag. This is necessary because there could
265  // be multiple MachineBasicBlocks corresponding to one BasicBlock, and only
266  // the first one should be marked.
267  if (BB.hasAddressTaken())
268  MBB->setHasAddressTaken();
269 
270  // Mark landing pad blocks.
271  if (BB.isEHPad())
272  MBB->setIsEHPad();
273 
274  // Create Machine PHI nodes for LLVM PHI nodes, lowering them as
275  // appropriate.
276  for (const PHINode &PN : BB.phis()) {
277  if (PN.use_empty())
278  continue;
279 
280  // Skip empty types
281  if (PN.getType()->isEmptyTy())
282  continue;
283 
284  DebugLoc DL = PN.getDebugLoc();
285  unsigned PHIReg = ValueMap[&PN];
286  assert(PHIReg && "PHI node does not have an assigned virtual register!");
287 
288  SmallVector<EVT, 4> ValueVTs;
289  ComputeValueVTs(*TLI, MF->getDataLayout(), PN.getType(), ValueVTs);
290  for (EVT VT : ValueVTs) {
291  unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
293  for (unsigned i = 0; i != NumRegisters; ++i)
294  BuildMI(MBB, DL, TII->get(TargetOpcode::PHI), PHIReg + i);
295  PHIReg += NumRegisters;
296  }
297  }
298  }
299 
300  if (isFuncletEHPersonality(Personality)) {
301  WinEHFuncInfo &EHInfo = *MF->getWinEHFuncInfo();
302 
303  // Map all BB references in the WinEH data to MBBs.
304  for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
305  for (WinEHHandlerType &H : TBME.HandlerArray) {
306  if (H.Handler)
307  H.Handler = MBBMap[H.Handler.get<const BasicBlock *>()];
308  }
309  }
310  for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap)
311  if (UME.Cleanup)
312  UME.Cleanup = MBBMap[UME.Cleanup.get<const BasicBlock *>()];
313  for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) {
314  const auto *BB = UME.Handler.get<const BasicBlock *>();
315  UME.Handler = MBBMap[BB];
316  }
317  for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap) {
318  const auto *BB = CME.Handler.get<const BasicBlock *>();
319  CME.Handler = MBBMap[BB];
320  }
321  }
322 
323  else if (Personality == EHPersonality::Wasm_CXX) {
324  WasmEHFuncInfo &EHInfo = *MF->getWasmEHFuncInfo();
325  // Map all BB references in the WinEH data to MBBs.
327  for (auto &KV : EHInfo.EHPadUnwindMap) {
328  const auto *Src = KV.first.get<const BasicBlock *>();
329  const auto *Dst = KV.second.get<const BasicBlock *>();
330  NewMap[MBBMap[Src]] = MBBMap[Dst];
331  }
332  EHInfo.EHPadUnwindMap = std::move(NewMap);
333  }
334 }
335 
336 /// clear - Clear out all the function-specific state. This returns this
337 /// FunctionLoweringInfo to an empty state, ready to be used for a
338 /// different function.
340  MBBMap.clear();
341  ValueMap.clear();
342  VirtReg2Value.clear();
343  StaticAllocaMap.clear();
344  LiveOutRegInfo.clear();
345  VisitedBBs.clear();
346  ArgDbgValues.clear();
348  ByValArgFrameIndexMap.clear();
349  RegFixups.clear();
352  StatepointSpillMaps.clear();
353  PreferredExtendType.clear();
354 }
355 
356 /// CreateReg - Allocate a single virtual register for the given type.
357 unsigned FunctionLoweringInfo::CreateReg(MVT VT, bool isDivergent) {
359  MF->getSubtarget().getTargetLowering()->getRegClassFor(VT, isDivergent));
360 }
361 
362 /// CreateRegs - Allocate the appropriate number of virtual registers of
363 /// the correctly promoted or expanded types. Assign these registers
364 /// consecutive vreg numbers and return the first assigned number.
365 ///
366 /// In the case that the given value has struct or array type, this function
367 /// will assign registers for each member or element.
368 ///
369 unsigned FunctionLoweringInfo::CreateRegs(Type *Ty, bool isDivergent) {
371 
372  SmallVector<EVT, 4> ValueVTs;
373  ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
374 
375  unsigned FirstReg = 0;
376  for (unsigned Value = 0, e = ValueVTs.size(); Value != e; ++Value) {
377  EVT ValueVT = ValueVTs[Value];
378  MVT RegisterVT = TLI->getRegisterType(Ty->getContext(), ValueVT);
379 
380  unsigned NumRegs = TLI->getNumRegisters(Ty->getContext(), ValueVT);
381  for (unsigned i = 0; i != NumRegs; ++i) {
382  unsigned R = CreateReg(RegisterVT, isDivergent);
383  if (!FirstReg) FirstReg = R;
384  }
385  }
386  return FirstReg;
387 }
388 
390  return CreateRegs(V->getType(), DA && !TLI->requiresUniformRegister(*MF, V) &&
391  DA->isDivergent(V));
392 }
393 
394 /// GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the
395 /// register is a PHI destination and the PHI's LiveOutInfo is not valid. If
396 /// the register's LiveOutInfo is for a smaller bit width, it is extended to
397 /// the larger bit width by zero extension. The bit width must be no smaller
398 /// than the LiveOutInfo's existing bit width.
400 FunctionLoweringInfo::GetLiveOutRegInfo(unsigned Reg, unsigned BitWidth) {
401  if (!LiveOutRegInfo.inBounds(Reg))
402  return nullptr;
403 
404  LiveOutInfo *LOI = &LiveOutRegInfo[Reg];
405  if (!LOI->IsValid)
406  return nullptr;
407 
408  if (BitWidth > LOI->Known.getBitWidth()) {
409  LOI->NumSignBits = 1;
410  LOI->Known = LOI->Known.zext(BitWidth, false /* => any extend */);
411  }
412 
413  return LOI;
414 }
415 
416 /// ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI's destination
417 /// register based on the LiveOutInfo of its operands.
419  Type *Ty = PN->getType();
420  if (!Ty->isIntegerTy() || Ty->isVectorTy())
421  return;
422 
423  SmallVector<EVT, 1> ValueVTs;
424  ComputeValueVTs(*TLI, MF->getDataLayout(), Ty, ValueVTs);
425  assert(ValueVTs.size() == 1 &&
426  "PHIs with non-vector integer types should have a single VT.");
427  EVT IntVT = ValueVTs[0];
428 
429  if (TLI->getNumRegisters(PN->getContext(), IntVT) != 1)
430  return;
431  IntVT = TLI->getTypeToTransformTo(PN->getContext(), IntVT);
432  unsigned BitWidth = IntVT.getSizeInBits();
433 
434  unsigned DestReg = ValueMap[PN];
435  if (!Register::isVirtualRegister(DestReg))
436  return;
437  LiveOutRegInfo.grow(DestReg);
438  LiveOutInfo &DestLOI = LiveOutRegInfo[DestReg];
439 
440  Value *V = PN->getIncomingValue(0);
441  if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
442  DestLOI.NumSignBits = 1;
443  DestLOI.Known = KnownBits(BitWidth);
444  return;
445  }
446 
447  if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
448  APInt Val = CI->getValue().zextOrTrunc(BitWidth);
449  DestLOI.NumSignBits = Val.getNumSignBits();
450  DestLOI.Known.Zero = ~Val;
451  DestLOI.Known.One = Val;
452  } else {
453  assert(ValueMap.count(V) && "V should have been placed in ValueMap when its"
454  "CopyToReg node was created.");
455  unsigned SrcReg = ValueMap[V];
456  if (!Register::isVirtualRegister(SrcReg)) {
457  DestLOI.IsValid = false;
458  return;
459  }
460  const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
461  if (!SrcLOI) {
462  DestLOI.IsValid = false;
463  return;
464  }
465  DestLOI = *SrcLOI;
466  }
467 
468  assert(DestLOI.Known.Zero.getBitWidth() == BitWidth &&
469  DestLOI.Known.One.getBitWidth() == BitWidth &&
470  "Masks should have the same bit width as the type.");
471 
472  for (unsigned i = 1, e = PN->getNumIncomingValues(); i != e; ++i) {
473  Value *V = PN->getIncomingValue(i);
474  if (isa<UndefValue>(V) || isa<ConstantExpr>(V)) {
475  DestLOI.NumSignBits = 1;
476  DestLOI.Known = KnownBits(BitWidth);
477  return;
478  }
479 
480  if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
481  APInt Val = CI->getValue().zextOrTrunc(BitWidth);
482  DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, Val.getNumSignBits());
483  DestLOI.Known.Zero &= ~Val;
484  DestLOI.Known.One &= Val;
485  continue;
486  }
487 
488  assert(ValueMap.count(V) && "V should have been placed in ValueMap when "
489  "its CopyToReg node was created.");
490  unsigned SrcReg = ValueMap[V];
491  if (!Register::isVirtualRegister(SrcReg)) {
492  DestLOI.IsValid = false;
493  return;
494  }
495  const LiveOutInfo *SrcLOI = GetLiveOutRegInfo(SrcReg, BitWidth);
496  if (!SrcLOI) {
497  DestLOI.IsValid = false;
498  return;
499  }
500  DestLOI.NumSignBits = std::min(DestLOI.NumSignBits, SrcLOI->NumSignBits);
501  DestLOI.Known.Zero &= SrcLOI->Known.Zero;
502  DestLOI.Known.One &= SrcLOI->Known.One;
503  }
504 }
505 
506 /// setArgumentFrameIndex - Record frame index for the byval
507 /// argument. This overrides previous frame index entry for this argument,
508 /// if any.
510  int FI) {
511  ByValArgFrameIndexMap[A] = FI;
512 }
513 
514 /// getArgumentFrameIndex - Get frame index for the byval argument.
515 /// If the argument does not have any assigned frame index then 0 is
516 /// returned.
518  auto I = ByValArgFrameIndexMap.find(A);
519  if (I != ByValArgFrameIndexMap.end())
520  return I->second;
521  LLVM_DEBUG(dbgs() << "Argument does not have assigned frame index!\n");
522  return INT_MAX;
523 }
524 
526  const Value *CPI, const TargetRegisterClass *RC) {
528  auto I = CatchPadExceptionPointers.insert({CPI, 0});
529  unsigned &VReg = I.first->second;
530  if (I.second)
531  VReg = MRI.createVirtualRegister(RC);
532  assert(VReg && "null vreg in exception pointer table!");
533  return VReg;
534 }
535 
536 const Value *
538  if (VirtReg2Value.empty()) {
539  SmallVector<EVT, 4> ValueVTs;
540  for (auto &P : ValueMap) {
541  ValueVTs.clear();
543  P.first->getType(), ValueVTs);
544  unsigned Reg = P.second;
545  for (EVT VT : ValueVTs) {
546  unsigned NumRegisters = TLI->getNumRegisters(Fn->getContext(), VT);
547  for (unsigned i = 0, e = NumRegisters; i != e; ++i)
548  VirtReg2Value[Reg++] = P.first;
549  }
550  }
551  }
552  return VirtReg2Value.lookup(Vreg);
553 }
void clear()
Definition: ValueMap.h:146
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.h:176
unsigned CreateReg(MVT VT, bool isDivergent=false)
CreateReg - Allocate a single virtual register for the given type.
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:82
SmallVector< WinEHHandlerType, 1 > HandlerArray
Definition: WinEHFuncInfo.h:76
bool isDivergent(const Value *V) const
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
MBBOrBasicBlock Cleanup
Definition: WinEHFuncInfo.h:42
This class represents lattice values for constants.
Definition: AllocatorList.h:23
unsigned getCatchPadExceptionPointerVReg(const Value *CPI, const TargetRegisterClass *RC)
void setIsEHPad(bool V=true)
Indicates the block is a landing pad.
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
SmallVector< SEHUnwindMapEntry, 4 > SEHUnwindMap
Definition: WinEHFuncInfo.h:97
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void setHasEHFunclets(bool V)
unsigned Reg
virtual const TargetLowering * getTargetLowering() const
const AllocaInst * Alloca
Definition: WinEHFuncInfo.h:65
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:744
unsigned const TargetRegisterInfo * TRI
A debug info location.
Definition: DebugLoc.h:33
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
Definition: APInt.cpp:955
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:230
DenseMap< const Value *, unsigned > CatchPadExceptionPointers
Track virtual registers created for exception pointers.
bool CanLowerReturn
CanLowerReturn - true iff the function&#39;s return value can be lowered to registers.
unsigned getBitWidth() const
Get the bit width of this value.
Definition: KnownBits.h:39
T get() const
Returns the value of the specified pointer type.
Definition: PointerUnion.h:194
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:40
void set(const Function &Fn, MachineFunction &MF, SelectionDAG *DAG)
set - Initialize this FunctionLoweringInfo with the given Function and its associated MachineFunction...
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1566
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:130
MBBOrBasicBlock Handler
Holds the __except or __finally basic block.
Definition: WinEHFuncInfo.h:57
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:195
static bool isUsedOutsideOfDefiningBlock(const Instruction *I)
isUsedOutsideOfDefiningBlock - Return true if this instruction is used by PHI nodes or outside of the...
void clear()
clear - Removes all bits from the bitvector. Does not change capacity.
Definition: BitVector.h:366
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
const HexagonInstrInfo * TII
void calculateSEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Definition: CallSite.h:104
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
int getArgumentFrameIndex(const Argument *A)
getArgumentFrameIndex - Get frame index for the byval argument.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
void setHasMustTailInVarArgFunc(bool B)
const LiveOutInfo * GetLiveOutRegInfo(unsigned Reg)
GetLiveOutRegInfo - Gets LiveOutInfo for a register, returning NULL if the register is a PHI destinat...
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
virtual TargetStackID::Value getStackIDForScalableVectors() const
Returns the StackID that scalable vectors should be associated with.
DenseMap< BBOrMBB, BBOrMBB > EHPadUnwindMap
This contains information for each constraint that we are lowering.
DenseSet< unsigned > RegsWithFixups
const LegacyDivergenceAnalysis * DA
static ISD::NodeType getPreferredExtendForValue(const Value *V)
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:223
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:743
virtual const TargetInstrInfo * getInstrInfo() const
void setHasOpaqueSPAdjustment(bool B)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition: Analysis.cpp:119
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
TargetInstrInfo - Interface to description of machine instruction set.
void clear()
clear - Clear out all the function-specific state.
Similar to CxxUnwindMapEntry, but supports SEH filters.
Definition: WinEHFuncInfo.h:46
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void setHasEHScopes(bool V)
#define P(N)
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:168
SmallVector< ClrEHUnwindMapEntry, 4 > ClrEHUnwindMap
Definition: WinEHFuncInfo.h:98
DenseMap< unsigned, const Value * > VirtReg2Value
VirtReg2Value map is needed by the Divergence Analysis driven instruction selection.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
Definition: Constants.h:148
unsigned const MachineRegisterInfo * MRI
Machine Value Type.
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
KnownBits zext(unsigned BitWidth, bool ExtendedBitsAreKnownZero) const
Extends the underlying known Zero and One bits.
Definition: KnownBits.h:135
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
#define H(x, y, z)
Definition: MD5.cpp:57
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:486
const LegacyDivergenceAnalysis * getDivergenceAnalysis() const
Definition: SelectionDAG.h:429
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:765
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
constexpr double e
Definition: MathExtras.h:57
void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo)
void setStackID(int ObjectIdx, uint8_t ID)
DenseMap< const Instruction *, StatepointSpillMap > StatepointSpillMaps
Maps gc.statepoint instructions to their corresponding StatepointSpillMap instances.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:223
SmallPtrSet< const BasicBlock *, 4 > VisitedBBs
VisitedBBs - The set of basic blocks visited thus far by instruction selection.
Extended Value Type.
Definition: ValueTypes.h:34
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:298
size_t size() const
Definition: SmallVector.h:52
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
void ComputePHILiveOutRegInfo(const PHINode *)
ComputePHILiveOutRegInfo - Compute LiveOutInfo for a PHI&#39;s destination register based on the LiveOutI...
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:40
MachineBasicBlock * MBB
MBB - The current block.
MBBOrBasicBlock Handler
Definition: WinEHFuncInfo.h:69
SmallVector< unsigned, 50 > StatepointStackSlots
StatepointStackSlots - A list of temporary stack slots (frame indices) used to spill values at a stat...
unsigned first
void GetReturnInfo(CallingConv::ID CC, Type *ReturnType, AttributeList attr, SmallVectorImpl< ISD::OutputArg > &Outs, const TargetLowering &TLI, const DataLayout &DL)
Given an LLVM IR type and return type attributes, compute the return value EVTs and flags...
void calculateWinCXXEHStateNumbers(const Function *ParentFn, WinEHFuncInfo &FuncInfo)
Analyze the IR in ParentFn and it&#39;s handlers to build WinEHFuncInfo, which describes the state number...
SmallVector< CxxUnwindMapEntry, 4 > CxxUnwindMap
Definition: WinEHFuncInfo.h:95
See the file comment.
Definition: ValueMap.h:85
This is the shared class of boolean and integer constants.
Definition: Constants.h:83
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
bool isFuncletEHPersonality(EHPersonality Pers)
Returns true if this is a personality function that invokes handler funclets (which must return to it...
DenseMap< unsigned, unsigned > RegFixups
RegFixups - Registers which need to be replaced after isel is done.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:212
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:223
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
SmallVector< MachineInstr *, 8 > ArgDbgValues
ArgDbgValues - A list of DBG_VALUE instructions created during isel for function arguments that are i...
Module.h This file contains the declarations for the Module class.
Information about stack frame layout on the target.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
virtual bool requiresUniformRegister(MachineFunction &MF, const Value *) const
Allows target to decide about the register class of the specific value that is live outside the defin...
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
Definition: WinEHFuncInfo.h:96
Class for arbitrary precision integers.
Definition: APInt.h:69
iterator_range< user_iterator > users()
Definition: Value.h:420
union llvm::WinEHHandlerType::@202 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:532
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
const WasmEHFuncInfo * getWasmEHFuncInfo() const
getWasmEHFuncInfo - Return information about how the current function uses Wasm exception handling...
DenseMap< const Value *, ISD::NodeType > PreferredExtendType
Record the preferred extend type (ISD::SIGN_EXTEND or ISD::ZERO_EXTEND) for a value.
unsigned CreateRegs(const Value *V)
MachineRegisterInfo * RegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
DenseMap< const Argument *, int > ByValArgFrameIndexMap
ByValArgFrameIndexMap - Keep track of frame indices for byval arguments.
uint64_t getKnownMinSize() const
Definition: TypeSize.h:132
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:44
Establish a view to a call site for examination.
Definition: CallSite.h:697
#define I(x, y, z)
Definition: MD5.cpp:58
virtual const TargetFrameLowering * getFrameLowering() const
BitVector DescribedArgs
Bitvector with a bit set if corresponding argument is described in ArgDbgValues.
const Value * getValueFromVirtualReg(unsigned Vreg)
This method is called from TargetLowerinInfo::isSDNodeSourceOfDivergence to get the Value correspondi...
DenseMap< const AllocaInst *, int > StaticAllocaMap
StaticAllocaMap - Keep track of frame indices for fixed sized allocas in the entry block...
bool getVectorIsScalable() const
Definition: DerivedTypes.h:570
void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo)
unsigned getNumRegisters(LLVMContext &Context, EVT VT) const
Return the number of registers that this ValueType will eventually require.
bool isStackRealignable() const
isStackRealignable - This method returns whether the stack can be realigned.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: ValueMap.h:152
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit. ...
Definition: APInt.h:1677
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1484
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:69
void push_back(MachineBasicBlock *MBB)
DenseMap< const BasicBlock *, MachineBasicBlock * > MBBMap
MBBMap - A mapping from LLVM basic blocks to their machine code entry.
const TargetLowering * TLI
Conversion operators.
Definition: ISDOpcodes.h:526
#define LLVM_DEBUG(X)
Definition: Debug.h:122
void setArgumentFrameIndex(const Argument *A, int FI)
setArgumentFrameIndex - Record frame index for the byval argument.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
bool use_empty() const
Definition: Value.h:343
This file describes how to lower LLVM code to machine code.
const BasicBlock * getParent() const
Definition: Instruction.h:66
an instruction to allocate memory on the stack
Definition: Instructions.h:59
unsigned InitializeRegForValue(const Value *V)