Skip to content

Commit 9a7e250

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into zcfs
2 parents 6945c2e + 3d71939 commit 9a7e250

File tree

78 files changed

+1699
-249
lines changed

Some content is hidden

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

78 files changed

+1699
-249
lines changed

clang/Maintainers.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ Clang LLVM IR generation
5151
| Anton Korobeynikov
5252
| anton\@korobeynikov.info (email), asl (Phabricator), asl (GitHub)
5353
54+
Clang MLIR generation
55+
~~~~~~~~~~~~~~~~~~~~~
56+
| Andy Kaylor
57+
| akaylor\@nvidia.com (email), AndyKaylor (Discord), AndyKaylor (GitHub)
58+
59+
| Bruno Cardoso Lopes
60+
| bruno.cardoso\@gmail.com (email), sonicsprawl (Discord), bcardosolopes (GitHub)
61+
5462

5563
Analysis & CFG
5664
~~~~~~~~~~~~~~

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,8 @@ Bug Fixes to C++ Support
660660
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
661661
- No longer crashes when instantiating invalid variable template specialization
662662
whose type depends on itself. (#GH51347), (#GH55872)
663+
- Improved parser recovery of invalid requirement expressions. In turn, this
664+
fixes crashes from follow-on processing of the invalid requirement. (#GH138820)
663665

664666
Bug Fixes to AST Handling
665667
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/CIR/CIRToCIRPasses.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace cir {
3232
mlir::LogicalResult runCIRToCIRPasses(mlir::ModuleOp theModule,
3333
mlir::MLIRContext &mlirCtx,
3434
clang::ASTContext &astCtx,
35-
bool enableVerifier);
35+
bool enableVerifier,
36+
bool enableCIRSimplify);
3637

3738
} // namespace cir
3839

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
111111
cir::BoolType getBoolTy() { return cir::BoolType::get(getContext()); }
112112

113113
cir::PointerType getPointerTo(mlir::Type ty) {
114-
return cir::PointerType::get(getContext(), ty);
114+
return cir::PointerType::get(ty);
115115
}
116116

117117
cir::PointerType getVoidPtrTy() {

clang/include/clang/CIR/Dialect/IR/CIRDialect.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def CIR_Dialect : Dialect {
2727
let useDefaultAttributePrinterParser = 0;
2828
let useDefaultTypePrinterParser = 0;
2929

30+
// Enable constant materialization for the CIR dialect. This generates a
31+
// declaration for the cir::CIRDialect::materializeConstant function. This
32+
// hook is necessary for canonicalization to properly handle attributes
33+
// returned by fold methods, allowing them to be materialized as constant
34+
// operations in the IR.
35+
let hasConstantMaterializer = 1;
36+
3037
let extraClassDeclaration = [{
3138
static llvm::StringRef getTripleAttrName() { return "cir.triple"; }
3239

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ def AllocaOp : CIR_Op<"alloca", [
384384
`]`
385385
($annotations^)? attr-dict
386386
}];
387-
388-
let hasVerifier = 0;
389387
}
390388

391389
//===----------------------------------------------------------------------===//
@@ -1464,6 +1462,8 @@ def SelectOp : CIR_Op<"select", [Pure,
14641462
qualified(type($false_value))
14651463
`)` `->` qualified(type($result)) attr-dict
14661464
}];
1465+
1466+
let hasFolder = 1;
14671467
}
14681468

14691469
//===----------------------------------------------------------------------===//
@@ -1512,9 +1512,6 @@ def TernaryOp : CIR_Op<"ternary",
15121512
>
15131513
];
15141514

1515-
// All constraints already verified elsewhere.
1516-
let hasVerifier = 0;
1517-
15181515
let assemblyFormat = [{
15191516
`(` $cond `,`
15201517
`true` $trueRegion `,`
@@ -1652,9 +1649,6 @@ def GetGlobalOp : CIR_Op<"get_global",
16521649
let assemblyFormat = [{
16531650
$name `:` qualified(type($addr)) attr-dict
16541651
}];
1655-
1656-
// `GetGlobalOp` is fully verified by its traits.
1657-
let hasVerifier = 0;
16581652
}
16591653

16601654
//===----------------------------------------------------------------------===//
@@ -1837,7 +1831,6 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
18371831

18381832
let hasCustomAssemblyFormat = 1;
18391833
let skipDefaultBuilders = 1;
1840-
let hasVerifier = 0;
18411834

18421835
// TODO(cir): for now cir.call is just a tiny shell of what it will become.
18431836
// More attributes, arguments, and properties will be added in the future as

clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,37 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
141141
let cppFunctionName = "isAnyIntegerOrFloatingPointType";
142142
}
143143

