Skip to content

Commit 3aae8fd

Browse files
philnik777lanza
authored andcommitted
[CIR][NFC] Enable the formatting workflow for llvm/clangir and format the files (#390)
Fixes #345
1 parent 52575fe commit 3aae8fd

22 files changed

+143
-159
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
jobs:
1212
code_formatter:
1313
runs-on: ubuntu-latest
14-
if: github.repository == 'llvm/llvm-project'
14+
if: github.repository == 'llvm/clangir'
1515
steps:
1616
- name: Fetch LLVM sources
1717
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/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)
@@ -675,8 +674,8 @@ void AggExprEmitter::VisitLambdaExpr(LambdaExpr *E) {
675674
}
676675

677676
// Emit initialization
678-
LValue LV = CGF.buildLValueForFieldInitialization(
679-
SlotLV, *CurField, fieldName);
677+
LValue LV =
678+
CGF.buildLValueForFieldInitialization(SlotLV, *CurField, fieldName);
680679
if (CurField->hasCapturedVLAType()) {
681680
llvm_unreachable("NYI");
682681
}
@@ -823,8 +822,8 @@ void AggExprEmitter::withReturnValueSlot(
823822
if (!UseTemp) {
824823
RetAddr = Dest.getAddress();
825824
} else {
826-
RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()),
827-
"tmp", &RetAddr);
825+
RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()), "tmp",
826+
&RetAddr);
828827
assert(!UnimplementedFeature::shouldEmitLifetimeMarkers() && "NYI");
829828
}
830829

@@ -943,8 +942,8 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
943942
if (curInitIndex == NumInitElements && Dest.isZeroed() &&
944943
CGF.getTypes().isZeroInitializable(ExprToVisit->getType()))
945944
break;
946-
LValue LV = CGF.buildLValueForFieldInitialization(
947-
DestLV, field, field->getName());
945+
LValue LV =
946+
CGF.buildLValueForFieldInitialization(DestLV, field, field->getName());
948947
// We never generate write-barries for initialized fields.
949948
assert(!UnimplementedFeature::setNonGC());
950949

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

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

10791079
// Handle attribute constant LValues.
1080-
if (auto Attr =
1081-
C.Value.dyn_cast<mlir::Attribute>()) {
1080+
if (auto Attr = C.Value.dyn_cast<mlir::Attribute>()) {
10821081
if (auto GV = Attr.dyn_cast<mlir::cir::GlobalViewAttr>()) {
10831082
auto baseTy = GV.getType().cast<mlir::cir::PointerType>().getPointee();
10841083
auto destTy = CGM.getTypes().convertTypeForMem(DestType);
@@ -1341,7 +1340,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &D) {
13411340
}
13421341
InConstantContext = D.hasConstantInitialization();
13431342

1344-
const Expr * E = D.getInit();
1343+
const Expr *E = D.getInit();
13451344
assert(E && "No initializer to emit");
13461345

13471346
QualType destType = D.getType();

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ class CIRGenFunction : public CIRGenTypeCache {
771771
/// Create a check for a function parameter that may potentially be
772772
/// declared as non-null.
773773
void buildNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc,
774-
AbstractCallee AC, unsigned ParmNum);
774+
AbstractCallee AC, unsigned ParmNum);
775775

776776
void buildCallArg(CallArgList &args, const clang::Expr *E,
777777
clang::QualType ArgType);
@@ -1362,7 +1362,7 @@ class CIRGenFunction : public CIRGenTypeCache {
13621362
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD);
13631363
LValue buildLValueForField(LValue Base, const clang::FieldDecl *Field);
13641364
LValue buildLValueForBitField(LValue base, const FieldDecl *field);
1365-
1365+
13661366
/// Like buildLValueForField, excpet that if the Field is a reference, this
13671367
/// will return the address of the reference and not the address of the value
13681368
/// stored in the reference.
@@ -1520,8 +1520,8 @@ class CIRGenFunction : public CIRGenTypeCache {
15201520

15211521
static Destroyer destroyCXXObject;
15221522

1523-
void pushDestroy(QualType::DestructionKind dtorKind,
1524-
Address addr, QualType type);
1523+
void pushDestroy(QualType::DestructionKind dtorKind, Address addr,
1524+
QualType type);
15251525

15261526
void pushDestroy(CleanupKind kind, Address addr, QualType type,
15271527
Destroyer *destroyer, bool useEHCleanupForArray);

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
100100
const clang::CodeGenOptions &CGO,
101101
DiagnosticsEngine &Diags)
102102
: builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
103-
codeGenOpts(CGO), theModule{mlir::ModuleOp::create(
104-
builder.getUnknownLoc())},
105-
Diags(Diags), target(astCtx.getTargetInfo()),
106-
ABI(createCXXABI(*this)), genTypes{*this}, VTables{*this} {
103+
codeGenOpts(CGO),
104+
theModule{mlir::ModuleOp::create(builder.getUnknownLoc())}, Diags(Diags),
105+
target(astCtx.getTargetInfo()), ABI(createCXXABI(*this)), genTypes{*this},
106+
VTables{*this} {
107107

108108
// Initialize CIR signed integer types cache.
109109
SInt8Ty =

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class CIRGenModule : public CIRGenTypeCache {
196196

197197
mlir::cir::GlobalOp
198198
getOrCreateStaticVarDecl(const VarDecl &D,
199-
mlir::cir::GlobalLinkageKind Linkage);
199+
mlir::cir::GlobalLinkageKind Linkage);
200200

201201
mlir::cir::GlobalOp buildGlobal(const VarDecl *D, mlir::Type Ty,
202202
ForDefinition_t IsForDefinition);
@@ -239,7 +239,7 @@ class CIRGenModule : public CIRGenTypeCache {
239239
ForDefinition_t IsForDefinition = NotForDefinition);
240240

241241
/// Get a reference to the target of VD.
242-
mlir::Operation* getWeakRefReference(const ValueDecl *VD);
242+
mlir::Operation *getWeakRefReference(const ValueDecl *VD);
243243

244244
CharUnits
245245
computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
@@ -509,7 +509,7 @@ class CIRGenModule : public CIRGenTypeCache {
509509

510510
/// Emit the function that initializes the specified global
511511
void buildGlobalVarDeclInit(const VarDecl *D, mlir::cir::GlobalOp Addr,
512-
bool PerformInit);
512+
bool PerformInit);
513513

514514
void addDeferredVTable(const CXXRecordDecl *RD) {
515515
DeferredVTables.push_back(RD);

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ mlir::Type CIRGenTypes::ConvertType(QualType T) {
634634
SkippedLayout = true;
635635
ResultType = Builder.getUInt8Ty();
636636
}
637-
ResultType = Builder.getArrayType(ResultType, 0);
637+
ResultType = Builder.getArrayType(ResultType, 0);
638638
break;
639639
}
640640
case Type::ConstantArray: {

clang/lib/CIR/CodeGen/CIRGenVTables.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ getAddrOfVTTVTable(CIRGenVTables &CGVT, CIRGenModule &CGM,
434434
llvm_unreachable("generateConstructionVTable NYI");
435435
}
436436

437-
mlir::cir::GlobalOp CIRGenVTables::getAddrOfVTT(const CXXRecordDecl *RD)
438-
{
437+
mlir::cir::GlobalOp CIRGenVTables::getAddrOfVTT(const CXXRecordDecl *RD) {
439438
assert(RD->getNumVBases() && "Only classes with virtual bases need a VTT");
440439

441440
SmallString<256> OutName;

0 commit comments

Comments
 (0)