Skip to content

Commit aecacaf

Browse files
authored
Merge branch 'main' into cir_complex_comma_op
2 parents 06a9a5d + 34c12ae commit aecacaf

26 files changed

+525
-187
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,29 +2962,16 @@ def CIR_GetMemberOp : CIR_Op<"get_member"> {
29622962
let arguments = (ins
29632963
Arg<CIR_PointerType, "the address to load from", [MemRead]>:$addr,
29642964
StrAttr:$name,
2965-
IndexAttr:$index_attr);
2965+
I64Attr:$index);
29662966

29672967
let results = (outs Res<CIR_PointerType, "">:$result);
29682968

29692969
let assemblyFormat = [{
2970-
$addr `[` $index_attr `]` attr-dict
2970+
$addr `[` $index `]` attr-dict
29712971
`:` qualified(type($addr)) `->` qualified(type($result))
29722972
}];
29732973

2974-
let builders = [
2975-
OpBuilder<(ins "mlir::Type":$type,
2976-
"mlir::Value":$value,
2977-
"llvm::StringRef":$name,
2978-
"unsigned":$index),
2979-
[{
2980-
mlir::APInt fieldIdx(64, index);
2981-
build($_builder, $_state, type, value, name, fieldIdx);
2982-
}]>
2983-
];
2984-
29852974
let extraClassDeclaration = [{
2986-
/// Return the index of the record member being accessed.
2987-
uint64_t getIndex() { return getIndexAttr().getZExtValue(); }
29882975

29892976
/// Return the record type pointed by the base pointer.
29902977
cir::PointerType getAddrTy() { return getAddr().getType(); }

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ static mlir::Value emitX86ExpandLoad(CIRGenFunction &cgf,
134134
.getResult();
135135
}
136136

137+
static mlir::Value emitX86CompressStore(CIRGenFunction &cgf,
138+
ArrayRef<mlir::Value> ops,
139+
mlir::Location loc) {
140+
auto resultTy = cast<cir::VectorType>(ops[1].getType());
141+
mlir::Value ptr = ops[0];
142+
143+
mlir::Value maskVec = getMaskVecValue(cgf, ops[2], resultTy.getSize(), loc);
144+
145+
return cgf.getBuilder()
146+
.create<cir::LLVMIntrinsicCallOp>(
147+
loc, cgf.getBuilder().getStringAttr("masked.compressstore"),
148+
cgf.getBuilder().getVoidTy(), mlir::ValueRange{ops[1], ptr, maskVec})
149+
.getResult();
150+
}
151+
137152
static mlir::Value emitX86SExtMask(CIRGenFunction &cgf, mlir::Value op,
138153
mlir::Type dstTy, mlir::Location loc) {
139154
unsigned numberOfElements = cast<cir::VectorType>(dstTy).getSize();
@@ -645,7 +660,7 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
645660
case X86::BI__builtin_ia32_compressstoreqi128_mask:
646661
case X86::BI__builtin_ia32_compressstoreqi256_mask:
647662
case X86::BI__builtin_ia32_compressstoreqi512_mask:
648-
llvm_unreachable("compress*_mask NYI");
663+
return emitX86CompressStore(*this, Ops, getLoc(E->getExprLoc()));
649664

650665
case X86::BI__builtin_ia32_expanddf128_mask:
651666
case X86::BI__builtin_ia32_expanddf256_mask:

clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ bool CIRGenCXXABI::isZeroInitializable(const MemberPointerType *MPT) {
8686
return true;
8787
}
8888

89+
mlir::TypedAttr CIRGenCXXABI::emitNullMemberPointer(clang::QualType T) {
90+
llvm_unreachable("NYI");
91+
}
92+
8993
CharUnits CIRGenCXXABI::getArrayCookieSize(const CXXNewExpr *E) {
9094
if (!requiresArrayCookie(E))
9195
return CharUnits::Zero();

clang/lib/CIR/CodeGen/CIRGenCXXABI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ class CIRGenCXXABI {
292292
return true;
293293
}
294294

295+
/// Create a null member pointer of the given type.
296+
virtual mlir::TypedAttr emitNullMemberPointer(clang::QualType T);
297+
295298
/// Gets the offsets of all the virtual base pointers in a given class.
296299
virtual std::vector<CharUnits> getVBPtrOffsets(const CXXRecordDecl *RD);
297300

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,8 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *E) {
10561056
cir::GlobalOp var = CGM.getOrCreateStaticVarDecl(
10571057
*VD, CGM.getCIRLinkageVarDefinition(VD, /*IsConstant=*/false));
10581058
auto getGlobalOp = builder.createGetGlobal(var);
1059-
auto actualElemTy = llvm::cast<cir::PointerType>(getGlobalOp.getType()).getPointee();
1059+
auto actualElemTy =
1060+
llvm::cast<cir::PointerType>(getGlobalOp.getType()).getPointee();
10601061
addr = Address(getGlobalOp, actualElemTy, getContext().getDeclAlign(VD));
10611062
} else {
10621063
llvm_unreachable("DeclRefExpr for decl not entered in LocalDeclMap?");
@@ -2017,7 +2018,15 @@ LValue CIRGenFunction::emitCastLValue(const CastExpr *E) {
20172018
assert(0 && "NYI");
20182019
}
20192020
case CK_LValueBitCast: {
2020-
assert(0 && "NYI");
2021+
// This must be a reinterpret_cast (or c-style equivalent).
2022+
const auto *ce = cast<ExplicitCastExpr>(E);
2023+
2024+
CGM.emitExplicitCastExprType(ce, this);
2025+
LValue LV = emitLValue(E->getSubExpr());
2026+
Address V = LV.getAddress().withElementType(
2027+
builder, convertTypeForMem(ce->getTypeAsWritten()->getPointeeType()));
2028+
2029+
return makeAddrLValue(V, E->getType(), LV.getBaseInfo(), LV.getTBAAInfo());
20212030
}
20222031
case CK_AddressSpaceConversion: {
20232032
LValue LV = emitLValue(E->getSubExpr());

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,24 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
311311
}
312312

313313
mlir::Value
314-
VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO) {
315-
llvm_unreachable("NYI");
314+
VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
315+
mlir::Value condValue = Visit(E->getCond());
316+
mlir::Location loc = CGF.getLoc(E->getSourceRange());
317+
318+
return Builder
319+
.create<cir::TernaryOp>(
320+
loc, condValue,
321+
/*thenBuilder=*/
322+
[&](mlir::OpBuilder &b, mlir::Location loc) {
323+
mlir::Value trueValue = Visit(E->getTrueExpr());
324+
b.create<cir::YieldOp>(loc, trueValue);
325+
},
326+
/*elseBuilder=*/
327+
[&](mlir::OpBuilder &b, mlir::Location loc) {
328+
mlir::Value falseValue = Visit(E->getFalseExpr());
329+
b.create<cir::YieldOp>(loc, falseValue);
330+
})
331+
.getResult();
316332
}
317333

318334
mlir::Value VisitChooseExpr(ChooseExpr *CE) {
@@ -429,8 +445,13 @@ mlir::Value ComplexExprEmitter::emitCast(CastKind CK, Expr *Op,
429445
case CK_UserDefinedConversion:
430446
llvm_unreachable("NYI");
431447

432-
case CK_LValueBitCast:
433-
llvm_unreachable("NYI");
448+
case CK_LValueBitCast: {
449+
LValue origLV = CGF.emitLValue(Op);
450+
Address addr =
451+
origLV.getAddress().withElementType(Builder, CGF.convertType(DestTy));
452+
LValue destLV = CGF.makeAddrLValue(addr, DestTy);
453+
return emitLoadOfLValue(destLV, Op->getExprLoc());
454+
}
434455

435456
case CK_LValueToRValueBitCast: {
436457
LValue SourceLVal = CGF.emitLValue(Op);

0 commit comments

Comments
 (0)