144+
//===----------------------------------------------------------------------===//
145+
// Pointer Type predicates
146+
//===----------------------------------------------------------------------===//
147+
148+
def CIR_AnyPtrType : CIR_TypeBase<"::cir::PointerType", "pointer type">;
149+
150+
// Pointer to type constraint bases
151+
class CIR_IsPtrToPred<code type> : CPred<"$_self.isPtrTo<" # type # ">()">;
152+
153+
class CIR_PtrTo<code type, string summary>
154+
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPred<type>],
155+
"pointer to " # summary>;
156+
157+
// Pointer to pointer constraint bases
158+
class CIR_IsPtrToPtrToPred<code type>
159+
: CPred<"$_self.isPtrToPtrTo<" # type # ">()">;
160+
161+
class CIR_PtrToPtrTo<code type, string summary>
162+
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPtrToPred<type>],
163+
"pointer to pointer to " # summary>;
164+
165+
// Void pointer type constraints
166+
def CIR_VoidPtrType
167+
: CIR_PtrTo<"::cir::VoidType", "void type">,
168+
BuildableType<"$_builder.getType<" # cppType # ">("
169+
"cir::VoidType::get($_builder.getContext()))">;
170+
171+
def CIR_PtrToVoidPtrType
172+
: CIR_PtrToPtrTo<"::cir::VoidType", "void type">,
173+
BuildableType<"$_builder.getType<" # cppType # ">("
174+
"$_builder.getType<" # cppType # ">("
175+
"cir::VoidType::get($_builder.getContext())))">;
176+
144177
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,30 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr",
197197
let skipDefaultBuilders = 1;
198198

199199
let extraClassDeclaration = [{
200+
template <typename ...Types>
201+
bool isPtrTo() const {
202+
return mlir::isa< Types... >(getPointee());
203+
}
204+
200205
bool isVoidPtr() const {
201-
return mlir::isa<cir::VoidType>(getPointee());
206+
return isPtrTo<cir::VoidType>();
207+
}
208+
209+
template <typename ...Types>
210+
bool isPtrToPtrTo() const {
211+
if (auto ptrType = mlir::dyn_cast<cir::PointerType>(getPointee()))
212+
return ptrType.isPtrTo<Types...>();
213+
return false;
214+
}
215+
216+
bool isPtrTo(mlir::Type type) const {
217+
return getPointee() == type;
218+
}
219+
220+
bool isPtrToPtrTo(mlir::Type type) const {
221+
if (auto ptrType = mlir::dyn_cast<cir::PointerType>(getPointee()))
222+
return ptrType.isPtrTo(type);
223+
return false;
202224
}
203225
}];
204226
}
@@ -368,20 +390,6 @@ def CIR_VoidType : CIR_Type<"Void", "void"> {
368390
}];
369391
}
370392

371-
// Constraints
372-
373-
// Pointer to void
374-
def VoidPtr : Type<
375-
And<[
376-
CPred<"::mlir::isa<::cir::PointerType>($_self)">,
377-
CPred<"::mlir::isa<::cir::VoidType>("
378-
"::mlir::cast<::cir::PointerType>($_self).getPointee())">,
379-
]>, "void*">,
380-
BuildableType<
381-
"cir::PointerType::get($_builder.getContext(),"
382-
"cir::VoidType::get($_builder.getContext()))"> {
383-
}
384-
385393
//===----------------------------------------------------------------------===//
386394
// RecordType
387395
//

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace mlir {
2222

2323
std::unique_ptr<Pass> createCIRCanonicalizePass();
2424
std::unique_ptr<Pass> createCIRFlattenCFGPass();
25+
std::unique_ptr<Pass> createCIRSimplifyPass();
2526
std::unique_ptr<Pass> createHoistAllocasPass();
2627

2728
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);

clang/include/clang/CIR/Dialect/Passes.td

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ def CIRCanonicalize : Pass<"cir-canonicalize"> {
2929
let dependentDialects = ["cir::CIRDialect"];
3030
}
3131

32+
def CIRSimplify : Pass<"cir-simplify"> {
33+
let summary = "Performs CIR simplification and code optimization";
34+
let description = [{
35+
The pass performs semantics-preserving code simplifications and optimizations
36+
on CIR while maintaining strict program correctness.
37+
38+
Unlike the `cir-canonicalize` pass, these transformations may reduce the IR's
39+
structural similarity to the original source code as a trade-off for improved
40+
code quality. This can affect debugging fidelity by altering intermediate
41+
representations of folded expressions, hoisted operations, and other
42+
optimized constructs.
43+
44+
Example transformations include ternary expression folding and code hoisting
45+
while preserving program semantics.
46+
}];
47+
let constructor = "mlir::createCIRSimplifyPass()";
48+
let dependentDialects = ["cir::CIRDialect"];
49+
}
50+
3251
def HoistAllocas : Pass<"cir-hoist-allocas"> {
3352
let summary = "Hoist allocas to the entry of the function";
3453
let description = [{

0 commit comments

Comments
 (0)