blob: ee30ba988521382ec6191958509c1b92b59852ca [file] [log] [blame]
Andrew Walbran16937d02019-10-22 13:54:20 +01001//===-- llvm/CodeGen/GlobalISel/CombinerHelper.h --------------*- C++ -*-===//
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01002//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===--------------------------------------------------------------------===//
8//
9/// This contains common combine transformations that may be used in a combine
10/// pass,or by the target elsewhere.
11/// Targets can pick individual opcode transformations from the helper or use
12/// tryCombine which invokes all transformations. All of the transformations
13/// return true if the MachineInstruction changed and false otherwise.
14//
15//===--------------------------------------------------------------------===//
16
17#ifndef LLVM_CODEGEN_GLOBALISEL_COMBINER_HELPER_H
18#define LLVM_CODEGEN_GLOBALISEL_COMBINER_HELPER_H
19
20namespace llvm {
21
Andrew Walbran16937d02019-10-22 13:54:20 +010022class GISelChangeObserver;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010023class MachineIRBuilder;
24class MachineRegisterInfo;
25class MachineInstr;
Andrew Walbran16937d02019-10-22 13:54:20 +010026class MachineOperand;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010027
28class CombinerHelper {
29 MachineIRBuilder &Builder;
30 MachineRegisterInfo &MRI;
Andrew Walbran16937d02019-10-22 13:54:20 +010031 GISelChangeObserver &Observer;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010032
33public:
Andrew Walbran16937d02019-10-22 13:54:20 +010034 CombinerHelper(GISelChangeObserver &Observer, MachineIRBuilder &B);
35
36 /// MachineRegisterInfo::replaceRegWith() and inform the observer of the changes
37 void replaceRegWith(MachineRegisterInfo &MRI, unsigned FromReg, unsigned ToReg) const;
38
39 /// Replace a single register operand with a new register and inform the
40 /// observer of the changes.
41 void replaceRegOpWith(MachineRegisterInfo &MRI, MachineOperand &FromRegOp,
42 unsigned ToReg) const;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010043
44 /// If \p MI is COPY, try to combine it.
45 /// Returns true if MI changed.
46 bool tryCombineCopy(MachineInstr &MI);
47
Andrew Scull0372a572018-11-16 15:47:06 +000048 /// If \p MI is extend that consumes the result of a load, try to combine it.
49 /// Returns true if MI changed.
50 bool tryCombineExtendingLoads(MachineInstr &MI);
51
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010052 /// Try to transform \p MI by using all of the above
53 /// combine functions. Returns true if changed.
54 bool tryCombine(MachineInstr &MI);
55};
56} // namespace llvm
57
58#endif