Skip to content

Commit 7eff535

Browse files
committed
Address review feedback
1 parent 080cfdd commit 7eff535

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,10 +3696,10 @@ def CIR_VAEndOp : CIR_Op<"va_end"> {
36963696
}];
36973697
}
36983698

3699-
def CIR_VAArgOp : CIR_Op<"va.arg"> {
3699+
def CIR_VAArgOp : CIR_Op<"va_arg"> {
37003700
let summary = "Fetches next variadic element as a given type";
37013701
let description = [{
3702-
The `cir.va.arg` operation models the C/C++ `va_arg` macro by reading the
3702+
The `cir.va_arg` operation models the C/C++ `va_arg` macro by reading the
37033703
next argument from an active variable argument list and producing it as a
37043704
value of a specified result type.
37053705

@@ -3708,16 +3708,12 @@ def CIR_VAArgOp : CIR_Op<"va.arg"> {
37083708
the fetched value as the result, whose type is chosen by the user of the
37093709
operation.
37103710

3711-
A `cir.va.arg` must only be used on a `va_list` that has been initialized
3711+
A `cir.va_arg` must only be used on a `va_list` that has been initialized
37123712
with `cir.va.start` and not yet finalized by `cir.va.end`. The semantics
37133713
(including alignment and promotion rules) follow the platform ABI; the
37143714
frontend is responsible for providing a `va_list` pointer that matches the
37153715
target representation.
37163716

3717-
Unless replaced by LoweringPrepare for the chosen target ABI this maps to
3718-
LLVM's `va_arg` instruction, yielding a value of the requested result type
3719-
and updating the underlying `va_list` pointer.
3720-
37213717
Example:
37223718
```mlir
37233719
// %args : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>
@@ -3727,7 +3723,7 @@ def CIR_VAArgOp : CIR_Op<"va.arg"> {
37273723
cir.va.start %p : !cir.ptr<!rec___va_list_tag>
37283724

37293725
// Fetch an `int` from the vararg list.
3730-
%v = cir.va.arg %p : (!cir.ptr<!rec___va_list_tag>) -> !s32i
3726+
%v = cir.va_arg %p : (!cir.ptr<!rec___va_list_tag>) -> !s32i
37313727

37323728
cir.va.end %p : !cir.ptr<!rec___va_list_tag>
37333729
```

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ struct MissingFeatures {
279279
static bool vtableInitialization() { return false; }
280280
static bool vtableRelativeLayout() { return false; }
281281
static bool msvcBuiltins() { return false; }
282+
static bool vaArgABILowering() { return false; }
282283
static bool vlas() { return false; }
283284

284285
// Missing types

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,12 @@ void CIRGenFunction::emitVAEnd(mlir::Value vaList) {
402402
cir::VAEndOp::create(builder, vaList.getLoc(), vaList);
403403
}
404404

405-
// FIXME(cir): This completely abstracts away the ABI with a generic CIR Op. We
406-
// need to decide how to handle va_arg target-specific codegen.
407-
mlir::Value CIRGenFunction::emitVAArg(VAArgExpr *ve, Address &vaListAddr) {
405+
// FIXME(cir): This completely abstracts away the ABI with a generic CIR Op. By
406+
// default this lowers to llvm.va_arg which is incomplete and not ABI-compliant
407+
// on most targets so cir.va_arg will need some ABI handling in LoweringPrepare
408+
mlir::Value CIRGenFunction::emitVAArg(VAArgExpr *ve) {
408409
assert(!cir::MissingFeatures::msabi());
410+
assert(!cir::MissingFeatures::vlas());
409411
mlir::Location loc = cgm.getLoc(ve->getExprLoc());
410412
mlir::Type type = convertType(ve->getType());
411413
mlir::Value vaList = emitVAListRef(ve->getSubExpr()).getPointer();

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,14 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
400400
}
401401

402402
mlir::Value VisitVAArgExpr(VAArgExpr *ve) {
403-
QualType Ty = ve->getType();
403+
QualType ty = ve->getType();
404404

405-
if (Ty->isVariablyModifiedType()) {
406-
cgf.cgm.errorNYI(ve->getSourceRange(), "variably modified types in varargs");
405+
if (ty->isVariablyModifiedType()) {
406+
cgf.cgm.errorNYI(ve->getSourceRange(),
407+
"variably modified types in varargs");
407408
}
408409

409-
Address argValue = Address::invalid();
410-
mlir::Value val = cgf.emitVAArg(ve, argValue);
411-
412-
return val;
410+
return cgf.emitVAArg(ve);
413411
}
414412

415413
mlir::Value VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *e);

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ class CIRGenFunction : public CIRGenTypeCache {
15131513
/// either \c emitVAListRef or \c emitMSVAListRef.
15141514
///
15151515
/// \returns SSA value with the argument.
1516-
mlir::Value emitVAArg(VAArgExpr *ve, Address &vaListAddr);
1516+
mlir::Value emitVAArg(VAArgExpr *ve);
15171517

15181518
/// ----------------------
15191519
/// CIR build helpers

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,6 +3152,7 @@ mlir::LogicalResult CIRToLLVMVAEndOpLowering::matchAndRewrite(
31523152
mlir::LogicalResult CIRToLLVMVAArgOpLowering::matchAndRewrite(
31533153
cir::VAArgOp op, OpAdaptor adaptor,
31543154
mlir::ConversionPatternRewriter &rewriter) const {
3155+
assert(!cir::MissingFeatures::vaArgABILowering());
31553156
auto opaquePtr = mlir::LLVM::LLVMPointerType::get(getContext());
31563157
auto vaList = mlir::LLVM::BitcastOp::create(rewriter, op.getLoc(), opaquePtr,
31573158
adaptor.getArgList());

clang/test/CIR/CodeGen/var_arg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int varargs(int count, ...) {
2727
// CIR: %[[COUNT_VAL:.+]] = cir.load{{.*}} %[[COUNT_ADDR]] : !cir.ptr<!s32i>, !s32i
2828
// CIR: cir.va_start %[[VA_PTR0]] %[[COUNT_VAL]] : !cir.ptr<!rec___va_list_tag>, !s32i
2929
// CIR: %[[VA_PTR1:.+]] = cir.cast(array_to_ptrdecay, %[[VAAREA]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag>
30-
// CIR: %[[VA_ARG:.+]] = cir.va.arg %[[VA_PTR1]] : (!cir.ptr<!rec___va_list_tag>) -> !s32i
30+
// CIR: %[[VA_ARG:.+]] = cir.va_arg %[[VA_PTR1]] : (!cir.ptr<!rec___va_list_tag>) -> !s32i
3131
// CIR: cir.store{{.*}} %[[VA_ARG]], %[[RES_ADDR]] : !s32i, !cir.ptr<!s32i>
3232
// CIR: %[[VA_PTR2:.+]] = cir.cast(array_to_ptrdecay, %[[VAAREA]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag>
3333
// CIR: cir.va_end %[[VA_PTR2]] : !cir.ptr<!rec___va_list_tag>
@@ -103,7 +103,7 @@ int stdarg_start(int count, ...) {
103103
// CIR: %[[C12345:.+]] = cir.const #cir.int<12345> : !s32i
104104
// CIR: cir.va_start %[[VA_PTR0]] %[[C12345]] : !cir.ptr<!rec___va_list_tag>, !s32i
105105
// CIR: %[[VA_PTR1:.+]] = cir.cast(array_to_ptrdecay, %[[VAAREA]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag>
106-
// CIR: %[[VA_ARG:.+]] = cir.va.arg %[[VA_PTR1]] : (!cir.ptr<!rec___va_list_tag>) -> !s32i
106+
// CIR: %[[VA_ARG:.+]] = cir.va_arg %[[VA_PTR1]] : (!cir.ptr<!rec___va_list_tag>) -> !s32i
107107
// CIR: cir.store{{.*}} %[[VA_ARG]], %[[RES_ADDR]] : !s32i, !cir.ptr<!s32i>
108108
// CIR: %[[VA_PTR2:.+]] = cir.cast(array_to_ptrdecay, %[[VAAREA]] : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>), !cir.ptr<!rec___va_list_tag>
109109
// CIR: cir.va_end %[[VA_PTR2]] : !cir.ptr<!rec___va_list_tag>

0 commit comments

Comments
 (0)