Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MachineFrameInfo.h
Line
Count
Source
1
//===-- CodeGen/MachineFrameInfo.h - Abstract Stack Frame Rep. --*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// The file defines the MachineFrameInfo class.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CODEGEN_MACHINEFRAMEINFO_H
15
#define LLVM_CODEGEN_MACHINEFRAMEINFO_H
16
17
#include "llvm/ADT/SmallVector.h"
18
#include "llvm/Support/DataTypes.h"
19
#include <cassert>
20
#include <vector>
21
22
namespace llvm {
23
class raw_ostream;
24
class MachineFunction;
25
class MachineBasicBlock;
26
class BitVector;
27
class AllocaInst;
28
29
/// The CalleeSavedInfo class tracks the information need to locate where a
30
/// callee saved register is in the current frame.
31
/// Callee saved reg can also be saved to a different register rather than
32
/// on the stack by setting DstReg instead of FrameIdx.
33
class CalleeSavedInfo {
34
  unsigned Reg;
35
  union {
36
    int FrameIdx;
37
    unsigned DstReg;
38
  };
39
  /// Flag indicating whether the register is actually restored in the epilog.
40
  /// In most cases, if a register is saved, it is also restored. There are
41
  /// some situations, though, when this is not the case. For example, the
42
  /// LR register on ARM is usually saved, but on exit from the function its
43
  /// saved value may be loaded directly into PC. Since liveness tracking of
44
  /// physical registers treats callee-saved registers are live outside of
45
  /// the function, LR would be treated as live-on-exit, even though in these
46
  /// scenarios it is not. This flag is added to indicate that the saved
47
  /// register described by this object is not restored in the epilog.
48
  /// The long-term solution is to model the liveness of callee-saved registers
49
  /// by implicit uses on the return instructions, however, the required
50
  /// changes in the ARM backend would be quite extensive.
51
  bool Restored;
52
  /// Flag indicating whether the register is spilled to stack or another
53
  /// register.
54
  bool SpilledToReg;
55
56
public:
57
  explicit CalleeSavedInfo(unsigned R, int FI = 0)
58
1.34M
  : Reg(R), FrameIdx(FI), Restored(true), SpilledToReg(false) {}
59
60
  // Accessors.
61
11.9M
  unsigned getReg()                        const { return Reg; }
62
1.78M
  int getFrameIdx()                        const { return FrameIdx; }
63
24
  unsigned getDstReg()                     const { return DstReg; }
64
1.34M
  void setFrameIdx(int FI) {
65
1.34M
    FrameIdx = FI;
66
1.34M
    SpilledToReg = false;
67
1.34M
  }
68
6
  void setDstReg(unsigned SpillReg) {
69
6
    DstReg = SpillReg;
70
6
    SpilledToReg = true;
71
6
  }
72
472k
  bool isRestored()                        const { return Restored; }
73
9.03k
  void setRestored(bool R)                       { Restored = R; }
74
2.63M
  bool isSpilledToReg()                    const { return SpilledToReg; }
75
};
76
77
/// The MachineFrameInfo class represents an abstract stack frame until
78
/// prolog/epilog code is inserted.  This class is key to allowing stack frame
79
/// representation optimizations, such as frame pointer elimination.  It also
80
/// allows more mundane (but still important) optimizations, such as reordering
81
/// of abstract objects on the stack frame.
82
///
83
/// To support this, the class assigns unique integer identifiers to stack
84
/// objects requested clients.  These identifiers are negative integers for
85
/// fixed stack objects (such as arguments passed on the stack) or nonnegative
86
/// for objects that may be reordered.  Instructions which refer to stack
87
/// objects use a special MO_FrameIndex operand to represent these frame
88
/// indexes.
89
///
90
/// Because this class keeps track of all references to the stack frame, it
91
/// knows when a variable sized object is allocated on the stack.  This is the
92
/// sole condition which prevents frame pointer elimination, which is an
93
/// important optimization on register-poor architectures.  Because original
94
/// variable sized alloca's in the source program are the only source of
95
/// variable sized stack objects, it is safe to decide whether there will be
96
/// any variable sized objects before all stack objects are known (for
97
/// example, register allocator spill code never needs variable sized
98
/// objects).
99
///
100
/// When prolog/epilog code emission is performed, the final stack frame is
101
/// built and the machine instructions are modified to refer to the actual
102
/// stack offsets of the object, eliminating all MO_FrameIndex operands from
103
/// the program.
104
///
105
/// Abstract Stack Frame Information
106
class MachineFrameInfo {
107
public:
108
  /// Stack Smashing Protection (SSP) rules require that vulnerable stack
109
  /// allocations are located close the stack protector.
110
  enum SSPLayoutKind {
111
    SSPLK_None,       ///< Did not trigger a stack protector.  No effect on data
112
                      ///< layout.
113
    SSPLK_LargeArray, ///< Array or nested array >= SSP-buffer-size.  Closest
114
                      ///< to the stack protector.
115
    SSPLK_SmallArray, ///< Array or nested array < SSP-buffer-size. 2nd closest
116
                      ///< to the stack protector.
117
    SSPLK_AddrOf      ///< The address of this allocation is exposed and
118
                      ///< triggered protection.  3rd closest to the protector.
119
  };
120
121
private:
122
  // Represent a single object allocated on the stack.
123
  struct StackObject {
124
    // The offset of this object from the stack pointer on entry to
125
    // the function.  This field has no meaning for a variable sized element.
126
    int64_t SPOffset;
127
128
    // The size of this object on the stack. 0 means a variable sized object,
129
    // ~0ULL means a dead object.
130
    uint64_t Size;
131
132
    // The required alignment of this stack slot.
133
    unsigned Alignment;
134
135
    // If true, the value of the stack object is set before
136
    // entering the function and is not modified inside the function. By
137
    // default, fixed objects are immutable unless marked otherwise.
138
    bool isImmutable;
139
140
    // If true the stack object is used as spill slot. It
141
    // cannot alias any other memory objects.
142
    bool isSpillSlot;
143
144
    /// If true, this stack slot is used to spill a value (could be deopt
145
    /// and/or GC related) over a statepoint. We know that the address of the
146
    /// slot can't alias any LLVM IR value.  This is very similar to a Spill
147
    /// Slot, but is created by statepoint lowering is SelectionDAG, not the
148
    /// register allocator.
149
    bool isStatepointSpillSlot = false;
150
151
    /// Identifier for stack memory type analagous to address space. If this is
152
    /// non-0, the meaning is target defined. Offsets cannot be directly
153
    /// compared between objects with different stack IDs. The object may not
154
    /// necessarily reside in the same contiguous memory block as other stack
155
    /// objects. Objects with differing stack IDs should not be merged or
156
    /// replaced substituted for each other.
157
    //
158
    /// It is assumed a target uses consecutive, increasing stack IDs starting
159
    /// from 1.
160
    uint8_t StackID;
161
162
    /// If this stack object is originated from an Alloca instruction
163
    /// this value saves the original IR allocation. Can be NULL.
164
    const AllocaInst *Alloca;
165
166
    // If true, the object was mapped into the local frame
167
    // block and doesn't need additional handling for allocation beyond that.
168
    bool PreAllocated = false;
169
170
    // If true, an LLVM IR value might point to this object.
171
    // Normally, spill slots and fixed-offset objects don't alias IR-accessible
172
    // objects, but there are exceptions (on PowerPC, for example, some byval
173
    // arguments have ABI-prescribed offsets).
174
    bool isAliased;
175
176
    /// If true, the object has been zero-extended.
177
    bool isZExt = false;
178
179
    /// If true, the object has been zero-extended.
180
    bool isSExt = false;
181
182
    uint8_t SSPLayout;
183
184
    StackObject(uint64_t Size, unsigned Alignment, int64_t SPOffset,
185
                bool IsImmutable, bool IsSpillSlot, const AllocaInst *Alloca,
186
                bool IsAliased, uint8_t StackID = 0)
187
      : SPOffset(SPOffset), Size(Size), Alignment(Alignment),
188
        isImmutable(IsImmutable), isSpillSlot(IsSpillSlot),
189
        StackID(StackID), Alloca(Alloca), isAliased(IsAliased),
190
1.74M
        SSPLayout(SSPLK_None) {}
191
  };
192
193
  /// The alignment of the stack.
194
  unsigned StackAlignment;
195
196
  /// Can the stack be realigned. This can be false if the target does not
197
  /// support stack realignment, or if the user asks us not to realign the
198
  /// stack. In this situation, overaligned allocas are all treated as dynamic
199
  /// allocations and the target must handle them as part of DYNAMIC_STACKALLOC
200
  /// lowering. All non-alloca stack objects have their alignment clamped to the
201
  /// base ABI stack alignment.
202
  /// FIXME: There is room for improvement in this case, in terms of
203
  /// grouping overaligned allocas into a "secondary stack frame" and
204
  /// then only use a single alloca to allocate this frame and only a
205
  /// single virtual register to access it. Currently, without such an
206
  /// optimization, each such alloca gets its own dynamic realignment.
207
  bool StackRealignable;
208
209
  /// Whether the function has the \c alignstack attribute.
210
  bool ForcedRealign;
211
212
  /// The list of stack objects allocated.
213
  std::vector<StackObject> Objects;
214
215
  /// This contains the number of fixed objects contained on
216
  /// the stack.  Because fixed objects are stored at a negative index in the
217
  /// Objects list, this is also the index to the 0th object in the list.
218
  unsigned NumFixedObjects = 0;
219
220
  /// This boolean keeps track of whether any variable
221
  /// sized objects have been allocated yet.
222
  bool HasVarSizedObjects = false;
223
224
  /// This boolean keeps track of whether there is a call
225
  /// to builtin \@llvm.frameaddress.
226
  bool FrameAddressTaken = false;
227
228
  /// This boolean keeps track of whether there is a call
229
  /// to builtin \@llvm.returnaddress.
230
  bool ReturnAddressTaken = false;
231
232
  /// This boolean keeps track of whether there is a call
233
  /// to builtin \@llvm.experimental.stackmap.
234
  bool HasStackMap = false;
235
236
  /// This boolean keeps track of whether there is a call
237
  /// to builtin \@llvm.experimental.patchpoint.
238
  bool HasPatchPoint = false;
239
240
  /// The prolog/epilog code inserter calculates the final stack
241
  /// offsets for all of the fixed size objects, updating the Objects list
242
  /// above.  It then updates StackSize to contain the number of bytes that need
243
  /// to be allocated on entry to the function.
244
  uint64_t StackSize = 0;
245
246
  /// The amount that a frame offset needs to be adjusted to
247
  /// have the actual offset from the stack/frame pointer.  The exact usage of
248
  /// this is target-dependent, but it is typically used to adjust between
249
  /// SP-relative and FP-relative offsets.  E.G., if objects are accessed via
250
  /// SP then OffsetAdjustment is zero; if FP is used, OffsetAdjustment is set
251
  /// to the distance between the initial SP and the value in FP.  For many
252
  /// targets, this value is only used when generating debug info (via
253
  /// TargetRegisterInfo::getFrameIndexReference); when generating code, the
254
  /// corresponding adjustments are performed directly.
255
  int OffsetAdjustment = 0;
256
257
  /// The prolog/epilog code inserter may process objects that require greater
258
  /// alignment than the default alignment the target provides.
259
  /// To handle this, MaxAlignment is set to the maximum alignment
260
  /// needed by the objects on the current frame.  If this is greater than the
261
  /// native alignment maintained by the compiler, dynamic alignment code will
262
  /// be needed.
263
  ///
264
  unsigned MaxAlignment = 0;
265
266
  /// Set to true if this function adjusts the stack -- e.g.,
267
  /// when calling another function. This is only valid during and after
268
  /// prolog/epilog code insertion.
269
  bool AdjustsStack = false;
270
271
  /// Set to true if this function has any function calls.
272
  bool HasCalls = false;
273
274
  /// The frame index for the stack protector.
275
  int StackProtectorIdx = -1;
276
277
  /// The frame index for the function context. Used for SjLj exceptions.
278
  int FunctionContextIdx = -1;
279
280
  /// This contains the size of the largest call frame if the target uses frame
281
  /// setup/destroy pseudo instructions (as defined in the TargetFrameInfo
282
  /// class).  This information is important for frame pointer elimination.
283
  /// It is only valid during and after prolog/epilog code insertion.
284
  unsigned MaxCallFrameSize = ~0u;
285
286
  /// The number of bytes of callee saved registers that the target wants to
287
  /// report for the current function in the CodeView S_FRAMEPROC record.
288
  unsigned CVBytesOfCalleeSavedRegisters = 0;
289
290
  /// The prolog/epilog code inserter fills in this vector with each
291
  /// callee saved register saved in either the frame or a different
292
  /// register.  Beyond its use by the prolog/ epilog code inserter,
293
  /// this data is used for debug info and exception handling.
294
  std::vector<CalleeSavedInfo> CSInfo;
295
296
  /// Has CSInfo been set yet?
297
  bool CSIValid = false;
298
299
  /// References to frame indices which are mapped
300
  /// into the local frame allocation block. <FrameIdx, LocalOffset>
301
  SmallVector<std::pair<int, int64_t>, 32> LocalFrameObjects;
302
303
  /// Size of the pre-allocated local frame block.
304
  int64_t LocalFrameSize = 0;
305
306
  /// Required alignment of the local object blob, which is the strictest
307
  /// alignment of any object in it.
308
  unsigned LocalFrameMaxAlign = 0;
309
310
  /// Whether the local object blob needs to be allocated together. If not,
311
  /// PEI should ignore the isPreAllocated flags on the stack objects and
312
  /// just allocate them normally.
313
  bool UseLocalStackAllocationBlock = false;
314
315
  /// True if the function dynamically adjusts the stack pointer through some
316
  /// opaque mechanism like inline assembly or Win32 EH.
317
  bool HasOpaqueSPAdjustment = false;
318
319
  /// True if the function contains operations which will lower down to
320
  /// instructions which manipulate the stack pointer.
321
  bool HasCopyImplyingStackAdjustment = false;
322
323
  /// True if the function contains a call to the llvm.vastart intrinsic.
324
  bool HasVAStart = false;
325
326
  /// True if this is a varargs function that contains a musttail call.
327
  bool HasMustTailInVarArgFunc = false;
328
329
  /// True if this function contains a tail call. If so immutable objects like
330
  /// function arguments are no longer so. A tail call *can* override fixed
331
  /// stack objects like arguments so we can't treat them as immutable.
332
  bool HasTailCall = false;
333
334
  /// Not null, if shrink-wrapping found a better place for the prologue.
335
  MachineBasicBlock *Save = nullptr;
336
  /// Not null, if shrink-wrapping found a better place for the epilogue.
337
  MachineBasicBlock *Restore = nullptr;
338
339
public:
340
  explicit MachineFrameInfo(unsigned StackAlignment, bool StackRealignable,
341
                            bool ForcedRealign)
342
      : StackAlignment(StackAlignment), StackRealignable(StackRealignable),
343
525k
        ForcedRealign(ForcedRealign) {}
344
345
  /// Return true if there are any stack objects in this function.
346
638k
  bool hasStackObjects() const { return !Objects.empty(); }
347
348
  /// This method may be called any time after instruction
349
  /// selection is complete to determine if the stack frame for this function
350
  /// contains any variable sized objects.
351
35.8M
  bool hasVarSizedObjects() const { return HasVarSizedObjects; }
352
353
  /// Return the index for the stack protector object.
354
831k
  int getStackProtectorIndex() const { return StackProtectorIdx; }
355
2.56k
  void setStackProtectorIndex(int I) { StackProtectorIdx = I; }
356
5.05k
  bool hasStackProtectorIndex() const { return StackProtectorIdx != -1; }
357
358
  /// Return the index for the function context object.
359
  /// This object is used for SjLj exceptions.
360
36
  int getFunctionContextIndex() const { return FunctionContextIdx; }
361
36
  void setFunctionContextIndex(int I) { FunctionContextIdx = I; }
362
363
  /// This method may be called any time after instruction
364
  /// selection is complete to determine if there is a call to
365
  /// \@llvm.frameaddress in this function.
366
8.74M
  bool isFrameAddressTaken() const { return FrameAddressTaken; }
367
15.4k
  void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; }
368
369
  /// This method may be called any time after
370
  /// instruction selection is complete to determine if there is a call to
371
  /// \@llvm.returnaddress in this function.
372
6.68k
  bool isReturnAddressTaken() const { return ReturnAddressTaken; }
373
10.7k
  void setReturnAddressIsTaken(bool s) { ReturnAddressTaken = s; }
374
375
  /// This method may be called any time after instruction
376
  /// selection is complete to determine if there is a call to builtin
377
  /// \@llvm.experimental.stackmap.
378
8.36M
  bool hasStackMap() const { return HasStackMap; }
379
4.78k
  void setHasStackMap(bool s = true) { HasStackMap = s; }
380
381
  /// This method may be called any time after instruction
382
  /// selection is complete to determine if there is a call to builtin
383
  /// \@llvm.experimental.patchpoint.
384
8.81M
  bool hasPatchPoint() const { return HasPatchPoint; }
385
4.80k
  void setHasPatchPoint(bool s = true) { HasPatchPoint = s; }
386
387
  /// Return the minimum frame object index.
388
895k
  int getObjectIndexBegin() const { return -NumFixedObjects; }
389
390
  /// Return one past the maximum frame object index.
391
2.32M
  int getObjectIndexEnd() const { return (int)Objects.size()-NumFixedObjects; }
392
393
  /// Return the number of fixed objects.
394
  unsigned getNumFixedObjects() const { return NumFixedObjects; }
395
396
  /// Return the number of objects.
397
7.03k
  unsigned getNumObjects() const { return Objects.size(); }
398
399
  /// Map a frame index into the local object block
400
52.0k
  void mapLocalFrameObject(int ObjectIndex, int64_t Offset) {
401
52.0k
    LocalFrameObjects.push_back(std::pair<int, int64_t>(ObjectIndex, Offset));
402
52.0k
    Objects[ObjectIndex + NumFixedObjects].PreAllocated = true;
403
52.0k
  }
404
405
  /// Get the local offset mapping for a for an object.
406
6.79k
  std::pair<int, int64_t> getLocalFrameObjectMap(int i) const {
407
6.79k
    assert (i >= 0 && (unsigned)i < LocalFrameObjects.size() &&
408
6.79k
            "Invalid local object reference!");
409
6.79k
    return LocalFrameObjects[i];
410
6.79k
  }
411
412
  /// Return the number of objects allocated into the local object block.
413
6.54k
  int64_t getLocalFrameObjectCount() const { return LocalFrameObjects.size(); }
414
415
  /// Set the size of the local object blob.
416
34.8k
  void setLocalFrameSize(int64_t sz) { LocalFrameSize = sz; }
417
418
  /// Get the size of the local object blob.
419
359k
  int64_t getLocalFrameSize() const { return LocalFrameSize; }
420
421
  /// Required alignment of the local object blob,
422
  /// which is the strictest alignment of any object in it.
423
30.2k
  void setLocalFrameMaxAlign(unsigned Align) { LocalFrameMaxAlign = Align; }
424
425
  /// Return the required alignment of the local object blob.
426
26.5k
  unsigned getLocalFrameMaxAlign() const { return LocalFrameMaxAlign; }
427
428
  /// Get whether the local allocation blob should be allocated together or
429
  /// let PEI allocate the locals in it directly.
430
537k
  bool getUseLocalStackAllocationBlock() const {
431
537k
    return UseLocalStackAllocationBlock;
432
537k
  }
433
434
  /// setUseLocalStackAllocationBlock - Set whether the local allocation blob
435
  /// should be allocated together or let PEI allocate the locals in it
436
  /// directly.
437
30.2k
  void setUseLocalStackAllocationBlock(bool v) {
438
30.2k
    UseLocalStackAllocationBlock = v;
439
30.2k
  }
440
441
  /// Return true if the object was pre-allocated into the local block.
442
2.03M
  bool isObjectPreAllocated(int ObjectIdx) const {
443
2.03M
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
444
2.03M
           "Invalid Object Idx!");
445
2.03M
    return Objects[ObjectIdx+NumFixedObjects].PreAllocated;
446
2.03M
  }
