Skip to content

Partialy Solved #5

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 2 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
.DS_Store
3 changes: 3 additions & 0 deletions compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ class Compiler : public Visitor {
case ast::BinExp::Type::div:
result = RUNTIME_CALL(genericDiv, lhs, rhs);
return;
case ast::BinExp::Type::dot:
result = RUNTIME_CALL(genericDot, lhs, rhs);
return;
case ast::BinExp::Type::eq:
result = RUNTIME_CALL(genericEq, lhs, rhs);
return;
Expand Down
23 changes: 21 additions & 2 deletions runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,30 @@ RVal * c(int size, ...) {
}

double doubleDot(DoubleVector * lhs, DoubleVector * rhs) {
assert(false and "Fill me in");
double iRet = 0;
int maxSize = max(lhs->size, rhs->size);
for ( int i = 0; i < maxSize ; ++i){
iRet += lhs->data[i % lhs->size] * rhs->data[i % rhs->size];
}

return iRet;
}

RVal * genericDot(RVal * lhs, RVal * rhs) {
assert(false and "Fill me in");
if (lhs->type != rhs->type) {
throw "Types got to be same!";
}
if (lhs->type != RVal::Type::Double) {
throw "Left hand side must be Double";
}

if (rhs->type != RVal::Type::Double) {
throw "Right hand side must be double";
}

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


}


Expand Down
8 changes: 4 additions & 4 deletions tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ namespace rift {
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();
project2();
project3();
project4();
project5();
// project6();
}

Expand Down
9 changes: 6 additions & 3 deletions type_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ char TypeAnalysis::ID = 0;

AType * AType::top = createTop();



void TypeAnalysis::genericArithmetic(CallInst * ci) {
AType * lhs = state.get(ci->getOperand(0));
AType * rhs = state.get(ci->getOperand(1));
Expand Down Expand Up @@ -108,7 +106,9 @@ bool TypeAnalysis::runOnFunction(llvm::Function & f) {
genericRelational(ci);
} else if (s == "genericGt") {
genericRelational(ci);
} else if (s == "length") {
} else if (s == "genericDot") {
state.update(ci, new AType(AType::Kind::R, AType::Kind::DV, AType::Kind::D));
} else if (s == "length") {
// result of length operation is always
// double scalar
state.update(ci, new AType(AType::Kind::D));
Expand Down Expand Up @@ -191,5 +191,8 @@ void AType::print(std::ostream & s, MachineState & m) {
}
}




} // namespace rift

2 changes: 0 additions & 2 deletions type_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ class TypeAnalysis : public llvm::FunctionPass {
void genericArithmetic(llvm::CallInst * ci);
void genericRelational(llvm::CallInst * ci);
void genericGetElement(llvm::CallInst * ci);


};

} // namespace rift
Expand Down
21 changes: 21 additions & 0 deletions unboxing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ bool Unboxing::runOnFunction(llvm::Function & f) {
erase = genericC();
} else if (s == "genericEval") {
erase = genericEval();
} else if (s == "genericDot") {
erase = genericDot();
}
}
if (erase) {
Expand All @@ -374,5 +376,24 @@ bool Unboxing::runOnFunction(llvm::Function & f) {
}



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

if(lhs->isDouble() and rhs->isDouble()) {
llvm::Value * lhsPayload = getVectorPayload(lhs);
llvm::Value * rhsPayload = getVectorPayload(rhs);
AType* updated = updateAnalysis(RUNTIME_CALL(m->doubleDot, lhsPayload, rhsPayload), new AType(AType::Kind::D));
ins->replaceAllUsesWith(box(updated));
return true;
}
return false;
}





} // namespace rift

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