-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a843b20
commit 3557629
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2021 The DAPHNE Consortium | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <api/cli/Utils.h> | ||
|
||
#include <tags.h> | ||
|
||
#include <fstream> | ||
|
||
#include <catch.hpp> | ||
|
||
#include <string> | ||
|
||
const std::string dirPath = "test/api/cli/functions/"; | ||
|
||
#define MAKE_TEST_CASE(name) \ | ||
TEST_CASE(name, TAG_FUNCTIONS) { \ | ||
std::stringstream err; \ | ||
std::stringstream out; \ | ||
DYNAMIC_SECTION(name << ".daphne") { runDaphne(&out,&err, name, "--explain property_inference"); } \ | ||
std::string expected = ""; \ | ||
std::string line; \ | ||
std::ifstream file(name+".txt"); \ | ||
while(std::getline(file,line)) { \ | ||
expected += line; \ | ||
} \ | ||
file.close(); \ | ||
REQUIRE(err+out == expected); \ | ||
} \ | ||
} | ||
|
||
MAKE_TEST_CASE("specializeIRTest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// This test script tests 3 aspects simultaneously by comparing the IR with the expected IR output (specializeIRTest.txt), which are the following: | ||
// Similar Function detection and prevention (c is expected to be replaced with b) | ||
// Recursion detection and prevention (a is expected to only have 5 recursive calls, meaning 6 specializations) | ||
// Naming Convention (All function names in the IR should follow the naming convention) | ||
|
||
|
||
def a(n: si64) -> si64 { | ||
if(n<=0) { | ||
return 1; | ||
} else { | ||
return a(n-1)+a(n-2); | ||
} | ||
|
||
} | ||
|
||
def b(n: si64) -> si64 { | ||
if(n>=2) { | ||
return 2*n; | ||
} else { | ||
return n*n; | ||
} | ||
} | ||
|
||
def c(n: si64) -> si64 { | ||
if(n>=5) { | ||
return n*2; | ||
} else { | ||
return n; | ||
} | ||
} | ||
|
||
print(a(10)); | ||
print(b(10)); | ||
print(c(10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
IR after inference: | ||
module { | ||
func.func @"b-2(10)"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 20 : si64} : () -> si64 | ||
"daphne.return"(%0) : (si64) -> () | ||
} | ||
func.func @"a-1(10)"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 8 : si64} : () -> si64 | ||
%1 = "daphne.constant"() {value = 9 : si64} : () -> si64 | ||
%2 = "daphne.generic_call"(%1) {callee = "a-1(9)"} : (si64) -> si64 | ||
%3 = "daphne.generic_call"(%0) {callee = "a-1"} : (si64) -> si64 | ||
%4 = "daphne.ewAdd"(%2, %3) : (si64, si64) -> si64 | ||
"daphne.return"(%4) : (si64) -> () | ||
} | ||
func.func @"a-1(9)"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 7 : si64} : () -> si64 | ||
%1 = "daphne.constant"() {value = 8 : si64} : () -> si64 | ||
%2 = "daphne.generic_call"(%1) {callee = "a-1(8)"} : (si64) -> si64 | ||
%3 = "daphne.generic_call"(%0) {callee = "a-1"} : (si64) -> si64 | ||
%4 = "daphne.ewAdd"(%2, %3) : (si64, si64) -> si64 | ||
"daphne.return"(%4) : (si64) -> () | ||
} | ||
func.func @"a-1(8)"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 6 : si64} : () -> si64 | ||
%1 = "daphne.constant"() {value = 7 : si64} : () -> si64 | ||
%2 = "daphne.generic_call"(%1) {callee = "a-1(7)"} : (si64) -> si64 | ||
%3 = "daphne.generic_call"(%0) {callee = "a-1"} : (si64) -> si64 | ||
%4 = "daphne.ewAdd"(%2, %3) : (si64, si64) -> si64 | ||
"daphne.return"(%4) : (si64) -> () | ||
} | ||
func.func @"a-1(7)"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 5 : si64} : () -> si64 | ||
%1 = "daphne.constant"() {value = 6 : si64} : () -> si64 | ||
%2 = "daphne.generic_call"(%1) {callee = "a-1(6)"} : (si64) -> si64 | ||
%3 = "daphne.generic_call"(%0) {callee = "a-1"} : (si64) -> si64 | ||
%4 = "daphne.ewAdd"(%2, %3) : (si64, si64) -> si64 | ||
"daphne.return"(%4) : (si64) -> () | ||
} | ||
func.func @"a-1(6)"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 4 : si64} : () -> si64 | ||
%1 = "daphne.constant"() {value = 5 : si64} : () -> si64 | ||
%2 = "daphne.generic_call"(%1) {callee = "a-1(5)"} : (si64) -> si64 | ||
%3 = "daphne.generic_call"(%0) {callee = "a-1"} : (si64) -> si64 | ||
%4 = "daphne.ewAdd"(%2, %3) : (si64, si64) -> si64 | ||
"daphne.return"(%4) : (si64) -> () | ||
} | ||
func.func @"a-1(5)"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 3 : si64} : () -> si64 | ||
%1 = "daphne.constant"() {value = 4 : si64} : () -> si64 | ||
%2 = "daphne.generic_call"(%1) {callee = "a-1"} : (si64) -> si64 | ||
%3 = "daphne.generic_call"(%0) {callee = "a-1"} : (si64) -> si64 | ||
%4 = "daphne.ewAdd"(%2, %3) : (si64, si64) -> si64 | ||
"daphne.return"(%4) : (si64) -> () | ||
} | ||
func.func @"a-1"(%arg0: si64) -> si64 { | ||
%0 = "daphne.constant"() {value = 2 : si64} : () -> si64 | ||
%1 = "daphne.constant"() {value = 1 : si64} : () -> si64 | ||
%2 = "daphne.constant"() {value = 0 : si64} : () -> si64 | ||
%3 = "daphne.ewLe"(%arg0, %2) : (si64, si64) -> si64 | ||
%4 = "daphne.cast"(%3) : (si64) -> i1 | ||
%5 = scf.if %4 -> (si64) { | ||
scf.yield %1 : si64 | ||
} else { | ||
%6 = "daphne.ewSub"(%arg0, %1) : (si64, si64) -> si64 | ||
%7 = "daphne.generic_call"(%6) {callee = "a-1"} : (si64) -> si64 | ||
%8 = "daphne.ewSub"(%arg0, %0) : (si64, si64) -> si64 | ||
%9 = "daphne.generic_call"(%8) {callee = "a-1"} : (si64) -> si64 | ||
%10 = "daphne.ewAdd"(%7, %9) : (si64, si64) -> si64 | ||
scf.yield %10 : si64 | ||
} | ||
"daphne.return"(%5) : (si64) -> () | ||
} | ||
func.func @main() { | ||
%0 = "daphne.constant"() {value = false} : () -> i1 | ||
%1 = "daphne.constant"() {value = true} : () -> i1 | ||
%2 = "daphne.constant"() {value = 10 : si64} : () -> si64 | ||
%3 = "daphne.generic_call"(%2) {callee = "a-1(10)"} : (si64) -> si64 | ||
"daphne.print"(%3, %1, %0) : (si64, i1, i1) -> () | ||
%4 = "daphne.generic_call"(%2) {callee = "b-2(10)"} : (si64) -> si64 | ||
"daphne.print"(%4, %1, %0) : (si64, i1, i1) -> () | ||
%5 = "daphne.generic_call"(%2) {callee = "b-2(10)"} : (si64) -> si64 | ||
"daphne.print"(%5, %1, %0) : (si64, i1, i1) -> () | ||
"daphne.return"() : () -> () | ||
} | ||
} | ||
144 | ||
20 | ||
20 |