From b51fd7afa20306bbe125e7140c81a92c01200cf7 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Wed, 30 Oct 2024 17:30:56 +0300 Subject: [PATCH 1/4] [CIR][ABI][AArch64] support for return struct types greater 128 bits --- clang/include/clang/CIR/ABIArgInfo.h | 40 +++++++++++++++ .../Transforms/TargetLowering/ABIInfo.cpp | 7 +++ .../Transforms/TargetLowering/ABIInfo.h | 5 ++ .../TargetLowering/CIRToCIRArgMapping.h | 20 +++++++- .../Transforms/TargetLowering/LowerCall.cpp | 1 + .../TargetLowering/LowerFunction.cpp | 49 ++++++++++++++++++- .../Transforms/TargetLowering/LowerTypes.cpp | 9 +++- .../TargetLowering/Targets/AArch64.cpp | 2 +- .../AArch64/aarch64-cc-structs.c | 13 +++++ 9 files changed, 140 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/CIR/ABIArgInfo.h b/clang/include/clang/CIR/ABIArgInfo.h index d330b2c3e24d..f5a313528357 100644 --- a/clang/include/clang/CIR/ABIArgInfo.h +++ b/clang/include/clang/CIR/ABIArgInfo.h @@ -103,6 +103,9 @@ class ABIArgInfo { bool InReg : 1; // isDirect() || isExtend() || isIndirect() bool CanBeFlattened : 1; // isDirect() bool SignExt : 1; // isExtend() + bool IndirectByVal : 1; // isIndirect() + bool IndirectRealign : 1; // isIndirect() + bool SRetAfterThis : 1; // isIndirect() bool canHavePaddingType() const { return isDirect() || isExtend() || isIndirect() || isIndirectAliased() || @@ -195,6 +198,43 @@ class ABIArgInfo { static ABIArgInfo getIgnore() { return ABIArgInfo(Ignore); } + static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true, + bool Realign = false, + mlir::Type Padding = nullptr) { + auto AI = ABIArgInfo(Indirect); + AI.setIndirectAlign(Alignment); + AI.setIndirectByVal(ByVal); + AI.setIndirectRealign(Realign); + AI.setSRetAfterThis(false); + AI.setPaddingType(Padding); + return AI; + } + + void setIndirectAlign(unsigned align) { + assert((isIndirect() || isIndirectAliased()) && "Invalid kind!"); + IndirectAttr.Align = align; + } + + void setIndirectByVal(bool IBV) { + assert(isIndirect() && "Invalid kind!"); + IndirectByVal = IBV; + } + + void setIndirectRealign(bool IR) { + assert((isIndirect() || isIndirectAliased()) && "Invalid kind!"); + IndirectRealign = IR; + } + + void setSRetAfterThis(bool AfterThis) { + assert(isIndirect() && "Invalid kind!"); + SRetAfterThis = AfterThis; + } + + bool isSRetAfterThis() const { + assert(isIndirect() && "Invalid kind!"); + return SRetAfterThis; + } + Kind getKind() const { return TheKind; } bool isDirect() const { return TheKind == Direct; } bool isInAlloca() const { return TheKind == InAlloca; } diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp index f5cb64059d32..e27685b89d5f 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp @@ -42,5 +42,12 @@ bool ABIInfo::isPromotableIntegerTypeForABI(Type Ty) const { return false; } +::cir::ABIArgInfo ABIInfo::getNaturalAlignIndirect(mlir::Type Ty, bool ByVal, + bool Realign, + mlir::Type Padding) const { + return ::cir::ABIArgInfo::getIndirect(getContext().getTypeAlign(Ty), + ByVal, Realign, Padding); +} + } // namespace cir } // namespace mlir diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h index bbcd906e849a..f9a059d3d237 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h @@ -50,6 +50,11 @@ class ABIInfo { // Implement the Type::IsPromotableIntegerType for ABI specific needs. The // only difference is that this considers bit-precise integer types as well. bool isPromotableIntegerTypeForABI(Type Ty) const; + + ::cir::ABIArgInfo getNaturalAlignIndirect(mlir::Type Ty, + bool ByVal = true, + bool Realign = false, + mlir::Type Padding = {}) const; }; } // namespace cir diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h index 139f279385e6..ce2913992c52 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h @@ -29,6 +29,7 @@ namespace cir { /// LoweringFunctionInfo should be passed to actual CIR function. class CIRToCIRArgMapping { static const unsigned InvalidIndex = ~0U; + unsigned SRetArgNo; unsigned TotalIRArgs; /// Arguments of CIR function corresponding to single CIR argument. @@ -51,7 +52,8 @@ class CIRToCIRArgMapping { public: CIRToCIRArgMapping(const CIRLowerContext &context, const LowerFunctionInfo &FI, bool onlyRequiredArgs = false) - : ArgInfo(onlyRequiredArgs ? FI.getNumRequiredArgs() : FI.arg_size()) { + : SRetArgNo(InvalidIndex) + , ArgInfo(onlyRequiredArgs ? FI.getNumRequiredArgs() : FI.arg_size()) { construct(context, FI, onlyRequiredArgs); }; @@ -69,7 +71,8 @@ class CIRToCIRArgMapping { const ::cir::ABIArgInfo &RetAI = FI.getReturnInfo(); if (RetAI.getKind() == ::cir::ABIArgInfo::Indirect) { - cir_cconv_unreachable("NYI"); + SwapThisWithSRet = RetAI.isSRetAfterThis(); + SRetArgNo = SwapThisWithSRet ? 1 : IRArgNo++; } unsigned ArgNo = 0; @@ -100,6 +103,11 @@ class CIRToCIRArgMapping { } break; } + case ::cir::ABIArgInfo::Indirect: + case ::cir::ABIArgInfo::IndirectAliased: + IRArgs.NumberOfArgs = 1; + break; + default: cir_cconv_unreachable("Missing ABIArgInfo::Kind"); } @@ -130,6 +138,14 @@ class CIRToCIRArgMapping { return std::make_pair(ArgInfo[ArgNo].FirstArgIndex, ArgInfo[ArgNo].NumberOfArgs); } + + bool hasSRetArg() const { return SRetArgNo != InvalidIndex; } + + unsigned getSRetArgNo() const { + assert(hasSRetArg()); + return SRetArgNo; + } + }; } // namespace cir diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp index 1f59e5094d18..e98dc1e29fdf 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp @@ -157,6 +157,7 @@ void LowerModule::constructAttributeList(StringRef Name, cir_cconv_assert(!::cir::MissingFeatures::noFPClass()); break; case ABIArgInfo::Ignore: + case ABIArgInfo::Indirect: break; default: cir_cconv_unreachable("Missing ABIArgInfo::Kind"); diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index fee7a752d7fb..809161d8d144 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -10,7 +10,6 @@ // are adapted to operate on the CIR dialect, however. // //===----------------------------------------------------------------------===// - #include "LowerFunction.h" #include "CIRToCIRArgMapping.h" #include "LowerCall.h" @@ -433,6 +432,24 @@ LowerFunction::buildFunctionProlog(const LowerFunctionInfo &FI, FuncOp Fn, return success(); } +mlir::cir::AllocaOp findAlloca(Operation* op) { + if (!op) + return {}; + + if (auto al = dyn_cast(op)) { + return al; + } else if (auto ret = dyn_cast(op)) { + auto vals = ret.getInput(); + if (vals.size() == 1) + return findAlloca(vals[0].getDefiningOp()); + } else if (auto load = dyn_cast(op)) { + return findAlloca(load.getAddr().getDefiningOp()); + } else if (auto load = dyn_cast(op)) { + } + + return {}; +} + LogicalResult LowerFunction::buildFunctionEpilog(const LowerFunctionInfo &FI) { // NOTE(cir): no-return, naked, and no result functions should be handled in // CIRGen. @@ -446,6 +463,27 @@ LogicalResult LowerFunction::buildFunctionEpilog(const LowerFunctionInfo &FI) { case ABIArgInfo::Ignore: break; + case ABIArgInfo::Indirect: { + Value RV_addr = {}; + CIRToCIRArgMapping IRFunctionArgs(LM.getContext(), FI, true); + if (IRFunctionArgs.hasSRetArg()) { + auto& entry = NewFn.getBody().front(); + RV_addr = entry.getArgument(IRFunctionArgs.getSRetArgNo()); + } + + if (RV_addr) { + mlir::PatternRewriter::InsertionGuard guard(rewriter); + NewFn->walk([&](ReturnOp ret) { + if (auto al = findAlloca(ret)) { + rewriter.replaceAllUsesWith(al.getResult(), RV_addr); + rewriter.eraseOp(al); + rewriter.replaceOpWithNewOp(ret); + } + }); + } + break; + } + case ABIArgInfo::Extend: case ABIArgInfo::Direct: // FIXME(cir): Should we call ConvertType(RetTy) here? @@ -517,6 +555,15 @@ LogicalResult LowerFunction::generateCode(FuncOp oldFn, FuncOp newFn, Block *srcBlock = &oldFn.getBody().front(); Block *dstBlock = &newFn.getBody().front(); + // Ensure both blocks have the same number of arguments in order to + // safely merge them + CIRToCIRArgMapping IRFunctionArgs(LM.getContext(), FnInfo, true); + if (IRFunctionArgs.hasSRetArg()) { + auto dst_index = IRFunctionArgs.getSRetArgNo(); + auto ret_arg = dstBlock->getArguments()[dst_index]; + srcBlock->insertArgument(dst_index, ret_arg.getType(), ret_arg.getLoc()); + } + // Migrate function body to new ABI-aware function. rewriter.inlineRegionBefore(oldFn.getBody(), newFn.getBody(), newFn.getBody().end()); diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp index ea9f51f002f6..b9e9de84937e 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp @@ -50,6 +50,7 @@ FuncType LowerTypes::getFunctionType(const LowerFunctionInfo &FI) { resultType = retAI.getCoerceToType(); break; case ::cir::ABIArgInfo::Ignore: + case ::cir::ABIArgInfo::Indirect: resultType = VoidType::get(getMLIRContext()); break; default: @@ -59,8 +60,12 @@ FuncType LowerTypes::getFunctionType(const LowerFunctionInfo &FI) { CIRToCIRArgMapping IRFunctionArgs(getContext(), FI, true); SmallVector ArgTypes(IRFunctionArgs.totalIRArgs()); - // Add type for sret argument. - cir_cconv_assert(!::cir::MissingFeatures::sretArgs()); + // Add type for sret argument. + if (IRFunctionArgs.hasSRetArg()) { + mlir::Type ret = FI.getReturnType(); + ArgTypes[IRFunctionArgs.getSRetArgNo()] = + mlir::cir::PointerType::get(getMLIRContext(), ret); + } // Add type for inalloca argument. cir_cconv_assert(!::cir::MissingFeatures::inallocaArgs()); diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/AArch64.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/AArch64.cpp index 586f4a3d22e1..b4e02d8e08fb 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/AArch64.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/AArch64.cpp @@ -137,7 +137,7 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(Type RetTy, cir_cconv_unreachable("NYI"); } - cir_cconv_unreachable("NYI"); + return getNaturalAlignIndirect(RetTy); } ABIArgInfo diff --git a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c index 884580305282..649811a2265a 100644 --- a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c +++ b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c @@ -21,6 +21,12 @@ typedef struct { int64_t b; } EQ_128; +typedef struct { + int64_t a; + int64_t b; + int64_t c; +} GT_128; + // CHECK: cir.func {{.*@ret_lt_64}}() -> !u16i // CHECK: %[[#V0:]] = cir.alloca !ty_LT_64_, !cir.ptr, ["__retval"] // CHECK: %[[#V1:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr @@ -60,3 +66,10 @@ EQ_128 ret_eq_128() { EQ_128 x; return x; } + +// CHECK: cir.func {{.*@ret_gt_128}}(%arg0: !cir.ptr +// CHECK-NOT: cir.return {{%.*}} +GT_128 ret_gt_128() { + GT_128 x; + return x; +} From ae80e1d89d75680707c9095e2a1f0f5e5477580f Mon Sep 17 00:00:00 2001 From: gitoleg Date: Wed, 30 Oct 2024 18:00:04 +0300 Subject: [PATCH 2/4] add missing features assert --- clang/include/clang/CIR/MissingFeatures.h | 1 + clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/clang/include/clang/CIR/MissingFeatures.h b/clang/include/clang/CIR/MissingFeatures.h index 04f9cee7a2db..80d7d330b4b1 100644 --- a/clang/include/clang/CIR/MissingFeatures.h +++ b/clang/include/clang/CIR/MissingFeatures.h @@ -271,6 +271,7 @@ struct MissingFeatures { static bool ABIParameterCoercion() { return false; } static bool ABIPointerParameterAttrs() { return false; } static bool ABITransparentUnionHandling() { return false; } + static bool ABIPotentialArgAccess() { return false; } //-- Missing AST queries diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp index e98dc1e29fdf..54fe89838e82 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerCall.cpp @@ -158,6 +158,7 @@ void LowerModule::constructAttributeList(StringRef Name, break; case ABIArgInfo::Ignore: case ABIArgInfo::Indirect: + cir_cconv_assert(!::cir::MissingFeatures::ABIPotentialArgAccess()); break; default: cir_cconv_unreachable("Missing ABIArgInfo::Kind"); From 67193e76c965811f66d1011cf79e2f4e0609ae8d Mon Sep 17 00:00:00 2001 From: gitoleg Date: Thu, 31 Oct 2024 09:45:51 +0300 Subject: [PATCH 3/4] clang-format ... --- clang/include/clang/CIR/ABIArgInfo.h | 2 +- clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp | 4 ++-- clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h | 3 +-- .../Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h | 5 ++--- .../CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp | 4 ++-- .../lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp | 4 ++-- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/clang/include/clang/CIR/ABIArgInfo.h b/clang/include/clang/CIR/ABIArgInfo.h index f5a313528357..582feae157b2 100644 --- a/clang/include/clang/CIR/ABIArgInfo.h +++ b/clang/include/clang/CIR/ABIArgInfo.h @@ -103,7 +103,7 @@ class ABIArgInfo { bool InReg : 1; // isDirect() || isExtend() || isIndirect() bool CanBeFlattened : 1; // isDirect() bool SignExt : 1; // isExtend() - bool IndirectByVal : 1; // isIndirect() + bool IndirectByVal : 1; // isIndirect() bool IndirectRealign : 1; // isIndirect() bool SRetAfterThis : 1; // isIndirect() diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp index e27685b89d5f..7ff24be12b35 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.cpp @@ -45,8 +45,8 @@ bool ABIInfo::isPromotableIntegerTypeForABI(Type Ty) const { ::cir::ABIArgInfo ABIInfo::getNaturalAlignIndirect(mlir::Type Ty, bool ByVal, bool Realign, mlir::Type Padding) const { - return ::cir::ABIArgInfo::getIndirect(getContext().getTypeAlign(Ty), - ByVal, Realign, Padding); + return ::cir::ABIArgInfo::getIndirect(getContext().getTypeAlign(Ty), ByVal, + Realign, Padding); } } // namespace cir diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h index f9a059d3d237..0b67d84570ea 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/ABIInfo.h @@ -51,8 +51,7 @@ class ABIInfo { // only difference is that this considers bit-precise integer types as well. bool isPromotableIntegerTypeForABI(Type Ty) const; - ::cir::ABIArgInfo getNaturalAlignIndirect(mlir::Type Ty, - bool ByVal = true, + ::cir::ABIArgInfo getNaturalAlignIndirect(mlir::Type Ty, bool ByVal = true, bool Realign = false, mlir::Type Padding = {}) const; }; diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h index ce2913992c52..05c853b875c4 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRToCIRArgMapping.h @@ -52,8 +52,8 @@ class CIRToCIRArgMapping { public: CIRToCIRArgMapping(const CIRLowerContext &context, const LowerFunctionInfo &FI, bool onlyRequiredArgs = false) - : SRetArgNo(InvalidIndex) - , ArgInfo(onlyRequiredArgs ? FI.getNumRequiredArgs() : FI.arg_size()) { + : SRetArgNo(InvalidIndex), + ArgInfo(onlyRequiredArgs ? FI.getNumRequiredArgs() : FI.arg_size()) { construct(context, FI, onlyRequiredArgs); }; @@ -145,7 +145,6 @@ class CIRToCIRArgMapping { assert(hasSRetArg()); return SRetArgNo; } - }; } // namespace cir diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index 809161d8d144..8a2793049755 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -432,7 +432,7 @@ LowerFunction::buildFunctionProlog(const LowerFunctionInfo &FI, FuncOp Fn, return success(); } -mlir::cir::AllocaOp findAlloca(Operation* op) { +mlir::cir::AllocaOp findAlloca(Operation *op) { if (!op) return {}; @@ -467,7 +467,7 @@ LogicalResult LowerFunction::buildFunctionEpilog(const LowerFunctionInfo &FI) { Value RV_addr = {}; CIRToCIRArgMapping IRFunctionArgs(LM.getContext(), FI, true); if (IRFunctionArgs.hasSRetArg()) { - auto& entry = NewFn.getBody().front(); + auto &entry = NewFn.getBody().front(); RV_addr = entry.getArgument(IRFunctionArgs.getSRetArgNo()); } diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp index b9e9de84937e..8ed553a8f7d2 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerTypes.cpp @@ -60,11 +60,11 @@ FuncType LowerTypes::getFunctionType(const LowerFunctionInfo &FI) { CIRToCIRArgMapping IRFunctionArgs(getContext(), FI, true); SmallVector ArgTypes(IRFunctionArgs.totalIRArgs()); - // Add type for sret argument. + // Add type for sret argument. if (IRFunctionArgs.hasSRetArg()) { mlir::Type ret = FI.getReturnType(); ArgTypes[IRFunctionArgs.getSRetArgNo()] = - mlir::cir::PointerType::get(getMLIRContext(), ret); + mlir::cir::PointerType::get(getMLIRContext(), ret); } // Add type for inalloca argument. From 0e93acf64da07b8f91bf2900112f0c5785a3573f Mon Sep 17 00:00:00 2001 From: gitoleg Date: Thu, 31 Oct 2024 10:04:04 +0300 Subject: [PATCH 4/4] minor changes after review --- .../Transforms/TargetLowering/LowerFunction.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index 8a2793049755..f36522b187fc 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -444,7 +444,6 @@ mlir::cir::AllocaOp findAlloca(Operation *op) { return findAlloca(vals[0].getDefiningOp()); } else if (auto load = dyn_cast(op)) { return findAlloca(load.getAddr().getDefiningOp()); - } else if (auto load = dyn_cast(op)) { } return {}; @@ -464,18 +463,18 @@ LogicalResult LowerFunction::buildFunctionEpilog(const LowerFunctionInfo &FI) { break; case ABIArgInfo::Indirect: { - Value RV_addr = {}; + Value RVAddr = {}; CIRToCIRArgMapping IRFunctionArgs(LM.getContext(), FI, true); if (IRFunctionArgs.hasSRetArg()) { auto &entry = NewFn.getBody().front(); - RV_addr = entry.getArgument(IRFunctionArgs.getSRetArgNo()); + RVAddr = entry.getArgument(IRFunctionArgs.getSRetArgNo()); } - if (RV_addr) { + if (RVAddr) { mlir::PatternRewriter::InsertionGuard guard(rewriter); NewFn->walk([&](ReturnOp ret) { if (auto al = findAlloca(ret)) { - rewriter.replaceAllUsesWith(al.getResult(), RV_addr); + rewriter.replaceAllUsesWith(al.getResult(), RVAddr); rewriter.eraseOp(al); rewriter.replaceOpWithNewOp(ret); } @@ -556,12 +555,12 @@ LogicalResult LowerFunction::generateCode(FuncOp oldFn, FuncOp newFn, Block *dstBlock = &newFn.getBody().front(); // Ensure both blocks have the same number of arguments in order to - // safely merge them + // safely merge them. CIRToCIRArgMapping IRFunctionArgs(LM.getContext(), FnInfo, true); if (IRFunctionArgs.hasSRetArg()) { - auto dst_index = IRFunctionArgs.getSRetArgNo(); - auto ret_arg = dstBlock->getArguments()[dst_index]; - srcBlock->insertArgument(dst_index, ret_arg.getType(), ret_arg.getLoc()); + auto dstIndex = IRFunctionArgs.getSRetArgNo(); + auto retArg = dstBlock->getArguments()[dstIndex]; + srcBlock->insertArgument(dstIndex, retArg.getType(), retArg.getLoc()); } // Migrate function body to new ABI-aware function.