Skip to content

add short vector support to wrapper gen #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions lib/Transforms/HC/WrapperGen/WrapperGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,11 @@ namespace
}
// FIXME: Currently there seems to be a bug with char
// Current workaround is to use bool since they both have the same size
// https://bitbucket.org/snippets/wukevin/L8nbK
// Relevant test case: Unit/GridLaunch/customtype_byval_char.cpp
std::string typeNameWithQual(sTy->getTypeNameWithQual());
size_t start_pos = typeNameWithQual.find("char");
if(start_pos != std::string::npos) {
if(start_pos != std::string::npos
&& typeNameWithQual.find("hc::short_vector::char") == std::string::npos) {
typeNameWithQual.replace(start_pos, strlen("char"), "bool");
}

Expand Down Expand Up @@ -461,6 +462,45 @@ struct StringFinder
mArraySize = T->getArrayNumElements();
}

if(T->isVectorTy()) {
llvm::Type* elementType = T->getScalarType();
std::string elementTypeString("");

if(llvm::IntegerType *intTy = llvm::dyn_cast<llvm::IntegerType>(elementType)) {
unsigned bitwidth = intTy->getBitWidth();
switch(bitwidth) {
case 8:
elementTypeString = "char";
break;
case 16:
elementTypeString = "short";
break;
case 32:
elementTypeString = "int";
break;
case 64:
elementTypeString = "long";
break;
default:
break;
};
}
else if (elementType->isFloatTy()) {
elementTypeString = "float";
}
else if (elementType->isDoubleTy()) {
elementTypeString = "double";
}
else if (elementType->isHalfTy()) {
elementTypeString = "half";
}

if (elementTypeString != "") {
unsigned int numElements = T->getVectorNumElements();
str.insert(0, "hc::short_vector::" + elementTypeString + std::to_string(numElements) + "::vector_value_type");
}
}

if(str == "") {
str.append("\'!UNKNOWN_TYPE: ");
llvm::raw_string_ostream rso(str);
Expand Down Expand Up @@ -501,6 +541,7 @@ struct StringFinder
// headers and namespace uses
out << "#include \"hc.hpp\"\n";
out << "#include \"grid_launch.hpp\"\n";
out << "#include \"hc_short_vector.hpp\"\n";

out << "using namespace hc;\n";

Expand Down