Skip to content

Commit

Permalink
Merge branch 'master' into AndersenRegionAwareCI
Browse files Browse the repository at this point in the history
  • Loading branch information
haved authored Jan 13, 2025
2 parents 0fd0ea0 + f145b1f commit aaee9a5
Show file tree
Hide file tree
Showing 84 changed files with 2,559 additions and 2,474 deletions.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Checks: '-*,
bugprone-move-forwarding-reference,
misc-unused-parameters,
misc-unused-using-decls,
modernize-deprecated-headers,
modernize-redundant-void-arg,
'

WarningsAsErrors: '
bugprone-move-forwarding-reference,
misc-unused-parameters,
misc-unused-using-decls,
modernize-deprecated-headers,
modernize-redundant-void-arg,
'
3 changes: 2 additions & 1 deletion jlm/hls/backend/rvsdg2rhls/UnusedStateRemoval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include <jlm/hls/backend/rvsdg2rhls/UnusedStateRemoval.hpp>
#include <jlm/llvm/ir/CallSummary.hpp>
#include <jlm/llvm/ir/operators/lambda.hpp>
#include <jlm/llvm/ir/RvsdgModule.hpp>
#include <jlm/rvsdg/gamma.hpp>
Expand Down Expand Up @@ -109,7 +110,7 @@ RemoveUnusedStatesFromLambda(llvm::lambda::node & lambdaNode)

JLM_ASSERT(lambdaNode.output()->nusers() == 1);
lambdaNode.region()->RemoveResult((*lambdaNode.output()->begin())->index());
auto oldExport = lambdaNode.ComputeCallSummary()->GetRvsdgExport();
auto oldExport = jlm::llvm::ComputeCallSummary(lambdaNode).GetRvsdgExport();
jlm::llvm::GraphExport::Create(*newLambdaOutput, oldExport ? oldExport->Name() : "");
remove(&lambdaNode);
}
Expand Down
2 changes: 1 addition & 1 deletion jlm/hls/backend/rvsdg2rhls/add-prints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ convert_prints(llvm::RvsdgModule & rm)
auto fct =
llvm::FunctionType::Create({ rvsdg::bittype::Create(64), rvsdg::bittype::Create(64) }, {});
auto & printf =
llvm::GraphImport::Create(graph, fct, "printnode", llvm::linkage::external_linkage);
llvm::GraphImport::Create(graph, fct, fct, "printnode", llvm::linkage::external_linkage);
convert_prints(root, &printf, fct);
}

Expand Down
3 changes: 2 additions & 1 deletion jlm/hls/backend/rvsdg2rhls/add-triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <jlm/hls/backend/rvsdg2rhls/add-triggers.hpp>
#include <jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.hpp>
#include <jlm/hls/ir/hls.hpp>
#include <jlm/llvm/ir/CallSummary.hpp>
#include <jlm/rvsdg/gamma.hpp>
#include <jlm/rvsdg/theta.hpp>
#include <jlm/rvsdg/traverser.hpp>
Expand Down Expand Up @@ -79,7 +80,7 @@ add_lambda_argument(llvm::lambda::node * ln, std::shared_ptr<const jlm::rvsdg::T

// ln->output()->divert_users(new_out);
ln->region()->RemoveResult((*ln->output()->begin())->index());
auto oldExport = ln->ComputeCallSummary()->GetRvsdgExport();
auto oldExport = jlm::llvm::ComputeCallSummary(*ln).GetRvsdgExport();
jlm::llvm::GraphExport::Create(*new_out, oldExport ? oldExport->Name() : "");
remove(ln);
return new_lambda;
Expand Down
3 changes: 3 additions & 0 deletions jlm/hls/backend/rvsdg2rhls/instrument-ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ instrument_ref(llvm::RvsdgModule & rm)
auto & reference_load = llvm::GraphImport::Create(
graph,
loadFunctionType,
loadFunctionType,
"reference_load",
llvm::linkage::external_linkage);
// addr, data, width, memstate
Expand All @@ -105,6 +106,7 @@ instrument_ref(llvm::RvsdgModule & rm)
auto & reference_store = llvm::GraphImport::Create(
graph,
storeFunctionType,
storeFunctionType,
"reference_store",
llvm::linkage::external_linkage);
// addr, size, memstate
Expand All @@ -117,6 +119,7 @@ instrument_ref(llvm::RvsdgModule & rm)
auto & reference_alloca = llvm::GraphImport::Create(
graph,
allocaFunctionType,
allocaFunctionType,
"reference_alloca",
llvm::linkage::external_linkage);

Expand Down
3 changes: 2 additions & 1 deletion jlm/hls/backend/rvsdg2rhls/mem-conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <jlm/hls/backend/rvsdg2rhls/rhls-dne.hpp>
#include <jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.hpp>
#include <jlm/hls/ir/hls.hpp>
#include <jlm/llvm/ir/CallSummary.hpp>
#include <jlm/llvm/ir/operators/call.hpp>
#include <jlm/llvm/ir/operators/lambda.hpp>
#include <jlm/llvm/ir/operators/Load.hpp>
Expand Down Expand Up @@ -705,7 +706,7 @@ jlm::hls::MemoryConverter(jlm::llvm::RvsdgModule & rm)
}
originalResults.insert(originalResults.end(), newResults.begin(), newResults.end());
auto newOut = newLambda->finalize(originalResults);
auto oldExport = lambda->ComputeCallSummary()->GetRvsdgExport();
auto oldExport = jlm::llvm::ComputeCallSummary(*lambda).GetRvsdgExport();
llvm::GraphExport::Create(*newOut, oldExport ? oldExport->Name() : "");

