Skip to content
Snippets Groups Projects
Commit a4458235 authored by Akash Kothari's avatar Akash Kothari
Browse files

LLVM-9-port ExtractHPVMLeafNodes pass

parent cba16207
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,8 @@ if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS Core Support)
endif()
add_llvm_loadable_module( ExtractHPVMLeafNodes
add_llvm_library( ExtractHPVMLeafNodes
MODULE
ExtractHPVMLeafNodes.cpp
DEPENDS
......
......@@ -12,10 +12,11 @@
#include "llvm/Support/SourceMgr.h"
#include "llvm/Pass.h"
#include "llvm/SupportVISC/DFGTreeTraversal.h"
#include "llvm/ExtractHPVMLeafNodes/ExtractHPVMLeafNodes.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "SupportHPVM/DFGTreeTraversal.h"
#include "ExtractHPVMLeafNodes/ExtractHPVMLeafNodes.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/IR/IRPrintingPasses.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Support/ToolOutputFile.h"
......@@ -53,10 +54,10 @@ void PrintLeafNodes::process(DFLeafNode* N) {
}
// Find function generated for node
Function *F = N->getGenFuncForTarget(visc::CPU_TARGET);
Function *F = N->getGenFuncForTarget(hpvm::CPU_TARGET);
assert(F != NULL
&& "This pass is invoked after code generation for x86 is completed.\nFound leaf node for which code generation has not happened!\n");
assert(N->hasX86GenFuncForTarget(visc::CPU_TARGET) &&
assert(N->hasCPUGenFuncForTarget(hpvm::CPU_TARGET) &&
"The generated function from x86 pass is not an x86 function\n");
std::string module_name = std::string("./build/") + std::string(F->getName().str().c_str()) + std::string("_module.ll");
......@@ -85,8 +86,8 @@ void PrintLeafNodes::process(DFLeafNode* N) {
StringRef CallName = CalledF->getName();
errs() << "CallName: " << CallName << "\n";
// if (CallName.startswith("llvm_visc")) { //TODO
if ((CallName.startswith("llvm_visc")) || (CallName.startswith("tensor"))) { //TODO
// if (CallName.startswith("llvm_hpvm")) { //TODO
if ((CallName.startswith("llvm_hpvm")) || (CallName.startswith("tensor"))) { //TODO
// errs() << "This is an HPVM runtime call. Include its declaration.\n";
errs() << "This is an HPVM runtime call or tensor. Include its declaration.\n";
......@@ -96,7 +97,7 @@ void PrintLeafNodes::process(DFLeafNode* N) {
for (unsigned argno = 0; argno < CI->getNumArgOperands(); argno++) {
Fargs.push_back(CI->getArgOperand(argno));
}
Function *FDecl = cast<Function>(m->getOrInsertFunction(CallName, CalledFType));
Function *FDecl = dyn_cast<Function>((m->getOrInsertFunction(CallName, CalledFType)).getCallee());
CallInst *NewCI = CallInst::Create(CalledFType, FDecl, Fargs, CallName, CI);
errs() << "NewCI: " << *NewCI << "\n";
CI->replaceAllUsesWith(NewCI);
......@@ -116,7 +117,7 @@ void PrintLeafNodes::process(DFLeafNode* N) {
errs() << "Writing to File --- " << tw.str() << "\n";
std::error_code EC;
tool_output_file Out(tw.str(), EC, sys::fs::F_None);
ToolOutputFile Out(tw.str(), EC, sys::fs::F_None);
if (EC) {
errs() << EC.message() << '\n';
}
......@@ -145,10 +146,10 @@ void PrintLeafNodes::process(DFLeafNode* N) {
// Get the parent node's generated x86 function
DFInternalNode *ParentNode = N->getParent();
Function *PGenF = ParentNode->getGenFuncForTarget(visc::CPU_TARGET);
Function *PGenF = ParentNode->getGenFuncForTarget(hpvm::CPU_TARGET);
assert(PGenF != NULL
&& "This pass is invoked after code generation for x86 is completed.\nFound node for which code generation has not happened!\n");
assert(ParentNode->hasX86GenFuncForTarget(visc::CPU_TARGET) &&
assert(ParentNode->hasCPUGenFuncForTarget(hpvm::CPU_TARGET) &&
"The generated function from x86 pass is not an x86 function\n");
for (inst_iterator i = inst_begin(PGenF), e = inst_end(PGenF); i != e; ++i) {
......@@ -169,7 +170,7 @@ void PrintLeafNodes::process(DFLeafNode* N) {
for (unsigned argno = 0; argno < CI->getNumArgOperands(); argno++) {
Fargs.push_back(CI->getArgOperand(argno));
}
Function *FDecl = cast<Function>(M.getOrInsertFunction(FName, FType));
Function *FDecl = dyn_cast<Function>(M.getOrInsertFunction(FName, FType).getCallee());
CallInst *NewCI = CallInst::Create(FType, FDecl, Fargs, FName, CI);
errs() << "NewCI: " << *NewCI << "\n";
CI->replaceAllUsesWith(NewCI);
......@@ -244,3 +245,4 @@ static RegisterPass<ExtractHPVMLeafNodeGenFunctionsWrapper> X(
"Pass to extract leaf nodes to modules in HPVM",
false /* does not modify the CFG */,
true /* transformation, not just analysis */);
;===- ./lib/Transforms/DFG2LLVM_NVPTX/LLVMBuild.txt ------------*- Conf -*--===;
;===- ./lib/Transforms/DFG2LLVM_WrapperAPI/LLVMBuild.txt -------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
......@@ -19,4 +19,3 @@
type = Library
name = ExtractHPVMLeafNodes
parent = Transforms
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment