Skip to content

LLVM solution - [email protected] #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ class Compiler : public Visitor {
case ast::BinExp::Type::gt:
result = RUNTIME_CALL(genericGt, lhs, rhs);
return;
case ast::BinExp::Type::dot:
result = RUNTIME_CALL(genericDot, lhs, rhs);
return;
default: // can't happen
return;
}
Expand Down
15 changes: 13 additions & 2 deletions runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,22 @@ RVal * c(int size, ...) {
}

double doubleDot(DoubleVector * lhs, DoubleVector * rhs) {
assert(false and "Fill me in");
int maxLength = std::max(lhs->size, rhs->size);
double resolution = 0;

for(int i = 0; i < maxLength; i++)
{
resolution += lhs->data[i % lhs->size] * rhs->data[i % rhs->size];
}

return resolution;
}

RVal * genericDot(RVal * lhs, RVal * rhs) {
assert(false and "Fill me in");
if(lhs->type != RVal::Type::Double || rhs->type != RVal::Type::Double)
throw "Operands must be vectors of double";

return new RVal(new DoubleVector(doubleDot(lhs->d, rhs->d)));
}


Expand Down
20 changes: 12 additions & 8 deletions tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace rift {

void tests() {
cout << "Running tests..." << endl;
TEST("1", 1);
/* TEST("1", 1);
TEST("1 + 2", 3);
TEST("1 - 2", -1);
TEST("2 * 3", 6);
Expand Down Expand Up @@ -220,13 +220,17 @@ namespace rift {

TEST("a = c(1, 2, 3) a[1]", 2);
TEST("a = \"aba\" a[c(0,2)]", "aa");
TEST("a = c(1,2,3) a[c(0,1)] = 56 a", 56, 56, 3);

// project2();
// project3();
// project4();
// project5();
// project6();
TEST("a = c(1,2,3) a[c(0,1)] = 56 a", 56, 56, 3);*/
cout << "Running test for task 2" << endl;
project2();
cout << "Running test for task 3" << endl;
project3();
cout << "Running test for task 4" << endl;
project4();
cout << "Running test for task 5" << endl;
project5();
cout << "Running test for task 6" << endl;
project6();
}

} // namespace rift
4 changes: 3 additions & 1 deletion type_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ bool TypeAnalysis::runOnFunction(llvm::Function & f) {
state.update(ci, new AType(AType::Kind::R));
} else if (s == "envGet") {
state.update(ci, new AType(AType::Kind::R));
}
} else if (s == "genericDot"){
state.update(ci, new AType(AType::Kind::R, new AType(AType::Kind::DV, new AType(AType::Kind::D))));
}
} else if (PHINode * phi = dyn_cast<PHINode>(&i)) {
AType * first = state.get(phi->getOperand(0));
AType * second = state.get(phi->getOperand(1));
Expand Down
25 changes: 24 additions & 1 deletion unboxing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,27 @@ bool Unboxing::genericEval() {
}
}

bool Unboxing::genericDot() {
AType *lhs = state().get(ins->getOperand(0));
AType *rhs = state().get(ins->getOperand(1));
AType *tmp_result;

// both must be doubles
if( rhs->isDouble() and lhs->isDouble()) {
if(lhs->isScalar() and rhs->isScalar()) {
tmp_result = updateAnalysis(
BinaryOperator::Create(Instruction::FMul, getScalarPayload(lhs), getScalarPayload(rhs), "", ins), new AType(AType::Kind::D));
} else {
tmp_result = updateAnalysis( RUNTIME_CALL(m->doubleDot, getVectorPayload(lhs), getVectorPayload(rhs)), new AType(AType::Kind::D));
}

ins->replaceAllUsesWith(box(tmp_result));
return true;
} else {
return false;
}
}

bool Unboxing::runOnFunction(llvm::Function & f) {
//std::cout << "running Unboxing optimization..." << std::endl;
m = reinterpret_cast<RiftModule*>(f.getParent());
Expand Down Expand Up @@ -353,7 +374,9 @@ bool Unboxing::runOnFunction(llvm::Function & f) {
erase = genericC();
} else if (s == "genericEval") {
erase = genericEval();
}
} else if (s == "genericDot") {
erase = genericDot();
}
}
if (erase) {
llvm::Instruction * v = i;
Expand Down
2 changes: 2 additions & 0 deletions unboxing.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class Unboxing : public llvm::FunctionPass {

bool genericEval();

bool genericDot();

/** Rift module currently being optimized, obtained from the function.

The module is used for the declarations of the runtime functions.
Expand Down