@@ -89,8 +89,8 @@ void EVMArgumentMove::arrangeStackArgs(MachineFunction& MF) const {
89
89
unsigned returnAddrReg = 0 ;
90
90
91
91
// the stack arrangement is:
92
- // (top) 1st argument, 2nd argument, 3rd argument, ... (bottom)
93
- for (int i = stackargs.size () - 1 ; i >= 0 ; --i) {
92
+ // (top) 1st argument, 2nd argument, 3rd argument, ..., return address (bottom)
93
+ for (int i = stackargs.size () - 1 ; i >= 1 ; --i) {
94
94
// create the instruction, and insert it
95
95
if (!stackargs[i]) {
96
96
MachineBasicBlock::iterator insertPt = EntryMBB.begin ();
@@ -114,7 +114,7 @@ void EVMArgumentMove::arrangeStackArgs(MachineFunction& MF) const {
114
114
unsigned destReg = MRI.createVirtualRegister (&EVM::GPRRegClass);
115
115
auto bmi = BuildMI (EntryMBB, EntryMBB.front (), EntryMBB.front ().getDebugLoc (),
116
116
TII->get (EVM::pSTACKARG_r), destReg)
117
- .addImm (256 );
117
+ .addImm (0 );
118
118
returnAddrReg = destReg;
119
119
120
120
LLVM_DEBUG ({
@@ -177,12 +177,17 @@ bool EVMArgumentMove::runOnMachineFunction(MachineFunction &MF) {
177
177
if (EVMArgumentMove::isStackArg (MI)) {
178
178
MachineOperand &MO = MI.getOperand (1 );
179
179
unsigned index = MO.getImm ();
180
- if (index == 256 ) continue ;
180
+
181
+ LLVM_DEBUG ({
182
+ dbgs () << " Inserting index2mi: " << index << " , " ;
183
+ MI.dump ();
184
+ });
181
185
182
186
index2mi.insert (std::pair<unsigned , MachineInstr *>(index , &MI));
183
187
184
188
unsigned reg = MI.getOperand (0 ).getReg ();
185
189
190
+ // record unused stack arguments so we can pop it later.
186
191
bool IsDead = MRI.use_empty (reg);
187
192
if (IsDead) {
188
193
LLVM_DEBUG ({
0 commit comments