Skip to content

Commit

Permalink
Wrap all string building terms in std::string constructors
Browse files Browse the repository at this point in the history
explicitly since it appears GCC-12 isn't smart enough to
know how to compile them.

Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
  • Loading branch information
schweitzpgi committed Feb 5, 2025
1 parent 9a9b6c9 commit 7003aa7
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/Optimizer/CodeGen/ReturnToOutputLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ReturnRewrite : public OpRewritePattern<func::ReturnOp> {
TypeSwitch<Type>(valTy)
.Case([&](IntegerType intTy) {
int width = intTy.getWidth();
std::string labelStr{"i" + std::to_string(width)};
std::string labelStr = std::string("i") + std::to_string(width);
if (prefix)
labelStr = prefix->str();
Value label = makeLabel(loc, rewriter, labelStr);
Expand All @@ -113,7 +113,7 @@ class ReturnRewrite : public OpRewritePattern<func::ReturnOp> {
})
.Case([&](FloatType fltTy) {
int width = fltTy.getWidth();
std::string labelStr{"f" + std::to_string(width)};
std::string labelStr = std::string("f") + std::to_string(width);
if (prefix)
labelStr = prefix->str();
Value label = makeLabel(loc, rewriter, labelStr);
Expand All @@ -138,7 +138,7 @@ class ReturnRewrite : public OpRewritePattern<func::ReturnOp> {
ArrayRef<Value>{size, label});
std::string preStr = prefix ? prefix->str() : std::string{};
for (std::int32_t i = 0; i < sz; ++i) {
std::string offset = preStr + '.' + std::to_string(i);
std::string offset = preStr + std::string(".") + std::to_string(i);
Value w = rewriter.create<cudaq::cc::ExtractValueOp>(
loc, strTy.getMember(i), val,
ArrayRef<cudaq::cc::ExtractValueArg>{i});
Expand All @@ -155,7 +155,8 @@ class ReturnRewrite : public OpRewritePattern<func::ReturnOp> {
ArrayRef<Value>{size, label});
std::string preStr = prefix ? prefix->str() : std::string{};
for (std::int32_t i = 0; i < sz; ++i) {
std::string offset = preStr + '[' + std::to_string(i) + ']';
std::string offset = preStr + std::string("[") + std::to_string(i) +
std::string("]");
Value w = rewriter.create<cudaq::cc::ExtractValueOp>(
loc, arrTy.getElementType(), val,
ArrayRef<cudaq::cc::ExtractValueArg>{i});
Expand Down Expand Up @@ -187,7 +188,8 @@ class ReturnRewrite : public OpRewritePattern<func::ReturnOp> {
Value buffer =
rewriter.create<cudaq::cc::CastOp>(loc, ptrArrTy, rawBuffer);
for (std::int32_t i = 0; i < sz; ++i) {
std::string offset = preStr + '[' + std::to_string(i) + ']';
std::string offset = preStr + std::string("[") +
std::to_string(i) + std::string("]");
auto v = rewriter.create<cudaq::cc::ComputePtrOp>(
loc, buffTy, buffer, ArrayRef<cudaq::cc::ComputePtrArg>{i});
Value w = rewriter.create<cudaq::cc::LoadOp>(loc, v);
Expand All @@ -201,30 +203,30 @@ class ReturnRewrite : public OpRewritePattern<func::ReturnOp> {
translateType(Type ty, std::optional<std::int32_t> vecSz = std::nullopt) {
if (auto intTy = dyn_cast<IntegerType>(ty)) {
int width = intTy.getWidth();
return "i" + std::to_string(width);
return {std::string("i") + std::to_string(width)};
}
if (auto fltTy = dyn_cast<FloatType>(ty)) {
int width = fltTy.getWidth();
return "f" + std::to_string(width);
return {std::string("f") + std::to_string(width)};
}
if (auto strTy = dyn_cast<cudaq::cc::StructType>(ty)) {
std::string result = "tuple<";
if (strTy.getMembers().empty())
return result + '>';
return {result + std::string(">")};
result += translateType(strTy.getMembers().front());
for (auto memTy : strTy.getMembers().drop_front())
result += ", " + translateType(memTy);
return result + '>';
result += std::string(", ") + translateType(memTy);
return {result + std::string(">")};
}
if (auto arrTy = dyn_cast<cudaq::cc::ArrayType>(ty)) {
std::int32_t size = arrTy.getSize();
return "array<" + translateType(arrTy.getElementType()) + " x " +
std::to_string(size) + '>';
return {std::string("array<") + translateType(arrTy.getElementType()) +
std::string(" x ") + std::to_string(size) + std::string(">")};
}
if (auto arrTy = dyn_cast<cudaq::cc::StdvecType>(ty))
return "array<" + translateType(arrTy.getElementType()) + " x " +
std::to_string(*vecSz) + '>';
return "error";
return {std::string("array<") + translateType(arrTy.getElementType()) +
std::string(" x ") + std::to_string(*vecSz) + std::string(">")};
return {"error"};
}

static Value makeLabel(Location loc, PatternRewriter &rewriter,
Expand Down

0 comments on commit 7003aa7

Please sign in to comment.