Skip to content

Commit 88b1d08

Browse files
committed
Revert "[CIR] Infrastructure: class CIRGenBuilderTy; cache CIR types (llvm#119037)"
This reverts commit ffb19f4.
1 parent 4195345 commit 88b1d08

File tree

7 files changed

+22
-121
lines changed

7 files changed

+22
-121
lines changed

Diff for: clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

-25
This file was deleted.

Diff for: clang/lib/CIR/CodeGen/CIRGenBuilder.h

-28
This file was deleted.

Diff for: clang/lib/CIR/CodeGen/CIRGenModule.cpp

+2-15
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,9 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
2929
clang::ASTContext &astctx,
3030
const clang::CodeGenOptions &cgo,
3131
DiagnosticsEngine &diags)
32-
: builder(context, *this), astCtx(astctx), langOpts(astctx.getLangOpts()),
32+
: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
3333
theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
34-
diags(diags), target(astctx.getTargetInfo()), genTypes(*this) {
35-
36-
// Initialize cached types
37-
SInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/true);
38-
SInt16Ty = cir::IntType::get(&getMLIRContext(), 16, /*isSigned=*/true);
39-
SInt32Ty = cir::IntType::get(&getMLIRContext(), 32, /*isSigned=*/true);
40-
SInt64Ty = cir::IntType::get(&getMLIRContext(), 64, /*isSigned=*/true);
41-
SInt128Ty = cir::IntType::get(&getMLIRContext(), 128, /*isSigned=*/true);
42-
UInt8Ty = cir::IntType::get(&getMLIRContext(), 8, /*isSigned=*/false);
43-
UInt16Ty = cir::IntType::get(&getMLIRContext(), 16, /*isSigned=*/false);
44-
UInt32Ty = cir::IntType::get(&getMLIRContext(), 32, /*isSigned=*/false);
45-
UInt64Ty = cir::IntType::get(&getMLIRContext(), 64, /*isSigned=*/false);
46-
UInt128Ty = cir::IntType::get(&getMLIRContext(), 128, /*isSigned=*/false);
47-
}
34+
diags(diags), target(astCtx.getTargetInfo()), genTypes(*this) {}
4835

4936
mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
5037
assert(cLoc.isValid() && "expected valid source location");

Diff for: clang/lib/CIR/CodeGen/CIRGenModule.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
1414
#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
1515

16-
#include "CIRGenBuilder.h"
1716
#include "CIRGenTypeCache.h"
1817
#include "CIRGenTypes.h"
1918

