-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathI8080FrameLowering.cpp
101 lines (100 loc) · 3.19 KB
/
I8080FrameLowering.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Target/TargetOptions.h"
using namespace llvm;
//
//static unsigned materializeOffset(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned Offset) {
// const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
// DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() :
// DebugLoc();
// const uint64_t MaxSubImm = 0xfff;
// if (Offset <= MaxSubImm) {
// return 0;
// }
// else {
// unsigned OffsetReg = TOY::R2;
// unsigned OffsetLo = (unsigned)(Offset & 0xffff);
// unsigned OffsetHi = (unsigned)((Offset & 0xffff0000) >> 16);
// BuildMI(MBB, MBBI, dl, TII.get(TOY::MOVLOi16), OffsetReg)
// .addImm(OffsetLo)
// .setMIFlag(MachineInstr::FrameSetup);
// if (OffsetHi) {
// BuildMI(MBB, MBBI, dl, TII.get(TOY::MOVHIi16), OffsetReg)
// .addReg(OffsetReg)
// .addImm(OffsetHi)
// .setMIFlag(MachineInstr::FrameSetup);
// }
// return OffsetReg;
// }
//}
//
//
//uint64_t I8080FrameLowering::computeStackSize(MachineFunction &MF) const {
// MachineFrameInfo *MFI = MF.getFrameInfo();
// uint64_t StackSize = MFI->getStackSize();
// unsigned StackAlign = getStackAlignment();
// if (StackAlign > 0) {
// StackSize = RoundUpToAlignment(StackSize, StackAlign);
// }
// return StackSize;
//}
//
//
//void I8080FrameLowering::emitPrologue(MachineFunction &MF) const {
// const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
// MachineBasicBlock &MBB = MF.front();
// MachineBasicBlock::iterator MBBI = MBB.begin();
// DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() :
// DebugLoc();
// uint64_t StackSize = computeStackSize(MF);
// if (!StackSize) {
// return;
// }
// unsigned StackReg = TOY::SP;
// unsigned OffsetReg = materializeOffset(MF, MBB, MBBI, (unsigned)StackSize);
// if (OffsetReg) {
// BuildMI(MBB, MBBI, dl, TII.get(TOY::SUBrr), StackReg)
// .addReg(StackReg)
// .addReg(OffsetReg)
// .setMIFlag(MachineInstr::FrameSetup);
// }
// else {
// BuildMI(MBB, MBBI, dl, TII.get(TOY::SUBri), StackReg)
// .addReg(StackReg)
// .addImm(StackSize)
// .setMIFlag(MachineInstr::FrameSetup);
// }
//}
//
//
//void I8080FrameLowering::emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const {
// const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
// MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
// DebugLoc dl = MBBI->getDebugLoc();
// uint64_t StackSize = computeStackSize(MF);
// if (!StackSize) {
// return;
// }
// unsigned StackReg = TOY::SP;
// unsigned OffsetReg = materializeOffset(MF, MBB, MBBI, (unsigned)StackSize);
// if (OffsetReg) {
// BuildMI(MBB, MBBI, dl, TII.get(TOY::ADDrr), StackReg)
// .addReg(StackReg)
// .addReg(OffsetReg)
// .setMIFlag(MachineInstr::FrameSetup);
// }
// else {
// BuildMI(MBB, MBBI, dl, TII.get(TOY::ADDri), StackReg)
// .addReg(StackReg)
// .addImm(StackSize)
// .setMIFlag(MachineInstr::FrameSetup);
// }
//}
//