forked from OSchip/llvm-project
parent
9425afd6b5
commit
ac525ded21
|
@ -25,19 +25,14 @@
|
|||
|
||||
namespace Fortran::FIR {
|
||||
namespace {
|
||||
const Expression &ExprRef(const parser::Expr &a) {
|
||||
Expression *ExprRef(const parser::Expr &a) {
|
||||
CHECK(a.typedExpr);
|
||||
CHECK(a.typedExpr->v);
|
||||
return *a.typedExpr->v;
|
||||
return &*a.typedExpr->v;
|
||||
}
|
||||
const Expression &ExprRef(const common::Indirection<parser::Expr> &a) {
|
||||
Expression *ExprRef(const common::Indirection<parser::Expr> &a) {
|
||||
return ExprRef(a.value());
|
||||
}
|
||||
const Expression &ExprRef(const parser::Variable &a) {
|
||||
CHECK(a.typedExpr);
|
||||
CHECK(a.typedExpr->v);
|
||||
return *a.typedExpr->v;
|
||||
}
|
||||
|
||||
template<typename STMTTYPE, typename CT>
|
||||
const std::optional<parser::Name> &GetSwitchAssociateName(
|
||||
|
@ -146,7 +141,7 @@ static std::vector<SwitchRankStmt::ValueType> populateSwitchValues(
|
|||
common::visitors{
|
||||
[&](const parser::ScalarIntConstantExpr &exp) {
|
||||
const auto &e{exp.thing.thing.thing.value()};
|
||||
result.emplace_back(SwitchRankStmt::Exactly{&ExprRef(e)});
|
||||
result.emplace_back(SwitchRankStmt::Exactly{ExprRef(e)});
|
||||
},
|
||||
[&](const parser::Star &) {
|
||||
result.emplace_back(SwitchRankStmt::AssumedSize{});
|
||||
|
@ -542,7 +537,7 @@ public:
|
|||
return builder_->CreateExpr(ExprRef(e));
|
||||
},
|
||||
[&](const parser::Variable &v) {
|
||||
return builder_->CreateExpr(ExprRef(v));
|
||||
return builder_->CreateExpr(ToExpression(v));
|
||||
},
|
||||
},
|
||||
std::get<parser::Selector>(
|
||||
|
@ -637,7 +632,7 @@ public:
|
|||
// TODO: check if allocation or reallocation should happen, etc.
|
||||
auto *value{builder_->CreateExpr(ExprRef(std::get<parser::Expr>(stmt.t)))};
|
||||
auto addr{
|
||||
builder_->CreateAddr(ExprRef(std::get<parser::Variable>(stmt.t)))};
|
||||
builder_->CreateAddr(ToExpression(std::get<parser::Variable>(stmt.t)))};
|
||||
builder_->CreateStore(addr, value);
|
||||
}
|
||||
void handleDefinedAssignmentStmt(const parser::AssignmentStmt &stmt) {
|
||||
|
@ -665,10 +660,10 @@ public:
|
|||
std::visit(
|
||||
common::visitors{
|
||||
[&](const parser::AllocOpt::Mold &m) {
|
||||
opts.mold = ExprRef(m.v);
|
||||
opts.mold = *ExprRef(m.v);
|
||||
},
|
||||
[&](const parser::AllocOpt::Source &s) {
|
||||
opts.source = ExprRef(s.v);
|
||||
opts.source = *ExprRef(s.v);
|
||||
},
|
||||
[&](const parser::StatOrErrmsg &var) {
|
||||
std::visit(
|
||||
|
@ -932,7 +927,7 @@ public:
|
|||
if (info->stepExpr) {
|
||||
Expression compare{ConsExpr(common::RelationalOperator::GT,
|
||||
getLocalVariable(info->counter), CreateConstant(0))};
|
||||
auto *cond{builder_->CreateExpr(std::move(compare))};
|
||||
auto *cond{builder_->CreateExpr(&compare)};
|
||||
info->condition = cond;
|
||||
}
|
||||
}
|
||||
|
@ -942,8 +937,12 @@ public:
|
|||
void InitiateConstruct(const parser::AssociateStmt *stmt) {
|
||||
for (auto &assoc : std::get<std::list<parser::Association>>(stmt->t)) {
|
||||
auto &selector{std::get<parser::Selector>(assoc.t)};
|
||||
auto *expr{builder_->CreateExpr(
|
||||
std::visit([](const auto &x) { return ExprRef(x); }, selector.u))};
|
||||
auto *expr{builder_->CreateExpr(std::visit(
|
||||
common::visitors{
|
||||
[&](const parser::Variable &v) { return ToExpression(v); },
|
||||
[](const parser::Expr &e) { return *ExprRef(e); },
|
||||
},
|
||||
selector.u))};
|
||||
auto name{
|
||||
builder_->CreateAddr(ToExpression(std::get<parser::Name>(assoc.t)))};
|
||||
builder_->CreateStore(name, expr);
|
||||
|
@ -1000,7 +999,7 @@ public:
|
|||
getApplyExpr(e2), getApplyExpr(e1)),
|
||||
getApplyExpr(e3)),
|
||||
getApplyExpr(e3))};
|
||||
auto *totalTrips{builder_->CreateExpr(std::move(tripExpr))};
|
||||
auto *totalTrips{builder_->CreateExpr(&tripExpr)};
|
||||
builder_->CreateStore(tripCounter, totalTrips);
|
||||
PushDoContext(stmt, name, tripCounter, e3);
|
||||
},
|
||||
|
@ -1041,7 +1040,8 @@ public:
|
|||
return doMap_.find(stmt)->second.condition;
|
||||
},
|
||||
[&](const parser::ScalarLogicalExpr &sle) {
|
||||
const auto &exp{sle.thing.thing};
|
||||
auto &exp{sle.thing.thing.value()};
|
||||
SEMANTICS_CHECK(ExprRef(exp), "DO WHILE condition missing");
|
||||
return builder_->CreateExpr(ExprRef(exp));
|
||||
},
|
||||
[&](const parser::LoopControl::Concurrent &concurrent) {
|
||||
|
@ -1129,7 +1129,7 @@ public:
|
|||
[&](const parser::ReturnStmt *s) {
|
||||
// alt-return
|
||||
if (s->v) {
|
||||
const auto &exp{ExprRef(s->v->thing.thing)};
|
||||
auto *exp{ExprRef(s->v->thing.thing)};
|
||||
auto app{builder_->QualifiedCreateExpr(exp)};
|
||||
builder_->CreateReturn(app);
|
||||
} else {
|
||||
|
@ -1155,20 +1155,26 @@ public:
|
|||
const auto &exp{std::get<parser::ScalarLogicalExpr>(
|
||||
s->statement.t)
|
||||
.thing.thing.value()};
|
||||
SEMANTICS_CHECK(ExprRef(exp),
|
||||
"IF THEN condition expression missing");
|
||||
auto *cond{builder_->CreateExpr(ExprRef(exp))};
|
||||
AddOrQueueCGoto(cond, cop.trueLabel, cop.falseLabel);
|
||||
},
|
||||
[&](const parser::Statement<parser::ElseIfStmt> *s) {
|
||||
const auto &exp{std::get<parser::ScalarLogicalExpr>(
|
||||
s->statement.t)
|
||||
.thing.thing};
|
||||
.thing.thing.value()};
|
||||
SEMANTICS_CHECK(ExprRef(exp),
|
||||
"ELSE IF condition expression missing");
|
||||
auto *cond{builder_->CreateExpr(ExprRef(exp))};
|
||||
AddOrQueueCGoto(cond, cop.trueLabel, cop.falseLabel);
|
||||
},
|
||||
[&](const parser::IfStmt *s) {
|
||||
const auto &exp{
|
||||
std::get<parser::ScalarLogicalExpr>(s->t)
|
||||
.thing.thing};
|
||||
.thing.thing.value()};
|
||||
SEMANTICS_CHECK(
|
||||
ExprRef(exp), "IF condition expression missing");
|
||||
auto *cond{builder_->CreateExpr(ExprRef(exp))};
|
||||
AddOrQueueCGoto(cond, cop.trueLabel, cop.falseLabel);
|
||||
},
|
||||
|
|
|
@ -56,7 +56,7 @@ struct FIRBuilder {
|
|||
BasicBlock *GetInsertionPoint() const { return cursorBlock_; }
|
||||
|
||||
// create the various statements
|
||||
QualifiedStmt<Addressable_impl> CreateAddr(const Expression &e) {
|
||||
QualifiedStmt<Addressable_impl> CreateAddr(const Expression *e) {
|
||||
return QualifiedInsert<Addressable_impl>(LocateExprStmt::Create(e));
|
||||
}
|
||||
QualifiedStmt<Addressable_impl> CreateAddr(Expression &&e) {
|
||||
|
@ -80,16 +80,16 @@ struct FIRBuilder {
|
|||
Statement *CreateDealloc(QualifiedStmt<AllocateInsn> alloc) {
|
||||
return Insert(DeallocateInsn::Create(alloc));
|
||||
}
|
||||
Statement *CreateExpr(const Expression &e) {
|
||||
Statement *CreateExpr(const Expression *e) {
|
||||
return Insert(ApplyExprStmt::Create(e));
|
||||
}
|
||||
Statement *CreateExpr(Expression &&e) {
|
||||
return Insert(ApplyExprStmt::Create(std::move(e)));
|
||||
}
|
||||
ApplyExprStmt *MakeAsExpr(const Expression &e) {
|
||||
ApplyExprStmt *MakeAsExpr(const Expression *e) {
|
||||
return GetApplyExpr(CreateExpr(e));
|
||||
}
|
||||
QualifiedStmt<ApplyExprStmt> QualifiedCreateExpr(const Expression &e) {
|
||||
QualifiedStmt<ApplyExprStmt> QualifiedCreateExpr(const Expression *e) {
|
||||
return QualifiedInsert<ApplyExprStmt>(ApplyExprStmt::Create(e));
|
||||
}
|
||||
QualifiedStmt<ApplyExprStmt> QualifiedCreateExpr(Expression &&e) {
|
||||
|
|
|
@ -230,7 +230,7 @@ public:
|
|||
struct Default {}; // RANK DEFAULT
|
||||
struct AssumedSize {}; // RANK(*)
|
||||
struct Exactly { // RANK(n)
|
||||
const Expression *v;
|
||||
Expression *v;
|
||||
};
|
||||
using ValueType = std::variant<Exactly, AssumedSize, Default>;
|
||||
using ValueSuccPairType = std::pair<ValueType, BasicBlock *>;
|
||||
|
@ -295,7 +295,7 @@ protected:
|
|||
// Compute the value of an expression
|
||||
class ApplyExprStmt : public ActionStmt_impl {
|
||||
public:
|
||||
static ApplyExprStmt Create(const Expression &e) { return ApplyExprStmt{e}; }
|
||||
static ApplyExprStmt Create(const Expression *e) { return ApplyExprStmt{*e}; }
|
||||
static ApplyExprStmt Create(Expression &&e) {
|
||||
return ApplyExprStmt{std::move(e)};
|
||||
}
|
||||
|
@ -323,8 +323,8 @@ protected:
|
|||
// Compute the location of an expression
|
||||
class LocateExprStmt : public Addressable_impl {
|
||||
public:
|
||||
static LocateExprStmt Create(const Expression &e) {
|
||||
return LocateExprStmt(e);
|
||||
static LocateExprStmt Create(const Expression *e) {
|
||||
return LocateExprStmt(*e);
|
||||
}
|
||||
static LocateExprStmt Create(Expression &&e) { return LocateExprStmt(e); }
|
||||
|
||||
|
|
Loading…
Reference in New Issue