447
448
  /// Return the size of the specified object.
449
3.20M
  int64_t getObjectSize(int ObjectIdx) const {
450
3.20M
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
451
3.20M
           "Invalid Object Idx!");
452
3.20M
    return Objects[ObjectIdx+NumFixedObjects].Size;
453
3.20M
  }
454
455
  /// Change the size of the specified stack object.
456
105k
  void setObjectSize(int ObjectIdx, int64_t Size) {
457
105k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
458
105k
           "Invalid Object Idx!");
459
105k
    Objects[ObjectIdx+NumFixedObjects].Size = Size;
460
105k
  }
461
462
  /// Return the alignment of the specified stack object.
463
7.89M
  unsigned getObjectAlignment(int ObjectIdx) const {
464
7.89M
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
465
7.89M
           "Invalid Object Idx!");
466
7.89M
    return Objects[ObjectIdx+NumFixedObjects].Alignment;
467
7.89M
  }
468
469
  /// setObjectAlignment - Change the alignment of the specified stack object.
470
128k
  void setObjectAlignment(int ObjectIdx, unsigned Align) {
471
128k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
472
128k
           "Invalid Object Idx!");
473
128k
    Objects[ObjectIdx+NumFixedObjects].Alignment = Align;
474
128k
    ensureMaxAlignment(Align);
