[llvm-branch-commits] [clang] [CIR][AMDGPU] Lower Language specific address spaces and implement AMDGPU target (PR #179084)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 12 13:46:07 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/AMDGPU.cpp clang/test/CIR/CodeGen/amdgpu-address-spaces.cpp clang/lib/CIR/CodeGen/CIRGenModule.cpp clang/lib/CIR/CodeGen/TargetInfo.cpp clang/lib/CIR/CodeGen/TargetInfo.h clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp clang/lib/CIR/Dialect/Transforms/TargetLowering/TargetLoweringInfo.h clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp
index 524910737..0c1fcbe8f 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering.cpp
@@ -66,9 +66,8 @@ public:
if (operandsAndResultsLegal && regionsLegal)
return mlir::failure();
- assert(op->getNumRegions() == 0 &&
- "CIRGenericTargetLoweringPattern cannot "
- "deal with operations with regions");
+ assert(op->getNumRegions() == 0 && "CIRGenericTargetLoweringPattern cannot "
+ "deal with operations with regions");
mlir::OperationState loweredOpState(op->getLoc(), op->getName());
loweredOpState.addOperands(operands);
@@ -104,10 +103,10 @@ class CIRGlobalOpTargetLowering
public:
CIRGlobalOpTargetLowering(mlir::MLIRContext *context,
- const mlir::TypeConverter &typeConverter,
- const cir::TargetLoweringInfo &targetInfo)
+ const mlir::TypeConverter &typeConverter,
+ const cir::TargetLoweringInfo &targetInfo)
: mlir::OpConversionPattern<cir::GlobalOp>(typeConverter, context,
- /*benefit=*/1),
+ /*benefit=*/1),
targetInfo(targetInfo) {}
mlir::LogicalResult
@@ -119,14 +118,14 @@ public:
// Convert the addr_space attribute.
mlir::ptr::MemorySpaceAttrInterface addrSpace = op.getAddrSpaceAttr();
- if (auto langAS = mlir::dyn_cast_if_present<cir::LangAddressSpaceAttr>(
- addrSpace)) {
+ if (auto langAS =
+ mlir::dyn_cast_if_present<cir::LangAddressSpaceAttr>(addrSpace)) {
unsigned targetAS =
targetInfo.getTargetAddrSpaceFromCIRAddrSpace(langAS.getValue());
- addrSpace = targetAS == 0
- ? nullptr
- : cir::TargetAddressSpaceAttr::get(op.getContext(),
- targetAS);
+ addrSpace =
+ targetAS == 0
+ ? nullptr
+ : cir::TargetAddressSpaceAttr::get(op.getContext(), targetAS);
}
// Only rewrite if something actually changed.
@@ -142,8 +141,7 @@ public:
};
/// Pattern to lower FuncOp types that contain address spaces.
-class CIRFuncOpTargetLowering
- : public mlir::OpConversionPattern<cir::FuncOp> {
+class CIRFuncOpTargetLowering : public mlir::OpConversionPattern<cir::FuncOp> {
public:
using mlir::OpConversionPattern<cir::FuncOp>::OpConversionPattern;
@@ -178,9 +176,9 @@ public:
loweredFuncOp.setFunctionType(loweredFuncType);
rewriter.inlineRegionBefore(op.getBody(), loweredFuncOp.getBody(),
loweredFuncOp.end());
- if (mlir::failed(rewriter.convertRegionTypes(
- &loweredFuncOp.getBody(), *getTypeConverter(),
- &signatureConversion)))
+ if (mlir::failed(rewriter.convertRegionTypes(&loweredFuncOp.getBody(),
+ *getTypeConverter(),
+ &signatureConversion)))
return mlir::failure();
rewriter.eraseOp(op);
@@ -210,25 +208,23 @@ prepareTargetLoweringTypeConverter(mlir::TypeConverter &converter,
const cir::TargetLoweringInfo &targetInfo) {
converter.addConversion([](mlir::Type type) { return type; });
- converter.addConversion(
- [&converter, &targetInfo](cir::PointerType type) -> mlir::Type {
- mlir::Type pointee = converter.convertType(type.getPointee());
- if (!pointee)
- return {};
- auto addrSpace = type.getAddrSpace();
- if (auto langAS =
- mlir::dyn_cast_if_present<cir::LangAddressSpaceAttr>(
- addrSpace)) {
- unsigned targetAS =
- targetInfo.getTargetAddrSpaceFromCIRAddrSpace(langAS.getValue());
- addrSpace =
- targetAS == 0
- ? nullptr
- : cir::TargetAddressSpaceAttr::get(type.getContext(),
- targetAS);
- }
- return cir::PointerType::get(type.getContext(), pointee, addrSpace);
- });
+ converter.addConversion([&converter,
+ &targetInfo](cir::PointerType type) -> mlir::Type {
+ mlir::Type pointee = converter.convertType(type.getPointee());
+ if (!pointee)
+ return {};
+ auto addrSpace = type.getAddrSpace();
+ if (auto langAS =
+ mlir::dyn_cast_if_present<cir::LangAddressSpaceAttr>(addrSpace)) {
+ unsigned targetAS =
+ targetInfo.getTargetAddrSpaceFromCIRAddrSpace(langAS.getValue());
+ addrSpace =
+ targetAS == 0
+ ? nullptr
+ : cir::TargetAddressSpaceAttr::get(type.getContext(), targetAS);
+ }
+ return cir::PointerType::get(type.getContext(), pointee, addrSpace);
+ });
converter.addConversion([&converter](cir::ArrayType type) -> mlir::Type {
mlir::Type loweredElementType =
@@ -254,18 +250,18 @@ prepareTargetLoweringTypeConverter(mlir::TypeConverter &converter,
});
}
-static void populateTargetLoweringConversionTarget(
- mlir::ConversionTarget &target, const mlir::TypeConverter &tc) {
+static void
+populateTargetLoweringConversionTarget(mlir::ConversionTarget &target,
+ const mlir::TypeConverter &tc) {
target.addLegalOp<mlir::ModuleOp>();
target.addDynamicallyLegalDialect<cir::CIRDialect>(
[&tc](mlir::Operation *op) {
if (!tc.isLegal(op))
return false;
- return std::all_of(op->getRegions().begin(), op->getRegions().end(),
- [&tc](mlir::Region ®ion) {
- return tc.isLegal(®ion);
- });
+ return std::all_of(
+ op->getRegions().begin(), op->getRegions().end(),
+ [&tc](mlir::Region ®ion) { return tc.isLegal(®ion); });
});
target.addDynamicallyLegalOp<cir::FuncOp>(
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index edeea4bc6..00b107057 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -3266,8 +3266,8 @@ static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
unsigned numericAS = 0;
if (auto targetAsAttr =
- mlir::dyn_cast_if_present<cir::TargetAddressSpaceAttr>(
- addrSpaceAttr))
+ mlir::dyn_cast_if_present<cir::TargetAddressSpaceAttr>(
+ addrSpaceAttr))
numericAS = targetAsAttr.getValue();
return mlir::LLVM::LLVMPointerType::get(type.getContext(), numericAS);
});
``````````
</details>
https://github.com/llvm/llvm-project/pull/179084
More information about the llvm-branch-commits
mailing list