From aac001a7b7ccef6f22ae8c40739393da84fa8037 Mon Sep 17 00:00:00 2001 From: crop Date: Mon, 28 Oct 2024 21:39:13 +0100 Subject: [PATCH] wip move second half of ar loop generation into visitor function. for this i need the num io's --- compiler/generator/instructions.hh | 13 ++++++++----- compiler/generator/rust/rust_code_container.cpp | 12 ++++-------- compiler/generator/rust/rust_instructions.hh | 17 +++++++++++++++++ compiler/parallelize/code_loop.cpp | 4 ++-- compiler/parallelize/code_loop.hh | 2 +- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/compiler/generator/instructions.hh b/compiler/generator/instructions.hh index 52b33d8d5c..589d9e4857 100644 --- a/compiler/generator/instructions.hh +++ b/compiler/generator/instructions.hh @@ -1643,9 +1643,11 @@ struct IteratorForLoopInst : public StatementInst { std::vector fIterators; const bool fReverse; BlockInst* fCode; + uint fNumInputs; + uint fNumOutputs; - IteratorForLoopInst(const std::vector& iterators, bool reverse, BlockInst* code) - : fIterators(iterators), fReverse(reverse), fCode(code) + IteratorForLoopInst(const std::vector& iterators, bool reverse, BlockInst* code,uint fNumInputs,uint fNumOutputs) + : fIterators(iterators), fReverse(reverse), fCode(code), fNumInputs(fNumInputs), fNumOutputs(fNumOutputs) { } @@ -1906,7 +1908,7 @@ class BasicCloneVisitor : public CloneVisitor { iterators.push_back(static_cast(it->clone(this))); } return new IteratorForLoopInst(iterators, inst->fReverse, - static_cast(inst->fCode->clone(this))); + static_cast(inst->fCode->clone(this)),inst->fNumInputs, inst->fNumOutputs); } virtual StatementInst* visit(WhileLoopInst* inst) @@ -2560,11 +2562,12 @@ struct IB { faustassert(castInt32(lowerBound) || dynamic_cast(lowerBound)); return new SimpleForLoopInst(name, upperBound, lowerBound, reverse, code); } - static IteratorForLoopInst* genIteratorForLoopInst(const std::vector& iterators, + static IteratorForLoopInst* genIteratorForLoopInst(uint fNumInputs, uint fNumOutputs, + const std::vector& iterators, bool reverse = false, BlockInst* code = new BlockInst()) { - return new IteratorForLoopInst(iterators, reverse, code); + return new IteratorForLoopInst(iterators, reverse, code, fNumInputs, fNumOutputs); } static WhileLoopInst* genWhileLoopInst(ValueInst* cond, BlockInst* code) diff --git a/compiler/generator/rust/rust_code_container.cpp b/compiler/generator/rust/rust_code_container.cpp index a2e9a448c6..03fdbbf5cd 100644 --- a/compiler/generator/rust/rust_code_container.cpp +++ b/compiler/generator/rust/rust_code_container.cpp @@ -708,6 +708,7 @@ void RustCodeContainer::generateComputeFrame(int n) /* // TODO : atomic switch // Currently for soundfile management + // also for temp vars */ generatePostComputeBlock(&fCodeProducer); tab(n, *fOut); @@ -764,18 +765,13 @@ void RustScalarCodeContainer::generateCompute(int n) // todo // this is now really ugly // generateSimpleScalarLoop exits early and leaves the rest of the function to the following block - IteratorForLoopInst* loop = fCurLoop->generateSimpleScalarLoop(iterators); + IteratorForLoopInst* loop = fCurLoop->generateSimpleScalarLoop(fNumInputs,fNumOutputs,iterators); loop->accept(&fCodeProducer); if (gGlobal->gOneSample) { - *fOut << "self.compute_frame("; - bracket_named_list(fOut, fNumInputs,"input", "(", ")"); - *fOut << "," << endl; - bracket_named_list(fOut, fNumOutputs,"output", "(", ")"); - *fOut << ");" << endl; - *fOut << "}" << endl; } else { // Currently for soundfile management + // also for temp vars generatePostComputeBlock(&fCodeProducer); } @@ -847,7 +843,7 @@ BlockInst* RustVectorCodeContainer::generateDAGLoopVariant0(const string& counte } // Generates the DAG enclosing loop - StatementInst* loop = IB::genIteratorForLoopInst(iterators, false, loop_code); + StatementInst* loop = IB::genIteratorForLoopInst(fNumInputs,fNumOutputs,iterators, false, loop_code); // Put loop in block_res block_res->pushBackInst(loop); diff --git a/compiler/generator/rust/rust_instructions.hh b/compiler/generator/rust/rust_instructions.hh index f68550bd07..a2c1127aae 100644 --- a/compiler/generator/rust/rust_instructions.hh +++ b/compiler/generator/rust/rust_instructions.hh @@ -641,6 +641,17 @@ class RustInstVisitor : public TextInstVisitor { tab(fTab, *fOut); } +void bracket_named_list(std::ostream* fOut,int N, std::string name, std::string ob, std::string cb){ + *fOut << ob; + for(int i = 0; i < N; i++){ + *fOut << name << i; + if (i+1 < N){ + *fOut << ","; + }; + }; + *fOut << cb; +} + virtual void visit(IteratorForLoopInst* inst) { // Don't generate empty loops... @@ -672,6 +683,12 @@ class RustInstVisitor : public TextInstVisitor { *fOut << " in zipped_iterators {"; if (gGlobal->gOneSample) { *fOut << std::endl; + *fOut << "self.compute_frame("; + bracket_named_list(fOut, inst->fNumInputs,"input", "(", ")"); + *fOut << "," << std::endl; + bracket_named_list(fOut, inst->fNumOutputs,"output", "(", ")"); + *fOut << ");" << std::endl; + *fOut << "}" << std::endl; } else { fTab++; tab(fTab, *fOut); diff --git a/compiler/parallelize/code_loop.cpp b/compiler/parallelize/code_loop.cpp index 34ccbc6649..29c20656ac 100644 --- a/compiler/parallelize/code_loop.cpp +++ b/compiler/parallelize/code_loop.cpp @@ -88,7 +88,7 @@ SimpleForLoopInst* CodeLoop::generateSimpleScalarLoop(const string& counter) return static_cast(loop->clone(&cloner)); } -IteratorForLoopInst* CodeLoop::generateSimpleScalarLoop(const std::vector& iterators) +IteratorForLoopInst* CodeLoop::generateSimpleScalarLoop(uint fNumInputs, uint fNumOutputs, const std::vector& iterators) { std::vector iterators1; for (const auto& it : iterators) { @@ -96,7 +96,7 @@ IteratorForLoopInst* CodeLoop::generateSimpleScalarLoop(const std::vector(loop->clone(&cloner)); diff --git a/compiler/parallelize/code_loop.hh b/compiler/parallelize/code_loop.hh index f29254acb5..e7b5b10073 100644 --- a/compiler/parallelize/code_loop.hh +++ b/compiler/parallelize/code_loop.hh @@ -165,7 +165,7 @@ class CodeLoop : public virtual Garbageable { // For Rust backend SimpleForLoopInst* generateSimpleScalarLoop(const std::string& counter); - IteratorForLoopInst* generateSimpleScalarLoop(const std::vector& iterators); + IteratorForLoopInst* generateSimpleScalarLoop(uint fNumInputs, uint fNumOutputs, const std::vector& iterators); BlockInst* generateOneSample();