Skip to content

Commit

Permalink
parser: start using the SelectExpr negateCondition attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihalko committed Mar 14, 2024
1 parent ac88b7c commit d5c591e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions expr/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ bool GepExpr::classof(const Expr* expr) {
return expr->getKind() == EK_GepExpr;
}

SelectExpr::SelectExpr(Expr* comp, Expr* l, Expr* r, bool negateCondition = false) :
SelectExpr::SelectExpr(Expr* comp, Expr* l, Expr* r, bool negateCondition) :
ExprBase(EK_SelectExpr),
left(l),
right(r),
comp(comp)
comp(comp),
negateCondition(negateCondition) {
setType(l->getType());
}
Expand Down
2 changes: 1 addition & 1 deletion expr/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class SelectExpr : public ExprBase {
Expr* comp;
bool negateCondition;

SelectExpr(Expr*, Expr*, Expr*, bool negateCondition);
SelectExpr(Expr*, Expr*, Expr*, bool negateCondition = false);

void accept(ExprVisitor& visitor) override;

Expand Down
18 changes: 10 additions & 8 deletions parser/parseBreaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* return phi assignments as ExprList
*/
static std::vector<Expr*> generatePhiAssignments(Block* blockEnding, Block* nextBlock, bool isLoop = false) {
static std::vector<Expr*> generatePhiAssignments(Block* blockEnding, Block* nextBlock, bool isLoop = false, bool isNegated = false) {
std::vector<Expr*> exprs;

Program& program = *blockEnding->func->program;
Expand All @@ -35,7 +35,8 @@ static std::vector<Expr*> generatePhiAssignments(Block* blockEnding, Block* next
llvm::dyn_cast<llvm::BranchInst>(blockEnding->block->getTerminator())->getCondition()
),
incoming,
phiVar
phiVar,
isNegated
) : incoming));
}
}
Expand All @@ -44,10 +45,10 @@ static std::vector<Expr*> generatePhiAssignments(Block* blockEnding, Block* next
return exprs;
}

static Expr* createListOfOneGoto(Block* container, Block* gotoTarget, bool isLoop = false) {
static Expr* createListOfOneGoto(Block* container, Block* gotoTarget, bool isLoop = false, bool isNegated = false) {
auto gotoExpr = std::make_unique<GotoExpr>(gotoTarget);

std::vector<Expr*> exprs = generatePhiAssignments(container, gotoTarget, isLoop);
std::vector<Expr*> exprs = generatePhiAssignments(container, gotoTarget, isLoop, isNegated);
exprs.push_back(gotoExpr.get());
auto list = std::make_unique<ExprList>(std::move(exprs));

Expand Down Expand Up @@ -181,17 +182,18 @@ void parseLoop(Func* func, const llvm::Loop *loop) {
doWhileBodyExprs.push_back( gotoExpr.get() );

auto list = std::make_unique<ExprList>(std::move(doWhileBodyExprs));
auto doWhile = std::make_unique<DoWhile>( list.get() ,cmp);
auto whileCondIsTrueBlock = llvm::dyn_cast<llvm::BasicBlock>(doWhileTerminatorInst->getOperand(2));
auto doWhile = std::make_unique<DoWhile>( list.get(), cmp, whileCondIsTrueBlock != loop->getHeader());

loopPreheader->addOwnership(std::move( gotoExpr ));
loopPreheader->addOwnership(std::move( list ));

auto whileCondIsTrueBlock = llvm::dyn_cast<llvm::BasicBlock>(doWhileTerminatorInst->getOperand(2));
/*
auto doWhile = std::make_unique<DoWhile>(createListOfOneGoto( func->getBlock( loop->getLoopLatch() ),
doWhileBody, true /*isLoop = true*/),
doWhileBody, true , whileCondIsTrueBlock != loop->getHeader()),
cmp,
whileCondIsTrueBlock != loop->getHeader());

*/
// #4 it's safe to inline loopheader:
// loopHeader.succ_first() == loopLatch, loopHeader.succ_second() = loopPreheader
// we transform the edge from the loopLatch to loopHeader into to do{}while() block
Expand Down

0 comments on commit d5c591e

Please sign in to comment.