475
128k
  }
476
477
  /// Return the underlying Alloca of the specified
478
  /// stack object if it exists. Returns 0 if none exists.
479
607k
  const AllocaInst* getObjectAllocation(int ObjectIdx) const {
480
607k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
481
607k
           "Invalid Object Idx!");
482
607k
    return Objects[ObjectIdx+NumFixedObjects].Alloca;
483
607k
  }
484
485
  /// Return the assigned stack offset of the specified object
486
  /// from the incoming stack pointer.
487
3.00M
  int64_t getObjectOffset(int ObjectIdx) const {
488
3.00M
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
489
3.00M
           "Invalid Object Idx!");
490
3.00M
    assert(!isDeadObjectIndex(ObjectIdx) &&
491
3.00M
           "Getting frame offset for a dead object?");
492
3.00M
    return Objects[ObjectIdx+NumFixedObjects].SPOffset;
493
3.00M
  }
494
495
18
  bool isObjectZExt(int ObjectIdx) const {
496
18
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
497
18
           "Invalid Object Idx!");
498
18
    return Objects[ObjectIdx+NumFixedObjects].isZExt;
499
18
  }
500
501
1.38k
  void setObjectZExt(int ObjectIdx, bool IsZExt) {
502
1.38k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
503
1.38k
           "Invalid Object Idx!");
