Skip to content

Commit

Permalink
[EVM] Refactor EVMStackLayoutGenerator to use LLVM API more broadly
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelKopyl authored and akiramenai committed Jan 27, 2025
1 parent bcfffd1 commit 313b5f2
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 399 deletions.
1 change: 0 additions & 1 deletion llvm/lib/Target/EVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ add_llvm_target(EVMCodeGen
EVMBackwardPropagationStackification.cpp
EVMCodegenPrepare.cpp
EVMFrameLowering.cpp
EVMHelperUtilities.cpp
EVMISelDAGToDAG.cpp
EVMISelLowering.cpp
EVMInstrInfo.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool EVMBPStackification::runOnMachineFunction(MachineFunction &MF) {
EVMMachineCFGInfo CFGInfo(MF, MLI);
EVMStackModel StackModel(MF, LIS);
std::unique_ptr<EVMStackLayout> Layout =
EVMStackLayoutGenerator(MF, StackModel, CFGInfo).run();
EVMStackLayoutGenerator(MF, MLI, StackModel, CFGInfo).run();
EVMStackifyCodeEmitter(*Layout, StackModel, CFGInfo, MF).run();
return true;
}
27 changes: 0 additions & 27 deletions llvm/lib/Target/EVM/EVMHelperUtilities.cpp

This file was deleted.

110 changes: 0 additions & 110 deletions llvm/lib/Target/EVM/EVMHelperUtilities.h

This file was deleted.

8 changes: 2 additions & 6 deletions llvm/lib/Target/EVM/EVMMachineCFGInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

#include "EVMMachineCFGInfo.h"
#include "EVMHelperUtilities.h"
#include "EVMMachineFunctionInfo.h"
#include "EVMSubtarget.h"
#include "MCTargetDesc/EVMMCTargetDesc.h"
Expand Down Expand Up @@ -98,9 +97,6 @@ void EVMMachineCFGInfo::collectTerminatorsInfo(const TargetInstrInfo *TII,
return;
}

bool IsLatch = false;
if (MachineLoop *ML = MLI->getLoopFor(&MBB))
IsLatch = ML->isLoopLatch(&MBB);
auto [CondBr, UncondBr] = getBranchInstructions(MBB);
if (!TBB || (TBB && Cond.empty())) {
// Fall through, or unconditional jump.
Expand All @@ -111,10 +107,10 @@ void EVMMachineCFGInfo::collectTerminatorsInfo(const TargetInstrInfo *TII,
TBB = MBB.getFallThrough();
assert(TBB);
}

Info->ExitType = MBBExitType::UnconditionalBranch;
Info->BranchInfo.Unconditional = {TBB, UncondBr, IsLatch};
Info->BranchInfo.Unconditional = {TBB, UncondBr};
} else if (TBB && !Cond.empty()) {
assert(!IsLatch);
// Conditional jump + fallthrough, or
// conditional jump followed by unconditional jump).
if (!FBB) {
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/EVM/EVMMachineCFGInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class EVMMBBTerminatorsInfo {
struct {
MachineBasicBlock *TargetBB;
MachineInstr *Br;
bool IsLatch;
} Unconditional;
} BranchInfo;

Expand All @@ -73,11 +72,10 @@ class EVMMBBTerminatorsInfo {
BranchInfo.Conditional.Condition};
}

std::tuple<MachineInstr *, MachineBasicBlock *, bool>
std::pair<MachineInstr *, MachineBasicBlock *>
getUnconditionalBranch() const {
assert(ExitType == MBBExitType::UnconditionalBranch);
return {BranchInfo.Unconditional.Br, BranchInfo.Unconditional.TargetBB,
BranchInfo.Unconditional.IsLatch};
return {BranchInfo.Unconditional.Br, BranchInfo.Unconditional.TargetBB};
}

MachineInstr *getFunctionReturn() const {
Expand Down
10 changes: 6 additions & 4 deletions llvm/lib/Target/EVM/EVMStackDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
//===----------------------------------------------------------------------===//

#include "EVMStackDebug.h"
#include "EVMHelperUtilities.h"
#include "EVMStackLayoutGenerator.h"
#include "EVMSubtarget.h"
#include "MCTargetDesc/EVMMCTargetDesc.h"
#include <variant>

using namespace llvm;

template <class... Ts> struct Overload : Ts... {
using Ts::operator()...;
};
template <class... Ts> Overload(Ts...) -> Overload<Ts...>;

static std::string getInstName(const MachineInstr *MI) {
const MachineFunction *MF = MI->getParent()->getParent();
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
Expand Down Expand Up @@ -140,11 +144,9 @@ void StackLayoutPrinter::printBlock(MachineBasicBlock const &Block) {
const EVMMBBTerminatorsInfo *TermInfo = CFGInfo.getTerminatorsInfo(&Block);
MBBExitType ExitType = TermInfo->getExitType();
if (ExitType == MBBExitType::UnconditionalBranch) {
auto [BranchInstr, Target, IsLatch] = TermInfo->getUnconditionalBranch();
auto [BranchInstr, Target] = TermInfo->getUnconditionalBranch();
OS << "Block" << getBlockId(Block) << "Exit [label=\"";
OS << "Jump\"];\n";
if (IsLatch)
OS << "Backwards";
OS << "Block" << getBlockId(Block) << "Exit -> Block" << getBlockId(*Target)
<< ";\n";
} else if (ExitType == MBBExitType::ConditionalBranch) {
Expand Down
Loading

0 comments on commit 313b5f2

Please sign in to comment.