Skip to content

Commit 3f66d51

Browse files
authored
[CIR][CIRGen] Move CIRGen types into clang::CIRGen (#1082)
#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 5eb371d commit 3f66d51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+671
-666
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/ABIInfo.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212
#include "clang/AST/Type.h"
1313

14-
namespace cir {
14+
namespace clang::CIRGen {
1515

16-
class ABIArgInfo;
1716
class CIRGenCXXABI;
1817
class CIRGenFunctionInfo;
1918
class CIRGenTypes;
@@ -42,6 +41,6 @@ class ABIInfo {
4241
bool isPromotableIntegerTypeForABI(clang::QualType Ty) const;
4342
};
4443

45-
} // namespace cir
44+
} // namespace clang::CIRGen
4645

4746
#endif

clang/lib/CIR/CodeGen/Address.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "mlir/IR/Value.h"
2323

24-
namespace cir {
24+
namespace clang::CIRGen {
2525

2626
// Indicates whether a pointer is known not to be null.
2727
enum KnownNonNull_t { NotKnownNonNull, KnownNonNull };
@@ -143,6 +143,6 @@ class Address {
143143
}
144144
};
145145

146-
} // namespace cir
146+
} // namespace clang::CIRGen
147147

148148
#endif // LLVM_CLANG_LIB_CIR_ADDRESS_H

clang/lib/CIR/CodeGen/CIRAsm.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include "TargetInfo.h"
66
#include "clang/CIR/MissingFeatures.h"
77

8-
using namespace cir;
98
using namespace clang;
9+
using namespace clang::CIRGen;
1010
using namespace mlir::cir;
1111

1212
static bool isAggregateType(mlir::Type typ) {
@@ -285,7 +285,7 @@ static void buildAsmStores(CIRGenFunction &CGF, const AsmStmt &S,
285285
mlir::Type TruncTy = ResultTruncRegTypes[i];
286286

287287
if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
288-
assert(!MissingFeatures::asmLLVMAssume());
288+
assert(!cir::MissingFeatures::asmLLVMAssume());
289289
}
290290

291291
// If the result type of the LLVM IR asm doesn't match the result type of
@@ -311,7 +311,7 @@ static void buildAsmStores(CIRGenFunction &CGF, const AsmStmt &S,
311311
} else if (isa<mlir::cir::IntType>(TruncTy)) {
312312
Tmp = Builder.createIntCast(Tmp, TruncTy);
313313
} else if (false /*TruncTy->isVectorTy()*/) {
314-
assert(!MissingFeatures::asmVectorType());
314+
assert(!cir::MissingFeatures::asmVectorType());
315315
}
316316
}
317317

@@ -468,7 +468,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
468468
}
469469