504
1.38k
    Objects[ObjectIdx+NumFixedObjects].isZExt = IsZExt;
505
1.38k
  }
506
507
17
  bool isObjectSExt(int ObjectIdx) const {
508
17
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
509
17
           "Invalid Object Idx!");
510
17
    return Objects[ObjectIdx+NumFixedObjects].isSExt;
511
17
  }
512
513
66
  void setObjectSExt(int ObjectIdx, bool IsSExt) {
514
66
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
515
66
           "Invalid Object Idx!");
516
66
    Objects[ObjectIdx+NumFixedObjects].isSExt = IsSExt;
517
66
  }
518
519
  /// Set the stack frame offset of the specified object. The
520
  /// offset is relative to the stack pointer on entry to the function.
521
1.48M
  void setObjectOffset(int ObjectIdx, int64_t SPOffset) {
522
1.48M
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
523
1.48M
           "Invalid Object Idx!");
524
1.48M
    assert(!isDeadObjectIndex(ObjectIdx) &&
525
1.48M
           "Setting frame offset for a dead object?");
526
1.48M
    Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset;
527
1.48M
  }
528
529
54.3k
  SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const {
530
54.3k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
531
54.3k
           "Invalid Object Idx!");
532
54.3k
    return (SSPLayoutKind)Objects[ObjectIdx+NumFixedObjects].SSPLayout;
