Skip to content

Commit

Permalink
Remove code adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jun 19, 2024
1 parent 20400f8 commit 468404e
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 328 deletions.
88 changes: 0 additions & 88 deletions llvm/lib/Target/SBF/SBFAdjustOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class SBFAdjustOptImpl {
Module *M;
SmallVector<PassThroughInfo, 16> PassThroughs;

void adjustBasicBlock(BasicBlock &BB);
bool serializeICMPCrossBB(BasicBlock &BB);
void adjustInst(Instruction &I);
bool serializeICMPInBB(Instruction &I);
bool avoidSpeculation(Instruction &I);
Expand All @@ -70,7 +68,6 @@ class SBFAdjustOptImpl {
bool SBFAdjustOptImpl::run() {
for (Function &F : *M)
for (auto &BB : F) {
adjustBasicBlock(BB);
for (auto &I : BB)
adjustInst(I);
}
Expand Down Expand Up @@ -122,86 +119,6 @@ bool SBFAdjustOptImpl::serializeICMPInBB(Instruction &I) {
return true;
}

// To avoid combining conditionals in the same basic block by
// instrcombine optimization.
bool SBFAdjustOptImpl::serializeICMPCrossBB(BasicBlock &BB) {
// For:
// B1:
// comp1 = icmp <opcode> ...;
// if (comp1) goto B2 else B3;
// B2:
// comp2 = icmp <opcode> ...;
// if (comp2) goto B4 else B5;
// B4:
// ...
// changed to:
// B1:
// comp1 = icmp <opcode> ...;
// comp1 = __builtin_bpf_passthrough(seq_num, comp1);
// if (comp1) goto B2 else B3;
// B2:
// comp2 = icmp <opcode> ...;
// if (comp2) goto B4 else B5;
// B4:
// ...

// Check basic predecessors, if two of them (say B1, B2) are using
// icmp instructions to generate conditions and one is the predesessor
// of another (e.g., B1 is the predecessor of B2). Add a passthrough
// barrier after icmp inst of block B1.
BasicBlock *B2 = BB.getSinglePredecessor();
if (!B2)
return false;

BasicBlock *B1 = B2->getSinglePredecessor();
if (!B1)
return false;

Instruction *TI = B2->getTerminator();
auto *BI = dyn_cast<BranchInst>(TI);
if (!BI || !BI->isConditional())
return false;
auto *Cond = dyn_cast<ICmpInst>(BI->getCondition());
if (!Cond || B2->getFirstNonPHI() != Cond)
return false;
Value *B2Op0 = Cond->getOperand(0);
auto Cond2Op = Cond->getPredicate();

TI = B1->getTerminator();
BI = dyn_cast<BranchInst>(TI);
if (!BI || !BI->isConditional())
return false;
Cond = dyn_cast<ICmpInst>(BI->getCondition());
if (!Cond)
return false;
Value *B1Op0 = Cond->getOperand(0);
auto Cond1Op = Cond->getPredicate();

if (B1Op0 != B2Op0)
return false;

if (Cond1Op == ICmpInst::ICMP_SGT || Cond1Op == ICmpInst::ICMP_SGE) {
if (Cond2Op != ICmpInst::ICMP_SLT && Cond2Op != ICmpInst::ICMP_SLE)
return false;
} else if (Cond1Op == ICmpInst::ICMP_SLT || Cond1Op == ICmpInst::ICMP_SLE) {
if (Cond2Op != ICmpInst::ICMP_SGT && Cond2Op != ICmpInst::ICMP_SGE)
return false;
} else if (Cond1Op == ICmpInst::ICMP_ULT || Cond1Op == ICmpInst::ICMP_ULE) {
if (Cond2Op != ICmpInst::ICMP_UGT && Cond2Op != ICmpInst::ICMP_UGE)
return false;
} else if (Cond1Op == ICmpInst::ICMP_UGT || Cond1Op == ICmpInst::ICMP_UGE) {
if (Cond2Op != ICmpInst::ICMP_ULT && Cond2Op != ICmpInst::ICMP_ULE)
return false;
} else {
return false;
}

PassThroughInfo Info(Cond, BI, 0);
PassThroughs.push_back(Info);

return true;
}

// To avoid speculative hoisting certain computations out of
// a basic block.
bool SBFAdjustOptImpl::avoidSpeculation(Instruction &I) {
Expand Down Expand Up @@ -297,11 +214,6 @@ bool SBFAdjustOptImpl::avoidSpeculation(Instruction &I) {
return true;
}

void SBFAdjustOptImpl::adjustBasicBlock(BasicBlock &BB) {
if (!DisableSBFserializeICMP && serializeICMPCrossBB(BB))
return;
}

void SBFAdjustOptImpl::adjustInst(Instruction &I) {
if (!DisableSBFserializeICMP && serializeICMPInBB(I))
return;
Expand Down
98 changes: 0 additions & 98 deletions llvm/test/CodeGen/SBF/adjust-opt-icmp2.ll

This file was deleted.

71 changes: 0 additions & 71 deletions llvm/test/CodeGen/SBF/adjust-opt-icmp5.ll

This file was deleted.

71 changes: 0 additions & 71 deletions llvm/test/CodeGen/SBF/adjust-opt-icmp6.ll

This file was deleted.

0 comments on commit 468404e

Please sign in to comment.