JLM_ASSERT(lambda->output()->nusers() == 1);
Expand Down
3 changes: 2 additions & 1 deletion jlm/hls/backend/rvsdg2rhls/remove-unused-state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <jlm/hls/backend/rvsdg2rhls/remove-unused-state.hpp>
#include <jlm/hls/ir/hls.hpp>
#include <jlm/llvm/ir/CallSummary.hpp>
#include <jlm/llvm/ir/operators/MemoryStateOperations.hpp>
#include <jlm/rvsdg/traverser.hpp>
#include <jlm/rvsdg/view.hpp>
Expand Down Expand Up @@ -245,7 +246,7 @@ remove_lambda_passthrough(llvm::lambda::node * ln)
// ln->output()->divert_users(new_out); // can't divert since the type changed
JLM_ASSERT(ln->output()->nusers() == 1);
ln->region()->RemoveResult((*ln->output()->begin())->index());
auto oldExport = ln->ComputeCallSummary()->GetRvsdgExport();
auto oldExport = jlm::llvm::ComputeCallSummary(*ln).GetRvsdgExport();
jlm::llvm::GraphExport::Create(*new_out, oldExport ? oldExport->Name() : "");
remove(ln);
return new_lambda;
Expand Down
6 changes: 5 additions & 1 deletion jlm/hls/backend/rvsdg2rhls/rvsdg2rhls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <jlm/hls/util/view.hpp>
#include <jlm/llvm/backend/jlm2llvm/jlm2llvm.hpp>
#include <jlm/llvm/backend/rvsdg2jlm/rvsdg2jlm.hpp>
#include <jlm/llvm/ir/CallSummary.hpp>
#include <jlm/llvm/ir/operators/alloca.hpp>
#include <jlm/llvm/ir/operators/call.hpp>
#include <jlm/llvm/ir/operators/delta.hpp>
Expand Down Expand Up @@ -351,6 +352,7 @@ split_hls_function(llvm::RvsdgModule & rm, const std::string & function_name)
auto & newGraphImport = llvm::GraphImport::Create(
rhls->Rvsdg(),
oldGraphImport->ValueType(),
oldGraphImport->ImportedType(),
oldGraphImport->Name(),
oldGraphImport->Linkage());
smap.insert(ln->input(i)->origin(), &newGraphImport);
Expand All @@ -373,6 +375,7 @@ split_hls_function(llvm::RvsdgModule & rm, const std::string & function_name)
auto & graphImport = llvm::GraphImport::Create(
rhls->Rvsdg(),
odn->Type(),
llvm::PointerType::Create(),
odn->name(),
llvm::linkage::external_linkage);
smap.insert(ln->input(i)->origin(), &graphImport);
Expand All @@ -388,12 +391,13 @@ split_hls_function(llvm::RvsdgModule & rm, const std::string & function_name)
// copy function into rhls
auto new_ln = ln->copy(&rhls->Rvsdg().GetRootRegion(), smap);
new_ln = change_linkage(new_ln, llvm::linkage::external_linkage);
auto oldExport = ln->ComputeCallSummary()->GetRvsdgExport();
auto oldExport = jlm::llvm::ComputeCallSummary(*ln).GetRvsdgExport();
jlm::llvm::GraphExport::Create(*new_ln->output(), oldExport ? oldExport->Name() : "");
// add function as input to rm and remove it
auto & graphImport = llvm::GraphImport::Create(
rm.Rvsdg(),
ln->Type(),
ln->Type(),
ln->name(),
llvm::linkage::external_linkage); // TODO: change linkage?
ln->output()->divert_users(&graphImport);
Expand Down
7 changes: 7 additions & 0 deletions jlm/hls/ir/hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ loop_node::AddLoopVar(jlm::rvsdg::output * origin, jlm::rvsdg::output ** buffer)
return output;
}