533
54.3k
  }
534
535
6.41k
  void setObjectSSPLayout(int ObjectIdx, SSPLayoutKind Kind) {
536
6.41k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
537
6.41k
           "Invalid Object Idx!");
538
6.41k
    assert(!isDeadObjectIndex(ObjectIdx) &&
539
6.41k
           "Setting SSP layout for a dead object?");
540
6.41k
    Objects[ObjectIdx+NumFixedObjects].SSPLayout = Kind;
541
6.41k
  }
542
543
  /// Return the number of bytes that must be allocated to hold
544
  /// all of the fixed size frame objects.  This is only valid after
545
  /// Prolog/Epilog code insertion has finalized the stack frame layout.
546
2.68M
  uint64_t getStackSize() const { return StackSize; }
547
548
  /// Set the size of the stack.
549
588k
  void setStackSize(uint64_t Size) { StackSize = Size; }
550
551
  /// Estimate and return the size of the stack frame.
552
  unsigned estimateStackSize(const MachineFunction &MF) const;
553
554
  /// Return the correction for frame offsets.
555
9.01k
  int getOffsetAdjustment() const { return OffsetAdjustment; }
556
557
  /// Set the correction for frame offsets.
558
140k
  void setOffsetAdjustment(int Adj) { OffsetAdjustment = Adj; }
