|
18 | 18 | #include "llvm/CodeGen/LiveRegUnits.h"
|
19 | 19 | #include "llvm/CodeGen/MachineFunction.h"
|
20 | 20 | #include "llvm/CodeGen/MachineRegisterInfo.h"
|
| 21 | +#include "llvm/CodeGen/MachineStableHash.h" |
21 | 22 | #include <initializer_list>
|
22 | 23 |
|
23 | 24 | namespace llvm {
|
@@ -233,6 +234,9 @@ struct OutlinedFunction {
|
233 | 234 | /// Target-defined identifier for constructing a frame for this function.
|
234 | 235 | unsigned FrameConstructionID = 0;
|
235 | 236 |
|
| 237 | + /// The sequence of stable_hash'es of instructions. |
| 238 | + std::vector<stable_hash> OutlinedHashSequence; |
| 239 | + |
236 | 240 | /// Return the number of candidates for this \p OutlinedFunction.
|
237 | 241 | virtual unsigned getOccurrenceCount() const { return Candidates.size(); }
|
238 | 242 |
|
@@ -274,6 +278,41 @@ struct OutlinedFunction {
|
274 | 278 | OutlinedFunction() = delete;
|
275 | 279 | virtual ~OutlinedFunction() = default;
|
276 | 280 | };
|
| 281 | + |
| 282 | +/// The information necessary to create an outlined function that is matched |
| 283 | +/// globally. |
| 284 | +struct GlobalOutlinedFunction : public OutlinedFunction { |
| 285 | + GlobalOutlinedFunction(OutlinedFunction &OF, unsigned GlobalOccurrenceCount) |
| 286 | + : OutlinedFunction(OF.Candidates, OF.SequenceSize, OF.FrameOverhead, |
| 287 | + OF.FrameConstructionID), |
| 288 | + GlobalOccurrenceCount(GlobalOccurrenceCount) {} |
| 289 | + |
| 290 | + unsigned GlobalOccurrenceCount; |
| 291 | + |
| 292 | + /// Return the number of times that appear globally. |
| 293 | + /// Global outlining candidate is uniquely created per each match, but this |
| 294 | + /// might be erased out when it's overlapped with the previous outlining |
| 295 | + /// instance. |
| 296 | + unsigned getOccurrenceCount() const override { |
| 297 | + assert(Candidates.size() < 1); |
| 298 | + return Candidates.empty() ? 0 : GlobalOccurrenceCount; |
| 299 | + } |
| 300 | + |
| 301 | + /// Return the outlining cost using the global occurrence count |
| 302 | + /// with the same cost as the first (unique) candidate. |
| 303 | + unsigned getOutliningCost() const override { |
| 304 | + assert(Candidates.size() < 1); |
| 305 | + unsigned CallOverhead = |
| 306 | + Candidates.empty() |
| 307 | + ? 0 |
| 308 | + : Candidates[0].getCallOverhead() * getOccurrenceCount(); |
| 309 | + return CallOverhead + SequenceSize + FrameOverhead; |
| 310 | + } |
| 311 | + |
| 312 | + GlobalOutlinedFunction() = delete; |
| 313 | + ~GlobalOutlinedFunction() = default; |
| 314 | +}; |
| 315 | + |
277 | 316 | } // namespace outliner
|
278 | 317 | } // namespace llvm
|
279 | 318 |
|
|
0 commit comments