blob: 04f7f419f5eacfbb1a136cbf3835591ce6b19ee1 [file] [log] [blame]
David Goodwin83704852009-10-26 16:59:04 +00001//=- llvm/CodeGen/AntiDepBreaker.h - Anti-Dependence Breaking -*- C++ -*-=//
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 file implements the AntiDepBreaker class, which implements
11// anti-dependence breaking heuristics for post-register-allocation scheduling.
12//
13//===----------------------------------------------------------------------===//
14
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_CODEGEN_ANTIDEPBREAKER_H
16#define LLVM_LIB_CODEGEN_ANTIDEPBREAKER_H
David Goodwin83704852009-10-26 16:59:04 +000017
18#include "llvm/CodeGen/MachineBasicBlock.h"
19#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineRegisterInfo.h"
22#include "llvm/CodeGen/ScheduleDAG.h"
23#include "llvm/Target/TargetRegisterInfo.h"
David Goodwin80a03cc2009-11-20 19:32:48 +000024#include <vector>
David Goodwin83704852009-10-26 16:59:04 +000025
26namespace llvm {
27
Sanjay Pateld6492352014-09-21 14:48:16 +000028/// This class works in conjunction with the post-RA scheduler to rename
29/// registers to break register anti-dependencies (WAR hazards).
Benjamin Kramerf4c20252015-07-01 14:47:39 +000030class LLVM_LIBRARY_VISIBILITY AntiDepBreaker {
David Goodwin83704852009-10-26 16:59:04 +000031public:
Devang Patelf02a3762011-06-02 21:26:52 +000032 typedef std::vector<std::pair<MachineInstr *, MachineInstr *> >
33 DbgValueVector;
34
David Goodwin661ea982009-10-26 19:41:00 +000035 virtual ~AntiDepBreaker();
David Goodwin6b16b5e2009-10-26 19:00:47 +000036
Sanjay Pateld6492352014-09-21 14:48:16 +000037 /// Initialize anti-dep breaking for a new basic block.
David Goodwin83704852009-10-26 16:59:04 +000038 virtual void StartBlock(MachineBasicBlock *BB) =0;
39
Sanjay Pateld6492352014-09-21 14:48:16 +000040 /// Identifiy anti-dependencies within a basic-block region and break them by
41 /// renaming registers. Return the number of anti-dependencies broken.
Dan Gohman35bc4d42010-04-19 23:11:58 +000042 virtual unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
Devang Patelf02a3762011-06-02 21:26:52 +000043 MachineBasicBlock::iterator Begin,
44 MachineBasicBlock::iterator End,
45 unsigned InsertPosIndex,
46 DbgValueVector &DbgValues) = 0;
David Goodwin83704852009-10-26 16:59:04 +000047
Sanjay Pateld6492352014-09-21 14:48:16 +000048 /// Update liveness information to account for the current
David Goodwin83704852009-10-26 16:59:04 +000049 /// instruction, which will not be scheduled.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +000050 virtual void Observe(MachineInstr &MI, unsigned Count,
51 unsigned InsertPosIndex) = 0;
52
Sanjay Pateld6492352014-09-21 14:48:16 +000053 /// Finish anti-dep breaking for a basic block.
David Goodwin83704852009-10-26 16:59:04 +000054 virtual void FinishBlock() =0;
Devang Patelf02a3762011-06-02 21:26:52 +000055
Sanjay Pateld6492352014-09-21 14:48:16 +000056 /// Update DBG_VALUE if dependency breaker is updating
Devang Patelf02a3762011-06-02 21:26:52 +000057 /// other machine instruction to use NewReg.
Duncan P. N. Exon Smith5e6e8c72016-02-27 19:33:37 +000058 void UpdateDbgValue(MachineInstr &MI, unsigned OldReg, unsigned NewReg) {
59 assert(MI.isDebugValue() && "MI is not DBG_VALUE!");
60 if (MI.getOperand(0).isReg() && MI.getOperand(0).getReg() == OldReg)
61 MI.getOperand(0).setReg(NewReg);
Devang Patelf02a3762011-06-02 21:26:52 +000062 }
David Goodwin83704852009-10-26 16:59:04 +000063};
64
Alexander Kornienkof00654e2015-06-23 09:49:53 +000065}
David Goodwin83704852009-10-26 16:59:04 +000066
67#endif