Skip to content

Commit 214ff50

Browse files
authored
[X86] Add AMXProgModel to YAML serialization (#94988)
This allows tested passes to depend on the AMX model in the function info. Preparatory work for to adopt #94358 for other AMX passes.
1 parent 2ca8c85 commit 214ff50

10 files changed

+89
-7
lines changed

llvm/lib/Target/X86/X86MachineFunctionInfo.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@
1313

1414
using namespace llvm;
1515

16+
yaml::X86MachineFunctionInfo::X86MachineFunctionInfo(
17+
const llvm::X86MachineFunctionInfo &MFI)
18+
: AMXProgModel(MFI.getAMXProgModel()) {}
19+
20+
void yaml::X86MachineFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
21+
MappingTraits<X86MachineFunctionInfo>::mapping(YamlIO, *this);
22+
}
23+
1624
MachineFunctionInfo *X86MachineFunctionInfo::clone(
1725
BumpPtrAllocator &Allocator, MachineFunction &DestMF,
1826
const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
1927
const {
2028
return DestMF.cloneInfo<X86MachineFunctionInfo>(*this);
2129
}
2230

31+
void X86MachineFunctionInfo::initializeBaseYamlFields(
32+
const yaml::X86MachineFunctionInfo &YamlMFI) {
33+
AMXProgModel = YamlMFI.AMXProgModel;
34+
}
35+
2336
void X86MachineFunctionInfo::anchor() { }
2437

2538
void X86MachineFunctionInfo::setRestoreBasePointer(const MachineFunction *MF) {

llvm/lib/Target/X86/X86MachineFunctionInfo.h

+32
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,43 @@
1616
#include "llvm/ADT/ArrayRef.h"
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/CodeGen/CallingConvLower.h"
19+
#include "llvm/CodeGen/MIRYamlMapping.h"
1920
#include "llvm/CodeGen/MachineFunction.h"
21+
#include "llvm/Support/YAMLTraits.h"
2022
#include <set>
2123

2224
namespace llvm {
2325

2426
enum AMXProgModelEnum { None = 0, DirectReg = 1, ManagedRA = 2 };
2527

28+
class X86MachineFunctionInfo;
29+
30+
namespace yaml {
31+
template <> struct ScalarEnumerationTraits<AMXProgModelEnum> {
32+
static void enumeration(IO &YamlIO, AMXProgModelEnum &Value) {
33+
YamlIO.enumCase(Value, "None", AMXProgModelEnum::None);
34+
YamlIO.enumCase(Value, "DirectReg", AMXProgModelEnum::DirectReg);
35+
YamlIO.enumCase(Value, "ManagedRA", AMXProgModelEnum::ManagedRA);
36+
}
37+
};
38+
39+
struct X86MachineFunctionInfo final : public yaml::MachineFunctionInfo {
40+
AMXProgModelEnum AMXProgModel;
41+
42+
X86MachineFunctionInfo() = default;
43+
X86MachineFunctionInfo(const llvm::X86MachineFunctionInfo &MFI);
44+
45+
void mappingImpl(yaml::IO &YamlIO) override;
46+
~X86MachineFunctionInfo() = default;
47+
};
48+
49+
template <> struct MappingTraits<X86MachineFunctionInfo> {
50+
static void mapping(IO &YamlIO, X86MachineFunctionInfo &MFI) {
51+
YamlIO.mapOptional("amxProgModel", MFI.AMXProgModel);
52+
}
53+
};
54+
} // end namespace yaml
55+
2656
/// X86MachineFunctionInfo - This class is derived from MachineFunction and
2757
/// contains private X86 target-specific information for each MachineFunction.
2858
class X86MachineFunctionInfo : public MachineFunctionInfo {
@@ -160,6 +190,8 @@ class X86MachineFunctionInfo : public MachineFunctionInfo {
160190
const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
161191
const override;
162192

193+
void initializeBaseYamlFields(const yaml::X86MachineFunctionInfo &YamlMFI);
194+
163195
bool getForceFramePointer() const { return ForceFramePointer;}
164196
void setForceFramePointer(bool forceFP) { ForceFramePointer = forceFP; }
165197

llvm/lib/Target/X86/X86TargetMachine.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
3232
#include "llvm/CodeGen/GlobalISel/Legalizer.h"
3333
#include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
34+
#include "llvm/CodeGen/MIRParser/MIParser.h"
35+
#include "llvm/CodeGen/MIRYamlMapping.h"
3436
#include "llvm/CodeGen/MachineScheduler.h"
3537
#include "llvm/CodeGen/Passes.h"
3638
#include "llvm/CodeGen/RegAllocRegistry.h"
@@ -344,6 +346,24 @@ X86TargetMachine::getSubtargetImpl(const Function &F) const {
344346
return I.get();
345347
}
346348

349+
yaml::MachineFunctionInfo *X86TargetMachine::createDefaultFuncInfoYAML() const {
350+
return new yaml::X86MachineFunctionInfo();
351+
}
352+
353+
yaml::MachineFunctionInfo *
354+
X86TargetMachine::convertFuncInfoToYAML(const MachineFunction &MF) const {
355+
const auto *MFI = MF.getInfo<X86MachineFunctionInfo>();
356+
return new yaml::X86MachineFunctionInfo(*MFI);
357+
}
358+
359+
bool X86TargetMachine::parseMachineFunctionInfo(
360+
const yaml::MachineFunctionInfo &MFI, PerFunctionMIParsingState &PFS,
361+
SMDiagnostic &Error, SMRange &SourceRange) const {
362+
const auto &YamlMFI = static_cast<const yaml::X86MachineFunctionInfo &>(MFI);
363+
PFS.MF.getInfo<X86MachineFunctionInfo>()->initializeBaseYamlFields(YamlMFI);
364+
return false;
365+
}
366+
347367
bool X86TargetMachine::isNoopAddrSpaceCast(unsigned SrcAS,
348368
unsigned DestAS) const {
349369
assert(SrcAS != DestAS && "Expected different address spaces!");

llvm/lib/Target/X86/X86TargetMachine.h

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class X86TargetMachine final : public LLVMTargetMachine {
5858
createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
5959
const TargetSubtargetInfo *STI) const override;
6060

61+
yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
62+
yaml::MachineFunctionInfo *
63+
convertFuncInfoToYAML(const MachineFunction &MF) const override;
64+
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
65+
PerFunctionMIParsingState &PFS,
66+
SMDiagnostic &Error,
67+
SMRange &SourceRange) const override;
68+
6169
void registerPassBuilderCallbacks(PassBuilder &PB,
6270
bool PopulateClassToPassNames) override;
6371

llvm/test/CodeGen/X86/AMX/amx-fastconfig-phi.mir

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ liveins:
8787
- { reg: '$rsi', virtual-reg: '%14' }
8888
frameInfo:
8989
maxAlignment: 1
90-
machineFunctionInfo: {}
90+
machineFunctionInfo:
91+
amxProgModel: ManagedRA
9192
body: |
9293
; CHECK-LABEL: name: foo
9394
; CHECK: bb.0.entry:

llvm/test/CodeGen/X86/AMX/amx-fastconfig-phi2.mir

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ liveins:
3434
- { reg: '$edi', virtual-reg: '%12' }
3535
frameInfo:
3636
maxAlignment: 1
37-
machineFunctionInfo: {}
37+
machineFunctionInfo:
38+
amxProgModel: ManagedRA
3839
body: |
3940
; CHECK-LABEL: name: foo
4041
; CHECK: bb.0.entry:

llvm/test/CodeGen/X86/AMX/amx-fastconfig-phi4.mir

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ liveins:
3535
- { reg: '$edi', virtual-reg: '%12' }
3636
frameInfo:
3737
maxAlignment: 1
38-
machineFunctionInfo: {}
38+
machineFunctionInfo:
39+
amxProgModel: ManagedRA
3940
body: |
4041
; CHECK-LABEL: name: foo
4142
; CHECK: bb.0.entry:

llvm/test/CodeGen/X86/AMX/amx-fastconfig-spill.mir

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ frameInfo:
2323
stack:
2424
- { id: 0, size: 1024, alignment: 16 }
2525
- { id: 1, size: 64, alignment: 4 }
26-
machineFunctionInfo: {}
26+
machineFunctionInfo:
27+
amxProgModel: ManagedRA
2728
body: |
2829
; CHECK-LABEL: name: foo
2930
; CHECK: bb.0.entry:
@@ -100,7 +101,8 @@ frameInfo:
100101
stack:
101102
- { id: 0, size: 1024, alignment: 16 }
102103
- { id: 1, size: 64, alignment: 4 }
103-
machineFunctionInfo: {}
104+
machineFunctionInfo:
105+
amxProgModel: ManagedRA
104106
body: |
105107
; CHECK-LABEL: name: copy
106108
; CHECK: bb.0.entry:

llvm/test/CodeGen/X86/AMX/amx-fastconfig.mir

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ liveins:
7777
- { reg: '$edx', virtual-reg: '%11' }
7878
frameInfo:
7979
maxAlignment: 1
80-
machineFunctionInfo: {}
80+
machineFunctionInfo:
81+
amxProgModel: ManagedRA
8182
body: |
8283
; CHECK-LABEL: name: test_api
8384
; CHECK: bb.0.entry:

llvm/test/CodeGen/X86/AMX/amx-fastpreconfig.mir

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ frameInfo:
2323
stack:
2424
- { id: 0, size: 1024, alignment: 16 }
2525
- { id: 1, size: 64, alignment: 4 }
26-
machineFunctionInfo: {}
26+
machineFunctionInfo:
27+
amxProgModel: ManagedRA
2728
body: |
2829
bb.0.entry:
2930
; CHECK-LABEL: name: main
@@ -79,6 +80,8 @@ registers:
7980
liveins:
8081
- { reg: '$rdi', virtual-reg: '' }
8182
- { reg: '$rsi', virtual-reg: '' }
83+
machineFunctionInfo:
84+
amxProgModel: ManagedRA
8285
body: |
8386
bb.1.entry:
8487
liveins: $rdi, $rsi

0 commit comments

Comments
 (0)