Skip to content

Commit 87599bd

Browse files
kito-chengtstellar
authored andcommitted
[RISCV] Store/restore RISCVMachineFunctionInfo into MIR YAML file
RISCVMachineFunctionInfo has some fields like VarArgsFrameIndex and VarArgsSaveSize are calculated at ISel lowering stage, those info are not contained in MIR files, that cause test cases rely on those field can't not reproduce correctly by MIR dump files. This patch adding the MIR read/write for those fields. Reviewed By: frasercrmck Differential Revision: https://reviews.llvm.org/D123178
1 parent 5c9eed7 commit 87599bd

File tree

6 files changed

+225
-0
lines changed

6 files changed

+225
-0
lines changed

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_llvm_target(RISCVCodeGen
3131
RISCVISelDAGToDAG.cpp
3232
RISCVISelLowering.cpp
3333
RISCVLegalizerInfo.cpp
34+
RISCVMachineFunctionInfo.cpp
3435
RISCVMCInstLower.cpp
3536
RISCVMergeBaseOffset.cpp
3637
RISCVRegisterBankInfo.cpp
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//=- RISCVMachineFunctionInfo.cpp - RISCV machine function info ---*- 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+
// This file declares RISCV-specific per-machine-function information.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "RISCVMachineFunctionInfo.h"
14+
15+
using namespace llvm;
16+
17+
yaml::RISCVMachineFunctionInfo::RISCVMachineFunctionInfo(
18+
const llvm::RISCVMachineFunctionInfo &MFI)
19+
: VarArgsFrameIndex(MFI.getVarArgsFrameIndex()),
20+
VarArgsSaveSize(MFI.getVarArgsSaveSize()) {}
21+
22+
void yaml::RISCVMachineFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
23+
MappingTraits<RISCVMachineFunctionInfo>::mapping(YamlIO, *this);
24+
}
25+
26+
void RISCVMachineFunctionInfo::initializeBaseYamlFields(
27+
const yaml::RISCVMachineFunctionInfo &YamlMFI) {
28+
VarArgsFrameIndex = YamlMFI.VarArgsFrameIndex;
29+
VarArgsSaveSize = YamlMFI.VarArgsSaveSize;
30+
}

llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,34 @@
1414
#define LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
1515

1616
#include "RISCVSubtarget.h"
17+
#include "llvm/CodeGen/MIRYamlMapping.h"
1718
#include "llvm/CodeGen/MachineFrameInfo.h"
1819
#include "llvm/CodeGen/MachineFunction.h"
1920

