Skip to content

Commit

Permalink
Merge pull request #66 from illuhad/llvm-6.0
Browse files Browse the repository at this point in the history
Initial support for LLVM > 4.0
  • Loading branch information
hughperkins authored Jul 3, 2018
2 parents 282f642 + 532a7a8 commit c63edf9
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 45 deletions.
29 changes: 29 additions & 0 deletions include/cocl/llvm_dump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Hugh Perkins 2016, 2017

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/// \author Aksel Alpay

#ifndef COCL_LLVM_DUMP_H
#define COCL_LLVM_DUMP_H

#include <llvm/Support/Debug.h>

#if LLVM_VERSION_MAJOR > 4
#define COCL_LLVM_DUMP(entity) (entity)->print(llvm::dbgs(), true)
#else
#define COCL_LLVM_DUMP(entity) ((entity)->dump())
#endif

#endif

4 changes: 2 additions & 2 deletions include/cocl/new_instruction_dumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "cocl/LocalValueInfo.h"
#include "cocl/InstructionDumper.h"
#include "cocl/shims.h"

#include "cocl/llvm_dump.h"
#include <string>
#include <stdexcept>

Expand All @@ -29,7 +29,7 @@ class NeedValueDependencyException : public std::exception {
}
virtual const char* what() const throw()
{
value->dump();
COCL_LLVM_DUMP(value);
return "Need dependent value";
}
llvm::Value *value;
Expand Down
6 changes: 4 additions & 2 deletions include/cocl/patch_hostside.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Ok, so the doc is mostly below, inside the class declaration, at the bottom of t
#include <vector>
#include <memory>

#include "cocl/llvm_dump.h"

#include "llvm/IR/Module.h"
// #include "llvm/IR/Verifier.h"
#include "llvm/IR/Type.h"
Expand Down Expand Up @@ -148,7 +150,7 @@ class GenericCallInst_Call : public GenericCallInst {
virtual llvm::Value *getOperand(int idx) override { return inst->getArgOperand(idx); }
virtual llvm::Module *getModule() override { return inst->getModule(); }
virtual llvm::Instruction *getInst() override { return inst; }
virtual void dump() override { inst->dump(); }
virtual void dump() override { COCL_LLVM_DUMP(inst); }
};

