Skip to content

Commit 060d449

Browse files
committed
Enable the formatting workflow for llvm/clangir
1 parent 3adad6b commit 060d449

23 files changed

+159
-175
lines changed

.github/workflows/pr-code-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ permissions:
66
jobs:
77
code_formatter:
88
runs-on: ubuntu-latest
9-
if: github.repository == 'llvm/llvm-project'
9+
if: github.repository == 'llvm/clangir'
1010
steps:
1111
- name: Fetch LLVM sources
1212
uses: actions/checkout@v4

clang/include/clang/CIR/Dialect/IR/CIRDialect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include "mlir/IR/BuiltinTypes.h"
1919
#include "mlir/IR/Dialect.h"
2020
#include "mlir/IR/OpDefinition.h"
21-
#include "mlir/Interfaces/FunctionInterfaces.h"
2221
#include "mlir/Interfaces/CallInterfaces.h"
2322
#include "mlir/Interfaces/ControlFlowInterfaces.h"
23+
#include "mlir/Interfaces/FunctionInterfaces.h"
2424
#include "mlir/Interfaces/InferTypeOpInterface.h"
2525
#include "mlir/Interfaces/LoopLikeInterface.h"
2626
#include "mlir/Interfaces/SideEffectInterfaces.h"

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,13 +1447,13 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point",
14471447

