Loading README.md +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ To build this fork of LLVM/Clang (be aware this step takes up a good amount of R $ apt-get install ninja-build [if you dont have ninja] $ git clone https://github.com/hfinkel/llvm-project-csp llvm $ cd llvm && mkdir build && cd build $ cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=$HOME/.llvm -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS=clang $ cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=$HOME/.llvm -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_DUMP=ON -DLLVM_ENABLE_PROJECTS=clang $ cmake --build . --target install $ sudo ln -s $HOME/.llvm/bin/llvm-config /usr/bin ``` Loading tools/driver/qcor.in +7 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,13 @@ def main(argv=None): sys.argv.remove('-qrt') sHandlerArgs += ['-Xclang', '-plugin-arg-qcor-args', '-Xclang', '-qrt', '-DQCOR_USE_QRT'] if '-print-qir' in sys.argv[1:]: if not qrt: print('[qcor] Cannot request -print-qir with -qrt flag. Please also pass -qrt.') exit(1) sys.argv.remove('-print-qir') sHandlerArgs += ['-Xclang', '-load', '-Xclang', '@CMAKE_INSTALL_PREFIX@/qopt-plugins/libprint_llvm_qir.so'] # Get the filename we are compiling or the object file filename = '' fileType = '' Loading tools/qopt/passes/print_llvm_qir/CMakeLists.txt +12 −0 Original line number Diff line number Diff line Loading @@ -25,4 +25,16 @@ if(APPLE) ) endif(APPLE) if(APPLE) set_target_properties(print_llvm_qir PROPERTIES INSTALL_RPATH "@loader_path/../lib;${LLVM_INSTALL_PREFIX}/lib") set_target_properties(print_llvm_qir PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") else() set_target_properties(print_llvm_qir PROPERTIES INSTALL_RPATH "$ORIGIN/../lib:${LLVM_INSTALL_PREFIX}/lib") set_target_properties(print_llvm_qir PROPERTIES LINK_FLAGS "-shared") endif() install(TARGETS print_llvm_qir DESTINATION qopt-plugins) tools/qopt/passes/print_llvm_qir/print_llvm_qir.cpp +0 −56 Original line number Diff line number Diff line Loading @@ -20,62 +20,6 @@ struct PrintKernelQIR : public qcor::QCORBaseFunctionPass { // This pass just dumps all quantum kernel IR F.dump(); for (auto &arg : F.args()) { std::string type_str; llvm::raw_string_ostream rso(type_str); arg.getType()->print(rso); llvm::errs() << "ARG TYPE: " << rso.str() << ", " << arg.getName().str() << "\n"; arg.dump(); for (auto use : arg.users()) { use->dump(); } } // Leaving here for now, print callinsts example... for (BasicBlock &b : F) { // for (Function::iterator bb = F.begin(), e = F.end(); bb != e; ++bb) { // BasicBlock &b = *bb; if (b.getName().str().find("for.cond") != std::string::npos) { llvm::errs() << "BasicBlock Name: " << b.getName().str() << "\n"; // Loop over instructions for (Instruction &i : b) { llvm::errs() << "GET OPCODENAME: " << i.getOpcodeName() << "\n"; if (isa<llvm::InvokeInst>(i)) { llvm::errs() << "we have a invoke inst\n"; auto *cmp = dyn_cast<ICmpInst>(&i); cmp->dump(); llvm::errs() << "HELLO: " << cmp->getPredicate() << ", " << cmp->getNumOperands() << "\n"; Value *LHS = cmp->getOperand(0); Value *RHS = cmp->getOperand(1); if (isa<ConstantInt>(RHS)) { auto c = dyn_cast<ConstantInt>(RHS); auto val = c->getValue(); llvm::errs() << "This is an int type " << val << "\n"; } } else if (isa<LoadInst>(&i)) { llvm::errs() << "we have a load inst " << i.getNumOperands() << "\n"; auto op = i.getOperand(0); llvm::errs() << "loop var name name = " << op->getName().str() << "\n"; op->dump(); if (isa<AllocaInst>(op)) { // auto c = dyn_cast<ConstantInt>(RHS); // auto val = c->getValue(); auto const_int = dyn_cast<ConstantInt>( dyn_cast<AllocaInst>(op)->getOperand(0)); llvm::errs() << "This is an alloc type for load inst \n"; llvm::errs() << const_int->getValue() << "\n"; } } } } } return false; } }; Loading Loading
README.md +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ To build this fork of LLVM/Clang (be aware this step takes up a good amount of R $ apt-get install ninja-build [if you dont have ninja] $ git clone https://github.com/hfinkel/llvm-project-csp llvm $ cd llvm && mkdir build && cd build $ cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=$HOME/.llvm -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS=clang $ cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=$HOME/.llvm -DBUILD_SHARED_LIBS=TRUE -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_DUMP=ON -DLLVM_ENABLE_PROJECTS=clang $ cmake --build . --target install $ sudo ln -s $HOME/.llvm/bin/llvm-config /usr/bin ``` Loading
tools/driver/qcor.in +7 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,13 @@ def main(argv=None): sys.argv.remove('-qrt') sHandlerArgs += ['-Xclang', '-plugin-arg-qcor-args', '-Xclang', '-qrt', '-DQCOR_USE_QRT'] if '-print-qir' in sys.argv[1:]: if not qrt: print('[qcor] Cannot request -print-qir with -qrt flag. Please also pass -qrt.') exit(1) sys.argv.remove('-print-qir') sHandlerArgs += ['-Xclang', '-load', '-Xclang', '@CMAKE_INSTALL_PREFIX@/qopt-plugins/libprint_llvm_qir.so'] # Get the filename we are compiling or the object file filename = '' fileType = '' Loading
tools/qopt/passes/print_llvm_qir/CMakeLists.txt +12 −0 Original line number Diff line number Diff line Loading @@ -25,4 +25,16 @@ if(APPLE) ) endif(APPLE) if(APPLE) set_target_properties(print_llvm_qir PROPERTIES INSTALL_RPATH "@loader_path/../lib;${LLVM_INSTALL_PREFIX}/lib") set_target_properties(print_llvm_qir PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") else() set_target_properties(print_llvm_qir PROPERTIES INSTALL_RPATH "$ORIGIN/../lib:${LLVM_INSTALL_PREFIX}/lib") set_target_properties(print_llvm_qir PROPERTIES LINK_FLAGS "-shared") endif() install(TARGETS print_llvm_qir DESTINATION qopt-plugins)
tools/qopt/passes/print_llvm_qir/print_llvm_qir.cpp +0 −56 Original line number Diff line number Diff line Loading @@ -20,62 +20,6 @@ struct PrintKernelQIR : public qcor::QCORBaseFunctionPass { // This pass just dumps all quantum kernel IR F.dump(); for (auto &arg : F.args()) { std::string type_str; llvm::raw_string_ostream rso(type_str); arg.getType()->print(rso); llvm::errs() << "ARG TYPE: " << rso.str() << ", " << arg.getName().str() << "\n"; arg.dump(); for (auto use : arg.users()) { use->dump(); } } // Leaving here for now, print callinsts example... for (BasicBlock &b : F) { // for (Function::iterator bb = F.begin(), e = F.end(); bb != e; ++bb) { // BasicBlock &b = *bb; if (b.getName().str().find("for.cond") != std::string::npos) { llvm::errs() << "BasicBlock Name: " << b.getName().str() << "\n"; // Loop over instructions for (Instruction &i : b) { llvm::errs() << "GET OPCODENAME: " << i.getOpcodeName() << "\n"; if (isa<llvm::InvokeInst>(i)) { llvm::errs() << "we have a invoke inst\n"; auto *cmp = dyn_cast<ICmpInst>(&i); cmp->dump(); llvm::errs() << "HELLO: " << cmp->getPredicate() << ", " << cmp->getNumOperands() << "\n"; Value *LHS = cmp->getOperand(0); Value *RHS = cmp->getOperand(1); if (isa<ConstantInt>(RHS)) { auto c = dyn_cast<ConstantInt>(RHS); auto val = c->getValue(); llvm::errs() << "This is an int type " << val << "\n"; } } else if (isa<LoadInst>(&i)) { llvm::errs() << "we have a load inst " << i.getNumOperands() << "\n"; auto op = i.getOperand(0); llvm::errs() << "loop var name name = " << op->getName().str() << "\n"; op->dump(); if (isa<AllocaInst>(op)) { // auto c = dyn_cast<ConstantInt>(RHS); // auto val = c->getValue(); auto const_int = dyn_cast<ConstantInt>( dyn_cast<AllocaInst>(op)->getOperand(0)); llvm::errs() << "This is an alloc type for load inst \n"; llvm::errs() << const_int->getValue() << "\n"; } } } } } return false; } }; Loading