Skip to content

Commit 00652e1

Browse files
committed
Issue #28: Rearrange return address stack argument.
1 parent 6271ae1 commit 00652e1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/Target/EVM/EVMArgumentMove.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ void EVMArgumentMove::arrangeStackArgs(MachineFunction& MF) const {
8989
unsigned returnAddrReg = 0;
9090

9191
// 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) {
9494
// create the instruction, and insert it
9595
if (!stackargs[i]) {
9696
MachineBasicBlock::iterator insertPt = EntryMBB.begin();
@@ -114,7 +114,7 @@ void EVMArgumentMove::arrangeStackArgs(MachineFunction& MF) const {
114114
unsigned destReg = MRI.createVirtualRegister(&EVM::GPRRegClass);
115115
auto bmi = BuildMI(EntryMBB, EntryMBB.front(), EntryMBB.front().getDebugLoc(),
116116
TII->get(EVM::pSTACKARG_r), destReg)
117-
.addImm(256);
117+
.addImm(0);
118118
returnAddrReg = destReg;
119119

120120
LLVM_DEBUG({
@@ -177,12 +177,17 @@ bool EVMArgumentMove::runOnMachineFunction(MachineFunction &MF) {
177177
if (EVMArgumentMove::isStackArg(MI)) {
178178
MachineOperand &MO = MI.getOperand(1);
179179
unsigned index = MO.getImm();
180-
if (index == 256) continue;
180+
181+
LLVM_DEBUG({
182+
dbgs() << "Inserting index2mi: " << index << ", ";
183+
MI.dump();
184+
});
181185

182186
index2mi.insert(std::pair<unsigned, MachineInstr *>(index, &MI));
183187

184188
unsigned reg = MI.getOperand(0).getReg();
185189

190+
// record unused stack arguments so we can pop it later.
186191
bool IsDead = MRI.use_empty(reg);
187192
if (IsDead) {
188193
LLVM_DEBUG({

lib/Target/EVM/EVMISelLowering.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ SDValue EVMTargetLowering::LowerFormalArguments(
508508
for (const ISD::InputArg &In __attribute__((unused)) : Ins) {
509509
SmallVector<SDValue, 4> Opnds;
510510

511-
512-
const SDValue &idx = DAG.getTargetConstant(InVals.size(),
511+
// the index starts with 1. the zero index is left for return address
512+
const SDValue &idx = DAG.getTargetConstant(InVals.size() + 1,
513513
DL, MVT::i64);
514514
Opnds.push_back(idx);
515515
//Opnds.push_back(Chain);

0 commit comments

Comments
 (0)