Skip to content

Enable the formatting workflow for llvm/clangir and format the files #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permissions:
jobs:
code_formatter:
runs-on: ubuntu-latest
if: github.repository == 'llvm/llvm-project'
if: github.repository == 'llvm/clangir'
steps:
- name: Fetch LLVM sources
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Interfaces/CallInterfaces.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/LoopLikeInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRTypesDetails.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- CIRTypesDetails.h - Details of CIR dialect types -----------*- C++ -*-===//
//===- CIRTypesDetails.h - Details of CIR dialect types ---------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRAsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {

AsmDialect AsmDialect = inferDialect(CGM, S);

builder.create<mlir::cir::InlineAsmOp>(
getLoc(S.getAsmLoc()), ResultType, AsmString, AsmDialect);
builder.create<mlir::cir::InlineAsmOp>(getLoc(S.getAsmLoc()), ResultType,
AsmString, AsmDialect);

return mlir::success();
}
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,10 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
return create<mlir::cir::StackSaveOp>(loc, ty);
}

mlir::cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v) {
mlir::cir::StackRestoreOp createStackRestore(mlir::Location loc,
mlir::Value v) {
return create<mlir::cir::StackRestoreOp>(loc, v);
}

};

} // namespace cir
Expand Down
10 changes: 4 additions & 6 deletions clang/lib/CIR/CodeGen/CIRGenCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ CIRGenFunction::buildCoroAllocBuiltinCall(mlir::Location loc) {

mlir::cir::FuncOp fnOp;
if (!builtin) {
fnOp = CGM.createCIRFunction(
loc, CGM.builtinCoroAlloc,
mlir::cir::FuncType::get({int32Ty}, boolTy),
/*FD=*/nullptr);
fnOp = CGM.createCIRFunction(loc, CGM.builtinCoroAlloc,
mlir::cir::FuncType::get({int32Ty}, boolTy),
/*FD=*/nullptr);
assert(fnOp && "should always succeed");
fnOp.setBuiltinAttr(mlir::UnitAttr::get(builder.getContext()));
} else
Expand All @@ -217,8 +216,7 @@ CIRGenFunction::buildCoroBeginBuiltinCall(mlir::Location loc,
if (!builtin) {
fnOp = CGM.createCIRFunction(
loc, CGM.builtinCoroBegin,
mlir::cir::FuncType::get({int32Ty, VoidPtrTy},
VoidPtrTy),
mlir::cir::FuncType::get({int32Ty, VoidPtrTy}, VoidPtrTy),
/*FD=*/nullptr);
assert(fnOp && "should always succeed");
fnOp.setBuiltinAttr(mlir::UnitAttr::get(builder.getContext()));
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ struct CallCleanupFunction final : EHScopeStack::Cleanup {
/// Push the standard destructor for the given type as
/// at least a normal cleanup.
void CIRGenFunction::pushDestroy(QualType::DestructionKind dtorKind,
Address addr, QualType type) {
Address addr, QualType type) {
assert(dtorKind && "cannot push destructor for trivial type");

CleanupKind cleanupKind = getCleanupKind(dtorKind);
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ Address CIRGenFunction::getAddrOfBitFieldStorage(LValue base,

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

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

if (CGM.LambdaFieldToName.count(field))
Expand Down Expand Up @@ -396,7 +396,7 @@ LValue CIRGenFunction::buildLValueForFieldInitialization(
if (!FieldType->isReferenceType())
return buildLValueForField(Base, Field);

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

Address V = buildAddrOfFieldStorage(*this, Base.getAddress(), Field,
Expand Down
71 changes: 35 additions & 36 deletions clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,36 @@ static bool isBlockVarRef(const Expr *E) {
// FIXME: pointer arithmetic?
return false;

// Check both sides of a conditional operator.
} else if (const AbstractConditionalOperator *op
= dyn_cast<AbstractConditionalOperator>(E)) {
return isBlockVarRef(op->getTrueExpr())
|| isBlockVarRef(op->getFalseExpr());

// OVEs are required to support BinaryConditionalOperators.
} else if (const OpaqueValueExpr *op
= dyn_cast<OpaqueValueExpr>(E)) {
// Check both sides of a conditional operator.
} else if (const AbstractConditionalOperator *op =
dyn_cast<AbstractConditionalOperator>(E)) {
return isBlockVarRef(op->getTrueExpr()) ||
isBlockVarRef(op->getFalseExpr());

// OVEs are required to support BinaryConditionalOperators.
} else if (const OpaqueValueExpr *op = dyn_cast<OpaqueValueExpr>(E)) {
if (const Expr *src = op->getSourceExpr())
return isBlockVarRef(src);

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

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

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

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

AggValueSlot EnsureSlot(mlir::Location loc, QualType T) {
if (!Dest.isIgnored()) return Dest;
if (!Dest.isIgnored())
return Dest;
return CGF.CreateAggTemp(T, loc, "agg.tmp.ensured");
}

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

if (isBlockVarRef(E->getLHS()) &&
E->getRHS()->HasSideEffects(CGF.getContext())) {
E->getRHS()->HasSideEffects(CGF.getContext())) {
llvm_unreachable("NYI");
}

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

// Codegen the RHS so that it stores directly into the LHS.
AggValueSlot lhsSlot = AggValueSlot::forLValue(
lhs, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers,
AggValueSlot::IsAliased, AggValueSlot::MayOverlap);
lhs, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers,
AggValueSlot::IsAliased, AggValueSlot::MayOverlap);

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

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

if (!Dest.isIgnored() && !Dest.isExternallyDestructed() &&
E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct)
CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Dest.getAddress(),
E->getType());
}
E->getType());
}

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

if (SrcValueKind == EVK_RValue) {
if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
llvm_unreachable("move assignment/move ctor for rvalue is NYI");
if (type.isNonTrivialToPrimitiveDestructiveMove() == QualType::PCK_Struct) {
llvm_unreachable("move assignment/move ctor for rvalue is NYI");
}
} else {
if (type.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct)
Expand Down Expand Up @@ -672,8 +671,8 @@ void AggExprEmitter::VisitLambdaExpr(LambdaExpr *E) {
}

// Emit initialization
LValue LV = CGF.buildLValueForFieldInitialization(
SlotLV, *CurField, fieldName);
LValue LV =
CGF.buildLValueForFieldInitialization(SlotLV, *CurField, fieldName);
if (CurField->hasCapturedVLAType()) {
llvm_unreachable("NYI");
}
Expand Down Expand Up @@ -820,8 +819,8 @@ void AggExprEmitter::withReturnValueSlot(
if (!UseTemp) {
RetAddr = Dest.getAddress();
} else {
RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()),
"tmp", &RetAddr);
RetAddr = CGF.CreateMemTemp(RetTy, CGF.getLoc(E->getSourceRange()), "tmp",
&RetAddr);
assert(!UnimplementedFeature::shouldEmitLifetimeMarkers() && "NYI");
}

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

Expand Down
7 changes: 3 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenExprConst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ class ConstExprEmitter
// Look through the temporary; it's just converting the value to an lvalue
// to pass it to the constructor.
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Arg))
return Visit(MTE->getSubExpr(), Ty);
return Visit(MTE->getSubExpr(), Ty);
// Don't try to support arbitrary lvalue-to-rvalue conversions for now.
return nullptr;
}
Expand Down Expand Up @@ -1074,8 +1074,7 @@ class ConstantLValueEmitter
ConstantLValue applyOffset(ConstantLValue &C) {

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

const Expr * E = D.getInit();
const Expr *E = D.getInit();
assert(E && "No initializer to emit");

QualType destType = D.getType();
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ class CIRGenFunction : public CIRGenTypeCache {
/// Create a check for a function parameter that may potentially be
/// declared as non-null.
void buildNonNullArgCheck(RValue RV, QualType ArgType, SourceLocation ArgLoc,
AbstractCallee AC, unsigned ParmNum);
AbstractCallee AC, unsigned ParmNum);

void buildCallArg(CallArgList &args, const clang::Expr *E,
clang::QualType ArgType);
Expand Down Expand Up @@ -1362,7 +1362,7 @@ class CIRGenFunction : public CIRGenTypeCache {
AggValueSlot::Overlap_t getOverlapForFieldInit(const FieldDecl *FD);
LValue buildLValueForField(LValue Base, const clang::FieldDecl *Field);
LValue buildLValueForBitField(LValue base, const FieldDecl *field);

/// Like buildLValueForField, excpet that if the Field is a reference, this
/// will return the address of the reference and not the address of the value
/// stored in the reference.
Expand Down Expand Up @@ -1520,8 +1520,8 @@ class CIRGenFunction : public CIRGenTypeCache {

static Destroyer destroyCXXObject;

void pushDestroy(QualType::DestructionKind dtorKind,
Address addr, QualType type);
void pushDestroy(QualType::DestructionKind dtorKind, Address addr,
QualType type);

void pushDestroy(CleanupKind kind, Address addr, QualType type,
Destroyer *destroyer, bool useEHCleanupForArray);
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
const clang::CodeGenOptions &CGO,
DiagnosticsEngine &Diags)
: builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
codeGenOpts(CGO), theModule{mlir::ModuleOp::create(
builder.getUnknownLoc())},
Diags(Diags), target(astCtx.getTargetInfo()),
ABI(createCXXABI(*this)), genTypes{*this}, VTables{*this} {
codeGenOpts(CGO),
theModule{mlir::ModuleOp::create(builder.getUnknownLoc())}, Diags(Diags),
target(astCtx.getTargetInfo()), ABI(createCXXABI(*this)), genTypes{*this},
VTables{*this} {

// Initialize CIR signed integer types cache.
SInt8Ty =
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class CIRGenModule : public CIRGenTypeCache {

mlir::cir::GlobalOp
getOrCreateStaticVarDecl(const VarDecl &D,
mlir::cir::GlobalLinkageKind Linkage);
mlir::cir::GlobalLinkageKind Linkage);

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

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

CharUnits
computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass,
Expand Down Expand Up @@ -509,7 +509,7 @@ class CIRGenModule : public CIRGenTypeCache {

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

void addDeferredVTable(const CXXRecordDecl *RD) {
DeferredVTables.push_back(RD);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ mlir::Type CIRGenTypes::ConvertType(QualType T) {
SkippedLayout = true;
ResultType = Builder.getUInt8Ty();
}
ResultType = Builder.getArrayType(ResultType, 0);
ResultType = Builder.getArrayType(ResultType, 0);
break;
}
case Type::ConstantArray: {
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/CIR/CodeGen/CIRGenVTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,7 @@ getAddrOfVTTVTable(CIRGenVTables &CGVT, CIRGenModule &CGM,
llvm_unreachable("generateConstructionVTable NYI");
}

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

SmallString<256> OutName;
Expand Down
Loading