aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorMatthias Springer <me@m-sp.org>2025-08-27 09:13:52 +0200
committerGitHub <noreply@github.com>2025-08-27 09:13:52 +0200
commit337707a5417dbdc8751c2a11eda920e250417b5a (patch)
tree792fa5f780943d6760b3e46a36e82dfbcbc671a9 /clang/lib/CodeGen/CodeGenModule.cpp
parente6f5aa9e2b69d1e84bd281c2525004800828b30d (diff)
downloadllvm-337707a5417dbdc8751c2a11eda920e250417b5a.zip
llvm-337707a5417dbdc8751c2a11eda920e250417b5a.tar.gz
llvm-337707a5417dbdc8751c2a11eda920e250417b5a.tar.bz2
[mlir][Transforms] Dialect conversion: Context-aware type conversions (#140434)
This commit adds support for context-aware type conversions: type conversion rules that can return different types depending on the IR. There is no change for existing (context-unaware) type conversion rules: ```c++ // Example: Conversion any integer type to f32. converter.addConversion([](IntegerType t) { return Float32Type::get(t.getContext()); } ``` There is now an additional overload to register context-aware type conversion rules: ```c++ // Example: Type conversion rule for integers, depending on the context: // Get the defining op of `v`, read its "increment" attribute and return an // integer with a bitwidth that is increased by "increment". converter.addConversion([](Value v) -> std::optional<Type> { auto intType = dyn_cast<IntegerType>(v.getType()); if (!intType) return std::nullopt; Operation *op = v.getDefiningOp(); if (!op) return std::nullopt; auto incrementAttr = op->getAttrOfType<IntegerAttr>("increment"); if (!incrementAttr) return std::nullopt; return IntegerType::get(v.getContext(), intType.getWidth() + incrementAttr.getInt()); }); ``` For performance reasons, the type converter caches the result of type conversions. This is no longer possible when there context-aware type conversions because each conversion could compute a different type depending on the context. There is no performance degradation when there are only context-unaware type conversions. Note: This commit just adds context-aware type conversions to the dialect conversion framework. There are many existing patterns that still call `converter.convertType(someValue.getType())`. These should be gradually updated in subsequent commits to call `converter.convertType(someValue)`. Co-authored-by: Markus Böck <markus.boeck02@gmail.com>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
0 files changed, 0 insertions, 0 deletions