Skip to content

Commit

Permalink
Correct wast backend -fm code generation, add use of 'tee-local' in F…
Browse files Browse the repository at this point in the history
…unctionInliner, cleanup.
  • Loading branch information
sletz committed Nov 25, 2017
1 parent d383ec9 commit c387d7e
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 89 deletions.
11 changes: 9 additions & 2 deletions compiler/generator/fir_to_fir.hh
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,17 @@ struct FunctionInliner {
if (fVarTable.find(fNamed->fName) == fVarTable.end()) {
// Create a stack variable with the value
string tmp_in = gGlobal->getFreshID("tmp_in");
fBlockStack.top()->pushBackInst(InstBuilder::genDecStackVar(tmp_in, fNamed->fType->clone(&cloner), fArg->clone(&cloner)));
fVarTable[fNamed->fName] = tmp_in;
if (gGlobal->gHasTeeLocal) {
fBlockStack.top()->pushBackInst(InstBuilder::genDecStackVar(tmp_in, fNamed->fType->clone(&cloner)));
return InstBuilder::genTeeVar(tmp_in, fArg->clone(&cloner));
} else {
fBlockStack.top()->pushBackInst(InstBuilder::genDecStackVar(tmp_in, fNamed->fType->clone(&cloner), fArg->clone(&cloner)));
return InstBuilder::genLoadStackVar(tmp_in);
}
} else {
return InstBuilder::genLoadStackVar(fVarTable[fNamed->fName]);
}
return InstBuilder::genLoadStackVar(fVarTable[fNamed->fName]);
}
} else {
return inst->clone(&cloner);
Expand Down
40 changes: 0 additions & 40 deletions compiler/generator/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "sigtype.hh"
#include "global.hh"
#include "floats.hh"
#include "global.hh"

std::stack<BlockInst*> BasicCloneVisitor::fBlockStack;

Expand Down Expand Up @@ -142,45 +141,6 @@ Typed* BasicCloneVisitor::visit(BasicTyped* typed)
return gGlobal->gTypeTable[typed->fType];
}

void Typed::init()
{
gGlobal->gTypeSizeMap.clear();

gGlobal->gTypeSizeMap[Typed::kFloat] = gGlobal->gMachineFloatSize;
gGlobal->gTypeSizeMap[Typed::kFloat_ptr] = gGlobal->gMachinePtrSize;
gGlobal->gTypeSizeMap[Typed::kFloat_vec] = gGlobal->gMachineFloatSize * gGlobal->gVecSize;
gGlobal->gTypeSizeMap[Typed::kFloat_vec_ptr] = gGlobal->gMachinePtrSize;

gGlobal->gTypeSizeMap[Typed::kInt32] = gGlobal->gMachineInt32Size;
gGlobal->gTypeSizeMap[Typed::kInt32_ptr] = gGlobal->gMachinePtrSize;
gGlobal->gTypeSizeMap[Typed::kInt32_vec] = gGlobal->gMachineInt32Size * gGlobal->gVecSize;
gGlobal->gTypeSizeMap[Typed::kInt32_vec_ptr] = gGlobal->gMachinePtrSize;

gGlobal->gTypeSizeMap[Typed::kInt64] = gGlobal->gMachineInt64Size;
gGlobal->gTypeSizeMap[Typed::kInt64_ptr] = gGlobal->gMachinePtrSize;
gGlobal->gTypeSizeMap[Typed::kInt64_vec] = gGlobal->gMachineInt64Size * gGlobal->gVecSize;
gGlobal->gTypeSizeMap[Typed::kInt64_vec_ptr] = gGlobal->gMachinePtrSize;

gGlobal->gTypeSizeMap[Typed::kDouble] = gGlobal->gMachineDoubleSize;
gGlobal->gTypeSizeMap[Typed::kDouble_ptr] = gGlobal->gMachinePtrSize;
gGlobal->gTypeSizeMap[Typed::kDouble_vec] = gGlobal->gMachineDoubleSize * gGlobal->gVecSize;
gGlobal->gTypeSizeMap[Typed::kDouble_vec_ptr] = gGlobal->gMachinePtrSize;

gGlobal->gTypeSizeMap[Typed::kBool] = gGlobal->gMachineBoolSize;
gGlobal->gTypeSizeMap[Typed::kBool_ptr] = gGlobal->gMachinePtrSize;
gGlobal->gTypeSizeMap[Typed::kBool_vec] = gGlobal->gMachineBoolSize * gGlobal->gVecSize;
gGlobal->gTypeSizeMap[Typed::kBool_vec_ptr] = gGlobal->gMachinePtrSize;

// Takes the type of internal real
gGlobal->gTypeSizeMap[Typed::kFloatMacro] = gGlobal->gTypeSizeMap[itfloat()];
gGlobal->gTypeSizeMap[Typed::kFloatMacro_ptr] = gGlobal->gMachinePtrSize;

gGlobal->gTypeSizeMap[Typed::kVoid_ptr] = gGlobal->gMachinePtrSize;
gGlobal->gTypeSizeMap[Typed::kVoid_ptr_ptr] = gGlobal->gMachinePtrSize;

gGlobal->gTypeSizeMap[Typed::kObj_ptr] = gGlobal->gMachinePtrSize;
}

