Skip to content

Commit

Permalink
More robust type checking in DeclareVarInst::DeclareVarInst. Correct …
Browse files Browse the repository at this point in the history
…a bug in LLVM backend -fm mode. Set version to 2.5.7.
  • Loading branch information
sletz committed Nov 24, 2017
1 parent 80da781 commit 4799aca
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version := 2.5.6
version := 2.5.7

system ?= $(shell uname -s)

Expand Down
Binary file modified architecture/webaudio/libfaust-wasm.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions architecture/webaudio/libfaust.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions architecture/webaudio/libfaustworker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/generator/export.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef __export__
#define __export__

#define FAUSTVERSION "2.5.6"
#define FAUSTVERSION "2.5.7"

#ifdef _WIN32
#define EXPORT __declspec(dllexport)
Expand Down
19 changes: 14 additions & 5 deletions compiler/generator/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ DeclareVarInst::DeclareVarInst(Address* address, Typed* type, ValueInst* value)
:fAddress(address), fType(type), fValue(value)
{
if (gGlobal->gVarTypeTable.find(fAddress->getName()) == gGlobal->gVarTypeTable.end()) {
gGlobal->gVarTypeTable[fAddress->getName()] = type;
//cout << "DeclareVarInst " << fAddress->getName() << " " << Typed::gTypeString[type->getType()] << endl;
gGlobal->gVarTypeTable[fAddress->getName()] = type;
} else if (gGlobal->gVarTypeTable[fAddress->getName()] != type) {
//cout << "DeclareVarInst " << fAddress->getName() << endl;
//faustassert(false);
// If array type, check the internal type
ArrayTyped* type1 = dynamic_cast<ArrayTyped*>(gGlobal->gVarTypeTable[fAddress->getName()]);
ArrayTyped* type2 = dynamic_cast<ArrayTyped*>(type);
if (type1 && type2) {
faustassert(type1->fType == type2->fType);
} else {
faustassert(false);
}
}
}

