Coverage Report

Created: 2019-02-20 07:29

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