Skip to content

Commit

Permalink
wip move second half of ar loop generation into visitor function. for…
Browse files Browse the repository at this point in the history
… this i need the num io's
  • Loading branch information
crop2000 committed Oct 28, 2024
1 parent 9bb5139 commit aac001a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
13 changes: 8 additions & 5 deletions compiler/generator/instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1643,9 +1643,11 @@ struct IteratorForLoopInst : public StatementInst {
std::vector<NamedAddress*> fIterators;
const bool fReverse;
BlockInst* fCode;
uint fNumInputs;
uint fNumOutputs;

IteratorForLoopInst(const std::vector<NamedAddress*>& iterators, bool reverse, BlockInst* code)
: fIterators(iterators), fReverse(reverse), fCode(code)
IteratorForLoopInst(const std::vector<NamedAddress*>& iterators, bool reverse, BlockInst* code,uint fNumInputs,uint fNumOutputs)
: fIterators(iterators), fReverse(reverse), fCode(code), fNumInputs(fNumInputs), fNumOutputs(fNumOutputs)
{
}

Expand Down Expand Up @@ -1906,7 +1908,7 @@ class BasicCloneVisitor : public CloneVisitor {
iterators.push_back(static_cast<NamedAddress*>(it->clone(this)));
}
return new IteratorForLoopInst(iterators, inst->fReverse,
static_cast<BlockInst*>(inst->fCode->clone(this)));
static_cast<BlockInst*>(inst->fCode->clone(this)),inst->fNumInputs, inst->fNumOutputs);
}

virtual StatementInst* visit(WhileLoopInst* inst)
Expand Down Expand Up @@ -2560,11 +2562,12 @@ struct IB {
faustassert(castInt32(lowerBound) || dynamic_cast<LoadVarInst*>(lowerBound));
return new SimpleForLoopInst(name, upperBound, lowerBound, reverse, code);
}
static IteratorForLoopInst* genIteratorForLoopInst(const std::vector<NamedAddress*>& iterators,
static IteratorForLoopInst* genIteratorForLoopInst(uint fNumInputs, uint fNumOutputs,
const std::vector<NamedAddress*>& 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)
Expand Down
12 changes: 4 additions & 8 deletions compiler/generator/rust/rust_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions compiler/generator/rust/rust_instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions compiler/parallelize/code_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ SimpleForLoopInst* CodeLoop::generateSimpleScalarLoop(const string& counter)
return static_cast<SimpleForLoopInst*>(loop->clone(&cloner));
}

IteratorForLoopInst* CodeLoop::generateSimpleScalarLoop(const std::vector<string>& iterators)
IteratorForLoopInst* CodeLoop::generateSimpleScalarLoop(uint fNumInputs, uint fNumOutputs, const std::vector<string>& iterators)
{
std::vector<NamedAddress*> iterators1;
for (const auto& it : iterators) {
iterators1.push_back(IB::genNamedAddress(it, Address::kStack));
}

BlockInst* block = generateOneSample();
IteratorForLoopInst* loop = IB::genIteratorForLoopInst(iterators1, false, block);
IteratorForLoopInst* loop = IB::genIteratorForLoopInst(fNumInputs, fNumOutputs, iterators1, false, block);

BasicCloneVisitor cloner;
return static_cast<IteratorForLoopInst*>(loop->clone(&cloner));
Expand Down
2 changes: 1 addition & 1 deletion compiler/parallelize/code_loop.hh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class CodeLoop : public virtual Garbageable {

// For Rust backend
SimpleForLoopInst* generateSimpleScalarLoop(const std::string& counter);
IteratorForLoopInst* generateSimpleScalarLoop(const std::vector<std::string>& iterators);
IteratorForLoopInst* generateSimpleScalarLoop(uint fNumInputs, uint fNumOutputs, const std::vector<std::string>& iterators);

BlockInst* generateOneSample();

Expand Down

0 comments on commit aac001a

Please sign in to comment.