@@ -48,7 +47,9 @@ class CIRGenModule : public CIRGenTypeCache {
4847
~CIRGenModule() = default;
4948

5049
private:
51-
CIRGenBuilderTy builder;
50+
// TODO(CIR) 'builder' will change to CIRGenBuilderTy once that type is
51+
// defined
52+
mlir::OpBuilder builder;
5253

5354
/// Hold Clang AST information.
5455
clang::ASTContext &astCtx;
@@ -66,10 +67,9 @@ class CIRGenModule : public CIRGenTypeCache {
6667

6768
public:
6869
mlir::ModuleOp getModule() const { return theModule; }
69-
CIRGenBuilderTy &getBuilder() { return builder; }
70+
mlir::OpBuilder &getBuilder() { return builder; }
7071
clang::ASTContext &getASTContext() const { return astCtx; }
7172
CIRGenTypes &getTypes() { return genTypes; }
72-
mlir::MLIRContext &getMLIRContext() { return *builder.getContext(); }
7373

7474
/// Helpers to convert the presumed location of Clang's SourceLocation to an
7575
/// MLIR Location.

Diff for: clang/lib/CIR/CodeGen/CIRGenTypeCache.h

-16
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,13 @@
1313
#ifndef LLVM_CLANG_LIB_CIR_CIRGENTYPECACHE_H
1414
#define LLVM_CLANG_LIB_CIR_CIRGENTYPECACHE_H
1515

16-
#include "clang/CIR/Dialect/IR/CIRTypes.h"
17-
1816
namespace clang::CIRGen {
1917

2018
/// This structure provides a set of types that are commonly used
2119
/// during IR emission. It's initialized once in CodeGenModule's
2220
/// constructor and then copied around into new CIRGenFunction's.
2321
struct CIRGenTypeCache {
2422
CIRGenTypeCache() = default;
25-
26-
// ClangIR signed integral types of common sizes
27-
cir::IntType SInt8Ty;
28-
cir::IntType SInt16Ty;
29-
cir::IntType SInt32Ty;
30-
cir::IntType SInt64Ty;
31-
cir::IntType SInt128Ty;
32-
33-
// ClangIR unsigned integral type of common sizes
34-
cir::IntType UInt8Ty;
35-
cir::IntType UInt16Ty;
36-
cir::IntType UInt32Ty;
37-
cir::IntType UInt64Ty;
38-
cir::IntType UInt128Ty;
3923
};
4024

4125
} // namespace clang::CIRGen

Diff for: clang/lib/CIR/CodeGen/CIRGenTypes.cpp

+16-21
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,22 @@ using namespace clang;
99
using namespace clang::CIRGen;
1010

1111
CIRGenTypes::CIRGenTypes(CIRGenModule &genModule)
12-
: cgm(genModule), context(genModule.getASTContext()),
13-
builder(cgm.getBuilder()) {}
12+
: cgm(genModule), context(genModule.getASTContext()) {}
1413

1514
CIRGenTypes::~CIRGenTypes() {}
1615

17-
mlir::MLIRContext &CIRGenTypes::getMLIRContext() const {
18-
return *builder.getContext();
19-
}
20-
2116
mlir::Type CIRGenTypes::convertType(QualType type) {
2217
type = context.getCanonicalType(type);
2318
const Type *ty = type.getTypePtr();
2419

25-
// Has the type already been processed?
26-
TypeCacheTy::iterator tci = typeCache.find(ty);
27-
if (tci != typeCache.end())
28-
return tci->second;
29-
3020
// For types that haven't been implemented yet or are otherwise unsupported,
3121
// report an error and return 'int'.
3222

3323
mlir::Type resultType = nullptr;
3424
switch (ty->getTypeClass()) {
3525
case Type::Builtin: {
3626
switch (cast<BuiltinType>(ty)->getKind()) {
37-
// Signed integral types.
27+
// Signed types.
3828
case BuiltinType::Char_S:
3929
case BuiltinType::Int:
4030
case BuiltinType::Int128:
@@ -43,10 +33,11 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
4333
case BuiltinType::SChar:
4434
case BuiltinType::Short:
4535
case BuiltinType::WChar_S:
46-
resultType = cir::IntType::get(&getMLIRContext(), context.getTypeSize(ty),
36+
resultType = cir::IntType::get(cgm.getBuilder().getContext(),
37+
context.getTypeSize(ty),
4738
/*isSigned=*/true);
4839
break;
49-
// Unsigned integral types.
40+
// Unsigned types.
5041
case BuiltinType::Char8:
5142
case BuiltinType::Char16:
5243
case BuiltinType::Char32:
@@ -58,12 +49,14 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
5849
case BuiltinType::ULongLong:
5950
case BuiltinType::UShort:
6051
case BuiltinType::WChar_U:
61-
resultType = cir::IntType::get(&getMLIRContext(), context.getTypeSize(ty),
52+
resultType = cir::IntType::get(cgm.getBuilder().getContext(),
53+
context.getTypeSize(ty),
6254
/*isSigned=*/false);
6355
break;
6456
default:
6557
cgm.errorNYI(SourceLocation(), "processing of built-in type", type);
66-
resultType = cgm.SInt32Ty;
58+
resultType = cir::IntType::get(cgm.getBuilder().getContext(), 32,
59+
/*isSigned=*/true);
6760
break;
6861
}
6962
break;
@@ -72,21 +65,23 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
7265
const auto *bitIntTy = cast<BitIntType>(type);
7366
if (bitIntTy->getNumBits() > cir::IntType::maxBitwidth()) {
7467
cgm.errorNYI(SourceLocation(), "large _BitInt type", type);
75-
resultType = cgm.SInt32Ty;
68+
resultType = cir::IntType::get(cgm.getBuilder().getContext(), 32,
69+
/*isSigned=*/true);
7670
} else {
77-
resultType = cir::IntType::get(&getMLIRContext(), bitIntTy->getNumBits(),
78-
bitIntTy->isSigned());
71+
resultType =
72+
cir::IntType::get(cgm.getBuilder().getContext(),
73+
bitIntTy->getNumBits(), bitIntTy->isSigned());
7974
}
8075
break;
8176
}
8277
default:
8378
cgm.errorNYI(SourceLocation(), "processing of type", type);
84-
resultType = cgm.SInt32Ty;
79+
resultType =
80+
cir::IntType::get(cgm.getBuilder().getContext(), 32, /*isSigned=*/true);
8581
break;
8682
}
8783

8884
assert(resultType && "Type conversion not yet implemented");
8985

90-
typeCache[ty] = resultType;
9186
return resultType;
9287
}

Diff for: clang/lib/CIR/CodeGen/CIRGenTypes.h

-12
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515

1616
#include "clang/CIR/Dialect/IR/CIRTypes.h"
1717

18-
#include "llvm/ADT/SmallPtrSet.h"
19-
2018
namespace clang {
2119
class ASTContext;
2220
class QualType;
23-
class Type;
2421
} // namespace clang
2522

2623
namespace mlir {
@@ -29,27 +26,18 @@ class Type;
2926

3027
namespace clang::CIRGen {
3128

32-
class CIRGenBuilderTy;
3329
class CIRGenModule;
3430

3531
/// This class organizes the cross-module state that is used while lowering
3632
/// AST types to CIR types.
3733
class CIRGenTypes {
3834
CIRGenModule &cgm;
3935
clang::ASTContext &context;
40-
CIRGenBuilderTy &builder;
4136

4237
public:
4338
CIRGenTypes(CIRGenModule &cgm);
4439
~CIRGenTypes();
4540

46-
/// This map of clang::Type to mlir::Type (which includes CIR type) is a
47-
/// cache of types that have already been processed.
48-
using TypeCacheTy = llvm::DenseMap<const clang::Type *, mlir::Type>;
49-
TypeCacheTy typeCache;
50-
51-
mlir::MLIRContext &getMLIRContext() const;
52-
5341
/// Convert a Clang type into a mlir::Type.
5442
mlir::Type convertType(clang::QualType type);
5543
};

0 commit comments

Comments
 (0)