559
560
  /// Return the alignment in bytes that this function must be aligned to,
561
  /// which is greater than the default stack alignment provided by the target.
562
14.0M
  unsigned getMaxAlignment() const { return MaxAlignment; }
563
564
  /// Make sure the function is at least Align bytes aligned.
565
  void ensureMaxAlignment(unsigned Align);
566
567
  /// Return true if this function adjusts the stack -- e.g.,
568
  /// when calling another function. This is only valid during and after
569
  /// prolog/epilog code insertion.
570
2.35M
  bool adjustsStack() const { return AdjustsStack; }
571
480k
  void setAdjustsStack(bool V) { AdjustsStack = V; }
572
573
  /// Return true if the current function has any function calls.
574
21.8M
  bool hasCalls() const { return HasCalls; }
575
1.90M
  void setHasCalls(bool V) { HasCalls = V; }
576
577
  /// Returns true if the function contains opaque dynamic stack adjustments.
578
1.58M
  bool hasOpaqueSPAdjustment() const { return HasOpaqueSPAdjustment; }
579
4.99k
  void setHasOpaqueSPAdjustment(bool B) { HasOpaqueSPAdjustment = B; }
580
581
  /// Returns true if the function contains operations which will lower down to
582
  /// instructions which manipulate the stack pointer.
583
1.50M
  bool hasCopyImplyingStackAdjustment() const {
584
1.50M
    return HasCopyImplyingStackAdjustment;
585
1.50M
  }
586
12
  void setHasCopyImplyingStackAdjustment(bool B) {
587
12
    HasCopyImplyingStackAdjustment = B;
588
12
  }
589
590
  /// Returns true if the function calls the llvm.va_start intrinsic.
591
138k
  bool hasVAStart() const { return HasVAStart; }
592
5.14k
  void setHasVAStart(bool B) { HasVAStart = B; }
593
594
  /// Returns true if the function is variadic and contains a musttail call.
