1193323Sed//===-- MachineFunctionPass.h - Pass for MachineFunctions --------*-C++ -*-===// 2193323Sed// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6193323Sed// 7193323Sed//===----------------------------------------------------------------------===// 8193323Sed// 9193323Sed// This file defines the MachineFunctionPass class. MachineFunctionPass's are 10193323Sed// just FunctionPass's, except they operate on machine code as part of a code 11193323Sed// generator. Because they operate on machine code, not the LLVM 12193323Sed// representation, MachineFunctionPass's are not allowed to modify the LLVM 13193323Sed// representation. Due to this limitation, the MachineFunctionPass class takes 14193323Sed// care of declaring that no LLVM passes are invalidated. 15193323Sed// 16193323Sed//===----------------------------------------------------------------------===// 17193323Sed 18249423Sdim#ifndef LLVM_CODEGEN_MACHINEFUNCTIONPASS_H 19249423Sdim#define LLVM_CODEGEN_MACHINEFUNCTIONPASS_H 20193323Sed 21321369Sdim#include "llvm/CodeGen/MachineFunction.h" 22193323Sed#include "llvm/Pass.h" 23193323Sed 24193323Sednamespace llvm { 25193323Sed 26198090Srdivacky/// MachineFunctionPass - This class adapts the FunctionPass interface to 27198090Srdivacky/// allow convenient creation of passes that operate on the MachineFunction 28198090Srdivacky/// representation. Instead of overriding runOnFunction, subclasses 29198090Srdivacky/// override runOnMachineFunction. 30198090Srdivackyclass MachineFunctionPass : public FunctionPass { 31309124Sdimpublic: 32309124Sdim bool doInitialization(Module&) override { 33309124Sdim // Cache the properties info at module-init time so we don't have to 34309124Sdim // construct them for every function. 35309124Sdim RequiredProperties = getRequiredProperties(); 36309124Sdim SetProperties = getSetProperties(); 37309124Sdim ClearedProperties = getClearedProperties(); 38309124Sdim return false; 39309124Sdim } 40198090Srdivackyprotected: 41212904Sdim explicit MachineFunctionPass(char &ID) : FunctionPass(ID) {} 42193323Sed 43193323Sed /// runOnMachineFunction - This method must be overloaded to perform the 44193323Sed /// desired machine code transformation or analysis. 45193323Sed /// 46193323Sed virtual bool runOnMachineFunction(MachineFunction &MF) = 0; 47193323Sed 48198090Srdivacky /// getAnalysisUsage - Subclasses that override getAnalysisUsage 49198090Srdivacky /// must call this. 50198090Srdivacky /// 51198090Srdivacky /// For MachineFunctionPasses, calling AU.preservesCFG() indicates that 52198090Srdivacky /// the pass does not modify the MachineBasicBlock CFG. 53198090Srdivacky /// 54276479Sdim void getAnalysisUsage(AnalysisUsage &AU) const override; 55198090Srdivacky 56309124Sdim virtual MachineFunctionProperties getRequiredProperties() const { 57309124Sdim return MachineFunctionProperties(); 58309124Sdim } 59309124Sdim virtual MachineFunctionProperties getSetProperties() const { 60309124Sdim return MachineFunctionProperties(); 61309124Sdim } 62309124Sdim virtual MachineFunctionProperties getClearedProperties() const { 63309124Sdim return MachineFunctionProperties(); 64309124Sdim } 65309124Sdim 66198090Srdivackyprivate: 67309124Sdim MachineFunctionProperties RequiredProperties; 68309124Sdim MachineFunctionProperties SetProperties; 69309124Sdim MachineFunctionProperties ClearedProperties; 70309124Sdim 71210299Sed /// createPrinterPass - Get a machine function printer pass. 72276479Sdim Pass *createPrinterPass(raw_ostream &O, 73276479Sdim const std::string &Banner) const override; 74210299Sed 75276479Sdim bool runOnFunction(Function &F) override; 76193323Sed}; 77193323Sed 78193323Sed} // End llvm namespace 79193323Sed 80193323Sed#endif 81