[flang] Some initial bridge code

add QualifiedStmt class

Original-commit: flang-compiler/f18@b2d89fe696
This commit is contained in:
Eric Schweitz 2019-04-01 11:09:03 -07:00
parent bb832078a1
commit 0b7fa133ae
6 changed files with 128 additions and 65 deletions

View File

@ -17,3 +17,4 @@ add_subdirectory(evaluate)
add_subdirectory(FIR)
add_subdirectory(parser)
add_subdirectory(semantics)
add_subdirectory(bridge)

View File

@ -137,19 +137,18 @@ static std::vector<SwitchRankStmt::ValueType> populateSwitchValues(
auto &rank{std::get<parser::SelectRankCaseStmt::Rank>(
std::get<parser::Statement<parser::SelectRankCaseStmt>>(v.t)
.statement.t)};
std::visit(
common::visitors{
[&](const parser::ScalarIntConstantExpr &exp) {
const auto &e{exp.thing.thing.thing.value()};
result.emplace_back(SwitchRankStmt::Exactly{ExprRef(e)});
},
[&](const parser::Star &) {
result.emplace_back(SwitchRankStmt::AssumedSize{});
},
[&](const parser::Default &) {
result.emplace_back(SwitchRankStmt::Default{});
},
},
std::visit(common::visitors{
[&](const parser::ScalarIntConstantExpr &exp) {
const auto &e{exp.thing.thing.thing.value()};
result.emplace_back(SwitchRankStmt::Exactly{ExprRef(e)});
},
[&](const parser::Star &) {
result.emplace_back(SwitchRankStmt::AssumedSize{});
},
[&](const parser::Default &) {
result.emplace_back(SwitchRankStmt::Default{});
},
},
rank.u);
}
return result;
@ -161,19 +160,19 @@ static std::vector<SwitchTypeStmt::ValueType> populateSwitchValues(
for (auto &v : list) {
auto &guard{std::get<parser::TypeGuardStmt::Guard>(
std::get<parser::Statement<parser::TypeGuardStmt>>(v.t).statement.t)};
std::visit(
common::visitors{
[&](const parser::TypeSpec &spec) {
result.emplace_back(SwitchTypeStmt::TypeSpec{spec.declTypeSpec});
},
[&](const parser::DerivedTypeSpec &spec) {
result.emplace_back(
SwitchTypeStmt::DerivedTypeSpec{nullptr /* FIXME */});
},
[&](const parser::Default &) {
result.emplace_back(SwitchTypeStmt::Default{});
},
},
std::visit(common::visitors{
[&](const parser::TypeSpec &spec) {
result.emplace_back(
SwitchTypeStmt::TypeSpec{spec.declTypeSpec});
},
[&](const parser::DerivedTypeSpec &spec) {
result.emplace_back(
SwitchTypeStmt::DerivedTypeSpec{nullptr /* FIXME */});
},
[&](const parser::Default &) {
result.emplace_back(SwitchTypeStmt::Default{});
},
},
guard.u);
}
return result;
@ -470,15 +469,14 @@ public:
template<typename STMTTYPE, typename CT>
Statement *GetSwitchSelector(const CT *selectConstruct) {
return std::visit(
common::visitors{
[&](const parser::Expr &e) {
return builder_->CreateExpr(ExprRef(e));
},
[&](const parser::Variable &v) {
return builder_->CreateExpr(ToExpression(v));
},
},
return std::visit(common::visitors{
[&](const parser::Expr &e) {
return builder_->CreateExpr(ExprRef(e));
},
[&](const parser::Variable &v) {
return builder_->CreateExpr(ToExpression(v));
},
},
std::get<parser::Selector>(
std::get<parser::Statement<STMTTYPE>>(selectConstruct->t)
.statement.t)
@ -596,27 +594,26 @@ public:
// extract options from list -> opts
AllocOpts opts;
for (auto &allocOpt : std::get<std::list<parser::AllocOpt>>(stmt.t)) {
std::visit(
common::visitors{
[&](const parser::AllocOpt::Mold &m) {
opts.mold = *ExprRef(m.v);
},
[&](const parser::AllocOpt::Source &s) {
opts.source = *ExprRef(s.v);
},
[&](const parser::StatOrErrmsg &var) {
std::visit(
common::visitors{
[&](const parser::StatVariable &sv) {
opts.stat = ToExpression(sv.v.thing.thing);
},
[&](const parser::MsgVariable &mv) {
opts.errmsg = ToExpression(mv.v.thing.thing);
},
},
var.u);
},
},
std::visit(common::visitors{
[&](const parser::AllocOpt::Mold &m) {
opts.mold = *ExprRef(m.v);
},
[&](const parser::AllocOpt::Source &s) {
opts.source = *ExprRef(s.v);
},
[&](const parser::StatOrErrmsg &var) {
std::visit(
common::visitors{
[&](const parser::StatVariable &sv) {
opts.stat = ToExpression(sv.v.thing.thing);
},
[&](const parser::MsgVariable &mv) {
opts.errmsg = ToExpression(mv.v.thing.thing);
},
},
var.u);
},
},
allocOpt.u);
}
// process the list of allocations
@ -1320,11 +1317,12 @@ void FortranIRLowering::ConstructFIR(AnalysisData &ad) {
[&](const parser::ReturnStmt *s) {
// alt-return
if (s->v) {
auto *app{
builder_->CreateExpr(ExprRef(s->v->thing.thing))};
auto *exp{ExprRef(s->v->thing.thing)};
auto app{builder_->QualifiedCreateExpr(exp)};
builder_->CreateReturn(app);
} else {
auto *zero{builder_->CreateExpr(CreateConstant(0))};
auto zero{
builder_->QualifiedCreateExpr(CreateConstant(0))};
builder_->CreateReturn(zero);
}
},

View File

@ -107,12 +107,11 @@ BasicBlock *SwitchRankStmt::defaultSucc() const {
// check LoadInsn constraints
static void CheckLoadInsn(const Value &v) {
std::visit(
common::visitors{
[](DataObject *) { /* ok */ },
[](Statement *s) { CHECK(GetAddressable(s)); },
[](auto) { CHECK(!"invalid load input"); },
},
std::visit(common::visitors{
[](DataObject *) { /* ok */ },
[](Statement *s) { CHECK(GetAddressable(s)); },
[](auto) { CHECK(!"invalid load input"); },
},
v.u);
}
LoadInsn::LoadInsn(const Value &addr) : address_{addr} {

View File

@ -0,0 +1,23 @@
# Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_library(FortranBridge
ir-gen.cc
)
target_link_libraries(FortranBridge
FortranCommon
FortranFIR
)

View File

@ -0,0 +1,22 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ir-gen.h"
namespace Fortran::bridge {
void GenerateIR(void) {
}
}

20
flang/lib/bridge/ir-gen.h Normal file
View File

@ -0,0 +1,20 @@
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Fortran::bridge {
/// Generate LLVM-IR
void GenerateIR(void);
}