class GenericCallInst_Invoke : public GenericCallInst {
Expand All @@ -159,7 +161,7 @@ class GenericCallInst_Invoke : public GenericCallInst {
virtual llvm::Value *getOperand(int idx) override { return inst->getArgOperand(idx); }
virtual llvm::Module *getModule() override { return inst->getModule(); }
virtual llvm::Instruction *getInst() override { return inst; }
virtual void dump() override { inst->dump(); }
virtual void dump() override { COCL_LLVM_DUMP(inst); }
};

class PatchHostside {
Expand Down
12 changes: 7 additions & 5 deletions src/ClWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Constants.h"

#include "cocl/llvm_dump.h"

#include <iostream>
using namespace std;
using namespace llvm;
Expand Down Expand Up @@ -74,7 +76,7 @@ void ClWriter::writeInlineCl(std::string indent, std::ostream &os) { // writes a
}
if(localValueInfo->toBeDeclared) {
if(!localValueInfo->expressionValid) {
localValueInfo->value->dump();
COCL_LLVM_DUMP(localValueInfo->value);
cout << "expression for " << localValueInfo->name + " not defined" << endl;
throw runtime_error("expression for " + localValueInfo->name + " not defined");
}
Expand Down Expand Up @@ -156,7 +158,7 @@ void AllocaClWriter::writeDeclaration(std::string indent, TypeDumper *typeDumper
throw runtime_error("not implemented: alloca for count != 1");
}
} else {
alloca->dump();
COCL_LLVM_DUMP(alloca);
throw runtime_error("dumpalloca not implemented for non pointer type");
}
}
Expand Down Expand Up @@ -244,7 +246,7 @@ void SharedClWriter::writeDeclaration(std::string indent, TypeDumper *typeDumper
// primitiveType->dump();
} else {
cout << "ERROR: sharedclwriter::writedlecaraiotn, not implemneted for:" << endl;
value->dump();
COCL_LLVM_DUMP(value);
cout << endl;
// TODO: uncomment this line FIXME
return;
Expand All @@ -256,7 +258,7 @@ void SharedClWriter::writeDeclaration(std::string indent, TypeDumper *typeDumper
os << indent << "local " << typeDumper->dumpType(primitiveType) << " " << localValueInfo->name << "[" << numElements << "];\n";
} else {
cout << "sharedclwriter writedeclaration not implmeneted for htis type:" << endl;
value->dump();
COCL_LLVM_DUMP(value);
cout << endl;
throw runtime_error("not implemented: sharedclwriter for this type");
}
Expand Down Expand Up @@ -311,7 +313,7 @@ void CallClWriter::writeInlineCl(std::string indent, std::ostream &os) { // writ
}
if(localValueInfo->toBeDeclared) {
if(!localValueInfo->expressionValid) {
localValueInfo->value->dump();
COCL_LLVM_DUMP(localValueInfo->value);
cout << "expression for " << localValueInfo->name + " not defined" << endl;
throw runtime_error("expression for " + localValueInfo->name + " not defined");
}
Expand Down
5 changes: 3 additions & 2 deletions src/GlobalNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "cocl/GlobalNames.h"
#include "cocl/llvm_dump.h"

#include "EasyCL/util/easycl_stringhelper.h"

Expand All @@ -35,7 +36,7 @@ std::string GlobalNames::getName(Value *value) {
auto it = nameByValue.find(value);
if(it == nameByValue.end()) {
cout << "this value not found in global name map:" << endl;
value->dump();
COCL_LLVM_DUMP(value);
cout << endl;
throw runtime_error("value not found in global name map");
}
Expand Down Expand Up @@ -99,7 +100,7 @@ std::string GlobalNames::createName(Value *value, std::string name) {
std::string GlobalNames::getName(Type *type) {
auto it = nameByType.find(type);
if(it == nameByType.end()) {
type->dump();
COCL_LLVM_DUMP(type);
cout << endl;
throw runtime_error("type not found in name map");
}
Expand Down
5 changes: 3 additions & 2 deletions src/LocalNames.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cocl/LocalNames.h"
#include "cocl/llvm_dump.h"

#include "EasyCL/util/easycl_stringhelper.h"

Expand All @@ -14,7 +15,7 @@ std::string LocalNames::getName(Value *value) {
auto it = nameByValue.find(value);
if(it == nameByValue.end()) {
cout << "this value not found in local names:" << endl;
value->dump();
COCL_LLVM_DUMP(value);
cout << endl;
throw runtime_error("value not found in local name map");
}
Expand Down Expand Up @@ -67,7 +68,7 @@ bool LocalNames::hasValue(llvm::Value *value) {

std::string LocalNames::createName(Value *value, std::string name) {
if(valueByName.find(name) != valueByName.end()) {
valueByName[name]->dump();
COCL_LLVM_DUMP(valueByName[name]);
cout << endl;
throw runtime_error("duplicate name " + name);
}
Expand Down
3 changes: 2 additions & 1 deletion src/basicblockdumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include "cocl/basicblockdumper.h"
#include "cocl/llvm_dump.h"

#include <iostream>
#include <stdexcept>
Expand Down Expand Up @@ -98,7 +99,7 @@ bool BasicBlockDumper::runGeneration(const std::map<llvm::Function *, llvm::Type
}
} catch(runtime_error &e) {
cout << "basicblockdumper.runGeneration got exception whilst processing:" << endl;
inst->dump();
COCL_LLVM_DUMP(inst);
cout << endl;
throw e;
}
Expand Down
4 changes: 3 additions & 1 deletion src/function_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include "llvm/IR/Function.h"

#include "cocl/llvm_dump.h"

#include <sstream>

using namespace std;
Expand Down Expand Up @@ -349,7 +351,7 @@ std::string FunctionDumper::dumpTerminator(Type **pReturnType, Instruction *term
terminatorCl = dumpBranch(branch);
} else {
cout << "unhandled terminator type:";
terminator->dump();
COCL_LLVM_DUMP(terminator);
throw runtime_error("unhandled terminator type");
}
return terminatorCl;
Expand Down
10 changes: 6 additions & 4 deletions src/new_instruction_dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "cocl/readIR.h"
#include "EasyCL/util/easycl_stringhelper.h"

#include "cocl/llvm_dump.h"

#include "llvm/IR/Instructions.h"
#include "llvm/IR/Constants.h"
#include "llvm/Transforms/Utils/Cloning.h"
Expand Down Expand Up @@ -125,7 +127,7 @@ LocalValueInfo *NewInstructionDumper::dumpConstant(llvm::Constant *constant) {
return constantInfo;
} else {
cout << "dumpconstant, unhandled valuetype valueTy " << valueTy << endl;
constant->dump();
COCL_LLVM_DUMP(constant);
cout << endl;
throw runtime_error("unknown constnat type");
}
Expand Down Expand Up @@ -475,7 +477,7 @@ void NewInstructionDumper::dumpGetElementPtr(cocl::LocalValueInfo *localValueInf
}
} else {
cout << "type unimplemeneted in gep:" << endl;
currentType->dump();
COCL_LLVM_DUMP(currentType);
cout << endl;
cout << "isa pointer " << isa<PointerType>(currentType) << endl;
cout << "isa struct " << isa<StructType>(currentType) << endl;
Expand Down Expand Up @@ -620,7 +622,7 @@ void NewInstructionDumper::dumpExtractValue(cocl::LocalValueInfo *localValueInfo
}
} else {
cout << "NewInstructionDumper::dumpExtractValue unimplemented type" << endl;
currentType->dump();
COCL_LLVM_DUMP(currentType);
throw runtime_error("type not implemented in extractvalue");
}
currentType = newType;
Expand Down Expand Up @@ -682,7 +684,7 @@ void NewInstructionDumper::dumpInsertValue(cocl::LocalValueInfo *localValueInfo)
newType = elementType;
}
} else {
currentType->dump();
COCL_LLVM_DUMP(currentType);
throw runtime_error("type not implemented in insertvalue");
}
currentType = newType;
Expand Down
Loading

0 comments on commit c63edf9

Please sign in to comment.