595
5.20k
  bool hasMustTailInVarArgFunc() const { return HasMustTailInVarArgFunc; }
596
4.65k
  void setHasMustTailInVarArgFunc(bool B) { HasMustTailInVarArgFunc = B; }
597
598
  /// Returns true if the function contains a tail call.
599
202k
  bool hasTailCall() const { return HasTailCall; }
600
76.9k
  void setHasTailCall() { HasTailCall = true; }
601
602
  /// Computes the maximum size of a callframe and the AdjustsStack property.
603
  /// This only works for targets defining
604
  /// TargetInstrInfo::getCallFrameSetupOpcode(), getCallFrameDestroyOpcode(),
605
  /// and getFrameSize().
606
  /// This is usually computed by the prologue epilogue inserter but some
607
  /// targets may call this to compute it earlier.
608
  void computeMaxCallFrameSize(const MachineFunction &MF);
609
610
  /// Return the maximum size of a call frame that must be
611
  /// allocated for an outgoing function call.  This is only available if
612
  /// CallFrameSetup/Destroy pseudo instructions are used by the target, and
613
  /// then only during or after prolog/epilog code insertion.
614
  ///
615
2.56M
  unsigned getMaxCallFrameSize() const {
616
2.56M
    // TODO: Enable this assert when targets are fixed.
617
2.56M
    //assert(isMaxCallFrameSizeComputed() && "MaxCallFrameSize not computed yet");
618
2.56M
    if (!isMaxCallFrameSizeComputed())
619
3.95k
      return 0;
620
2.55M
    return MaxCallFrameSize;
621
2.55M
  }
622
9.58M
  bool isMaxCallFrameSizeComputed() const {
623
9.58M
    return MaxCallFrameSize != ~0u;
624
9.58M
  }
625
481k
  void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; }
626
627
  /// Returns how many bytes of callee-saved registers the target pushed in the
628
  /// prologue. Only used for debug info.
629
5.05k
  unsigned getCVBytesOfCalleeSavedRegisters() const {
630
5.05k
    return CVBytesOfCalleeSavedRegisters;
631
5.05k
  }
632
140k
  void setCVBytesOfCalleeSavedRegisters(unsigned S) {
633
140k
    CVBytesOfCalleeSavedRegisters = S;
634
140k
  }
635
636
  /// Create a new object at a fixed location on the stack.
637
  /// All fixed objects should be created before other objects are created for
638
  /// efficiency. By default, fixed objects are not pointed to by LLVM IR
639
  /// values. This returns an index with a negative value.
640
  int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable,
641
                        bool isAliased = false);
642
643
  /// Create a spill slot at a fixed location on the stack.
644
  /// Returns an index with a negative value.
645
  int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset,
646
                                  bool IsImmutable = false);
647
648
  /// Returns true if the specified index corresponds to a fixed stack object.
649
1.36M
  bool isFixedObjectIndex(int ObjectIdx) const {
650
1.36M
    return ObjectIdx < 0 && 
(ObjectIdx >= -(int)NumFixedObjects)125k
;
651
1.36M
  }
652
653
  /// Returns true if the specified index corresponds
654
  /// to an object that might be pointed to by an LLVM IR value.
655
58.8k
  bool isAliasedObjectIndex(int ObjectIdx) const {
656
58.8k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
657
58.8k
           "Invalid Object Idx!");
658
58.8k
    return Objects[ObjectIdx+NumFixedObjects].isAliased;
659
58.8k
  }
660
661
  /// Returns true if the specified index corresponds to an immutable object.
662
769k
  bool isImmutableObjectIndex(int ObjectIdx) const {
663
769k
    // Tail calling functions can clobber their function arguments.
664
769k
    if (HasTailCall)
665
168k
      return false;
666
601k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
667
601k
           "Invalid Object Idx!");
668
601k
    return Objects[ObjectIdx+NumFixedObjects].isImmutable;
669
601k
  }
670
671
  /// Marks the immutability of an object.
672
328
  void setIsImmutableObjectIndex(int ObjectIdx, bool IsImmutable) {
673
328
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
674
328
           "Invalid Object Idx!");
675
328
    Objects[ObjectIdx+NumFixedObjects].isImmutable = IsImmutable;
676
328
  }
677
678
  /// Returns true if the specified index corresponds to a spill slot.
679
559k
  bool isSpillSlotObjectIndex(int ObjectIdx) const {
680
559k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
681
559k
           "Invalid Object Idx!");
682
559k
    return Objects[ObjectIdx+NumFixedObjects].isSpillSlot;
683
559k
  }
684
685
162
  bool isStatepointSpillSlotObjectIndex(int ObjectIdx) const {
686
162
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
687
162
           "Invalid Object Idx!");