470470
// Update largest vector width for any vector types.
471-
assert(!MissingFeatures::asmVectorType());
471+
assert(!cir::MissingFeatures::asmVectorType());
472472
} else {
473473
Address DestAddr = Dest.getAddress();
474474

@@ -504,7 +504,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
504504
Arg = builder.createBitcast(Arg, AdjTy);
505505

506506
// Update largest vector width for any vector types.
507-
assert(!MissingFeatures::asmVectorType());
507+
assert(!cir::MissingFeatures::asmVectorType());
508508

509509
// Only tie earlyclobber physregs.
510510
if (Info.allowsRegister() && (GCCReg.empty() || Info.earlyClobber()))
@@ -521,7 +521,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
521521
// If this is a Microsoft-style asm blob, store the return registers (EAX:EDX)
522522
// to the return value slot. Only do this when returning in registers.
523523
if (isa<MSAsmStmt>(&S)) {
524-
const ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
524+
const cir::ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
525525
if (RetAI.isDirect() || RetAI.isExtend()) {
526526
// Make a fake lvalue for the return value slot.
527527
LValue ReturnSlot = makeAddrLValue(ReturnValue, FnRetTy);
@@ -593,7 +593,7 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
593593
<< InputExpr->getType() << InputConstraint;
594594

595595
// Update largest vector width for any vector types.
596-
assert(!MissingFeatures::asmVectorType());
596+
assert(!cir::MissingFeatures::asmVectorType());
597597

598598
ArgTypes.push_back(Arg.getType());
599599
ArgElemTypes.push_back(ArgElemType);
@@ -636,11 +636,11 @@ mlir::LogicalResult CIRGenFunction::buildAsmStmt(const AsmStmt &S) {
636636
HasSideEffect, inferFlavor(CGM, S), mlir::ArrayAttr());
637637

638638
if (false /*IsGCCAsmGoto*/) {
639-
assert(!MissingFeatures::asmGoto());
639+
assert(!cir::MissingFeatures::asmGoto());
640640
} else if (HasUnwindClobber) {
641-
assert(!MissingFeatures::asmUnwindClobber());
641+
assert(!cir::MissingFeatures::asmUnwindClobber());
642642
} else {
643-
assert(!MissingFeatures::asmMemoryEffects());
643+
assert(!cir::MissingFeatures::asmMemoryEffects());
644644

645645
mlir::Value result;
646646
if (IA.getNumResults())

clang/lib/CIR/CodeGen/CIRGenAtomic.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
#include "mlir/IR/BuiltinTypes.h"
3131
#include "mlir/IR/Value.h"
3232

33-
using namespace cir;
3433
using namespace clang;
34+
using namespace clang::CIRGen;
3535

3636
namespace {
3737
class AtomicInfo {
@@ -42,7 +42,7 @@ class AtomicInfo {
4242
uint64_t ValueSizeInBits;
4343
CharUnits AtomicAlign;
4444
CharUnits ValueAlign;
45-
TypeEvaluationKind EvaluationKind;
45+
cir::TypeEvaluationKind EvaluationKind;
4646
bool UseLibcall;
4747
LValue LVal;
4848
CIRGenBitFieldInfo BFI;
@@ -51,7 +51,7 @@ class AtomicInfo {
5151
public:
5252
AtomicInfo(CIRGenFunction &CGF, LValue &lvalue, mlir::Location l)
5353
: CGF(CGF), AtomicSizeInBits(0), ValueSizeInBits(0),
54-
EvaluationKind(TEK_Scalar), UseLibcall(true), loc(l) {
54+
EvaluationKind(cir::TEK_Scalar), UseLibcall(true), loc(l) {
5555
assert(!lvalue.isGlobalReg());
5656
ASTContext &C = CGF.getContext();
5757
if (lvalue.isSimple()) {
@@ -102,7 +102,7 @@ class AtomicInfo {
102102
CharUnits getAtomicAlignment() const { return AtomicAlign; }
103103
uint64_t getAtomicSizeInBits() const { return AtomicSizeInBits; }
104104
uint64_t getValueSizeInBits() const { return ValueSizeInBits; }
105-
TypeEvaluationKind getEvaluationKind() const { return EvaluationKind; }
105+
cir::TypeEvaluationKind getEvaluationKind() const { return EvaluationKind; }
106106
bool shouldUseLibcall() const { return UseLibcall; }
107107
const LValue &getAtomicLValue() const { return LVal; }
108108
mlir::Value getAtomicPointer() const {
@@ -287,13 +287,13 @@ bool AtomicInfo::requiresMemSetZero(mlir::Type ty) const {
287287
switch (getEvaluationKind()) {
288288
// For scalars and complexes, check whether the store size of the
289289
// type uses the full size.
290-
case TEK_Scalar:
290+
case cir::TEK_Scalar:
291291
return !isFullSizeType(CGF.CGM, ty, AtomicSizeInBits);
292-
case TEK_Complex:
292+
case cir::TEK_Complex:
293293
llvm_unreachable("NYI");
294294

295295
// Padding in structs has an undefined bit pattern. User beware.
296-
case TEK_Aggregate:
296+
case cir::TEK_Aggregate:
297297
return false;
298298
}
299299
llvm_unreachable("bad evaluation kind");
@@ -545,7 +545,7 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
545545
mlir::Value IsWeak, mlir::Value FailureOrder,
546546
uint64_t Size, mlir::cir::MemOrder Order,
547547
uint8_t Scope) {
548-
assert(!MissingFeatures::syncScopeID());
548+
assert(!cir::MissingFeatures::syncScopeID());
549549
StringRef Op;
550550

551551
auto &builder = CGF.getBuilder();
@@ -592,7 +592,7 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
592592
case AtomicExpr::AO__scoped_atomic_load: {
593593
auto *load = builder.createLoad(loc, Ptr).getDefiningOp();
594594
// FIXME(cir): add scope information.
595-
assert(!MissingFeatures::syncScopeID());
595+
assert(!cir::MissingFeatures::syncScopeID());
596596
load->setAttr("mem_order", orderAttr);
597597
if (E->isVolatile())
598598
load->setAttr("is_volatile", mlir::UnitAttr::get(builder.getContext()));
@@ -618,7 +618,7 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest,
618618
case AtomicExpr::AO__scoped_atomic_store_n: {
619619
auto loadVal1 = builder.createLoad(loc, Val1);
620620
// FIXME(cir): add scope information.
621-
assert(!MissingFeatures::syncScopeID());
621+
assert(!cir::MissingFeatures::syncScopeID());
622622
builder.createStore(loc, loadVal1, Ptr, E->isVolatile(),
623623
/*alignment=*/mlir::IntegerAttr{}, orderAttr);
624624
return;
@@ -791,15 +791,15 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *Expr, Address Dest,
791791
// LLVM atomic instructions always have synch scope. If clang atomic
792792
// expression has no scope operand, use default LLVM synch scope.
793793
if (!ScopeModel) {
794-
assert(!MissingFeatures::syncScopeID());
794+
assert(!cir::MissingFeatures::syncScopeID());
795795
buildAtomicOp(CGF, Expr, Dest, Ptr, Val1, Val2, IsWeak, FailureOrder, Size,
796796
Order, /*FIXME(cir): LLVM default scope*/ 1);
797797
return;
798798
}
799799

800800
// Handle constant scope.
801801
if (getConstOpIntAttr(Scope)) {
802-
assert(!MissingFeatures::syncScopeID());
802+
assert(!cir::MissingFeatures::syncScopeID());
803803
llvm_unreachable("NYI");
804804
return;
805805
}
@@ -1469,7 +1469,7 @@ void CIRGenFunction::buildAtomicStore(RValue rvalue, LValue dest,
14691469
store.setIsVolatile(true);
14701470

14711471
// DecorateInstructionWithTBAA
1472-
assert(!MissingFeatures::tbaa());
1472+
assert(!cir::MissingFeatures::tbaa());
14731473
return;
14741474
}
14751475

@@ -1480,18 +1480,18 @@ void CIRGenFunction::buildAtomicInit(Expr *init, LValue dest) {
14801480
AtomicInfo atomics(*this, dest, getLoc(init->getSourceRange()));
14811481

14821482
switch (atomics.getEvaluationKind()) {
1483-
case TEK_Scalar: {
1483+
case cir::TEK_Scalar: {
14841484
mlir::Value value = buildScalarExpr(init);
14851485
atomics.emitCopyIntoMemory(RValue::get(value));
14861486
return;
14871487
}
14881488

1489-
case TEK_Complex: {
1489+
case cir::TEK_Complex: {
14901490
llvm_unreachable("NYI");
14911491
return;
14921492
}
14931493

1494-
case TEK_Aggregate: {
1494+
case cir::TEK_Aggregate: {
14951495
// Fix up the destination if the initializer isn't an expression
14961496
// of atomic type.
14971497
llvm_unreachable("NYI");

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88
#include "CIRGenBuilder.h"
99

10-
namespace cir {
10+
using namespace clang::CIRGen;
1111

1212
mlir::Value CIRGenBuilderTy::maybeBuildArrayDecay(mlir::Location loc,
1313
mlir::Value arrayPtr,
@@ -67,4 +67,3 @@ mlir::cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
6767
return create<mlir::cir::ConstantOp>(loc, intTy,
6868
mlir::cir::IntAttr::get(t, C));
6969
}
70-
} // namespace cir

0 commit comments

Comments
 (0)