Skip to content

Commit

Permalink
Issue #59: Replace JUMPDEST with BEGINSUB at begin of functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lialan committed Apr 28, 2020
1 parent 6cf2cf9 commit e8c5a66
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/Target/EVM/EVMFinalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class EVMFinalization final : public MachineFunctionPass {

bool runOnMachineFunction(MachineFunction &MF) override;
bool shouldInsertJUMPDEST(MachineBasicBlock &MBB) const;
bool shouldInsertBEGINSUB(MachineBasicBlock &MBB) const;

void expandADJFP(MachineInstr *MI) const;
};
} // end anonymous namespace
Expand All @@ -56,6 +58,10 @@ FunctionPass *llvm::createEVMFinalization() {
}

bool EVMFinalization::shouldInsertJUMPDEST(MachineBasicBlock &MBB) const {
if (ST->hasSubroutine()) {
return false;
}

if (MBB.empty()) {
return false;
}
Expand All @@ -69,6 +75,14 @@ bool EVMFinalization::shouldInsertJUMPDEST(MachineBasicBlock &MBB) const {
return true;
}

bool EVMFinalization::shouldInsertBEGINSUB(MachineBasicBlock &MBB) const {
if (!ST->hasSubroutine()) {
return false;
}

return true;
}

void EVMFinalization::expandADJFP(MachineInstr* MI) const {
MachineBasicBlock* MBB = MI->getParent();
DebugLoc DL = MI->getDebugLoc();
Expand Down Expand Up @@ -116,11 +130,14 @@ bool EVMFinalization::runOnMachineFunction(MachineFunction &MF) {

//// TODO: we force each of those MBB's to have address taken.
//MBB.setHasAddressTaken();
MachineBasicBlock::iterator begin = MBB.begin();
if (shouldInsertJUMPDEST(MBB)) {
MachineBasicBlock::iterator begin = MBB.begin();
BuildMI(MBB, begin, begin->getDebugLoc(), TII->get(EVM::JUMPDEST));
} else if (shouldInsertBEGINSUB(MBB)) {
BuildMI(MBB, begin, begin->getDebugLoc(), TII->get(EVM::BEGINSUB));
}


// use iterator since we need to remove pseudo instructions
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
I != E;) {
Expand Down

0 comments on commit e8c5a66

Please sign in to comment.