Skip to content
Snippets Groups Projects
Commit 5f734814 authored by kotsifa2's avatar kotsifa2
Browse files

Refactored BuildDFG pass (required for adding the VISC to LLVM pass).

parent 5a8d69fb
No related branches found
No related tags found
No related merge requests found
//== BuildDFG.h - Header file for "Hierarchical Dataflow Graph Builder Pass" =//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/ValueMap.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/DFGraph.h"
#include "llvm/Pass.h"
using namespace llvm;
namespace builddfg {
// BuildDFG - The first implementation.
struct BuildDFG : public ModulePass {
static char ID; // Pass identification, replacement for typeid
BuildDFG() : ModulePass(ID) {}
private:
// Member variables
DFInternalNode *Root;
typedef ValueMap<Value*, DFNode*> HandleToDFNode;
typedef ValueMap<Value*, DFEdge*> HandleToDFEdge;
HandleToDFNode HandleToDFNodeMap; // This map associates the i8* pointer
// with the DFNode structure that it
// represents
HandleToDFEdge HandleToDFEdgeMap; // This map associates the i8* pointer
// with the DFEdge structure that it
// represents
// Functions
bool isViscLaunchIntrinsic(Instruction * I);
bool isViscGraphIntrinsic(Instruction * I);
void handleCreateNode (DFInternalNode* N, IntrinsicInst* II);
void handleCreateEdge (DFInternalNode* N, IntrinsicInst* II);
void BuildGraph (DFInternalNode* N, Function* F);
public:
virtual bool runOnModule(Module &M);
};
} // End of namespace
......@@ -8,102 +8,69 @@
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "buildDFG"
#include "llvm/BuildDFG/BuildDFG.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/ValueMap.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/DFGraph.h"
#include "llvm/Pass.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
STATISTIC(IntrinsicCounter, "Counts number of visc intrinsics greeted");
namespace {
// BuildDFG - The first implementation.
struct BuildDFG : public ModulePass {
static char ID; // Pass identification, replacement for typeid
BuildDFG() : ModulePass(ID) {}
private:
// Member variables
DFInternalNode *Root;
typedef ValueMap<Value*, DFNode*> HandleToDFNode;
typedef ValueMap<Value*, DFEdge*> HandleToDFEdge;
HandleToDFNode HandleToDFNodeMap; // This map associates the i8* pointer
// with the DFNode structure that it
// represents
HandleToDFEdge HandleToDFEdgeMap; // This map associates the i8* pointer
// with the DFEdge structure that it
// represents
// Functions
bool isViscLaunchIntrinsic(Instruction * I);
bool isViscGraphIntrinsic(Instruction * I);
void handleCreateNode (DFInternalNode* N, IntrinsicInst* II);
void handleCreateEdge (DFInternalNode* N, IntrinsicInst* II);
void BuildGraph (DFInternalNode* N, Function* F);
public:
virtual bool runOnModule(Module &M) {
Function* f; // Root function, initialized later
bool foundRootFunction = false;
// Loop over all of the global variables
for (Module::const_global_iterator i = M.global_begin(),
e = M.global_end(); (i != e) && (!foundRootFunction); ++i) {
errs() << "Global: " << i->getName() << "\t" << *(i->getOperand(0))<< "\n";
// Find the root (main) function
// The name of the root function is llvm.visc.root (for now)
if((i->getName()).equals("llvm.visc.root")) {
errs() << "----------- Found Root Function -------------\n\n";
foundRootFunction = true;
f = cast<Function>(i->getOperand(0));
}
namespace builddfg {
bool BuildDFG::runOnModule(Module &M) {
Function* f; // Root function, initialized later
bool foundRootFunction = false;
// Loop over all of the global variables
for (Module::const_global_iterator i = M.global_begin(),
e = M.global_end(); (i != e) && (!foundRootFunction); ++i) {
errs() << "Global: " << i->getName() << "\t" << *(i->getOperand(0))<< "\n";
// Find the root (main) function
// The name of the root function is llvm.visc.root (for now)
if((i->getName()).equals("llvm.visc.root")) {
errs() << "----------- Found Root Function -------------\n\n";
foundRootFunction = true;
f = cast<Function>(i->getOperand(0));
}
}
assert(foundRootFunction && "Root function not found!");
assert(foundRootFunction && "Root function not found!");
// Root function has been initialized from this point on.
// Root function has been initialized from this point on.
errs() << "-------- Searching for launch site ----------\n";
errs() << "-------- Searching for launch site ----------\n";
bool foundLaunchSite = false;
IntrinsicInst* II;
bool foundLaunchSite = false;
IntrinsicInst* II;
for (inst_iterator i = inst_begin(f), e = inst_end(f);
(i != e) && (!foundLaunchSite); ++i) {
Instruction* I = &*i; // Grab pointer to Instruction
if (isViscLaunchIntrinsic(I)) {
errs() << "------------ Found launch site --------------\n";
foundLaunchSite = true;
II = cast<IntrinsicInst>(I);
}
for (inst_iterator i = inst_begin(f), e = inst_end(f);
(i != e) && (!foundLaunchSite); ++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(foundLaunchSite && "Launch site not found!");
// 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);
BuildGraph(Root, F);
viewDFGraph(Root->getChildGraph());
return false; //TODO: What does returning "false" mean?
}
viewDFGraph(Root->getChildGraph());
return false; //TODO: What does returning "false" mean?
}
};
// Returns true if instruction I is a visc launch intrinsic, false otherwise
bool BuildDFG::isViscLaunchIntrinsic(Instruction* I) {
......@@ -250,8 +217,9 @@ namespace {
}
}
}
} // End of namespace
char BuildDFG::ID = 0;
static RegisterPass<BuildDFG> X("buildDFG", "Hierarchical Dataflow Graph Builder Pass", false, false);
char BuildDFG::ID = 0;
static RegisterPass<BuildDFG> X("buildDFG", "Hierarchical Dataflow Graph Builder Pass", false, false);
} // End of namespace
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