From af287da423a6ed1d2c4580b33eea8a4f7f8fe17f Mon Sep 17 00:00:00 2001 From: Prakalp Srivastava <psrivas2@illinois.edu> Date: Tue, 27 Jan 2015 23:29:08 +0000 Subject: [PATCH] Multiple launch for unit test case working --- llvm/lib/Transforms/BuildDFG/BuildDFG.cpp | 58 ++++++++++--------- llvm/lib/Transforms/ClearDFG/ClearDFG.cpp | 7 ++- .../DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp | 18 +++--- .../Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp | 22 +++---- 4 files changed, 60 insertions(+), 45 deletions(-) diff --git a/llvm/lib/Transforms/BuildDFG/BuildDFG.cpp b/llvm/lib/Transforms/BuildDFG/BuildDFG.cpp index c236e5094d..827fb383e7 100644 --- a/llvm/lib/Transforms/BuildDFG/BuildDFG.cpp +++ b/llvm/lib/Transforms/BuildDFG/BuildDFG.cpp @@ -23,48 +23,50 @@ namespace builddfg { bool BuildDFG::runOnModule(Module &M) { - errs() << "-------- Searching for launch site ----------\n"; + errs() << "-------- Searching for launch sites ----------\n"; - bool foundLaunchSite = false; IntrinsicInst* II; // Iterate over all functions in the module - for (Module::iterator mi = M.begin(), - me = M.end(); (mi != me) && (!foundLaunchSite); ++mi) { + for (Module::iterator mi = M.begin(), me = M.end(); mi != me; ++mi) { Function* f = &*mi; errs() << "Function: " << f->getName() << "\n"; - for (inst_iterator i = inst_begin(f), e = inst_end(f); - (i != e) && (!foundLaunchSite); ++i) { + for (inst_iterator i = inst_begin(f), e = inst_end(f); i != e ; ++i) { Instruction* I = &*i; // Grab pointer to Instruction if (isViscLaunchIntrinsic(I)) { errs() << "------------ Found launch site --------------\n"; - foundLaunchSite = true; II = cast<IntrinsicInst>(I); - } - } - } - assert(foundLaunchSite && "Launch site not found!"); + assert(II && "Launch intrinsic not recognized."); - // Intrinsic Instruction has been initialized from this point on. + // Intrinsic Instruction has been initialized from this point on. - Function* F = cast<Function>((II->getOperand(0))->stripPointerCasts()); - Root = DFInternalNode::Create(II, F); - BuildGraph(Root, F); + Function* F = cast<Function>((II->getOperand(0))->stripPointerCasts()); + Root = DFInternalNode::Create(II, F); + Roots.push_back(Root); + BuildGraph(Root, F); - for(DFGraph::children_iterator i = Root->getChildGraph()->begin(), - e = Root->getChildGraph()->end(); i!=e; i++) { - DFNode* N = *i; - errs() << "\t" << N->getFuncPointer()->getName() << "\n"; - } - Root->getChildGraph()->sortChildren(); - for(DFGraph::children_iterator i = Root->getChildGraph()->begin(), - e = Root->getChildGraph()->end(); i!=e; i++) { - DFNode* N = *i; - errs() << "\t" << N->getFuncPointer()->getName() << "\n"; + for(DFGraph::children_iterator i = Root->getChildGraph()->begin(), + e = Root->getChildGraph()->end(); i!=e; i++) { + DFNode* N = *i; + errs() << "\t" << N->getFuncPointer()->getName() << "\n"; + } + Root->getChildGraph()->sortChildren(); + for(DFGraph::children_iterator i = Root->getChildGraph()->begin(), + e = Root->getChildGraph()->end(); i!=e; i++) { + DFNode* N = *i; + errs() << "\t" << N->getFuncPointer()->getName() << "\n"; + } + viewDFGraph(Root->getChildGraph()); + + } + } } - viewDFGraph(Root->getChildGraph()); + + // Checking that we found at least one launch site + assert((Roots.size() != 0) && "Launch site not found."); + return false; //TODO: What does returning "false" mean? } @@ -72,6 +74,10 @@ DFInternalNode *BuildDFG::getRoot() const { return Root; } +std::vector<DFInternalNode*> &BuildDFG::getRoots() { + return Roots; +} + //TODO: Maybe make this const BuildDFG::HandleToDFNode &BuildDFG::getHandleToDFNodeMap() { return HandleToDFNodeMap; diff --git a/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp b/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp index 4b392b2c96..6a410d31ae 100644 --- a/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp +++ b/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp @@ -92,7 +92,8 @@ bool ClearDFG::runOnModule(Module &M) { // - Maps from i8* hansles to DFNode and DFEdge BuildDFG &DFG = getAnalysis<BuildDFG>(); - DFInternalNode *Root = DFG.getRoot(); + // DFInternalNode *Root = DFG.getRoot(); + std::vector<DFInternalNode*> Roots = DFG.getRoots(); // BuildDFG::HandleToDFNode &HandleToDFNodeMap = DFG.getHandleToDFNodeMap(); // BuildDFG::HandleToDFEdge &HandleToDFEdgeMap = DFG.getHandleToDFEdgeMap(); @@ -100,7 +101,9 @@ bool ClearDFG::runOnModule(Module &M) { TreeTraversal *Visitor = new TreeTraversal(M, DFG); // Initiate code generation for root DFNode - Visitor->visit(Root); + for (auto rootNode: Roots) { + Visitor->visit(rootNode); + } delete Visitor; return true; } diff --git a/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp index e8c027686a..708711e1d9 100644 --- a/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp +++ b/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp @@ -98,7 +98,6 @@ public: localWGSize = V; } - bool hasLocalWG() { return blockDim != 0; } @@ -1110,15 +1109,20 @@ bool DFG2LLVM_NVPTX::runOnModule(Module &M) { // - Maps from i8* hansles to DFNode and DFEdge BuildDFG &DFG = getAnalysis<BuildDFG>(); - DFInternalNode *Root = DFG.getRoot(); -// BuildDFG::HandleToDFNode &HandleToDFNodeMap = DFG.getHandleToDFNodeMap(); -// BuildDFG::HandleToDFEdge &HandleToDFEdgeMap = DFG.getHandleToDFEdgeMap(); + // DFInternalNode *Root = DFG.getRoot(); + std::vector<DFInternalNode*> Roots = DFG.getRoots(); + // BuildDFG::HandleToDFNode &HandleToDFNodeMap = DFG.getHandleToDFNodeMap(); + // BuildDFG::HandleToDFEdge &HandleToDFEdgeMap = DFG.getHandleToDFEdgeMap(); // Visitor for Code Generation Graph Traversal CodeGenTraversal *CGTVisitor = new CodeGenTraversal(M, DFG); - // Initiate code generation for root DFNode - CGTVisitor->visit(Root); + // Iterate over all the DFGs and produce code for each one of them + for (auto rootNode: Roots) { + // Initiate code generation for root DFNode + CGTVisitor->visit(rootNode); + } + //TODO: Edit module epilogue to remove the VISC intrinsic declarations delete CGTVisitor; @@ -1246,7 +1250,7 @@ void CodeGenTraversal::addCLMetadata(Function *F) { NamedMDNode *MDN_annotations = KernelM.getOrInsertNamedMetadata("nvvm.annotations"); MDN_annotations->addOperand(MDNvvmAnnotationsNode); -//!1 = metadata !{void (float addrspace(1)*, float addrspace(1)*, float addrspace(1)*, i32, i32)* @matrixMul, metadata !"kernel", i32 1} + //!1 = metadata !{void (float addrspace(1)*, float addrspace(1)*, float addrspace(1)*, i32, i32)* @matrixMul, metadata !"kernel", i32 1} } void CodeGenTraversal::writeKernelsModule() { diff --git a/llvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp b/llvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp index 818be97f6f..594e76384b 100644 --- a/llvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp +++ b/llvm/lib/Transforms/DFG2LLVM_X86/DFG2LLVM_X86.cpp @@ -126,22 +126,24 @@ bool DFG2LLVM_X86::runOnModule(Module &M) { // - Maps from i8* hansles to DFNode and DFEdge BuildDFG &DFG = getAnalysis<BuildDFG>(); - DFInternalNode *Root = DFG.getRoot(); + //DFInternalNode *Root = DFG.getRoot(); + std::vector<DFInternalNode*> Roots = DFG.getRoots(); // BuildDFG::HandleToDFNode &HandleToDFNodeMap = DFG.getHandleToDFNodeMap(); // BuildDFG::HandleToDFEdge &HandleToDFEdgeMap = DFG.getHandleToDFEdgeMap(); // Visitor for Code Generation Graph Traversal CodeGenTraversal *CGTVisitor = new CodeGenTraversal(M, DFG); - // Initiate code generation for root DFNode - CGTVisitor->visit(Root); - - - // Go ahead and replace the launch intrinsic with pthread call, otherwise return now. - // TODO: Later on, we might like to do this in a separate pass, which would - // allow us the flexibility to switch between complete static code generation - // for DFG or having a customized runtime+scheduler - CGTVisitor->codeGenLaunch(Root); + // Iterate over all the DFGs and produce code for each one of them + for (auto rootNode: Roots) { + // Initiate code generation for root DFNode + CGTVisitor->visit(rootNode); + // Go ahead and replace the launch intrinsic with pthread call, otherwise return now. + // TODO: Later on, we might like to do this in a separate pass, which would + // allow us the flexibility to switch between complete static code generation + // for DFG or having a customized runtime+scheduler + CGTVisitor->codeGenLaunch(rootNode); + } delete CGTVisitor; return true; -- GitLab