Skip to content
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

[SYCLomatic] Refine bindless image helper functions. #1763

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
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
86 changes: 9 additions & 77 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10440,7 +10440,8 @@ void MemoryMigrationRule::arrayMigration(
auto Begin = getArgEndLocation(C, EndPos - 2, SM),
End = getArgEndLocation(C, EndPos, SM);
llvm::raw_string_ostream OS(Str);
OS << ", " << MapNames::getDpctNamespace() << "automatic";
if (!DpctGlobalInfo::useExtBindlessImages())
OS << ", " << MapNames::getDpctNamespace() << "automatic";
OS << ", ";
DerefExpr(StreamExpr, C).print(OS);
emplaceTransformation(replaceText(Begin, End, std::move(Str), SM));
Expand All @@ -10457,20 +10458,7 @@ void MemoryMigrationRule::arrayMigration(

if (NameRef == "cudaMemcpy2DArrayToArray") {
if (DpctGlobalInfo::useExtBindlessImages()) {
std::string Replacement;
llvm::raw_string_ostream OS(Replacement);
OS << ReplaceStr << "(" << ExprAnalysis::ref(C->getArg(3)) << ", "
<< ExprAnalysis::ref(C->getArg(4)) << ", "
<< ExprAnalysis::ref(C->getArg(5)) << ", "
<< ExprAnalysis::ref(C->getArg(0)) << ", "
<< ExprAnalysis::ref(C->getArg(1)) << ", "
<< ExprAnalysis::ref(C->getArg(2)) << ", "
<< ExprAnalysis::ref(C->getArg(6)) << ", "
<< ExprAnalysis::ref(C->getArg(7)) << ", ";
int Index = DpctGlobalInfo::getHelperFuncReplInfoIndexThenInc();
buildTempVariableMap(Index, C, HelperFuncType::HFT_DefaultQueue);
OS << "{{NEEDREPLACEQ" + std::to_string(Index) + "}})";
emplaceTransformation(new ReplaceStmt(C, Replacement));
emplaceTransformation(new ReplaceCalleeName(C, std::move(ReplaceStr)));
} else {
insertToPitchedData(C, 0);
aggregate3DVectorClassCtor(C, "id", 1, "0", SM);
Expand All @@ -10480,19 +10468,7 @@ void MemoryMigrationRule::arrayMigration(
}
} else if (NameRef == "cudaMemcpy2DFromArray") {
if (DpctGlobalInfo::useExtBindlessImages()) {
std::string Replacement;
llvm::raw_string_ostream OS(Replacement);
OS << ReplaceStr << "(" << ExprAnalysis::ref(C->getArg(2)) << ", "
<< ExprAnalysis::ref(C->getArg(3)) << ", "
<< ExprAnalysis::ref(C->getArg(4)) << ", "
<< ExprAnalysis::ref(C->getArg(0)) << ", "
<< ExprAnalysis::ref(C->getArg(1)) << ", "
<< ExprAnalysis::ref(C->getArg(5)) << ", "
<< ExprAnalysis::ref(C->getArg(6)) << ", ";
int Index = DpctGlobalInfo::getHelperFuncReplInfoIndexThenInc();
buildTempVariableMap(Index, C, HelperFuncType::HFT_DefaultQueue);
OS << "{{NEEDREPLACEQ" + std::to_string(Index) + "}})";
emplaceTransformation(new ReplaceStmt(C, Replacement));
emplaceTransformation(new ReplaceCalleeName(C, std::move(ReplaceStr)));
} else {
aggregatePitchedData(C, 0, 1, SM);
insertZeroOffset(C, 2);
Expand All @@ -10502,19 +10478,7 @@ void MemoryMigrationRule::arrayMigration(
}
} else if (NameRef == "cudaMemcpy2DToArray") {
if (DpctGlobalInfo::useExtBindlessImages()) {
std::string Replacement;
llvm::raw_string_ostream OS(Replacement);
OS << ReplaceStr << "(" << ExprAnalysis::ref(C->getArg(3)) << ", "
<< ExprAnalysis::ref(C->getArg(0)) << ", "
<< ExprAnalysis::ref(C->getArg(1)) << ", "
<< ExprAnalysis::ref(C->getArg(2)) << ", "
<< ExprAnalysis::ref(C->getArg(4)) << ", "
<< ExprAnalysis::ref(C->getArg(5)) << ", "
<< ExprAnalysis::ref(C->getArg(6)) << ", ";
int Index = DpctGlobalInfo::getHelperFuncReplInfoIndexThenInc();
buildTempVariableMap(Index, C, HelperFuncType::HFT_DefaultQueue);
OS << "{{NEEDREPLACEQ" + std::to_string(Index) + "}})";
emplaceTransformation(new ReplaceStmt(C, Replacement));
emplaceTransformation(new ReplaceCalleeName(C, std::move(ReplaceStr)));
} else {
insertToPitchedData(C, 0);
aggregate3DVectorClassCtor(C, "id", 1, "0", SM);
Expand All @@ -10524,19 +10488,7 @@ void MemoryMigrationRule::arrayMigration(
}
} else if (NameRef == "cudaMemcpyArrayToArray") {
if (DpctGlobalInfo::useExtBindlessImages()) {
std::string Replacement;
llvm::raw_string_ostream OS(Replacement);
OS << ReplaceStr << "(" << ExprAnalysis::ref(C->getArg(3)) << ", "
<< ExprAnalysis::ref(C->getArg(4)) << ", "
<< ExprAnalysis::ref(C->getArg(5)) << ", "
<< ExprAnalysis::ref(C->getArg(0)) << ", "
<< ExprAnalysis::ref(C->getArg(1)) << ", "
<< ExprAnalysis::ref(C->getArg(2)) << ", "
<< ExprAnalysis::ref(C->getArg(6)) << ", ";
int Index = DpctGlobalInfo::getHelperFuncReplInfoIndexThenInc();
buildTempVariableMap(Index, C, HelperFuncType::HFT_DefaultQueue);
OS << "{{NEEDREPLACEQ" + std::to_string(Index) + "}})";
emplaceTransformation(new ReplaceStmt(C, Replacement));
emplaceTransformation(new ReplaceCalleeName(C, std::move(ReplaceStr)));
} else {
insertToPitchedData(C, 0);
aggregate3DVectorClassCtor(C, "id", 1, "0", SM);
Expand All @@ -10546,17 +10498,7 @@ void MemoryMigrationRule::arrayMigration(
}
} else if (NameRef == "cudaMemcpyFromArray") {
if (DpctGlobalInfo::useExtBindlessImages()) {
std::string Replacement;
llvm::raw_string_ostream OS(Replacement);
OS << ReplaceStr << "(" << ExprAnalysis::ref(C->getArg(1)) << ", "
<< ExprAnalysis::ref(C->getArg(2)) << ", "
<< ExprAnalysis::ref(C->getArg(3)) << ", "
<< ExprAnalysis::ref(C->getArg(0)) << ", "
<< ExprAnalysis::ref(C->getArg(4)) << ", ";
int Index = DpctGlobalInfo::getHelperFuncReplInfoIndexThenInc();
buildTempVariableMap(Index, C, HelperFuncType::HFT_DefaultQueue);
OS << "{{NEEDREPLACEQ" + std::to_string(Index) + "}})";
emplaceTransformation(new ReplaceStmt(C, Replacement));
emplaceTransformation(new ReplaceCalleeName(C, std::move(ReplaceStr)));
} else {
aggregatePitchedData(C, 0, 4, SM, true);
insertZeroOffset(C, 1);
Expand All @@ -10566,17 +10508,7 @@ void MemoryMigrationRule::arrayMigration(
}
} else if (NameRef == "cudaMemcpyToArray") {
if (DpctGlobalInfo::useExtBindlessImages()) {
std::string Replacement;
llvm::raw_string_ostream OS(Replacement);
OS << ReplaceStr << "(" << ExprAnalysis::ref(C->getArg(3)) << ", "
<< ExprAnalysis::ref(C->getArg(0)) << ", "
<< ExprAnalysis::ref(C->getArg(1)) << ", "
<< ExprAnalysis::ref(C->getArg(2)) << ", "
<< ExprAnalysis::ref(C->getArg(4)) << ", ";
int Index = DpctGlobalInfo::getHelperFuncReplInfoIndexThenInc();
buildTempVariableMap(Index, C, HelperFuncType::HFT_DefaultQueue);
OS << "{{NEEDREPLACEQ" + std::to_string(Index) + "}})";
emplaceTransformation(new ReplaceStmt(C, Replacement));
emplaceTransformation(new ReplaceCalleeName(C, std::move(ReplaceStr)));
} else {
insertToPitchedData(C, 0);
aggregate3DVectorClassCtor(C, "id", 1, "0", SM);
Expand Down Expand Up @@ -13261,7 +13193,7 @@ bool TextureRule::tryMerge(const MemberExpr *ME, const Expr *BO) {
void TextureRule::replaceTextureMember(const MemberExpr *ME,
ASTContext &Context, SourceManager &SM) {
auto AssignedBO = getParentAsAssignedBO(ME, Context);
if (tryMerge(ME, AssignedBO))
if (!DpctGlobalInfo::useExtBindlessImages() && tryMerge(ME, AssignedBO))
return;

auto Field = ME->getMemberNameInfo().getAsString();
Expand Down
Loading
Loading