Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
StackColoring.cpp
Go to the documentation of this file.
1//===- StackColoring.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This pass implements the stack-coloring optimization that looks for
10// lifetime markers machine instructions (LIFETIME_START and LIFETIME_END),
11// which represent the possible lifetime of stack slots. It attempts to
12// merge disjoint stack slots and reduce the used stack space.
13// NOTE: This pass is not StackSlotColoring, which optimizes spill slots.
14//
15// TODO: In the future we plan to improve stack coloring in the following ways:
16// 1. Allow merging multiple small slots into a single larger slot at different
17// offsets.
18// 2. Merge this pass with StackSlotColoring and allow merging of allocas with
19// spill slots.
20//
21//===----------------------------------------------------------------------===//
22
23#include "llvm/CodeGen/StackColoring.h"
24#include "llvm/ADT/BitVector.h"
25#include "llvm/ADT/DenseMap.h"
26#include "llvm/ADT/DepthFirstIterator.h"
27#include "llvm/ADT/SmallPtrSet.h"
28#include "llvm/ADT/SmallVector.h"
29#include "llvm/ADT/Statistic.h"
30#include "llvm/Analysis/ValueTracking.h"
31#include "llvm/CodeGen/LiveInterval.h"
32#include "llvm/CodeGen/MachineBasicBlock.h"
33#include "llvm/CodeGen/MachineFrameInfo.h"
34#include "llvm/CodeGen/MachineFunction.h"
35#include "llvm/CodeGen/MachineFunctionPass.h"
36#include "llvm/CodeGen/MachineInstr.h"
37#include "llvm/CodeGen/MachineMemOperand.h"
38#include "llvm/CodeGen/MachineOperand.h"
39#include "llvm/CodeGen/Passes.h"
40#include "llvm/CodeGen/PseudoSourceValueManager.h"
41#include "llvm/CodeGen/SlotIndexes.h"
42#include "llvm/CodeGen/TargetOpcodes.h"
43#include "llvm/CodeGen/WinEHFuncInfo.h"
44#include "llvm/Config/llvm-config.h"
45#include "llvm/IR/Constants.h"
46#include "llvm/IR/DebugInfoMetadata.h"
47#include "llvm/IR/Instructions.h"
48#include "llvm/IR/Metadata.h"
49#include "llvm/IR/Use.h"
50#include "llvm/IR/Value.h"
51#include "llvm/InitializePasses.h"
52#include "llvm/Pass.h"
53#include "llvm/Support/Casting.h"
54#include "llvm/Support/CommandLine.h"
55#include "llvm/Support/Compiler.h"
56#include "llvm/Support/Debug.h"
57#include "llvm/Support/raw_ostream.h"
58#include <algorithm>
59#include <cassert>
60#include <limits>
61#include <memory>
62#include <utility>
63
64using namespacellvm;
65
66#define DEBUG_TYPE "stack-coloring"
67
68staticcl::opt<bool>
69DisableColoring("no-stack-coloring",
70cl::init(false),cl::Hidden,
71cl::desc("Disable stack coloring"));
72
73/// The user may write code that uses allocas outside of the declared lifetime
74/// zone. This can happen when the user returns a reference to a local
75/// data-structure. We can detect these cases and decide not to optimize the
76/// code. If this flag is enabled, we try to save the user. This option
77/// is treated as overriding LifetimeStartOnFirstUse below.
78staticcl::opt<bool>
79ProtectFromEscapedAllocas("protect-from-escaped-allocas",
80cl::init(false),cl::Hidden,
81cl::desc("Do not optimize lifetime zones that "
82"are broken"));
83
84/// Enable enhanced dataflow scheme for lifetime analysis (treat first
85/// use of stack slot as start of slot lifetime, as opposed to looking
86/// for LIFETIME_START marker). See "Implementation notes" below for
87/// more info.
88staticcl::opt<bool>
89LifetimeStartOnFirstUse("stackcoloring-lifetime-start-on-first-use",
90cl::init(true),cl::Hidden,
91cl::desc("Treat stack lifetimes as starting on first use, not on START marker."));
92
93
94STATISTIC(NumMarkerSeen,"Number of lifetime markers found.");
95STATISTIC(StackSpaceSaved,"Number of bytes saved due to merging slots.");
96STATISTIC(StackSlotMerged,"Number of stack slot merged.");
97STATISTIC(EscapedAllocas,"Number of allocas that escaped the lifetime region");
98
99//===----------------------------------------------------------------------===//
100// StackColoring Pass
101//===----------------------------------------------------------------------===//
102//
103// Stack Coloring reduces stack usage by merging stack slots when they
104// can't be used together. For example, consider the following C program:
105//
106// void bar(char *, int);
107// void foo(bool var) {
108// A: {
109// char z[4096];
110// bar(z, 0);
111// }
112//
113// char *p;
114// char x[4096];
115// char y[4096];
116// if (var) {
117// p = x;
118// } else {
119// bar(y, 1);
120// p = y + 1024;
121// }
122// B:
123// bar(p, 2);
124// }
125//
126// Naively-compiled, this program would use 12k of stack space. However, the
127// stack slot corresponding to `z` is always destroyed before either of the
128// stack slots for `x` or `y` are used, and then `x` is only used if `var`
129// is true, while `y` is only used if `var` is false. So in no time are 2
130// of the stack slots used together, and therefore we can merge them,
131// compiling the function using only a single 4k alloca:
132//
133// void foo(bool var) { // equivalent
134// char x[4096];
135// char *p;
136// bar(x, 0);
137// if (var) {
138// p = x;
139// } else {
140// bar(x, 1);
141// p = x + 1024;
142// }
143// bar(p, 2);
144// }
145//
146// This is an important optimization if we want stack space to be under
147// control in large functions, both open-coded ones and ones created by
148// inlining.
149//
150// Implementation Notes:
151// ---------------------
152//
153// An important part of the above reasoning is that `z` can't be accessed
154// while the latter 2 calls to `bar` are running. This is justified because
155// `z`'s lifetime is over after we exit from block `A:`, so any further
156// accesses to it would be UB. The way we represent this information
157// in LLVM is by having frontends delimit blocks with `lifetime.start`
158// and `lifetime.end` intrinsics.
159//
160// The effect of these intrinsics seems to be as follows (maybe I should
161// specify this in the reference?):
162//
163// L1) at start, each stack-slot is marked as *out-of-scope*, unless no
164// lifetime intrinsic refers to that stack slot, in which case
165// it is marked as *in-scope*.
166// L2) on a `lifetime.start`, a stack slot is marked as *in-scope* and
167// the stack slot is overwritten with `undef`.
168// L3) on a `lifetime.end`, a stack slot is marked as *out-of-scope*.
169// L4) on function exit, all stack slots are marked as *out-of-scope*.
170// L5) `lifetime.end` is a no-op when called on a slot that is already
171// *out-of-scope*.
172// L6) memory accesses to *out-of-scope* stack slots are UB.
173// L7) when a stack-slot is marked as *out-of-scope*, all pointers to it
174// are invalidated, unless the slot is "degenerate". This is used to
175// justify not marking slots as in-use until the pointer to them is
176// used, but feels a bit hacky in the presence of things like LICM. See
177// the "Degenerate Slots" section for more details.
178//
179// Now, let's ground stack coloring on these rules. We'll define a slot
180// as *in-use* at a (dynamic) point in execution if it either can be
181// written to at that point, or if it has a live and non-undef content
182// at that point.
183//
184// Obviously, slots that are never *in-use* together can be merged, and
185// in our example `foo`, the slots for `x`, `y` and `z` are never
186// in-use together (of course, sometimes slots that *are* in-use together
187// might still be mergable, but we don't care about that here).
188//
189// In this implementation, we successively merge pairs of slots that are
190// not *in-use* together. We could be smarter - for example, we could merge
191// a single large slot with 2 small slots, or we could construct the
192// interference graph and run a "smart" graph coloring algorithm, but with
193// that aside, how do we find out whether a pair of slots might be *in-use*
194// together?
195//
196// From our rules, we see that *out-of-scope* slots are never *in-use*,
197// and from (L7) we see that "non-degenerate" slots remain non-*in-use*
198// until their address is taken. Therefore, we can approximate slot activity
199// using dataflow.
200//
201// A subtle point: naively, we might try to figure out which pairs of
202// stack-slots interfere by propagating `S in-use` through the CFG for every
203// stack-slot `S`, and having `S` and `T` interfere if there is a CFG point in
204// which they are both *in-use*.
205//
206// That is sound, but overly conservative in some cases: in our (artificial)
207// example `foo`, either `x` or `y` might be in use at the label `B:`, but
208// as `x` is only in use if we came in from the `var` edge and `y` only
209// if we came from the `!var` edge, they still can't be in use together.
210// See PR32488 for an important real-life case.
211//
212// If we wanted to find all points of interference precisely, we could
213// propagate `S in-use` and `S&T in-use` predicates through the CFG. That
214// would be precise, but requires propagating `O(n^2)` dataflow facts.
215//
216// However, we aren't interested in the *set* of points of interference
217// between 2 stack slots, only *whether* there *is* such a point. So we
218// can rely on a little trick: for `S` and `T` to be in-use together,
219// one of them needs to become in-use while the other is in-use (or
220// they might both become in use simultaneously). We can check this
221// by also keeping track of the points at which a stack slot might *start*
222// being in-use.
223//
224// Exact first use:
225// ----------------
226//
227// Consider the following motivating example:
228//
229// int foo() {
230// char b1[1024], b2[1024];
231// if (...) {
232// char b3[1024];
233// <uses of b1, b3>;
234// return x;
235// } else {
236// char b4[1024], b5[1024];
237// <uses of b2, b4, b5>;
238// return y;
239// }
240// }
241//
242// In the code above, "b3" and "b4" are declared in distinct lexical
243// scopes, meaning that it is easy to prove that they can share the
244// same stack slot. Variables "b1" and "b2" are declared in the same
245// scope, meaning that from a lexical point of view, their lifetimes
246// overlap. From a control flow pointer of view, however, the two
247// variables are accessed in disjoint regions of the CFG, thus it
248// should be possible for them to share the same stack slot. An ideal
249// stack allocation for the function above would look like:
250//
251// slot 0: b1, b2
252// slot 1: b3, b4
253// slot 2: b5
254//
255// Achieving this allocation is tricky, however, due to the way
256// lifetime markers are inserted. Here is a simplified view of the
257// control flow graph for the code above:
258//
259// +------ block 0 -------+
260// 0| LIFETIME_START b1, b2 |
261// 1| <test 'if' condition> |
262// +-----------------------+
263// ./ \.
264// +------ block 1 -------+ +------ block 2 -------+
265// 2| LIFETIME_START b3 | 5| LIFETIME_START b4, b5 |
266// 3| <uses of b1, b3> | 6| <uses of b2, b4, b5> |
267// 4| LIFETIME_END b3 | 7| LIFETIME_END b4, b5 |
268// +-----------------------+ +-----------------------+
269// \. /.
270// +------ block 3 -------+
271// 8| <cleanupcode> |
272// 9| LIFETIME_END b1, b2 |
273// 10| return |
274// +-----------------------+
275//
276// If we create live intervals for the variables above strictly based
277// on the lifetime markers, we'll get the set of intervals on the
278// left. If we ignore the lifetime start markers and instead treat a
279// variable's lifetime as beginning with the first reference to the
280// var, then we get the intervals on the right.
281//
282// LIFETIME_START First Use
283// b1: [0,9] [3,4] [8,9]
284// b2: [0,9] [6,9]
285// b3: [2,4] [3,4]
286// b4: [5,7] [6,7]
287// b5: [5,7] [6,7]
288//
289// For the intervals on the left, the best we can do is overlap two
290// variables (b3 and b4, for example); this gives us a stack size of
291// 4*1024 bytes, not ideal. When treating first-use as the start of a
292// lifetime, we can additionally overlap b1 and b5, giving us a 3*1024
293// byte stack (better).
294//
295// Degenerate Slots:
296// -----------------
297//
298// Relying entirely on first-use of stack slots is problematic,
299// however, due to the fact that optimizations can sometimes migrate
300// uses of a variable outside of its lifetime start/end region. Here
301// is an example:
302//
303// int bar() {
304// char b1[1024], b2[1024];
305// if (...) {
306// <uses of b2>
307// return y;
308// } else {
309// <uses of b1>
310// while (...) {
311// char b3[1024];
312// <uses of b3>
313// }
314// }
315// }
316//
317// Before optimization, the control flow graph for the code above
318// might look like the following:
319//
320// +------ block 0 -------+
321// 0| LIFETIME_START b1, b2 |
322// 1| <test 'if' condition> |
323// +-----------------------+
324// ./ \.
325// +------ block 1 -------+ +------- block 2 -------+
326// 2| <uses of b2> | 3| <uses of b1> |
327// +-----------------------+ +-----------------------+
328// | |
329// | +------- block 3 -------+ <-\.
330// | 4| <while condition> | |
331// | +-----------------------+ |
332// | / | |
333// | / +------- block 4 -------+
334// \ / 5| LIFETIME_START b3 | |
335// \ / 6| <uses of b3> | |
336// \ / 7| LIFETIME_END b3 | |
337// \ | +------------------------+ |
338// \ | \ /
339// +------ block 5 -----+ \---------------
340// 8| <cleanupcode> |
341// 9| LIFETIME_END b1, b2 |
342// 10| return |
343// +---------------------+
344//
345// During optimization, however, it can happen that an instruction
346// computing an address in "b3" (for example, a loop-invariant GEP) is
347// hoisted up out of the loop from block 4 to block 2. [Note that
348// this is not an actual load from the stack, only an instruction that
349// computes the address to be loaded]. If this happens, there is now a
350// path leading from the first use of b3 to the return instruction
351// that does not encounter the b3 LIFETIME_END, hence b3's lifetime is
352// now larger than if we were computing live intervals strictly based
353// on lifetime markers. In the example above, this lengthened lifetime
354// would mean that it would appear illegal to overlap b3 with b2.
355//
356// To deal with this such cases, the code in ::collectMarkers() below
357// tries to identify "degenerate" slots -- those slots where on a single
358// forward pass through the CFG we encounter a first reference to slot
359// K before we hit the slot K lifetime start marker. For such slots,
360// we fall back on using the lifetime start marker as the beginning of
361// the variable's lifetime. NB: with this implementation, slots can
362// appear degenerate in cases where there is unstructured control flow:
363//
364// if (q) goto mid;
365// if (x > 9) {
366// int b[100];
367// memcpy(&b[0], ...);
368// mid: b[k] = ...;
369// abc(&b);
370// }
371//
372// If in RPO ordering chosen to walk the CFG we happen to visit the b[k]
373// before visiting the memcpy block (which will contain the lifetime start
374// for "b" then it will appear that 'b' has a degenerate lifetime.
375
376namespace{
377
378/// StackColoring - A machine pass for merging disjoint stack allocations,
379/// marked by the LIFETIME_START and LIFETIME_END pseudo instructions.
380classStackColoring {
381MachineFrameInfo *MFI =nullptr;
382MachineFunction *MF =nullptr;
383
384 /// A class representing liveness information for a single basic block.
385 /// Each bit in the BitVector represents the liveness property
386 /// for a different stack slot.
387structBlockLifetimeInfo {
388 /// Which slots BEGINs in each basic block.
389BitVector Begin;
390
391 /// Which slots ENDs in each basic block.
392BitVectorEnd;
393
394 /// Which slots are marked as LIVE_IN, coming into each basic block.
395BitVector LiveIn;
396
397 /// Which slots are marked as LIVE_OUT, coming out of each basic block.
398BitVector LiveOut;
399 };
400
401 /// Maps active slots (per bit) for each basic block.
402usingLivenessMap =DenseMap<const MachineBasicBlock *, BlockLifetimeInfo>;
403 LivenessMap BlockLiveness;
404
405 /// Maps serial numbers to basic blocks.
406DenseMap<const MachineBasicBlock *, int> BasicBlocks;
407
408 /// Maps basic blocks to a serial number.
409SmallVector<const MachineBasicBlock *, 8> BasicBlockNumbering;
410
411 /// Maps slots to their use interval. Outside of this interval, slots
412 /// values are either dead or `undef` and they will not be written to.
413SmallVector<std::unique_ptr<LiveInterval>, 16> Intervals;
414
415 /// Maps slots to the points where they can become in-use.
416SmallVector<SmallVector<SlotIndex, 4>, 16> LiveStarts;
417
418 /// VNInfo is used for the construction of LiveIntervals.
419VNInfo::Allocator VNInfoAllocator;
420
421 /// SlotIndex analysis object.
422SlotIndexes *Indexes =nullptr;
423
424 /// The list of lifetime markers found. These markers are to be removed
425 /// once the coloring is done.
426SmallVector<MachineInstr*, 8>Markers;
427
428 /// Record the FI slots for which we have seen some sort of
429 /// lifetime marker (either start or end).
430BitVector InterestingSlots;
431
432 /// FI slots that need to be handled conservatively (for these
433 /// slots lifetime-start-on-first-use is disabled).
434BitVector ConservativeSlots;
435
436 /// Number of iterations taken during data flow analysis.
437unsigned NumIterations;
438
439public:
440 StackColoring(SlotIndexes *Indexes) : Indexes(Indexes) {}
441boolrun(MachineFunction &Func);
442
443private:
444 /// Used in collectMarkers
445usingBlockBitVecMap =DenseMap<const MachineBasicBlock *, BitVector>;
446
447 /// Debug.
448voiddump()const;
449void dumpIntervals()const;
450void dumpBB(MachineBasicBlock *MBB)const;
451void dumpBV(constchar *tag,constBitVector &BV)const;
452
453 /// Removes all of the lifetime marker instructions from the function.
454 /// \returns true if any markers were removed.
455bool removeAllMarkers();
456
457 /// Scan the machine function and find all of the lifetime markers.
458 /// Record the findings in the BEGIN and END vectors.
459 /// \returns the number of markers found.
460unsigned collectMarkers(unsigned NumSlot);
461
462 /// Perform the dataflow calculation and calculate the lifetime for each of
463 /// the slots, based on the BEGIN/END vectors. Set the LifetimeLIVE_IN and
464 /// LifetimeLIVE_OUT maps that represent which stack slots are live coming
465 /// in and out blocks.
466void calculateLocalLiveness();
467
468 /// Returns TRUE if we're using the first-use-begins-lifetime method for
469 /// this slot (if FALSE, then the start marker is treated as start of lifetime).
470bool applyFirstUse(int Slot) {
471if (!LifetimeStartOnFirstUse ||ProtectFromEscapedAllocas)
472returnfalse;
473if (ConservativeSlots.test(Slot))
474returnfalse;
475returntrue;
476 }
477
478 /// Examines the specified instruction and returns TRUE if the instruction
479 /// represents the start or end of an interesting lifetime. The slot or slots
480 /// starting or ending are added to the vector "slots" and "isStart" is set
481 /// accordingly.
482 /// \returns True if inst contains a lifetime start or end
483bool isLifetimeStartOrEnd(constMachineInstr &MI,
484SmallVector<int, 4> &slots,
485bool &isStart);
486
487 /// Construct the LiveIntervals for the slots.
488void calculateLiveIntervals(unsigned NumSlots);
489
490 /// Go over the machine function and change instructions which use stack
491 /// slots to use the joint slots.
492void remapInstructions(DenseMap<int, int> &SlotRemap);
493
494 /// The input program may contain instructions which are not inside lifetime
495 /// markers. This can happen due to a bug in the compiler or due to a bug in
496 /// user code (for example, returning a reference to a local variable).
497 /// This procedure checks all of the instructions in the function and
498 /// invalidates lifetime ranges which do not contain all of the instructions
499 /// which access that frame slot.
500void removeInvalidSlotRanges();
501
502 /// Map entries which point to other entries to their destination.
503 /// A->B->C becomes A->C.
504void expungeSlotMap(DenseMap<int, int> &SlotRemap,unsigned NumSlots);
505};
506
507classStackColoringLegacy :publicMachineFunctionPass {
508public:
509staticcharID;
510
511 StackColoringLegacy() :MachineFunctionPass(ID) {}
512
513voidgetAnalysisUsage(AnalysisUsage &AU)const override;
514boolrunOnMachineFunction(MachineFunction &Func)override;
515};
516
517}// end anonymous namespace
518
519char StackColoringLegacy::ID = 0;
520
521char &llvm::StackColoringLegacyID = StackColoringLegacy::ID;
522
523INITIALIZE_PASS_BEGIN(StackColoringLegacy,DEBUG_TYPE,
524"Merge disjoint stack slots",false,false)
525INITIALIZE_PASS_DEPENDENCY(SlotIndexesWrapperPass)
526INITIALIZE_PASS_END(StackColoringLegacy,DEBUG_TYPE,
527 "Merge disjoint stackslots",false,false)
528
529void StackColoringLegacy::getAnalysisUsage(AnalysisUsage &AU) const{
530 AU.addRequired<SlotIndexesWrapperPass>();
531MachineFunctionPass::getAnalysisUsage(AU);
532}
533
534#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
535LLVM_DUMP_METHODvoid StackColoring::dumpBV(constchar *tag,
536constBitVector &BV) const{
537dbgs() << tag <<" : { ";
538for (unsignedI = 0, E = BV.size();I != E; ++I)
539dbgs() << BV.test(I) <<" ";
540dbgs() <<"}\n";
541}
542
543LLVM_DUMP_METHODvoid StackColoring::dumpBB(MachineBasicBlock *MBB) const{
544 LivenessMap::const_iterator BI = BlockLiveness.find(MBB);
545assert(BI != BlockLiveness.end() &&"Block not found");
546const BlockLifetimeInfo &BlockInfo = BI->second;
547
548 dumpBV("BEGIN", BlockInfo.Begin);
549 dumpBV("END", BlockInfo.End);
550 dumpBV("LIVE_IN", BlockInfo.LiveIn);
551 dumpBV("LIVE_OUT", BlockInfo.LiveOut);
552}
553
554LLVM_DUMP_METHODvoid StackColoring::dump() const{
555for (MachineBasicBlock *MBB :depth_first(MF)) {
556dbgs() <<"Inspecting block #" <<MBB->getNumber() <<" ["
557 <<MBB->getName() <<"]\n";
558 dumpBB(MBB);
559 }
560}
561
562LLVM_DUMP_METHODvoid StackColoring::dumpIntervals() const{
563for (unsignedI = 0, E = Intervals.size();I != E; ++I) {
564dbgs() <<"Interval[" <<I <<"]:\n";
565 Intervals[I]->dump();
566 }
567}
568#endif
569
570staticinlineintgetStartOrEndSlot(constMachineInstr &MI)
571{
572assert((MI.getOpcode() == TargetOpcode::LIFETIME_START ||
573MI.getOpcode() == TargetOpcode::LIFETIME_END) &&
574"Expected LIFETIME_START or LIFETIME_END op");
575constMachineOperand &MO =MI.getOperand(0);
576int Slot = MO.getIndex();
577if (Slot >= 0)
578return Slot;
579return -1;
580}
581
582// At the moment the only way to end a variable lifetime is with
583// a VARIABLE_LIFETIME op (which can't contain a start). If things
584// change and the IR allows for a single inst that both begins
585// and ends lifetime(s), this interface will need to be reworked.
586bool StackColoring::isLifetimeStartOrEnd(constMachineInstr &MI,
587SmallVector<int, 4> &slots,
588bool &isStart) {
589if (MI.getOpcode() == TargetOpcode::LIFETIME_START ||
590MI.getOpcode() == TargetOpcode::LIFETIME_END) {
591intSlot =getStartOrEndSlot(MI);
592if (Slot < 0)
593returnfalse;
594if (!InterestingSlots.test(Slot))
595returnfalse;
596slots.push_back(Slot);
597if (MI.getOpcode() == TargetOpcode::LIFETIME_END) {
598 isStart =false;
599returntrue;
600 }
601if (!applyFirstUse(Slot)) {
602 isStart =true;
603returntrue;
604 }
605 }elseif (LifetimeStartOnFirstUse && !ProtectFromEscapedAllocas) {
606if (!MI.isDebugInstr()) {
607bool found =false;
608for (constMachineOperand &MO :MI.operands()) {
609if (!MO.isFI())
610continue;
611intSlot = MO.getIndex();
612if (Slot<0)
613continue;
614if (InterestingSlots.test(Slot) && applyFirstUse(Slot)) {
615slots.push_back(Slot);
616 found =true;
617 }
618 }
619if (found) {
620 isStart =true;
621returntrue;
622 }
623 }
624 }
625returnfalse;
626}
627
628unsigned StackColoring::collectMarkers(unsigned NumSlot) {
629unsigned MarkersFound = 0;
630 BlockBitVecMap SeenStartMap;
631 InterestingSlots.clear();
632 InterestingSlots.resize(NumSlot);
633 ConservativeSlots.clear();
634 ConservativeSlots.resize(NumSlot);
635
636// number of start and end lifetime ops for each slot
637SmallVector<int, 8> NumStartLifetimes(NumSlot, 0);
638SmallVector<int, 8> NumEndLifetimes(NumSlot, 0);
639
640// Step 1: collect markers and populate the "InterestingSlots"
641// and "ConservativeSlots" sets.
642for (MachineBasicBlock *MBB :depth_first(MF)) {
643// Compute the set of slots for which we've seen a START marker but have
644// not yet seen an END marker at this point in the walk (e.g. on entry
645// to this bb).
646BitVector BetweenStartEnd;
647 BetweenStartEnd.resize(NumSlot);
648for (constMachineBasicBlock *Pred :MBB->predecessors()) {
649 BlockBitVecMap::const_iteratorI = SeenStartMap.find(Pred);
650if (I != SeenStartMap.end()) {
651 BetweenStartEnd |=I->second;
652 }
653 }
654
655// Walk the instructions in the block to look for start/end ops.
656for (MachineInstr &MI : *MBB) {
657if (MI.isDebugInstr())
658continue;
659if (MI.getOpcode() == TargetOpcode::LIFETIME_START ||
660MI.getOpcode() == TargetOpcode::LIFETIME_END) {
661intSlot =getStartOrEndSlot(MI);
662if (Slot < 0)
663continue;
664 InterestingSlots.set(Slot);
665if (MI.getOpcode() == TargetOpcode::LIFETIME_START) {
666 BetweenStartEnd.set(Slot);
667 NumStartLifetimes[Slot] += 1;
668 }else {
669 BetweenStartEnd.reset(Slot);
670 NumEndLifetimes[Slot] += 1;
671 }
672constAllocaInst *Allocation = MFI->getObjectAllocation(Slot);
673if (Allocation) {
674LLVM_DEBUG(dbgs() <<"Found a lifetime ");
675LLVM_DEBUG(dbgs() << (MI.getOpcode() == TargetOpcode::LIFETIME_START
676 ?"start"
677 :"end"));
678LLVM_DEBUG(dbgs() <<" marker for slot #" << Slot);
679LLVM_DEBUG(dbgs()
680 <<" with allocation: " << Allocation->getName() <<"\n");
681 }
682Markers.push_back(&MI);
683 MarkersFound += 1;
684 }else {
685for (constMachineOperand &MO :MI.operands()) {
686if (!MO.isFI())
687continue;
688intSlot = MO.getIndex();
689if (Slot < 0)
690continue;
691if (! BetweenStartEnd.test(Slot)) {
692 ConservativeSlots.set(Slot);
693 }
694 }
695 }
696 }
697BitVector &SeenStart = SeenStartMap[MBB];
698 SeenStart |= BetweenStartEnd;
699 }
700if (!MarkersFound) {
701return 0;
702 }
703
704// PR27903: slots with multiple start or end lifetime ops are not
705// safe to enable for "lifetime-start-on-first-use".
706for (unsigned slot = 0; slot < NumSlot; ++slot) {
707if (NumStartLifetimes[slot] > 1 || NumEndLifetimes[slot] > 1)
708 ConservativeSlots.set(slot);
709 }
710
711// The write to the catch object by the personality function is not propely
712// modeled in IR: It happens before any cleanuppads are executed, even if the
713// first mention of the catch object is in a catchpad. As such, mark catch
714// object slots as conservative, so they are excluded from first-use analysis.
715if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
716for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
717for (WinEHHandlerType &H : TBME.HandlerArray)
718if (H.CatchObj.FrameIndex != std::numeric_limits<int>::max() &&
719H.CatchObj.FrameIndex >= 0)
720 ConservativeSlots.set(H.CatchObj.FrameIndex);
721
722LLVM_DEBUG(dumpBV("Conservative slots", ConservativeSlots));
723
724// Step 2: compute begin/end sets for each block
725
726// NOTE: We use a depth-first iteration to ensure that we obtain a
727// deterministic numbering.
728for (MachineBasicBlock *MBB :depth_first(MF)) {
729// Assign a serial number to this basic block.
730 BasicBlocks[MBB] = BasicBlockNumbering.size();
731 BasicBlockNumbering.push_back(MBB);
732
733// Keep a reference to avoid repeated lookups.
734 BlockLifetimeInfo &BlockInfo = BlockLiveness[MBB];
735
736 BlockInfo.Begin.resize(NumSlot);
737 BlockInfo.End.resize(NumSlot);
738
739SmallVector<int, 4>slots;
740for (MachineInstr &MI : *MBB) {
741bool isStart =false;
742slots.clear();
743if (isLifetimeStartOrEnd(MI,slots, isStart)) {
744if (!isStart) {
745assert(slots.size() == 1 &&"unexpected: MI ends multiple slots");
746intSlot =slots[0];
747if (BlockInfo.Begin.test(Slot)) {
748 BlockInfo.Begin.reset(Slot);
749 }
750 BlockInfo.End.set(Slot);
751 }else {
752for (auto Slot :slots) {
753LLVM_DEBUG(dbgs() <<"Found a use of slot #" << Slot);
754LLVM_DEBUG(dbgs()
755 <<" at " <<printMBBReference(*MBB) <<" index ");
756LLVM_DEBUG(Indexes->getInstructionIndex(MI).print(dbgs()));
757constAllocaInst *Allocation = MFI->getObjectAllocation(Slot);
758if (Allocation) {
759LLVM_DEBUG(dbgs()
760 <<" with allocation: " << Allocation->getName());
761 }
762LLVM_DEBUG(dbgs() <<"\n");
763if (BlockInfo.End.test(Slot)) {
764 BlockInfo.End.reset(Slot);
765 }
766 BlockInfo.Begin.set(Slot);
767 }
768 }
769 }
770 }
771 }
772
773// Update statistics.
774 NumMarkerSeen += MarkersFound;
775return MarkersFound;
776}
777
778void StackColoring::calculateLocalLiveness() {
779unsigned NumIters = 0;
780bool changed =true;
781// Create BitVector outside the loop and reuse them to avoid repeated heap
782// allocations.
783BitVector LocalLiveIn;
784BitVector LocalLiveOut;
785while (changed) {
786 changed =false;
787 ++NumIters;
788
789for (constMachineBasicBlock *BB : BasicBlockNumbering) {
790// Use an iterator to avoid repeated lookups.
791 LivenessMap::iterator BI = BlockLiveness.find(BB);
792assert(BI != BlockLiveness.end() &&"Block not found");
793 BlockLifetimeInfo &BlockInfo = BI->second;
794
795// Compute LiveIn by unioning together the LiveOut sets of all preds.
796 LocalLiveIn.clear();
797for (MachineBasicBlock *Pred : BB->predecessors()) {
798 LivenessMap::const_iteratorI = BlockLiveness.find(Pred);
799// PR37130: transformations prior to stack coloring can
800// sometimes leave behind statically unreachable blocks; these
801// can be safely skipped here.
802if (I != BlockLiveness.end())
803 LocalLiveIn |=I->second.LiveOut;
804 }
805
806// Compute LiveOut by subtracting out lifetimes that end in this
807// block, then adding in lifetimes that begin in this block. If
808// we have both BEGIN and END markers in the same basic block
809// then we know that the BEGIN marker comes after the END,
810// because we already handle the case where the BEGIN comes
811// before the END when collecting the markers (and building the
812// BEGIN/END vectors).
813 LocalLiveOut = LocalLiveIn;
814 LocalLiveOut.reset(BlockInfo.End);
815 LocalLiveOut |= BlockInfo.Begin;
816
817// Update block LiveIn set, noting whether it has changed.
818if (LocalLiveIn.test(BlockInfo.LiveIn)) {
819 changed =true;
820 BlockInfo.LiveIn |= LocalLiveIn;
821 }
822
823// Update block LiveOut set, noting whether it has changed.
824if (LocalLiveOut.test(BlockInfo.LiveOut)) {
825 changed =true;
826 BlockInfo.LiveOut |= LocalLiveOut;
827 }
828 }
829 }// while changed.
830
831 NumIterations = NumIters;
832}
833
834void StackColoring::calculateLiveIntervals(unsigned NumSlots) {
835SmallVector<SlotIndex, 16> Starts;
836SmallVector<bool, 16> DefinitelyInUse;
837
838// For each block, find which slots are active within this block
839// and update the live intervals.
840for (constMachineBasicBlock &MBB : *MF) {
841 Starts.clear();
842 Starts.resize(NumSlots);
843 DefinitelyInUse.clear();
844 DefinitelyInUse.resize(NumSlots);
845
846// Start the interval of the slots that we previously found to be 'in-use'.
847 BlockLifetimeInfo &MBBLiveness = BlockLiveness[&MBB];
848for (int pos = MBBLiveness.LiveIn.find_first(); pos != -1;
849 pos = MBBLiveness.LiveIn.find_next(pos)) {
850 Starts[pos] = Indexes->getMBBStartIdx(&MBB);
851 }
852
853// Create the interval for the basic blocks containing lifetime begin/end.
854for (constMachineInstr &MI :MBB) {
855SmallVector<int, 4>slots;
856bool IsStart =false;
857if (!isLifetimeStartOrEnd(MI,slots, IsStart))
858continue;
859SlotIndex ThisIndex = Indexes->getInstructionIndex(MI);
860for (auto Slot :slots) {
861if (IsStart) {
862// If a slot is already definitely in use, we don't have to emit
863// a new start marker because there is already a pre-existing
864// one.
865if (!DefinitelyInUse[Slot]) {
866 LiveStarts[Slot].push_back(ThisIndex);
867 DefinitelyInUse[Slot] =true;
868 }
869if (!Starts[Slot].isValid())
870 Starts[Slot] = ThisIndex;
871 }else {
872if (Starts[Slot].isValid()) {
873VNInfo *VNI = Intervals[Slot]->getValNumInfo(0);
874 Intervals[Slot]->addSegment(
875LiveInterval::Segment(Starts[Slot], ThisIndex, VNI));
876 Starts[Slot] =SlotIndex();// Invalidate the start index
877 DefinitelyInUse[Slot] =false;
878 }
879 }
880 }
881 }
882
883// Finish up started segments
884for (unsigned i = 0; i < NumSlots; ++i) {
885if (!Starts[i].isValid())
886continue;
887
888SlotIndex EndIdx = Indexes->getMBBEndIdx(&MBB);
889VNInfo *VNI = Intervals[i]->getValNumInfo(0);
890 Intervals[i]->addSegment(LiveInterval::Segment(Starts[i], EndIdx, VNI));
891 }
892 }
893}
894
895bool StackColoring::removeAllMarkers() {
896unsigned Count = 0;
897for (MachineInstr *MI :Markers) {
898MI->eraseFromParent();
899 Count++;
900 }
901Markers.clear();
902
903LLVM_DEBUG(dbgs() <<"Removed " << Count <<" markers.\n");
904return Count;
905}
906
907void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
908unsigned FixedInstr = 0;
909unsigned FixedMemOp = 0;
910unsigned FixedDbg = 0;
911
912// Remap debug information that refers to stack slots.
913for (auto &VI : MF->getVariableDbgInfo()) {
914if (!VI.Var || !VI.inStackSlot())
915continue;
916intSlot =VI.getStackSlot();
917if (SlotRemap.count(Slot)) {
918LLVM_DEBUG(dbgs() <<"Remapping debug info for ["
919 << cast<DILocalVariable>(VI.Var)->getName() <<"].\n");
920VI.updateStackSlot(SlotRemap[Slot]);
921 FixedDbg++;
922 }
923 }
924
925// Keep a list of *allocas* which need to be remapped.
926DenseMap<const AllocaInst*, const AllocaInst*> Allocas;
927
928// Keep a list of allocas which has been affected by the remap.
929SmallPtrSet<const AllocaInst*, 32> MergedAllocas;
930
931for (const std::pair<int, int> &SI : SlotRemap) {
932constAllocaInst *From = MFI->getObjectAllocation(SI.first);
933constAllocaInst *To = MFI->getObjectAllocation(SI.second);
934assert(To &&From &&"Invalid allocation object");
935 Allocas[From] = To;
936
937// If From is before wo, its possible that there is a use of From between
938// them.
939if (From->comesBefore(To))
940const_cast<AllocaInst *>(To)->moveBefore(
941const_cast<AllocaInst *>(From)->getIterator());
942
943// AA might be used later for instruction scheduling, and we need it to be
944// able to deduce the correct aliasing releationships between pointers
945// derived from the alloca being remapped and the target of that remapping.
946// The only safe way, without directly informing AA about the remapping
947// somehow, is to directly update the IR to reflect the change being made
948// here.
949Instruction *Inst =const_cast<AllocaInst *>(To);
950if (From->getType() != To->getType()) {
951BitCastInst *Cast =newBitCastInst(Inst,From->getType());
952 Cast->insertAfter(Inst->getIterator());
953 Inst = Cast;
954 }
955
956// We keep both slots to maintain AliasAnalysis metadata later.
957 MergedAllocas.insert(From);
958 MergedAllocas.insert(To);
959
960// Transfer the stack protector layout tag, but make sure that SSPLK_AddrOf
961// does not overwrite SSPLK_SmallArray or SSPLK_LargeArray, and make sure
962// that SSPLK_SmallArray does not overwrite SSPLK_LargeArray.
963MachineFrameInfo::SSPLayoutKind FromKind
964 = MFI->getObjectSSPLayout(SI.first);
965MachineFrameInfo::SSPLayoutKind ToKind = MFI->getObjectSSPLayout(SI.second);
966if (FromKind !=MachineFrameInfo::SSPLK_None &&
967 (ToKind ==MachineFrameInfo::SSPLK_None ||
968 (ToKind !=MachineFrameInfo::SSPLK_LargeArray &&
969 FromKind !=MachineFrameInfo::SSPLK_AddrOf)))
970 MFI->setObjectSSPLayout(SI.second, FromKind);
971
972// The new alloca might not be valid in a llvm.dbg.declare for this
973// variable, so poison out the use to make the verifier happy.
974AllocaInst *FromAI =const_cast<AllocaInst *>(From);
975if (FromAI->isUsedByMetadata())
976ValueAsMetadata::handleRAUW(FromAI,PoisonValue::get(FromAI->getType()));
977for (auto &Use : FromAI->uses()) {
978if (BitCastInst *BCI = dyn_cast<BitCastInst>(Use.get()))
979if (BCI->isUsedByMetadata())
980ValueAsMetadata::handleRAUW(BCI,PoisonValue::get(BCI->getType()));
981 }
982
983// Note that this will not replace uses in MMOs (which we'll update below),
984// or anywhere else (which is why we won't delete the original
985// instruction).
986 FromAI->replaceAllUsesWith(Inst);
987 }
988
989// Remap all instructions to the new stack slots.
990 std::vector<std::vector<MachineMemOperand *>> SSRefs(
991 MFI->getObjectIndexEnd());
992for (MachineBasicBlock &BB : *MF)
993for (MachineInstr &I : BB) {
994// Skip lifetime markers. We'll remove them soon.
995if (I.getOpcode() == TargetOpcode::LIFETIME_START ||
996I.getOpcode() == TargetOpcode::LIFETIME_END)
997continue;
998
999// Update the MachineMemOperand to use the new alloca.
1000for (MachineMemOperand *MMO :I.memoperands()) {
1001// We've replaced IR-level uses of the remapped allocas, so we only
1002// need to replace direct uses here.
1003constAllocaInst *AI = dyn_cast_or_null<AllocaInst>(MMO->getValue());
1004if (!AI)
1005continue;
1006
1007if (!Allocas.count(AI))
1008continue;
1009
1010 MMO->setValue(Allocas[AI]);
1011 FixedMemOp++;
1012 }
1013
1014// Update all of the machine instruction operands.
1015for (MachineOperand &MO :I.operands()) {
1016if (!MO.isFI())
1017continue;
1018int FromSlot = MO.getIndex();
1019
1020// Don't touch arguments.
1021if (FromSlot<0)
1022continue;
1023
1024// Only look at mapped slots.
1025if (!SlotRemap.count(FromSlot))
1026continue;
1027
1028// In a debug build, check that the instruction that we are modifying is
1029// inside the expected live range. If the instruction is not inside
1030// the calculated range then it means that the alloca usage moved
1031// outside of the lifetime markers, or that the user has a bug.
1032// NOTE: Alloca address calculations which happen outside the lifetime
1033// zone are okay, despite the fact that we don't have a good way
1034// for validating all of the usages of the calculation.
1035#ifndef NDEBUG
1036bool TouchesMemory =I.mayLoadOrStore();
1037// If we *don't* protect the user from escaped allocas, don't bother
1038// validating the instructions.
1039if (!I.isDebugInstr() && TouchesMemory &&ProtectFromEscapedAllocas) {
1040SlotIndexIndex = Indexes->getInstructionIndex(I);
1041constLiveInterval *Interval = &*Intervals[FromSlot];
1042assert(Interval->find(Index) !=Interval->end() &&
1043"Found instruction usage outside of live range.");
1044 }
1045#endif
1046
1047// Fix the machine instructions.
1048int ToSlot = SlotRemap[FromSlot];
1049 MO.setIndex(ToSlot);
1050 FixedInstr++;
1051 }
1052
1053// We adjust AliasAnalysis information for merged stack slots.
1054SmallVector<MachineMemOperand *, 2> NewMMOs;
1055bool ReplaceMemOps =false;
1056for (MachineMemOperand *MMO :I.memoperands()) {
1057// Collect MachineMemOperands which reference
1058// FixedStackPseudoSourceValues with old frame indices.
1059if (constauto *FSV = dyn_cast_or_null<FixedStackPseudoSourceValue>(
1060 MMO->getPseudoValue())) {
1061int FI = FSV->getFrameIndex();
1062auto To = SlotRemap.find(FI);
1063if (To != SlotRemap.end())
1064 SSRefs[FI].push_back(MMO);
1065 }
1066
1067// If this memory location can be a slot remapped here,
1068// we remove AA information.
1069bool MayHaveConflictingAAMD =false;
1070if (MMO->getAAInfo()) {
1071if (constValue *MMOV = MMO->getValue()) {
1072SmallVector<Value *, 4> Objs;
1073getUnderlyingObjectsForCodeGen(MMOV, Objs);
1074
1075if (Objs.empty())
1076 MayHaveConflictingAAMD =true;
1077else
1078for (Value *V : Objs) {
1079// If this memory location comes from a known stack slot
1080// that is not remapped, we continue checking.
1081// Otherwise, we need to invalidate AA infomation.
1082constAllocaInst *AI = dyn_cast_or_null<AllocaInst>(V);
1083if (AI && MergedAllocas.count(AI)) {
1084 MayHaveConflictingAAMD =true;
1085break;
1086 }
1087 }
1088 }
1089 }
1090if (MayHaveConflictingAAMD) {
1091 NewMMOs.push_back(MF->getMachineMemOperand(MMO,AAMDNodes()));
1092 ReplaceMemOps =true;
1093 }else {
1094 NewMMOs.push_back(MMO);
1095 }
1096 }
1097
1098// If any memory operand is updated, set memory references of
1099// this instruction.
1100if (ReplaceMemOps)
1101I.setMemRefs(*MF, NewMMOs);
1102 }
1103
1104// Rewrite MachineMemOperands that reference old frame indices.
1105for (auto E :enumerate(SSRefs))
1106if (!E.value().empty()) {
1107constPseudoSourceValue *NewSV =
1108 MF->getPSVManager().getFixedStack(SlotRemap.find(E.index())->second);
1109for (MachineMemOperand *Ref : E.value())
1110Ref->setValue(NewSV);
1111 }
1112
1113// Update the location of C++ catch objects for the MSVC personality routine.
1114if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
1115for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
1116for (WinEHHandlerType &H : TBME.HandlerArray)
1117if (H.CatchObj.FrameIndex != std::numeric_limits<int>::max() &&
1118 SlotRemap.count(H.CatchObj.FrameIndex))
1119H.CatchObj.FrameIndex = SlotRemap[H.CatchObj.FrameIndex];
1120
1121LLVM_DEBUG(dbgs() <<"Fixed " << FixedMemOp <<" machine memory operands.\n");
1122LLVM_DEBUG(dbgs() <<"Fixed " << FixedDbg <<" debug locations.\n");
1123LLVM_DEBUG(dbgs() <<"Fixed " << FixedInstr <<" machine instructions.\n");
1124 (void) FixedMemOp;
1125 (void) FixedDbg;
1126 (void) FixedInstr;
1127}
1128
1129void StackColoring::removeInvalidSlotRanges() {
1130for (MachineBasicBlock &BB : *MF)
1131for (MachineInstr &I : BB) {
1132if (I.getOpcode() == TargetOpcode::LIFETIME_START ||
1133I.getOpcode() == TargetOpcode::LIFETIME_END ||I.isDebugInstr())
1134continue;
1135
1136// Some intervals are suspicious! In some cases we find address
1137// calculations outside of the lifetime zone, but not actual memory
1138// read or write. Memory accesses outside of the lifetime zone are a clear
1139// violation, but address calculations are okay. This can happen when
1140// GEPs are hoisted outside of the lifetime zone.
1141// So, in here we only check instructions which can read or write memory.
1142if (!I.mayLoad() && !I.mayStore())
1143continue;
1144
1145// Check all of the machine operands.
1146for (constMachineOperand &MO :I.operands()) {
1147if (!MO.isFI())
1148continue;
1149
1150intSlot = MO.getIndex();
1151
1152if (Slot<0)
1153continue;
1154
1155if (Intervals[Slot]->empty())
1156continue;
1157
1158// Check that the used slot is inside the calculated lifetime range.
1159// If it is not, warn about it and invalidate the range.
1160LiveInterval *Interval = &*Intervals[Slot];
1161SlotIndexIndex = Indexes->getInstructionIndex(I);
1162if (Interval->find(Index) ==Interval->end()) {
1163Interval->clear();
1164LLVM_DEBUG(dbgs() <<"Invalidating range #" << Slot <<"\n");
1165 EscapedAllocas++;
1166 }
1167 }
1168 }
1169}
1170
1171void StackColoring::expungeSlotMap(DenseMap<int, int> &SlotRemap,
1172unsigned NumSlots) {
1173// Expunge slot remap map.
1174for (unsigned i=0; i < NumSlots; ++i) {
1175// If we are remapping i
1176if (SlotRemap.count(i)) {
1177intTarget = SlotRemap[i];
1178// As long as our target is mapped to something else, follow it.
1179while (SlotRemap.count(Target)) {
1180Target = SlotRemap[Target];
1181 SlotRemap[i] =Target;
1182 }
1183 }
1184 }
1185}
1186
1187bool StackColoringLegacy::runOnMachineFunction(MachineFunction &MF) {
1188if (skipFunction(MF.getFunction()))
1189returnfalse;
1190
1191 StackColoringSC(&getAnalysis<SlotIndexesWrapperPass>().getSI());
1192returnSC.run(MF);
1193}
1194
1195PreservedAnalysesStackColoringPass::run(MachineFunction &MF,
1196MachineFunctionAnalysisManager &MFAM) {
1197 StackColoring SC(&MFAM.getResult<SlotIndexesAnalysis>(MF));
1198if (SC.run(MF))
1199returnPreservedAnalyses::none();
1200returnPreservedAnalyses::all();
1201}
1202
1203bool StackColoring::run(MachineFunction &Func) {
1204LLVM_DEBUG(dbgs() <<"********** Stack Coloring **********\n"
1205 <<"********** Function: " << Func.getName() <<'\n');
1206 MF = &Func;
1207 MFI = &MF->getFrameInfo();
1208 BlockLiveness.clear();
1209 BasicBlocks.clear();
1210 BasicBlockNumbering.clear();
1211Markers.clear();
1212 Intervals.clear();
1213 LiveStarts.clear();
1214 VNInfoAllocator.Reset();
1215
1216unsigned NumSlots = MFI->getObjectIndexEnd();
1217
1218// If there are no stack slots then there are no markers to remove.
1219if (!NumSlots)
1220returnfalse;
1221
1222SmallVector<int, 8> SortedSlots;
1223 SortedSlots.reserve(NumSlots);
1224 Intervals.reserve(NumSlots);
1225 LiveStarts.resize(NumSlots);
1226
1227unsigned NumMarkers = collectMarkers(NumSlots);
1228
1229unsigned TotalSize = 0;
1230LLVM_DEBUG(dbgs() <<"Found " << NumMarkers <<" markers and " << NumSlots
1231 <<" slots\n");
1232LLVM_DEBUG(dbgs() <<"Slot structure:\n");
1233
1234for (int i=0; i < MFI->getObjectIndexEnd(); ++i) {
1235LLVM_DEBUG(dbgs() <<"Slot #" << i <<" - " << MFI->getObjectSize(i)
1236 <<" bytes.\n");
1237 TotalSize += MFI->getObjectSize(i);
1238 }
1239
1240LLVM_DEBUG(dbgs() <<"Total Stack size: " << TotalSize <<" bytes\n\n");
1241
1242// Don't continue because there are not enough lifetime markers, or the
1243// stack is too small, or we are told not to optimize the slots.
1244if (NumMarkers < 2 || TotalSize < 16 ||DisableColoring) {
1245LLVM_DEBUG(dbgs() <<"Will not try to merge slots.\n");
1246return removeAllMarkers();
1247 }
1248
1249for (unsigned i=0; i < NumSlots; ++i) {
1250 std::unique_ptr<LiveInterval> LI(newLiveInterval(i, 0));
1251 LI->getNextValue(Indexes->getZeroIndex(), VNInfoAllocator);
1252 Intervals.push_back(std::move(LI));
1253 SortedSlots.push_back(i);
1254 }
1255
1256// Calculate the liveness of each block.
1257 calculateLocalLiveness();
1258LLVM_DEBUG(dbgs() <<"Dataflow iterations: " << NumIterations <<"\n");
1259LLVM_DEBUG(dump());
1260
1261// Propagate the liveness information.
1262 calculateLiveIntervals(NumSlots);
1263LLVM_DEBUG(dumpIntervals());
1264
1265// Search for allocas which are used outside of the declared lifetime
1266// markers.
1267if (ProtectFromEscapedAllocas)
1268 removeInvalidSlotRanges();
1269
1270// Maps old slots to new slots.
1271DenseMap<int, int> SlotRemap;
1272unsigned RemovedSlots = 0;
1273unsigned ReducedSize = 0;
1274
1275// Do not bother looking at empty intervals.
1276for (unsignedI = 0;I < NumSlots; ++I) {
1277if (Intervals[SortedSlots[I]]->empty())
1278 SortedSlots[I] = -1;
1279 }
1280
1281// This is a simple greedy algorithm for merging allocas. First, sort the
1282// slots, placing the largest slots first. Next, perform an n^2 scan and look
1283// for disjoint slots. When you find disjoint slots, merge the smaller one
1284// into the bigger one and update the live interval. Remove the small alloca
1285// and continue.
1286
1287// Sort the slots according to their size. Place unused slots at the end.
1288// Use stable sort to guarantee deterministic code generation.
1289llvm::stable_sort(SortedSlots, [this](int LHS,int RHS) {
1290// We use -1 to denote a uninteresting slot. Place these slots at the end.
1291if (LHS == -1)
1292returnfalse;
1293if (RHS == -1)
1294returntrue;
1295// Sort according to size.
1296return MFI->getObjectSize(LHS) > MFI->getObjectSize(RHS);
1297 });
1298
1299for (auto &s : LiveStarts)
1300llvm::sort(s);
1301
1302bool Changed =true;
1303while (Changed) {
1304 Changed =false;
1305for (unsignedI = 0;I < NumSlots; ++I) {
1306if (SortedSlots[I] == -1)
1307continue;
1308
1309for (unsigned J=I+1; J < NumSlots; ++J) {
1310if (SortedSlots[J] == -1)
1311continue;
1312
1313int FirstSlot = SortedSlots[I];
1314int SecondSlot = SortedSlots[J];
1315
1316// Objects with different stack IDs cannot be merged.
1317if (MFI->getStackID(FirstSlot) != MFI->getStackID(SecondSlot))
1318continue;
1319
1320LiveInterval *First = &*Intervals[FirstSlot];
1321LiveInterval *Second = &*Intervals[SecondSlot];
1322auto &FirstS = LiveStarts[FirstSlot];
1323auto &SecondS = LiveStarts[SecondSlot];
1324assert(!First->empty() && !Second->empty() &&"Found an empty range");
1325
1326// Merge disjoint slots. This is a little bit tricky - see the
1327// Implementation Notes section for an explanation.
1328if (!First->isLiveAtIndexes(SecondS) &&
1329 !Second->isLiveAtIndexes(FirstS)) {
1330 Changed =true;
1331First->MergeSegmentsInAsValue(*Second,First->getValNumInfo(0));
1332
1333int OldSize = FirstS.size();
1334 FirstS.append(SecondS.begin(), SecondS.end());
1335auto Mid = FirstS.begin() + OldSize;
1336 std::inplace_merge(FirstS.begin(), Mid, FirstS.end());
1337
1338 SlotRemap[SecondSlot] = FirstSlot;
1339 SortedSlots[J] = -1;
1340LLVM_DEBUG(dbgs() <<"Merging #" << FirstSlot <<" and slots #"
1341 << SecondSlot <<" together.\n");
1342Align MaxAlignment = std::max(MFI->getObjectAlign(FirstSlot),
1343 MFI->getObjectAlign(SecondSlot));
1344
1345assert(MFI->getObjectSize(FirstSlot) >=
1346 MFI->getObjectSize(SecondSlot) &&
1347"Merging a small object into a larger one");
1348
1349 RemovedSlots+=1;
1350 ReducedSize += MFI->getObjectSize(SecondSlot);
1351 MFI->setObjectAlignment(FirstSlot, MaxAlignment);
1352 MFI->RemoveStackObject(SecondSlot);
1353 }
1354 }
1355 }
1356 }// While changed.
1357
1358// Record statistics.
1359 StackSpaceSaved += ReducedSize;
1360 StackSlotMerged += RemovedSlots;
1361LLVM_DEBUG(dbgs() <<"Merge " << RemovedSlots <<" slots. Saved "
1362 << ReducedSize <<" bytes\n");
1363
1364// Scan the entire function and update all machine operands that use frame
1365// indices to use the remapped frame index.
1366if (!SlotRemap.empty()) {
1367 expungeSlotMap(SlotRemap, NumSlots);
1368 remapInstructions(SlotRemap);
1369 }
1370
1371return removeAllMarkers();
1372}
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
BitVector.h
This file implements the BitVector class.
From
BlockVerifier::State From
Definition:BlockVerifier.cpp:57
Casting.h
Passes.h
CommandLine.h
Compiler.h
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition:Compiler.h:622
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DebugInfoMetadata.h
Debug.h
LLVM_DEBUG
#define LLVM_DEBUG(...)
Definition:Debug.h:106
DenseMap.h
This file defines the DenseMap class.
DepthFirstIterator.h
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
End
bool End
Definition:ELF_riscv.cpp:480
MI
IRTranslator LLVM IR MI
Definition:IRTranslator.cpp:112
Use.h
This defines the Use class.
Value.h
InitializePasses.h
Instructions.h
LiveInterval.h
I
#define I(x, y, z)
Definition:MD5.cpp:58
H
#define H(x, y, z)
Definition:MD5.cpp:57
MachineBasicBlock.h
MachineFrameInfo.h
MachineFunctionPass.h
MachineFunction.h
MachineInstr.h
MachineMemOperand.h
MachineOperand.h
Interval
std::pair< uint64_t, uint64_t > Interval
Definition:MappedBlockStream.cpp:36
Metadata.h
This file contains the declarations for metadata subclasses.
INITIALIZE_PASS_DEPENDENCY
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition:PassSupport.h:55
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition:PassSupport.h:57
INITIALIZE_PASS_BEGIN
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition:PassSupport.h:52
Pass.h
PseudoSourceValueManager.h
Merge
R600 Clause Merge
Definition:R600ClauseMergePass.cpp:70
Markers
R600 Emit Clause Markers
Definition:R600EmitClauseMarkers.cpp:328
isValid
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Definition:RustDemangle.cpp:181
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SlotIndexes.h
SmallPtrSet.h
This file defines the SmallPtrSet class.
SmallVector.h
This file defines the SmallVector class.
getStartOrEndSlot
static int getStartOrEndSlot(const MachineInstr &MI)
Definition:StackColoring.cpp:570
DisableColoring
static cl::opt< bool > DisableColoring("no-stack-coloring", cl::init(false), cl::Hidden, cl::desc("Disable stack coloring"))
ProtectFromEscapedAllocas
static cl::opt< bool > ProtectFromEscapedAllocas("protect-from-escaped-allocas", cl::init(false), cl::Hidden, cl::desc("Do not optimize lifetime zones that " "are broken"))
The user may write code that uses allocas outside of the declared lifetime zone.
LifetimeStartOnFirstUse
static cl::opt< bool > LifetimeStartOnFirstUse("stackcoloring-lifetime-start-on-first-use", cl::init(true), cl::Hidden, cl::desc("Treat stack lifetimes as starting on first use, not on START marker."))
Enable enhanced dataflow scheme for lifetime analysis (treat first use of stack slot as start of slot...
DEBUG_TYPE
#define DEBUG_TYPE
Definition:StackColoring.cpp:66
slots
Merge disjoint stack slots
Definition:StackColoring.cpp:527
StackColoring.h
Statistic.h
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
STATISTIC
#define STATISTIC(VARNAME, DESC)
Definition:Statistic.h:166
TargetOpcodes.h
ValueTracking.h
WinEHFuncInfo.h
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition:Instructions.h:63
llvm::AllocaInst::getType
PointerType * getType() const
Overload to return most specific pointer type.
Definition:Instructions.h:99
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition:PassManager.h:253
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition:PassManager.h:410
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition:PassAnalysisSupport.h:47
llvm::BitCastInst
This class represents a no-op cast from one type to another.
Definition:Instructions.h:4894
llvm::BitVector
Definition:BitVector.h:82
llvm::BitVector::test
bool test(unsigned Idx) const
Definition:BitVector.h:461
llvm::BitVector::reset
BitVector & reset()
Definition:BitVector.h:392
llvm::BitVector::resize
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
Definition:BitVector.h:341
llvm::BitVector::clear
void clear()
clear - Removes all bits from the bitvector.
Definition:BitVector.h:335
llvm::BitVector::set
BitVector & set()
Definition:BitVector.h:351
llvm::BitVector::size
size_type size() const
size - Returns the number of bits in this bitvector.
Definition:BitVector.h:159
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition:Allocator.h:66
llvm::BumpPtrAllocatorImpl::Reset
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
Definition:Allocator.h:123
llvm::DenseMapBase::empty
bool empty() const
Definition:DenseMap.h:98
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition:DenseMap.h:152
llvm::DenseMapBase::clear
void clear()
Definition:DenseMap.h:110
llvm::DenseMap
Definition:DenseMap.h:727
llvm::Instruction
Definition:Instruction.h:68
llvm::Instruction::insertAfter
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
Definition:Instruction.cpp:111
llvm::LiveInterval
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition:LiveInterval.h:687
llvm::LiveRange::isLiveAtIndexes
bool isLiveAtIndexes(ArrayRef< SlotIndex > Slots) const
Definition:LiveInterval.cpp:803
llvm::LiveRange::empty
bool empty() const
Definition:LiveInterval.h:382
llvm::MachineBasicBlock
Definition:MachineBasicBlock.h:125
llvm::MachineBasicBlock::getNumber
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Definition:MachineBasicBlock.h:1217
llvm::MachineBasicBlock::predecessors
iterator_range< pred_iterator > predecessors()
Definition:MachineBasicBlock.h:438
llvm::MachineBasicBlock::getName
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
Definition:MachineBasicBlock.cpp:326
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition:MachineFrameInfo.h:106
llvm::MachineFrameInfo::getObjectSSPLayout
SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const
Definition:MachineFrameInfo.h:570
llvm::MachineFrameInfo::getObjectAllocation
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
Definition:MachineFrameInfo.h:512
llvm::MachineFrameInfo::SSPLayoutKind
SSPLayoutKind
Stack Smashing Protection (SSP) rules require that vulnerable stack allocations are located close the...
Definition:MachineFrameInfo.h:110
llvm::MachineFrameInfo::SSPLK_LargeArray
@ SSPLK_LargeArray
Array or nested array >= SSP-buffer-size.
Definition:MachineFrameInfo.h:113
llvm::MachineFrameInfo::SSPLK_AddrOf
@ SSPLK_AddrOf
The address of this allocation is exposed and triggered protection.
Definition:MachineFrameInfo.h:117
llvm::MachineFrameInfo::SSPLK_None
@ SSPLK_None
Did not trigger a stack protector.
Definition:MachineFrameInfo.h:111
llvm::MachineFrameInfo::setObjectSSPLayout
void setObjectSSPLayout(int ObjectIdx, SSPLayoutKind Kind)
Definition:MachineFrameInfo.h:576
llvm::MachineFrameInfo::getObjectAlign
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
Definition:MachineFrameInfo.h:486
llvm::MachineFrameInfo::getObjectSize
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Definition:MachineFrameInfo.h:472
llvm::MachineFrameInfo::RemoveStackObject
void RemoveStackObject(int ObjectIdx)
Remove or mark dead a statically sized stack object.
Definition:MachineFrameInfo.h:795
llvm::MachineFrameInfo::getObjectIndexEnd
int getObjectIndexEnd() const
Return one past the maximum frame object index.
Definition:MachineFrameInfo.h:412
llvm::MachineFrameInfo::getStackID
uint8_t getStackID(int ObjectIdx) const
Definition:MachineFrameInfo.h:750
llvm::MachineFrameInfo::setObjectAlignment
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
Definition:MachineFrameInfo.h:499
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition:MachineFunctionPass.h:30
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition:MachineFunctionPass.cpp:169
llvm::MachineFunctionPass::runOnMachineFunction
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::getWinEHFuncInfo
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
Definition:MachineFunction.h:777
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition:MachineFunction.h:749
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition:MachineFunction.h:704
llvm::MachineInstr
Representation of each machine instruction.
Definition:MachineInstr.h:71
llvm::MachineMemOperand
A description of a memory reference used in the backend.
Definition:MachineMemOperand.h:129
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition:MachineOperand.h:48
llvm::MachineOperand::getIndex
int getIndex() const
Definition:MachineOperand.h:576
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition:Constants.cpp:1878
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition:Analysis.h:111
llvm::PreservedAnalyses::none
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition:Analysis.h:114
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition:Analysis.h:117
llvm::PseudoSourceValue
Special value supplied for machine level alias analysis.
Definition:PseudoSourceValue.h:31
llvm::SlotIndex
SlotIndex - An opaque wrapper around machine indexes.
Definition:SlotIndexes.h:65
llvm::SlotIndex::print
void print(raw_ostream &os) const
Print this index to the given raw_ostream.
Definition:SlotIndexes.cpp:277
llvm::SlotIndexesAnalysis
Definition:SlotIndexes.h:644
llvm::SlotIndexesWrapperPass
Definition:SlotIndexes.h:663
llvm::SlotIndexes
SlotIndexes pass.
Definition:SlotIndexes.h:297
llvm::SlotIndexes::getMBBEndIdx
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
Definition:SlotIndexes.h:470
llvm::SlotIndexes::getInstructionIndex
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
Definition:SlotIndexes.h:379
llvm::SlotIndexes::getMBBStartIdx
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
Definition:SlotIndexes.h:460
llvm::SlotIndexes::getZeroIndex
SlotIndex getZeroIndex()
Returns the zero index for this analysis.
Definition:SlotIndexes.h:362
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition:SmallPtrSet.h:452
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition:SmallPtrSet.h:384
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition:SmallVector.h:663
llvm::SmallVectorImpl::clear
void clear()
Definition:SmallVector.h:610
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition:SmallVector.h:638
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StackColoringPass::run
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition:StackColoring.cpp:1195
llvm::Target
Target - Wrapper for Target specific information.
Definition:TargetRegistry.h:144
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition:Use.h:43
llvm::Use::get
Value * get() const
Definition:Use.h:66
llvm::VNInfo
VNInfo - Value Number Information.
Definition:LiveInterval.h:53
llvm::ValueAsMetadata::handleRAUW
static void handleRAUW(Value *From, Value *To)
Definition:Metadata.cpp:544
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition:Value.cpp:534
llvm::Value::isUsedByMetadata
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
Definition:Value.h:557
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition:Value.h:376
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition:Value.cpp:309
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition:ilist_node.h:132
unsigned
false
Definition:StackSlotColoring.cpp:193
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition:CallingConv.h:24
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition:PPCISelLowering.h:429
llvm::SIEncodingFamily::VI
@ VI
Definition:SIDefines.h:37
llvm::SIEncodingFamily::SI
@ SI
Definition:SIDefines.h:36
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm::dwarf::Index
Index
Definition:Dwarf.h:882
llvm::dxil::PointerTypeAnalysis::run
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Definition:PointerTypeAnalysis.cpp:191
llvm::pdb::PDB_LocType::Slot
@ Slot
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::dump
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Definition:SparseBitVector.h:877
llvm::stable_sort
void stable_sort(R &&Range)
Definition:STLExtras.h:2037
llvm::enumerate
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition:STLExtras.h:2448
llvm::getUnderlyingObjectsForCodeGen
bool getUnderlyingObjectsForCodeGen(const Value *V, SmallVectorImpl< Value * > &Objects)
This is a wrapper around getUnderlyingObjects and adds support for basic ptrtoint+arithmetic+inttoptr...
Definition:ValueTracking.cpp:6930
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::ModRefInfo::Ref
@ Ref
The access may reference the value stored in memory.
llvm::IRMemLocation::First
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
llvm::StackColoringLegacyID
char & StackColoringLegacyID
StackSlotColoring - This pass performs stack coloring and merging.
Definition:StackColoring.cpp:521
llvm::depth_first
iterator_range< df_iterator< T > > depth_first(const T &G)
Definition:DepthFirstIterator.h:233
llvm::printMBBReference
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Definition:MachineBasicBlock.cpp:122
raw_ostream.h
llvm::AAMDNodes
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition:Metadata.h:764
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::LiveRange::Segment
This represents a simple continuous liveness interval for a value.
Definition:LiveInterval.h:162
llvm::WinEHFuncInfo
Definition:WinEHFuncInfo.h:90
llvm::WinEHHandlerType
Definition:WinEHFuncInfo.h:60
llvm::WinEHTryBlockMapEntry
Definition:WinEHFuncInfo.h:72
llvm::WinEHTryBlockMapEntry::HandlerArray
SmallVector< WinEHHandlerType, 1 > HandlerArray
Definition:WinEHFuncInfo.h:76
llvm::cl::desc
Definition:CommandLine.h:409

Generated on Fri Jul 18 2025 11:03:18 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp