LLVM 24.0.0git
MachineFunctionProperties.h
Go to the documentation of this file.
1//===- MachineFunctionProperties.h - Machine IR properties -*- 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
9#ifndef LLVM_CODEGEN_MACHINEFUNCTIONPROPERTIES_H
10#define LLVM_CODEGEN_MACHINEFUNCTIONPROPERTIES_H
11
13#include <bitset>
14
15namespace llvm {
16
17class raw_ostream;
18
19/// Properties which a MachineFunction may have at a given point in time.
20/// Each of these has checking code in the MachineVerifier, and passes can
21/// require that a property be set.
23 // Possible TODO: Allow targets to extend this (perhaps by allowing the
24 // constructor to specify the size of the bit vector)
25 // Possible TODO: Allow requiring the negative (e.g. VRegsAllocated could be
26 // stated as the negative of "has vregs"
27
28public:
29 // The properties are stated in "positive" form; i.e. a pass could require
30 // that the property hold, but not that it does not hold.
31
32 // Property descriptions:
33 // IsSSA: True when the machine function is in SSA form and virtual registers
34 // have a single def.
35 // NoPHIs: The machine function does not contain any PHI instruction.
36 // TracksLiveness: True when tracking register liveness accurately.
37 // While this property is set, register liveness information in basic block
38 // live-in lists and machine instruction operands (e.g. implicit defs) is
39 // accurate, kill flags are conservatively accurate (kill flag correctly
40 // indicates the last use of a register, an operand without kill flag may or
41 // may not be the last use of a register). This means it can be used to
42 // change the code in ways that affect the values in registers, for example
43 // by the register scavenger.
44 // When this property is cleared at a very late time, liveness is no longer
45 // reliable.
46 // NoVRegs: The machine function does not use any virtual registers.
47 // Legalized: In GlobalISel: the MachineLegalizer ran and all pre-isel generic
48 // instructions have been legalized; i.e., all instructions are now one of:
49 // - generic and always legal (e.g., COPY)
50 // - target-specific
51 // - legal pre-isel generic instructions.
52 // RegBankSelected: In GlobalISel: the RegBankSelect pass ran and all generic
53 // virtual registers have been assigned to a register bank.
54 // Selected: In GlobalISel: the InstructionSelect pass ran and all pre-isel
55 // generic instructions have been eliminated; i.e., all instructions are now
56 // target-specific or non-pre-isel generic instructions (e.g., COPY).
57 // Since only pre-isel generic instructions can have generic virtual register
58 // operands, this also means that all generic virtual registers have been
59 // constrained to virtual registers (assigned to register classes) and that
60 // all sizes attached to them have been eliminated.
61 // TiedOpsRewritten: The twoaddressinstruction pass will set this flag, it
62 // means that tied-def have been rewritten to meet the RegConstraint.
63 // FailsVerification: Means that the function is not expected to pass machine
64 // verification. This can be set by passes that introduce known problems that
65 // have not been fixed yet.
66 // TracksDebugUserValues: Without this property enabled, debug instructions
67 // such as DBG_VALUE are allowed to reference virtual registers even if those
68 // registers do not have a definition. With the property enabled virtual
69 // registers must only be used if they have a definition. This property
70 // allows earlier passes in the pipeline to skip updates of `DBG_VALUE`
71 // instructions to save compile time.
87
88 bool hasProperty(Property P) const {
89 return Properties[static_cast<unsigned>(P)];
90 }
91
93 Properties.set(static_cast<unsigned>(P));
94 return *this;
95 }
96
98 Properties.reset(static_cast<unsigned>(P));
99 return *this;
100 }
101
102 // Per property has/set/reset accessors.
103#define PPACCESSORS(X) \
104 bool has##X() const { return hasProperty(Property::X); } \
105 MachineFunctionProperties &set##X(void) { return set(Property::X); } \
106 MachineFunctionProperties &reset##X(void) { return reset(Property::X); }
107
120
121 /// Reset all the properties.
123 Properties.reset();
124 return *this;
125 }
126
127 /// Reset all properties and re-establish baseline invariants.
129 reset();
130 setIsSSA();
131 setTracksLiveness();
132 return *this;
133 }
134
136 Properties |= MFP.Properties;
137 return *this;
138 }
139
141 Properties &= ~MFP.Properties;
142 return *this;
143 }
144
145 // Returns true if all properties set in V (i.e. required by a pass) are set
146 // in this.
148 return (Properties | ~V.Properties).all();
149 }
150
151 /// Print the MachineFunctionProperties in human-readable form.
152 LLVM_ABI void print(raw_ostream &OS) const;
153
154private:
155 std::bitset<static_cast<unsigned>(Property::LastProperty) + 1> Properties;
156};
157
158} // namespace llvm
159
160#endif // LLVM_CODEGEN_MACHINEFUNCTIONPROPERTIES_H
#define LLVM_ABI
Definition Compiler.h:211
#define PPACCESSORS(X)
#define P(N)
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & reset()
Reset all the properties.
MachineFunctionProperties & resetToInitial()
Reset all properties and re-establish baseline invariants.
MachineFunctionProperties & set(const MachineFunctionProperties &MFP)
LLVM_ABI void print(raw_ostream &OS) const
Print the MachineFunctionProperties in human-readable form.
bool verifyRequiredProperties(const MachineFunctionProperties &V) const
MachineFunctionProperties & reset(const MachineFunctionProperties &MFP)
MachineFunctionProperties & set(Property P)
MachineFunctionProperties & reset(Property P)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.