Skip to content

Commit 557e915

Browse files
committed
Update to fix issues after rebase
1 parent 07966ba commit 557e915

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

clang/include/clang/CIR/MissingFeatures.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct MissingFeatures {
3535
static bool opGlobalThreadLocal() { return false; }
3636
static bool opGlobalConstant() { return false; }
3737
static bool opGlobalAlignment() { return false; }
38-
38+
static bool opGlobalMlirLinkage() { return false; }
3939
static bool supportIFuncAttr() { return false; }
4040
static bool supportVisibility() { return false; }
4141
static bool supportComdat() { return false; }

clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp

+19-5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ struct ConvertCIRToMLIRPass
4242
StringRef getArgument() const override { return "cir-to-mlir"; }
4343
};
4444

45+
/// Given a type convertor and a data layout, convert the given type to a type
46+
/// that is suitable for memory operations. For example, this can be used to
47+
/// lower cir.bool accesses to i8.
48+
static mlir::Type convertTypeForMemory(const mlir::TypeConverter &converter,
49+
mlir::Type type) {
50+
// TODO(cir): Handle other types similarly to clang's codegen
51+
// convertTypeForMemory
52+
if (isa<cir::BoolType>(type)) {
53+
// TODO: Use datalayout to get the size of bool
54+
return mlir::IntegerType::get(type.getContext(), 8);
55+
}
56+
57+
return converter.convertType(type);
58+
}
59+
4560
class CIRGlobalOpLowering : public mlir::OpConversionPattern<cir::GlobalOp> {
4661
public:
4762
using OpConversionPattern<cir::GlobalOp>::OpConversionPattern;
@@ -55,8 +70,8 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern<cir::GlobalOp> {
5570
mlir::OpBuilder b(moduleOp.getContext());
5671

5772
const mlir::Type cirSymType = op.getSymType();
58-
assert(!cir::MissingFeatures::convertTypeForMemory());
59-
mlir::Type convertedType = getTypeConverter()->convertType(cirSymType);
73+
mlir::Type convertedType =
74+
convertTypeForMemory(*getTypeConverter(), cirSymType);
6075
if (!convertedType)
6176
return mlir::failure();
6277
auto memrefType = dyn_cast<mlir::MemRefType>(convertedType);
@@ -87,7 +102,7 @@ class CIRGlobalOpLowering : public mlir::OpConversionPattern<cir::GlobalOp> {
87102
}
88103

89104
// Add symbol visibility
90-
assert(!cir::MissingFeatures::opGlobalLinkage());
105+
assert(!cir::MissingFeatures::opGlobalMlirLinkage());
91106
std::string symVisibility = "public";
92107

93108
assert(!cir::MissingFeatures::opGlobalConstant());
@@ -112,8 +127,7 @@ void populateCIRToMLIRConversionPatterns(mlir::RewritePatternSet &patterns,
112127
static mlir::TypeConverter prepareTypeConverter() {
113128
mlir::TypeConverter converter;
114129
converter.addConversion([&](cir::PointerType type) -> mlir::Type {
115-
assert(!cir::MissingFeatures::convertTypeForMemory());
116-
mlir::Type ty = converter.convertType(type.getPointee());
130+
mlir::Type ty = convertTypeForMemory(converter, type.getPointee());
117131
// FIXME: The pointee type might not be converted (e.g. struct)
118132
if (!ty)
119133
return nullptr;

clang/test/CIR/hello.c

-6
This file was deleted.

0 commit comments

Comments
 (0)