Commit 4f8007cf authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Merge branch 'hpvm-release-internal' into hpvm-release

parents 86f9a54a 8a4c1734
;===- ./lib/Transforms/DFG2LLVM_NVPTX/LLVMBuild.txt ------------*- Conf -*--===;
;===- ./lib/Transforms/DFG2LLVM_OpenCL/LLVMBuild.txt ------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
......@@ -17,5 +17,5 @@
[component_0]
type = Library
name = DFG2LLVM_NVPTX
name = DFG2LLVM_OpenCL
parent = Transforms
......@@ -6,6 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This pass takes LLVM IR with HPVM-C functions to generate textual representa-
// -tion for HPVM IR consisting of HPVM intrinsics. Memory-to-register
// optimization pass is expected to execute prior to execution of this pass.
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "genhpvm"
#include "GenHPVM/GenHPVM.h"
......
......@@ -6,6 +6,12 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This pass traverses the dataflow graph to recognize the allocation nodes
// which allocate scratch memory. This pass does not make changes to the textual
// representation of HPVM IR.
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "LocalMem"
#include "SupportHPVM/DFG2LLVM.h"
......
......@@ -39,7 +39,7 @@ typedef struct {
std::vector<CircularBuffer<uint64_t> *> *BindOutputBuffers;
std::vector<CircularBuffer<uint64_t> *> *EdgeBuffers;
std::vector<CircularBuffer<uint64_t> *> *isLastInputBuffers;
} DFNodeContext_X86;
} DFNodeContext_CPU;
typedef struct {
cl_context clOCLContext;
......@@ -212,7 +212,7 @@ static inline void checkErr(cl_int err, cl_int success, const char *name) {
/************************* Depth Stack Routines ***************************/
void llvm_hpvm_x86_dstack_push(unsigned n, uint64_t limitX, uint64_t iX,
void llvm_hpvm_cpu_dstack_push(unsigned n, uint64_t limitX, uint64_t iX,
uint64_t limitY, uint64_t iY, uint64_t limitZ,
uint64_t iZ) {
DEBUG(cout << "Pushing node information on stack:\n");
......@@ -226,7 +226,7 @@ void llvm_hpvm_x86_dstack_push(unsigned n, uint64_t limitX, uint64_t iX,
pthread_mutex_unlock(&ocl_mtx);
}
void llvm_hpvm_x86_dstack_pop() {
void llvm_hpvm_cpu_dstack_pop() {
DEBUG(cout << "Popping from depth stack\n");
pthread_mutex_lock(&ocl_mtx);
DStack.pop_back();
......@@ -234,7 +234,7 @@ void llvm_hpvm_x86_dstack_pop() {
pthread_mutex_unlock(&ocl_mtx);
}
uint64_t llvm_hpvm_x86_getDimLimit(unsigned level, unsigned dim) {
uint64_t llvm_hpvm_cpu_getDimLimit(unsigned level, unsigned dim) {
DEBUG(cout << "Request limit for dim " << dim << " of ancestor " << level
<< flush << "\n");
pthread_mutex_lock(&ocl_mtx);
......@@ -246,7 +246,7 @@ uint64_t llvm_hpvm_x86_getDimLimit(unsigned level, unsigned dim) {
return result;
}
uint64_t llvm_hpvm_x86_getDimInstance(unsigned level, unsigned dim) {
uint64_t llvm_hpvm_cpu_getDimInstance(unsigned level, unsigned dim) {
DEBUG(cout << "Request instance id for dim " << dim << " of ancestor "
<< level << flush << "\n");
pthread_mutex_lock(&ocl_mtx);
......@@ -350,13 +350,13 @@ static void *llvm_hpvm_ocl_request_mem(void *ptr, size_t size,
return d_input;
}
void *llvm_hpvm_x86_argument_ptr(void *ptr, size_t size) {
void *llvm_hpvm_cpu_argument_ptr(void *ptr, size_t size) {
return llvm_hpvm_request_mem(ptr, size);
}
void *llvm_hpvm_request_mem(void *ptr, size_t size) {
pthread_mutex_lock(&ocl_mtx);
DEBUG(cout << "[X86] Request memory: " << ptr << flush << "\n");
DEBUG(cout << "[CPU] Request memory: " << ptr << flush << "\n");
MemTrackerEntry *MTE = MTracker.lookup(ptr);
if (MTE == NULL) {
cout << "ERROR: Requesting memory not present in Table\n";
......@@ -1152,8 +1152,8 @@ void hpvm_DestroyTimerSet(struct hpvm_TimerSet *timers) {
// Launch API for a streaming dataflow graph
void *llvm_hpvm_streamLaunch(void (*LaunchFunc)(void *, void *), void *args) {
DFNodeContext_X86 *Context =
(DFNodeContext_X86 *)malloc(sizeof(DFNodeContext_X86));
DFNodeContext_CPU *Context =
(DFNodeContext_CPU *)malloc(sizeof(DFNodeContext_CPU));
Context->threads = new std::vector<pthread_t>();
Context->ArgInPortSizeMap = new std::map<unsigned, uint64_t>();
......@@ -1176,7 +1176,7 @@ void *llvm_hpvm_streamLaunch(void (*LaunchFunc)(void *, void *), void *args) {
void llvm_hpvm_streamPush(void *graphID, void *args) {
DEBUG(cout << "StreamPush -- Graph: " << graphID << ", Arguments: " << args
<< flush << "\n");
DFNodeContext_X86 *Ctx = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Ctx = (DFNodeContext_CPU *)graphID;
unsigned offset = 0;
for (unsigned i = 0; i < Ctx->ArgInPortSizeMap->size(); i++) {
uint64_t element;
......@@ -1198,7 +1198,7 @@ void llvm_hpvm_streamPush(void *graphID, void *args) {
// Pop API for a streaming dataflow graph
void *llvm_hpvm_streamPop(void *graphID) {
DEBUG(cout << "StreamPop -- Graph: " << graphID << flush << "\n");
DFNodeContext_X86 *Ctx = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Ctx = (DFNodeContext_CPU *)graphID;
unsigned totalBytes = 0;
for (uint64_t size : *(Ctx->BindOutSizes))
totalBytes += size;
......@@ -1216,7 +1216,7 @@ void *llvm_hpvm_streamPop(void *graphID) {
// Wait API for a streaming dataflow graph
void llvm_hpvm_streamWait(void *graphID) {
DEBUG(cout << "StreamWait -- Graph: " << graphID << flush << "\n");
DFNodeContext_X86 *Ctx = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Ctx = (DFNodeContext_CPU *)graphID;
// Push garbage to all other input buffers
for (unsigned i = 0; i < Ctx->BindInputBuffers->size(); i++) {
uint64_t element = 0;
......@@ -1235,7 +1235,7 @@ void *llvm_hpvm_createBindInBuffer(void *graphID, uint64_t size,
unsigned inArgPort) {
DEBUG(cout << "Create BindInBuffer -- Graph: " << graphID
<< ", Size: " << size << flush << "\n");
DFNodeContext_X86 *Context = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Context = (DFNodeContext_CPU *)graphID;
CircularBuffer<uint64_t> *bufferID =
new CircularBuffer<uint64_t>(BUFFER_SIZE, "BindIn");
DEBUG(cout << "\tNew Buffer: " << bufferID << flush << "\n");
......@@ -1249,7 +1249,7 @@ void *llvm_hpvm_createBindInBuffer(void *graphID, uint64_t size,
void *llvm_hpvm_createBindOutBuffer(void *graphID, uint64_t size) {
DEBUG(cout << "Create BindOutBuffer -- Graph: " << graphID
<< ", Size: " << size << flush << "\n");
DFNodeContext_X86 *Context = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Context = (DFNodeContext_CPU *)graphID;
// Twine name = Twine("Bind.Out.")+Twine(Context->BindOutputBuffers->size());
CircularBuffer<uint64_t> *bufferID =
new CircularBuffer<uint64_t>(BUFFER_SIZE, "BindOut");
......@@ -1261,7 +1261,7 @@ void *llvm_hpvm_createBindOutBuffer(void *graphID, uint64_t size) {
void *llvm_hpvm_createEdgeBuffer(void *graphID, uint64_t size) {
DEBUG(cout << "Create EdgeBuffer -- Graph: " << graphID << ", Size: " << size
<< flush << "\n");
DFNodeContext_X86 *Context = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Context = (DFNodeContext_CPU *)graphID;
// Twine name = Twine("Edge.")+Twine(Context->EdgeBuffers->size());
CircularBuffer<uint64_t> *bufferID =
new CircularBuffer<uint64_t>(BUFFER_SIZE, "Edge");
......@@ -1274,7 +1274,7 @@ void *llvm_hpvm_createEdgeBuffer(void *graphID, uint64_t size) {
void *llvm_hpvm_createLastInputBuffer(void *graphID, uint64_t size) {
DEBUG(cout << "Create isLastInputBuffer -- Graph: " << graphID
<< ", Size: " << size << flush << "\n");
DFNodeContext_X86 *Context = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Context = (DFNodeContext_CPU *)graphID;
// Twine name = Twine("isLastInput.")+Twine(Context->EdgeBuffers->size());
CircularBuffer<uint64_t> *bufferID =
new CircularBuffer<uint64_t>(BUFFER_SIZE, "LastInput");
......@@ -1286,7 +1286,7 @@ void *llvm_hpvm_createLastInputBuffer(void *graphID, uint64_t size) {
// Free buffers
void llvm_hpvm_freeBuffers(void *graphID) {
DEBUG(cout << "Free all buffers -- Graph: " << graphID << flush << "\n");
DFNodeContext_X86 *Context = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Context = (DFNodeContext_CPU *)graphID;
for (CircularBuffer<uint64_t> *bufferID : *(Context->BindInputBuffers))
delete bufferID;
for (CircularBuffer<uint64_t> *bufferID : *(Context->BindOutputBuffers))
......@@ -1314,7 +1314,7 @@ void llvm_hpvm_createThread(void *graphID, void *(*Func)(void *),
void *arguments) {
DEBUG(cout << "Create Thread -- Graph: " << graphID << ", Func: " << Func
<< ", Args: " << arguments << flush << "\n");
DFNodeContext_X86 *Ctx = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Ctx = (DFNodeContext_CPU *)graphID;
int err;
pthread_t threadID;
if ((err = pthread_create(&threadID, NULL, Func, arguments)) != 0)
......@@ -1326,16 +1326,16 @@ void llvm_hpvm_createThread(void *graphID, void *(*Func)(void *),
// Wait for thread to finish
void llvm_hpvm_freeThreads(void *graphID) {
DEBUG(cout << "Free Threads -- Graph: " << graphID << flush << "\n");
DFNodeContext_X86 *Ctx = (DFNodeContext_X86 *)graphID;
DFNodeContext_CPU *Ctx = (DFNodeContext_CPU *)graphID;
for (pthread_t thread : *(Ctx->threads))
pthread_join(thread, NULL);
}
/************************ OPENCL & PTHREAD API ********************************/
void *llvm_hpvm_x86_launch(void *(*rootFunc)(void *), void *arguments) {
DFNodeContext_X86 *Context =
(DFNodeContext_X86 *)malloc(sizeof(DFNodeContext_X86));
void *llvm_hpvm_cpu_launch(void *(*rootFunc)(void *), void *arguments) {
DFNodeContext_CPU *Context =
(DFNodeContext_CPU *)malloc(sizeof(DFNodeContext_CPU));
// int err;
// if((err = pthread_create(&Context->threadID, NULL, rootFunc, arguments)) !=
// 0) cout << "Failed to create pthread. Error code = " << err << flush <<
......@@ -1344,9 +1344,9 @@ void *llvm_hpvm_x86_launch(void *(*rootFunc)(void *), void *arguments) {
return Context;
}
void llvm_hpvm_x86_wait(void *graphID) {
void llvm_hpvm_cpu_wait(void *graphID) {
DEBUG(cout << "Waiting for pthread to finish ...\n");
// DFNodeContext_X86* Context = (DFNodeContext_X86*) graphID;
// DFNodeContext_CPU* Context = (DFNodeContext_CPU*) graphID;
// pthread_join(Context->threadID, NULL);
free(graphID);
DEBUG(cout << "\t... pthread Done!\n");
......@@ -1451,8 +1451,7 @@ void *llvm_hpvm_ocl_initContext(enum hpvm::Target T) {
DEBUG(cout << "\tNAME = " << buffer << flush << "\n");
clGetPlatformInfo(platformId, CL_PLATFORM_VENDOR, 10240, buffer, NULL);
DEBUG(cout << "\tVENDOR = " << buffer << flush << "\n");
clGetPlatformInfo(platformId, CL_PLATFORM_EXTENSIONS, 10240, buffer,
NULL);
clGetPlatformInfo(platformId, CL_PLATFORM_EXTENSIONS, 10240, buffer, NULL);
DEBUG(cout << "\tEXTENSIONS = " << buffer << flush << "\n");
} else {
platformId = findPlatform("intel");
......@@ -1466,8 +1465,7 @@ void *llvm_hpvm_ocl_initContext(enum hpvm::Target T) {
DEBUG(cout << "\tNAME = " << buffer << flush << "\n");
clGetPlatformInfo(platformId, CL_PLATFORM_VENDOR, 10240, buffer, NULL);
DEBUG(cout << "\tVENDOR = " << buffer << flush << "\n");
clGetPlatformInfo(platformId, CL_PLATFORM_EXTENSIONS, 10240, buffer,
NULL);
clGetPlatformInfo(platformId, CL_PLATFORM_EXTENSIONS, 10240, buffer, NULL);
DEBUG(cout << "\tEXTENSIONS = " << buffer << flush << "\n");
}
DEBUG(cout << "Found plarform with id: " << platformId << "\n");
......@@ -1483,7 +1481,7 @@ void *llvm_hpvm_ocl_initContext(enum hpvm::Target T) {
errcode = clGetContextInfo(globalOCLContext, CL_CONTEXT_DEVICES, 0, NULL,
&dataBytes);
checkErr(errcode, CL_SUCCESS, "Failure to get context info length");
DEBUG(cout << "Got databytes: " << dataBytes << "\n");
clDevices = (cl_device_id *)malloc(dataBytes);
......
......@@ -64,12 +64,12 @@ public:
unsigned getNumDim() const { return numDim; }
};
void llvm_hpvm_x86_dstack_push(unsigned n, uint64_t limitX = 0, uint64_t iX = 0,
void llvm_hpvm_cpu_dstack_push(unsigned n, uint64_t limitX = 0, uint64_t iX = 0,
uint64_t limitY = 0, uint64_t iY = 0,
uint64_t limitZ = 0, uint64_t iZ = 0);
void llvm_hpvm_x86_dstack_pop();
uint64_t llvm_hpvm_x86_getDimLimit(unsigned level, unsigned dim);
uint64_t llvm_hpvm_x86_getDimInstance(unsigned level, unsigned dim);
void llvm_hpvm_cpu_dstack_pop();
uint64_t llvm_hpvm_cpu_getDimLimit(unsigned level, unsigned dim);
uint64_t llvm_hpvm_cpu_getDimInstance(unsigned level, unsigned dim);
/********************* Memory Tracker **********************************/
class MemTrackerEntry {
......@@ -148,11 +148,11 @@ void llvm_hpvm_untrack_mem(void *);
void *llvm_hpvm_request_mem(void *, size_t);
/*********************** OPENCL & PTHREAD API **************************/
void *llvm_hpvm_x86_launch(void *(void *), void *);
void llvm_hpvm_x86_wait(void *);
void *llvm_hpvm_cpu_launch(void *(void *), void *);
void llvm_hpvm_cpu_wait(void *);
void *llvm_hpvm_ocl_initContext(enum hpvm::Target);
void *llvm_hpvm_x86_argument_ptr(void *, size_t);
void *llvm_hpvm_cpu_argument_ptr(void *, size_t);
void llvm_hpvm_ocl_clearContext(void *);
void llvm_hpvm_ocl_argument_shared(void *, int, size_t);
......
......@@ -29,15 +29,8 @@
#include <iostream>
//#include "PHINodePass.h"
#define DEBUG_TYPE "cbe"
// Jackson Korba 9/29/14
#ifndef DEBUG_TYPE
#define DEBUG_TYPE ""
#endif
// End Modification
#define DEBUG(x) x
// Some ms header decided to define setjmp as _setjmp, undo this for this file
// since we don't need it
#ifdef setjmp
......@@ -149,7 +142,7 @@ bool CWriter::isInlineAsm(Instruction &I) const {
bool CWriter::runOnFunction(Function &F) {
// Do not codegen any 'available_externally' functions at all, they have
// definitions outside the translation unit.
errs() << "Running CBE on function: " << F.getName() << "\n";
DEBUG(errs() << "Running CBE on function: " << F.getName() << "\n");
if (F.hasAvailableExternallyLinkage())
return false;
......@@ -262,9 +255,7 @@ raw_ostream &CWriter::printTypeString(raw_ostream &Out, Type *Ty,
}
default:
#ifndef NDEBUG
errs() << "Unknown primitive type: " << *Ty << "\n";
#endif
DEBUG(errs() << "Unknown primitive type: " << *Ty << "\n");
llvm_unreachable(0);
}
}
......@@ -367,9 +358,7 @@ static const std::string getCmpPredicateName(CmpInst::Predicate P) {
case ICmpInst::ICMP_SGT:
return "sgt";
default:
#ifndef NDEBUG
errs() << "Invalid icmp predicate!" << P;
#endif
DEBUG(errs() << "Invalid icmp predicate!" << P);
llvm_unreachable(0);
}
}
......@@ -414,9 +403,7 @@ raw_ostream &CWriter::printSimpleType(raw_ostream &Out, Type *Ty,
<< " __attribute__((vector_size(8)))";
default:
#ifndef NDEBUG
errs() << "Unknown primitive type: " << *Ty << "\n";
#endif
DEBUG(errs() << "Unknown primitive type: " << *Ty << "\n");
llvm_unreachable(0);
}
}
......@@ -462,9 +449,7 @@ CWriter::printTypeName(raw_ostream &Out, Type *Ty, bool isSigned,
}
default:
#ifndef NDEBUG
errs() << "Unexpected type: " << *Ty << "\n";
#endif
DEBUG(errs() << "Unexpected type: " << *Ty << "\n");
llvm_unreachable(0);
}
}
......@@ -1067,9 +1052,8 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
return;
}
default:
#ifndef NDEBUG
errs() << "CWriter Error: Unhandled constant expression: " << *CE << "\n";
#endif
DEBUG(errs() << "CWriter Error: Unhandled constant expression: " << *CE
<< "\n");
llvm_unreachable(0);
}
} else if (isa<UndefValue>(CPV) && CPV->getType()->isSingleValueType()) {
......@@ -1344,9 +1328,7 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
}
// FALL THROUGH
default:
#ifndef NDEBUG
errs() << "Unknown constant type: " << *CPV << "\n";
#endif
DEBUG(errs() << "Unknown constant type: " << *CPV << "\n");
llvm_unreachable(0);
}
}
......@@ -2447,9 +2429,7 @@ void CWriter::generateHeader(Module &M) {
Out << " > ";
break;
default:
#ifndef NDEBUG
errs() << "Invalid icmp predicate!" << (*it).first;
#endif
DEBUG(errs() << "Invalid icmp predicate!" << (*it).first);
llvm_unreachable(0);
}
Out << "r.vector[" << n << "];\n";
......@@ -2688,9 +2668,7 @@ void CWriter::generateHeader(Module &M) {
Out << " >> ";
break;
default:
#ifndef NDEBUG
errs() << "Invalid operator type!" << opcode;
#endif
DEBUG(errs() << "Invalid operator type!" << opcode);
llvm_unreachable(0);
}
Out << "b.vector[" << n << "]";
......@@ -2746,9 +2724,7 @@ void CWriter::generateHeader(Module &M) {
Out << " >> ";
break;
default:
#ifndef NDEBUG
errs() << "Invalid operator type!" << opcode;
#endif
DEBUG(errs() << "Invalid operator type!" << opcode);
llvm_unreachable(0);
}
Out << "b;\n";
......@@ -2821,9 +2797,7 @@ void CWriter::generateHeader(Module &M) {
Out << "AShr";
break;
default:
#ifndef NDEBUG
errs() << "Invalid operator type!" << opcode;
#endif
DEBUG(errs() << "Invalid operator type!" << opcode);
llvm_unreachable(0);
}
Out << "(16, &a, &b, &r);\n";
......@@ -2888,9 +2862,7 @@ void CWriter::generateHeader(Module &M) {
Out << " >> ";
break;
default:
#ifndef NDEBUG
errs() << "Invalid operator type!" << opcode;
#endif
DEBUG(errs() << "Invalid operator type!" << opcode);
llvm_unreachable(0);
}
Out << "b";
......@@ -3569,7 +3541,7 @@ void CWriter::printLoop(Loop *L) {
Loop::LoopBounds::Direction::Increasing)
? "increasing"
: "decreasing")
<< "\n";)
<< "\n");
std::string startStr;
if (ConstantInt *startConst = dyn_cast<ConstantInt>(StartValue)) {
......@@ -3592,7 +3564,7 @@ void CWriter::printLoop(Loop *L) {
DEBUG(errs() << "\n for ( " << IVName << " = " << startStr << "; "
<< IVName << BranchPredicate << finalStr << "; " << IVName
<< " = " << IVName << " + " << stepStr << ") {\n";)
<< " = " << IVName << " + " << stepStr << ") {\n");
Out << "\n for ( " << IVName << " = " << startStr << "; " << IVName
<< BranchPredicate << finalStr << "; " << IVName << " = " << IVName
......@@ -4039,7 +4011,7 @@ bool CWriter::findMatch(BasicBlock *CurrBlock, BasicBlock *CompBlock,
// that immediately succeeds the current one.
//
void CWriter::visitBranchInst(BranchInst &I) {
errs() << "Visiting Branch Instruction: " << I << "\n";
DEBUG(errs() << "Visiting Branch Instruction: " << I << "\n");
Out << "\n/* Branch: " << I << " */\n";
if (I.isConditional()) {
......@@ -4055,12 +4027,13 @@ void CWriter::visitBranchInst(BranchInst &I) {
}
if (Loop *L = LI->getLoopFor(I.getParent())) {
if (L == LI->getLoopFor(BB0) && !(L == LI->getLoopFor(BB1))) {
errs() << "This is a loop branch!\n";
DEBUG(errs() << "This is a loop branch!\n");
Out << "/* This is a loop branch! */\n";
// BB0 is in the loop. Print it if it hsn't been printed
if (VisitedBlocks.find(BB0) != VisitedBlocks.end()) {
errs() << "Branching back to header: " << BB0->getName() << "\n";
errs() << "This is the end of the loop, closing!\n";
DEBUG(errs() << "Branching back to header: " << BB0->getName()
<< "\n");
DEBUG(errs() << "This is the end of the loop, closing!\n");
Out << "/* Branching back to header: " << BB0->getName() << " */\n";
Out << "/* Closing loop! */\n";
// BB0 is the loop header. CLose the loop then print BB1.
......@@ -4069,18 +4042,19 @@ void CWriter::visitBranchInst(BranchInst &I) {
printPHICopiesForSuccessor(I.getParent(), BB1, 2);
printBBorLoop(BB1);
} else {
errs() << "Not branching to header! Branching to: " << BB0->getName()
<< "\n";
DEBUG(errs() << "Not branching to header! Branching to: "
<< BB0->getName() << "\n");
// BB0 is not the loop header. That means we are entering loop body
llvm_unreachable("loop branch unhandled!\n");
}
} else if (L == LI->getLoopFor(BB1) && !(L == LI->getLoopFor(BB0))) {
errs() << "This is a loop branch!\n";
DEBUG(errs() << "This is a loop branch!\n");
Out << "/* This is a loop branch! */\n";
if (VisitedBlocks.find(BB1) != VisitedBlocks.end()) {
errs() << "Branching back to header: " << BB1->getName() << "\n";
errs() << "This is the end of the loop, closing!\n";
DEBUG(errs() << "Branching back to header: " << BB1->getName()
<< "\n");
DEBUG(errs() << "This is the end of the loop, closing!\n");
Out << "/* Branching back to header: " << BB1->getName() << " */\n";
Out << "/* Closing loop! */\n";
// BB0 is the loop header. CLose the loop then print BB1.
......@@ -4089,22 +4063,23 @@ void CWriter::visitBranchInst(BranchInst &I) {
printPHICopiesForSuccessor(I.getParent(), BB0, 2);
printBBorLoop(BB0);
} else {
errs() << "Not branching to header! Branching to: " << BB1->getName()
<< "\n";
DEBUG(errs() << "Not branching to header! Branching to: "
<< BB1->getName() << "\n");
// BB1 is not the loop header. That means we are entering loop body
llvm_unreachable("loop branch unhandled!\n");
}
} else {
errs() << "This is a conditional statement within a loop!\n";
DEBUG(errs() << "This is a conditional statement within a loop!\n");
Out << "/* This is a conditional statement within a loop! */\n";
errs() << ImmPostDomm->getName()
<< " is the immediate post dominator of " << BB0->getName()
<< " and " << BB1->getName() << "\n";
DEBUG(errs() << ImmPostDomm->getName()
<< " is the immediate post dominator of " << BB0->getName()
<< " and " << BB1->getName() << "\n");
if (VisitedBlocks.find(ImmPostDomm) != VisitedBlocks.end()) {
errs() << "Not pushing " << ImmPostDomm->getName()
<< " because it has already been visited!\n";
DEBUG(errs() << "Not pushing " << ImmPostDomm->getName()
<< " because it has already been visited!\n");
} else {
errs() << "Pushing " << ImmPostDomm->getName() << " onto stack!\n";
DEBUG(errs() << "Pushing " << ImmPostDomm->getName()
<< " onto stack!\n");
ImmPostDommBlocks.push(ImmPostDomm);
}
......@@ -4117,25 +4092,25 @@ void CWriter::visitBranchInst(BranchInst &I) {
Out << ") { /* " << I << "*/\n";
printPHICopiesForSuccessor(I.getParent(), BB0, 2);
printBBorLoop(BB0);
errs() << "Back to handling " << I.getParent()->getName() << ": " << I
<< "\n";
DEBUG(errs() << "Back to handling " << I.getParent()->getName() << ": "
<< I << "\n");
Out << "/* Back to handling " << I.getParent()->getName() << ": " << I
<< " */\n";
if (!noElse) {
errs() << "Printing else!\n";
DEBUG(errs() << "Printing else!\n");
Out << " } else { /*" << I << "*/\n";
printPHICopiesForSuccessor(I.getParent(), BB1, 2);
ElseBlocks.push(BB1);
ElseBranches.push(&I);
printBBorLoop(BB1);
errs() << "Back to handling " << I.getParent()->getName() << ": " << I
<< "\n";
errs() << "Check to see if else block is closed!\n";
DEBUG(errs() << "Back to handling " << I.getParent()->getName()
<< ": " << I << "\n");
DEBUG(errs() << "Check to see if else block is closed!\n");
Out << "/* Back to handling " << I.getParent()->getName() << ": " << I
<< " */\n";
Out << "/* Check to see if else block is closed! */\n";
if (!ElseBlocks.empty() && ElseBlocks.top() == BB1) {
errs() << "Else block not closed, need to close braces!\n";
DEBUG(errs() << "Else block not closed, need to close braces!\n");
Out << "/* Else block not closed, need to close braces! */\n";
Out << "} /* closing " << *(ElseBranches.top()) << " */\n";
ElseBranches.pop();
......@@ -4143,20 +4118,20 @@ void CWriter::visitBranchInst(BranchInst &I) {
}
if (!ImmPostDommBlocks.empty() &&
ImmPostDommBlocks.top() == ImmPostDomm) {
errs() << "Will now pop post dom them handle it!\n";
DEBUG(errs() << "Will now pop post dom them handle it!\n");
ImmPostDommBlocks.pop();
printBBorLoop(ImmPostDomm);
} else {
errs()
<< "*!*!*!*!*!*!Not sure what is happening here!*!*!*!*!*!*!\n";
DEBUG(errs() << "*!*!*!*!*!*!Not sure what is happening "
"here!*!*!*!*!*!*!\n");
}
} else {
errs() << "No else block. Adding one for phis, then moving to "
<< BB1->getName() << "!\n";
DEBUG(errs() << "No else block. Adding one for phis, then moving to "
<< BB1->getName() << "!\n");
Out << "/* (3913) No else block. Adding one for phis, then moving to "
<< BB1->getName() << "! */\n";
Out << " } /* closing " << I << "*/\n";
errs() << "Will now pop post dom them handle it!\n";
DEBUG(errs() << "Will now pop post dom them handle it!\n");
ImmPostDommBlocks.pop();
Out << "else {\n";
printPHICopiesForSuccessor(I.getParent(), BB1, 2);
......@@ -4165,14 +4140,16 @@ void CWriter::visitBranchInst(BranchInst &I) {
}