1 //===- ShrinkWrap.cpp - Compute safe point for prolog/epilog insertion ----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass looks for safe point where the prologue and epilogue can be
11 // inserted.
12 // The safe point for the prologue (resp. epilogue) is called Save
13 // (resp. Restore).
14 // A point is safe for prologue (resp. epilogue) if and only if
15 // it 1) dominates (resp. post-dominates) all the frame related operations and
16 // between 2) two executions of the Save (resp. Restore) point there is an
17 // execution of the Restore (resp. Save) point.
18 //
19 // For instance, the following points are safe:
20 // for (int i = 0; i < 10; ++i) {
21 //   Save
22 //   ...
23 //   Restore
24 // }
25 // Indeed, the execution looks like Save -> Restore -> Save -> Restore ...
26 // And the following points are not:
27 // for (int i = 0; i < 10; ++i) {
28 //   Save
29 //   ...
30 // }
31 // for (int i = 0; i < 10; ++i) {
32 //   ...
33 //   Restore
34 // }
35 // Indeed, the execution looks like Save -> Save -> ... -> Restore -> Restore.
36 //
37 // This pass also ensures that the safe points are 3) cheaper than the regular
38 // entry and exits blocks.
39 //
40 // Property #1 is ensured via the use of MachineDominatorTree and
41 // MachinePostDominatorTree.
42 // Property #2 is ensured via property #1 and MachineLoopInfo, i.e., both
43 // points must be in the same loop.
44 // Property #3 is ensured via the MachineBlockFrequencyInfo.
45 //
46 // If this pass found points matching all these properties, then
47 // MachineFrameInfo is updated with this information.
48 //
49 //===----------------------------------------------------------------------===//
50 
51 #include "llvm/ADT/BitVector.h"
52 #include "llvm/ADT/PostOrderIterator.h"
53 #include "llvm/ADT/SetVector.h"
54 #include "llvm/ADT/SmallVector.h"
55 #include "llvm/ADT/Statistic.h"
56 #include "llvm/Analysis/CFG.h"
57 #include "llvm/CodeGen/MachineBasicBlock.h"
58 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
59 #include "llvm/CodeGen/MachineDominators.h"
60 #include "llvm/CodeGen/MachineFrameInfo.h"
61 #include "llvm/CodeGen/MachineFunction.h"
62 #include "llvm/CodeGen/MachineFunctionPass.h"
63 #include "llvm/CodeGen/MachineInstr.h"
64 #include "llvm/CodeGen/MachineLoopInfo.h"
65 #include "llvm/CodeGen/MachineOperand.h"
66 #include "llvm/CodeGen/MachinePostDominators.h"
67 #include "llvm/CodeGen/RegisterClassInfo.h"
68 #include "llvm/CodeGen/RegisterScavenging.h"
69 #include "llvm/CodeGen/TargetFrameLowering.h"
70 #include "llvm/CodeGen/TargetInstrInfo.h"
71 #include "llvm/CodeGen/TargetLowering.h"
72 #include "llvm/CodeGen/TargetRegisterInfo.h"
73 #include "llvm/CodeGen/TargetSubtargetInfo.h"
74 #include "llvm/IR/Attributes.h"
75 #include "llvm/IR/Function.h"
76 #include "llvm/MC/MCAsmInfo.h"
77 #include "llvm/Pass.h"
78 #include "llvm/Support/CommandLine.h"
79 #include "llvm/Support/Debug.h"
80 #include "llvm/Support/ErrorHandling.h"
81 #include "llvm/Support/raw_ostream.h"
82 #include "llvm/Target/TargetMachine.h"
83 #include <cassert>
84 #include <cstdint>
85 #include <memory>
86 
87 using namespace llvm;
88 
89 #define DEBUG_TYPE "shrink-wrap"
90 
91 STATISTIC(NumFunc, "Number of functions");
92 STATISTIC(NumCandidates, "Number of shrink-wrapping candidates");
93 STATISTIC(NumCandidatesDropped,
94           "Number of shrink-wrapping candidates dropped because of frequency");
95 
96 static cl::opt<cl::boolOrDefault>
97 EnableShrinkWrapOpt("enable-shrink-wrap", cl::Hidden,
98                     cl::desc("enable the shrink-wrapping pass"));
99 
100 namespace {
101 
102 /// Class to determine where the safe point to insert the
103 /// prologue and epilogue are.
104 /// Unlike the paper from Fred C. Chow, PLDI'88, that introduces the
105 /// shrink-wrapping term for prologue/epilogue placement, this pass
106 /// does not rely on expensive data-flow analysis. Instead we use the
107 /// dominance properties and loop information to decide which point
108 /// are safe for such insertion.
109 class ShrinkWrap : public MachineFunctionPass {
110   /// Hold callee-saved information.
111   RegisterClassInfo RCI;
112   MachineDominatorTree *MDT;
113   MachinePostDominatorTree *MPDT;
114 
115   /// Current safe point found for the prologue.
116   /// The prologue will be inserted before the first instruction
117   /// in this basic block.
118   MachineBasicBlock *Save;
119 
120   /// Current safe point found for the epilogue.
121   /// The epilogue will be inserted before the first terminator instruction
122   /// in this basic block.
123   MachineBasicBlock *Restore;
124 
125   /// Hold the information of the basic block frequency.
126   /// Use to check the profitability of the new points.
127   MachineBlockFrequencyInfo *MBFI;
128 
129   /// Hold the loop information. Used to determine if Save and Restore
130   /// are in the same loop.
131   MachineLoopInfo *MLI;
132 
133   /// Frequency of the Entry block.
134   uint64_t EntryFreq;
135 
136   /// Current opcode for frame setup.
137   unsigned FrameSetupOpcode;
138 
139   /// Current opcode for frame destroy.
140   unsigned FrameDestroyOpcode;
141 
142   /// Stack pointer register, used by llvm.{savestack,restorestack}
143   unsigned SP;
144 
145   /// Entry block.
146   const MachineBasicBlock *Entry;
147 
148   using SetOfRegs = SmallSetVector<unsigned, 16>;
149 
150   /// Registers that need to be saved for the current function.
151   mutable SetOfRegs CurrentCSRs;
152 
153   /// Current MachineFunction.
154   MachineFunction *MachineFunc;
155 
156   /// Check if \p MI uses or defines a callee-saved register or
157   /// a frame index. If this is the case, this means \p MI must happen
158   /// after Save and before Restore.
159   bool useOrDefCSROrFI(const MachineInstr &MI, RegScavenger *RS) const;
160 
161   const SetOfRegs &getCurrentCSRs(RegScavenger *RS) const {
162     if (CurrentCSRs.empty()) {
163       BitVector SavedRegs;
164       const TargetFrameLowering *TFI =
165           MachineFunc->getSubtarget().getFrameLowering();
166 
167       TFI->determineCalleeSaves(*MachineFunc, SavedRegs, RS);
168 
169       for (int Reg = SavedRegs.find_first(); Reg != -1;
170            Reg = SavedRegs.find_next(Reg))
171         CurrentCSRs.insert((unsigned)Reg);
172     }
173     return CurrentCSRs;
174   }
175 
176   /// Update the Save and Restore points such that \p MBB is in
177   /// the region that is dominated by Save and post-dominated by Restore
178   /// and Save and Restore still match the safe point definition.
179   /// Such point may not exist and Save and/or Restore may be null after
180   /// this call.
181   void updateSaveRestorePoints(MachineBasicBlock &MBB, RegScavenger *RS);
182 
183   /// Initialize the pass for \p MF.
184   void init(MachineFunction &MF) {
185     RCI.runOnMachineFunction(MF);
186     MDT = &getAnalysis<MachineDominatorTree>();
187     MPDT = &getAnalysis<MachinePostDominatorTree>();
188     Save = nullptr;
189     Restore = nullptr;
190     MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
191     MLI = &getAnalysis<MachineLoopInfo>();
192     EntryFreq = MBFI->getEntryFreq();
193     const TargetSubtargetInfo &Subtarget = MF.getSubtarget();
194     const TargetInstrInfo &TII = *Subtarget.getInstrInfo();
195     FrameSetupOpcode = TII.getCallFrameSetupOpcode();
196     FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
197     SP = Subtarget.getTargetLowering()->getStackPointerRegisterToSaveRestore();
198     Entry = &MF.front();
199     CurrentCSRs.clear();
200     MachineFunc = &MF;
201 
202     ++NumFunc;
203   }
204 
205   /// Check whether or not Save and Restore points are still interesting for
206   /// shrink-wrapping.
207   bool ArePointsInteresting() const { return Save != Entry && Save && Restore; }
208 
209   /// Check if shrink wrapping is enabled for this target and function.
210   static bool isShrinkWrapEnabled(const MachineFunction &MF);
211 
212 public:
213   static char ID;
214 
215   ShrinkWrap() : MachineFunctionPass(ID) {
216     initializeShrinkWrapPass(*PassRegistry::getPassRegistry());
217   }
218 
219   void getAnalysisUsage(AnalysisUsage &AU) const override {
220     AU.setPreservesAll();
221     AU.addRequired<MachineBlockFrequencyInfo>();
222     AU.addRequired<MachineDominatorTree>();
223     AU.addRequired<MachinePostDominatorTree>();
224     AU.addRequired<MachineLoopInfo>();
225     MachineFunctionPass::getAnalysisUsage(AU);
226   }
227 
228   MachineFunctionProperties getRequiredProperties() const override {
229     return MachineFunctionProperties().set(
230       MachineFunctionProperties::Property::NoVRegs);
231   }
232 
233   StringRef getPassName() const override { return "Shrink Wrapping analysis"; }
234 
235   /// Perform the shrink-wrapping analysis and update
236   /// the MachineFrameInfo attached to \p MF with the results.
237   bool runOnMachineFunction(MachineFunction &MF) override;
238 };
239 
240 } // end anonymous namespace
241 
242 char ShrinkWrap::ID = 0;
243 
244 char &llvm::ShrinkWrapID = ShrinkWrap::ID;
245 
246 INITIALIZE_PASS_BEGIN(ShrinkWrap, DEBUG_TYPE, "Shrink Wrap Pass", false, false)
247 INITIALIZE_PASS_DEPENDENCY(MachineBlockFrequencyInfo)
248 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
249 INITIALIZE_PASS_DEPENDENCY(MachinePostDominatorTree)
250 INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
251 INITIALIZE_PASS_END(ShrinkWrap, DEBUG_TYPE, "Shrink Wrap Pass", false, false)
252 
253 bool ShrinkWrap::useOrDefCSROrFI(const MachineInstr &MI,
254                                  RegScavenger *RS) const {
255   if (MI.getOpcode() == FrameSetupOpcode ||
256       MI.getOpcode() == FrameDestroyOpcode) {
257     LLVM_DEBUG(dbgs() << "Frame instruction: " << MI << '\n');
258     return true;
259   }
260   for (const MachineOperand &MO : MI.operands()) {
261     bool UseOrDefCSR = false;
262     if (MO.isReg()) {
263       // Ignore instructions like DBG_VALUE which don't read/def the register.
264       if (!MO.isDef() && !MO.readsReg())
265         continue;
266       unsigned PhysReg = MO.getReg();
267       if (!PhysReg)
268         continue;
269       assert(TargetRegisterInfo::isPhysicalRegister(PhysReg) &&
270              "Unallocated register?!");
271       // The stack pointer is not normally described as a callee-saved register
272       // in calling convention definitions, so we need to watch for it
273       // separately. An SP mentioned by a call instruction, we can ignore,
274       // though, as it's harmless and we do not want to effectively disable tail
275       // calls by forcing the restore point to post-dominate them.
276       UseOrDefCSR = (!MI.isCall() && PhysReg == SP) ||
277                     RCI.getLastCalleeSavedAlias(PhysReg);
278     } else if (MO.isRegMask()) {
279       // Check if this regmask clobbers any of the CSRs.
280       for (unsigned Reg : getCurrentCSRs(RS)) {
281         if (MO.clobbersPhysReg(Reg)) {
282           UseOrDefCSR = true;
283           break;
284         }
285       }
286     }
287     // Skip FrameIndex operands in DBG_VALUE instructions.
288     if (UseOrDefCSR || (MO.isFI() && !MI.isDebugValue())) {
289       LLVM_DEBUG(dbgs() << "Use or define CSR(" << UseOrDefCSR << ") or FI("
290                         << MO.isFI() << "): " << MI << '\n');
291       return true;
292     }
293   }
294   return false;
295 }
296 
297 /// Helper function to find the immediate (post) dominator.
298 template <typename ListOfBBs, typename DominanceAnalysis>
299 static MachineBasicBlock *FindIDom(MachineBasicBlock &Block, ListOfBBs BBs,
300                                    DominanceAnalysis &Dom) {
301   MachineBasicBlock *IDom = &Block;
302   for (MachineBasicBlock *BB : BBs) {
303     IDom = Dom.findNearestCommonDominator(IDom, BB);
304     if (!IDom)
305       break;
306   }
307   if (IDom == &Block)
308     return nullptr;
309   return IDom;
310 }
311 
312 void ShrinkWrap::updateSaveRestorePoints(MachineBasicBlock &MBB,
313                                          RegScavenger *RS) {
314   // Get rid of the easy cases first.
315   if (!Save)
316     Save = &MBB;
317   else
318     Save = MDT->findNearestCommonDominator(Save, &MBB);
319 
320   if (!Save) {
321     LLVM_DEBUG(dbgs() << "Found a block that is not reachable from Entry\n");
322     return;
323   }
324 
325   if (!Restore)
326     Restore = &MBB;
327   else if (MPDT->getNode(&MBB)) // If the block is not in the post dom tree, it
328                                 // means the block never returns. If that's the
329                                 // case, we don't want to call
330                                 // `findNearestCommonDominator`, which will
331                                 // return `Restore`.
332     Restore = MPDT->findNearestCommonDominator(Restore, &MBB);
333   else
334     Restore = nullptr; // Abort, we can't find a restore point in this case.
335 
336   // Make sure we would be able to insert the restore code before the
337   // terminator.
338   if (Restore == &MBB) {
339     for (const MachineInstr &Terminator : MBB.terminators()) {
340       if (!useOrDefCSROrFI(Terminator, RS))
341         continue;
342       // One of the terminator needs to happen before the restore point.
343       if (MBB.succ_empty()) {
344         Restore = nullptr; // Abort, we can't find a restore point in this case.
345         break;
346       }
347       // Look for a restore point that post-dominates all the successors.
348       // The immediate post-dominator is what we are looking for.
349       Restore = FindIDom<>(*Restore, Restore->successors(), *MPDT);
350       break;
351     }
352   }
353 
354   if (!Restore) {
355     LLVM_DEBUG(
356         dbgs() << "Restore point needs to be spanned on several blocks\n");
357     return;
358   }
359 
360   // Make sure Save and Restore are suitable for shrink-wrapping:
361   // 1. all path from Save needs to lead to Restore before exiting.
362   // 2. all path to Restore needs to go through Save from Entry.
363   // We achieve that by making sure that:
364   // A. Save dominates Restore.
365   // B. Restore post-dominates Save.
366   // C. Save and Restore are in the same loop.
367   bool SaveDominatesRestore = false;
368   bool RestorePostDominatesSave = false;
369   while (Save && Restore &&
370          (!(SaveDominatesRestore = MDT->dominates(Save, Restore)) ||
371           !(RestorePostDominatesSave = MPDT->dominates(Restore, Save)) ||
372           // Post-dominance is not enough in loops to ensure that all uses/defs
373           // are after the prologue and before the epilogue at runtime.
374           // E.g.,
375           // while(1) {
376           //  Save
377           //  Restore
378           //   if (...)
379           //     break;
380           //  use/def CSRs
381           // }
382           // All the uses/defs of CSRs are dominated by Save and post-dominated
383           // by Restore. However, the CSRs uses are still reachable after
384           // Restore and before Save are executed.
385           //
386           // For now, just push the restore/save points outside of loops.
387           // FIXME: Refine the criteria to still find interesting cases
388           // for loops.
389           MLI->getLoopFor(Save) || MLI->getLoopFor(Restore))) {
390     // Fix (A).
391     if (!SaveDominatesRestore) {
392       Save = MDT->findNearestCommonDominator(Save, Restore);
393       continue;
394     }
395     // Fix (B).
396     if (!RestorePostDominatesSave)
397       Restore = MPDT->findNearestCommonDominator(Restore, Save);
398 
399     // Fix (C).
400     if (Save && Restore &&
401         (MLI->getLoopFor(Save) || MLI->getLoopFor(Restore))) {
402       if (MLI->getLoopDepth(Save) > MLI->getLoopDepth(Restore)) {
403         // Push Save outside of this loop if immediate dominator is different
404         // from save block. If immediate dominator is not different, bail out.
405         Save = FindIDom<>(*Save, Save->predecessors(), *MDT);
406         if (!Save)
407           break;
408       } else {
409         // If the loop does not exit, there is no point in looking
410         // for a post-dominator outside the loop.
411         SmallVector<MachineBasicBlock*, 4> ExitBlocks;
412         MLI->getLoopFor(Restore)->getExitingBlocks(ExitBlocks);
413         // Push Restore outside of this loop.
414         // Look for the immediate post-dominator of the loop exits.
415         MachineBasicBlock *IPdom = Restore;
416         for (MachineBasicBlock *LoopExitBB: ExitBlocks) {
417           IPdom = FindIDom<>(*IPdom, LoopExitBB->successors(), *MPDT);
418           if (!IPdom)
419             break;
420         }
421         // If the immediate post-dominator is not in a less nested loop,
422         // then we are stuck in a program with an infinite loop.
423         // In that case, we will not find a safe point, hence, bail out.
424         if (IPdom && MLI->getLoopDepth(IPdom) < MLI->getLoopDepth(Restore))
425           Restore = IPdom;
426         else {
427           Restore = nullptr;
428           break;
429         }
430       }
431     }
432   }
433 }
434 
435 bool ShrinkWrap::runOnMachineFunction(MachineFunction &MF) {
436   if (skipFunction(MF.getFunction()) || MF.empty() || !isShrinkWrapEnabled(MF))
437     return false;
438 
439   LLVM_DEBUG(dbgs() << "**** Analysing " << MF.getName() << '\n');
440 
441   init(MF);
442 
443   ReversePostOrderTraversal<MachineBasicBlock *> RPOT(&*MF.begin());
444   if (containsIrreducibleCFG<MachineBasicBlock *>(RPOT, *MLI)) {
445     // If MF is irreducible, a block may be in a loop without
446     // MachineLoopInfo reporting it. I.e., we may use the
447     // post-dominance property in loops, which lead to incorrect
448     // results. Moreover, we may miss that the prologue and
449     // epilogue are not in the same loop, leading to unbalanced
450     // construction/deconstruction of the stack frame.
451     LLVM_DEBUG(dbgs() << "Irreducible CFGs are not supported yet\n");
452     return false;
453   }
454 
455   const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
456   std::unique_ptr<RegScavenger> RS(
457       TRI->requiresRegisterScavenging(MF) ? new RegScavenger() : nullptr);
458 
459   for (MachineBasicBlock &MBB : MF) {
460     LLVM_DEBUG(dbgs() << "Look into: " << MBB.getNumber() << ' '
461                       << MBB.getName() << '\n');
462 
463     if (MBB.isEHFuncletEntry()) {
464       LLVM_DEBUG(dbgs() << "EH Funclets are not supported yet.\n");
465       return false;
466     }
467 
468     if (MBB.isEHPad()) {
469       // Push the prologue and epilogue outside of
470       // the region that may throw by making sure
471       // that all the landing pads are at least at the
472       // boundary of the save and restore points.
473       // The problem with exceptions is that the throw
474       // is not properly modeled and in particular, a
475       // basic block can jump out from the middle.
476       updateSaveRestorePoints(MBB, RS.get());
477       if (!ArePointsInteresting()) {
478         LLVM_DEBUG(dbgs() << "EHPad prevents shrink-wrapping\n");
479         return false;
480       }
481       continue;
482     }
483 
484     for (const MachineInstr &MI : MBB) {
485       if (!useOrDefCSROrFI(MI, RS.get()))
486         continue;
487       // Save (resp. restore) point must dominate (resp. post dominate)
488       // MI. Look for the proper basic block for those.
489       updateSaveRestorePoints(MBB, RS.get());
490       // If we are at a point where we cannot improve the placement of
491       // save/restore instructions, just give up.
492       if (!ArePointsInteresting()) {
493         LLVM_DEBUG(dbgs() << "No Shrink wrap candidate found\n");
494         return false;
495       }
496       // No need to look for other instructions, this basic block
497       // will already be part of the handled region.
498       break;
499     }
500   }
501   if (!ArePointsInteresting()) {
502     // If the points are not interesting at this point, then they must be null
503     // because it means we did not encounter any frame/CSR related code.
504     // Otherwise, we would have returned from the previous loop.
505     assert(!Save && !Restore && "We miss a shrink-wrap opportunity?!");
506     LLVM_DEBUG(dbgs() << "Nothing to shrink-wrap\n");
507     return false;
508   }
509 
510   LLVM_DEBUG(dbgs() << "\n ** Results **\nFrequency of the Entry: " << EntryFreq
511                     << '\n');
512 
513   const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
514   do {
515     LLVM_DEBUG(dbgs() << "Shrink wrap candidates (#, Name, Freq):\nSave: "
516                       << Save->getNumber() << ' ' << Save->getName() << ' '
517                       << MBFI->getBlockFreq(Save).getFrequency()
518                       << "\nRestore: " << Restore->getNumber() << ' '
519                       << Restore->getName() << ' '
520                       << MBFI->getBlockFreq(Restore).getFrequency() << '\n');
521 
522     bool IsSaveCheap, TargetCanUseSaveAsPrologue = false;
523     if (((IsSaveCheap = EntryFreq >= MBFI->getBlockFreq(Save).getFrequency()) &&
524          EntryFreq >= MBFI->getBlockFreq(Restore).getFrequency()) &&
525         ((TargetCanUseSaveAsPrologue = TFI->canUseAsPrologue(*Save)) &&
526          TFI->canUseAsEpilogue(*Restore)))
527       break;
528     LLVM_DEBUG(
529         dbgs() << "New points are too expensive or invalid for the target\n");
530     MachineBasicBlock *NewBB;
531     if (!IsSaveCheap || !TargetCanUseSaveAsPrologue) {
532       Save = FindIDom<>(*Save, Save->predecessors(), *MDT);
533       if (!Save)
534         break;
535       NewBB = Save;
536     } else {
537       // Restore is expensive.
538       Restore = FindIDom<>(*Restore, Restore->successors(), *MPDT);
539       if (!Restore)
540         break;
541       NewBB = Restore;
542     }
543     updateSaveRestorePoints(*NewBB, RS.get());
544   } while (Save && Restore);
545 
546   if (!ArePointsInteresting()) {
547     ++NumCandidatesDropped;
548     return false;
549   }
550 
551   LLVM_DEBUG(dbgs() << "Final shrink wrap candidates:\nSave: "
552                     << Save->getNumber() << ' ' << Save->getName()
553                     << "\nRestore: " << Restore->getNumber() << ' '
554                     << Restore->getName() << '\n');
555 
556   MachineFrameInfo &MFI = MF.getFrameInfo();
557   MFI.setSavePoint(Save);
558   MFI.setRestorePoint(Restore);
559   ++NumCandidates;
560   return false;
561 }
562 
563 bool ShrinkWrap::isShrinkWrapEnabled(const MachineFunction &MF) {
564   const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
565 
566   switch (EnableShrinkWrapOpt) {
567   case cl::BOU_UNSET:
568     return TFI->enableShrinkWrapping(MF) &&
569            // Windows with CFI has some limitations that make it impossible
570            // to use shrink-wrapping.
571            !MF.getTarget().getMCAsmInfo()->usesWindowsCFI() &&
572            // Sanitizers look at the value of the stack at the location
573            // of the crash. Since a crash can happen anywhere, the
574            // frame must be lowered before anything else happen for the
575            // sanitizers to be able to get a correct stack frame.
576            !(MF.getFunction().hasFnAttribute(Attribute::SanitizeAddress) ||
577              MF.getFunction().hasFnAttribute(Attribute::SanitizeThread) ||
578              MF.getFunction().hasFnAttribute(Attribute::SanitizeMemory) ||
579              MF.getFunction().hasFnAttribute(Attribute::SanitizeHWAddress));
580   // If EnableShrinkWrap is set, it takes precedence on whatever the
581   // target sets. The rational is that we assume we want to test
582   // something related to shrink-wrapping.
583   case cl::BOU_TRUE:
584     return true;
585   case cl::BOU_FALSE:
586     return false;
587   }
588   llvm_unreachable("Invalid shrink-wrapping state");
589 }
590