1 //== llvm/CodeGen/GlobalISel/InstructionSelect.h -----------------*- 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 /// \file This file describes the interface of the MachineFunctionPass 9 /// responsible for selecting (possibly generic) machine instructions to 10 /// target-specific instructions. 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECT_H 14 #define LLVM_CODEGEN_GLOBALISEL_INSTRUCTIONSELECT_H 15 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/CodeGen/MachineFunction.h" 18 #include "llvm/CodeGen/MachineFunctionPass.h" 19 #include "llvm/Support/CodeGen.h" 20 21 namespace llvm { 22 23 class InstructionSelector; 24 class GISelKnownBits; 25 class BlockFrequencyInfo; 26 class ProfileSummaryInfo; 27 28 /// This pass is responsible for selecting generic machine instructions to 29 /// target-specific instructions. It relies on the InstructionSelector provided 30 /// by the target. 31 /// Selection is done by examining blocks in post-order, and instructions in 32 /// reverse order. 33 /// 34 /// \post for all inst in MF: not isPreISelGenericOpcode(inst.opcode) 35 class InstructionSelect : public MachineFunctionPass { 36 public: 37 static char ID; getPassName()38 StringRef getPassName() const override { return "InstructionSelect"; } 39 40 void getAnalysisUsage(AnalysisUsage &AU) const override; 41 getRequiredProperties()42 MachineFunctionProperties getRequiredProperties() const override { 43 return MachineFunctionProperties() 44 .set(MachineFunctionProperties::Property::IsSSA) 45 .set(MachineFunctionProperties::Property::Legalized) 46 .set(MachineFunctionProperties::Property::RegBankSelected); 47 } 48 getSetProperties()49 MachineFunctionProperties getSetProperties() const override { 50 return MachineFunctionProperties().set( 51 MachineFunctionProperties::Property::Selected); 52 } 53 54 InstructionSelect(CodeGenOptLevel OL = CodeGenOptLevel::Default, 55 char &PassID = ID); 56 57 bool runOnMachineFunction(MachineFunction &MF) override; 58 bool selectMachineFunction(MachineFunction &MF); setInstructionSelector(InstructionSelector * NewISel)59 void setInstructionSelector(InstructionSelector *NewISel) { ISel = NewISel; } 60 61 protected: 62 class MIIteratorMaintainer; 63 64 InstructionSelector *ISel = nullptr; 65 GISelKnownBits *KB = nullptr; 66 BlockFrequencyInfo *BFI = nullptr; 67 ProfileSummaryInfo *PSI = nullptr; 68 69 CodeGenOptLevel OptLevel = CodeGenOptLevel::None; 70 71 bool selectInstr(MachineInstr &MI); 72 }; 73 } // End namespace llvm. 74 75 #endif 76