Coverage Report

Created: 2018-07-19 03:59

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