xref: /llvm-project/llvm/include/llvm/CodeGen/Spiller.h (revision 4f96fb5fb349b0030f9c14b4fe389cebc3069702)
1 //===- llvm/CodeGen/Spiller.h - Spiller -------------------------*- 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 #ifndef LLVM_CODEGEN_SPILLER_H
10 #define LLVM_CODEGEN_SPILLER_H
11 
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/CodeGen/Register.h"
14 
15 namespace llvm {
16 
17 class LiveRangeEdit;
18 class MachineFunction;
19 class MachineFunctionPass;
20 class VirtRegMap;
21 class VirtRegAuxInfo;
22 class LiveIntervals;
23 class LiveStacks;
24 class MachineDominatorTree;
25 class MachineBlockFrequencyInfo;
26 
27 /// Spiller interface.
28 ///
29 /// Implementations are utility classes which insert spill or remat code on
30 /// demand.
31 class Spiller {
32   virtual void anchor();
33 
34 public:
35   virtual ~Spiller() = 0;
36 
37   /// spill - Spill the LRE.getParent() live interval.
38   virtual void spill(LiveRangeEdit &LRE) = 0;
39 
40   /// Return the registers that were spilled.
41   virtual ArrayRef<Register> getSpilledRegs() = 0;
42 
43   /// Return registers that were not spilled, but otherwise replaced
44   /// (e.g. rematerialized).
45   virtual ArrayRef<Register> getReplacedRegs() = 0;
46 
47   virtual void postOptimization() {}
48 
49   struct RequiredAnalyses {
50     LiveIntervals &LIS;
51     LiveStacks &LSS;
52     MachineDominatorTree &MDT;
53     const MachineBlockFrequencyInfo &MBFI;
54   };
55 };
56 
57 /// Create and return a spiller that will insert spill code directly instead
58 /// of deferring though VirtRegMap.
59 Spiller *createInlineSpiller(const Spiller::RequiredAnalyses &Analyses,
60                              MachineFunction &MF, VirtRegMap &VRM,
61                              VirtRegAuxInfo &VRAI);
62 
63 } // end namespace llvm
64 
65 #endif // LLVM_CODEGEN_SPILLER_H
66