14481448
def SetBitfieldOp : CIR_Op<"set_bitfield"> {
14491449
let summary = "Set a bitfield";
1450-
let description = [{
1451-
The `cir.set_bitfield` operation provides a store-like access to
1450+
let description = [{
1451+
The `cir.set_bitfield` operation provides a store-like access to
14521452
a bit field of a record.
14531453

14541454
It expects an address of a storage where to store, a type of the storage,
14551455
a value being stored, a name of a bit field, a pointer to the storage in the
1456-
base record, a size of the storage, a size the bit field, an offset
1456+
base record, a size of the storage, a size the bit field, an offset
14571457
of the bit field and a sign. Returns a value being stored.
14581458

14591459
Example.
@@ -1496,20 +1496,20 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
14961496

14971497
let assemblyFormat = [{ `(`$bitfield_info`,` $dst`:`type($dst)`,`
14981498
$src`:`type($src) `)` attr-dict `->` type($result) }];
1499-
1499+
15001500
let builders = [
15011501
OpBuilder<(ins "Type":$type,
15021502
"Value":$dst,
15031503
"Type":$storage_type,
15041504
"Value":$src,
15051505
"StringRef":$name,
1506-
"unsigned":$size,
1506+
"unsigned":$size,
15071507
"unsigned":$offset,
15081508
"bool":$is_signed
15091509
),
1510-
[{
1511-
BitfieldInfoAttr info =
1512-
BitfieldInfoAttr::get($_builder.getContext(),
1510+
[{
1511+
BitfieldInfoAttr info =
1512+
BitfieldInfoAttr::get($_builder.getContext(),
15131513
name, storage_type,
15141514
size, offset, is_signed);
15151515
build($_builder, $_state, type, dst, src, info);
@@ -1523,7 +1523,7 @@ def SetBitfieldOp : CIR_Op<"set_bitfield"> {
15231523

15241524
def GetBitfieldOp : CIR_Op<"get_bitfield"> {
15251525
let summary = "Get a bitfield";
1526-
let description = [{
1526+
let description = [{
15271527
The `cir.get_bitfield` operation provides a load-like access to
15281528
a bit field of a record.
15291529

@@ -1561,13 +1561,13 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
15611561
}];
15621562

15631563
let arguments = (ins
1564-
AnyType:$addr,
1564+
AnyType:$addr,
15651565
BitfieldInfoAttr:$bitfield_info
15661566
);
15671567

15681568
let results = (outs CIR_IntType:$result);
15691569

1570-
let assemblyFormat = [{ `(`$bitfield_info `,` $addr attr-dict `:`
1570+
let assemblyFormat = [{ `(`$bitfield_info `,` $addr attr-dict `:`
15711571
type($addr) `)` `->` type($result) }];
15721572

15731573
let builders = [
@@ -1580,8 +1580,8 @@ def GetBitfieldOp : CIR_Op<"get_bitfield"> {
15801580
"bool":$is_signed
15811581
),
15821582
[{
1583-
BitfieldInfoAttr info =
1584-
BitfieldInfoAttr::get($_builder.getContext(),
1583+
BitfieldInfoAttr info =
1584+
BitfieldInfoAttr::get($_builder.getContext(),
15851585
name, storage_type,
15861586
size, offset, is_signed);
15871587
build($_builder, $_state, type, addr, info);
@@ -2593,19 +2593,19 @@ def CIR_InlineAsmOp : CIR_Op<"asm", [RecursiveMemoryEffects]> {
25932593

25942594
```
25952595
```mlir
2596-
cir.asm(x86_att, {"xyz"}) -> !void
2596+
cir.asm(x86_att, {"xyz"}) -> !void
25972597
```
25982598
}];
25992599

26002600
let results = (outs Optional<AnyType>:$res);
26012601

26022602
let arguments = (
26032603
ins StrAttr:$asm_string,
2604-
AsmFlavor:$asm_flavor);
2604+
AsmFlavor:$asm_flavor);
26052605

26062606
let assemblyFormat = [{
26072607
`(`$asm_flavor`,` `{` $asm_string `}` `)` attr-dict `:` type($res)
2608-
}];
2608+
}];
26092609
}
26102610

26112611
#endif // MLIR_CIR_DIALECT_CIR_OPS

clang/include/clang/CIR/Dialect/IR/CIRTypesDetails.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- CIRTypesDetails.h - Details of CIR dialect types -----------*- C++ -*-===//
1+
//===- CIRTypesDetails.h - Details of CIR dialect types ---------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang/lib/CIR/CodeGen/CIRAsm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
4141

4242
AsmDialect AsmDialect = inferDialect(CGM, S);
4343

44-
builder.create<mlir::cir::InlineAsmOp>(
45-
getLoc(S.getAsmLoc()), ResultType, AsmString, AsmDialect);
44+
builder.create<mlir::cir::InlineAsmOp>(getLoc(S.getAsmLoc()), ResultType,
45+
AsmString, AsmDialect);
4646

4747
return mlir::success();
4848
}

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,10 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
787787
return create<mlir::cir::StackSaveOp>(loc, ty);
788788
}
789789

790-
mlir::cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v) {
790+
mlir::cir::StackRestoreOp createStackRestore(mlir::Location loc,
791+
mlir::Value v) {
791792
return create<mlir::cir::StackRestoreOp>(loc, v);
792793
}
793-
794794
};
795795

796796
} // namespace cir

clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,9 @@ CIRGenFunction::buildCoroAllocBuiltinCall(mlir::Location loc) {
194194

195195
mlir::cir::FuncOp fnOp;
196196
if (!builtin) {
197-
fnOp = CGM.createCIRFunction(
198-
loc, CGM.builtinCoroAlloc,
199-
mlir::cir::FuncType::get({int32Ty}, boolTy),
200-
/*FD=*/nullptr);
197+
fnOp = CGM.createCIRFunction(loc, CGM.builtinCoroAlloc,
198+
mlir::cir::FuncType::get({int32Ty}, boolTy),
199+
/*FD=*/nullptr);
201200
assert(fnOp && "should always succeed");
202201
fnOp.setBuiltinAttr(mlir::UnitAttr::get(builder.getContext()));
203202
} else
@@ -217,8 +216,7 @@ CIRGenFunction::buildCoroBeginBuiltinCall(mlir::Location loc,
217216
if (!builtin) {
218217
fnOp = CGM.createCIRFunction(
219218
loc, CGM.builtinCoroBegin,
220-
mlir::cir::FuncType::get({int32Ty, VoidPtrTy},
221-
VoidPtrTy),
219+
mlir::cir::FuncType::get({int32Ty, VoidPtrTy}, VoidPtrTy),
222220
/*FD=*/nullptr);
223221
assert(fnOp && "should always succeed");
224222
fnOp.setBuiltinAttr(mlir::UnitAttr::get(builder.getContext()));

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ struct CallCleanupFunction final : EHScopeStack::Cleanup {
892892
/// Push the standard destructor for the given type as
893893
/// at least a normal cleanup.
894894
void CIRGenFunction::pushDestroy(QualType::DestructionKind dtorKind,
895-
Address addr, QualType type) {
895+
Address addr, QualType type) {
896896
assert(dtorKind && "cannot push destructor for trivial type");
897897

898898
CleanupKind cleanupKind = getCleanupKind(dtorKind);

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ Address CIRGenFunction::getAddrOfBitFieldStorage(LValue base,
234234

235235
auto fieldPtr =
236236
mlir::cir::PointerType::get(getBuilder().getContext(), fieldType);
237-
auto sea = getBuilder().createGetMember(
238-
loc, fieldPtr, base.getPointer(), field->getName(), index);
237+
auto sea = getBuilder().createGetMember(loc, fieldPtr, base.getPointer(),
238+
field->getName(), index);
239239

240240
return Address(sea, CharUnits::One());
241241
}
@@ -341,7 +341,7 @@ LValue CIRGenFunction::buildLValueForField(LValue base,
341341
if (!IsInPreservedAIRegion &&
342342
(!getDebugInfo() || !rec->hasAttr<BPFPreserveAccessIndexAttr>())) {
343343
llvm::StringRef fieldName = field->getName();
344-
auto& layout = CGM.getTypes().getCIRGenRecordLayout(field->getParent());
344+
auto &layout = CGM.getTypes().getCIRGenRecordLayout(field->getParent());
345345
unsigned fieldIndex = layout.getCIRFieldNo(field);
346346

347347
if (CGM.LambdaFieldToName.count(field))
@@ -396,7 +396,7 @@ LValue CIRGenFunction::buildLValueForFieldInitialization(
396396
if (!FieldType->isReferenceType())
397397
return buildLValueForField(Base, Field);
398398

399-
auto& layout = CGM.getTypes().getCIRGenRecordLayout(Field->getParent());
399+
auto &layout = CGM.getTypes().getCIRGenRecordLayout(Field->getParent());
400400
unsigned FieldIndex = layout.getCIRFieldNo(Field);
401401

402402
Address V = buildAddrOfFieldStorage(*this, Base.getAddress(), Field,

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,36 @@ static bool isBlockVarRef(const Expr *E) {
6060
// FIXME: pointer arithmetic?
6161
return false;
6262

63-
// Check both sides of a conditional operator.
64-
} else if (const AbstractConditionalOperator *op
65-
= dyn_cast<AbstractConditionalOperator>(E)) {
66-
return isBlockVarRef(op->getTrueExpr())
67-
|| isBlockVarRef(op->getFalseExpr());
68-
69-
// OVEs are required to support BinaryConditionalOperators.
70-
} else if (const OpaqueValueExpr *op
71-
= dyn_cast<OpaqueValueExpr>(E)) {
63+
// Check both sides of a conditional operator.
64+
} else if (const AbstractConditionalOperator *op =
65+
dyn_cast<AbstractConditionalOperator>(E)) {
66+
return isBlockVarRef(op->getTrueExpr()) ||
67+
isBlockVarRef(op->getFalseExpr());
68+
69+
// OVEs are required to support BinaryConditionalOperators.
70+
} else if (const OpaqueValueExpr *op = dyn_cast<OpaqueValueExpr>(E)) {
7271
if (const Expr *src = op->getSourceExpr())
7372
return isBlockVarRef(src);
7473

75-
// Casts are necessary to get things like (*(int*)&var) = foo().
76-
// We don't really care about the kind of cast here, except
77-
// we don't want to look through l2r casts, because it's okay
78-
// to get the *value* in a __block variable.
74+
// Casts are necessary to get things like (*(int*)&var) = foo().
75+
// We don't really care about the kind of cast here, except
76+
// we don't want to look through l2r casts, because it's okay
77+
// to get the *value* in a __block variable.
7978
} else if (const CastExpr *cast = dyn_cast<CastExpr>(E)) {
8079
if (cast->getCastKind() == CK_LValueToRValue)
8180
return false;
8281
return isBlockVarRef(cast->getSubExpr());
8382

84-
// Handle unary operators. Again, just aggressively look through
85-
// it, ignoring the operation.
83+
// Handle unary operators. Again, just aggressively look through
84+
// it, ignoring the operation.
8685
} else if (const UnaryOperator *uop = dyn_cast<UnaryOperator>(E)) {
8786
return isBlockVarRef(uop->getSubExpr());
8887

89-
// Look into the base of a field access.
88+
// Look into the base of a field access.
9089
} else if (const MemberExpr *mem = dyn_cast<MemberExpr>(E)) {
9190
return isBlockVarRef(mem->getBase());
9291

93-
// Look into the base of a subscript.
92+
// Look into the base of a subscript.
9493
} else if (const ArraySubscriptExpr *sub = dyn_cast<ArraySubscriptExpr>(E)) {
9594
return isBlockVarRef(sub->getBase());
9695
}
@@ -113,7 +112,8 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
113112
llvm::function_ref<RValue(ReturnValueSlot)> Fn);
114113

115114
AggValueSlot EnsureSlot(mlir::Location loc, QualType T) {
116-
if (!Dest.isIgnored()) return Dest;
115+
if (!Dest.isIgnored())
116+
return Dest;
117117
return CGF.CreateAggTemp(T, loc, "agg.tmp.ensured");
118118
}
119119

@@ -213,11 +213,11 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
213213
// For an assignment to work, the value on the right has
214214
// to be compatible with the value on the left.
215215
assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
216-
E->getRHS()->getType())
217-
&& "Invalid assignment");
216+
E->getRHS()->getType()) &&
217+
"Invalid assignment");
218218

219219
if (isBlockVarRef(E->getLHS()) &&
220-
E->getRHS()->HasSideEffects(CGF.getContext())) {
220+
E->getRHS()->HasSideEffects(CGF.getContext())) {
221221
llvm_unreachable("NYI");
222222
}
223223

@@ -233,12 +233,11 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
233233

234234
// Codegen the RHS so that it stores directly into the LHS.
235235
AggValueSlot lhsSlot = AggValueSlot::forLValue(
236-
lhs, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers,
237-
AggValueSlot::IsAliased, AggValueSlot::MayOverlap);
236+
lhs, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers,
237+
AggValueSlot::IsAliased, AggValueSlot::MayOverlap);
238238

239239
// A non-volatile aggregate destination might have volatile member.
240-
if (!lhsSlot.isVolatile() &&
241-
CGF.hasVolatileMember(E->getLHS()->getType()))
240+
if (!lhsSlot.isVolatile() && CGF.hasVolatileMember(E->getLHS()->getType()))
242241
assert(!UnimplementedFeature::atomicTypes());
243242

244243
CGF.buildAggExpr(E->getRHS(), lhsSlot);
@@ -247,10 +246,10 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
247246
buildFinalDestCopy(E->getType(), lhs);
248247

249248
if (!Dest.isIgnored() && !Dest.isExternallyDestructed() &&
250-
E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
249+
E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
251250
CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Dest.getAddress(),
252-
E->getType());
253-
}
251+
E->getType());
252+
}
254253

255254
void VisitBinComma(const BinaryOperator *E) { llvm_unreachable("NYI"); }
256255
void VisitBinCmp(const BinaryOperator *E) { llvm_unreachable("NYI"); }
@@ -356,8 +355,8 @@ void AggExprEmitter::buildFinalDestCopy(QualType type, const LValue &src,
356355
assert(!UnimplementedFeature::volatileTypes());
357356

358357
if (SrcValueKind == EVK_RValue) {
359-
if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
360-
llvm_unreachable("move assignment/move ctor for rvalue is NYI");
358+
if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
359+
llvm_unreachable("move assignment/move ctor for rvalue is NYI");
361360
}
362361
} else {
363362
if (type.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct)
@@ -672,8 +671,8 @@ void AggExprEmitter::VisitLambdaExpr(LambdaExpr *E) {
672671
}
673672

674673
// Emit initialization
675-
LValue LV = CGF.buildLValueForFieldInitialization(
676-
SlotLV, *CurField, fieldName);
674+
LValue LV =
675+
CGF.buildLValueForFieldInitialization(SlotLV, *CurField, fieldName);
677676
if (CurField->hasCapturedVLAType()) {
678677
llvm_unreachable("NYI");
679678
}
@@ -820,8 +819,8 @@ void AggExprEmitter::withReturnValueSlot(
820819
if (!UseTemp) {
821820
RetAddr = Dest.getAddress();
822821
} else {
823-
RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()),
824-
"tmp", &RetAddr);
822+
RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()), "tmp",
823+
&RetAddr);
825824
assert(!UnimplementedFeature::shouldEmitLifetimeMarkers() && "NYI");
826825
}
827826

@@ -940,8 +939,8 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
940939
if (curInitIndex == NumInitElements && Dest.isZeroed() &&
941940
CGF.getTypes().isZeroInitializable(ExprToVisit->getType()))
942941
break;
943-
LValue LV = CGF.buildLValueForFieldInitialization(
944-
DestLV, field, field->getName());
942+
LValue LV =
943+
CGF.buildLValueForFieldInitialization(DestLV, field, field->getName());
945944
// We never generate write-barries for initialized fields.
946945
assert(!UnimplementedFeature::setNonGC());
947946

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ class ConstExprEmitter
907907
// Look through the temporary; it's just converting the value to an lvalue
908908
// to pass it to the constructor.
909909
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Arg))
910-
return Visit(MTE->getSubExpr(), Ty);
910+
return Visit(MTE->getSubExpr(), Ty);
911911
// Don't try to support arbitrary lvalue-to-rvalue conversions for now.
912912
return nullptr;
913913
}
@@ -1074,8 +1074,7 @@ class ConstantLValueEmitter
10741074
ConstantLValue applyOffset(ConstantLValue &C) {
10751075

10761076
// Handle attribute constant LValues.
1077-
if (auto Attr =
1078-
C.Value.dyn_cast<mlir::Attribute>()) {
1077+
if (auto Attr = C.Value.dyn_cast<mlir::Attribute>()) {
10791078
if (auto GV = Attr.dyn_cast<mlir::cir::GlobalViewAttr>()) {
10801079
auto baseTy = GV.getType().cast<mlir::cir::PointerType>().getPointee();
10811080
auto destTy = CGM.getTypes().convertTypeForMem(DestType);
@@ -1338,7 +1337,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
13381337
}
13391338
InConstantContext = D.hasConstantInitialization();
13401339

1341-
const Expr * E = D.getInit();
1340+
const Expr *E = D.getInit();
13421341
assert(E && "No initializer to emit");
13431342

13441343
QualType destType = D.getType();

0 commit comments

Comments
 (0)