bool BlockInst::hasReturn()
{
list<StatementInst*>::const_iterator it = fCode.end(); it--;
Expand Down
11 changes: 8 additions & 3 deletions compiler/generator/instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ struct Typed : public Printable

static string gTypeString[];

static void init();

Typed()
{}

Expand Down Expand Up @@ -1522,7 +1520,14 @@ class BasicCloneVisitor : public CloneVisitor {
virtual StatementInst* visit(DropInst* inst) { return new DropInst((inst->fResult) ? inst->fResult->clone(this) : NULL); }

// Conditionnal
virtual ValueInst* visit(Select2Inst* inst) { return new Select2Inst(inst->fCond->clone(this), inst->fThen->clone(this), inst->fElse->clone(this), inst->fSize); }
virtual ValueInst* visit(Select2Inst* inst)
{
ValueInst* then_exp = inst->fThen->clone(this);
ValueInst* else_exp = inst->fElse->clone(this);
ValueInst* cond_exp = inst->fCond->clone(this);
// cond_exp has to be evaluated last for FunctionInliner to correctly work in gHasTeeLocal mode
return new Select2Inst(cond_exp, then_exp, else_exp);
}
virtual StatementInst* visit(IfInst* inst)
{
return new IfInst(inst->fCond->clone(this), dynamic_cast<BlockInst*>(inst->fThen->clone(this)), dynamic_cast<BlockInst*>(inst->fElse->clone(this)));
Expand Down
12 changes: 6 additions & 6 deletions compiler/generator/typing_instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ struct TypingVisitor : public InstVisitor {
//dump2FIR(inst);

// Stack or struct variables
if (gGlobal->gVarTypeTable.find(inst->getName()) != gGlobal->gVarTypeTable.end()) {
fCurType = gGlobal->gVarTypeTable[inst->getName()]->getType();
if (gGlobal->hasVarType(inst->getName())) {
fCurType = gGlobal->getVarType(inst->getName());
if (dynamic_cast<IndexedAddress*>(inst->fAddress)) {
fCurType = Typed::getTypeFromPtr(fCurType);
}
Expand All @@ -60,8 +60,8 @@ struct TypingVisitor : public InstVisitor {

virtual void visit(TeeVarInst* inst)
{
if (gGlobal->gVarTypeTable.find(inst->getName()) != gGlobal->gVarTypeTable.end()) {
fCurType = gGlobal->gVarTypeTable[inst->getName()]->getType();
if (gGlobal->hasVarType(inst->getName())) {
fCurType = gGlobal->getVarType(inst->getName());
} else {
fCurType = Typed::kNoType;
}
Expand Down Expand Up @@ -150,8 +150,8 @@ struct TypingVisitor : public InstVisitor {

virtual void visit(FunCallInst* inst)
{
if (gGlobal->gVarTypeTable.find(inst->fName) != gGlobal->gVarTypeTable.end()) {
fCurType = gGlobal->gVarTypeTable[inst->fName]->getType();
if (gGlobal->hasVarType(inst->fName)) {
fCurType = gGlobal->getVarType(inst->fName);
} else {
// Should never happen...
faustassert(false);
Expand Down
4 changes: 2 additions & 2 deletions compiler/generator/wasm/wast_instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class WASTInstVisitor : public TextInstVisitor, public WASInst {
if (desc.fMode == MathFunDesc::Gen::kExtMath || desc.fMode == MathFunDesc::Gen::kExtWAS) {
tab(fTab, *fOut);
if (desc.fMode == MathFunDesc::Gen::kExtMath || desc.fMode == MathFunDesc::Gen::kExtWAS) {
*fOut << "(import $" << inst->fName << " \"env\" \"" << gGlobal->getMathFunction(desc.fName) << "\" (param ";
*fOut << "(import $" << inst->fName << " \"env\" \"" << gGlobal->getMathFunction(inst->fName) << "\" (param ";
} else {
faustassert(false);
}
Expand Down Expand Up @@ -523,7 +523,7 @@ class WASTInstVisitor : public TextInstVisitor, public WASInst {
*fOut << "(" << realStr << "." << desc.fName << " ";
}
} else {
*fOut << "(call $" << gGlobal->getMathFunction(inst->fName) << " ";
*fOut << "(call $" << inst->fName << " ";
}
} else {
*fOut << "(call $" << inst->fName << " ";
Expand Down
61 changes: 47 additions & 14 deletions compiler/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,29 +431,29 @@ void global::init()
gAllocationCount = 0;
gEnableFlag = true;

TINT = makeSimpleType(kInt, kKonst, kComp, kVect, kNum, interval());
TREAL = makeSimpleType(kReal, kKonst, kComp, kVect, kNum, interval());
TINT = makeSimpleType(kInt, kKonst, kComp, kVect, kNum, interval());
TREAL = makeSimpleType(kReal, kKonst, kComp, kVect, kNum, interval());

TKONST = makeSimpleType(kInt, kKonst, kComp, kVect, kNum, interval());
TBLOCK = makeSimpleType(kInt, kBlock, kComp, kVect, kNum, interval());
TSAMP = makeSimpleType(kInt, kSamp, kComp, kVect, kNum, interval());
TSAMP = makeSimpleType(kInt, kSamp, kComp, kVect, kNum, interval());

TCOMP = makeSimpleType(kInt, kKonst, kComp, kVect, kNum, interval());
TINIT = makeSimpleType(kInt, kKonst, kInit, kVect, kNum, interval());
TEXEC = makeSimpleType(kInt, kKonst, kExec, kVect, kNum, interval());
TCOMP = makeSimpleType(kInt, kKonst, kComp, kVect, kNum, interval());
TINIT = makeSimpleType(kInt, kKonst, kInit, kVect, kNum, interval());
TEXEC = makeSimpleType(kInt, kKonst, kExec, kVect, kNum, interval());

// more predefined types

TINPUT = makeSimpleType(kReal, kSamp, kExec, kVect, kNum, interval());
TGUI = makeSimpleType(kReal, kBlock,kExec, kVect, kNum, interval());
TGUI01 = makeSimpleType(kReal, kBlock,kExec, kVect, kNum, interval(0,1));
INT_TGUI = makeSimpleType(kInt, kBlock,kExec, kVect, kNum, interval());
TINPUT = makeSimpleType(kReal, kSamp, kExec, kVect, kNum, interval());
TGUI = makeSimpleType(kReal, kBlock,kExec, kVect, kNum, interval());
TGUI01 = makeSimpleType(kReal, kBlock,kExec, kVect, kNum, interval(0,1));
INT_TGUI = makeSimpleType(kInt, kBlock,kExec, kVect, kNum, interval());

TREC = makeSimpleType(kInt, kSamp, kInit, kScal, kNum, interval());
TREC = makeSimpleType(kInt, kSamp, kInit, kScal, kNum, interval());

// predefined symbols CONS and NIL
CONS = symbol("cons");
NIL = symbol("nil");
NIL = symbol("nil");

// predefined nil tree
nil = tree(NIL);
Expand Down Expand Up @@ -486,8 +486,41 @@ void global::init()

gLatexheaderfilename = "latexheader.tex";
gDocTextsDefaultFile = "mathdoctexts-default.txt";

Typed::init();

// Init type size table
gTypeSizeMap[Typed::kFloat] = gMachineFloatSize;
gTypeSizeMap[Typed::kFloat_ptr] = gMachinePtrSize;
gTypeSizeMap[Typed::kFloat_vec] = gMachineFloatSize * gVecSize;
gTypeSizeMap[Typed::kFloat_vec_ptr] = gMachinePtrSize;

gTypeSizeMap[Typed::kInt32] = gMachineInt32Size;
gTypeSizeMap[Typed::kInt32_ptr] = gMachinePtrSize;
gTypeSizeMap[Typed::kInt32_vec] = gMachineInt32Size * gVecSize;
gTypeSizeMap[Typed::kInt32_vec_ptr] = gMachinePtrSize;

gTypeSizeMap[Typed::kInt64] = gMachineInt64Size;
gTypeSizeMap[Typed::kInt64_ptr] = gMachinePtrSize;
gTypeSizeMap[Typed::kInt64_vec] = gMachineInt64Size * gVecSize;
gTypeSizeMap[Typed::kInt64_vec_ptr] = gMachinePtrSize;

gTypeSizeMap[Typed::kDouble] = gMachineDoubleSize;
gTypeSizeMap[Typed::kDouble_ptr] = gMachinePtrSize;
gTypeSizeMap[Typed::kDouble_vec] = gMachineDoubleSize * gVecSize;
gTypeSizeMap[Typed::kDouble_vec_ptr] = gMachinePtrSize;

gTypeSizeMap[Typed::kBool] = gMachineBoolSize;
gTypeSizeMap[Typed::kBool_ptr] = gMachinePtrSize;
gTypeSizeMap[Typed::kBool_vec] = gMachineBoolSize * gVecSize;
gTypeSizeMap[Typed::kBool_vec_ptr] = gMachinePtrSize;

// Takes the type of internal real
gTypeSizeMap[Typed::kFloatMacro] = gTypeSizeMap[itfloat()];
gTypeSizeMap[Typed::kFloatMacro_ptr] = gMachinePtrSize;

gTypeSizeMap[Typed::kVoid_ptr] = gMachinePtrSize;
gTypeSizeMap[Typed::kVoid_ptr_ptr] = gMachinePtrSize;

gTypeSizeMap[Typed::kObj_ptr] = gMachinePtrSize;

gCurrentLocal = setlocale(LC_ALL, NULL);
if (gCurrentLocal != NULL) {
Expand Down
16 changes: 13 additions & 3 deletions compiler/global.hh
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ struct global {
map<Tree, string> gBackLink; // link to enclosing file for sub schema

// FIR
map<Typed::VarType, BasicTyped*> gTypeTable;
map<string, Typed*> gVarTypeTable; // Types of variables or functions
map<Typed::VarType, int> gTypeSizeMap; // Size of types in bytes
map<Typed::VarType, BasicTyped*> gTypeTable; // To share a unique BasicTyped* object for a given type
map<string, Typed*> gVarTypeTable; // Types of variables or functions
map<Typed::VarType, int> gTypeSizeMap; // Size of types in bytes

// colorize
map<Tree, int> gColorMap;
Expand Down Expand Up @@ -518,6 +518,16 @@ struct global {
return name;
}
}

bool hasVarType(const string& name)
{
return gVarTypeTable.find(name) != gVarTypeTable.end();
}

Typed::VarType getVarType(const string& name)
{
return gVarTypeTable[name]->getType();
}
};

// Unique shared global pointer
Expand Down
15 changes: 10 additions & 5 deletions embedded/faust4processing/src/libfaust_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ using namespace std;

static char gLastError[256];

llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename, const char* argv,
const char* target, int opt_level)
llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename,
const char* argv,
const char* target,
int opt_level)
{
int argc1 = 0;
const char* argv1[64];
Expand All @@ -69,8 +71,11 @@ llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename, const char*
return factory;
}

llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app, const char* dsp_content,
const char* argv, const char* target, int opt_level)
llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app,
const char* dsp_content,
const char* argv,
const char* target,
int opt_level)
{
int argc1 = 0;
const char* argv1[64];
Expand All @@ -94,4 +99,4 @@ llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app, const cha
const char* getCDSPLastError()
{
return gLastError;
}
}
15 changes: 10 additions & 5 deletions embedded/faust4processing/src/libfaust_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@

#include "faust/dsp/llvm-c-dsp.h"

llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename, const char* argv,
const char* target, int opt_level);
llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename,
const char* argv,
const char* target,
int opt_level);

llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app, const char* dsp_content,
const char* argv, const char* target, int opt_level);
llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app,
const char* dsp_content,
const char* argv,
const char* target,
int opt_level);

const char* getCDSPLastError();


2 changes: 2 additions & 0 deletions embedded/faustcsound/faustcsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class controls : public UI {
FAUSTFLOAT min, FAUSTFLOAT max){};
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone,
FAUSTFLOAT min, FAUSTFLOAT max) {};

void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) {}

MYFLT *getZone(char *label){
ctl *pctl = &anchor;
Expand Down
15 changes: 10 additions & 5 deletions embedded/faustjava/libfaust_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ using namespace std;

static char gLastError[256];

llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename, const char* argv,
const char* target, int opt_level)
llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename,
const char* argv,
const char* target,
int opt_level)
{
int argc1 = 0;
const char* argv1[64];
Expand All @@ -69,8 +71,11 @@ llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename, const char*
return factory;
}

llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app, const char* dsp_content,
const char* argv, const char* target, int opt_level)
llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app,
const char* dsp_content,
const char* argv,
const char* target,
int opt_level)
{
int argc1 = 0;
const char* argv1[64];
Expand All @@ -94,4 +99,4 @@ llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app, const cha
const char* getCDSPLastError()
{
return gLastError;
}
}
13 changes: 9 additions & 4 deletions embedded/faustjava/libfaust_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@
#include "faust/dsp/llvm-c-dsp.h"
#include "faust/dsp/libfaust-c.h"

llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename, const char* argv,
const char* target, int opt_level);
llvm_dsp_factory* createCDSPFactoryFromFileAux(const char* filename,
const char* argv,
const char* target,
int opt_level);

llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app, const char* dsp_content,
const char* argv, const char* target, int opt_level);
llvm_dsp_factory* createCDSPFactoryFromStringAux(const char* name_app,
const char* dsp_content,
const char* argv,
const char* target,
int opt_level);

const char* getCDSPLastError();

Expand Down

0 comments on commit c387d7e

Please sign in to comment.