[[nodiscard]] const rvsdg::Operation &
loop_node::GetOperation() const noexcept
{
static const loop_op singleton;
return singleton;
}

jlm::rvsdg::output *
loop_node::add_loopconst(jlm::rvsdg::output * origin)
{
Expand Down
5 changes: 4 additions & 1 deletion jlm/hls/ir/hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,15 @@ class loop_node final : public rvsdg::StructuralNode

private:
inline loop_node(rvsdg::Region * parent)
: StructuralNode(loop_op(), parent, 1)
: StructuralNode(parent, 1)
{}

jlm::rvsdg::node_output * _predicate_buffer;

public:
[[nodiscard]] const rvsdg::Operation &
GetOperation() const noexcept override;

static loop_node *
create(rvsdg::Region * parent, bool init = true);

Expand Down
3 changes: 3 additions & 0 deletions jlm/llvm/Makefile.sub
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ libllvm_SOURCES = \
jlm/llvm/ir/Annotation.cpp \
jlm/llvm/ir/attribute.cpp \
jlm/llvm/ir/basic-block.cpp \
jlm/llvm/ir/CallSummary.cpp \
jlm/llvm/ir/cfg.cpp \
jlm/llvm/ir/cfg-structure.cpp \
jlm/llvm/ir/cfg-node.cpp \
Expand Down Expand Up @@ -108,6 +109,7 @@ libllvm_HEADERS = \
jlm/llvm/ir/linkage.hpp \
jlm/llvm/ir/Annotation.hpp \
jlm/llvm/ir/attribute.hpp \
jlm/llvm/ir/CallSummary.hpp \
jlm/llvm/ir/tac.hpp \
jlm/llvm/ir/domtree.hpp \
jlm/llvm/ir/cfg-node.hpp \
Expand Down Expand Up @@ -192,6 +194,7 @@ libllvm_TESTS += \
tests/jlm/llvm/ir/test-ssa-destruction \
tests/jlm/llvm/ir/TestTypes \
tests/jlm/llvm/ir/TestAnnotation \
tests/jlm/llvm/ir/TestCallSummary \
tests/jlm/llvm/ir/ThreeAddressCodeTests \
tests/jlm/llvm/opt/alias-analyses/TestAgnosticMemoryNodeProvider \
tests/jlm/llvm/opt/alias-analyses/TestAndersen \
Expand Down
10 changes: 5 additions & 5 deletions jlm/llvm/frontend/InterProceduralGraphConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ Convert(const llvm::tac & threeAddressCode, rvsdg::Region & region, llvm::Variab
operands.push_back(variableMap.lookup(operand));
}

auto operation = util::AssertedCast<const TOperation>(&threeAddressCode.operation());
auto results = TNode::Create(region, *operation, operands);
std::unique_ptr<TOperation> operation(
util::AssertedCast<TOperation>(threeAddressCode.operation().copy().release()));
auto results = TNode::Create(region, std::move(operation), operands);

JLM_ASSERT(results.size() == threeAddressCode.nresults());
for (size_t n = 0; n < threeAddressCode.nresults(); n++)
Expand Down Expand Up @@ -994,6 +995,7 @@ ConvertFunctionNode(
return &GraphImport::Create(
*region.graph(),
functionNode.GetFunctionType(),
functionNode.GetFunctionType(),
functionNode.name(),
functionNode.linkage());
}
Expand Down Expand Up @@ -1035,6 +1037,7 @@ ConvertDataNode(
return &GraphImport::Create(
*region.graph(),
dataNode.GetValueType(),
PointerType::Create(),
dataNode.name(),
dataNode.linkage());
}
Expand Down Expand Up @@ -1201,9 +1204,6 @@ ConvertInterProceduralGraphModule(
auto nf = graph->GetNodeNormalForm(typeid(rvsdg::Operation));
nf->set_mutable(false);

/* FIXME: we currently cannot handle flattened_binary_op in jlm2llvm pass */
rvsdg::BinaryOperation::normal_form(graph)->set_flatten(false);

RegionalizedVariableMap regionalizedVariableMap(
interProceduralGraphModule,
graph->GetRootRegion());
Expand Down
60 changes: 57 additions & 3 deletions jlm/llvm/frontend/LlvmInstructionConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
namespace jlm::llvm
{

// Converts a value into a variable either representing the llvm
// value or representing a function object.
// The distinction stems from the fact that llvm treats functions simply
// as pointers to the function code while we distinguish between the two.
// This function can return either and caller needs to check / adapt.
const variable *
ConvertValue(::llvm::Value * v, tacsvector_t & tacs, context & ctx)
ConvertValueOrFunction(::llvm::Value * v, tacsvector_t & tacs, context & ctx)
{
auto node = ctx.node();
if (node && ctx.has_value(v))
Expand All @@ -38,6 +43,20 @@ ConvertValue(::llvm::Value * v, tacsvector_t & tacs, context & ctx)
JLM_UNREACHABLE("This should not have happened!");
}

// Converts a value into a variable representing the llvm value.
const variable *
ConvertValue(::llvm::Value * v, tacsvector_t & tacs, context & ctx)
{
const variable * var = ConvertValueOrFunction(v, tacs, ctx);
if (auto fntype = std::dynamic_pointer_cast<const FunctionType>(var->Type()))
{
std::unique_ptr<tac> ptr_cast = tac::create(FunctionToPointerOperation(fntype), { var });
var = ptr_cast->result(0);
tacs.push_back(std::move(ptr_cast));
}
return var;
}

/* constant */

const variable *
Expand Down Expand Up @@ -886,15 +905,50 @@ convert_call_instruction(::llvm::Instruction * instruction, tacsvector_t & tacs,
return convert_memcpy_call(i, tacs, ctx);

auto ftype = i->getFunctionType();
auto convertedFType = ConvertFunctionType(ftype, ctx);

auto arguments = create_arguments(i, tacs, ctx);
if (ftype->isVarArg())
arguments.push_back(create_varargs(i, tacs, ctx));
arguments.push_back(ctx.iostate());
arguments.push_back(ctx.memory_state());

auto fctvar = ConvertValue(i->getCalledOperand(), tacs, ctx);
auto call = CallOperation::create(fctvar, ConvertFunctionType(ftype, ctx), arguments);
const variable * callee = ConvertValueOrFunction(i->getCalledOperand(), tacs, ctx);
// Llvm does not distinguish between "function objects" and
// "pointers to functions" while we need to be precise in modelling.
// If the called object is a function object, then we can just
// feed it to the call operator directly, otherwise we have
// to cast it into a function object.
if (is<PointerType>(*callee->Type()))
{
std::unique_ptr<tac> callee_cast =
tac::create(PointerToFunctionOperation(convertedFType), { callee });
callee = callee_cast->result(0);
tacs.push_back(std::move(callee_cast));
}
else if (auto fntype = std::dynamic_pointer_cast<const FunctionType>(callee->Type()))
{
// Llvm also allows argument type mismatches if the function
// features varargs. The code here could be made more precise by
// validating and accepting only vararg-related mismatches.
if (*convertedFType != *fntype)
{
// Since vararg passing is not modelled explicitly, simply hide the
// argument mismtach via pointer casts.
std::unique_ptr<tac> ptrCast = tac::create(FunctionToPointerOperation(fntype), { callee });
std::unique_ptr<tac> fnCast =
tac::create(PointerToFunctionOperation(convertedFType), { ptrCast->result(0) });
callee = fnCast->result(0);
tacs.push_back(std::move(ptrCast));
tacs.push_back(std::move(fnCast));
}
}
else
{
throw std::runtime_error("Unexpected callee type: " + callee->Type()->debug_string());
}

auto call = CallOperation::create(callee, convertedFType, arguments);

auto result = call->result(0);
auto iostate = call->result(call->nresults() - 2);
Expand Down
2 changes: 1 addition & 1 deletion jlm/llvm/ir/Annotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class VariableSet final
std::unordered_set<const llvm::variable *>::const_iterator It_;
};

using ConstRange = jlm::util::iterator_range<ConstIterator>;
using ConstRange = util::IteratorRange<ConstIterator>;

public:
VariableSet() = default;
Expand Down
Loading

0 comments on commit aaee9a5

Please sign in to comment.