Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/generator/code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ void CodeContainer::produceInfoFunctions(int tabs, const string& classname, cons
generateGetOutputs(out_fun + classname, obj, ismethod, funtype)->accept(producer);
}

void CodeContainer::generateDAGLoopInternal(CodeLoop* loop, BlockInst* block, DeclareVarInst* count, bool omp)
void CodeContainer::generateDAGLoopInternal(CodeLoop* loop, BlockInst* block, LoadVarInst* count, bool omp)
{
loop->generateDAGScalarLoop(block, count, omp);
}

void CodeContainer::generateDAGLoopAux(CodeLoop* loop, BlockInst* loop_code, DeclareVarInst* count, int loop_num,
void CodeContainer::generateDAGLoopAux(CodeLoop* loop, BlockInst* loop_code, LoadVarInst* count, int loop_num,
bool omp)
{
if (gGlobal->gFunTaskSwitch) {
Expand All @@ -341,7 +341,7 @@ void CodeContainer::generateDAGLoopAux(CodeLoop* loop, BlockInst* loop_code, Dec
}
}

void CodeContainer::generateDAGLoop(BlockInst* block, DeclareVarInst* count)
void CodeContainer::generateDAGLoop(BlockInst* block, LoadVarInst* count)
{
int loop_num = 0;

Expand Down
6 changes: 3 additions & 3 deletions compiler/generator/code_container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ class CodeContainer : public virtual Garbageable {
merge(S, fLibrarySet);
}

void generateDAGLoopAux(CodeLoop* loop, BlockInst* loop_code, DeclareVarInst* count, int loop_num,
void generateDAGLoopAux(CodeLoop* loop, BlockInst* loop_code, LoadVarInst* count, int loop_num,
bool omp = false);
void generateDAGLoopInternal(CodeLoop* loop, BlockInst* block, DeclareVarInst* count, bool omp);
void generateDAGLoopInternal(CodeLoop* loop, BlockInst* block, LoadVarInst* count, bool omp);

void includeFastMath()
{
Expand Down Expand Up @@ -364,7 +364,7 @@ class CodeContainer : public virtual Garbageable {
void produceInfoFunctions(int tabs, const std::string& classname, const std::string& obj, bool ismethod, FunTyped::FunAttribute funtype,
TextInstVisitor* producer, const std::string& in_fun = "getNumInputs", const std::string& out_fun = "getNumOutputs");

void generateDAGLoop(BlockInst* loop_code, DeclareVarInst* count);
void generateDAGLoop(BlockInst* loop_code, LoadVarInst* count);

template <typename REAL>
void generateMetaData(JSONUIReal<REAL>* json)
Expand Down
8 changes: 4 additions & 4 deletions compiler/generator/cpp/cpp_gpu_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,13 +1075,13 @@ void CPPOpenCLVectorCodeContainer::generateComputeKernel(int n)
int loop_num = 0;
for (lclset::const_iterator p = dag[l].begin(); p != dag[l].end(); p++) {
BlockInst* switch_case_block = InstBuilder::genBlockInst();
generateDAGLoopAux(*p, switch_case_block, count_dec, loop_num);
generateDAGLoopAux(*p, switch_case_block, count_dec->load(), loop_num);
switch_block->addCase(loop_num, switch_case_block);
loop_num++;
}
} else {
BlockInst* single_case_block = InstBuilder::genBlockInst();
generateDAGLoopAux(*dag[l].begin(), single_case_block, count_dec, 0);
generateDAGLoopAux(*dag[l].begin(), single_case_block, count_dec->load(), 0);
switch_block->addCase(0, single_case_block);
}

Expand Down Expand Up @@ -2016,13 +2016,13 @@ void CPPCUDAVectorCodeContainer::generateComputeKernel(int n)
int loop_num = 0;
for (lclset::const_iterator p = dag[l].begin(); p != dag[l].end(); p++) {
BlockInst* switch_case_block = InstBuilder::genBlockInst();
generateDAGLoopAux(*p, switch_case_block, count_dec, loop_num);
generateDAGLoopAux(*p, switch_case_block, count_dec->load(), loop_num);
switch_block->addCase(loop_num, switch_case_block);
loop_num++;
}
} else {
BlockInst* single_case_block = InstBuilder::genBlockInst();
generateDAGLoopAux(*dag[l].begin(), single_case_block, count_dec, 0);
generateDAGLoopAux(*dag[l].begin(), single_case_block, count_dec->load(), 0);
switch_block->addCase(0, single_case_block);
}

Expand Down
7 changes: 5 additions & 2 deletions compiler/generator/dag_instructions_compiler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class DAGInstructionsCompiler : public InstructionsCompiler {

virtual void compileMultiSignal(Tree sig);

private:
protected:
// reimplemented code generation methods
virtual ValueInst* CS(Tree sig);

private:
virtual ValueInst* generateCode(Tree sig);
virtual void generateCodeRecursions(Tree sig);
virtual ValueInst* generateCodeNonRec(Tree sig);
Expand All @@ -50,7 +52,8 @@ class DAGInstructionsCompiler : public InstructionsCompiler {
virtual ValueInst* generateInput(Tree sig, int idx);

virtual ValueInst* generateDelay(Tree sig, Tree arg, Tree size);
virtual ValueInst* generateDelayVec(Tree sig, ValueInst* exp, Typed::VarType ctype, const std::string& vname, int mxd);
virtual ValueInst* generateDelayVec(Tree sig, ValueInst* exp, Typed::VarType ctype, const std::string& vname,
int mxd);
virtual ValueInst* generateDelayLine(ValueInst* exp, Typed::VarType ctype, const std::string& vname, int mxd,
Address::AccessType& access, ValueInst* ccs);

Expand Down
14 changes: 6 additions & 8 deletions compiler/generator/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,17 @@ DeclareVarInst::DeclareVarInst(Address* address, Typed* type, ValueInst* value)
}

// A list of channels variables also kept in the global name <===> type table (use in Rust and Julia backends)
DeclareBufferIterators::DeclareBufferIterators(const std::string& name1,
const std::string& name2,
int channels,
Typed* type,
bool mut)
: fBufferName1(name1), fBufferName2(name2), fChannels(channels), fType(type), fMutable(mut)
DeclareBufferIterators::DeclareBufferIterators(const std::string& name1, const std::string& name2, int channels,
Typed* type, bool mut, bool chunk)
: fBufferName1(name1), fBufferName2(name2), fChannels(channels), fType(type), fMutable(mut), fChunk(chunk)
{
for (int i = 0; i < channels; i++) {
string chan_name = name1 + std::to_string(i);
if (gGlobal->gVarTypeTable.find(chan_name) == gGlobal->gVarTypeTable.end()) {
auto contains = gGlobal->gVarTypeTable.find(chan_name);
if (contains == gGlobal->gVarTypeTable.end()) {
gGlobal->gVarTypeTable[chan_name] = type;
} else {
faustassert(false);
faustassert(contains->second == type);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions compiler/generator/instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,9 @@ struct DeclareBufferIterators : public StatementInst {
int fChannels;
Typed* fType;
bool fMutable;
bool fChunk;

DeclareBufferIterators(const std::string& name1, const std::string& name2, int channels, Typed* type, bool mut);
DeclareBufferIterators(const std::string& name1, const std::string& name2, int channels, Typed* type, bool mut, bool chunk);

virtual ~DeclareBufferIterators() {}

Expand Down Expand Up @@ -1484,7 +1485,7 @@ class BasicCloneVisitor : public CloneVisitor {
}
virtual StatementInst* visit(DeclareBufferIterators* inst)
{
return new DeclareBufferIterators(inst->fBufferName1, inst->fBufferName2, inst->fChannels, inst->fType, inst->fMutable);
return new DeclareBufferIterators(inst->fBufferName1, inst->fBufferName2, inst->fChannels, inst->fType, inst->fMutable, inst->fChunk);
}

// Memory
Expand Down Expand Up @@ -2079,9 +2080,9 @@ struct InstBuilder {
return new DeclareStructTypeInst(type);
}

static DeclareBufferIterators* genDeclareBufferIterators(const std::string& name1, const std::string& name2, int channels, Typed* type, bool mut)
static DeclareBufferIterators* genDeclareBufferIterators(const std::string& name1, const std::string& name2, int channels, Typed* type, bool mut, bool chunk = false)
{
return new DeclareBufferIterators(name1, name2, channels, type, mut);
return new DeclareBufferIterators(name1, name2, channels, type, mut, chunk);
}

// Memory
Expand Down
6 changes: 3 additions & 3 deletions compiler/generator/omp_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ StatementInst* OpenMPCodeContainer::generateDAGLoopOMP(const string& counter)
BlockInst* omp_section_block = InstBuilder::genBlockInst();
if (dag[l].size() == 1) { // Only one loop
if (!p->isRecursive() && gGlobal->gOpenMPLoop) {
generateDAGLoopAux(p, omp_section_block, count_dec, loop_num++, true);
generateDAGLoopAux(p, omp_section_block, count_dec->load(), loop_num++, true);
} else {
omp_section_block->setIndent(true);
if (!is_single) {
Expand All @@ -139,13 +139,13 @@ StatementInst* OpenMPCodeContainer::generateDAGLoopOMP(const string& counter)
} else {
omp_sections_block->pushBackInst(InstBuilder::genLabelInst("/* Still in a single section */"));
}
generateDAGLoopAux(p, omp_section_block, count_dec, loop_num++);
generateDAGLoopAux(p, omp_section_block, count_dec->load(), loop_num++);
}
} else {
is_single = false;
omp_section_block->setIndent(true);
omp_sections_block->pushBackInst(InstBuilder::genLabelInst("#pragma omp section"));
generateDAGLoopAux(p, omp_section_block, count_dec, loop_num++);
generateDAGLoopAux(p, omp_section_block, count_dec->load(), loop_num++);
}
omp_sections_block->pushBackInst(omp_section_block);
}
Expand Down
142 changes: 142 additions & 0 deletions compiler/generator/rust/dag_instructions_compiler_rust.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/************************************************************************
************************************************************************
FAUST compiler
Copyright (C) 2017-2021 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
************************************************************************
************************************************************************/

#include "dag_instructions_compiler_rust.hh"
#include "fir_to_fir.hh"
#include "sigtyperules.hh"
#include "timing.hh"

using std::string;

void DAGInstructionsCompilerRust::compileMultiSignal(Tree L)
{
startTiming("compileMultiSignal");

// Has to be done *after* gMachinePtrSize is set by the actual backend
gGlobal->initTypeSizeMap();

L = prepare(L); // Optimize, share and annotate expression

Typed* type = InstBuilder::genBasicTyped(Typed::kFloatMacro_ptr);
pushComputeBlockMethod(
InstBuilder::genDeclareBufferIterators("input", "inputs", fContainer->inputs(), type, false, true));
pushComputeBlockMethod(
InstBuilder::genDeclareBufferIterators("output", "outputs", fContainer->outputs(), type, true, true));

for (int index = 0; isList(L); L = tl(L), index++) {
Tree sig = hd(L);
string name = subst("output$0", T(index));

fContainer->openLoop("i");

// Possibly cast to external float
ValueInst* res = genCastedOutput(getCertifiedSigType(sig)->nature(), CS(sig));

if (gGlobal->gComputeMix) {
ValueInst* res1 = InstBuilder::genAdd(res, InstBuilder::genLoadArrayStackVar(name, getCurrentLoopIndex()));
pushComputeDSPMethod(InstBuilder::genStoreArrayStackVar(name, getCurrentLoopIndex(), res1));
} else {
pushComputeDSPMethod(InstBuilder::genStoreArrayStackVar(name, getCurrentLoopIndex(), res));
}

fContainer->closeLoop(sig);
}

generateUserInterfaceTree(fUITree.prepareUserInterfaceTree(), true);
generateMacroInterfaceTree("", fUITree.prepareUserInterfaceTree());
if (fDescription) {
fDescription->ui(fUITree.prepareUserInterfaceTree());
}

// Apply FIR to FIR transformations
fContainer->processFIR();

endTiming("compileMultiSignal");
}

StatementInst* DAGInstructionsCompilerRust::generateInitArray(const string& vname, Typed::VarType ctype, int delay)
{
ValueInst* init = InstBuilder::genTypedZero(ctype);
BasicTyped* typed = InstBuilder::genBasicTyped(ctype);

// Generates table declaration
pushDeclare(InstBuilder::genDecStructVar(vname, InstBuilder::genArrayTyped(typed, delay)));

Values args;
args.push_back(InstBuilder::genLoadStructVar(vname));
args.push_back(init);
return InstBuilder::genVoidFunCallInst("fill", args, true);

// ValueInst* init = InstBuilder::genTypedZero(ctype);
// BasicTyped* typed = InstBuilder::genBasicTyped(ctype);
// string index = gGlobal->getFreshID("l");
//
// // Generates table declaration
// pushDeclare(InstBuilder::genDecStructVar(vname, InstBuilder::genArrayTyped(typed, delay)));
//
// ValueInst* upperBound = InstBuilder::genInt32NumInst(delay);
// // Generates init table loop
// SimpleForLoopInst* loop = InstBuilder::genSimpleForLoopInst(index, upperBound);
//
// LoadVarInst* loadVarInst = InstBuilder::genLoadVarInst(InstBuilder::genNamedAddress(index, Address::kLoop));
// loop->pushFrontInst(InstBuilder::genStoreArrayStructVar(vname, loadVarInst, init));
// return loop;
}

StatementInst* DAGInstructionsCompilerRust::generateShiftArray(const string& vname, int delay)
{
std::cout << "generateShiftArray " << vname << " " << delay << std::endl;

string index = gGlobal->getFreshID("j");

ValueInst* upperBound = InstBuilder::genInt32NumInst(delay);
ValueInst* lowerBound = InstBuilder::genInt32NumInst(1);

SimpleForLoopInst* loop = InstBuilder::genSimpleForLoopInst(index, upperBound, lowerBound, true);
LoadVarInst* loadVarInst = InstBuilder::genLoadVarInst(InstBuilder::genNamedAddress(index, Address::kLoop));
ValueInst* load_value2 = InstBuilder::genSub(loadVarInst, InstBuilder::genInt32NumInst(1));
ValueInst* load_value3 = InstBuilder::genLoadArrayStructVar(vname, load_value2);

loop->pushFrontInst(InstBuilder::genStoreArrayStructVar(vname, loadVarInst, load_value3));
return loop;
}

StatementInst* DAGInstructionsCompilerRust::generateCopyArray(const string& vname_to, const string& vname_from,
int size)
{
// std::cout << "generateCopyArray " << vname_to << " " << vname_from << " " << size << std::endl;
// Values args;
// args.push_back(InstBuilder::genLoadStackVar(vname_to));
// args.push_back(
// InstBuilder::genLoadVarAddressInst(InstBuilder::genNamedAddress(vname_from,
// Address::AccessType::kStruct)));
// return InstBuilder::genVoidFunCallInst("copy_from_slice", args, true);

string index = gGlobal->getFreshID("j");

ValueInst* upperBound = InstBuilder::genInt32NumInst(size);
SimpleForLoopInst* loop = InstBuilder::genSimpleForLoopInst(index, upperBound);
LoadVarInst* loadVarInst = InstBuilder::genLoadVarInst(InstBuilder::genNamedAddress(index, Address::kLoop));
ValueInst* load_value = InstBuilder::genLoadArrayStructVar(vname_from, loadVarInst);

loop->pushFrontInst(InstBuilder::genStoreArrayStackVar(vname_to, loadVarInst, load_value));
return loop;
}
39 changes: 39 additions & 0 deletions compiler/generator/rust/dag_instructions_compiler_rust.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/************************************************************************
************************************************************************
FAUST compiler
Copyright (C) 2017-2021 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
************************************************************************
************************************************************************/

#ifndef FAUST_DAG_INSTRUCTIONS_COMPILER_RUST_H
#define FAUST_DAG_INSTRUCTIONS_COMPILER_RUST_H

#include "dag_instructions_compiler.hh"

class DAGInstructionsCompilerRust : public DAGInstructionsCompiler {
public:
DAGInstructionsCompilerRust(CodeContainer* container) : DAGInstructionsCompiler(container) {}

void compileMultiSignal(Tree sig) override;

private:
StatementInst* generateInitArray(const std::string& vname, Typed::VarType ctype, int delay) override;
StatementInst* generateShiftArray(const std::string& vname, int delay) override;
StatementInst* generateCopyArray(const std::string& vname_to, const std::string& vname_from, int size) override;
};

#endif // FAUST_DAG_INSTRUCTIONS_COMPILER_RUST_H
Loading