Loading compiler/QCORCompiler.cpp +11 −8 Original line number Diff line number Diff line #include "QCORCompiler.hpp" #include "IRProvider.hpp" #include "xacc_service.hpp" namespace qcor { std::shared_ptr<IR> QCORCompiler::compile(const std::string &src, std::shared_ptr<Accelerator> acc) { return nullptr; } Loading @@ -16,19 +17,21 @@ std::shared_ptr<IR> QCORCompiler::compile(const std::string &src) { const std::shared_ptr<Function> QCORCompiler::compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) { if (acc) { // xacc::info("[qcor] Compiling for " + acc->name()); } // Hardware Independent Transformation auto provider = xacc::getService<xacc::IRProvider>("quantum"); auto ir = provider->createIR(); ir->addKernel(f); // FIXME Hardware Independent Transformation // Hardware Dependent Transformations if (acc) { auto ts = acc->getIRTransformations(); for (auto& t : ts) { ir = t->transform(ir); } } // Program Verification??? // FIXME Program Verification??? return f; } Loading compiler/clang/FuzzyParsingExternalSemaSource.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -30,9 +30,12 @@ bool FuzzyParsingExternalSemaSource::LookupUnqualified(clang::LookupResult &R, // If this is a valid quantum instruction, tell Clang its // all gonna be ok, we got this... if (std::find(validInstructions.begin(), validInstructions.end(), unknownName) != validInstructions.end()) { if (std::find(validInstructions.begin(), validInstructions.end(), // not template scope unknownName) != validInstructions.end() && S->getFlags() != 128 && S->getBlockParent() != nullptr) { // std::cout << "HELLO FP: " << unknownName << ", " << S->getFlags() << "\n"; // S->dump(); // S->getBlockParent()->dump(); IdentifierInfo *II = Name.getAsIdentifierInfo(); SourceLocation Loc = R.getNameLoc(); auto fdecl = FunctionDecl::Create( Loading compiler/clang/LambdaVisitor.cpp +7 −6 Original line number Diff line number Diff line Loading @@ -162,8 +162,8 @@ bool LambdaVisitor::CallExprToIRGenerator::VisitInitListExpr( ScanInitListExpr visitor; visitor.TraverseStmt(child); options.insert({visitor.key, visitor.value}); std::cout << "Inserting " << visitor.key << ", " << visitor.value.toString() << "\n"; // std::cout << "Inserting " << visitor.key << ", " // << visitor.value.toString() << "\n"; } keepSearching = false; Loading @@ -182,7 +182,6 @@ bool LambdaVisitor::CallExprToIRGenerator::VisitDeclRefExpr(DeclRefExpr *decl) { if (dyn_cast<ParmVarDecl>(decl->getDecl())) { auto declName = decl->getNameInfo().getAsString(); // std::cout << "IRGENERATOR FOUND PARAM: " << declName << "\n"; options.insert({"param-id", declName}); } return true; Loading Loading @@ -268,6 +267,7 @@ bool LambdaVisitor::ScanInitListExpr::VisitStringLiteral( } return true; } bool LambdaVisitor::ScanInitListExpr::VisitFloatingLiteral( FloatingLiteral *literal) { Loading @@ -280,6 +280,7 @@ bool LambdaVisitor::ScanInitListExpr::VisitFloatingLiteral( } return true; } bool LambdaVisitor::ScanInitListExpr::VisitIntegerLiteral( IntegerLiteral *literal) { Loading Loading @@ -325,8 +326,8 @@ bool LambdaVisitor::VisitLambdaExpr(LambdaExpr *LE) { // If it is, then map it to XACC IR if (isqk.isQuantumKernel()) { LE->dumpColor(); // LE->dumpColor(); // exit(0); auto cb = LE->capture_begin(); // implicit_capture_begin(); auto ce = LE->capture_end(); VarDecl *v; Loading Loading @@ -386,7 +387,7 @@ bool LambdaVisitor::VisitLambdaExpr(LambdaExpr *LE) { } } std::cout << "\n\nXACC IR:\n" << function->toString() << "\n"; // std::cout << "\n\nXACC IR:\n" << function->toString() << "\n"; // Check if we have IRGenerators in the tree if (function->hasIRGenerators()) { Loading compiler/clang/QCORASTConsumer.cpp +19 −4 Original line number Diff line number Diff line #include "QCORASTConsumer.hpp" #include "LambdaVisitor.hpp" #include <chrono> // #include "clang/ASTMatchers/ASTMatchFinder.h" // #include "clang/ASTMatchers/ASTMatchers.h" // using namespace clang::ast_matchers; using namespace clang; Loading @@ -7,16 +13,25 @@ namespace qcor { namespace compiler { QCORASTConsumer::QCORASTConsumer(CompilerInstance &c, Rewriter &rw) : ci(c), fuzzyParser(std::make_shared<FuzzyParsingExternalSemaSource>( c.getASTContext())), rewriter(rw) {} c.getASTContext())), rewriter(rw) {} bool QCORASTConsumer::HandleTopLevelDecl(DeclGroupRef DR) { using namespace std::chrono; auto start = std::chrono::high_resolution_clock::now(); LambdaVisitor visitor(ci, rewriter); ci.getSema().addExternalSource(fuzzyParser.get()); for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { // if (std::string((*b)->getDeclKindName()) == "Function") { // std::cout << (*b)->getDeclKindName() << "\n"; // (*b)->dumpColor(); visitor.TraverseDecl(*b); // } } auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<microseconds>(stop - start); // std::cout << "Visitor time: " << duration.count() << ", " << std::endl; return true; } } // namespace compiler Loading compiler/clang/qcor-driver.in.cpp +7 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <fstream> #include <string> #include "FuzzyParsingExternalSemaSource.hpp" #include "QCORASTConsumer.hpp" #include "XACC.hpp" using namespace clang; Loading @@ -46,6 +48,9 @@ protected: CI.createSema(getTranslationUnitKind(), nullptr); rewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); qcor::compiler::FuzzyParsingExternalSemaSource source(CI.getASTContext()); CI.getSema().addExternalSource(&source); ParseAST(CI.getSema()); CI.getDiagnosticClient().EndSourceFile(); Loading Loading @@ -86,7 +91,6 @@ int main(int argc, char **argv) { xacc::error("File " + fileName + " does not exist."); } std::ifstream t(fileName); std::string src((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>()); Loading @@ -96,10 +100,8 @@ int main(int argc, char **argv) { auto action = new QCORFrontendAction(Rewrite, fileName); std::vector<std::string> args{ "-std=c++11", "-I@CMAKE_INSTALL_PREFIX@/include/qcor", "-I@CMAKE_INSTALL_PREFIX@/include/xacc", "-I@CMAKE_INSTALL_PREFIX@/include/cppmicroservices4", "-I@CMAKE_INSTALL_PREFIX@/include/quantum/gate"}; "-ftime-report", "-std=c++11", "-I@CMAKE_INSTALL_PREFIX@/include/qcor", "-I@CMAKE_INSTALL_PREFIX@/include/xacc"}; if (!tooling::runToolOnCodeWithArgs(action, src, args)) { xacc::error("Error running qcor compiler."); Loading Loading
compiler/QCORCompiler.cpp +11 −8 Original line number Diff line number Diff line #include "QCORCompiler.hpp" #include "IRProvider.hpp" #include "xacc_service.hpp" namespace qcor { std::shared_ptr<IR> QCORCompiler::compile(const std::string &src, std::shared_ptr<Accelerator> acc) { return nullptr; } Loading @@ -16,19 +17,21 @@ std::shared_ptr<IR> QCORCompiler::compile(const std::string &src) { const std::shared_ptr<Function> QCORCompiler::compile(std::shared_ptr<Function> f, std::shared_ptr<Accelerator> acc) { if (acc) { // xacc::info("[qcor] Compiling for " + acc->name()); } // Hardware Independent Transformation auto provider = xacc::getService<xacc::IRProvider>("quantum"); auto ir = provider->createIR(); ir->addKernel(f); // FIXME Hardware Independent Transformation // Hardware Dependent Transformations if (acc) { auto ts = acc->getIRTransformations(); for (auto& t : ts) { ir = t->transform(ir); } } // Program Verification??? // FIXME Program Verification??? return f; } Loading
compiler/clang/FuzzyParsingExternalSemaSource.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -30,9 +30,12 @@ bool FuzzyParsingExternalSemaSource::LookupUnqualified(clang::LookupResult &R, // If this is a valid quantum instruction, tell Clang its // all gonna be ok, we got this... if (std::find(validInstructions.begin(), validInstructions.end(), unknownName) != validInstructions.end()) { if (std::find(validInstructions.begin(), validInstructions.end(), // not template scope unknownName) != validInstructions.end() && S->getFlags() != 128 && S->getBlockParent() != nullptr) { // std::cout << "HELLO FP: " << unknownName << ", " << S->getFlags() << "\n"; // S->dump(); // S->getBlockParent()->dump(); IdentifierInfo *II = Name.getAsIdentifierInfo(); SourceLocation Loc = R.getNameLoc(); auto fdecl = FunctionDecl::Create( Loading
compiler/clang/LambdaVisitor.cpp +7 −6 Original line number Diff line number Diff line Loading @@ -162,8 +162,8 @@ bool LambdaVisitor::CallExprToIRGenerator::VisitInitListExpr( ScanInitListExpr visitor; visitor.TraverseStmt(child); options.insert({visitor.key, visitor.value}); std::cout << "Inserting " << visitor.key << ", " << visitor.value.toString() << "\n"; // std::cout << "Inserting " << visitor.key << ", " // << visitor.value.toString() << "\n"; } keepSearching = false; Loading @@ -182,7 +182,6 @@ bool LambdaVisitor::CallExprToIRGenerator::VisitDeclRefExpr(DeclRefExpr *decl) { if (dyn_cast<ParmVarDecl>(decl->getDecl())) { auto declName = decl->getNameInfo().getAsString(); // std::cout << "IRGENERATOR FOUND PARAM: " << declName << "\n"; options.insert({"param-id", declName}); } return true; Loading Loading @@ -268,6 +267,7 @@ bool LambdaVisitor::ScanInitListExpr::VisitStringLiteral( } return true; } bool LambdaVisitor::ScanInitListExpr::VisitFloatingLiteral( FloatingLiteral *literal) { Loading @@ -280,6 +280,7 @@ bool LambdaVisitor::ScanInitListExpr::VisitFloatingLiteral( } return true; } bool LambdaVisitor::ScanInitListExpr::VisitIntegerLiteral( IntegerLiteral *literal) { Loading Loading @@ -325,8 +326,8 @@ bool LambdaVisitor::VisitLambdaExpr(LambdaExpr *LE) { // If it is, then map it to XACC IR if (isqk.isQuantumKernel()) { LE->dumpColor(); // LE->dumpColor(); // exit(0); auto cb = LE->capture_begin(); // implicit_capture_begin(); auto ce = LE->capture_end(); VarDecl *v; Loading Loading @@ -386,7 +387,7 @@ bool LambdaVisitor::VisitLambdaExpr(LambdaExpr *LE) { } } std::cout << "\n\nXACC IR:\n" << function->toString() << "\n"; // std::cout << "\n\nXACC IR:\n" << function->toString() << "\n"; // Check if we have IRGenerators in the tree if (function->hasIRGenerators()) { Loading
compiler/clang/QCORASTConsumer.cpp +19 −4 Original line number Diff line number Diff line #include "QCORASTConsumer.hpp" #include "LambdaVisitor.hpp" #include <chrono> // #include "clang/ASTMatchers/ASTMatchFinder.h" // #include "clang/ASTMatchers/ASTMatchers.h" // using namespace clang::ast_matchers; using namespace clang; Loading @@ -7,16 +13,25 @@ namespace qcor { namespace compiler { QCORASTConsumer::QCORASTConsumer(CompilerInstance &c, Rewriter &rw) : ci(c), fuzzyParser(std::make_shared<FuzzyParsingExternalSemaSource>( c.getASTContext())), rewriter(rw) {} c.getASTContext())), rewriter(rw) {} bool QCORASTConsumer::HandleTopLevelDecl(DeclGroupRef DR) { using namespace std::chrono; auto start = std::chrono::high_resolution_clock::now(); LambdaVisitor visitor(ci, rewriter); ci.getSema().addExternalSource(fuzzyParser.get()); for (DeclGroupRef::iterator b = DR.begin(), e = DR.end(); b != e; ++b) { // if (std::string((*b)->getDeclKindName()) == "Function") { // std::cout << (*b)->getDeclKindName() << "\n"; // (*b)->dumpColor(); visitor.TraverseDecl(*b); // } } auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<microseconds>(stop - start); // std::cout << "Visitor time: " << duration.count() << ", " << std::endl; return true; } } // namespace compiler Loading
compiler/clang/qcor-driver.in.cpp +7 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,8 @@ #include <fstream> #include <string> #include "FuzzyParsingExternalSemaSource.hpp" #include "QCORASTConsumer.hpp" #include "XACC.hpp" using namespace clang; Loading @@ -46,6 +48,9 @@ protected: CI.createSema(getTranslationUnitKind(), nullptr); rewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts()); qcor::compiler::FuzzyParsingExternalSemaSource source(CI.getASTContext()); CI.getSema().addExternalSource(&source); ParseAST(CI.getSema()); CI.getDiagnosticClient().EndSourceFile(); Loading Loading @@ -86,7 +91,6 @@ int main(int argc, char **argv) { xacc::error("File " + fileName + " does not exist."); } std::ifstream t(fileName); std::string src((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>()); Loading @@ -96,10 +100,8 @@ int main(int argc, char **argv) { auto action = new QCORFrontendAction(Rewrite, fileName); std::vector<std::string> args{ "-std=c++11", "-I@CMAKE_INSTALL_PREFIX@/include/qcor", "-I@CMAKE_INSTALL_PREFIX@/include/xacc", "-I@CMAKE_INSTALL_PREFIX@/include/cppmicroservices4", "-I@CMAKE_INSTALL_PREFIX@/include/quantum/gate"}; "-ftime-report", "-std=c++11", "-I@CMAKE_INSTALL_PREFIX@/include/qcor", "-I@CMAKE_INSTALL_PREFIX@/include/xacc"}; if (!tooling::runToolOnCodeWithArgs(action, src, args)) { xacc::error("Error running qcor compiler."); Loading