[GlobalISel] Add Legalized MachineFunction property.

Legalized: The MachineLegalizer ran; all pre-isel generic instructions
have been legalized, i.e., all instructions are now one of:
  - generic and always legal (e.g., COPY)
  - target-specific
  - legal pre-isel generic instructions.

This lets us enforce certain invariants across passes.
This property is GlobalISel-specific, but is always available.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277470 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ahmed Bougacha 2016-08-02 15:10:25 +00:00
parent 07d957665f
commit 46fe427fc7
6 changed files with 53 additions and 0 deletions

View File

@ -384,6 +384,8 @@ struct MachineFunction {
bool HasInlineAsm = false;
// MachineFunctionProperties
bool AllVRegsAllocated = false;
// GISel MachineFunctionProperties.
bool Legalized = false;
// Register information
bool IsSSA = false;
bool TracksRegLiveness = false;
@ -408,6 +410,7 @@ template <> struct MappingTraits<MachineFunction> {
YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice);
YamlIO.mapOptional("hasInlineAsm", MF.HasInlineAsm);
YamlIO.mapOptional("allVRegsAllocated", MF.AllVRegsAllocated);
YamlIO.mapOptional("legalized", MF.Legalized);
YamlIO.mapOptional("isSSA", MF.IsSSA);
YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness);
YamlIO.mapOptional("tracksSubRegLiveness", MF.TracksSubRegLiveness);

View File

@ -117,10 +117,16 @@ public:
// When this property is clear, liveness is no longer reliable.
// AllVRegsAllocated: All virtual registers have been allocated; i.e. all
// register operands are physical registers.
// Legalized: In GlobalISel: the MachineLegalizer ran and all pre-isel generic
// instructions have been legalized; i.e., all instructions are now one of:
// - generic and always legal (e.g., COPY)
// - target-specific
// - legal pre-isel generic instructions.
enum class Property : unsigned {
IsSSA,
TracksLiveness,
AllVRegsAllocated,
Legalized,
LastProperty,
};

View File

@ -292,6 +292,10 @@ bool MIRParserImpl::initializeMachineFunction(MachineFunction &MF) {
MF.setHasInlineAsm(YamlMF.HasInlineAsm);
if (YamlMF.AllVRegsAllocated)
MF.getProperties().set(MachineFunctionProperties::Property::AllVRegsAllocated);
if (YamlMF.Legalized)
MF.getProperties().set(MachineFunctionProperties::Property::Legalized);
PerFunctionMIParsingState PFS(MF, SM, IRSlots);
if (initializeRegisterInfo(PFS, YamlMF))
return true;

View File

@ -178,6 +178,9 @@ void MIRPrinter::print(const MachineFunction &MF) {
YamlMF.AllVRegsAllocated = MF.getProperties().hasProperty(
MachineFunctionProperties::Property::AllVRegsAllocated);
YamlMF.Legalized = MF.getProperties().hasProperty(
MachineFunctionProperties::Property::Legalized);
convert(YamlMF, MF.getRegInfo(), MF.getSubtarget().getRegisterInfo());
ModuleSlotTracker MST(MF.getFunction()->getParent());
MST.incorporateFunction(*MF.getFunction());

View File

@ -76,6 +76,9 @@ void MachineFunctionProperties::print(raw_ostream &ROS, bool OnlySet) const {
case Property::AllVRegsAllocated:
ROS << (HasProperty ? "AllVRegsAllocated" : "HasVRegs");
break;
case Property::Legalized:
ROS << (HasProperty ? "" : "not ") << "legalized";
break;
default:
break;
}

View File

@ -0,0 +1,34 @@
# RUN: llc -run-pass none -o - %s | FileCheck %s
# This test ensures that the MIR parser parses GlobalISel MachineFunction
# properties correctly.
# This doesn't require GlobalISel to be built, as the properties are always
# available in CodeGen.
--- |
define i32 @test_defaults() {
entry:
ret i32 0
}
define i32 @test() {
start:
ret i32 0
}
...
---
# CHECK-LABEL: name: test_defaults
# CHECK: legalized: false
name: test_defaults
body: |
bb.0:
...
---
# CHECK-LABEL: name: test
# CHECK: legalized: true
name: test
legalized: true
body: |
bb.0:
...