Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 1 | //===-- llvm/CodeGen/GlobalISel/CombinerHelper.h --------------*- C++ -*-===// |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 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 | |
| 20 | namespace llvm { |
| 21 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 22 | class GISelChangeObserver; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 23 | class MachineIRBuilder; |
| 24 | class MachineRegisterInfo; |
| 25 | class MachineInstr; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 26 | class MachineOperand; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 27 | |
| 28 | class CombinerHelper { |
| 29 | MachineIRBuilder &Builder; |
| 30 | MachineRegisterInfo &MRI; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 31 | GISelChangeObserver &Observer; |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 32 | |
| 33 | public: |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame^] | 34 | 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 Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 43 | |
| 44 | /// If \p MI is COPY, try to combine it. |
| 45 | /// Returns true if MI changed. |
| 46 | bool tryCombineCopy(MachineInstr &MI); |
| 47 | |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 48 | /// 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 Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 52 | /// 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 |