Skip to content

Commit e52c7ed

Browse files
committed
Address comments regarding allocaAS source casting on tempAlloca. and address more nits
1 parent 979c034 commit e52c7ed

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

clang/lib/CIR/CodeGen/Address.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
#include "mlir/IR/Value.h"
1818
#include "clang/AST/CharUnits.h"
19+
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
1920
#include "clang/CIR/Dialect/IR/CIRTypes.h"
2021
#include "clang/CIR/MissingFeatures.h"
2122
#include "llvm/ADT/PointerIntPair.h"
23+
#include "llvm/Support/Casting.h"
2224

2325
namespace clang::CIRGen {
2426

@@ -114,6 +116,11 @@ class Address {
114116
return elementType;
115117
}
116118

119+
cir::TargetAddressSpaceAttr getAddressSpace() const {
120+
auto ptrTy = llvm::dyn_cast<cir::PointerType>(getType());
121+
return ptrTy.getAddrSpace();
122+
}
123+
117124
clang::CharUnits getAlignment() const { return alignment; }
118125

119126
/// Get the operation which defines this address.

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,13 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *e) {
12201220

12211221
clang::LangAS srcLangAS = e->getSubExpr()->getType().getAddressSpace();
12221222
cir::TargetAddressSpaceAttr srcAS;
1223-
if (clang::isTargetAddressSpace(srcLangAS)) {
1223+
if (clang::isTargetAddressSpace(srcLangAS))
12241224
srcAS = cir::toCIRTargetAddressSpace(getMLIRContext(), srcLangAS);
1225-
}
1225+
else
1226+
cgm.errorNYI(
1227+
e->getSourceRange(),
1228+
"emitCastLValue: address space conversion from unknown address "
1229+
"space");
12261230

12271231
mlir::Value v = getTargetHooks().performAddrSpaceCast(
12281232
*this, lv.getPointer(), srcAS, convertType(destTy));
@@ -2311,7 +2315,10 @@ Address CIRGenFunction::createTempAlloca(mlir::Type ty, CharUnits align,
23112315
// in C++ the auto variables are in the default address space. Therefore
23122316
// cast alloca to the default address space when necessary.
23132317

2314-
LangAS allocaAS = cgm.getLangTempAllocaAddressSpace();
2318+
LangAS allocaAS = alloca.getAddressSpace()
2319+
? clang::getLangASFromTargetAS(
2320+
alloca.getAddressSpace().getValue().getUInt())
2321+
: clang::LangAS::Default;
23152322
LangAS dstTyAS = clang::LangAS::Default;
23162323
if (getCIRAllocaAddressSpace()) {
23172324
dstTyAS = clang::getLangASFromTargetAS(

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,9 +1888,11 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
18881888

18891889
clang::LangAS srcLangAS = subExpr->getType().getAddressSpace();
18901890
cir::TargetAddressSpaceAttr subExprAS;
1891-
if (clang::isTargetAddressSpace(srcLangAS)) {
1891+
if (clang::isTargetAddressSpace(srcLangAS))
18921892
subExprAS = cir::toCIRTargetAddressSpace(cgf.getMLIRContext(), srcLangAS);
1893-
}
1893+
else
1894+
cgf.cgm.errorNYI(subExpr->getSourceRange(),
1895+
"non-target address space conversion");
18941896
// Since target may map different address spaces in AST to the same address
18951897
// space, an address space conversion may end up as a bitcast.
18961898
return cgf.cgm.getTargetCIRGenInfo().performAddrSpaceCast(

0 commit comments

Comments
 (0)