Skip to content

Commit ae4807d

Browse files
smeenaixlauko
authored andcommitted
[CIR][CIRGen] Move CIRGen types into clang::CIRGen (llvm#1082)
llvm/clangir#1025 explains why we want to move the CIR dialect from the `mlir::cir` to the `cir` namespace. To avoid overloading the `cir` namespace too much afterwards, move all symbols whose equivalents live inside the `clang::CodeGen` namespace to a new `clang::CIRGen` namespace, so that we match the original CodeGen's structure more closely. There's some symbols that live under `clang/include/clang/CIR` whose equivalents live in `clang/lib/CodeGen` and are in the `clang::CodeGen` namespace. We have these symbols in a common location since they're also used by lowering, so I've also left them in the `cir` namespace. Those symbols are: - AArch64ABIKind - ABIArgInfo - FnInfoOpts - TypeEvaluationKind - X86AVXABILevel This is a pretty large PR out of necessity. To make it slightly more reviewable, I've split it out into three commits (which will be squashed together when the PR lands): - The first commit manually switches places to the `clang::CIRGen` namespace. This has to be manual because we only want to move things selectively. - The second commit adjusts namespace prefixes to make builds work. I ran https://gist.github.com/smeenai/f4dd441fb61c53e835c4e6057f8c322f to make this change. The script is idempotent, and I added substitutions one at a time and reviewed each one afterwards (using `git diff --color-words=.`) to ensure only intended changes were being made. - The third commit runs `git clang-format`. Because I went one-by-one with all my substitutions and checked each one afterwards, I'm pretty confident in the validity of all the changes (despite the size of the PR).
1 parent db950e2 commit ae4807d

26 files changed

+199
-196
lines changed

clang/include/clang/CIR/CIRGenerator.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ namespace clang {
3434
class ASTContext;
3535
class DeclGroupRef;
3636
class FunctionDecl;
37-
} // namespace clang
3837

39-
namespace cir {
38+
namespace CIRGen {
4039
class CIRGenModule;
4140
class CIRGenTypes;
41+
} // namespace CIRGen
42+
} // namespace clang
4243

44+
namespace cir {
4345
class CIRGenerator : public clang::ASTConsumer {
4446
virtual void anchor();
4547
clang::DiagnosticsEngine &Diags;
@@ -70,7 +72,7 @@ class CIRGenerator : public clang::ASTConsumer {
7072

7173
protected:
7274
std::unique_ptr<mlir::MLIRContext> mlirCtx;
73-
std::unique_ptr<CIRGenModule> CGM;
75+
std::unique_ptr<clang::CIRGen::CIRGenModule> CGM;
7476

7577
private:
7678
llvm::SmallVector<clang::FunctionDecl *, 8> DeferredInlineMemberFuncDefs;

clang/lib/CIR/CodeGen/CIRAsm.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &S) {
699699
}
700700

701701
// Update largest vector width for any vector types.
702-
assert(!MissingFeatures::asmVectorType());
702+
assert(!cir::MissingFeatures::asmVectorType());
703703
} else {
704704
Address DestAddr = Dest.getAddress();
705705

@@ -735,7 +735,7 @@ mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &S) {
735735
Arg = builder.createBitcast(Arg, AdjTy);
736736

737737
// Update largest vector width for any vector types.
738-
assert(!MissingFeatures::asmVectorType());
738+
assert(!cir::MissingFeatures::asmVectorType());
739739

740740
// Only tie earlyclobber physregs.
741741
if (Info.allowsRegister() && (GCCReg.empty() || Info.earlyClobber()))
@@ -752,7 +752,7 @@ mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &S) {
752752
// If this is a Microsoft-style asm blob, store the return registers (EAX:EDX)
753753
// to the return value slot. Only do this when returning in registers.
754754
if (isa<MSAsmStmt>(&S)) {
755-
const ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
755+
const cir::ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
756756
if (RetAI.isDirect() || RetAI.isExtend()) {
757757
// Make a fake lvalue for the return value slot.
758758
LValue ReturnSlot = makeAddrLValue(ReturnValue, FnRetTy);
@@ -824,7 +824,7 @@ mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &S) {
824824
<< InputExpr->getType() << InputConstraint;
825825

826826
// Update largest vector width for any vector types.
827-
assert(!MissingFeatures::asmVectorType());
827+
assert(!cir::MissingFeatures::asmVectorType());
828828

829829
ArgTypes.push_back(Arg.getType());
830830
ArgElemTypes.push_back(ArgElemType);

clang/lib/CIR/CodeGen/CIRGenBuilder.h

+27-27
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
#include <string>
4444
#include <utility>
4545

46-
namespace cir {
46+
namespace clang::CIRGen {
4747

4848
class CIRGenFunction;
4949

50-
class CIRGenBuilderTy : public CIRBaseBuilderTy {
50+
class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
5151
const CIRGenTypeCache &typeCache;
5252
bool IsFPConstrained = false;
53-
fp::ExceptionBehavior DefaultConstrainedExcept = fp::ebStrict;
53+
cir::fp::ExceptionBehavior DefaultConstrainedExcept = cir::fp::ebStrict;
5454
llvm::RoundingMode DefaultConstrainedRounding = llvm::RoundingMode::Dynamic;
5555

5656
llvm::StringMap<unsigned> GlobalsVersioning;
@@ -96,10 +96,10 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
9696
}
9797

9898
/// Set the exception handling to be used with constrained floating point
99-
void setDefaultConstrainedExcept(fp::ExceptionBehavior NewExcept) {
99+
void setDefaultConstrainedExcept(cir::fp::ExceptionBehavior NewExcept) {
100100
#ifndef NDEBUG
101101
std::optional<llvm::StringRef> ExceptStr =
102-
convertExceptionBehaviorToStr(NewExcept);
102+
cir::convertExceptionBehaviorToStr(NewExcept);
103103
assert(ExceptStr && "Garbage strict exception behavior!");
104104
#endif
105105
DefaultConstrainedExcept = NewExcept;
@@ -109,14 +109,14 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
109109
void setDefaultConstrainedRounding(llvm::RoundingMode NewRounding) {
110110
#ifndef NDEBUG
111111
std::optional<llvm::StringRef> RoundingStr =
112-
convertRoundingModeToStr(NewRounding);
112+
cir::convertRoundingModeToStr(NewRounding);
113113
assert(RoundingStr && "Garbage strict rounding mode!");
114114
#endif
115115
DefaultConstrainedRounding = NewRounding;
116116
}
117117

118118
/// Get the exception handling used with constrained floating point
119-
fp::ExceptionBehavior getDefaultConstrainedExcept() {
119+
cir::fp::ExceptionBehavior getDefaultConstrainedExcept() {
120120
return DefaultConstrainedExcept;
121121
}
122122

@@ -422,7 +422,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
422422
// FIXME: replay LLVM codegen for now, perhaps add a vtable ptr special
423423
// type so it's a bit more clear and C++ idiomatic.
424424
auto fnTy = mlir::cir::FuncType::get({}, getUInt32Ty(), isVarArg);
425-
assert(!MissingFeatures::isVarArg());
425+
assert(!cir::MissingFeatures::isVarArg());
426426
return getPointerTo(getPointerTo(fnTy));
427427
}
428428

@@ -657,30 +657,30 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
657657
}
658658

659659
mlir::Value createFSub(mlir::Value lhs, mlir::Value rhs) {
660-
assert(!MissingFeatures::metaDataNode());
660+
assert(!cir::MissingFeatures::metaDataNode());
661661
if (IsFPConstrained)
662662
llvm_unreachable("Constrained FP NYI");
663663

664-
assert(!MissingFeatures::foldBinOpFMF());
664+
assert(!cir::MissingFeatures::foldBinOpFMF());
665665
return create<mlir::cir::BinOp>(lhs.getLoc(), mlir::cir::BinOpKind::Sub,
666666
lhs, rhs);
667667
}
668668

669669
mlir::Value createFAdd(mlir::Value lhs, mlir::Value rhs) {
670-
assert(!MissingFeatures::metaDataNode());
670+
assert(!cir::MissingFeatures::metaDataNode());
671671
if (IsFPConstrained)
672672
llvm_unreachable("Constrained FP NYI");
673673

674-
assert(!MissingFeatures::foldBinOpFMF());
674+
assert(!cir::MissingFeatures::foldBinOpFMF());
675675
return create<mlir::cir::BinOp>(lhs.getLoc(), mlir::cir::BinOpKind::Add,
676676
lhs, rhs);
677677
}
678678
mlir::Value createFMul(mlir::Value lhs, mlir::Value rhs) {
679-
assert(!MissingFeatures::metaDataNode());
679+
assert(!cir::MissingFeatures::metaDataNode());
680680
if (IsFPConstrained)
681681
llvm_unreachable("Constrained FP NYI");
682682

683-
assert(!MissingFeatures::foldBinOpFMF());
683+
assert(!cir::MissingFeatures::foldBinOpFMF());
684684
return create<mlir::cir::BinOp>(lhs.getLoc(), mlir::cir::BinOpKind::Mul,
685685
lhs, rhs);
686686
}
@@ -697,16 +697,16 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
697697
mlir::Value createDynCastToVoid(mlir::Location loc, mlir::Value src,
698698
bool vtableUseRelativeLayout) {
699699
// TODO(cir): consider address space here.
700-
assert(!MissingFeatures::addressSpace());
700+
assert(!cir::MissingFeatures::addressSpace());
701701
auto destTy = getVoidPtrTy();
702702
return create<mlir::cir::DynamicCastOp>(
703703
loc, destTy, mlir::cir::DynamicCastKind::ptr, src,
704704
mlir::cir::DynamicCastInfoAttr{}, vtableUseRelativeLayout);
705705
}
706706

707-
cir::Address createBaseClassAddr(mlir::Location loc, cir::Address addr,
708-
mlir::Type destType, unsigned offset,
709-
bool assumeNotNull) {
707+
Address createBaseClassAddr(mlir::Location loc, Address addr,
708+
mlir::Type destType, unsigned offset,
709+
bool assumeNotNull) {
710710
if (destType == addr.getElementType())
711711
return addr;
712712

@@ -716,9 +716,9 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
716716
return Address(baseAddr, ptrTy, addr.getAlignment());
717717
}
718718

719-
cir::Address createDerivedClassAddr(mlir::Location loc, cir::Address addr,
720-
mlir::Type destType, unsigned offset,
721-
bool assumeNotNull) {
719+
Address createDerivedClassAddr(mlir::Location loc, Address addr,
720+
mlir::Type destType, unsigned offset,
721+
bool assumeNotNull) {
722722
if (destType == addr.getElementType())
723723
return addr;
724724

@@ -833,8 +833,8 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
833833

834834
/// Cast the element type of the given address to a different type,
835835
/// preserving information like the alignment.
836-
cir::Address createElementBitCast(mlir::Location loc, cir::Address addr,
837-
mlir::Type destType) {
836+
Address createElementBitCast(mlir::Location loc, Address addr,
837+
mlir::Type destType) {
838838
if (destType == addr.getElementType())
839839
return addr;
840840

@@ -869,7 +869,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
869869
mlir::Value createAlignedLoad(mlir::Location loc, mlir::Type ty,
870870
mlir::Value ptr, llvm::MaybeAlign align) {
871871
// TODO: make sure callsites shouldn't be really passing volatile.
872-
assert(!MissingFeatures::volatileLoadOrStore());
872+
assert(!cir::MissingFeatures::volatileLoadOrStore());
873873
return createAlignedLoad(loc, ty, ptr, align, /*isVolatile=*/false);
874874
}
875875

@@ -942,7 +942,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
942942
// but currently some parts of Clang AST, which we don't want to touch just
943943
// yet, return them.
944944
void computeGlobalViewIndicesFromFlatOffset(
945-
int64_t Offset, mlir::Type Ty, CIRDataLayout Layout,
945+
int64_t Offset, mlir::Type Ty, cir::CIRDataLayout Layout,
946946
llvm::SmallVectorImpl<int64_t> &Indices) {
947947
if (!Offset)
948948
return;
@@ -1046,7 +1046,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
10461046
mlir::cast<mlir::cir::DataMemberType>(memberPtr.getType());
10471047

10481048
// TODO(cir): consider address space.
1049-
assert(!MissingFeatures::addressSpace());
1049+
assert(!cir::MissingFeatures::addressSpace());
10501050
auto resultTy = getPointerTo(memberPtrTy.getMemberTy());
10511051

10521052
return create<mlir::cir::GetRuntimeMemberOp>(loc, resultTy, objectPtr,
@@ -1067,5 +1067,5 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
10671067
mlir::Type eltTy);
10681068
};
10691069

1070-
} // namespace cir
1070+
} // namespace clang::CIRGen
10711071
#endif

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static mlir::Value tryUseTestFPKind(CIRGenFunction &CGF, unsigned BuiltinID,
6565
static mlir::Value tryUseTestFPKind(CIRGenFunction &CGF, unsigned BuiltinID,
6666
mlir::Value V) {
6767
if (CGF.getBuilder().getIsFPConstrained() &&
68-
CGF.getBuilder().getDefaultConstrainedExcept() != fp::ebIgnore) {
68+
CGF.getBuilder().getDefaultConstrainedExcept() != cir::fp::ebIgnore) {
6969
if (mlir::Value Result = CGF.getTargetHooks().testFPKind(
7070
V, BuiltinID, CGF.getBuilder(), CGF.CGM))
7171
return Result;
@@ -2507,7 +2507,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
25072507

25082508
case Builtin::BI__builtin_unpredictable: {
25092509
if (CGM.getCodeGenOpts().OptimizationLevel != 0)
2510-
assert(!MissingFeatures::insertBuiltinUnpredictable());
2510+
assert(!cir::MissingFeatures::insertBuiltinUnpredictable());
25112511
return RValue::get(buildScalarExpr(E->getArg(0)));
25122512
}
25132513

@@ -3266,7 +3266,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
32663266
// default (e.g. in C / C++ auto vars are in the generic address space). At
32673267
// the AST level this is handled within CreateTempAlloca et al., but for the
32683268
// builtin / dynamic alloca we have to handle it here.
3269-
assert(!MissingFeatures::addressSpace());
3269+
assert(!cir::MissingFeatures::addressSpace());
32703270
auto AAS = getCIRAllocaAddressSpace();
32713271
auto EAS = builder.getAddrSpaceAttr(
32723272
E->getType()->getPointeeType().getAddressSpace());

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -3291,13 +3291,13 @@ mlir::Value buildNeonCall(CIRGenBuilderTy &builder,
32913291
unsigned shift = 0, bool rightshift = false) {
32923292
// TODO: Consider removing the following unreachable when we have
32933293
// buildConstrainedFPCall feature implemented
3294-
assert(!MissingFeatures::buildConstrainedFPCall());
3294+
assert(!cir::MissingFeatures::buildConstrainedFPCall());
32953295
if (isConstrainedFPIntrinsic)
32963296
llvm_unreachable("isConstrainedFPIntrinsic NYI");
32973297

32983298
for (unsigned j = 0; j < argTypes.size(); ++j) {
32993299
if (isConstrainedFPIntrinsic) {
3300-
assert(!MissingFeatures::buildConstrainedFPCall());
3300+
assert(!cir::MissingFeatures::buildConstrainedFPCall());
33013301
}
33023302
if (shift > 0 && shift == j) {
33033303
args[j] = buildNeonShiftVector(
@@ -3308,7 +3308,7 @@ mlir::Value buildNeonCall(CIRGenBuilderTy &builder,
33083308
}
33093309
}
33103310
if (isConstrainedFPIntrinsic) {
3311-
assert(!MissingFeatures::buildConstrainedFPCall());
3311+
assert(!cir::MissingFeatures::buildConstrainedFPCall());
33123312
return nullptr;
33133313
}
33143314
return builder
@@ -3345,8 +3345,8 @@ buildCommonNeonCallPattern0(CIRGenFunction &cgf, llvm::StringRef intrincsName,
33453345
mlir::Value CIRGenFunction::buildCommonNeonBuiltinExpr(
33463346
unsigned builtinID, unsigned llvmIntrinsic, unsigned altLLVMIntrinsic,
33473347
const char *nameHint, unsigned modifier, const CallExpr *e,
3348-
llvm::SmallVectorImpl<mlir::Value> &ops, cir::Address ptrOp0,
3349-
cir::Address ptrOp1, llvm::Triple::ArchType arch) {
3348+
llvm::SmallVectorImpl<mlir::Value> &ops, Address ptrOp0, Address ptrOp1,
3349+
llvm::Triple::ArchType arch) {
33503350
// Get the last argument, which specifies the vector type.
33513351
const clang::Expr *arg = e->getArg(e->getNumArgs() - 1);
33523352
std::optional<llvm::APSInt> neonTypeConst =

clang/lib/CIR/CodeGen/CIRGenCall.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ CIRGenTypes::arrangeFreeFunctionType(CanQual<FunctionNoProtoType> FTNP) {
13511351
// When translating an unprototyped function type, always use a
13521352
// variadic type.
13531353
return arrangeCIRFunctionInfo(FTNP->getReturnType().getUnqualifiedType(),
1354-
FnInfoOpts::None, std::nullopt,
1354+
cir::FnInfoOpts::None, std::nullopt,
13551355
FTNP->getExtInfo(), {}, RequiredArgs(0));
13561356
}
13571357

0 commit comments

Comments
 (0)