Expand All @@ -64,7 +70,6 @@ DeclareFunInst::DeclareFunInst(const string& name, FunTyped* type, BlockInst* co
if (gGlobal->gVarTypeTable.find(name) == gGlobal->gVarTypeTable.end()) {
gGlobal->gVarTypeTable[name] = type->getTyped();
//cout << "DeclareFunInst " << name << " " << Typed::gTypeString[type->getType()] << endl;
//stacktrace(20);
} else if (gGlobal->gVarTypeTable[name] != type->getTyped()) {
//cout << "DeclareFunInst " << name << endl;
faustassert(false);
Expand Down Expand Up @@ -132,7 +137,10 @@ ValueInst* InstBuilder::genCastNumIntInst(ValueInst* inst)
}

// BasicTyped are not cloned, but actually point on the same underlying type
Typed* BasicCloneVisitor::visit(BasicTyped* typed) { return gGlobal->gTypeTable[typed->fType]; }
Typed* BasicCloneVisitor::visit(BasicTyped* typed)
{
return gGlobal->gTypeTable[typed->fType];
}

void Typed::init()
{
Expand Down Expand Up @@ -179,6 +187,7 @@ bool BlockInst::hasReturn()
return dynamic_cast<RetInst*>(*it);
}

// Return the block value (if is has one) and remove it from the block
ValueInst* BlockInst::getReturnValue()
{
list<StatementInst*>::const_iterator it = fCode.end(); it--;
Expand Down
3 changes: 1 addition & 2 deletions compiler/generator/instructions.hh
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ struct BasicTyped : public Typed {

static void cleanup();

BasicTyped(VarType type)
:fType(type)
BasicTyped(VarType type):fType(type)
{}

VarType getType() { return fType; }
Expand Down
59 changes: 33 additions & 26 deletions compiler/generator/llvm/llvm_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,36 @@ void LLVMCodeContainer::generateGetSize(LlvmValue size)
verifyFunction(*llvm_getSize);
}

void LLVMCodeContainer::generateFunMaps()
{
if (gGlobal->gFastMath) {
generateFunMap("acos", "fast_acos", 1);
generateFunMap("asin", "fast_asin", 1);
generateFunMap("atan", "fast_atan", 1);
generateFunMap("atan2", "fast_atan2", 2);
generateFunMap("ceil", "fast_ceil", 1);
generateFunMap("cos", "fast_cos", 1);
generateFunMap("exp", "fast_exp", 1);
generateFunMap("exp2", "fast_exp2", 1);
generateFunMap("exp10", "fast_exp10", 1);
generateFunMap("floor", "fast_floor", 1);
generateFunMap("fmod", "fast_fmod", 2);
generateFunMap("log", "fast_log", 1);
generateFunMap("log2", "fast_log2", 1);
generateFunMap("log10", "fast_log10", 1);
generateFunMap("pow", "fast_pow", 2);
generateFunMap("remainder", "fast_remainder", 2);
generateFunMap("round", "fast_round", 1);
generateFunMap("sin", "fast_sin", 1);
generateFunMap("sqrt", "fast_sqrt", 1);
generateFunMap("tan", "fast_tan", 1);
} else {
#ifdef __APPLE__
generateFunMap("exp10", "__exp10", 1, true);
#endif
}
}

void LLVMCodeContainer::produceInternal()
{
// Creates DSP structure
Expand All @@ -714,6 +744,8 @@ void LLVMCodeContainer::produceInternal()

fCodeProducer = new LLVMInstVisitor(fModule, fBuilder, fAllocaBuilder, fTypeBuilder.getFieldNames(), fTypeBuilder.getUIPtr(), fStructDSP, fKlassName);

generateFunMaps();

generateInfoFunctions(fKlassName, false);

// Global declarations
Expand Down Expand Up @@ -783,32 +815,7 @@ dsp_factory_base* LLVMCodeContainer::produceFactory()

fCodeProducer = new LLVMInstVisitor(fModule, fBuilder, fAllocaBuilder, fields_names, fTypeBuilder.getUIPtr(), fStructDSP, fKlassName);

if (gGlobal->gFastMath) {
generateFunMap("acos", "fast_acos", 1);
generateFunMap("asin", "fast_asin", 1);
generateFunMap("atan", "fast_atan", 1);
generateFunMap("atan2", "fast_atan2", 2);
generateFunMap("ceil", "fast_ceil", 1);
generateFunMap("cos", "fast_cos", 1);
generateFunMap("exp", "fast_exp", 1);
generateFunMap("exp2", "fast_exp2", 1);
generateFunMap("exp10", "fast_exp10", 1);
generateFunMap("floor", "fast_floor", 1);
generateFunMap("fmod", "fast_fmod", 2);
generateFunMap("log", "fast_log", 1);
generateFunMap("log2", "fast_log2", 1);
generateFunMap("log10", "fast_log10", 1);
generateFunMap("pow", "fast_pow", 2);
generateFunMap("remainder", "fast_remainder", 2);
generateFunMap("round", "fast_round", 1);
generateFunMap("sin", "fast_sin", 1);
generateFunMap("sqrt", "fast_sqrt", 1);
generateFunMap("tan", "fast_tan", 1);
} else {
#ifdef __APPLE__
generateFunMap("exp10", "__exp10", 1, true);
#endif
}
generateFunMaps();

generateInfoFunctions(fKlassName, true);

Expand Down
2 changes: 2 additions & 0 deletions compiler/generator/llvm/llvm_code_container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class LLVMCodeContainer : public virtual CodeContainer {

// To be used for mathematical function mapping (-fm and exp10 on OSX)
void generateFunMap(const string& fun1_aux, const string& fun2_aux, int num_args, bool body = false);

void generateFunMaps();

public:

Expand Down

0 comments on commit 4799aca

Please sign in to comment.