Skip to content

Commit

Permalink
Issue #28: Rearrange return address stack argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
lialan committed Nov 18, 2019
1 parent 6271ae1 commit 00652e1
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions lib/Target/EVM/EVMArgumentMove.cpp
Original file line number Diff line number Diff line change
@@ -89,8 +89,8 @@ void EVMArgumentMove::arrangeStackArgs(MachineFunction& MF) const {
unsigned returnAddrReg = 0;

// the stack arrangement is:
// (top) 1st argument, 2nd argument, 3rd argument, ... (bottom)
for (int i = stackargs.size() - 1; i >= 0 ; --i) {
// (top) 1st argument, 2nd argument, 3rd argument, ..., return address (bottom)
for (int i = stackargs.size() - 1; i >= 1 ; --i) {
// create the instruction, and insert it
if (!stackargs[i]) {
MachineBasicBlock::iterator insertPt = EntryMBB.begin();
@@ -114,7 +114,7 @@ void EVMArgumentMove::arrangeStackArgs(MachineFunction& MF) const {
unsigned destReg = MRI.createVirtualRegister(&EVM::GPRRegClass);
auto bmi = BuildMI(EntryMBB, EntryMBB.front(), EntryMBB.front().getDebugLoc(),
TII->get(EVM::pSTACKARG_r), destReg)
.addImm(256);
.addImm(0);
returnAddrReg = destReg;

LLVM_DEBUG({
@@ -177,12 +177,17 @@ bool EVMArgumentMove::runOnMachineFunction(MachineFunction &MF) {
if (EVMArgumentMove::isStackArg(MI)) {
MachineOperand &MO = MI.getOperand(1);
unsigned index = MO.getImm();
if (index == 256) continue;

LLVM_DEBUG({
dbgs() << "Inserting index2mi: " << index << ", ";
MI.dump();
});

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

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

// record unused stack arguments so we can pop it later.
bool IsDead = MRI.use_empty(reg);
if (IsDead) {
LLVM_DEBUG({
4 changes: 2 additions & 2 deletions lib/Target/EVM/EVMISelLowering.cpp
Original file line number Diff line number Diff line change
@@ -508,8 +508,8 @@ SDValue EVMTargetLowering::LowerFormalArguments(
for (const ISD::InputArg &In __attribute__((unused)) : Ins) {
SmallVector<SDValue, 4> Opnds;


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

0 comments on commit 00652e1

Please sign in to comment.