2021
namespace llvm {
2122

23+
class RISCVMachineFunctionInfo;
24+
25+
namespace yaml {
26+
struct RISCVMachineFunctionInfo final : public yaml::MachineFunctionInfo {
27+
int VarArgsFrameIndex;
28+
int VarArgsSaveSize;
29+
30+
RISCVMachineFunctionInfo() = default;
31+
RISCVMachineFunctionInfo(const llvm::RISCVMachineFunctionInfo &MFI);
32+
33+
void mappingImpl(yaml::IO &YamlIO) override;
34+
~RISCVMachineFunctionInfo() = default;
35+
};
36+
37+
template <> struct MappingTraits<RISCVMachineFunctionInfo> {
38+
static void mapping(IO &YamlIO, RISCVMachineFunctionInfo &MFI) {
39+
YamlIO.mapOptional("varArgsFrameIndex", MFI.VarArgsFrameIndex);
40+
YamlIO.mapOptional("varArgsSaveSize", MFI.VarArgsSaveSize);
41+
}
42+
};
43+
} // end namespace yaml
44+
2245
/// RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo
2346
/// and contains private RISCV-specific information for each MachineFunction.
2447
class RISCVMachineFunctionInfo : public MachineFunctionInfo {
@@ -74,6 +97,8 @@ class RISCVMachineFunctionInfo : public MachineFunctionInfo {
7497

7598
unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
7699
void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
100+
101+
void initializeBaseYamlFields(const yaml::RISCVMachineFunctionInfo &YamlMFI);
77102
};
78103

79104
} // end namespace llvm

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "RISCVTargetMachine.h"
1414
#include "MCTargetDesc/RISCVBaseInfo.h"
1515
#include "RISCV.h"
16+
#include "RISCVMachineFunctionInfo.h"
1617
#include "RISCVTargetObjectFile.h"
1718
#include "RISCVTargetTransformInfo.h"
1819
#include "TargetInfo/RISCVTargetInfo.h"
@@ -22,6 +23,8 @@
2223
#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
2324
#include "llvm/CodeGen/GlobalISel/Legalizer.h"
2425
#include "llvm/CodeGen/GlobalISel/RegBankSelect.h"
26+
#include "llvm/CodeGen/MIRParser/MIParser.h"
27+
#include "llvm/CodeGen/MIRYamlMapping.h"
2528
#include "llvm/CodeGen/Passes.h"
2629
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
2730
#include "llvm/CodeGen/TargetPassConfig.h"
@@ -208,3 +211,23 @@ void RISCVPassConfig::addPreRegAlloc() {
208211
addPass(createRISCVMergeBaseOffsetOptPass());
209212
addPass(createRISCVInsertVSETVLIPass());
210213
}
214+
215+
yaml::MachineFunctionInfo *
216+
RISCVTargetMachine::createDefaultFuncInfoYAML() const {
217+
return new yaml::RISCVMachineFunctionInfo();
218+
}
219+
220+
yaml::MachineFunctionInfo *
221+
RISCVTargetMachine::convertFuncInfoToYAML(const MachineFunction &MF) const {
222+
const auto *MFI = MF.getInfo<RISCVMachineFunctionInfo>();
223+
return new yaml::RISCVMachineFunctionInfo(*MFI);
224+
}
225+
226+
bool RISCVTargetMachine::parseMachineFunctionInfo(
227+
const yaml::MachineFunctionInfo &MFI, PerFunctionMIParsingState &PFS,
228+
SMDiagnostic &Error, SMRange &SourceRange) const {
229+
const auto &YamlMFI =
230+
static_cast<const yaml::RISCVMachineFunctionInfo &>(MFI);
231+
PFS.MF.getInfo<RISCVMachineFunctionInfo>()->initializeBaseYamlFields(YamlMFI);
232+
return false;
233+
}

llvm/lib/Target/RISCV/RISCVTargetMachine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ class RISCVTargetMachine : public LLVMTargetMachine {
4646

4747
virtual bool isNoopAddrSpaceCast(unsigned SrcAS,
4848
unsigned DstAS) const override;
49+
50+
yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override;
51+
yaml::MachineFunctionInfo *
52+
convertFuncInfoToYAML(const MachineFunction &MF) const override;
53+
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &,
54+
PerFunctionMIParsingState &PFS,
55+
SMDiagnostic &Error,
56+
SMRange &SourceRange) const override;
4957
};
5058
} // namespace llvm
5159

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# RUN: llc -mtriple=riscv64 -run-pass none %s -o - | FileCheck %s
2+
3+
--- |
4+
; ModuleID = 'foo.ll'
5+
source_filename = "foo.ll"
6+
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
7+
target triple = "riscv64"
8+
9+
define void @foo(i32 %0, ...) {
10+
ret void
11+
}
12+
13+
...
14+
---
15+
name: foo
16+
alignment: 4
17+
exposesReturnsTwice: false
18+
legalized: false
19+
regBankSelected: false
20+
selected: false
21+
failedISel: false
22+
tracksRegLiveness: true
23+
hasWinCFI: false
24+
failsVerification: false
25+
tracksDebugUserValues: false
26+
registers:
27+
- { id: 0, class: gpr, preferred-register: '' }
28+
- { id: 1, class: gpr, preferred-register: '' }
29+
- { id: 2, class: gpr, preferred-register: '' }
30+
- { id: 3, class: gpr, preferred-register: '' }
31+
- { id: 4, class: gpr, preferred-register: '' }
32+
- { id: 5, class: gpr, preferred-register: '' }
33+
- { id: 6, class: gpr, preferred-register: '' }
34+
- { id: 7, class: gpr, preferred-register: '' }
35+
liveins:
36+
- { reg: '$x11', virtual-reg: '%1' }
37+
- { reg: '$x12', virtual-reg: '%2' }
38+
- { reg: '$x13', virtual-reg: '%3' }
39+
- { reg: '$x14', virtual-reg: '%4' }
40+
- { reg: '$x15', virtual-reg: '%5' }
41+
- { reg: '$x16', virtual-reg: '%6' }
42+
- { reg: '$x17', virtual-reg: '%7' }
43+
frameInfo:
44+
isFrameAddressTaken: false
45+
isReturnAddressTaken: false
46+
hasStackMap: false
47+
hasPatchPoint: false
48+
stackSize: 0
49+
offsetAdjustment: 0
50+
maxAlignment: 1
51+
adjustsStack: false
52+
hasCalls: false
53+
stackProtector: ''
54+
maxCallFrameSize: 4294967295
55+
cvBytesOfCalleeSavedRegisters: 0
56+
hasOpaqueSPAdjustment: false
57+
hasVAStart: false
58+
hasMustTailInVarArgFunc: false
59+
hasTailCall: false
60+
localFrameSize: 0
61+
savePoint: ''
62+
restorePoint: ''
63+
fixedStack:
64+
- { id: 0, type: default, offset: -8, size: 8, alignment: 8, stack-id: default,
65+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
66+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
67+
- { id: 1, type: default, offset: -16, size: 8, alignment: 16, stack-id: default,
68+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
69+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
70+
- { id: 2, type: default, offset: -24, size: 8, alignment: 8, stack-id: default,
71+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
72+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
73+
- { id: 3, type: default, offset: -32, size: 8, alignment: 16, stack-id: default,
74+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
75+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
76+
- { id: 4, type: default, offset: -40, size: 8, alignment: 8, stack-id: default,
77+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
78+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
79+
- { id: 5, type: default, offset: -48, size: 8, alignment: 16, stack-id: default,
80+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
81+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
82+
- { id: 6, type: default, offset: -56, size: 8, alignment: 8, stack-id: default,
83+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
84+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
85+
- { id: 7, type: default, offset: -64, size: 8, alignment: 16, stack-id: default,
86+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
87+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
88+
- { id: 8, type: default, offset: -56, size: 8, alignment: 8, stack-id: default,
89+
isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
90+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
91+
stack: []
92+
callSites: []
93+
debugValueSubstitutions: []
94+
constants: []
95+
machineFunctionInfo:
96+
varArgsFrameIndex: -1
97+
varArgsSaveSize: 64
98+
body: |
99+
bb.0 (%ir-block.1):
100+
liveins: $x11, $x12, $x13, $x14, $x15, $x16, $x17
101+
; CHECK-LABEL: name: foo
102+
; CHECK: machineFunctionInfo:
103+
; CHECK-NEXT: varArgsFrameIndex: -1
104+
; CHECK-NEXT: varArgsSaveSize: 64
105+
; CHECK: liveins: $x11, $x12, $x13, $x14, $x15, $x16, $x17
106+
; CHECK-NEXT: {{ $}}
107+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x17
108+
; CHECK-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $x16
109+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:gpr = COPY $x15
110+
; CHECK-NEXT: [[COPY3:%[0-9]+]]:gpr = COPY $x14
111+
; CHECK-NEXT: [[COPY4:%[0-9]+]]:gpr = COPY $x13
112+
; CHECK-NEXT: [[COPY5:%[0-9]+]]:gpr = COPY $x12
113+
; CHECK-NEXT: [[COPY6:%[0-9]+]]:gpr = COPY $x11
114+
; CHECK-NEXT: SD [[COPY]], %fixed-stack.8, 0 :: (store (s64))
115+
; CHECK-NEXT: SD [[COPY1]], %fixed-stack.7, 0 :: (store (s64) into %fixed-stack.7, align 16)
116+
; CHECK-NEXT: SD [[COPY2]], %fixed-stack.6, 0 :: (store (s64))
117+
; CHECK-NEXT: SD [[COPY3]], %fixed-stack.5, 0 :: (store (s64) into %fixed-stack.5, align 16)
118+
; CHECK-NEXT: SD [[COPY4]], %fixed-stack.4, 0 :: (store (s64))
119+
; CHECK-NEXT: SD [[COPY5]], %fixed-stack.3, 0 :: (store (s64) into %fixed-stack.3, align 16)
120+
; CHECK-NEXT: SD [[COPY6]], %fixed-stack.2, 0 :: (store (s64))
121+
; CHECK-NEXT: PseudoRET
122+
%7:gpr = COPY $x17
123+
%6:gpr = COPY $x16
124+
%5:gpr = COPY $x15
125+
%4:gpr = COPY $x14
126+
%3:gpr = COPY $x13
127+
%2:gpr = COPY $x12
128+
%1:gpr = COPY $x11
129+
SD %7, %fixed-stack.0, 0 :: (store (s64))
130+
SD %6, %fixed-stack.1, 0 :: (store (s64) into %fixed-stack.1, align 16)
131+
SD %5, %fixed-stack.2, 0 :: (store (s64))
132+
SD %4, %fixed-stack.3, 0 :: (store (s64) into %fixed-stack.3, align 16)
133+
SD %3, %fixed-stack.4, 0 :: (store (s64))
134+
SD %2, %fixed-stack.5, 0 :: (store (s64) into %fixed-stack.5, align 16)
135+
SD %1, %fixed-stack.6, 0 :: (store (s64))
136+
PseudoRET
137+
138+
...

0 commit comments

Comments
 (0)