688
162
    return Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot;
689
162
  }
690
691
  /// \see StackID
692
320k
  uint8_t getStackID(int ObjectIdx) const {
693
320k
    return Objects[ObjectIdx+NumFixedObjects].StackID;
694
320k
  }
695
696
  /// \see StackID
697
2.01k
  void setStackID(int ObjectIdx, uint8_t ID) {
698
2.01k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
699
2.01k
           "Invalid Object Idx!");
700
2.01k
    Objects[ObjectIdx+NumFixedObjects].StackID = ID;
701
2.01k
  }
702
703
  /// Returns true if the specified index corresponds to a dead object.
704
793k
  bool isDeadObjectIndex(int ObjectIdx) const {
705
793k
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
706
793k
           "Invalid Object Idx!");
707
793k
    return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
708
793k
  }
709
710
  /// Returns true if the specified index corresponds to a variable sized
711
  /// object.
712
180k
  bool isVariableSizedObjectIndex(int ObjectIdx) const {
713
180k
    assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
714
180k
           "Invalid Object Idx!");
715
180k
    return Objects[ObjectIdx + NumFixedObjects].Size == 0;
716
180k
  }
717
718
49
  void markAsStatepointSpillSlotObjectIndex(int ObjectIdx) {
719
49
    assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
720
49
           "Invalid Object Idx!");
721
49
    Objects[ObjectIdx+NumFixedObjects].isStatepointSpillSlot = true;
722
49
    assert(isStatepointSpillSlotObjectIndex(ObjectIdx) && "inconsistent");
723
49
  }
724
725
  /// Create a new statically sized stack object, returning
726
  /// a nonnegative identifier to represent it.
727
  int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSpillSlot,
728
                        const AllocaInst *Alloca = nullptr, uint8_t ID = 0);
729
730
  /// Create a new statically sized stack object that represents a spill slot,
731
  /// returning a nonnegative identifier to represent it.
732
  int CreateSpillStackObject(uint64_t Size, unsigned Alignment);
733
734
  /// Remove or mark dead a statically sized stack object.
735
47.5k
  void RemoveStackObject(int ObjectIdx) {
736
47.5k
    // Mark it dead.
737
47.5k
    Objects[ObjectIdx+NumFixedObjects].Size = ~0ULL;
738
47.5k
  }
739
740
  /// Notify the MachineFrameInfo object that a variable sized object has been
741
  /// created.  This must be created whenever a variable sized object is
742
  /// created, whether or not the index returned is actually used.
743
  int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca);
744
745
  /// Returns a reference to call saved info vector for the current function.
746
1.97M
  const std::vector<CalleeSavedInfo> &getCalleeSavedInfo() const {
747
1.97M
    return CSInfo;
748
1.97M
  }
749
  /// \copydoc getCalleeSavedInfo()
750
822k
  std::vector<CalleeSavedInfo> &getCalleeSavedInfo() { return CSInfo; }
751
752
  /// Used by prolog/epilog inserter to set the function's callee saved
753
  /// information.
754
359k
  void setCalleeSavedInfo(const std::vector<CalleeSavedInfo> &CSI) {
755
359k
    CSInfo = CSI;
756
359k
  }
757
758
  /// Has the callee saved info been calculated yet?
759
3.73M
  bool isCalleeSavedInfoValid() const { return CSIValid; }
760
761
473k
  void setCalleeSavedInfoValid(bool v) { CSIValid = v; }
762
763
721k
  MachineBasicBlock *getSavePoint() const { return Save; }
764
482k
  void setSavePoint(MachineBasicBlock *NewSave) { Save = NewSave; }
765
234k
  MachineBasicBlock *getRestorePoint() const { return Restore; }
766
482k
  void setRestorePoint(MachineBasicBlock *NewRestore) { Restore = NewRestore; }
767
768
  /// Return a set of physical registers that are pristine.
769
  ///
770
  /// Pristine registers hold a value that is useless to the current function,
771
  /// but that must be preserved - they are callee saved registers that are not
772
  /// saved.
773
  ///
774
  /// Before the PrologueEpilogueInserter has placed the CSR spill code, this
775
  /// method always returns an empty set.
776
  BitVector getPristineRegs(const MachineFunction &MF) const;
777
778
  /// Used by the MachineFunction printer to print information about
779
  /// stack objects. Implemented in MachineFunction.cpp.
780
  void print(const MachineFunction &MF, raw_ostream &OS) const;
781
782
  /// dump - Print the function to stderr.
783
  void dump(const MachineFunction &MF) const;
784
};
785
786
} // End llvm namespace
787
788
#endif