From 59d7d4bc325495b251eb5959b779344298af32f0 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 2 Jul 2024 00:35:59 +0200 Subject: [MLIR][NVVM] Remove irrelevant guards (#97345) This code does not seem to involve the NVPTX backend anywhere. --- mlir/include/mlir/InitAllPasses.h | 2 -- mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp | 3 --- 2 files changed, 5 deletions(-) diff --git a/mlir/include/mlir/InitAllPasses.h b/mlir/include/mlir/InitAllPasses.h index fedd773..1b9c1b1 100644 --- a/mlir/include/mlir/InitAllPasses.h +++ b/mlir/include/mlir/InitAllPasses.h @@ -98,9 +98,7 @@ inline void registerAllPasses() { bufferization::registerBufferizationPipelines(); sparse_tensor::registerSparseTensorPipelines(); tosa::registerTosaToLinalgPipelines(); -#if LLVM_HAS_NVPTX_TARGET gpu::registerGPUToNVVMPipeline(); -#endif } } // namespace mlir diff --git a/mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp b/mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp index f457303..fb44075 100644 --- a/mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp +++ b/mlir/lib/Dialect/GPU/Pipelines/GPUToNVVMPipeline.cpp @@ -38,7 +38,6 @@ using namespace mlir; -#if LLVM_HAS_NVPTX_TARGET namespace { //===----------------------------------------------------------------------===// @@ -126,5 +125,3 @@ void mlir::gpu::registerGPUToNVVMPipeline() { "code.", buildLowerToNVVMPassPipeline); } - -#endif // LLVM_HAS_NVPTX_TARGET -- cgit v1.1 From 78804f891c052c2f8eefb2845cc4a4e4e1d68075 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 15:38:18 -0700 Subject: [MC] Remove the evaluateAsAbsolute overload that takes a MCAsmLayout parameter Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95. --- llvm/include/llvm/MC/MCExpr.h | 2 -- llvm/lib/MC/MCAssembler.cpp | 4 ++-- llvm/lib/MC/MCExpr.cpp | 17 +++++------------ llvm/lib/MC/WasmObjectWriter.cpp | 4 ++-- .../LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 4 ++-- llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 2 +- 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h index 40319dc..3c051b5 100644 --- a/llvm/include/llvm/MC/MCExpr.h +++ b/llvm/include/llvm/MC/MCExpr.h @@ -54,7 +54,6 @@ private: SMLoc Loc; bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, - const MCAsmLayout *Layout, const SectionAddrMap *Addrs, bool InSet) const; protected: @@ -101,7 +100,6 @@ public: bool evaluateAsAbsolute(int64_t &Res) const; bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const; bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const; - bool evaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const; bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const; diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 53bebdc..e8a7eae 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -1151,7 +1151,7 @@ bool MCAssembler::relaxLEB(MCLEBFragment &LF) { // fragments. This is used by __gcc_except_table. bool Abs = getSubsectionsViaSymbols() ? LF.getValue().evaluateKnownAbsolute(Value, *Layout) - : LF.getValue().evaluateAsAbsolute(Value, *Layout); + : LF.getValue().evaluateAsAbsolute(Value, *this); if (!Abs) { bool Relaxed, UseZeroPad; std::tie(Relaxed, UseZeroPad) = getBackend().relaxLEB128(*this, LF, Value); @@ -1269,7 +1269,7 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCDwarfCallFrameFragment &DF) { MCContext &Context = getContext(); int64_t Value; - bool Abs = DF.getAddrDelta().evaluateAsAbsolute(Value, *Layout); + bool Abs = DF.getAddrDelta().evaluateAsAbsolute(Value, *this); if (!Abs) { getContext().reportError(DF.getAddrDelta().getLoc(), "invalid CFI advance_loc expression"); diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index af9dcff..4b778e9 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -545,37 +545,30 @@ void MCTargetExpr::anchor() {} /* *** */ bool MCExpr::evaluateAsAbsolute(int64_t &Res) const { - return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr, false); -} - -bool MCExpr::evaluateAsAbsolute(int64_t &Res, - const MCAsmLayout &Layout) const { - return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, false); + return evaluateAsAbsolute(Res, nullptr, nullptr, false); } bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm, const SectionAddrMap &Addrs) const { // Setting InSet causes us to absolutize differences across sections and that // is what the MachO writer uses Addrs for. - return evaluateAsAbsolute(Res, &Asm, Asm.getLayout(), &Addrs, true); + return evaluateAsAbsolute(Res, &Asm, &Addrs, true); } bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const { - return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr, false); + return evaluateAsAbsolute(Res, &Asm, nullptr, false); } bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const { - return evaluateAsAbsolute(Res, Asm, nullptr, nullptr, false); + return evaluateAsAbsolute(Res, Asm, nullptr, false); } bool MCExpr::evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const { - return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, - true); + return evaluateAsAbsolute(Res, &Layout.getAssembler(), nullptr, true); } bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, - const MCAsmLayout *Layout, const SectionAddrMap *Addrs, bool InSet) const { MCValue Value; diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 5602c9b..187851b 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -1633,7 +1633,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, WS.getName()); int64_t Size = 0; - if (!WS.getSize()->evaluateAsAbsolute(Size, Layout)) + if (!WS.getSize()->evaluateAsAbsolute(Size, Asm)) report_fatal_error(".size expression must be evaluatable"); auto &DataSection = static_cast(WS.getSection()); @@ -1752,7 +1752,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, // size of the alias. When an offset from the base is involved this // can result in a offset + size goes past the end of the data section // which out object format doesn't support. So we must clamp it. - if (!Base->getSize()->evaluateAsAbsolute(Size, Layout)) + if (!Base->getSize()->evaluateAsAbsolute(Size, Asm)) report_fatal_error(".size expression must be evaluatable"); const WasmDataSegment &Segment = DataSegments[DataSection.getSegmentIndex()]; diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp index e3200b0..eb059d3 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp @@ -323,7 +323,7 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm, size_t OldSize = Data.size(); int64_t Value; - if (AddrDelta.evaluateAsAbsolute(Value, Layout)) + if (AddrDelta.evaluateAsAbsolute(Value, Asm)) return false; bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout); assert(IsAbsolute && "CFA with invalid expression"); @@ -389,7 +389,7 @@ bool LoongArchAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, auto &Layout = *Asm.getLayout(); int64_t Value; - if (AddrDelta.evaluateAsAbsolute(Value, Layout)) + if (AddrDelta.evaluateAsAbsolute(Value, Asm)) return false; bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout); assert(IsAbsolute && "CFA with invalid expression"); diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp index 445e589..e8d7fdc 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -278,7 +278,7 @@ bool RISCVAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, size_t OldSize = Data.size(); int64_t Value; - if (AddrDelta.evaluateAsAbsolute(Value, Layout)) + if (AddrDelta.evaluateAsAbsolute(Value, Asm)) return false; [[maybe_unused]] bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout); -- cgit v1.1 From 03e46475f510d9d7fa813dcfa1fd91894af39862 Mon Sep 17 00:00:00 2001 From: aaryanshukla <53713108+aaryanshukla@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:43:59 -0700 Subject: [libc] implemented add_function to yaml hdrgen (#97079) users can now input a new function in the CLI: the yaml, and .h will be updated instantly tested on different cases and does not change the yaml format in anyway except decreasing extra spaces if present --- libc/newhdrgen/yaml_to_classes.py | 96 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 4 deletions(-) diff --git a/libc/newhdrgen/yaml_to_classes.py b/libc/newhdrgen/yaml_to_classes.py index 7159dd9..9b52c9c 100644 --- a/libc/newhdrgen/yaml_to_classes.py +++ b/libc/newhdrgen/yaml_to_classes.py @@ -10,7 +10,6 @@ import yaml -import re import argparse from pathlib import Path @@ -54,10 +53,10 @@ def yaml_to_classes(yaml_data): standards = (function_data.get("standards", None),) header.add_function( Function( - standards, function_data["return_type"], function_data["name"], arguments, + standards, guard, attributes, ) @@ -103,7 +102,79 @@ def fill_public_api(header_str, h_def_content): return h_def_content.replace("%%public_api()", header_str, 1) -def main(yaml_file, h_def_file, output_dir): +def parse_function_details(details): + """ + Parse function details from a list of strings and return a Function object. + + Args: + details: A list containing function details + + Returns: + Function: An instance of Function initialized with the details. + """ + return_type, name, arguments, standards, guard, attributes = details + standards = standards.split(",") if standards != "null" else [] + arguments = [arg.strip() for arg in arguments.split(",")] + attributes = attributes.split(",") if attributes != "null" else [] + + return Function( + return_type=return_type, + name=name, + arguments=arguments, + standards=standards, + guard=guard if guard != "null" else None, + attributes=attributes if attributes else [], + ) + + +def add_function_to_yaml(yaml_file, function_details): + """ + Add a function to the YAML file. + + Args: + yaml_file: The path to the YAML file. + function_details: A list containing function details (return_type, name, arguments, standards, guard, attributes). + """ + new_function = parse_function_details(function_details) + + with open(yaml_file, "r") as f: + yaml_data = yaml.safe_load(f) + + if "functions" not in yaml_data: + yaml_data["functions"] = [] + + function_dict = { + "name": new_function.name, + "standards": new_function.standards, + "return_type": new_function.return_type, + "arguments": [{"type": arg} for arg in new_function.arguments], + } + + if new_function.guard: + function_dict["guard"] = new_function.guard + + if new_function.attributes: + function_dict["attributes"] = new_function.attributes + + yaml_data["functions"].append(function_dict) + + class IndentYamlListDumper(yaml.Dumper): + def increase_indent(self, flow=False, indentless=False): + return super(IndentYamlListDumper, self).increase_indent(flow, False) + + with open(yaml_file, "w") as f: + yaml.dump( + yaml_data, + f, + Dumper=IndentYamlListDumper, + default_flow_style=False, + sort_keys=False, + ) + + print(f"Added function {new_function.name} to {yaml_file}") + + +def main(yaml_file, h_def_file, output_dir, add_function=None): """ Main function to generate header files from YAML and .h.def templates. @@ -111,8 +182,12 @@ def main(yaml_file, h_def_file, output_dir): yaml_file: Path to the YAML file containing header specification. h_def_file: Path to the .h.def template file. output_dir: Directory to output the generated header file. + add_function: Details of the function to be added to the YAML file (if any). """ + if add_function: + add_function_to_yaml(yaml_file, add_function) + header = load_yaml_file(yaml_file) with open(h_def_file, "r") as f: @@ -143,6 +218,19 @@ if __name__ == "__main__": default=".", help="Directory to output the generated header file", ) + parser.add_argument( + "--add_function", + nargs=6, + metavar=( + "RETURN_TYPE", + "NAME", + "ARGUMENTS", + "STANDARDS", + "GUARD", + "ATTRIBUTES", + ), + help="Add a function to the YAML file", + ) args = parser.parse_args() - main(args.yaml_file, args.h_def_file, args.output_dir) + main(args.yaml_file, args.h_def_file, args.output_dir, args.add_function) -- cgit v1.1 From ffca4ef5b1a8eff6097454df4b0f212e2393e41e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Horv=C3=A1th?= Date: Mon, 1 Jul 2024 23:56:59 +0100 Subject: [clang] Remove a pointer union from the lifetime bound analysis (#97327) Since all callers of the API is called with the same type, we do not actually need the pointer union. --- clang/lib/Sema/CheckExprLifetime.cpp | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/clang/lib/Sema/CheckExprLifetime.cpp b/clang/lib/Sema/CheckExprLifetime.cpp index be77949..fea0239 100644 --- a/clang/lib/Sema/CheckExprLifetime.cpp +++ b/clang/lib/Sema/CheckExprLifetime.cpp @@ -966,27 +966,11 @@ static bool pathOnlyInitializesGslPointer(IndirectLocalPath &Path) { return false; } -static void checkExprLifetimeImpl( - Sema &SemaRef, - llvm::PointerUnion - CEntity, - Expr *Init) { - LifetimeKind LK = LK_FullExpression; - - const AssignedEntity *AEntity = nullptr; - // Local variables for initialized entity. - const InitializedEntity *InitEntity = nullptr; - const InitializedEntity *ExtendingEntity = nullptr; - if (CEntity.is()) { - InitEntity = CEntity.get(); - auto LTResult = getEntityLifetime(InitEntity); - LK = LTResult.getInt(); - ExtendingEntity = LTResult.getPointer(); - } else { - AEntity = CEntity.get(); - if (AEntity->LHS->getType()->isPointerType()) // builtin pointer type - LK = LK_Extended; - } +static void checkExprLifetimeImpl(Sema &SemaRef, + const InitializedEntity *InitEntity, + const InitializedEntity *ExtendingEntity, + LifetimeKind LK, + const AssignedEntity *AEntity, Expr *Init) { // If this entity doesn't have an interesting lifetime, don't bother looking // for temporaries within its initializer. if (LK == LK_FullExpression) @@ -1292,12 +1276,18 @@ static void checkExprLifetimeImpl( void checkExprLifetime(Sema &SemaRef, const InitializedEntity &Entity, Expr *Init) { - checkExprLifetimeImpl(SemaRef, &Entity, Init); + auto LTResult = getEntityLifetime(&Entity); + LifetimeKind LK = LTResult.getInt(); + const InitializedEntity *ExtendingEntity = LTResult.getPointer(); + checkExprLifetimeImpl(SemaRef, &Entity, ExtendingEntity, LK, nullptr, Init); } void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity, Expr *Init) { - checkExprLifetimeImpl(SemaRef, &Entity, Init); + LifetimeKind LK = LK_FullExpression; + if (Entity.LHS->getType()->isPointerType()) // builtin pointer type + LK = LK_Extended; + checkExprLifetimeImpl(SemaRef, nullptr, nullptr, LK, &Entity, Init); } } // namespace clang::sema -- cgit v1.1 From f22af401a4535f66751f24ade2a948ef695512d9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 16:07:48 -0700 Subject: [MC,AMDGPU] Migrate MCAsmLayout to MCAssembler --- .../Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp | 31 +++++++++++++--------- llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h | 8 +++--- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp index 83fbf4a..4962b79 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp @@ -10,6 +10,8 @@ #include "GCNSubtarget.h" #include "Utils/AMDGPUBaseInfo.h" #include "llvm/IR/Function.h" +#include "llvm/MC/MCAsmLayout.h" +#include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" @@ -93,11 +95,12 @@ static int64_t op(AMDGPUMCExpr::VariantKind Kind, int64_t Arg1, int64_t Arg2) { } } -bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -123,11 +126,12 @@ bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAsmLayout *Layout, return true; } -bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -151,11 +155,12 @@ bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAsmLayout *Layout, return true; } -bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -173,11 +178,12 @@ bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAsmLayout *Layout, return true; } -bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res, const MCAsmLayout *Layout, +bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Layout, Fixup) || + if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, + Fixup) || !MCVal.isAbsolute()) return false; @@ -221,18 +227,19 @@ bool AMDGPUMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const { std::optional Total; + MCAssembler *Asm = Layout ? &Layout->getAssembler() : nullptr; switch (Kind) { default: break; case AGVK_ExtraSGPRs: - return evaluateExtraSGPRs(Res, Layout, Fixup); + return evaluateExtraSGPRs(Res, Asm, Fixup); case AGVK_AlignTo: - return evaluateAlignTo(Res, Layout, Fixup); + return evaluateAlignTo(Res, Asm, Fixup); case AGVK_TotalNumVGPRs: - return evaluateTotalNumVGPR(Res, Layout, Fixup); + return evaluateTotalNumVGPR(Res, Asm, Fixup); case AGVK_Occupancy: - return evaluateOccupancy(Res, Layout, Fixup); + return evaluateOccupancy(Res, Asm, Fixup); } for (const MCExpr *Arg : Args) { diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h index 207a619..9b2e2a6 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h @@ -48,13 +48,13 @@ private: AMDGPUMCExpr(VariantKind Kind, ArrayRef Args, MCContext &Ctx); ~AMDGPUMCExpr(); - bool evaluateExtraSGPRs(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; - bool evaluateTotalNumVGPR(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; - bool evaluateAlignTo(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAlignTo(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; - bool evaluateOccupancy(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateOccupancy(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; public: -- cgit v1.1 From bf6f2c1c431943c69892d9b0355da91e95090601 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 1 Jul 2024 16:11:09 -0700 Subject: [CodeGen] Use range-based for loops (NFC) (#97187) --- llvm/lib/CodeGen/MachineSSAUpdater.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/CodeGen/MachineSSAUpdater.cpp b/llvm/lib/CodeGen/MachineSSAUpdater.cpp index ffe1df4..4cbb6ad 100644 --- a/llvm/lib/CodeGen/MachineSSAUpdater.cpp +++ b/llvm/lib/CodeGen/MachineSSAUpdater.cpp @@ -89,8 +89,8 @@ Register LookForIdenticalPHI(MachineBasicBlock *BB, return Register(); AvailableValsTy AVals; - for (unsigned i = 0, e = PredValues.size(); i != e; ++i) - AVals[PredValues[i].first] = PredValues[i].second; + for (const auto &[SrcBB, SrcReg] : PredValues) + AVals[SrcBB] = SrcReg; while (I != BB->end() && I->isPHI()) { bool Same = true; for (unsigned i = 1, e = I->getNumOperands(); i != e; i += 2) { @@ -196,8 +196,8 @@ Register MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB, InsertNewDef(TargetOpcode::PHI, BB, Loc, RegAttrs, MRI, TII); // Fill in all the predecessors of the PHI. - for (unsigned i = 0, e = PredValues.size(); i != e; ++i) - InsertedPHI.addReg(PredValues[i].second).addMBB(PredValues[i].first); + for (const auto &[SrcBB, SrcReg] : PredValues) + InsertedPHI.addReg(SrcReg).addMBB(SrcBB); // See if the PHI node can be merged to a single value. This can happen in // loop cases when we get a PHI of itself and one other value. -- cgit v1.1 From e25e8003ca2e9d623666b1cd65d4b98648416dd3 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 16:23:43 -0700 Subject: MCExpr::evaluateAsRelocatable: replace the MCAsmLayout parameter with MCAssembler Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95. --- llvm/include/llvm/MC/MCExpr.h | 7 +++---- llvm/lib/MC/MCAssembler.cpp | 2 +- llvm/lib/MC/MCExpr.cpp | 9 +++------ llvm/lib/MC/MachObjectWriter.cpp | 3 ++- .../Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp | 8 ++++---- .../Target/AArch64/MCTargetDesc/AArch64MCExpr.h | 4 ++-- .../Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp | 23 ++++++---------------- llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h | 2 +- llvm/lib/Target/ARM/MCTargetDesc/ARMMCExpr.h | 3 +-- llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp | 8 ++++---- llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.h | 2 +- llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.cpp | 5 ++--- llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.h | 2 +- .../Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp | 4 ++-- .../Target/Hexagon/MCTargetDesc/HexagonMCExpr.h | 2 +- llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.cpp | 4 ++-- llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.h | 2 +- .../LoongArch/MCTargetDesc/LoongArchMCExpr.cpp | 2 +- .../LoongArch/MCTargetDesc/LoongArchMCExpr.h | 2 +- llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp | 12 +++++------ llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h | 2 +- llvm/lib/Target/NVPTX/NVPTXMCExpr.h | 6 ++---- llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp | 12 +++++------ llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h | 3 +-- .../Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 3 +-- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp | 2 +- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h | 2 +- llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp | 9 ++++----- llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h | 3 +-- .../Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp | 4 ++-- .../Target/SystemZ/MCTargetDesc/SystemZMCExpr.h | 2 +- llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp | 5 ++--- llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h | 2 +- llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h | 2 +- .../Target/Xtensa/MCTargetDesc/XtensaMCExpr.cpp | 4 ++-- llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.h | 2 +- 36 files changed, 71 insertions(+), 98 deletions(-) diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h index 3c051b5..38b89d5 100644 --- a/llvm/include/llvm/MC/MCExpr.h +++ b/llvm/include/llvm/MC/MCExpr.h @@ -107,10 +107,10 @@ public: /// expression of the fixed form (a - b + constant). /// /// \param Res - The relocatable value, if evaluation succeeds. - /// \param Layout - The assembler layout object to use for evaluating values. + /// \param Asm - The assembler object to use for evaluating values. /// \param Fixup - The Fixup object if available. /// \return - True on success. - bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const; /// Try to evaluate the expression to the form (a - b + constant) where @@ -656,8 +656,7 @@ protected: public: virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const = 0; - virtual bool evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + virtual bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const = 0; // allow Target Expressions to be checked for equality virtual bool isEqualTo(const MCExpr *x) const { return false; } diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index e8a7eae..532f68b 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -187,7 +187,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF, MCContext &Ctx = getContext(); Value = 0; WasForced = false; - if (!Expr->evaluateAsRelocatable(Target, Layout, &Fixup)) { + if (!Expr->evaluateAsRelocatable(Target, this, &Fixup)) { Ctx.reportError(Fixup.getLoc(), "expected relocatable expression"); return true; } diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index 4b778e9..7e71111 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -788,11 +788,9 @@ static bool evaluateSymbolicAdd(const MCAssembler *Asm, return true; } -bool MCExpr::evaluateAsRelocatable(MCValue &Res, - const MCAsmLayout *Layout, +bool MCExpr::evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { - MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr; - return evaluateAsRelocatableImpl(Res, Assembler, Fixup, nullptr, false); + return evaluateAsRelocatableImpl(Res, Asm, Fixup, nullptr, false); } bool MCExpr::evaluateAsValue(MCValue &Res, const MCAssembler &Asm) const { @@ -823,8 +821,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, MCAsmLayout *Layout = Asm ? Asm->getLayout() : nullptr; switch (getKind()) { case Target: - return cast(this)->evaluateAsRelocatableImpl(Res, Layout, - Fixup); + return cast(this)->evaluateAsRelocatableImpl(Res, Asm, Fixup); case Constant: Res = MCValue::get(cast(this)->getValue()); diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index 258dd69..5d656a0 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -99,7 +99,8 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S, return C->getValue(); MCValue Target; - if (!S.getVariableValue()->evaluateAsRelocatable(Target, &Layout, nullptr)) + if (!S.getVariableValue()->evaluateAsRelocatable( + Target, &Layout.getAssembler(), nullptr)) report_fatal_error("unable to evaluate offset for variable '" + S.getName() + "'"); diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp index 0c5a9d7..fb8eb9f 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp @@ -101,9 +101,9 @@ MCFragment *AArch64MCExpr::findAssociatedFragment() const { } bool AArch64MCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { - if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup)) return false; Res = @@ -187,9 +187,9 @@ MCFragment *AArch64AuthMCExpr::findAssociatedFragment() const { } bool AArch64AuthMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { - if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup)) return false; if (Res.getSymB()) diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h index 4823598..cf3a90f 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h @@ -167,7 +167,7 @@ public: MCFragment *findAssociatedFragment() const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override; @@ -201,7 +201,7 @@ public: MCFragment *findAssociatedFragment() const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; static bool classof(const MCExpr *E) { diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp index 4962b79..75b74f1 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp @@ -99,9 +99,7 @@ bool AMDGPUMCExpr::evaluateExtraSGPRs(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, - Fixup) || - !MCVal.isAbsolute()) + if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute()) return false; ConstantValue = MCVal.getConstant(); @@ -130,9 +128,7 @@ bool AMDGPUMCExpr::evaluateTotalNumVGPR(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, - Fixup) || - !MCVal.isAbsolute()) + if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute()) return false; ConstantValue = MCVal.getConstant(); @@ -159,9 +155,7 @@ bool AMDGPUMCExpr::evaluateAlignTo(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, - Fixup) || - !MCVal.isAbsolute()) + if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute()) return false; ConstantValue = MCVal.getConstant(); @@ -182,9 +176,7 @@ bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { auto TryGetMCExprValue = [&](const MCExpr *Arg, uint64_t &ConstantValue) { MCValue MCVal; - if (!Arg->evaluateAsRelocatable(MCVal, Asm ? Asm->getLayout() : nullptr, - Fixup) || - !MCVal.isAbsolute()) + if (!Arg->evaluateAsRelocatable(MCVal, Asm, Fixup) || !MCVal.isAbsolute()) return false; ConstantValue = MCVal.getConstant(); @@ -224,11 +216,9 @@ bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res, const MCAssembler *Asm, } bool AMDGPUMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { std::optional Total; - MCAssembler *Asm = Layout ? &Layout->getAssembler() : nullptr; - switch (Kind) { default: break; @@ -244,8 +234,7 @@ bool AMDGPUMCExpr::evaluateAsRelocatableImpl(MCValue &Res, for (const MCExpr *Arg : Args) { MCValue ArgRes; - if (!Arg->evaluateAsRelocatable(ArgRes, Layout, Fixup) || - !ArgRes.isAbsolute()) + if (!Arg->evaluateAsRelocatable(ArgRes, Asm, Fixup) || !ArgRes.isAbsolute()) return false; if (!Total.has_value()) diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h index 9b2e2a6..970802d 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h @@ -94,7 +94,7 @@ public: const MCExpr *getSubExpr(size_t Index) const; void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override; diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCExpr.h b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCExpr.h index edeff9c..5f32b37 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCExpr.h +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCExpr.h @@ -81,8 +81,7 @@ public: /// @} void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override { return false; } diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp index d6b6546..be3b9ab 100644 --- a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp +++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp @@ -69,10 +69,10 @@ bool AVRMCExpr::evaluateAsConstant(int64_t &Result) const { } bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { MCValue Value; - bool isRelocatable = SubExpr->evaluateAsRelocatable(Value, Layout, Fixup); + bool isRelocatable = SubExpr->evaluateAsRelocatable(Value, Asm, Fixup); if (!isRelocatable) return false; @@ -80,10 +80,10 @@ bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result, if (Value.isAbsolute()) { Result = MCValue::get(evaluateAsInt64(Value.getConstant())); } else { - if (!Layout) + if (!Asm || !Asm->getLayout()) return false; - MCContext &Context = Layout->getAssembler().getContext(); + MCContext &Context = Asm->getContext(); const MCSymbolRefExpr *Sym = Value.getSymA(); MCSymbolRefExpr::VariantKind Modifier = Sym->getKind(); if (Modifier != MCSymbolRefExpr::VK_None) diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.h b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.h index 5bf6c1a..03d3363 100644 --- a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.h +++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.h @@ -56,7 +56,7 @@ public: void setNegated(bool negated = true) { Negated = negated; } void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &streamer) const override; diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.cpp index b998982..d96b700 100644 --- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.cpp +++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.cpp @@ -109,10 +109,9 @@ void CSKYMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const { fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm); } -bool CSKYMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, +bool CSKYMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { - if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup)) return false; // Some custom fixup types are not valid with symbol difference expressions diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.h b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.h index 9e5b4ca..73aebc7 100644 --- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.h +++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYMCExpr.h @@ -55,7 +55,7 @@ public: void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp index 0cfea77..598d1e8 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp @@ -25,9 +25,9 @@ HexagonMCExpr *HexagonMCExpr::create(MCExpr const *Expr, MCContext &Ctx) { } bool HexagonMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - MCAsmLayout const *Layout, + const MCAssembler *Asm, MCFixup const *Fixup) const { - return Expr->evaluateAsRelocatable(Res, Layout, Fixup); + return Expr->evaluateAsRelocatable(Res, Asm, Fixup); } void HexagonMCExpr::visitUsedExpr(MCStreamer &Streamer) const { diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h index 6438ac9..eda96e2 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h @@ -16,7 +16,7 @@ class HexagonMCExpr : public MCTargetExpr { public: static HexagonMCExpr *create(MCExpr const *Expr, MCContext &Ctx); void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override; diff --git a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.cpp b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.cpp index 56d5fbf..285e938 100644 --- a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.cpp +++ b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.cpp @@ -47,9 +47,9 @@ void LanaiMCExpr::visitUsedExpr(MCStreamer &Streamer) const { } bool LanaiMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { - if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup)) return false; Res = diff --git a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.h b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.h index c99af32..1829165 100644 --- a/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.h +++ b/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCExpr.h @@ -36,7 +36,7 @@ public: const MCExpr *getSubExpr() const { return Expr; } void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override { diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp index 34f9bc6..9b53779 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp @@ -44,7 +44,7 @@ void LoongArchMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { } bool LoongArchMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { // Explicitly drop the layout and assembler to prevent any symbolic folding in // the expression handling. This is required to preserve symbolic difference diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h index 71dd5bd..148fea3 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h @@ -92,7 +92,7 @@ public: bool getRelaxHint() const { return RelaxHint; } void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override { diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp index a25783b..c856aa8 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp @@ -129,16 +129,14 @@ void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { OS << ')'; } -bool -MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, - const MCFixup *Fixup) const { +bool MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, + const MCFixup *Fixup) const { // Look for the %hi(%neg(%gp_rel(X))) and %lo(%neg(%gp_rel(X))) special cases. if (isGpOff()) { const MCExpr *SubExpr = cast(cast(getSubExpr())->getSubExpr()) ->getSubExpr(); - if (!SubExpr->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!SubExpr->evaluateAsRelocatable(Res, Asm, Fixup)) return false; Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), @@ -146,7 +144,7 @@ MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res, return true; } - if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup)) return false; if (Res.getRefKind() != MCSymbolRefExpr::VK_None) @@ -164,7 +162,7 @@ MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res, case MEK_DTPREL: // MEK_DTPREL is used for marking TLS DIEExpr only // and contains a regular sub-expression. - return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup); + return getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup); case MEK_DTPREL_HI: case MEK_DTPREL_LO: case MEK_GOT: diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h index edc12e8..2dc3661e 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h @@ -67,7 +67,7 @@ public: const MCExpr *getSubExpr() const { return Expr; } void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; diff --git a/llvm/lib/Target/NVPTX/NVPTXMCExpr.h b/llvm/lib/Target/NVPTX/NVPTXMCExpr.h index ef99def..d95b61c 100644 --- a/llvm/lib/Target/NVPTX/NVPTXMCExpr.h +++ b/llvm/lib/Target/NVPTX/NVPTXMCExpr.h @@ -74,8 +74,7 @@ public: /// @} void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override { return false; } @@ -116,8 +115,7 @@ public: /// @} void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override { return false; } diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp index 6cd04ee..05fc733 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp @@ -99,13 +99,11 @@ PPCMCExpr::evaluateAsInt64(int64_t Value) const { llvm_unreachable("Invalid kind!"); } -bool -PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, - const MCFixup *Fixup) const { +bool PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, + const MCFixup *Fixup) const { MCValue Value; - if (!getSubExpr()->evaluateAsRelocatable(Value, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Value, Asm, Fixup)) return false; if (Value.isAbsolute()) { @@ -124,10 +122,10 @@ PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, Res = MCValue::get(Result); } else { - if (!Layout) + if (!Asm || !Asm->getLayout()) return false; - MCContext &Context = Layout->getAssembler().getContext(); + MCContext &Context = Asm->getContext(); const MCSymbolRefExpr *Sym = Value.getSymA(); MCSymbolRefExpr::VariantKind Modifier = Sym->getKind(); if (Modifier != MCSymbolRefExpr::VK_None) diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h index 1dbc7ea..6209601 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h @@ -71,8 +71,7 @@ public: /// @} void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override { diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp index e8d7fdc..bbb8914 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -549,8 +549,7 @@ bool RISCVAsmBackend::evaluateTargetFixup(const MCAssembler &Asm, // MCAssembler::evaluateFixup will emit an error for this case when it sees // the %pcrel_hi, so don't duplicate it when also seeing the %pcrel_lo. const MCExpr *AUIPCExpr = AUIPCFixup->getValue(); - if (!AUIPCExpr->evaluateAsRelocatable(AUIPCTarget, Asm.getLayout(), - AUIPCFixup)) + if (!AUIPCExpr->evaluateAsRelocatable(AUIPCTarget, &Asm, AUIPCFixup)) return true; break; } diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp index d83dadd..3b5f37d 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp @@ -90,7 +90,7 @@ const MCFixup *RISCVMCExpr::getPCRelHiFixup(const MCFragment **DFOut) const { } bool RISCVMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { // Explicitly drop the layout and assembler to prevent any symbolic folding in // the expression handling. This is required to preserve symbolic difference diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h index fcc4c5c..d144548 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h @@ -69,7 +69,7 @@ public: const MCFixup *getPCRelHiFixup(const MCFragment **DFOut) const; void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override { diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp index 4688837..3da19a8 100644 --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp @@ -180,11 +180,10 @@ Sparc::Fixups SparcMCExpr::getFixupKind(SparcMCExpr::VariantKind Kind) { } } -bool -SparcMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, - const MCFixup *Fixup) const { - return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup); +bool SparcMCExpr::evaluateAsRelocatableImpl(MCValue &Res, + const MCAssembler *Asm, + const MCFixup *Fixup) const { + return getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup); } static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) { diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h index d26a748..74f90ae 100644 --- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h +++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCExpr.h @@ -94,8 +94,7 @@ public: /// @} void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override { diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp index 647cf76..4fa2028 100644 --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.cpp @@ -37,9 +37,9 @@ void SystemZMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { } bool SystemZMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { - if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup)) return false; Res = diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h index 62e6109..98f3a23 100644 --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCExpr.h @@ -45,7 +45,7 @@ public: StringRef getVariantKindName() const; void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override { Streamer.visitUsedExpr(*getSubExpr()); diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp index a104510..45c768e 100644 --- a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp +++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp @@ -173,10 +173,9 @@ VE::Fixups VEMCExpr::getFixupKind(VEMCExpr::VariantKind Kind) { } } -bool VEMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, +bool VEMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const { - if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup)) + if (!getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup)) return false; Res = diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h index 2da956d..ec71f9d 100644 --- a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h +++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h @@ -69,7 +69,7 @@ public: /// @} void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override { diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h b/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h index db91d38..c159d30 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h @@ -53,7 +53,7 @@ public: OS << X86ATTInstPrinter::getRegisterName(RegNo); } - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override { return false; } diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.cpp b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.cpp index cafd8b7..900ce3c 100644 --- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.cpp +++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.cpp @@ -41,9 +41,9 @@ void XtensaMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const { } bool XtensaMCExpr::evaluateAsRelocatableImpl(MCValue &Res, - const MCAsmLayout *Layout, + const MCAssembler *Asm, const MCFixup *Fixup) const { - return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup); + return getSubExpr()->evaluateAsRelocatable(Res, Asm, Fixup); } void XtensaMCExpr::visitUsedExpr(MCStreamer &Streamer) const { diff --git a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.h b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.h index 4cc78fe..92ffb5c 100644 --- a/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.h +++ b/llvm/lib/Target/Xtensa/MCTargetDesc/XtensaMCExpr.h @@ -40,7 +40,7 @@ public: const MCExpr *getSubExpr() const { return Expr; } void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; - bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, + bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCFixup *Fixup) const override; void visitUsedExpr(MCStreamer &Streamer) const override; MCFragment *findAssociatedFragment() const override { -- cgit v1.1 From cbd3f252e3ff2115497c771590f69f1c989b402e Mon Sep 17 00:00:00 2001 From: Chengjunp Date: Mon, 1 Jul 2024 16:30:33 -0700 Subject: [NVPTX] Support inline asm with 128-bit operand in NVPTX backend (#97113) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change supports the 128-bit operands for inline ptx asm, both input and output.\ \ The major changes are: - Tablegen:\     Define Int128Regs in NVPTXRegisterInfo.td. But this register does not set as general register type in NVPTX backend so that this change will not influence the codegen without inline asm.\     Define three NVPTX intrinsics, IMOV128rr, V2I64toI128 and I128toV2I64. The first one moves a register, the second one moves two 64-bit registers into one 128-bit register, and the third one just does the opposite. - NVPTXISelLowering & NVPTXISelDAGToDAG:\     Custom lowering CopyToReg and CopyFromReg with 128-bit operands. CopyToReg deals with the inputs of the inline asm and the CopyFromReg deals with the outputs.\     CopyToReg is custom lowered into a V2I64toI128, which takes in the expanded values(Lo and Hi) of the input, and moves into a 128-bit reg.\     CopyFromReg is custom lowered by adding a I128toV2I64, which breaks down the 128-bit outputs of inline asm into the expanded values. --- clang/lib/Basic/Targets/NVPTX.h | 1 + llvm/docs/LangRef.rst | 1 + .../Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp | 3 + llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 2 + llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp | 68 ++++++++++ llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h | 3 +- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp | 88 ++++++++++++ llvm/lib/Target/NVPTX/NVPTXISelLowering.h | 8 ++ llvm/lib/Target/NVPTX/NVPTXInstrInfo.cpp | 2 + llvm/lib/Target/NVPTX/NVPTXInstrInfo.td | 12 +- llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp | 4 + llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td | 3 + llvm/test/CodeGen/NVPTX/inline-asm-b128-test1.ll | 148 +++++++++++++++++++++ llvm/test/CodeGen/NVPTX/inline-asm-b128-test2.ll | 122 +++++++++++++++++ llvm/test/CodeGen/NVPTX/inline-asm-b128-test3.ll | 67 ++++++++++ 15 files changed, 529 insertions(+), 3 deletions(-) create mode 100644 llvm/test/CodeGen/NVPTX/inline-asm-b128-test1.ll create mode 100644 llvm/test/CodeGen/NVPTX/inline-asm-b128-test2.ll create mode 100644 llvm/test/CodeGen/NVPTX/inline-asm-b128-test3.ll diff --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h index a5daf36..9a985e4 100644 --- a/clang/lib/Basic/Targets/NVPTX.h +++ b/clang/lib/Basic/Targets/NVPTX.h @@ -105,6 +105,7 @@ public: case 'l': case 'f': case 'd': + case 'q': Info.setAllowsRegister(); return true; } diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 211fee5..e2c4720 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -5381,6 +5381,7 @@ NVPTX: - ``c`` or ``h``: A 16-bit integer register. - ``r``: A 32-bit integer register. - ``l`` or ``N``: A 64-bit integer register. +- ``q``: A 128-bit integer register. - ``f``: A 32-bit float register. - ``d``: A 64-bit float register. diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp index b7a20c3..380d878 100644 --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXInstPrinter.cpp @@ -60,6 +60,9 @@ void NVPTXInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) const { case 6: OS << "%fd"; break; + case 7: + OS << "%rq"; + break; } unsigned VReg = Reg.id() & 0x0FFFFFFF; diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index ca077d4..1645261 100644 --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -315,6 +315,8 @@ unsigned NVPTXAsmPrinter::encodeVirtualRegister(unsigned Reg) { Ret = (5 << 28); } else if (RC == &NVPTX::Float64RegsRegClass) { Ret = (6 << 28); + } else if (RC == &NVPTX::Int128RegsRegClass) { + Ret = (7 << 28); } else { report_fatal_error("Bad register class"); } diff --git a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp index 1e1cbb1..11193c1 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp @@ -519,6 +519,20 @@ void NVPTXDAGToDAGISel::Select(SDNode *N) { if (tryConstantFP(N)) return; break; + case ISD::CopyToReg: { + if (N->getOperand(1).getValueType() == MVT::i128) { + SelectV2I64toI128(N); + return; + } + break; + } + case ISD::CopyFromReg: { + if (N->getOperand(1).getValueType() == MVT::i128) { + SelectI128toV2I64(N); + return; + } + break; + } default: break; } @@ -3798,6 +3812,60 @@ bool NVPTXDAGToDAGISel::SelectInlineAsmMemoryOperand( return true; } +void NVPTXDAGToDAGISel::SelectV2I64toI128(SDNode *N) { + // Lower a CopyToReg with two 64-bit inputs + // Dst:i128, lo:i64, hi:i64 + // + // CopyToReg Dst, lo, hi; + // + // ==> + // + // tmp = V2I64toI128 {lo, hi}; + // CopyToReg Dst, tmp; + SDValue Dst = N->getOperand(1); + SDValue Lo = N->getOperand(2); + SDValue Hi = N->getOperand(3); + + SDLoc DL(N); + SDNode *Mov = + CurDAG->getMachineNode(NVPTX::V2I64toI128, DL, MVT::i128, {Lo, Hi}); + + SmallVector NewOps(N->getNumOperands() - 1); + NewOps[0] = N->getOperand(0); + NewOps[1] = Dst; + NewOps[2] = SDValue(Mov, 0); + if (N->getNumOperands() == 5) + NewOps[3] = N->getOperand(4); + SDValue NewValue = CurDAG->getNode(ISD::CopyToReg, DL, SmallVector(N->values()), NewOps); + + ReplaceNode(N, NewValue.getNode()); +} + +void NVPTXDAGToDAGISel::SelectI128toV2I64(SDNode *N) { + // Lower CopyFromReg from a 128-bit regs to two 64-bit regs + // Dst:i128, Src:i128 + // + // {lo, hi} = CopyFromReg Src + // + // ==> + // + // {lo, hi} = I128toV2I64 Src + // + SDValue Ch = N->getOperand(0); + SDValue Src = N->getOperand(1); + SDValue Glue = N->getOperand(2); + SDLoc DL(N); + + // Add Glue and Ch to the operands and results to avoid break the execution + // order + SDNode *Mov = CurDAG->getMachineNode( + NVPTX::I128toV2I64, DL, + {MVT::i64, MVT::i64, Ch.getValueType(), Glue.getValueType()}, + {Src, Ch, Glue}); + + ReplaceNode(N, Mov); +} + /// GetConvertOpcode - Returns the CVT_ instruction opcode that implements a /// conversion from \p SrcTy to \p DestTy. unsigned NVPTXDAGToDAGISel::GetConvertOpcode(MVT DestTy, MVT SrcTy, diff --git a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h index c552435..49626d4 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h +++ b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.h @@ -74,7 +74,8 @@ private: bool SelectSETP_F16X2(SDNode *N); bool SelectSETP_BF16X2(SDNode *N); bool tryEXTRACT_VECTOR_ELEMENT(SDNode *N); - + void SelectV2I64toI128(SDNode *N); + void SelectI128toV2I64(SDNode *N); inline SDValue getI32Imm(unsigned Imm, const SDLoc &DL) { return CurDAG->getTargetConstant(Imm, DL, MVT::i32); } diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp index 476a532..26c16ee 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -859,6 +859,10 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM, setBF16OperationAction(Op, MVT::v2bf16, Legal, Expand); } + // Custom lowering for inline asm with 128-bit operands + setOperationAction(ISD::CopyToReg, MVT::i128, Custom); + setOperationAction(ISD::CopyFromReg, MVT::i128, Custom); + // No FEXP2, FLOG2. The PTX ex2 and log2 functions are always approximate. // No FPOW or FREM in PTX. @@ -2804,6 +2808,8 @@ NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { return LowerVectorArith(Op, DAG); case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); + case ISD::CopyToReg: + return LowerCopyToReg_128(Op, DAG); default: llvm_unreachable("Custom lowering not defined for operation"); } @@ -3094,6 +3100,54 @@ SDValue NVPTXTargetLowering::LowerSTOREi1(SDValue Op, SelectionDAG &DAG) const { return Result; } +SDValue NVPTXTargetLowering::LowerCopyToReg_128(SDValue Op, + SelectionDAG &DAG) const { + // Change the CopyToReg to take in two 64-bit operands instead of a 128-bit + // operand so that it can pass the legalization. + + assert(Op.getOperand(1).getValueType() == MVT::i128 && + "Custom lowering for 128-bit CopyToReg only"); + + SDNode *Node = Op.getNode(); + SDLoc DL(Node); + + SDValue Cast = DAG.getBitcast(MVT::v2i64, Op->getOperand(2)); + SDValue Lo = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i64, Cast, + DAG.getIntPtrConstant(0, DL)); + SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i64, Cast, + DAG.getIntPtrConstant(1, DL)); + + SmallVector NewOps(Op->getNumOperands() + 1); + SmallVector ResultsType(Node->values()); + + NewOps[0] = Op->getOperand(0); // Chain + NewOps[1] = Op->getOperand(1); // Dst Reg + NewOps[2] = Lo; // Lower 64-bit + NewOps[3] = Hi; // Higher 64-bit + if (Op.getNumOperands() == 4) + NewOps[4] = Op->getOperand(3); // Glue if exists + + return DAG.getNode(ISD::CopyToReg, DL, ResultsType, NewOps); +} + +unsigned NVPTXTargetLowering::getNumRegisters( + LLVMContext &Context, EVT VT, + std::optional RegisterVT = std::nullopt) const { + if (VT == MVT::i128 && RegisterVT == MVT::i128) + return 1; + return TargetLoweringBase::getNumRegisters(Context, VT, RegisterVT); +} + +bool NVPTXTargetLowering::splitValueIntoRegisterParts( + SelectionDAG &DAG, const SDLoc &DL, SDValue Val, SDValue *Parts, + unsigned NumParts, MVT PartVT, std::optional CC) const { + if (Val.getValueType() == MVT::i128 && NumParts == 1) { + Parts[0] = Val; + return true; + } + return false; +} + // This creates target external symbol for a function parameter. // Name of the symbol is composed from its index and the function name. // Negative index corresponds to special parameter (unsized array) used for @@ -5150,6 +5204,7 @@ NVPTXTargetLowering::getConstraintType(StringRef Constraint) const { case 'l': case 'f': case 'd': + case 'q': case '0': case 'N': return C_RegisterClass; @@ -5175,6 +5230,12 @@ NVPTXTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, case 'l': case 'N': return std::make_pair(0U, &NVPTX::Int64RegsRegClass); + case 'q': { + if (STI.getSmVersion() < 70) + report_fatal_error("Inline asm with 128 bit operands is only " + "supported for sm_70 and higher!"); + return std::make_pair(0U, &NVPTX::Int128RegsRegClass); + } case 'f': return std::make_pair(0U, &NVPTX::Float32RegsRegClass); case 'd': @@ -6261,6 +6322,30 @@ static void ReplaceINTRINSIC_W_CHAIN(SDNode *N, SelectionDAG &DAG, } } +static void ReplaceCopyFromReg_128(SDNode *N, SelectionDAG &DAG, + SmallVectorImpl &Results) { + // Change the CopyFromReg to output 2 64-bit results instead of a 128-bit + // result so that it can pass the legalization + SDLoc DL(N); + SDValue Chain = N->getOperand(0); + SDValue Reg = N->getOperand(1); + SDValue Glue = N->getOperand(2); + + assert(Reg.getValueType() == MVT::i128 && + "Custom lowering for CopyFromReg with 128-bit reg only"); + SmallVector ResultsType = {MVT::i64, MVT::i64, N->getValueType(1), + N->getValueType(2)}; + SmallVector NewOps = {Chain, Reg, Glue}; + + SDValue NewValue = DAG.getNode(ISD::CopyFromReg, DL, ResultsType, NewOps); + SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i128, + {NewValue.getValue(0), NewValue.getValue(1)}); + + Results.push_back(Pair); + Results.push_back(NewValue.getValue(2)); + Results.push_back(NewValue.getValue(3)); +} + void NVPTXTargetLowering::ReplaceNodeResults( SDNode *N, SmallVectorImpl &Results, SelectionDAG &DAG) const { switch (N->getOpcode()) { @@ -6272,6 +6357,9 @@ void NVPTXTargetLowering::ReplaceNodeResults( case ISD::INTRINSIC_W_CHAIN: ReplaceINTRINSIC_W_CHAIN(N, DAG, Results); return; + case ISD::CopyFromReg: + ReplaceCopyFromReg_128(N, DAG, Results); + return; } } diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.h b/llvm/lib/Target/NVPTX/NVPTXISelLowering.h index e211286..6326296 100644 --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.h +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.h @@ -640,6 +640,14 @@ private: SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const; SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; + SDValue LowerCopyToReg_128(SDValue Op, SelectionDAG &DAG) const; + unsigned getNumRegisters(LLVMContext &Context, EVT VT, + std::optional RegisterVT) const override; + bool + splitValueIntoRegisterParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val, + SDValue *Parts, unsigned NumParts, MVT PartVT, + std::optional CC) const override; + void ReplaceNodeResults(SDNode *N, SmallVectorImpl &Results, SelectionDAG &DAG) const override; SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override; diff --git a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.cpp index b0d792b..673858f 100644 --- a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.cpp @@ -51,6 +51,8 @@ void NVPTXInstrInfo::copyPhysReg(MachineBasicBlock &MBB, } else if (DestRC == &NVPTX::Int64RegsRegClass) { Op = (SrcRC == &NVPTX::Int64RegsRegClass ? NVPTX::IMOV64rr : NVPTX::BITCONVERT_64_F2I); + } else if (DestRC == &NVPTX::Int128RegsRegClass) { + Op = NVPTX::IMOV128rr; } else if (DestRC == &NVPTX::Float32RegsRegClass) { Op = (SrcRC == &NVPTX::Float32RegsRegClass ? NVPTX::FMOV32rr : NVPTX::BITCONVERT_32_I2F); diff --git a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td index c4c35a1..827febe 100644 --- a/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td +++ b/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td @@ -2097,6 +2097,8 @@ let IsSimpleMove=1, hasSideEffects=0 in { "mov.u32 \t$dst, $sss;", []>; def IMOV64rr : NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$sss), "mov.u64 \t$dst, $sss;", []>; + def IMOV128rr : NVPTXInst<(outs Int128Regs:$dst), (ins Int128Regs:$sss), + "mov.b128 \t$dst, $sss;", []>; def IMOVB16rr : NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$sss), "mov.b16 \t$dst, $sss;", []>; @@ -3545,6 +3547,9 @@ let hasSideEffects = false in { def V2I32toI64 : NVPTXInst<(outs Int64Regs:$d), (ins Int32Regs:$s1, Int32Regs:$s2), "mov.b64 \t$d, {{$s1, $s2}};", []>; + def V2I64toI128 : NVPTXInst<(outs Int128Regs:$d), + (ins Int64Regs:$s1, Int64Regs:$s2), + "mov.b128 \t$d, {{$s1, $s2}};", []>; def V2F32toF64 : NVPTXInst<(outs Float64Regs:$d), (ins Float32Regs:$s1, Float32Regs:$s2), "mov.b64 \t$d, {{$s1, $s2}};", []>; @@ -3560,6 +3565,9 @@ let hasSideEffects = false in { def I64toV2I32 : NVPTXInst<(outs Int32Regs:$d1, Int32Regs:$d2), (ins Int64Regs:$s), "mov.b64 \t{{$d1, $d2}}, $s;", []>; + def I128toV2I64: NVPTXInst<(outs Int64Regs:$d1, Int64Regs:$d2), + (ins Int128Regs:$s), + "mov.b128 \t{{$d1, $d2}}, $s;", []>; def F64toV2F32 : NVPTXInst<(outs Float32Regs:$d1, Float32Regs:$d2), (ins Float64Regs:$s), "mov.b64 \t{{$d1, $d2}}, $s;", []>; @@ -3629,7 +3637,7 @@ def : Pat<(i32 (ctlz (i32 Int32Regs:$a))), (CLZr32 Int32Regs:$a)>; // ptx value to 64 bits to match the ISD node's semantics, unless we know we're // truncating back down to 32 bits. def : Pat<(i64 (ctlz Int64Regs:$a)), (CVT_u64_u32 (CLZr64 Int64Regs:$a), CvtNONE)>; -def : Pat<(i32 (trunc (ctlz Int64Regs:$a))), (CLZr64 Int64Regs:$a)>; +def : Pat<(i32 (trunc (i64 (ctlz Int64Regs:$a)))), (CLZr64 Int64Regs:$a)>; // For 16-bit ctlz, we zero-extend to 32-bit, perform the count, then trunc the // result back to 16-bits if necessary. We also need to subtract 16 because @@ -3667,7 +3675,7 @@ def : Pat<(i32 (ctpop (i32 Int32Regs:$a))), (POPCr32 Int32Regs:$a)>; // pattern that avoids the type conversion if we're truncating the result to // i32 anyway. def : Pat<(ctpop Int64Regs:$a), (CVT_u64_u32 (POPCr64 Int64Regs:$a), CvtNONE)>; -def : Pat<(i32 (trunc (ctpop Int64Regs:$a))), (POPCr64 Int64Regs:$a)>; +def : Pat<(i32 (trunc (i64 (ctpop Int64Regs:$a)))), (POPCr64 Int64Regs:$a)>; // For 16-bit, we zero-extend to 32-bit, then trunc the result back to 16-bits. // If we know that we're storing into an i32, we can avoid the final trunc. diff --git a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp index f1213f0..a8a23f0 100644 --- a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.cpp @@ -31,6 +31,8 @@ std::string getNVPTXRegClassName(TargetRegisterClass const *RC) { return ".f32"; if (RC == &NVPTX::Float64RegsRegClass) return ".f64"; + if (RC == &NVPTX::Int128RegsRegClass) + return ".b128"; if (RC == &NVPTX::Int64RegsRegClass) // We use untyped (.b) integer registers here as NVCC does. // Correctness of generated code does not depend on register type, @@ -67,6 +69,8 @@ std::string getNVPTXRegClassStr(TargetRegisterClass const *RC) { return "%f"; if (RC == &NVPTX::Float64RegsRegClass) return "%fd"; + if (RC == &NVPTX::Int128RegsRegClass) + return "%rq"; if (RC == &NVPTX::Int64RegsRegClass) return "%rd"; if (RC == &NVPTX::Int32RegsRegClass) diff --git a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td index b5231a9..2011f0f 100644 --- a/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td +++ b/llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td @@ -37,6 +37,7 @@ foreach i = 0...4 in { def RS#i : NVPTXReg<"%rs"#i>; // 16-bit def R#i : NVPTXReg<"%r"#i>; // 32-bit def RL#i : NVPTXReg<"%rd"#i>; // 64-bit + def RQ#i : NVPTXReg<"%rq"#i>; // 128-bit def H#i : NVPTXReg<"%h"#i>; // 16-bit float def HH#i : NVPTXReg<"%hh"#i>; // 2x16-bit float def F#i : NVPTXReg<"%f"#i>; // 32-bit float @@ -62,6 +63,8 @@ def Int32Regs : NVPTXRegClass<[i32, v2f16, v2bf16, v2i16, v4i8], 32, (add (sequence "R%u", 0, 4), VRFrame32, VRFrameLocal32)>; def Int64Regs : NVPTXRegClass<[i64], 64, (add (sequence "RL%u", 0, 4), VRFrame64, VRFrameLocal64)>; +// 128-bit regs are not defined as general regs in NVPTX. They are used for inlineASM only. +def Int128Regs : NVPTXRegClass<[i128], 128, (add (sequence "RQ%u", 0, 4))>; def Float32Regs : NVPTXRegClass<[f32], 32, (add (sequence "F%u", 0, 4))>; def Float64Regs : NVPTXRegClass<[f64], 64, (add (sequence "FL%u", 0, 4))>; def Int32ArgRegs : NVPTXRegClass<[i32], 32, (add (sequence "ia%u", 0, 4))>; diff --git a/llvm/test/CodeGen/NVPTX/inline-asm-b128-test1.ll b/llvm/test/CodeGen/NVPTX/inline-asm-b128-test1.ll new file mode 100644 index 0000000..3232f40 --- /dev/null +++ b/llvm/test/CodeGen/NVPTX/inline-asm-b128-test1.ll @@ -0,0 +1,148 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --extra_scrub --version 5 +; RUN: llc < %s -march=nvptx -mcpu=sm_70 -mattr=+ptx83 | FileCheck %s +; RUN: %if ptxas %{ llc < %s -march=nvptx -mcpu=sm_70 -mattr=+ptx83 | %ptxas-verify -arch=sm_70 %} + +target triple = "nvptx64-nvidia-cuda" + +@value = internal addrspace(1) global i128 0, align 16 + +define void @test_b128_input_from_const() { +; CHECK-LABEL: test_b128_input_from_const( +; CHECK: { +; CHECK-NEXT: .reg .b32 %r<3>; +; CHECK-NEXT: .reg .b64 %rd<4>; +; CHECK-NEXT: .reg .b128 %rq<2>; +; CHECK-EMPTY: +; CHECK-NEXT: // %bb.0: +; CHECK-NEXT: mov.u64 %rd2, 0; +; CHECK-NEXT: mov.u64 %rd3, 42; +; CHECK-NEXT: mov.b128 %rq1, {%rd3, %rd2}; +; CHECK-NEXT: mov.u32 %r1, value; +; CHECK-NEXT: cvta.global.u32 %r2, %r1; +; CHECK-NEXT: cvt.u64.u32 %rd1, %r2; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { st.b128 [%rd1], %rq1; } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: ret; + + tail call void asm sideeffect "{ st.b128 [$0], $1; }", "l,q"(ptr nonnull addrspacecast (ptr addrspace(1) @value to ptr), i128 42) + ret void +} + +define void @test_b128_input_from_load(ptr nocapture readonly %data) { +; CHECK-LABEL: test_b128_input_from_load( +; CHECK: { +; CHECK-NEXT: .reg .b32 %r<5>; +; CHECK-NEXT: .reg .b64 %rd<4>; +; CHECK-NEXT: .reg .b128 %rq<2>; +; CHECK-EMPTY: +; CHECK-NEXT: // %bb.0: +; CHECK-NEXT: ld.param.u32 %r1, [test_b128_input_from_load_param_0]; +; CHECK-NEXT: cvta.to.global.u32 %r2, %r1; +; CHECK-NEXT: ld.global.u64 %rd2, [%r2+8]; +; CHECK-NEXT: ld.global.u64 %rd3, [%r2]; +; CHECK-NEXT: mov.b128 %rq1, {%rd3, %rd2}; +; CHECK-NEXT: mov.u32 %r3, value; +; CHECK-NEXT: cvta.global.u32 %r4, %r3; +; CHECK-NEXT: cvt.u64.u32 %rd1, %r4; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { st.b128 [%rd1], %rq1; } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: ret; + + %1 = addrspacecast ptr %data to ptr addrspace(1) + %2 = load <2 x i64>, ptr addrspace(1) %1, align 16 + %3 = bitcast <2 x i64> %2 to i128 + tail call void asm sideeffect "{ st.b128 [$0], $1; }", "l,q"(ptr nonnull addrspacecast (ptr addrspace(1) @value to ptr), i128 %3) + ret void +} + +define void @test_b128_input_from_select(ptr nocapture readonly %flag) { +; CHECK-LABEL: test_b128_input_from_select( +; CHECK: { +; CHECK-NEXT: .reg .pred %p<2>; +; CHECK-NEXT: .reg .b16 %rs<2>; +; CHECK-NEXT: .reg .b32 %r<5>; +; CHECK-NEXT: .reg .b64 %rd<4>; +; CHECK-NEXT: .reg .b128 %rq<2>; +; CHECK-EMPTY: +; CHECK-NEXT: // %bb.0: +; CHECK-NEXT: ld.param.u32 %r1, [test_b128_input_from_select_param_0]; +; CHECK-NEXT: cvta.to.global.u32 %r2, %r1; +; CHECK-NEXT: ld.global.u8 %rs1, [%r2]; +; CHECK-NEXT: setp.eq.s16 %p1, %rs1, 0; +; CHECK-NEXT: selp.b64 %rd2, 24, 42, %p1; +; CHECK-NEXT: mov.u64 %rd3, 0; +; CHECK-NEXT: mov.b128 %rq1, {%rd2, %rd3}; +; CHECK-NEXT: mov.u32 %r3, value; +; CHECK-NEXT: cvta.global.u32 %r4, %r3; +; CHECK-NEXT: cvt.u64.u32 %rd1, %r4; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { st.b128 [%rd1], %rq1; } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: ret; + + %1 = addrspacecast ptr %flag to ptr addrspace(1) + %2 = load i8, ptr addrspace(1) %1, align 1 + %3 = icmp eq i8 %2, 0 + %4 = select i1 %3, i128 24, i128 42 + tail call void asm sideeffect "{ st.b128 [$0], $1; }", "l,q"(ptr nonnull addrspacecast (ptr addrspace(1) @value to ptr), i128 %4) + ret void +} + +define void @test_store_b128_output() { +; CHECK-LABEL: test_store_b128_output( +; CHECK: { +; CHECK-NEXT: .reg .b64 %rd<5>; +; CHECK-NEXT: .reg .b128 %rq<2>; +; CHECK-EMPTY: +; CHECK-NEXT: // %bb.0: +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { mov.b128 %rq1, 41; } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: mov.b128 {%rd1, %rd2}, %rq1; +; CHECK-NEXT: add.cc.s64 %rd3, %rd1, 1; +; CHECK-NEXT: addc.cc.s64 %rd4, %rd2, 0; +; CHECK-NEXT: st.global.u64 [value+8], %rd4; +; CHECK-NEXT: st.global.u64 [value], %rd3; +; CHECK-NEXT: ret; + + %1 = tail call i128 asm "{ mov.b128 $0, 41; }", "=q"() + %add = add nsw i128 %1, 1 + %2 = bitcast i128 %add to <2 x i64> + store <2 x i64> %2, ptr addrspace(1) @value, align 16 + ret void +} + +define void @test_use_of_b128_output(ptr nocapture readonly %data) { +; CHECK-LABEL: test_use_of_b128_output( +; CHECK: { +; CHECK-NEXT: .reg .b32 %r<3>; +; CHECK-NEXT: .reg .b64 %rd<7>; +; CHECK-NEXT: .reg .b128 %rq<3>; +; CHECK-EMPTY: +; CHECK-NEXT: // %bb.0: +; CHECK-NEXT: ld.param.u32 %r1, [test_use_of_b128_output_param_0]; +; CHECK-NEXT: cvta.to.global.u32 %r2, %r1; +; CHECK-NEXT: ld.global.u64 %rd1, [%r2+8]; +; CHECK-NEXT: ld.global.u64 %rd2, [%r2]; +; CHECK-NEXT: mov.b128 %rq2, {%rd2, %rd1}; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { mov.b128 %rq1, %rq2; } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: mov.b128 {%rd3, %rd4}, %rq1; +; CHECK-NEXT: add.cc.s64 %rd5, %rd3, 1; +; CHECK-NEXT: addc.cc.s64 %rd6, %rd4, 0; +; CHECK-NEXT: st.global.u64 [value], %rd5; +; CHECK-NEXT: st.global.u64 [value+8], %rd6; +; CHECK-NEXT: ret; + + %1 = addrspacecast ptr %data to ptr addrspace(1) + %2 = load <2 x i64>, ptr addrspace(1) %1, align 16 + %3 = bitcast <2 x i64> %2 to i128 + %4 = tail call i128 asm "{ mov.b128 $0, $1; }", "=q,q"(i128 %3) + %add = add nsw i128 %4, 1 + %5 = bitcast i128 %add to <2 x i64> + store <2 x i64> %5, ptr addrspace(1) @value, align 16 + ret void +} diff --git a/llvm/test/CodeGen/NVPTX/inline-asm-b128-test2.ll b/llvm/test/CodeGen/NVPTX/inline-asm-b128-test2.ll new file mode 100644 index 0000000..3d1d7fb --- /dev/null +++ b/llvm/test/CodeGen/NVPTX/inline-asm-b128-test2.ll @@ -0,0 +1,122 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --extra_scrub --version 5 +; RUN: llc < %s -march=nvptx -mcpu=sm_70 -mattr=+ptx83 | FileCheck %s +; RUN: %if ptxas %{ llc < %s -march=nvptx -mcpu=sm_70 -mattr=+ptx83 | %ptxas-verify -arch=sm_70 %} + +target triple = "nvptx64-nvidia-cuda" + +@u128_max = internal addrspace(1) global i128 0, align 16 +@u128_zero = internal addrspace(1) global i128 0, align 16 +@i128_max = internal addrspace(1) global i128 0, align 16 +@i128_min = internal addrspace(1) global i128 0, align 16 +@v_u128_max = internal addrspace(1) global i128 0, align 16 +@v_u128_zero = internal addrspace(1) global i128 0, align 16 +@v_i128_max = internal addrspace(1) global i128 0, align 16 +@v_i128_min = internal addrspace(1) global i128 0, align 16 +@v64 = internal addrspace(1) global ptr null, align 8 + +define void @test_corner_values() { +; CHECK-LABEL: test_corner_values( +; CHECK: { +; CHECK-NEXT: .reg .b32 %r<20>; +; CHECK-NEXT: .reg .b64 %rd<17>; +; CHECK-NEXT: .reg .b128 %rq<5>; +; CHECK-EMPTY: +; CHECK-NEXT: // %bb.0: +; CHECK-NEXT: ld.global.u32 %r1, [v64]; +; CHECK-NEXT: add.s32 %r2, %r1, 8; +; CHECK-NEXT: mov.u64 %rd13, -1; +; CHECK-NEXT: mov.b128 %rq1, {%rd13, %rd13}; +; CHECK-NEXT: cvt.u64.u32 %rd1, %r1; +; CHECK-NEXT: cvt.u64.u32 %rd2, %r2; +; CHECK-NEXT: mov.u32 %r3, v_u128_max; +; CHECK-NEXT: cvta.global.u32 %r4, %r3; +; CHECK-NEXT: cvt.u64.u32 %rd3, %r4; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { +; CHECK-NEXT: .reg .b64 hi; +; CHECK-NEXT: .reg .b64 lo; +; CHECK-NEXT: mov.b128 {lo, hi}, %rq1; +; CHECK-NEXT: st.b64 [%rd1], lo; +; CHECK-NEXT: st.b64 [%rd2], hi; +; CHECK-NEXT: st.b128 [%rd3], %rq1; +; CHECK-NEXT: } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: ld.global.u32 %r5, [v64]; +; CHECK-NEXT: add.s32 %r6, %r5, 16; +; CHECK-NEXT: add.s32 %r7, %r5, 24; +; CHECK-NEXT: mov.u64 %rd14, 9223372036854775807; +; CHECK-NEXT: mov.b128 %rq2, {%rd13, %rd14}; +; CHECK-NEXT: mov.u32 %r8, v_i128_max; +; CHECK-NEXT: cvta.global.u32 %r9, %r8; +; CHECK-NEXT: cvt.u64.u32 %rd6, %r9; +; CHECK-NEXT: cvt.u64.u32 %rd4, %r6; +; CHECK-NEXT: cvt.u64.u32 %rd5, %r7; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { +; CHECK-NEXT: .reg .b64 hi; +; CHECK-NEXT: .reg .b64 lo; +; CHECK-NEXT: mov.b128 {lo, hi}, %rq2; +; CHECK-NEXT: st.b64 [%rd4], lo; +; CHECK-NEXT: st.b64 [%rd5], hi; +; CHECK-NEXT: st.b128 [%rd6], %rq2; +; CHECK-NEXT: } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: ld.global.u32 %r10, [v64]; +; CHECK-NEXT: add.s32 %r11, %r10, 32; +; CHECK-NEXT: add.s32 %r12, %r10, 40; +; CHECK-NEXT: mov.u64 %rd15, -9223372036854775808; +; CHECK-NEXT: mov.u64 %rd16, 0; +; CHECK-NEXT: mov.b128 %rq3, {%rd16, %rd15}; +; CHECK-NEXT: mov.u32 %r13, v_i128_min; +; CHECK-NEXT: cvta.global.u32 %r14, %r13; +; CHECK-NEXT: cvt.u64.u32 %rd9, %r14; +; CHECK-NEXT: cvt.u64.u32 %rd7, %r11; +; CHECK-NEXT: cvt.u64.u32 %rd8, %r12; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { +; CHECK-NEXT: .reg .b64 hi; +; CHECK-NEXT: .reg .b64 lo; +; CHECK-NEXT: mov.b128 {lo, hi}, %rq3; +; CHECK-NEXT: st.b64 [%rd7], lo; +; CHECK-NEXT: st.b64 [%rd8], hi; +; CHECK-NEXT: st.b128 [%rd9], %rq3; +; CHECK-NEXT: } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: ld.global.u32 %r15, [v64]; +; CHECK-NEXT: add.s32 %r16, %r15, 48; +; CHECK-NEXT: add.s32 %r17, %r15, 56; +; CHECK-NEXT: mov.b128 %rq4, {%rd16, %rd16}; +; CHECK-NEXT: mov.u32 %r18, v_u128_zero; +; CHECK-NEXT: cvta.global.u32 %r19, %r18; +; CHECK-NEXT: cvt.u64.u32 %rd12, %r19; +; CHECK-NEXT: cvt.u64.u32 %rd10, %r16; +; CHECK-NEXT: cvt.u64.u32 %rd11, %r17; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { +; CHECK-NEXT: .reg .b64 hi; +; CHECK-NEXT: .reg .b64 lo; +; CHECK-NEXT: mov.b128 {lo, hi}, %rq4; +; CHECK-NEXT: st.b64 [%rd10], lo; +; CHECK-NEXT: st.b64 [%rd11], hi; +; CHECK-NEXT: st.b128 [%rd12], %rq4; +; CHECK-NEXT: } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: ret; + + %1 = load ptr, ptr addrspace(1) @v64, align 8 + %2 = getelementptr inbounds i64, ptr %1, i64 1 + tail call void asm sideeffect "{\0A\09.reg .b64 hi;\0A\09.reg .b64 lo;\0A\09mov.b128 {lo, hi}, $0;\0A\09st.b64 [$1], lo;\0A\09st.b64 [$2], hi;\0A\09st.b128 [$3], $0;\0A\09}", "q,l,l,l"(i128 -1, ptr %1, ptr nonnull %2, ptr nonnull addrspacecast (ptr addrspace(1) @v_u128_max to ptr)) + %3 = load ptr, ptr addrspace(1) @v64, align 8 + %4 = getelementptr inbounds i64, ptr %3, i64 2 + %5 = getelementptr inbounds i64, ptr %3, i64 3 + tail call void asm sideeffect "{\0A\09.reg .b64 hi;\0A\09.reg .b64 lo;\0A\09mov.b128 {lo, hi}, $0;\0A\09st.b64 [$1], lo;\0A\09st.b64 [$2], hi;\0A\09st.b128 [$3], $0;\0A\09}", "q,l,l,l"(i128 170141183460469231731687303715884105727, ptr nonnull %4, ptr nonnull %5, ptr nonnull addrspacecast (ptr addrspace(1) @v_i128_max to ptr)) + %6 = load ptr, ptr addrspace(1) @v64, align 8 + %7 = getelementptr inbounds i64, ptr %6, i64 4 + %8 = getelementptr inbounds i64, ptr %6, i64 5 + tail call void asm sideeffect "{\0A\09.reg .b64 hi;\0A\09.reg .b64 lo;\0A\09mov.b128 {lo, hi}, $0;\0A\09st.b64 [$1], lo;\0A\09st.b64 [$2], hi;\0A\09st.b128 [$3], $0;\0A\09}", "q,l,l,l"(i128 -170141183460469231731687303715884105728, ptr nonnull %7, ptr nonnull %8, ptr nonnull addrspacecast (ptr addrspace(1) @v_i128_min to ptr)) + %9 = load ptr, ptr addrspace(1) @v64, align 8 + %10 = getelementptr inbounds i64, ptr %9, i64 6 + %11 = getelementptr inbounds i64, ptr %9, i64 7 + tail call void asm sideeffect "{\0A\09.reg .b64 hi;\0A\09.reg .b64 lo;\0A\09mov.b128 {lo, hi}, $0;\0A\09st.b64 [$1], lo;\0A\09st.b64 [$2], hi;\0A\09st.b128 [$3], $0;\0A\09}", "q,l,l,l"(i128 0, ptr nonnull %10, ptr nonnull %11, ptr nonnull addrspacecast (ptr addrspace(1) @v_u128_zero to ptr)) + ret void +} diff --git a/llvm/test/CodeGen/NVPTX/inline-asm-b128-test3.ll b/llvm/test/CodeGen/NVPTX/inline-asm-b128-test3.ll new file mode 100644 index 0000000..ae45397 --- /dev/null +++ b/llvm/test/CodeGen/NVPTX/inline-asm-b128-test3.ll @@ -0,0 +1,67 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --extra_scrub --version 5 +; RUN: llc < %s -march=nvptx -mcpu=sm_70 -mattr=+ptx83 | FileCheck %s +; RUN: %if ptxas %{ llc < %s -march=nvptx -mcpu=sm_70 -mattr=+ptx83 | %ptxas-verify -arch=sm_70 %} + +target triple = "nvptx64-nvidia-cuda" + +@size = internal addrspace(1) global i32 0, align 4 +@x = internal addrspace(1) global i128 0, align 16 + +define void @test_b128_in_loop() { +; CHECK-LABEL: test_b128_in_loop( +; CHECK: { +; CHECK-NEXT: .reg .pred %p<3>; +; CHECK-NEXT: .reg .b64 %rd<15>; +; CHECK-NEXT: .reg .b128 %rq<3>; +; CHECK-EMPTY: +; CHECK-NEXT: // %bb.0: +; CHECK-NEXT: ld.global.s32 %rd1, [size]; +; CHECK-NEXT: setp.eq.s64 %p1, %rd1, 0; +; CHECK-NEXT: @%p1 bra $L__BB0_3; +; CHECK-NEXT: // %bb.1: // %BB1 +; CHECK-NEXT: ld.global.u64 %rd13, [x+8]; +; CHECK-NEXT: ld.global.u64 %rd12, [x]; +; CHECK-NEXT: mov.u64 %rd14, 0; +; CHECK-NEXT: $L__BB0_2: // %BB2 +; CHECK-NEXT: // =>This Inner Loop Header: Depth=1 +; CHECK-NEXT: mov.b128 %rq1, {%rd12, %rd13}; +; CHECK-NEXT: // begin inline asm +; CHECK-NEXT: { +; CHECK-NEXT: .reg .b64 lo; +; CHECK-NEXT: .reg .b64 hi; +; CHECK-NEXT: mov.b128 {lo, hi}, %rq1; +; CHECK-NEXT: add.cc.u64 lo, lo, %rd14; +; CHECK-NEXT: mov.b128 %rq1, {lo, hi}; +; CHECK-NEXT: } +; CHECK-NEXT: // end inline asm +; CHECK-NEXT: mov.b128 {%rd12, %rd13}, %rq1; +; CHECK-NEXT: st.global.u64 [x+8], %rd13; +; CHECK-NEXT: st.global.u64 [x], %rd12; +; CHECK-NEXT: add.s64 %rd14, %rd14, 1; +; CHECK-NEXT: setp.ne.s64 %p2, %rd1, %rd14; +; CHECK-NEXT: @%p2 bra $L__BB0_2; +; CHECK-NEXT: $L__BB0_3: // %BB3 +; CHECK-NEXT: ret; + + %1 = load i32, ptr addrspace(1) @size, align 4 + %2 = icmp eq i32 %1, 0 + br i1 %2, label %BB3, label %BB1 + +BB1: ; preds = %0 + %3 = load i128, ptr addrspace(1) @x, align 16 + %4 = sext i32 %1 to i64 + br label %BB2 + +BB2: ; preds = %BB2, %BB1 + %5 = phi i128 [ %7, %BB2 ], [ %3, %BB1 ] + %6 = phi i64 [ %9, %BB2 ], [ 0, %BB1 ] + %7 = tail call i128 asm "{\0A\09.reg .b64 lo;\0A\09.reg .b64 hi;\0A\09mov.b128 {lo, hi}, $0;\0A\09add.cc.u64 lo, lo, $1;\0A\09mov.b128 $0, {lo, hi};\0A\09}", "=q,l,0"(i64 %6, i128 %5) + %8 = bitcast i128 %7 to <2 x i64> + store <2 x i64> %8, ptr addrspace(1) @x, align 16 + %9 = add nuw i64 %6, 1 + %10 = icmp eq i64 %9, %4 + br i1 %10, label %BB3, label %BB2 + +BB3: ; preds = %BB2, %0 + ret void +} -- cgit v1.1 From bd3215149aa16428666e520ddc94a638e1178437 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 16:45:57 -0700 Subject: MCExpr::evaluateKnownAbsolute: replace the MCAsmLayout parameter with MCAssembler and add a comment. --- llvm/include/llvm/MC/MCExpr.h | 6 ++++-- llvm/lib/MC/ELFObjectWriter.cpp | 2 +- llvm/lib/MC/MCAssembler.cpp | 8 ++++---- llvm/lib/MC/MCCodeView.cpp | 3 ++- llvm/lib/MC/MCExpr.cpp | 5 ++--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 7 +++---- llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 8 +++----- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h index 38b89d5..118b1dd 100644 --- a/llvm/include/llvm/MC/MCExpr.h +++ b/llvm/include/llvm/MC/MCExpr.h @@ -16,7 +16,6 @@ namespace llvm { class MCAsmInfo; -class MCAsmLayout; class MCAssembler; class MCContext; class MCFixup; @@ -101,7 +100,10 @@ public: bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const; bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const; - bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const; + /// Aggressive variant of evaluateAsRelocatable when relocations are + /// unavailable (e.g. .fill). Expects callers to handle errors when true is + /// returned. + bool evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const; /// Try to evaluate the expression to a relocatable value, i.e. an /// expression of the fixed form (a - b + constant). diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index e7e729f..be4831d 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -567,7 +567,7 @@ void ELFWriter::writeSymbol(const MCAssembler &Asm, SymbolTableWriter &Writer, if (ESize) { int64_t Res; - if (!ESize->evaluateKnownAbsolute(Res, *Asm.getLayout())) + if (!ESize->evaluateKnownAbsolute(Res, Asm)) report_fatal_error("Size expression must be absolute."); Size = Res; } diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 532f68b..6da4815 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -288,7 +288,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const { case MCFragment::FT_Fill: { auto &FF = cast(F); int64_t NumValues = 0; - if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *Layout)) { + if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *this)) { getContext().reportError(FF.getLoc(), "expected assembly-time absolute expression"); return 0; @@ -1150,7 +1150,7 @@ bool MCAssembler::relaxLEB(MCLEBFragment &LF) { // requires that .uleb128 A-B is foldable where A and B reside in different // fragments. This is used by __gcc_except_table. bool Abs = getSubsectionsViaSymbols() - ? LF.getValue().evaluateKnownAbsolute(Value, *Layout) + ? LF.getValue().evaluateKnownAbsolute(Value, *this) : LF.getValue().evaluateAsAbsolute(Value, *this); if (!Abs) { bool Relaxed, UseZeroPad; @@ -1248,7 +1248,7 @@ bool MCAssembler::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF) { MCContext &Context = getContext(); uint64_t OldSize = DF.getContents().size(); int64_t AddrDelta; - bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *Layout); + bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *this); assert(Abs && "We created a line delta with an invalid expression"); (void)Abs; int64_t LineDelta; @@ -1301,7 +1301,7 @@ bool MCAssembler::relaxCVDefRange(MCCVDefRangeFragment &F) { bool MCAssembler::relaxPseudoProbeAddr(MCPseudoProbeAddrFragment &PF) { uint64_t OldSize = PF.getContents().size(); int64_t AddrDelta; - bool Abs = PF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *Layout); + bool Abs = PF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *this); assert(Abs && "We created a pseudo probe with an invalid expression"); (void)Abs; SmallVectorImpl &Data = PF.getContents(); diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp index 89b28b4..a47a07b 100644 --- a/llvm/lib/MC/MCCodeView.cpp +++ b/llvm/lib/MC/MCCodeView.cpp @@ -474,7 +474,8 @@ static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin, const MCExpr *AddrDelta = MCBinaryExpr::create(MCBinaryExpr::Sub, EndRef, BeginRef, Ctx); int64_t Result; - bool Success = AddrDelta->evaluateKnownAbsolute(Result, Layout); + bool Success = + AddrDelta->evaluateKnownAbsolute(Result, Layout.getAssembler()); assert(Success && "failed to evaluate label difference as absolute"); (void)Success; assert(Result >= 0 && "negative label difference requested"); diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index 7e71111..8279539 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -563,9 +563,8 @@ bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const { return evaluateAsAbsolute(Res, Asm, nullptr, false); } -bool MCExpr::evaluateKnownAbsolute(int64_t &Res, - const MCAsmLayout &Layout) const { - return evaluateAsAbsolute(Res, &Layout.getAssembler(), nullptr, true); +bool MCExpr::evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const { + return evaluateAsAbsolute(Res, &Asm, nullptr, true); } bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp index eb059d3..0d65bde 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp @@ -303,7 +303,7 @@ std::pair LoongArchAsmBackend::relaxLEB128(const MCAssembler &Asm, MCLEBFragment &LF, int64_t &Value) const { const MCExpr &Expr = LF.getValue(); - if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, *Asm.getLayout())) + if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, Asm)) return std::make_pair(false, false); LF.getFixups().push_back( MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc())); @@ -313,7 +313,6 @@ std::pair LoongArchAsmBackend::relaxLEB128(const MCAssembler &Asm, bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm, MCDwarfLineAddrFragment &DF, bool &WasRelaxed) const { - auto &Layout = *Asm.getLayout(); MCContext &C = Asm.getContext(); int64_t LineDelta = DF.getLineDelta(); @@ -325,7 +324,7 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm, int64_t Value; if (AddrDelta.evaluateAsAbsolute(Value, Asm)) return false; - bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout); + bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Asm); assert(IsAbsolute && "CFA with invalid expression"); (void)IsAbsolute; @@ -391,7 +390,7 @@ bool LoongArchAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, int64_t Value; if (AddrDelta.evaluateAsAbsolute(Value, Asm)) return false; - bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout); + bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Asm); assert(IsAbsolute && "CFA with invalid expression"); (void)IsAbsolute; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp index bbb8914..1bd23e6 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -215,7 +215,7 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm, int64_t Value; [[maybe_unused]] bool IsAbsolute = - AddrDelta.evaluateKnownAbsolute(Value, *Asm.getLayout()); + AddrDelta.evaluateKnownAbsolute(Value, Asm); assert(IsAbsolute && "CFA with invalid expression"); Data.clear(); @@ -271,7 +271,6 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm, bool RISCVAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, MCDwarfCallFrameFragment &DF, bool &WasRelaxed) const { - auto &Layout = *Asm.getLayout(); const MCExpr &AddrDelta = DF.getAddrDelta(); SmallVectorImpl &Data = DF.getContents(); SmallVectorImpl &Fixups = DF.getFixups(); @@ -281,7 +280,7 @@ bool RISCVAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, if (AddrDelta.evaluateAsAbsolute(Value, Asm)) return false; [[maybe_unused]] bool IsAbsolute = - AddrDelta.evaluateKnownAbsolute(Value, Layout); + AddrDelta.evaluateKnownAbsolute(Value, Asm); assert(IsAbsolute && "CFA with invalid expression"); Data.clear(); @@ -341,8 +340,7 @@ std::pair RISCVAsmBackend::relaxLEB128(const MCAssembler &Asm, LF.getFixups().push_back( MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc())); } - return std::make_pair(Expr.evaluateKnownAbsolute(Value, *Asm.getLayout()), - false); + return std::make_pair(Expr.evaluateKnownAbsolute(Value, Asm), false); } // Given a compressed control flow instruction this function returns -- cgit v1.1 From 08969ca159d77905a1e6212f0533c444813cf511 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 1 Jul 2024 14:57:34 -0700 Subject: [RISCV] Remove RISCVISAInfo::addExtension. NFC We can edit the map directly at the caller. Many of the callers already directly call contains or erase on the map. So there's no good reason to have a wrapper for adding to the map. --- llvm/include/llvm/TargetParser/RISCVISAInfo.h | 2 -- llvm/lib/TargetParser/RISCVISAInfo.cpp | 24 +++++++++++------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/llvm/include/llvm/TargetParser/RISCVISAInfo.h b/llvm/include/llvm/TargetParser/RISCVISAInfo.h index 12f6b46..5e9cf67 100644 --- a/llvm/include/llvm/TargetParser/RISCVISAInfo.h +++ b/llvm/include/llvm/TargetParser/RISCVISAInfo.h @@ -87,8 +87,6 @@ private: RISCVISAUtils::OrderedExtensionMap Exts; - bool addExtension(StringRef ExtName, RISCVISAUtils::ExtensionVersion Version); - Error checkDependency(); void updateImplication(); diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index 2a6ecee..91ade25 100644 --- a/llvm/lib/TargetParser/RISCVISAInfo.cpp +++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp @@ -171,11 +171,6 @@ findDefaultVersion(StringRef ExtName) { return std::nullopt; } -bool RISCVISAInfo::addExtension(StringRef ExtName, - RISCVISAUtils::ExtensionVersion Version) { - return Exts.emplace(ExtName, Version).second; -} - static StringRef getExtensionTypeDesc(StringRef Ext) { if (Ext.starts_with('s')) return "standard supervisor-level extension"; @@ -431,7 +426,7 @@ RISCVISAInfo::parseFeatures(unsigned XLen, continue; if (Add) - ISAInfo->addExtension(ExtName, ExtensionInfoIterator->Version); + ISAInfo->Exts[ExtName.str()] = ExtensionInfoIterator->Version; else ISAInfo->Exts.erase(ExtName.str()); } @@ -513,7 +508,11 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) { "'" + Twine(ExtName[0]) + "' must be followed by a letter"); - if (!ISAInfo->addExtension(ExtName, {MajorVersion, MinorVersion})) + if (!ISAInfo->Exts + .emplace( + ExtName.str(), + RISCVISAUtils::ExtensionVersion{MajorVersion, MinorVersion}) + .second) return createStringError(errc::invalid_argument, "duplicate extension '" + ExtName + "'"); } @@ -722,11 +721,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, // Check all Extensions are supported. for (auto &SeenExtAndVers : SeenExtMap) { const std::string &ExtName = SeenExtAndVers.first; - RISCVISAUtils::ExtensionVersion ExtVers = SeenExtAndVers.second; if (!RISCVISAInfo::isSupportedExtension(ExtName)) return getStringErrorForInvalidExt(ExtName); - ISAInfo->addExtension(ExtName, ExtVers); + ISAInfo->Exts[ExtName] = SeenExtAndVers.second; } return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo)); @@ -830,7 +828,7 @@ void RISCVISAInfo::updateImplication() { // implied if (!HasE && !HasI) { auto Version = findDefaultVersion("i"); - addExtension("i", *Version); + Exts["i"] = *Version; } if (HasE && HasI) @@ -854,7 +852,7 @@ void RISCVISAInfo::updateImplication() { if (Exts.count(ImpliedExt)) return; auto Version = findDefaultVersion(ImpliedExt); - addExtension(ImpliedExt, *Version); + Exts[ImpliedExt] = *Version; WorkList.push_back(ImpliedExt); }); } @@ -863,7 +861,7 @@ void RISCVISAInfo::updateImplication() { if (XLen == 32 && Exts.count("zce") && Exts.count("f") && !Exts.count("zcf")) { auto Version = findDefaultVersion("zcf"); - addExtension("zcf", *Version); + Exts["zcf"] = *Version; } } @@ -890,7 +888,7 @@ void RISCVISAInfo::updateCombination() { }); if (HasAllRequiredFeatures) { auto Version = findDefaultVersion(CombineExt); - addExtension(CombineExt, *Version); + Exts[CombineExt.str()] = *Version; MadeChange = true; } } -- cgit v1.1 From 4ba9956958b5646853a0abd81a96d935749eef8b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:01:51 -0700 Subject: MachObjectWriter: replace the MCAsmLayout parameter with MCAssembler --- llvm/include/llvm/MC/MCLinkerOptimizationHint.h | 22 ++++++++--------- llvm/include/llvm/MC/MCMachObjectWriter.h | 4 ++-- llvm/lib/MC/MCLinkerOptimizationHint.cpp | 21 ++++++++-------- llvm/lib/MC/MachObjectWriter.cpp | 28 ++++++++++------------ .../MCTargetDesc/AArch64MachObjectWriter.cpp | 22 +++++++---------- .../ARM/MCTargetDesc/ARMMachObjectWriter.cpp | 8 +++---- .../X86/MCTargetDesc/X86MachObjectWriter.cpp | 18 +++++++------- 7 files changed, 57 insertions(+), 66 deletions(-) diff --git a/llvm/include/llvm/MC/MCLinkerOptimizationHint.h b/llvm/include/llvm/MC/MCLinkerOptimizationHint.h index b91fbc6..530f288 100644 --- a/llvm/include/llvm/MC/MCLinkerOptimizationHint.h +++ b/llvm/include/llvm/MC/MCLinkerOptimizationHint.h @@ -25,7 +25,7 @@ namespace llvm { class MachObjectWriter; -class MCAsmLayout; +class MCAssembler; class MCSymbol; class raw_ostream; @@ -108,8 +108,8 @@ class MCLOHDirective { /// Emit this directive in \p OutStream using the information available /// in the given \p ObjWriter and \p Layout to get the address of the /// arguments within the object file. - void emit_impl(raw_ostream &OutStream, const MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const; + void emit_impl(const MCAssembler &Asm, raw_ostream &OutStream, + const MachObjectWriter &ObjWriter) const; public: using LOHArgs = SmallVectorImpl; @@ -125,12 +125,12 @@ public: /// Emit this directive as: /// - void emit(MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const; + void emit(const MCAssembler &Asm, MachObjectWriter &ObjWriter) const; /// Get the size in bytes of this directive if emitted in \p ObjWriter with /// the given \p Layout. - uint64_t getEmitSize(const MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const; + uint64_t getEmitSize(const MCAssembler &Asm, + const MachObjectWriter &ObjWriter) const; }; class MCLOHContainer { @@ -157,20 +157,20 @@ public: } /// Get the size of the directives if emitted. - uint64_t getEmitSize(const MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const { + uint64_t getEmitSize(const MCAssembler &Asm, + const MachObjectWriter &ObjWriter) const { if (!EmitSize) { for (const MCLOHDirective &D : Directives) - EmitSize += D.getEmitSize(ObjWriter, Layout); + EmitSize += D.getEmitSize(Asm, ObjWriter); } return EmitSize; } /// Emit all Linker Optimization Hint in one big table. /// Each line of the table is emitted by LOHDirective::emit. - void emit(MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const { + void emit(const MCAssembler &Asm, MachObjectWriter &ObjWriter) const { for (const MCLOHDirective &D : Directives) - D.emit(ObjWriter, Layout); + D.emit(Asm, ObjWriter); } void reset() { diff --git a/llvm/include/llvm/MC/MCMachObjectWriter.h b/llvm/include/llvm/MC/MCMachObjectWriter.h index c685e27..172dadb 100644 --- a/llvm/include/llvm/MC/MCMachObjectWriter.h +++ b/llvm/include/llvm/MC/MCMachObjectWriter.h @@ -161,7 +161,7 @@ public: uint64_t getSectionAddress(const MCSection *Sec) const { return SectionAddress.lookup(Sec); } - uint64_t getSymbolAddress(const MCSymbol &S, const MCAsmLayout &Layout) const; + uint64_t getSymbolAddress(const MCSymbol &S, const MCAssembler &Asm) const; uint64_t getFragmentAddress(const MCAssembler &Asm, const MCFragment *Fragment) const; @@ -212,7 +212,7 @@ public: uint32_t FirstUndefinedSymbol, uint32_t NumUndefinedSymbols, uint32_t IndirectSymbolOffset, uint32_t NumIndirectSymbols); - void writeNlist(MachSymbolData &MSD, const MCAsmLayout &Layout); + void writeNlist(MachSymbolData &MSD, const MCAssembler &Asm); void writeLinkeditLoadCommand(uint32_t Type, uint32_t DataOffset, uint32_t DataSize); diff --git a/llvm/lib/MC/MCLinkerOptimizationHint.cpp b/llvm/lib/MC/MCLinkerOptimizationHint.cpp index 9ab3218..2e6fde2 100644 --- a/llvm/lib/MC/MCLinkerOptimizationHint.cpp +++ b/llvm/lib/MC/MCLinkerOptimizationHint.cpp @@ -24,23 +24,24 @@ using namespace llvm; // - Its argN. // to are absolute addresses in the object file, i.e., // relative addresses from the beginning of the object file. -void MCLOHDirective::emit_impl(raw_ostream &OutStream, - const MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const { +void MCLOHDirective::emit_impl(const MCAssembler &Asm, raw_ostream &OutStream, + const MachObjectWriter &ObjWriter + +) const { encodeULEB128(Kind, OutStream); encodeULEB128(Args.size(), OutStream); for (const MCSymbol *Arg : Args) - encodeULEB128(ObjWriter.getSymbolAddress(*Arg, Layout), OutStream); + encodeULEB128(ObjWriter.getSymbolAddress(*Arg, Asm), OutStream); } -void MCLOHDirective::emit(MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const { +void MCLOHDirective::emit(const MCAssembler &Asm, + MachObjectWriter &ObjWriter) const { raw_ostream &OutStream = ObjWriter.W.OS; - emit_impl(OutStream, ObjWriter, Layout); + emit_impl(Asm, OutStream, ObjWriter); } -uint64_t MCLOHDirective::getEmitSize(const MachObjectWriter &ObjWriter, - const MCAsmLayout &Layout) const { +uint64_t MCLOHDirective::getEmitSize(const MCAssembler &Asm, + const MachObjectWriter &ObjWriter) const { class raw_counting_ostream : public raw_ostream { uint64_t Count = 0; @@ -54,6 +55,6 @@ uint64_t MCLOHDirective::getEmitSize(const MachObjectWriter &ObjWriter, }; raw_counting_ostream OutStream; - emit_impl(OutStream, ObjWriter, Layout); + emit_impl(Asm, OutStream, ObjWriter); return OutStream.tell(); } diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index 5d656a0..3f5bdd8 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -11,7 +11,6 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAsmInfoDarwin.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" @@ -91,7 +90,7 @@ MachObjectWriter::getFragmentAddress(const MCAssembler &Asm, } uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S, - const MCAsmLayout &Layout) const { + const MCAssembler &Asm) const { // If this is a variable, then recursively evaluate now. if (S.isVariable()) { if (const MCConstantExpr *C = @@ -99,8 +98,7 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S, return C->getValue(); MCValue Target; - if (!S.getVariableValue()->evaluateAsRelocatable( - Target, &Layout.getAssembler(), nullptr)) + if (!S.getVariableValue()->evaluateAsRelocatable(Target, &Asm, nullptr)) report_fatal_error("unable to evaluate offset for variable '" + S.getName() + "'"); @@ -114,14 +112,14 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S, uint64_t Address = Target.getConstant(); if (Target.getSymA()) - Address += getSymbolAddress(Target.getSymA()->getSymbol(), Layout); + Address += getSymbolAddress(Target.getSymA()->getSymbol(), Asm); if (Target.getSymB()) - Address += getSymbolAddress(Target.getSymB()->getSymbol(), Layout); + Address += getSymbolAddress(Target.getSymB()->getSymbol(), Asm); return Address; } return getSectionAddress(S.getFragment()->getParent()) + - Layout.getAssembler().getSymbolOffset(S); + Asm.getSymbolOffset(S); } uint64_t MachObjectWriter::getPaddingSize(const MCAssembler &Asm, @@ -371,8 +369,7 @@ const MCSymbol &MachObjectWriter::findAliasedSymbol(const MCSymbol &Sym) const { return *S; } -void MachObjectWriter::writeNlist(MachSymbolData &MSD, - const MCAsmLayout &Layout) { +void MachObjectWriter::writeNlist(MachSymbolData &MSD, const MCAssembler &Asm) { const MCSymbol *Symbol = MSD.Symbol; const MCSymbol &Data = *Symbol; const MCSymbol *AliasedSymbol = &findAliasedSymbol(*Symbol); @@ -416,7 +413,7 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD, if (IsAlias && Symbol->isUndefined()) Address = AliaseeInfo->StringIndex; else if (Symbol->isDefined()) - Address = getSymbolAddress(OrigSymbol, Layout); + Address = getSymbolAddress(OrigSymbol, Asm); else if (Symbol->isCommon()) { // Common symbols are encoded with the size in the address // field, and their alignment in the flags. @@ -781,7 +778,6 @@ void MachObjectWriter::populateAddrSigSection(MCAssembler &Asm) { } uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) { - auto &Layout = *Asm.getLayout(); uint64_t StartOffset = W.OS.tell(); populateAddrSigSection(Asm); @@ -843,7 +839,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) { } // Add the loh load command size, if used. - uint64_t LOHRawSize = Asm.getLOHContainer().getEmitSize(*this, Layout); + uint64_t LOHRawSize = Asm.getLOHContainer().getEmitSize(Asm, *this); uint64_t LOHSize = alignTo(LOHRawSize, is64Bit() ? 8 : 4); if (LOHSize) { ++NumLoadCommands; @@ -1037,10 +1033,10 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) { it = Asm.data_region_begin(), ie = Asm.data_region_end(); it != ie; ++it) { const DataRegionData *Data = &(*it); - uint64_t Start = getSymbolAddress(*Data->Start, Layout); + uint64_t Start = getSymbolAddress(*Data->Start, Asm); uint64_t End; if (Data->End) - End = getSymbolAddress(*Data->End, Layout); + End = getSymbolAddress(*Data->End, Asm); else report_fatal_error("Data region not terminated"); @@ -1059,7 +1055,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) { #ifndef NDEBUG unsigned Start = W.OS.tell(); #endif - Asm.getLOHContainer().emit(*this, Layout); + Asm.getLOHContainer().emit(Asm, *this); // Pad to a multiple of the pointer size. W.OS.write_zeros( offsetToAlignment(LOHRawSize, is64Bit() ? Align(8) : Align(4))); @@ -1096,7 +1092,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) { for (auto *SymbolData : {&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData}) for (MachSymbolData &Entry : *SymbolData) - writeNlist(Entry, Layout); + writeNlist(Entry, Asm); // Write the string table. StringTable.write(W.OS); diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp index d5177aa..a1f2259 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp @@ -278,18 +278,14 @@ void AArch64MachObjectWriter::recordRelocation( return; } - Value += - (!A->getFragment() ? 0 - : Writer->getSymbolAddress(*A, *Asm.getLayout())) - - (!A_Base || !A_Base->getFragment() - ? 0 - : Writer->getSymbolAddress(*A_Base, *Asm.getLayout())); - Value -= - (!B->getFragment() ? 0 - : Writer->getSymbolAddress(*B, *Asm.getLayout())) - - (!B_Base || !B_Base->getFragment() - ? 0 - : Writer->getSymbolAddress(*B_Base, *Asm.getLayout())); + Value += (!A->getFragment() ? 0 : Writer->getSymbolAddress(*A, Asm)) - + (!A_Base || !A_Base->getFragment() + ? 0 + : Writer->getSymbolAddress(*A_Base, Asm)); + Value -= (!B->getFragment() ? 0 : Writer->getSymbolAddress(*B, Asm)) - + (!B_Base || !B_Base->getFragment() + ? 0 + : Writer->getSymbolAddress(*B_Base, Asm)); Type = MachO::ARM64_RELOC_UNSIGNED; @@ -358,7 +354,7 @@ void AArch64MachObjectWriter::recordRelocation( // The index is the section ordinal (1-based). const MCSection &Sec = Symbol->getSection(); Index = Sec.getOrdinal() + 1; - Value += Writer->getSymbolAddress(*Symbol, *Asm.getLayout()); + Value += Writer->getSymbolAddress(*Symbol, Asm); if (IsPCRel) Value -= Writer->getFragmentAddress(Asm, Fragment) + Fixup.getOffset() + diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp index 2a2372d..e9f2c3e 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp @@ -158,7 +158,7 @@ void ARMMachObjectWriter::recordARMScatteredHalfRelocation( return; } - uint32_t Value = Writer->getSymbolAddress(*A, *Asm.getLayout()); + uint32_t Value = Writer->getSymbolAddress(*A, Asm); uint32_t Value2 = 0; uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); FixedValue += SecAddr; @@ -175,7 +175,7 @@ void ARMMachObjectWriter::recordARMScatteredHalfRelocation( // Select the appropriate difference relocation type. Type = MachO::ARM_RELOC_HALF_SECTDIFF; - Value2 = Writer->getSymbolAddress(B->getSymbol(), *Asm.getLayout()); + Value2 = Writer->getSymbolAddress(B->getSymbol(), Asm); FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); } @@ -267,7 +267,7 @@ void ARMMachObjectWriter::recordARMScatteredRelocation( return; } - uint32_t Value = Writer->getSymbolAddress(*A, *Asm.getLayout()); + uint32_t Value = Writer->getSymbolAddress(*A, Asm); uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); FixedValue += SecAddr; uint32_t Value2 = 0; @@ -285,7 +285,7 @@ void ARMMachObjectWriter::recordARMScatteredRelocation( // Select the appropriate difference relocation type. Type = MachO::ARM_RELOC_SECTDIFF; - Value2 = Writer->getSymbolAddress(B->getSymbol(), *Asm.getLayout()); + Value2 = Writer->getSymbolAddress(B->getSymbol(), Asm); FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); } diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp index d28195f..a956ae3 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp @@ -185,12 +185,10 @@ void X86MachObjectWriter::RecordX86_64Relocation( return; } - Value += - Writer->getSymbolAddress(*A, *Asm.getLayout()) - - (!A_Base ? 0 : Writer->getSymbolAddress(*A_Base, *Asm.getLayout())); - Value -= - Writer->getSymbolAddress(*B, *Asm.getLayout()) - - (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, *Asm.getLayout())); + Value += Writer->getSymbolAddress(*A, Asm) - + (!A_Base ? 0 : Writer->getSymbolAddress(*A_Base, Asm)); + Value -= Writer->getSymbolAddress(*B, Asm) - + (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, Asm)); if (!A_Base) Index = A->getFragment()->getParent()->getOrdinal() + 1; @@ -237,7 +235,7 @@ void X86MachObjectWriter::RecordX86_64Relocation( } else if (Symbol->isInSection() && !Symbol->isVariable()) { // The index is the section ordinal (1-based). Index = Symbol->getFragment()->getParent()->getOrdinal() + 1; - Value += Writer->getSymbolAddress(*Symbol, *Asm.getLayout()); + Value += Writer->getSymbolAddress(*Symbol, Asm); if (IsPCRel) Value -= FixupAddress + (1 << Log2Size); @@ -376,7 +374,7 @@ bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer, return false; } - uint32_t Value = Writer->getSymbolAddress(*A, *Asm.getLayout()); + uint32_t Value = Writer->getSymbolAddress(*A, Asm); uint64_t SecAddr = Writer->getSectionAddress(A->getFragment()->getParent()); FixedValue += SecAddr; uint32_t Value2 = 0; @@ -399,7 +397,7 @@ bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer, // pedantic compatibility with 'as'. Type = A->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF : (unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF; - Value2 = Writer->getSymbolAddress(*SB, *Asm.getLayout()); + Value2 = Writer->getSymbolAddress(*SB, Asm); FixedValue -= Writer->getSectionAddress(SB->getFragment()->getParent()); } @@ -476,7 +474,7 @@ void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer, Writer->getFragmentAddress(Asm, Fragment) + Fixup.getOffset(); IsPCRel = 1; FixedValue = FixupAddress - - Writer->getSymbolAddress(SymB->getSymbol(), *Asm.getLayout()) + + Writer->getSymbolAddress(SymB->getSymbol(), Asm) + Target.getConstant(); FixedValue += 1ULL << Log2Size; } else { -- cgit v1.1 From 66cd8ec4c08252ebc73c82e4883a8da247ed146b Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:08:38 -0700 Subject: MCCodeView: replace the MCAsmLayout parameter with MCAssembler --- llvm/include/llvm/MC/MCCodeView.h | 6 +++--- llvm/lib/MC/MCAssembler.cpp | 4 ++-- llvm/lib/MC/MCCodeView.cpp | 26 ++++++++++++-------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/llvm/include/llvm/MC/MCCodeView.h b/llvm/include/llvm/MC/MCCodeView.h index b1d8fe3..3092327 100644 --- a/llvm/include/llvm/MC/MCCodeView.h +++ b/llvm/include/llvm/MC/MCCodeView.h @@ -22,7 +22,7 @@ #include namespace llvm { -class MCAsmLayout; +class MCAssembler; class MCCVDefRangeFragment; class MCCVInlineLineTableFragment; class MCDataFragment; @@ -199,7 +199,7 @@ public: const MCSymbol *FnEndSym); /// Encodes the binary annotations once we have a layout. - void encodeInlineLineTable(MCAsmLayout &Layout, + void encodeInlineLineTable(const MCAssembler &Asm, MCCVInlineLineTableFragment &F); MCFragment * @@ -207,7 +207,7 @@ public: ArrayRef> Ranges, StringRef FixedSizePortion); - void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F); + void encodeDefRange(const MCAssembler &Asm, MCCVDefRangeFragment &F); /// Emits the string table substream. void emitStringTable(MCObjectStreamer &OS); diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 6da4815..f820cc9 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -1288,13 +1288,13 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCDwarfCallFrameFragment &DF) { bool MCAssembler::relaxCVInlineLineTable(MCCVInlineLineTableFragment &F) { unsigned OldSize = F.getContents().size(); - getContext().getCVContext().encodeInlineLineTable(*Layout, F); + getContext().getCVContext().encodeInlineLineTable(*this, F); return OldSize != F.getContents().size(); } bool MCAssembler::relaxCVDefRange(MCCVDefRangeFragment &F) { unsigned OldSize = F.getContents().size(); - getContext().getCVContext().encodeDefRange(*Layout, F); + getContext().getCVContext().encodeDefRange(*this, F); return OldSize != F.getContents().size(); } diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp index a47a07b..792a132 100644 --- a/llvm/lib/MC/MCCodeView.cpp +++ b/llvm/lib/MC/MCCodeView.cpp @@ -16,7 +16,6 @@ #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/Line.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCObjectStreamer.h" @@ -465,17 +464,16 @@ MCFragment *CodeViewContext::emitDefRange( return F; } -static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin, +static unsigned computeLabelDiff(const MCAssembler &Asm, const MCSymbol *Begin, const MCSymbol *End) { - MCContext &Ctx = Layout.getAssembler().getContext(); + MCContext &Ctx = Asm.getContext(); MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None; const MCExpr *BeginRef = MCSymbolRefExpr::create(Begin, Variant, Ctx), *EndRef = MCSymbolRefExpr::create(End, Variant, Ctx); const MCExpr *AddrDelta = MCBinaryExpr::create(MCBinaryExpr::Sub, EndRef, BeginRef, Ctx); int64_t Result; - bool Success = - AddrDelta->evaluateKnownAbsolute(Result, Layout.getAssembler()); + bool Success = AddrDelta->evaluateKnownAbsolute(Result, Asm); assert(Success && "failed to evaluate label difference as absolute"); (void)Success; assert(Result >= 0 && "negative label difference requested"); @@ -483,7 +481,7 @@ static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin, return unsigned(Result); } -void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, +void CodeViewContext::encodeInlineLineTable(const MCAssembler &Asm, MCCVInlineLineTableFragment &Frag) { size_t LocBegin; size_t LocEnd; @@ -550,7 +548,7 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, // We've hit a cv_loc not attributed to this inline call site. Use this // label to end the PC range. if (HaveOpenRange) { - unsigned Length = computeLabelDiff(Layout, LastLabel, Loc.getLabel()); + unsigned Length = computeLabelDiff(Asm, LastLabel, Loc.getLabel()); compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer); compressAnnotation(Length, Buffer); LastLabel = Loc.getLabel(); @@ -580,7 +578,7 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, int LineDelta = CurSourceLoc.Line - LastSourceLoc.Line; unsigned EncodedLineDelta = encodeSignedNumber(LineDelta); - unsigned CodeDelta = computeLabelDiff(Layout, LastLabel, Loc.getLabel()); + unsigned CodeDelta = computeLabelDiff(Asm, LastLabel, Loc.getLabel()); if (EncodedLineDelta < 0x8 && CodeDelta <= 0xf) { // The ChangeCodeOffsetAndLineOffset combination opcode is used when the // encoded line delta uses 3 or fewer set bits and the code offset fits @@ -606,23 +604,23 @@ void CodeViewContext::encodeInlineLineTable(MCAsmLayout &Layout, assert(HaveOpenRange); unsigned EndSymLength = - computeLabelDiff(Layout, LastLabel, Frag.getFnEndSym()); + computeLabelDiff(Asm, LastLabel, Frag.getFnEndSym()); unsigned LocAfterLength = ~0U; ArrayRef LocAfter = getLinesForExtent(LocEnd, LocEnd + 1); if (!LocAfter.empty()) { // Only try to compute this difference if we're in the same section. const MCCVLoc &Loc = LocAfter[0]; if (&Loc.getLabel()->getSection() == &LastLabel->getSection()) - LocAfterLength = computeLabelDiff(Layout, LastLabel, Loc.getLabel()); + LocAfterLength = computeLabelDiff(Asm, LastLabel, Loc.getLabel()); } compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer); compressAnnotation(std::min(EndSymLength, LocAfterLength), Buffer); } -void CodeViewContext::encodeDefRange(MCAsmLayout &Layout, +void CodeViewContext::encodeDefRange(const MCAssembler &Asm, MCCVDefRangeFragment &Frag) { - MCContext &Ctx = Layout.getAssembler().getContext(); + MCContext &Ctx = Asm.getContext(); SmallVectorImpl &Contents = Frag.getContents(); Contents.clear(); SmallVectorImpl &Fixups = Frag.getFixups(); @@ -634,8 +632,8 @@ void CodeViewContext::encodeDefRange(MCAsmLayout &Layout, const MCSymbol *LastLabel = nullptr; for (std::pair Range : Frag.getRanges()) { unsigned GapSize = - LastLabel ? computeLabelDiff(Layout, LastLabel, Range.first) : 0; - unsigned RangeSize = computeLabelDiff(Layout, Range.first, Range.second); + LastLabel ? computeLabelDiff(Asm, LastLabel, Range.first) : 0; + unsigned RangeSize = computeLabelDiff(Asm, Range.first, Range.second); GapAndRangeSizes.push_back({GapSize, RangeSize}); LastLabel = Range.second; } -- cgit v1.1 From b76100e220591fab2bf0a4917b216439f7aa4b09 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:18:24 -0700 Subject: WasmObjectWriter: replace the MCAsmLayout parameter with MCAssembler --- llvm/lib/MC/WasmObjectWriter.cpp | 56 +++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp index 187851b..f25dc92 100644 --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -15,7 +15,6 @@ #include "llvm/BinaryFormat/WasmTraits.h" #include "llvm/Config/llvm-config.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" @@ -299,11 +298,10 @@ private: void executePostLayoutBinding(MCAssembler &Asm) override; void prepareImports(SmallVectorImpl &Imports, - MCAssembler &Asm, const MCAsmLayout &Layout); + MCAssembler &Asm); uint64_t writeObject(MCAssembler &Asm) override; - uint64_t writeOneObject(MCAssembler &Asm, const MCAsmLayout &Layout, - DwoMode Mode); + uint64_t writeOneObject(MCAssembler &Asm, DwoMode Mode); void writeString(const StringRef Str) { encodeULEB128(Str.size(), W->OS); @@ -334,9 +332,9 @@ private: void writeElemSection(const MCSymbolWasm *IndirectFunctionTable, ArrayRef TableElems); void writeDataCountSection(); - uint32_t writeCodeSection(const MCAssembler &Asm, const MCAsmLayout &Layout, + uint32_t writeCodeSection(const MCAssembler &Asm, ArrayRef Functions); - uint32_t writeDataSection(const MCAsmLayout &Layout); + uint32_t writeDataSection(const MCAssembler &Asm); void writeTagSection(ArrayRef TagTypes); void writeGlobalSection(ArrayRef Globals); void writeTableSection(ArrayRef Tables); @@ -347,13 +345,13 @@ private: ArrayRef> InitFuncs, const std::map> &Comdats); void writeCustomSection(WasmCustomSection &CustomSection, - const MCAssembler &Asm, const MCAsmLayout &Layout); + const MCAssembler &Asm); void writeCustomRelocSections(); uint64_t getProvisionalValue(const MCAssembler &Asm, const WasmRelocationEntry &RelEntry); void applyRelocations(ArrayRef Relocations, - uint64_t ContentsOffset, const MCAsmLayout &Layout); + uint64_t ContentsOffset, const MCAssembler &Asm); uint32_t getRelocationIndexValue(const WasmRelocationEntry &RelEntry); uint32_t getFunctionType(const MCSymbolWasm &Symbol); @@ -764,7 +762,7 @@ WasmObjectWriter::getRelocationIndexValue(const WasmRelocationEntry &RelEntry) { // directly. void WasmObjectWriter::applyRelocations( ArrayRef Relocations, uint64_t ContentsOffset, - const MCAsmLayout &Layout) { + const MCAssembler &Asm) { auto &Stream = static_cast(W->OS); for (const WasmRelocationEntry &RelEntry : Relocations) { uint64_t Offset = ContentsOffset + @@ -772,7 +770,7 @@ void WasmObjectWriter::applyRelocations( RelEntry.Offset; LLVM_DEBUG(dbgs() << "applyRelocation: " << RelEntry << "\n"); - uint64_t Value = getProvisionalValue(Layout.getAssembler(), RelEntry); + uint64_t Value = getProvisionalValue(Asm, RelEntry); switch (RelEntry.Type) { case wasm::R_WASM_FUNCTION_INDEX_LEB: @@ -1049,7 +1047,6 @@ void WasmObjectWriter::writeDataCountSection() { } uint32_t WasmObjectWriter::writeCodeSection(const MCAssembler &Asm, - const MCAsmLayout &Layout, ArrayRef Functions) { if (Functions.empty()) return 0; @@ -1069,13 +1066,13 @@ uint32_t WasmObjectWriter::writeCodeSection(const MCAssembler &Asm, } // Apply fixups. - applyRelocations(CodeRelocations, Section.ContentsOffset, Layout); + applyRelocations(CodeRelocations, Section.ContentsOffset, Asm); endSection(Section); return Section.Index; } -uint32_t WasmObjectWriter::writeDataSection(const MCAsmLayout &Layout) { +uint32_t WasmObjectWriter::writeDataSection(const MCAssembler &Asm) { if (DataSegments.empty()) return 0; @@ -1100,7 +1097,7 @@ uint32_t WasmObjectWriter::writeDataSection(const MCAsmLayout &Layout) { } // Apply fixups. - applyRelocations(DataRelocations, Section.ContentsOffset, Layout); + applyRelocations(DataRelocations, Section.ContentsOffset, Asm); endSection(Section); return Section.Index; @@ -1239,8 +1236,7 @@ void WasmObjectWriter::writeLinkingMetaDataSection( } void WasmObjectWriter::writeCustomSection(WasmCustomSection &CustomSection, - const MCAssembler &Asm, - const MCAsmLayout &Layout) { + const MCAssembler &Asm) { SectionBookkeeping Section; auto *Sec = CustomSection.Section; startCustomSection(Section, CustomSection.Name); @@ -1255,7 +1251,7 @@ void WasmObjectWriter::writeCustomSection(WasmCustomSection &CustomSection, // Apply fixups. auto &Relocations = CustomSectionsRelocations[CustomSection.Section]; - applyRelocations(Relocations, CustomSection.OutputContentsOffset, Layout); + applyRelocations(Relocations, CustomSection.OutputContentsOffset, Asm); } uint32_t WasmObjectWriter::getFunctionType(const MCSymbolWasm &Symbol) { @@ -1331,8 +1327,7 @@ static bool isInSymtab(const MCSymbolWasm &Sym) { } void WasmObjectWriter::prepareImports( - SmallVectorImpl &Imports, MCAssembler &Asm, - const MCAsmLayout &Layout) { + SmallVectorImpl &Imports, MCAssembler &Asm) { // For now, always emit the memory import, since loads and stores are not // valid without it. In the future, we could perhaps be more clever and omit // it if there are no loads or stores. @@ -1437,22 +1432,20 @@ void WasmObjectWriter::prepareImports( } uint64_t WasmObjectWriter::writeObject(MCAssembler &Asm) { - auto &Layout = *Asm.getLayout(); support::endian::Writer MainWriter(*OS, llvm::endianness::little); W = &MainWriter; if (IsSplitDwarf) { - uint64_t TotalSize = writeOneObject(Asm, Layout, DwoMode::NonDwoOnly); + uint64_t TotalSize = writeOneObject(Asm, DwoMode::NonDwoOnly); assert(DwoOS); support::endian::Writer DwoWriter(*DwoOS, llvm::endianness::little); W = &DwoWriter; - return TotalSize + writeOneObject(Asm, Layout, DwoMode::DwoOnly); + return TotalSize + writeOneObject(Asm, DwoMode::DwoOnly); } else { - return writeOneObject(Asm, Layout, DwoMode::AllSections); + return writeOneObject(Asm, DwoMode::AllSections); } } uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, - const MCAsmLayout &Layout, DwoMode Mode) { uint64_t StartOffset = W->OS.tell(); SectionCount = 0; @@ -1472,9 +1465,8 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, SmallVector, 2> InitFuncs; std::map> Comdats; uint64_t DataSize = 0; - if (Mode != DwoMode::DwoOnly) { - prepareImports(Imports, Asm, Layout); - } + if (Mode != DwoMode::DwoOnly) + prepareImports(Imports, Asm); // Populate DataSegments and CustomSections, which must be done before // populating DataLocations. @@ -1926,8 +1918,8 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, TableElems); writeDataCountSection(); - CodeSectionIndex = writeCodeSection(Asm, Layout, Functions); - DataSectionIndex = writeDataSection(Layout); + CodeSectionIndex = writeCodeSection(Asm, Functions); + DataSectionIndex = writeDataSection(Asm); } // The Sections in the COMDAT list have placeholder indices (their index among @@ -1940,7 +1932,7 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, } } for (auto &CustomSection : CustomSections) - writeCustomSection(CustomSection, Asm, Layout); + writeCustomSection(CustomSection, Asm); if (Mode != DwoMode::DwoOnly) { writeLinkingMetaDataSection(SymbolInfos, InitFuncs, Comdats); @@ -1950,9 +1942,9 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm, } writeCustomRelocSections(); if (ProducersSection) - writeCustomSection(*ProducersSection, Asm, Layout); + writeCustomSection(*ProducersSection, Asm); if (TargetFeaturesSection) - writeCustomSection(*TargetFeaturesSection, Asm, Layout); + writeCustomSection(*TargetFeaturesSection, Asm); // TODO: Translate the .comment section to the output. return W->OS.tell() - StartOffset; -- cgit v1.1 From c7633ddb28a22a9b9b8d6ee74e911c59ef7d6287 Mon Sep 17 00:00:00 2001 From: Vidush Singhal <54336227+vidsinghal@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:20:34 -0700 Subject: [Attributor]: Ensure cycle info is not null when handling PHI in AAPointerInfo (#97321) Ensure cycle info object is not null for simple PHI case for the test: `llvm/test/Transforms/Attributor/phi_bug_pointer_info.ll` Debug info Before the change: ``` Accesses by bin after update: [8-12] : 1 - 9 - store i32 %0, ptr %field2, align 4 - c: %0 = load i32, ptr %val, align 4 [32-36] : 1 - 9 - store i32 %1, ptr %field8, align 4 - c: %1 = load i32, ptr %val2, align 4 [2147483647-4294967294] : 1 - 6 - %ret = load i32, ptr %x, align 4 - c: ``` Debug info After the change: ``` Accesses by bin after update: [8-12] : 2 - 9 - store i32 %0, ptr %field2, align 4 - c: %0 = load i32, ptr %val, align 4 - 6 - %ret = load i32, ptr %x, align 4 - c: [32-36] : 2 - 9 - store i32 %1, ptr %field8, align 4 - c: %1 = load i32, ptr %val2, align 4 - 6 - %ret = load i32, ptr %x, align 4 - c: ``` Co-authored-by: Vidush Singhal --- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 25 +++++++------ .../Transforms/Attributor/phi_bug_pointer_info.ll | 41 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 llvm/test/Transforms/Attributor/phi_bug_pointer_info.ll diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index a47f976..2816a85 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -1621,13 +1621,6 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { return true; }; - const auto *F = getAnchorScope(); - const auto *CI = - F ? A.getInfoCache().getAnalysisResultForFunction(*F) - : nullptr; - const auto *TLI = - F ? A.getInfoCache().getTargetLibraryInfoForFunction(*F) : nullptr; - auto UsePred = [&](const Use &U, bool &Follow) -> bool { Value *CurPtr = U.get(); User *Usr = U.getUser(); @@ -1671,18 +1664,18 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { // For PHIs we need to take care of the recurrence explicitly as the value // might change while we iterate through a loop. For now, we give up if // the PHI is not invariant. - if (isa(Usr)) { + if (auto *PHI = dyn_cast(Usr)) { // Note the order here, the Usr access might change the map, CurPtr is // already in it though. - bool IsFirstPHIUser = !OffsetInfoMap.count(Usr); - auto &UsrOI = OffsetInfoMap[Usr]; + bool IsFirstPHIUser = !OffsetInfoMap.count(PHI); + auto &UsrOI = OffsetInfoMap[PHI]; auto &PtrOI = OffsetInfoMap[CurPtr]; // Check if the PHI operand has already an unknown offset as we can't // improve on that anymore. if (PtrOI.isUnknown()) { LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI operand offset unknown " - << *CurPtr << " in " << *Usr << "\n"); + << *CurPtr << " in " << *PHI << "\n"); Follow = !UsrOI.isUnknown(); UsrOI.setUnknown(); return true; @@ -1705,7 +1698,8 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { auto It = OffsetInfoMap.find(CurPtrBase); if (It == OffsetInfoMap.end()) { LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI operand is too complex " - << *CurPtr << " in " << *Usr << "\n"); + << *CurPtr << " in " << *PHI + << " (base: " << *CurPtrBase << ")\n"); UsrOI.setUnknown(); Follow = true; return true; @@ -1718,6 +1712,9 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { // Cycles reported by CycleInfo. It is sufficient to check the PHIs in // every Cycle header; if such a node is marked unknown, this will // eventually propagate through the whole net of PHIs in the recurrence. + const auto *CI = + A.getInfoCache().getAnalysisResultForFunction( + *PHI->getFunction()); if (mayBeInCycle(CI, cast(Usr), /* HeaderOnly */ true)) { auto BaseOI = It->getSecond(); BaseOI.addToAll(Offset.getZExtValue()); @@ -1729,7 +1726,7 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { LLVM_DEBUG( dbgs() << "[AAPointerInfo] PHI operand pointer offset mismatch " - << *CurPtr << " in " << *Usr << "\n"); + << *CurPtr << " in " << *PHI << "\n"); UsrOI.setUnknown(); Follow = true; return true; @@ -1882,6 +1879,8 @@ ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { if (auto *CB = dyn_cast(Usr)) { if (CB->isLifetimeStartOrEnd()) return true; + const auto *TLI = + A.getInfoCache().getTargetLibraryInfoForFunction(*CB->getFunction()); if (getFreedOperand(CB, TLI) == U) return true; if (CB->isArgOperand(&U)) { diff --git a/llvm/test/Transforms/Attributor/phi_bug_pointer_info.ll b/llvm/test/Transforms/Attributor/phi_bug_pointer_info.ll new file mode 100644 index 0000000..bb423e1 --- /dev/null +++ b/llvm/test/Transforms/Attributor/phi_bug_pointer_info.ll @@ -0,0 +1,41 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --check-globals --version 2 +; RUN: opt -aa-pipeline=basic-aa -passes=attributor -debug-only=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s 2>&1 | FileCheck %s +; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -debug-only=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s 2>&1 | FileCheck %s +; REQUIRES: asserts + + +@globalBytes = internal global [1024 x i8] zeroinitializer + +; CHECK: Accesses by bin after update: +; CHECK: [8-12] : 2 +; CHECK: - 9 - store i32 %0, ptr %field2, align 4 +; CHECK: - c: %0 = load i32, ptr %val, align 4 +; CHECK: - 6 - %ret = load i32, ptr %x, align 4 +; CHECK: - c: +; CHECK: [32-36] : 2 +; CHECK: - 9 - store i32 %1, ptr %field8, align 4 +; CHECK: - c: %1 = load i32, ptr %val2, align 4 +; CHECK: - 6 - %ret = load i32, ptr %x, align 4 +; CHECK: - c: +define dso_local i32 @phi_different_offsets(ptr nocapture %val, ptr nocapture %val2, i1 %cmp) { +entry: + br i1 %cmp, label %then, label %else + +then: + %field2 = getelementptr i32, ptr @globalBytes, i32 2 + %1 = load i32, ptr %val + store i32 %1, ptr %field2 + br label %end + +else: + %field8 = getelementptr i32, ptr @globalBytes, i32 8 + %2 = load i32, ptr %val2 + store i32 %2, ptr %field8 + br label %end + +end: + %x = phi ptr [ %field2, %then ], [ %field8, %else ] + %ret = load i32, ptr %x + ret i32 %ret + +} -- cgit v1.1 From fdd04e8c0c8bf19384901e8104f0643c4537ad73 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:21:14 -0700 Subject: WinCOFFObjectWriter: replace the MCAsmLayout parameter with MCAssembler --- llvm/lib/MC/WinCOFFObjectWriter.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index cd20985..c0bad19 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -18,7 +18,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/COFF.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" @@ -188,15 +187,13 @@ private: void WriteAuxiliarySymbols(const COFFSymbol::AuxiliarySymbols &S); void writeSectionHeaders(); void WriteRelocation(const COFF::relocation &R); - uint32_t writeSectionContents(MCAssembler &Asm, const MCAsmLayout &Layout, - const MCSection &MCSec); - void writeSection(MCAssembler &Asm, const MCAsmLayout &Layout, - const COFFSection &Sec); + uint32_t writeSectionContents(MCAssembler &Asm, const MCSection &MCSec); + void writeSection(MCAssembler &Asm, const COFFSection &Sec); void createFileSymbols(MCAssembler &Asm); void setWeakDefaultNames(); void assignSectionNumbers(); - void assignFileOffsets(MCAssembler &Asm, const MCAsmLayout &Layout); + void assignFileOffsets(MCAssembler &Asm); }; class WinCOFFObjectWriter : public MCObjectWriter { @@ -601,7 +598,6 @@ void WinCOFFWriter::WriteRelocation(const COFF::relocation &R) { // "Asm.writeSectionData(&MCSec)", but it's a bit complicated // because it needs to compute a CRC. uint32_t WinCOFFWriter::writeSectionContents(MCAssembler &Asm, - const MCAsmLayout &Layout, const MCSection &MCSec) { // Save the contents of the section to a temporary buffer, we need this // to CRC the data before we dump it into the object file. @@ -619,8 +615,7 @@ uint32_t WinCOFFWriter::writeSectionContents(MCAssembler &Asm, return JC.getCRC(); } -void WinCOFFWriter::writeSection(MCAssembler &Asm, const MCAsmLayout &Layout, - const COFFSection &Sec) { +void WinCOFFWriter::writeSection(MCAssembler &Asm, const COFFSection &Sec) { if (Sec.Number == -1) return; @@ -629,7 +624,7 @@ void WinCOFFWriter::writeSection(MCAssembler &Asm, const MCAsmLayout &Layout, assert(W.OS.tell() == Sec.Header.PointerToRawData && "Section::PointerToRawData is insane!"); - uint32_t CRC = writeSectionContents(Asm, Layout, *Sec.MCSection); + uint32_t CRC = writeSectionContents(Asm, *Sec.MCSection); // Update the section definition auxiliary symbol to record the CRC. COFFSymbol::AuxiliarySymbols &AuxSyms = Sec.Symbol->Aux; @@ -761,8 +756,7 @@ void WinCOFFWriter::assignSectionNumbers() { } // Assign file offsets to COFF object file structures. -void WinCOFFWriter::assignFileOffsets(MCAssembler &Asm, - const MCAsmLayout &Layout) { +void WinCOFFWriter::assignFileOffsets(MCAssembler &Asm) { unsigned Offset = W.OS.tell(); Offset += UseBigObj ? COFF::Header32Size : COFF::Header16Size; @@ -1127,7 +1121,7 @@ uint64_t WinCOFFWriter::writeObject(MCAssembler &Asm) { } } - assignFileOffsets(Asm, *Asm.getLayout()); + assignFileOffsets(Asm); // MS LINK expects to be able to use this timestamp to implement their // /INCREMENTAL feature. @@ -1157,7 +1151,7 @@ uint64_t WinCOFFWriter::writeObject(MCAssembler &Asm) { // Write section contents. for (std::unique_ptr &Sec : Sections) - writeSection(Asm, *Asm.getLayout(), *Sec); + writeSection(Asm, *Sec); assert(W.OS.tell() == Header.PointerToSymbolTable && "Header::PointerToSymbolTable is insane!"); -- cgit v1.1 From 557168767607dbf640b57bbfb97d870e6de07d4e Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 1 Jul 2024 17:23:45 -0700 Subject: [LoongArch] Fix a warning This patch fixes: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp:389:9: error: unused variable 'Layout' [-Werror,-Wunused-variable] --- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp index 0d65bde..a4ba831 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp @@ -402,6 +402,7 @@ bool LoongArchAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, Layout.getAssembler().getContext().getAsmInfo()->getMinInstAlignment() == 1 && "expected 1-byte alignment"); + (void)Layout; if (Value == 0) { WasRelaxed = OldSize != Data.size(); return true; -- cgit v1.1 From a7ddd605ca0a228fb1cf6b6aeb21f458778a8f69 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:24:41 -0700 Subject: XCOFFObjectWriter: replace the MCAsmLayout parameter with MCAssembler --- llvm/lib/MC/XCOFFObjectWriter.cpp | 45 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp index bce9ebd..03a4ee8 100644 --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -12,7 +12,6 @@ #include "llvm/BinaryFormat/XCOFF.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCFixup.h" #include "llvm/MC/MCFixupKindInfo.h" @@ -379,18 +378,16 @@ class XCOFFObjectWriter : public MCObjectWriter { void writeSectionHeaderTable(); void writeSections(const MCAssembler &Asm); void writeSectionForControlSectionEntry(const MCAssembler &Asm, - const MCAsmLayout &Layout, const CsectSectionEntry &CsectEntry, uint64_t &CurrentAddressLocation); void writeSectionForDwarfSectionEntry(const MCAssembler &Asm, - const MCAsmLayout &Layout, const DwarfSectionEntry &DwarfEntry, uint64_t &CurrentAddressLocation); - void writeSectionForExceptionSectionEntry( - const MCAssembler &Asm, const MCAsmLayout &Layout, - ExceptionSectionEntry &ExceptionEntry, uint64_t &CurrentAddressLocation); + void + writeSectionForExceptionSectionEntry(const MCAssembler &Asm, + ExceptionSectionEntry &ExceptionEntry, + uint64_t &CurrentAddressLocation); void writeSectionForCInfoSymSectionEntry(const MCAssembler &Asm, - const MCAsmLayout &Layout, CInfoSymSectionEntry &CInfoSymEntry, uint64_t &CurrentAddressLocation); void writeSymbolTable(MCAssembler &Asm); @@ -419,7 +416,7 @@ class XCOFFObjectWriter : public MCObjectWriter { // *) Assigns symbol table indices. // *) Builds up the section header table by adding any non-empty sections to // `Sections`. - void assignAddressesAndIndices(MCAssembler &Asm, const MCAsmLayout &); + void assignAddressesAndIndices(MCAssembler &Asm); // Called after relocations are recorded. void finalizeSectionInfo(); void finalizeRelocationInfo(SectionEntry *Sec, uint64_t RelCount); @@ -655,7 +652,7 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm) { Strings.add(Vers); Strings.finalize(); - assignAddressesAndIndices(Asm, *Asm.getLayout()); + assignAddressesAndIndices(Asm); } void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm, @@ -813,17 +810,14 @@ void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm, } void XCOFFObjectWriter::writeSections(const MCAssembler &Asm) { - auto &Layout = *Asm.getLayout(); uint64_t CurrentAddressLocation = 0; for (const auto *Section : Sections) - writeSectionForControlSectionEntry(Asm, Layout, *Section, - CurrentAddressLocation); + writeSectionForControlSectionEntry(Asm, *Section, CurrentAddressLocation); for (const auto &DwarfSection : DwarfSections) - writeSectionForDwarfSectionEntry(Asm, Layout, DwarfSection, - CurrentAddressLocation); - writeSectionForExceptionSectionEntry(Asm, Layout, ExceptionSection, + writeSectionForDwarfSectionEntry(Asm, DwarfSection, CurrentAddressLocation); + writeSectionForExceptionSectionEntry(Asm, ExceptionSection, CurrentAddressLocation); - writeSectionForCInfoSymSectionEntry(Asm, Layout, CInfoSymSection, + writeSectionForCInfoSymSectionEntry(Asm, CInfoSymSection, CurrentAddressLocation); } @@ -1419,8 +1413,7 @@ void XCOFFObjectWriter::addCInfoSymEntry(StringRef Name, StringRef Metadata) { std::make_unique(Name.str(), Metadata.str())); } -void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm, - const MCAsmLayout &Layout) { +void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm) { // The symbol table starts with all the C_FILE symbols. Each C_FILE symbol // requires 1 or 2 auxiliary entries. uint32_t SymbolTableIndex = @@ -1597,8 +1590,8 @@ void XCOFFObjectWriter::assignAddressesAndIndices(MCAssembler &Asm, } void XCOFFObjectWriter::writeSectionForControlSectionEntry( - const MCAssembler &Asm, const MCAsmLayout &Layout, - const CsectSectionEntry &CsectEntry, uint64_t &CurrentAddressLocation) { + const MCAssembler &Asm, const CsectSectionEntry &CsectEntry, + uint64_t &CurrentAddressLocation) { // Nothing to write for this Section. if (CsectEntry.Index == SectionEntry::UninitializedIndex) return; @@ -1644,8 +1637,8 @@ void XCOFFObjectWriter::writeSectionForControlSectionEntry( } void XCOFFObjectWriter::writeSectionForDwarfSectionEntry( - const MCAssembler &Asm, const MCAsmLayout &Layout, - const DwarfSectionEntry &DwarfEntry, uint64_t &CurrentAddressLocation) { + const MCAssembler &Asm, const DwarfSectionEntry &DwarfEntry, + uint64_t &CurrentAddressLocation) { // There could be a gap (without corresponding zero padding) between // sections. For example DWARF section alignment is bigger than // DefaultSectionAlign. @@ -1672,8 +1665,8 @@ void XCOFFObjectWriter::writeSectionForDwarfSectionEntry( } void XCOFFObjectWriter::writeSectionForExceptionSectionEntry( - const MCAssembler &Asm, const MCAsmLayout &Layout, - ExceptionSectionEntry &ExceptionEntry, uint64_t &CurrentAddressLocation) { + const MCAssembler &Asm, ExceptionSectionEntry &ExceptionEntry, + uint64_t &CurrentAddressLocation) { for (auto it = ExceptionEntry.ExceptionTable.begin(); it != ExceptionEntry.ExceptionTable.end(); it++) { // For every symbol that has exception entries, you must start the entries @@ -1695,8 +1688,8 @@ void XCOFFObjectWriter::writeSectionForExceptionSectionEntry( } void XCOFFObjectWriter::writeSectionForCInfoSymSectionEntry( - const MCAssembler &Asm, const MCAsmLayout &Layout, - CInfoSymSectionEntry &CInfoSymEntry, uint64_t &CurrentAddressLocation) { + const MCAssembler &Asm, CInfoSymSectionEntry &CInfoSymEntry, + uint64_t &CurrentAddressLocation) { if (!CInfoSymSection.Entry) return; -- cgit v1.1 From e8e05c3192af5c4a71cd2af03c1425158fc647cd Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:36:16 -0700 Subject: [MC] Remove the MCAsmLayout parameter from MCAsmBackend::finishLayout And remove unnecessary MCAssembler::finishLayout. --- llvm/include/llvm/MC/MCAsmBackend.h | 4 +--- llvm/include/llvm/MC/MCAssembler.h | 3 --- llvm/lib/MC/MCAssembler.cpp | 7 +------ llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp | 3 +-- llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp | 5 ++--- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/llvm/include/llvm/MC/MCAsmBackend.h b/llvm/include/llvm/MC/MCAsmBackend.h index 7841e8a..f91c8e1 100644 --- a/llvm/include/llvm/MC/MCAsmBackend.h +++ b/llvm/include/llvm/MC/MCAsmBackend.h @@ -24,7 +24,6 @@ class MCFragment; class MCLEBFragment; class MCRelaxableFragment; class MCSymbol; -class MCAsmLayout; class MCAssembler; class MCContext; struct MCDwarfFrameInfo; @@ -219,8 +218,7 @@ public: const MCSubtargetInfo *STI) const = 0; /// Give backend an opportunity to finish layout after relaxation - virtual void finishLayout(MCAssembler const &Asm, - MCAsmLayout &Layout) const {} + virtual void finishLayout(MCAssembler const &Asm) const {} /// Handle any target-specific assembler flags. By default, do nothing. virtual void handleAssemblerFlag(MCAssemblerFlag Flag) {} diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h index cc0267e..4eb0a91 100644 --- a/llvm/include/llvm/MC/MCAssembler.h +++ b/llvm/include/llvm/MC/MCAssembler.h @@ -210,9 +210,6 @@ private: bool relaxCVDefRange(MCCVDefRangeFragment &DF); bool relaxPseudoProbeAddr(MCPseudoProbeAddrFragment &DF); - /// finishLayout - Finalize a layout, including fragment lowering. - void finishLayout(MCAsmLayout &Layout); - std::tuple handleFixup(MCFragment &F, const MCFixup &Fixup, const MCSubtargetInfo *STI); diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index f820cc9..0a6bb52 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -984,7 +984,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) { dump(); }); // Finalize the layout, including fragment lowering. - finishLayout(Layout); + getBackend().finishLayout(*this); DEBUG_WITH_TYPE("mc-dump", { errs() << "assembler backend - final-layout\n--\n"; @@ -1350,11 +1350,6 @@ bool MCAssembler::layoutOnce() { return Changed; } -void MCAssembler::finishLayout(MCAsmLayout &Layout) { - assert(getBackendPtr() && "Expected assembler backend"); - getBackend().finishLayout(*this, Layout); -} - #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void MCAssembler::dump() const{ raw_ostream &OS = errs(); diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp index 2ce91bd..e9f49f6 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp @@ -703,8 +703,7 @@ public: return true; } - void finishLayout(MCAssembler const &Asm, - MCAsmLayout &Layout) const override { + void finishLayout(MCAssembler const &Asm) const override { SmallVector Frags; for (MCSection &Sec : Asm) { Frags.clear(); diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp index 670ff35..2b2cbfb 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -202,7 +202,7 @@ public: bool padInstructionEncoding(MCRelaxableFragment &RF, MCCodeEmitter &Emitter, unsigned &RemainingSize) const; - void finishLayout(MCAssembler const &Asm, MCAsmLayout &Layout) const override; + void finishLayout(const MCAssembler &Asm) const override; unsigned getMaximumNopSize(const MCSubtargetInfo &STI) const override; @@ -857,8 +857,7 @@ bool X86AsmBackend::padInstructionEncoding(MCRelaxableFragment &RF, return Changed; } -void X86AsmBackend::finishLayout(MCAssembler const &Asm, - MCAsmLayout &Layout) const { +void X86AsmBackend::finishLayout(MCAssembler const &Asm) const { // See if we can further relax some instructions to cut down on the number of // nop bytes required for code alignment. The actual win is in reducing // instruction count, not number of bytes. Modern X86-64 can easily end up -- cgit v1.1 From 926d142ece6a99da3f6d3438e9b2ab8ca31ac3a9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:43:17 -0700 Subject: [LoongArch] Remove unneeded MCAsmLayout --- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp index a4ba831..9235ade 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp @@ -386,7 +386,6 @@ bool LoongArchAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, SmallVectorImpl &Fixups = DF.getFixups(); size_t OldSize = Data.size(); - auto &Layout = *Asm.getLayout(); int64_t Value; if (AddrDelta.evaluateAsAbsolute(Value, Asm)) return false; @@ -398,11 +397,8 @@ bool LoongArchAsmBackend::relaxDwarfCFA(const MCAssembler &Asm, Fixups.clear(); raw_svector_ostream OS(Data); - assert( - Layout.getAssembler().getContext().getAsmInfo()->getMinInstAlignment() == - 1 && - "expected 1-byte alignment"); - (void)Layout; + assert(Asm.getContext().getAsmInfo()->getMinInstAlignment() == 1 && + "expected 1-byte alignment"); if (Value == 0) { WasRelaxed = OldSize != Data.size(); return true; -- cgit v1.1 From 057f28be3e1188de518bcbf007fee759aa7e812a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 17:47:13 -0700 Subject: [MC] Remove unused MCAsmLayout declarations and includes --- llvm/include/llvm/MC/MCAssembler.h | 2 -- llvm/include/llvm/MC/MCFragment.h | 1 - llvm/include/llvm/MC/MCObjectWriter.h | 1 - llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp | 1 - llvm/lib/MC/ELFObjectWriter.cpp | 1 - llvm/lib/MC/GOFFObjectWriter.cpp | 1 - llvm/lib/MC/MCDXContainerWriter.cpp | 1 - llvm/lib/MC/MCLinkerOptimizationHint.cpp | 1 - llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp | 1 - llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp | 1 - llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp | 1 - llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp | 1 - llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp | 1 - llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp | 1 - llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp | 1 - llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 1 - llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h | 1 - llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h | 1 - llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 1 - llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp | 1 - llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp | 1 - llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp | 1 - 22 files changed, 23 deletions(-) diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h index 4eb0a91..1e476ae6 100644 --- a/llvm/include/llvm/MC/MCAssembler.h +++ b/llvm/include/llvm/MC/MCAssembler.h @@ -71,8 +71,6 @@ struct DataRegionData { }; class MCAssembler { - friend class MCAsmLayout; - public: using SectionListType = std::vector; using SymbolDataListType = std::vector; diff --git a/llvm/include/llvm/MC/MCFragment.h b/llvm/include/llvm/MC/MCFragment.h index c8832e6..ee93cb9 100644 --- a/llvm/include/llvm/MC/MCFragment.h +++ b/llvm/include/llvm/MC/MCFragment.h @@ -30,7 +30,6 @@ class MCSubtargetInfo; class MCSymbol; class MCFragment { - friend class MCAsmLayout; friend class MCAssembler; friend class MCObjectStreamer; friend class MCSection; diff --git a/llvm/include/llvm/MC/MCObjectWriter.h b/llvm/include/llvm/MC/MCObjectWriter.h index 4184c4f..0111446 100644 --- a/llvm/include/llvm/MC/MCObjectWriter.h +++ b/llvm/include/llvm/MC/MCObjectWriter.h @@ -15,7 +15,6 @@ namespace llvm { -class MCAsmLayout; class MCAssembler; class MCFixup; class MCFragment; diff --git a/llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp b/llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp index 37842b1..4074b67 100644 --- a/llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp +++ b/llvm/lib/Analysis/InlineSizeEstimatorAnalysis.cpp @@ -30,7 +30,6 @@ AnalysisKey InlineSizeEstimatorAnalysis::Key; #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Instructions.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index be4831d..bcc6dfe 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -21,7 +21,6 @@ #include "llvm/BinaryFormat/ELF.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCELFObjectWriter.h" diff --git a/llvm/lib/MC/GOFFObjectWriter.cpp b/llvm/lib/MC/GOFFObjectWriter.cpp index 9c43ef1a..76f3735 100644 --- a/llvm/lib/MC/GOFFObjectWriter.cpp +++ b/llvm/lib/MC/GOFFObjectWriter.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "llvm/BinaryFormat/GOFF.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCGOFFObjectWriter.h" #include "llvm/MC/MCValue.h" diff --git a/llvm/lib/MC/MCDXContainerWriter.cpp b/llvm/lib/MC/MCDXContainerWriter.cpp index 002fe2f..6b42d38 100644 --- a/llvm/lib/MC/MCDXContainerWriter.cpp +++ b/llvm/lib/MC/MCDXContainerWriter.cpp @@ -8,7 +8,6 @@ #include "llvm/MC/MCDXContainerWriter.h" #include "llvm/BinaryFormat/DXContainer.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSection.h" diff --git a/llvm/lib/MC/MCLinkerOptimizationHint.cpp b/llvm/lib/MC/MCLinkerOptimizationHint.cpp index 2e6fde2..a0901af 100644 --- a/llvm/lib/MC/MCLinkerOptimizationHint.cpp +++ b/llvm/lib/MC/MCLinkerOptimizationHint.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "llvm/MC/MCLinkerOptimizationHint.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCMachObjectWriter.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/raw_ostream.h" diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp index a1f2259..33f0ca2 100644 --- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp +++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp @@ -12,7 +12,6 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAsmInfoDarwin.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp index 75b74f1..b2a9667 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp @@ -10,7 +10,6 @@ #include "GCNSubtarget.h" #include "Utils/AMDGPUBaseInfo.h" #include "llvm/IR/Function.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCStreamer.h" diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp index 48b4b69..33eb1cf 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp @@ -17,7 +17,6 @@ #include "llvm/BinaryFormat/ELF.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDirectives.h" diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp index e9f2c3e..e4a2cce 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp @@ -12,7 +12,6 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/BinaryFormat/MachO.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp index be3b9ab..87355561 100644 --- a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp +++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp @@ -8,7 +8,6 @@ #include "AVRMCExpr.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCStreamer.h" diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp index 222dc2c..dd06971 100644 --- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp +++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp @@ -9,7 +9,6 @@ #include "CSKYAsmBackend.h" #include "MCTargetDesc/CSKYMCTargetDesc.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCFixupKindInfo.h" diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp index e9f49f6..6acc37e 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp @@ -14,7 +14,6 @@ #include "MCTargetDesc/HexagonMCShuffler.h" #include "MCTargetDesc/HexagonMCTargetDesc.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCELFObjectWriter.h" diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp index 9235ade..0c24008 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp @@ -13,7 +13,6 @@ #include "LoongArchAsmBackend.h" #include "LoongArchFixupKinds.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCELFObjectWriter.h" diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h index 2dc3661e..fc97200 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsMCExpr.h @@ -9,7 +9,6 @@ #ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCEXPR_H #define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCEXPR_H -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCValue.h" diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h index 6209601..59ca514 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.h @@ -9,7 +9,6 @@ #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCMCEXPR_H -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCValue.h" diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp index 1bd23e6..cb64b64 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -10,7 +10,6 @@ #include "RISCVMCExpr.h" #include "llvm/ADT/APInt.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDirectives.h" diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp index 3b5f37d..16d0796 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp @@ -15,7 +15,6 @@ #include "MCTargetDesc/RISCVAsmBackend.h" #include "RISCVFixupKinds.h" #include "llvm/BinaryFormat/ELF.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCStreamer.h" diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp index 2b2cbfb..09a6d57 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -13,7 +13,6 @@ #include "llvm/BinaryFormat/ELF.h" #include "llvm/BinaryFormat/MachO.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCContext.h" diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp index a956ae3..ec95b1f 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp @@ -12,7 +12,6 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAsmInfoDarwin.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCMachObjectWriter.h" -- cgit v1.1 From e3e0df391c7116b519499aab2eba8990c647cdf5 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 18:02:34 -0700 Subject: [BOLT] Replace the MCAsmLayout parameter with MCAssembler Continue the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95. --- bolt/include/bolt/Rewrite/DWARFRewriter.h | 3 +-- bolt/lib/Rewrite/DWARFRewriter.cpp | 5 ++--- bolt/lib/Rewrite/RewriteInstance.cpp | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bolt/include/bolt/Rewrite/DWARFRewriter.h b/bolt/include/bolt/Rewrite/DWARFRewriter.h index 4559ff5..c34fbd5 100644 --- a/bolt/include/bolt/Rewrite/DWARFRewriter.h +++ b/bolt/include/bolt/Rewrite/DWARFRewriter.h @@ -16,7 +16,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/CodeGen/DIE.h" #include "llvm/DWP/DWP.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCContext.h" #include "llvm/Support/ToolOutputFile.h" #include @@ -183,7 +182,7 @@ public: void updateDebugInfo(); /// Update stmt_list for CUs based on the new .debug_line \p Layout. - void updateLineTableOffsets(const MCAsmLayout &Layout); + void updateLineTableOffsets(const MCAssembler &Asm); uint64_t getDwoRangesBase(uint64_t DWOId) { return DwoRangesBase[DWOId]; } diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp index 110f53f..1f5c3a4 100644 --- a/bolt/lib/Rewrite/DWARFRewriter.cpp +++ b/bolt/lib/Rewrite/DWARFRewriter.cpp @@ -29,7 +29,6 @@ #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCStreamer.h" @@ -1352,7 +1351,7 @@ void DWARFRewriter::updateDWARFObjectAddressRanges( } } -void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) { +void DWARFRewriter::updateLineTableOffsets(const MCAssembler &Asm) { ErrorOr DbgInfoSection = BC.getUniqueSectionByName(".debug_info"); ErrorOr TypeInfoSection = @@ -1394,7 +1393,7 @@ void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) { continue; const uint64_t LineTableOffset = - Layout.getAssembler().getSymbolOffset(*Label); + Asm.getSymbolOffset(*Label); DebugLineOffsetMap[*StmtOffset] = LineTableOffset; assert(DbgInfoSection && ".debug_info section must exist"); LineTablePatchMap[CU.get()] = LineTableOffset; diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index c118f2c..8248c1c 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -40,7 +40,6 @@ #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCDisassembler/MCDisassembler.h" #include "llvm/MC/MCObjectStreamer.h" #include "llvm/MC/MCStreamer.h" @@ -3508,9 +3507,8 @@ void RewriteInstance::emitAndLink() { updateOutputValues(*Linker); if (opts::UpdateDebugSections) { - MCAsmLayout FinalLayout( - static_cast(Streamer.get())->getAssembler()); - DebugInfoRewriter->updateLineTableOffsets(FinalLayout); + DebugInfoRewriter->updateLineTableOffsets( + static_cast(*Streamer).getAssembler()); } if (RuntimeLibrary *RtLibrary = BC->getRuntimeLibrary()) -- cgit v1.1 From bbb50369a149d9a7d1f91efaaabf75c260a220c7 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 18:04:27 -0700 Subject: [MC] Use a stub ctor for MCAsmLayout and replace MCAssembler::Layout with a bool. This mostly completes "[MC] Start merging MCAsmLayout into MCAssembler". --- llvm/include/llvm/MC/MCAsmLayout.h | 11 +---------- llvm/include/llvm/MC/MCAssembler.h | 5 ++--- llvm/lib/MC/MCAssembler.cpp | 10 +++++----- llvm/lib/MC/MCExpr.cpp | 4 ++-- llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp | 2 +- llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp | 2 +- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/llvm/include/llvm/MC/MCAsmLayout.h b/llvm/include/llvm/MC/MCAsmLayout.h index 765cc1e..33fae0a 100644 --- a/llvm/include/llvm/MC/MCAsmLayout.h +++ b/llvm/include/llvm/MC/MCAsmLayout.h @@ -9,21 +9,12 @@ #ifndef LLVM_MC_MCASMLAYOUT_H #define LLVM_MC_MCASMLAYOUT_H -#include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/SmallVector.h" - namespace llvm { class MCAssembler; -class MCSection; class MCAsmLayout { - MCAssembler &Assembler; - public: - MCAsmLayout(MCAssembler &Assembler); - - /// Get the assembler object this is a layout for. - MCAssembler &getAssembler() const { return Assembler; } + MCAsmLayout(MCAssembler &) {} }; } // end namespace llvm diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h index 1e476ae6..df5ad0e 100644 --- a/llvm/include/llvm/MC/MCAssembler.h +++ b/llvm/include/llvm/MC/MCAssembler.h @@ -116,7 +116,7 @@ private: std::unique_ptr Emitter; std::unique_ptr Writer; - MCAsmLayout *Layout = nullptr; + bool HasLayout = false; bool RelaxAll = false; bool SubsectionsViaSymbols = false; bool IncrementalLinkerCompatible = false; @@ -354,8 +354,7 @@ public: IncrementalLinkerCompatible = Value; } - MCAsmLayout *getLayout() const { return Layout; } - bool hasLayout() const { return Layout; } + bool hasLayout() const { return HasLayout; } bool getRelaxAll() const { return RelaxAll; } void setRelaxAll(bool Value) { RelaxAll = Value; } diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 0a6bb52..6866a58 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -381,8 +381,6 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const { llvm_unreachable("invalid fragment kind"); } -MCAsmLayout::MCAsmLayout(MCAssembler &Asm) : Assembler(Asm) {} - // Compute the amount of padding required before the fragment \p F to // obey bundling restrictions, where \p FOffset is the fragment's offset in // its section and \p FSize is the fragment's size. @@ -541,13 +539,14 @@ bool MCAssembler::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const { } uint64_t MCAssembler::getSymbolOffset(const MCSymbol &S) const { + assert(HasLayout); uint64_t Val; getSymbolOffsetImpl(*this, S, true, Val); return Val; } const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const { - assert(Layout); + assert(HasLayout); if (!Symbol.isVariable()) return &Symbol; @@ -584,6 +583,7 @@ const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const { } uint64_t MCAssembler::getSectionAddressSize(const MCSection &Sec) const { + assert(HasLayout); // The size is the last fragment's end offset. const MCFragment &F = *Sec.curFragList()->Tail; return getFragmentOffset(F) + computeFragmentSize(F); @@ -968,7 +968,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) { } // Layout until everything fits. - this->Layout = &Layout; + this->HasLayout = true; while (layoutOnce()) { if (getContext().hadError()) return; @@ -1081,7 +1081,7 @@ void MCAssembler::Finish() { // Write the object file. stats::ObjectBytes += getWriter().writeObject(*this); - this->Layout = nullptr; + HasLayout = false; } bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup, diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index 8279539..0a175ade 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -626,7 +626,7 @@ static void AttemptToFoldSymbolOffsetDifference( // separated by a linker-relaxable instruction. If the section contains // instructions and InSet is false (not expressions in directive like // .size/.fill), disable the fast path. - const MCAsmLayout *Layout = Asm->getLayout(); + bool Layout = Asm->hasLayout(); if (Layout && (InSet || !SecA.hasInstructions() || !(Asm->getContext().getTargetTriple().isRISCV() || Asm->getContext().getTargetTriple().isLoongArch()))) { @@ -817,7 +817,6 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const SectionAddrMap *Addrs, bool InSet) const { ++stats::MCExprEvaluate; - MCAsmLayout *Layout = Asm ? Asm->getLayout() : nullptr; switch (getKind()) { case Target: return cast(this)->evaluateAsRelocatableImpl(Res, Asm, Fixup); @@ -830,6 +829,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCSymbolRefExpr *SRE = cast(this); const MCSymbol &Sym = SRE->getSymbol(); const auto Kind = SRE->getKind(); + bool Layout = Asm && Asm->hasLayout(); // Evaluate recursively if this is a variable. if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) && diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp index 87355561..5386df7 100644 --- a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp +++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCExpr.cpp @@ -79,7 +79,7 @@ bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result, if (Value.isAbsolute()) { Result = MCValue::get(evaluateAsInt64(Value.getConstant())); } else { - if (!Asm || !Asm->getLayout()) + if (!Asm || !Asm->hasLayout()) return false; MCContext &Context = Asm->getContext(); diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp index 05fc733..cc1d981 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp @@ -122,7 +122,7 @@ bool PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, Res = MCValue::get(Result); } else { - if (!Asm || !Asm->getLayout()) + if (!Asm || !Asm->hasLayout()) return false; MCContext &Context = Asm->getContext(); -- cgit v1.1 From 63ec52f867ada8d841dd872acf3d0cb62e2a99e8 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 18:17:05 -0700 Subject: MCAssembler::layout: remove the unused MCAsmLayout parameter Almost complete the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95. --- bolt/lib/Core/BinaryContext.cpp | 4 +--- llvm/include/llvm/MC/MCAssembler.h | 3 +-- llvm/lib/MC/MCAssembler.cpp | 7 ++----- llvm/lib/MC/MCExpr.cpp | 1 - llvm/tools/dsymutil/MachOUtils.cpp | 4 +--- 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp index 3bd715d..f28a0cd 100644 --- a/bolt/lib/Core/BinaryContext.cpp +++ b/bolt/lib/Core/BinaryContext.cpp @@ -20,7 +20,6 @@ #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFUnit.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDisassembler/MCDisassembler.h" @@ -2416,8 +2415,7 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) { MCAssembler &Assembler = static_cast(Streamer.get())->getAssembler(); - MCAsmLayout Layout(Assembler); - Assembler.layout(Layout); + Assembler.layout(); // Obtain fragment sizes. std::vector FragmentSizes; diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h index df5ad0e..9cd65d3 100644 --- a/llvm/include/llvm/MC/MCAssembler.h +++ b/llvm/include/llvm/MC/MCAssembler.h @@ -46,7 +46,6 @@ class MCRelaxableFragment; class MCSymbolRefExpr; class raw_ostream; class MCAsmBackend; -class MCAsmLayout; class MCContext; class MCCodeEmitter; class MCFragment; @@ -341,7 +340,7 @@ public: void Finish(); // Layout all section and prepare them for emission. - void layout(MCAsmLayout &Layout); + void layout(); // FIXME: This does not belong here. bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; } diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 6866a58..4cafec6 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -15,7 +15,6 @@ #include "llvm/ADT/Twine.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCCodeEmitter.h" #include "llvm/MC/MCCodeView.h" #include "llvm/MC/MCContext.h" @@ -937,7 +936,7 @@ MCAssembler::handleFixup(MCFragment &F, const MCFixup &Fixup, return std::make_tuple(Target, FixedValue, IsResolved); } -void MCAssembler::layout(MCAsmLayout &Layout) { +void MCAssembler::layout() { assert(getBackendPtr() && "Expected assembler backend"); DEBUG_WITH_TYPE("mc-dump", { errs() << "assembler backend - pre-layout\n--\n"; @@ -1074,9 +1073,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) { } void MCAssembler::Finish() { - // Create the layout object. - MCAsmLayout Layout(*this); - layout(Layout); + layout(); // Write the object file. stats::ObjectBytes += getWriter().writeObject(*this); diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index 0a175ade..b42a668 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -12,7 +12,6 @@ #include "llvm/Config/llvm-config.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCObjectWriter.h" diff --git a/llvm/tools/dsymutil/MachOUtils.cpp b/llvm/tools/dsymutil/MachOUtils.cpp index fba6630..d2bdcf8 100644 --- a/llvm/tools/dsymutil/MachOUtils.cpp +++ b/llvm/tools/dsymutil/MachOUtils.cpp @@ -12,7 +12,6 @@ #include "LinkUtils.h" #include "llvm/ADT/SmallString.h" #include "llvm/CodeGen/NonRelocatableStringpool.h" -#include "llvm/MC/MCAsmLayout.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCMachObjectWriter.h" #include "llvm/MC/MCObjectStreamer.h" @@ -381,8 +380,7 @@ bool generateDsymCompanion( auto &Writer = static_cast(MCAsm.getWriter()); // Layout but don't emit. - MCAsmLayout Layout(MCAsm); - MCAsm.layout(Layout); + MCAsm.layout(); BinaryHolder InputBinaryHolder(VFS, false); -- cgit v1.1 From 299d3ddc618e9a95aa1050e4c1a7dfddbcd94395 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 1 Jul 2024 18:08:36 -0700 Subject: [RISCV] Simplify some control flow in RISCVISAInfo::parseArchString. NFC Merge handling of the baseline ISA into the switch that checks if the baseline is valid. Invert a condition to allow a better early out to reduce curly braces. --- llvm/lib/TargetParser/RISCVISAInfo.cpp | 59 ++++++++++++++++------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index 91ade25..869be57 100644 --- a/llvm/lib/TargetParser/RISCVISAInfo.cpp +++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp @@ -585,6 +585,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, // The canonical order specified in ISA manual. // Ref: Table 22.1 in RISC-V User-Level ISA V2.2 char Baseline = Arch.front(); + // Skip the baseline. + StringRef Exts = Arch.drop_front(); + + unsigned Major, Minor, ConsumeLength; // First letter should be 'e', 'i' or 'g'. switch (Baseline) { @@ -594,20 +598,29 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, "\' should be 'e', 'i' or 'g'"); case 'e': case 'i': + // Baseline is `i` or `e` + if (auto E = getExtensionVersion( + StringRef(&Baseline, 1), Exts, Major, Minor, ConsumeLength, + EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) { + if (!IgnoreUnknown) + return std::move(E); + // If IgnoreUnknown, then ignore an unrecognised version of the baseline + // ISA and just use the default supported version. + consumeError(std::move(E)); + auto Version = findDefaultVersion(StringRef(&Baseline, 1)); + Major = Version->Major; + Minor = Version->Minor; + } + + // Postpone AddExtension until end of this function + SeenExtMap[StringRef(&Baseline, 1).str()] = {Major, Minor}; break; case 'g': // g expands to extensions in RISCVGImplications. if (Arch.size() > 1 && isDigit(Arch[1])) return createStringError(errc::invalid_argument, "version not supported for 'g'"); - break; - } - - // Skip baseline. - StringRef Exts = Arch.drop_front(1); - unsigned Major, Minor, ConsumeLength; - if (Baseline == 'g') { // Versions for g are disallowed, and this was checked for previously. ConsumeLength = 0; @@ -620,23 +633,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, // Postpone AddExtension until end of this function SeenExtMap[Ext] = {Version->Major, Version->Minor}; } - } else { - // Baseline is `i` or `e` - if (auto E = getExtensionVersion( - StringRef(&Baseline, 1), Exts, Major, Minor, ConsumeLength, - EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) { - if (!IgnoreUnknown) - return std::move(E); - // If IgnoreUnknown, then ignore an unrecognised version of the baseline - // ISA and just use the default supported version. - consumeError(std::move(E)); - auto Version = findDefaultVersion(StringRef(&Baseline, 1)); - Major = Version->Major; - Minor = Version->Minor; - } - - // Postpone AddExtension until end of this function - SeenExtMap[StringRef(&Baseline, 1).str()] = {Major, Minor}; + break; } // Consume the base ISA version number and any '_' between rvxxx and the @@ -694,13 +691,13 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength, EnableExperimentalExtension, ExperimentalExtensionVersionCheck)) { - if (IgnoreUnknown) { - consumeError(std::move(E)); - if (Name.size() == 1) - Ext = Ext.substr(ConsumeLength); - continue; - } - return E; + if (!IgnoreUnknown) + return E; + + consumeError(std::move(E)); + if (Name.size() == 1) + Ext = Ext.substr(ConsumeLength); + continue; } if (Name.size() == 1) -- cgit v1.1 From 9b8c2fae38bcff0b16d996ee002ff1e989fa23ea Mon Sep 17 00:00:00 2001 From: Alfiya Siddique <86224794+AlfiyaSiddique@users.noreply.github.com> Date: Tue, 2 Jul 2024 07:17:36 +0530 Subject: fix: complete comment (#97322) Completing a comment related to dependent template names that abruptly ended and might cause confusion for beginner contributors. Fixes #96718 --- clang/include/clang/AST/TemplateName.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/TemplateName.h b/clang/include/clang/AST/TemplateName.h index 24a7fde..e3b7dd2 100644 --- a/clang/include/clang/AST/TemplateName.h +++ b/clang/include/clang/AST/TemplateName.h @@ -198,7 +198,8 @@ public: /// /// Here, "apply" is treated as a template name within the typename /// specifier in the typedef. "apply" is a nested template, and can -/// only be understood in the context of +/// only be understood in the context of a template instantiation, +/// hence is represented as a dependent template name. class TemplateName { // NameDecl is either a TemplateDecl or a UsingShadowDecl depending on the // NameKind. -- cgit v1.1 From a95c85fba5fde0db8f128cf5564ac333e2b1f90f Mon Sep 17 00:00:00 2001 From: Youngsuk Kim Date: Mon, 1 Jul 2024 21:52:37 -0400 Subject: [llvm][CodeGen] Avoid 'raw_string_ostream::str' (NFC) (#97318) Since `raw_string_ostream` doesn't own the string buffer, it is desirable (in terms of memory safety) for users to directly reference the string buffer rather than use `raw_string_ostream::str()`. Work towards TODO comment to remove `raw_string_ostream::str()`. --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 8 ++++---- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp | 4 ++-- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 2 +- llvm/lib/CodeGen/MIRPrinter.cpp | 6 +++--- llvm/lib/CodeGen/MachineOutliner.cpp | 3 +-- llvm/lib/CodeGen/MachineScheduler.cpp | 2 +- llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 2 +- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 6 +++--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp | 2 +- llvm/lib/CodeGen/TargetInstrInfo.cpp | 4 ++-- 11 files changed, 20 insertions(+), 21 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 0033f0a..c52cbff 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1128,7 +1128,7 @@ static void emitKill(const MachineInstr *MI, AsmPrinter &AP) { OS << ' ' << (Op.isDef() ? "def " : "killed ") << printReg(Op.getReg(), AP.MF->getSubtarget().getRegisterInfo()); } - AP.OutStreamer->AddComment(OS.str()); + AP.OutStreamer->AddComment(Str); AP.OutStreamer->addBlankLine(); } @@ -1235,7 +1235,7 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) { } // NOTE: Want this comment at start of line, don't emit with AddComment. - AP.OutStreamer->emitRawComment(OS.str()); + AP.OutStreamer->emitRawComment(Str); return true; } @@ -2274,7 +2274,7 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) { OutContext.getObjectFileInfo()->getRemarksSection(); OutStreamer->switchSection(RemarksSection); - OutStreamer->emitBinaryData(OS.str()); + OutStreamer->emitBinaryData(Buf); } bool AsmPrinter::doFinalization(Module &M) { @@ -3282,7 +3282,7 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV) { OS << "Unsupported expression in static initializer: "; CE->printAsOperand(OS, /*PrintType=*/false, !MF ? nullptr : MF->getFunction().getParent()); - report_fatal_error(Twine(OS.str())); + report_fatal_error(Twine(S)); } static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C, diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp index 08e3c20..5a7013c 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp @@ -311,7 +311,7 @@ static void EmitInlineAsmStr(const char *AsmStr, const MachineInstr *MI, std::string msg; raw_string_ostream Msg(msg); Msg << "invalid operand in inline asm: '" << AsmStr << "'"; - MMI->getModule()->getContext().emitError(LocCookie, Msg.str()); + MMI->getModule()->getContext().emitError(LocCookie, msg); } } break; @@ -411,7 +411,7 @@ void AsmPrinter::emitInlineAsm(const MachineInstr *MI) const { } } - emitInlineAsm(OS.str(), getSubtargetInfo(), TM.Options.MCOptions, LocMD, + emitInlineAsm(StringData, getSubtargetInfo(), TM.Options.MCOptions, LocMD, MI->getInlineAsmDialect()); // Emit the #NOAPP end marker. This has to happen even if verbose-asm isn't diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp index 14e6b79..552d4c9 100644 --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -3984,7 +3984,7 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) { raw_string_ostream InstStr(InstStrStorage); InstStr << Inst; - R << ": '" << InstStr.str() << "'"; + R << ": '" << InstStrStorage << "'"; } reportTranslationError(*MF, *TPC, *ORE, R); diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index 49993f7..48c3e0d 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -570,7 +570,7 @@ void MIRPrinter::convertMachineMetadataNodes(yaml::MachineFunction &YMF, std::string NS; raw_string_ostream StrOS(NS); MD.second->print(StrOS, MST, MF.getFunction().getParent()); - YMF.MachineMetadataNodes.push_back(StrOS.str()); + YMF.MachineMetadataNodes.push_back(NS); } } @@ -588,7 +588,7 @@ void MIRPrinter::convert(yaml::MachineFunction &MF, yaml::MachineConstantPoolValue YamlConstant; YamlConstant.ID = ID++; - YamlConstant.Value = StrOS.str(); + YamlConstant.Value = Str; YamlConstant.Alignment = Constant.getAlign(); YamlConstant.IsTargetSpecific = Constant.isMachineConstantPoolEntry(); @@ -608,7 +608,7 @@ void MIRPrinter::convert(ModuleSlotTracker &MST, for (const auto *MBB : Table.MBBs) { raw_string_ostream StrOS(Str); StrOS << printMBBReference(*MBB); - Entry.Blocks.push_back(StrOS.str()); + Entry.Blocks.push_back(Str); Str.clear(); } YamlJTI.Entries.push_back(Entry); diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index 76e5952..c7ccf10 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -804,8 +804,7 @@ MachineFunction *MachineOutliner::createOutlinedFunction( Mg.getNameWithPrefix(MangledNameStream, F, false); DISubprogram *OutlinedSP = DB.createFunction( - Unit /* Context */, F->getName(), StringRef(MangledNameStream.str()), - Unit /* File */, + Unit /* Context */, F->getName(), StringRef(Dummy), Unit /* File */, 0 /* Line 0 is reserved for compiler-generated code. */, DB.createSubroutineType( DB.getOrCreateTypeArray(std::nullopt)), /* void type */ diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp index cf72f74..4a6d5ed 100644 --- a/llvm/lib/CodeGen/MachineScheduler.cpp +++ b/llvm/lib/CodeGen/MachineScheduler.cpp @@ -4413,7 +4413,7 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { SS << "SU:" << SU->NodeNum; if (DFS) SS << " I:" << DFS->getNumInstrs(SU); - return SS.str(); + return Str; } static std::string getNodeDescription(const SUnit *SU, const ScheduleDAG *G) { diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp index c848ce4..68dece6 100644 --- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp +++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp @@ -1206,7 +1206,7 @@ std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const { oss << ""; else SU->getInstr()->print(oss, /*IsStandalone=*/true); - return oss.str(); + return s; } /// Return the basic block label. It is not necessarilly unique because a block diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 7429763..bc16f88 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -11749,7 +11749,7 @@ SDValue SelectionDAG::getSymbolFunctionGlobalAddress(SDValue Op, raw_string_ostream ErrorFormatter(ErrorStr); ErrorFormatter << "Undefined external symbol "; ErrorFormatter << '"' << Symbol << '"'; - report_fatal_error(Twine(ErrorFormatter.str())); + report_fatal_error(Twine(ErrorStr)); } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 8ce6dfc..ecdbf3e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1778,7 +1778,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) { raw_string_ostream InstStr(InstStrStorage); InstStr << *Inst; - R << ": " << InstStr.str(); + R << ": " << InstStrStorage; } reportFastISelFailure(*MF, *ORE, R, EnableFastISelAbort > 2); @@ -1827,7 +1827,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(const Function &Fn) { std::string InstStrStorage; raw_string_ostream InstStr(InstStrStorage); InstStr << *Inst; - R << ": " << InstStr.str(); + R << ": " << InstStrStorage; } reportFastISelFailure(*MF, *ORE, R, ShouldAbort); @@ -4370,5 +4370,5 @@ void SelectionDAGISel::CannotYetSelect(SDNode *N) { else Msg << "unknown intrinsic #" << iid; } - report_fatal_error(Twine(Msg.str())); + report_fatal_error(Twine(msg)); } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index b66eeb6..ac28f62 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -299,7 +299,7 @@ std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const { } else { O << "CROSS RC COPY"; } - return O.str(); + return s; } void ScheduleDAGSDNodes::getCustomGraphFeatures(GraphWriter &GW) const { diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index e01e7b3..3cd1bb2 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -1750,7 +1750,7 @@ std::string TargetInstrInfo::createMIROperandComment( OS << Info; } - return OS.str(); + return Flags; } int FlagIdx = MI.findInlineAsmFlagIdx(OpIdx); @@ -1784,7 +1784,7 @@ std::string TargetInstrInfo::createMIROperandComment( F.getRegMayBeFolded()) OS << " foldable"; - return OS.str(); + return Flags; } TargetInstrInfo::PipelinerLoopInfo::~PipelinerLoopInfo() = default; -- cgit v1.1 From a833fa7d3ef0ca993e7e788b45349c3246e2995e Mon Sep 17 00:00:00 2001 From: Yunzezhu94 <93851382+Yunzezhu94@users.noreply.github.com> Date: Tue, 2 Jul 2024 09:58:00 +0800 Subject: [RISCV] Move Machine Copy Propagation Pass before Branch relaxation pass (#97261) Machine Copy Propagation Pass may enlarge branch relaxation distance by breaking generation of compressed insts. This commit moves Machine Copy Propagation Pass before Branch relaxation pass so the results of Branch relaxation pass won't be affected by Machine Copy Propagation Pass. --- llvm/lib/Target/RISCV/RISCVTargetMachine.cpp | 5 ++--- llvm/test/CodeGen/RISCV/O3-pipeline.ll | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp index 35d0b34..f76aef7 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp @@ -497,9 +497,6 @@ void RISCVPassConfig::addPreSched2() { } void RISCVPassConfig::addPreEmitPass() { - addPass(&BranchRelaxationPassID); - addPass(createRISCVMakeCompressibleOptPass()); - // TODO: It would potentially be better to schedule copy propagation after // expanding pseudos (in addPreEmitPass2). However, performing copy // propagation after the machine outliner (which runs after addPreEmitPass) @@ -508,6 +505,8 @@ void RISCVPassConfig::addPreEmitPass() { if (TM->getOptLevel() >= CodeGenOptLevel::Default && EnableRISCVCopyPropagation) addPass(createMachineCopyPropagationPass(true)); + addPass(&BranchRelaxationPassID); + addPass(createRISCVMakeCompressibleOptPass()); } void RISCVPassConfig::addPreEmitPass2() { diff --git a/llvm/test/CodeGen/RISCV/O3-pipeline.ll b/llvm/test/CodeGen/RISCV/O3-pipeline.ll index 1eee62e8..3611d92 100644 --- a/llvm/test/CodeGen/RISCV/O3-pipeline.ll +++ b/llvm/test/CodeGen/RISCV/O3-pipeline.ll @@ -182,9 +182,9 @@ ; CHECK-NEXT: Insert fentry calls ; CHECK-NEXT: Insert XRay ops ; CHECK-NEXT: Implement the 'patchable-function' attribute +; CHECK-NEXT: Machine Copy Propagation Pass ; CHECK-NEXT: Branch relaxation pass ; CHECK-NEXT: RISC-V Make Compressible -; CHECK-NEXT: Machine Copy Propagation Pass ; CHECK-NEXT: Contiguously Lay Out Funclets ; CHECK-NEXT: StackMap Liveness Analysis ; CHECK-NEXT: Live DEBUG_VALUE analysis -- cgit v1.1 From 0330ce99c2992a26ed55a867b825763966034634 Mon Sep 17 00:00:00 2001 From: Dmitriy Chestnykh Date: Tue, 2 Jul 2024 04:59:24 +0300 Subject: [compiler-rt] Remove redundant checks. (#95753) Since `__sancov_default_options` and `__asan_default_suppressions` are weak definitions, not weak references (declarations) the checks of equality of addresses of these symbols to zero is not needed. So we can completely remove `MaybeCallSancovDefaultOptions` and use `__sancov_default_options` instead directly. gcc-14 emits `-Waddress` warning to such checks. --- compiler-rt/lib/asan/asan_suppressions.cpp | 3 +-- compiler-rt/lib/sanitizer_common/sancov_flags.cpp | 6 +----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/asan/asan_suppressions.cpp b/compiler-rt/lib/asan/asan_suppressions.cpp index e71d231..6cee674 100644 --- a/compiler-rt/lib/asan/asan_suppressions.cpp +++ b/compiler-rt/lib/asan/asan_suppressions.cpp @@ -39,8 +39,7 @@ void InitializeSuppressions() { suppression_ctx = new (suppression_placeholder) SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes)); suppression_ctx->ParseFromFile(flags()->suppressions); - if (&__asan_default_suppressions) - suppression_ctx->Parse(__asan_default_suppressions()); + suppression_ctx->Parse(__asan_default_suppressions()); } bool IsInterceptorSuppressed(const char *interceptor_name) { diff --git a/compiler-rt/lib/sanitizer_common/sancov_flags.cpp b/compiler-rt/lib/sanitizer_common/sancov_flags.cpp index ed46e88..43b4bcc 100644 --- a/compiler-rt/lib/sanitizer_common/sancov_flags.cpp +++ b/compiler-rt/lib/sanitizer_common/sancov_flags.cpp @@ -37,10 +37,6 @@ static void RegisterSancovFlags(FlagParser *parser, SancovFlags *f) { #undef SANCOV_FLAG } -static const char *MaybeCallSancovDefaultOptions() { - return (&__sancov_default_options) ? __sancov_default_options() : ""; -} - void InitializeSancovFlags() { SancovFlags *f = sancov_flags(); f->SetDefaults(); @@ -48,7 +44,7 @@ void InitializeSancovFlags() { FlagParser parser; RegisterSancovFlags(&parser, f); - parser.ParseString(MaybeCallSancovDefaultOptions()); + parser.ParseString(__sancov_default_options()); parser.ParseStringFromEnv("SANCOV_OPTIONS"); ReportUnrecognizedFlags(); -- cgit v1.1 From a07909ff11327baa72a4644dca7c6951ac6be902 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 1 Jul 2024 19:01:10 -0700 Subject: [IndirectCallPromotion] Migrate to a new version of getValueProfDataFromInst (#97357) --- .../Instrumentation/IndirectCallPromotion.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp index 6a5aeeb..0d1f506 100644 --- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp +++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp @@ -547,18 +547,17 @@ Instruction *IndirectCallPromoter::computeVTableInfos( for (size_t I = 0; I < Candidates.size(); I++) CalleeIndexMap[Candidates[I].TargetFunction] = I; - uint32_t ActualNumValueData = 0; uint64_t TotalVTableCount = 0; - auto VTableValueDataArray = getValueProfDataFromInst( - *VirtualCallInfo.VPtr, IPVK_VTableTarget, MaxNumVTableAnnotations, - ActualNumValueData, TotalVTableCount); - if (VTableValueDataArray.get() == nullptr) + auto VTableValueDataArray = + getValueProfDataFromInst(*VirtualCallInfo.VPtr, IPVK_VTableTarget, + MaxNumVTableAnnotations, TotalVTableCount); + if (VTableValueDataArray.empty()) return VPtr; // Compute the functions and counts from by each vtable. - for (size_t j = 0; j < ActualNumValueData; j++) { - uint64_t VTableVal = VTableValueDataArray[j].Value; - GUIDCountsMap[VTableVal] = VTableValueDataArray[j].Count; + for (const auto &V : VTableValueDataArray) { + uint64_t VTableVal = V.Value; + GUIDCountsMap[VTableVal] = V.Count; GlobalVariable *VTableVar = Symtab->getGlobalVariable(VTableVal); if (!VTableVar) { LLVM_DEBUG(dbgs() << " Cannot find vtable definition for " << VTableVal @@ -586,7 +585,7 @@ Instruction *IndirectCallPromoter::computeVTableInfos( // There shouldn't be duplicate GUIDs in one !prof metadata (except // duplicated zeros), so assign counters directly won't cause overwrite or // counter loss. - Candidate.VTableGUIDAndCounts[VTableVal] = VTableValueDataArray[j].Count; + Candidate.VTableGUIDAndCounts[VTableVal] = V.Count; Candidate.AddressPoints.push_back( getOrCreateVTableAddressPointVar(VTableVar, AddressPointOffset)); } -- cgit v1.1 From 122db8b2cb7fa43ce1d6dc17148080579fcfb55a Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 19:07:59 -0700 Subject: Remove llvm/MC/MCAsmLayout.h This complete the MCAsmLayout removal work started by 67957a45ee1ec42ae1671cdbfa0d73127346cc95. --- clang/docs/tools/clang-formatted-files.txt | 1 - llvm/include/llvm/MC/MCAsmLayout.h | 22 ---------------------- 2 files changed, 23 deletions(-) delete mode 100644 llvm/include/llvm/MC/MCAsmLayout.h diff --git a/clang/docs/tools/clang-formatted-files.txt b/clang/docs/tools/clang-formatted-files.txt index 4866bd4..a8ee8f1 100644 --- a/clang/docs/tools/clang-formatted-files.txt +++ b/clang/docs/tools/clang-formatted-files.txt @@ -5357,7 +5357,6 @@ llvm/include/llvm/MC/MCAsmInfoELF.h llvm/include/llvm/MC/MCAsmInfoGOFF.h llvm/include/llvm/MC/MCAsmInfoWasm.h llvm/include/llvm/MC/MCAsmInfoXCOFF.h -llvm/include/llvm/MC/MCAsmLayout.h llvm/include/llvm/MC/MCCodeView.h llvm/include/llvm/MC/MCContext.h llvm/include/llvm/MC/MCFixedLenDisassembler.h diff --git a/llvm/include/llvm/MC/MCAsmLayout.h b/llvm/include/llvm/MC/MCAsmLayout.h deleted file mode 100644 index 33fae0a..0000000 --- a/llvm/include/llvm/MC/MCAsmLayout.h +++ /dev/null @@ -1,22 +0,0 @@ -//===- MCAsmLayout.h - Assembly Layout Object -------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_MC_MCASMLAYOUT_H -#define LLVM_MC_MCASMLAYOUT_H - -namespace llvm { -class MCAssembler; - -class MCAsmLayout { -public: - MCAsmLayout(MCAssembler &) {} -}; - -} // end namespace llvm - -#endif -- cgit v1.1 From fb6e024f49ddbf1a018eccab7ccfa7c1f41964d0 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 1 Jul 2024 19:12:01 -0700 Subject: [WebAssembly] Update generic and bleeding-edge CPUs (#96584) This updates the list of features in 'generic' and 'bleeding-edge' CPUs in the backend to match https://github.com/llvm/llvm-project/blob/4e0a0eae58f7a6998866719f7eb970096a2a52e9/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L178 This updates existing CodeGen tests in a way that, if a test has separate RUN lines for a reference-types test and a non-reference-types test, I added -mattr=-reference-types to the no-reftype test's RUN command line. I didn't delete existing -mattr=+reference-types lines in reftype tests because having it helps readability. Also, when tests is not really about reference-types but they have to updated because they happen to contain call_indirect lines because now call_indirect will take __indirect_function_table as an argument, I just added the table argument to the expected output. `target-features-cpus.ll` has been updated reflecting the newly added features. --- llvm/lib/Target/WebAssembly/WebAssembly.td | 12 ++++--- llvm/test/CodeGen/WebAssembly/call-indirect.ll | 2 +- .../test/CodeGen/WebAssembly/function-pointer64.ll | 4 +-- llvm/test/CodeGen/WebAssembly/reg-stackify.ll | 2 +- llvm/test/CodeGen/WebAssembly/swiftcc.ll | 8 ++--- .../CodeGen/WebAssembly/target-features-cpus.ll | 39 +++++++++++++++++++--- llvm/test/MC/WebAssembly/function-alias.ll | 2 +- llvm/test/MC/WebAssembly/no-dead-strip.ll | 5 +++ 8 files changed, 56 insertions(+), 18 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td b/llvm/lib/Target/WebAssembly/WebAssembly.td index 0dd6744..9761861 100644 --- a/llvm/lib/Target/WebAssembly/WebAssembly.td +++ b/llvm/lib/Target/WebAssembly/WebAssembly.td @@ -110,13 +110,17 @@ def : ProcessorModel<"mvp", NoSchedModel, []>; // consideration given to available support in relevant engines and tools, and // the importance of the features. def : ProcessorModel<"generic", NoSchedModel, - [FeatureSignExt, FeatureMutableGlobals]>; + [FeatureMultivalue, FeatureMutableGlobals, + FeatureReferenceTypes, FeatureSignExt]>; // Latest and greatest experimental version of WebAssembly. Bugs included! def : ProcessorModel<"bleeding-edge", NoSchedModel, - [FeatureSIMD128, FeatureAtomics, - FeatureNontrappingFPToInt, FeatureSignExt, - FeatureMutableGlobals, FeatureBulkMemory, + [FeatureAtomics, FeatureBulkMemory, + FeatureExceptionHandling, FeatureExtendedConst, + FeatureHalfPrecision, FeatureMultiMemory, + FeatureMultivalue, FeatureMutableGlobals, + FeatureNontrappingFPToInt, FeatureRelaxedSIMD, + FeatureReferenceTypes, FeatureSIMD128, FeatureSignExt, FeatureTailCall]>; //===----------------------------------------------------------------------===// diff --git a/llvm/test/CodeGen/WebAssembly/call-indirect.ll b/llvm/test/CodeGen/WebAssembly/call-indirect.ll index b88d096..55a654f 100644 --- a/llvm/test/CodeGen/WebAssembly/call-indirect.ll +++ b/llvm/test/CodeGen/WebAssembly/call-indirect.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -asm-verbose=false -O2 | FileCheck --check-prefixes=CHECK,NOREF %s +; RUN: llc < %s -asm-verbose=false -mattr=-reference-types -O2 | FileCheck --check-prefixes=CHECK,NOREF %s ; RUN: llc < %s -asm-verbose=false -mattr=+reference-types -O2 | FileCheck --check-prefixes=CHECK,REF %s ; RUN: llc < %s -asm-verbose=false -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=OBJ %s diff --git a/llvm/test/CodeGen/WebAssembly/function-pointer64.ll b/llvm/test/CodeGen/WebAssembly/function-pointer64.ll index 7f98d3e..d5d10b0 100644 --- a/llvm/test/CodeGen/WebAssembly/function-pointer64.ll +++ b/llvm/test/CodeGen/WebAssembly/function-pointer64.ll @@ -1,6 +1,6 @@ -; RUN: llc < %s -asm-verbose=false -O2 | FileCheck %s +; RUN: llc < %s -asm-verbose=false -mattr=-reference-types -O2 | FileCheck %s ; RUN: llc < %s -asm-verbose=false -mattr=+reference-types -O2 | FileCheck --check-prefix=REF %s -; RUN: llc < %s -asm-verbose=false -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=YAML %s +; RUN: llc < %s -asm-verbose=false -mattr=-reference-types -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=YAML %s ; This tests pointer features that may codegen differently in wasm64. diff --git a/llvm/test/CodeGen/WebAssembly/reg-stackify.ll b/llvm/test/CodeGen/WebAssembly/reg-stackify.ll index f9845d4..f1466a4 100644 --- a/llvm/test/CodeGen/WebAssembly/reg-stackify.ll +++ b/llvm/test/CodeGen/WebAssembly/reg-stackify.ll @@ -649,7 +649,7 @@ define i32 @stackpointer_dependency(ptr readnone) { ; NOREGS-NEXT: local.tee 0 ; NOREGS: i32.load 0 ; NOREGS-NEXT: i32.load 0 -; NOREGS-NEXT: call_indirect (i32, i32) -> (i32) +; NOREGS-NEXT: call_indirect __indirect_function_table, (i32, i32) -> (i32) %class.call_indirect = type { ptr } define i32 @call_indirect_stackify(ptr %objptr, i32 %arg) { %obj = load ptr, ptr %objptr diff --git a/llvm/test/CodeGen/WebAssembly/swiftcc.ll b/llvm/test/CodeGen/WebAssembly/swiftcc.ll index e0f67b0..0c5c3d8 100644 --- a/llvm/test/CodeGen/WebAssembly/swiftcc.ll +++ b/llvm/test/CodeGen/WebAssembly/swiftcc.ll @@ -19,21 +19,21 @@ define swiftcc void @bar() { call swiftcc void @foo(i32 1, i32 2) ; REG: call_indirect $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}} -; CHECK: call_indirect (i32, i32, i32, i32) -> () +; CHECK: call_indirect __indirect_function_table, (i32, i32, i32, i32) -> () call swiftcc void %1(i32 1, i32 2) ; REG: call_indirect $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}} -; CHECK: call_indirect (i32, i32, i32, i32) -> () +; CHECK: call_indirect __indirect_function_table, (i32, i32, i32, i32) -> () call swiftcc void %1(i32 1, i32 2, i32 swiftself 3) %err = alloca swifterror ptr, align 4 ; REG: call_indirect $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}} -; CHECK: call_indirect (i32, i32, i32, i32) -> () +; CHECK: call_indirect __indirect_function_table, (i32, i32, i32, i32) -> () call swiftcc void %1(i32 1, i32 2, ptr swifterror %err) ; REG: call_indirect $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}}, $pop{{[0-9]+}} -; CHECK: call_indirect (i32, i32, i32, i32) -> () +; CHECK: call_indirect __indirect_function_table, (i32, i32, i32, i32) -> () call swiftcc void %1(i32 1, i32 2, i32 swiftself 3, ptr swifterror %err) ret void diff --git a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll index d368271..d931475 100644 --- a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll +++ b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll @@ -11,20 +11,28 @@ target triple = "wasm32-unknown-unknown" ; mvp: should not contain the target features section ; MVP-NOT: .custom_section.target_features,"",@ -; generic: +mutable-globals, +sign-ext +; generic: +multivalue, +mutable-globals, +reference-types, +sign-ext ; GENERIC-LABEL: .custom_section.target_features,"",@ -; GENERIC-NEXT: .int8 2 +; GENERIC-NEXT: .int8 4 +; GENERIC-NEXT: .int8 43 +; GENERIC-NEXT: .int8 10 +; GENERIC-NEXT: .ascii "multivalue" ; GENERIC-NEXT: .int8 43 ; GENERIC-NEXT: .int8 15 ; GENERIC-NEXT: .ascii "mutable-globals" ; GENERIC-NEXT: .int8 43 +; GENERIC-NEXT: .int8 15 +; GENERIC-NEXT: .ascii "reference-types" +; GENERIC-NEXT: .int8 43 ; GENERIC-NEXT: .int8 8 ; GENERIC-NEXT: .ascii "sign-ext" -; bleeding-edge: +atomics, +bulk-memory, +mutable-globals, +nontrapping-fptoint, -; +sign-ext, +simd128, +tail-call +; bleeding-edge: +atomics, +bulk-memory, +exception-handling, +extended-const, +; +half-precision, +multimemory, +multivalue, +mutable-globals, +; +nontrapping-fptoint, +relaxed-simd, +reference-types, +; +simd128, +sign-ext, +tail-call ; BLEEDING-EDGE-LABEL: .section .custom_section.target_features,"",@ -; BLEEDING-EDGE-NEXT: .int8 7 +; BLEEDING-EDGE-NEXT: .int8 14 ; BLEEDING-EDGE-NEXT: .int8 43 ; BLEEDING-EDGE-NEXT: .int8 7 ; BLEEDING-EDGE-NEXT: .ascii "atomics" @@ -32,12 +40,33 @@ target triple = "wasm32-unknown-unknown" ; BLEEDING-EDGE-NEXT: .int8 11 ; BLEEDING-EDGE-NEXT: .ascii "bulk-memory" ; BLEEDING-EDGE-NEXT: .int8 43 +; BLEEDING-EDGE-NEXT: .int8 18 +; BLEEDING-EDGE-NEXT: .ascii "exception-handling" +; BLEEDING-EDGE-NEXT: .int8 43 +; BLEEDING-EDGE-NEXT: .int8 14 +; BLEEDING-EDGE-NEXT: .ascii "extended-const" +; BLEEDING-EDGE-NEXT: .int8 43 +; BLEEDING-EDGE-NEXT: .int8 14 +; BLEEDING-EDGE-NEXT: .ascii "half-precision" +; BLEEDING-EDGE-NEXT: .int8 43 +; BLEEDING-EDGE-NEXT: .int8 11 +; BLEEDING-EDGE-NEXT: .ascii "multimemory" +; BLEEDING-EDGE-NEXT: .int8 43 +; BLEEDING-EDGE-NEXT: .int8 10 +; BLEEDING-EDGE-NEXT: .ascii "multivalue" +; BLEEDING-EDGE-NEXT: .int8 43 ; BLEEDING-EDGE-NEXT: .int8 15 ; BLEEDING-EDGE-NEXT: .ascii "mutable-globals" ; BLEEDING-EDGE-NEXT: .int8 43 ; BLEEDING-EDGE-NEXT: .int8 19 ; BLEEDING-EDGE-NEXT: .ascii "nontrapping-fptoint" ; BLEEDING-EDGE-NEXT: .int8 43 +; BLEEDING-EDGE-NEXT: .int8 15 +; BLEEDING-EDGE-NEXT: .ascii "reference-types" +; BLEEDING-EDGE-NEXT: .int8 43 +; BLEEDING-EDGE-NEXT: .int8 12 +; BLEEDING-EDGE-NEXT: .ascii "relaxed-simd" +; BLEEDING-EDGE-NEXT: .int8 43 ; BLEEDING-EDGE-NEXT: .int8 8 ; BLEEDING-EDGE-NEXT: .ascii "sign-ext" ; BLEEDING-EDGE-NEXT: .int8 43 diff --git a/llvm/test/MC/WebAssembly/function-alias.ll b/llvm/test/MC/WebAssembly/function-alias.ll index 6722d18..036cd7d 100644 --- a/llvm/test/MC/WebAssembly/function-alias.ll +++ b/llvm/test/MC/WebAssembly/function-alias.ll @@ -1,4 +1,4 @@ -; RUN: llc -filetype=obj %s -o - | llvm-readobj --symbols - | FileCheck %s +; RUN: llc -filetype=obj %s -mattr=-reference-types -o - | llvm-readobj --symbols - | FileCheck %s ; RUN: llc -filetype=obj %s -mattr=+reference-types -o - | llvm-readobj --symbols - | FileCheck --check-prefix=REF %s target triple = "wasm32-unknown-unknown-wasm" diff --git a/llvm/test/MC/WebAssembly/no-dead-strip.ll b/llvm/test/MC/WebAssembly/no-dead-strip.ll index 6b3f090..3125dcf 100644 --- a/llvm/test/MC/WebAssembly/no-dead-strip.ll +++ b/llvm/test/MC/WebAssembly/no-dead-strip.ll @@ -50,6 +50,11 @@ entry: ; CHECK-NEXT: Segment: 3 ; CHECK-NEXT: Offset: 8 ; CHECK-NEXT: Size: 8 +; CHECK-NEXT: - Index: 5 +; CHECK-NEXT: Kind: TABLE +; CHECK-NEXT: Name: __indirect_function_table +; CHECK-NEXT: Flags: [ UNDEFINED, NO_STRIP ] +; CHECK-NEXT: Table: 0 ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.gv0 -- cgit v1.1 From c72cb2766cec0ac519a051780ae5aed42485e012 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Jul 2024 20:41:15 -0700 Subject: [MC] Remove assert to work around BOLT BOLT used a dummy `MCAsmLayout` to call `getSymbolOffset`, which is technically not supported. There is some discussion in https://reviews.llvm.org/D154604 that this is not ideal. For now, remove the assert. The assert was added by bbb50369a149d9a7d1f91efaaabf75c260a220c7. --- llvm/lib/MC/MCAssembler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 4cafec6..14790f5 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -538,7 +538,6 @@ bool MCAssembler::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const { } uint64_t MCAssembler::getSymbolOffset(const MCSymbol &S) const { - assert(HasLayout); uint64_t Val; getSymbolOffsetImpl(*this, S, true, Val); return Val; -- cgit v1.1 From 18f3bcbb13ca83d33223b00761d8cddf463e9ffb Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Tue, 2 Jul 2024 11:29:17 +0800 Subject: [C++20] [Modules] Correct the linkage for template instantiations in named modules Close https://github.com/llvm/llvm-project/issues/97313 In the previous patch (https://github.com/llvm/llvm-project/pull/75912), I made an oversight that I ignored the templates in named module when calculating the linkage for the vtables. In this patch, I tried to correct the behavior by merging the logics to calculate the linkage with key functions with named modules. --- clang/lib/CodeGen/CGVTables.cpp | 43 ++++++++------- clang/test/Modules/pr97313.cppm | 118 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 clang/test/Modules/pr97313.cppm diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 3e88cd7..10d972e 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -1079,33 +1079,38 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { if (!RD->isExternallyVisible()) return llvm::GlobalVariable::InternalLinkage; - // V-tables for non-template classes with an owning module are always - // uniquely emitted in that module. - if (RD->isInNamedModule()) - return llvm::GlobalVariable::ExternalLinkage; - - // We're at the end of the translation unit, so the current key - // function is fully correct. - const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD); - if (keyFunction && !RD->hasAttr()) { + bool IsInNamedModule = RD->isInNamedModule(); + // If the CXXRecordDecl are not in a module unit, we need to get + // its key function. We're at the end of the translation unit, so the current + // key function is fully correct. + const CXXMethodDecl *keyFunction = + IsInNamedModule ? nullptr : Context.getCurrentKeyFunction(RD); + if (IsInNamedModule || (keyFunction && !RD->hasAttr())) { // If this class has a key function, use that to determine the // linkage of the vtable. const FunctionDecl *def = nullptr; - if (keyFunction->hasBody(def)) + if (keyFunction && keyFunction->hasBody(def)) keyFunction = cast(def); - switch (keyFunction->getTemplateSpecializationKind()) { - case TSK_Undeclared: - case TSK_ExplicitSpecialization: + bool IsExternalDefinition = + IsInNamedModule ? RD->shouldEmitInExternalSource() : !def; + + TemplateSpecializationKind Kind = + IsInNamedModule ? RD->getTemplateSpecializationKind() + : keyFunction->getTemplateSpecializationKind(); + + switch (Kind) { + case TSK_Undeclared: + case TSK_ExplicitSpecialization: assert( - (def || CodeGenOpts.OptimizationLevel > 0 || + (IsInNamedModule || def || CodeGenOpts.OptimizationLevel > 0 || CodeGenOpts.getDebugInfo() != llvm::codegenoptions::NoDebugInfo) && - "Shouldn't query vtable linkage without key function, " - "optimizations, or debug info"); - if (!def && CodeGenOpts.OptimizationLevel > 0) + "Shouldn't query vtable linkage without the class in module units, " + "key function, optimizations, or debug info"); + if (IsExternalDefinition && CodeGenOpts.OptimizationLevel > 0) return llvm::GlobalVariable::AvailableExternallyLinkage; - if (keyFunction->isInlined()) + if (keyFunction && keyFunction->isInlined()) return !Context.getLangOpts().AppleKext ? llvm::GlobalVariable::LinkOnceODRLinkage : llvm::Function::InternalLinkage; @@ -1124,7 +1129,7 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) { case TSK_ExplicitInstantiationDeclaration: llvm_unreachable("Should not have been asked to emit this"); - } + } } // -fapple-kext mode does not support weak linkage, so we must use diff --git a/clang/test/Modules/pr97313.cppm b/clang/test/Modules/pr97313.cppm new file mode 100644 index 0000000..ebbd0ee --- /dev/null +++ b/clang/test/Modules/pr97313.cppm @@ -0,0 +1,118 @@ +// REQUIRES: !system-windows +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Base.cppm \ +// RUN: -emit-module-interface -o %t/Base.pcm +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Sub.cppm \ +// RUN: -emit-module-interface -o %t/Sub.pcm -fprebuilt-module-path=%t +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Sub.pcm \ +// RUN: -emit-llvm -o %t/Sub.pcm -o - -fprebuilt-module-path=%t | \ +// RUN: FileCheck %t/Sub.cppm +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/main.cpp \ +// RUN: -emit-llvm -fprebuilt-module-path=%t -o - | FileCheck %t/main.cpp +// +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Mod.cppm \ +// RUN: -emit-module-interface -o %t/Mod.pcm +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Mod.pcm \ +// RUN: -emit-llvm -o - | FileCheck %t/Mod.cppm +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Use.cpp \ +// RUN: -emit-llvm -fprebuilt-module-path=%t -o - | \ +// RUN: FileCheck %t/Use.cpp + +//--- Base.cppm +export module Base; + +export template +class Base +{ +public: + constexpr Base(); + constexpr virtual ~Base(); +}; + +template +constexpr Base::Base() = default; + +template +constexpr Base::~Base() = default; + +//--- Sub.cppm +export module Sub; +export import Base; + +export class Sub : public Base +{ +}; + +// CHECK: @_ZTIW4Base4BaseIiE = {{.*}}linkonce_odr + +//--- main.cpp +import Sub; + +int main() +{ + Base *b = new Sub(); + delete b; +} + +// CHECK: @_ZTIW4Base4BaseIiE = {{.*}}linkonce_odr + +//--- Mod.cppm +export module Mod; + +export class NonTemplate { +public: + virtual ~NonTemplate(); +}; + +// CHECK: @_ZTIW3Mod11NonTemplate = {{.*}}constant + +export template +class Template { +public: + virtual ~Template(); +}; + +export template<> +class Template { +public: + virtual ~Template(); +}; + +// CHECK: @_ZTIW3Mod8TemplateIcE = {{.*}}constant + +export template class Template; + +// CHECK: @_ZTIW3Mod8TemplateIjE = {{.*}}weak_odr + +export extern template class Template; + +auto v = new Template(); + +// CHECK: @_ZTIW3Mod8TemplateIiE = {{.*}}linkonce_odr + +//--- Use.cpp +import Mod; + +auto v1 = new NonTemplate(); +auto v2 = new Template(); +auto v3 = new Template(); +auto v4 = new Template(); +auto v5 = new Template(); +auto v6 = new Template(); + +// CHECK: @_ZTVW3Mod11NonTemplate = {{.*}}external +// CHECK: @_ZTVW3Mod8TemplateIcE = {{.*}}external +// CHECK: @_ZTVW3Mod8TemplateIjE = {{.*}}weak_odr +// CHECK: @_ZTSW3Mod8TemplateIjE = {{.*}}weak_odr +// CHECK: @_ZTIW3Mod8TemplateIjE = {{.*}}weak_odr +// CHECK: @_ZTVW3Mod8TemplateIdE = {{.*}}external +// CHECK: @_ZTVW3Mod8TemplateIiE = {{.*}}linkonce_odr +// CHECK: @_ZTSW3Mod8TemplateIiE = {{.*}}linkonce_odr +// CHECK: @_ZTIW3Mod8TemplateIiE = {{.*}}linkonce_odr +// CHECK: @_ZTVW3Mod8TemplateIS_11NonTemplateE = {{.*}}linkonce_odr +// CHECK: @_ZTSW3Mod8TemplateIS_11NonTemplateE = {{.*}}linkonce_odr +// CHECK: @_ZTIW3Mod8TemplateIS_11NonTemplateE = {{.*}}linkonce_odr -- cgit v1.1 From 471ca9496f8a6c8253cc9db1a0aa72b6826d7f33 Mon Sep 17 00:00:00 2001 From: harishch4 Date: Tue, 2 Jul 2024 09:21:24 +0530 Subject: [Flang][OpenMP]Make Do concurrent indices private (#93785) Fixes: #85538 --- flang/lib/Semantics/resolve-directives.cpp | 56 +++++++++++++++++--------- flang/test/Semantics/OpenMP/doconcurrent01.f90 | 17 ++++++++ 2 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 flang/test/Semantics/OpenMP/doconcurrent01.f90 diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index 0bf63a0..16658d5 100644 --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -1708,26 +1708,46 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct( // Use of DO CONCURRENT inside OpenMP construct is unspecified behavior // till OpenMP-5.0 standard. // In above both cases we skip the privatization of iteration variables. +// [OpenMP 5.1] DO CONCURRENT indices are private bool OmpAttributeVisitor::Pre(const parser::DoConstruct &x) { - // TODO:[OpenMP 5.1] DO CONCURRENT indices are private - if (x.IsDoNormal()) { - if (!dirContext_.empty() && GetContext().withinConstruct) { + if (!dirContext_.empty() && GetContext().withinConstruct) { + llvm::SmallVector ivs; + if (x.IsDoNormal()) { const parser::Name *iv{GetLoopIndex(x)}; - if (iv && iv->symbol) { - if (!iv->symbol->test(Symbol::Flag::OmpPreDetermined)) { - ResolveSeqLoopIndexInParallelOrTaskConstruct(*iv); - } else { - // TODO: conflict checks with explicitly determined DSA - } - ordCollapseLevel--; - if (ordCollapseLevel) { - if (const auto *details{iv->symbol->detailsIf()}) { - const Symbol *tpSymbol = &details->symbol(); - if (tpSymbol->test(Symbol::Flag::OmpThreadprivate)) { - context_.Say(iv->source, - "Loop iteration variable %s is not allowed in THREADPRIVATE."_err_en_US, - iv->ToString()); - } + if (iv && iv->symbol) + ivs.push_back(iv); + } else if (x.IsDoConcurrent()) { + const Fortran::parser::LoopControl *loopControl = &*x.GetLoopControl(); + const Fortran::parser::LoopControl::Concurrent &concurrent = + std::get(loopControl->u); + const Fortran::parser::ConcurrentHeader &concurrentHeader = + std::get(concurrent.t); + const std::list &controls = + std::get>( + concurrentHeader.t); + for (const auto &control : controls) { + const parser::Name *iv{&std::get<0>(control.t)}; + if (iv && iv->symbol) + ivs.push_back(iv); + } + } + ordCollapseLevel--; + for (auto iv : ivs) { + if (!iv->symbol->test(Symbol::Flag::OmpPreDetermined)) { + ResolveSeqLoopIndexInParallelOrTaskConstruct(*iv); + } else { + // TODO: conflict checks with explicitly determined DSA + } + if (ordCollapseLevel) { + if (const auto *details{iv->symbol->detailsIf()}) { + const Symbol *tpSymbol = &details->symbol(); + // TODO: DoConcurrent won't capture the following check because a new + // symbol is declared in ResolveIndexName(), which will not have the + // OmpThreadprivate flag. + if (tpSymbol->test(Symbol::Flag::OmpThreadprivate)) { + context_.Say(iv->source, + "Loop iteration variable %s is not allowed in THREADPRIVATE."_err_en_US, + iv->ToString()); } } } diff --git a/flang/test/Semantics/OpenMP/doconcurrent01.f90 b/flang/test/Semantics/OpenMP/doconcurrent01.f90 new file mode 100644 index 0000000..7e3bdce8 --- /dev/null +++ b/flang/test/Semantics/OpenMP/doconcurrent01.f90 @@ -0,0 +1,17 @@ +! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp + +! OpenMP 5.1.1 +! DO Concurrent indices are private + +!DEF: /private_iv (Subroutine)Subprogram +subroutine private_iv + !DEF: /private_iv/i ObjectEntity INTEGER(4) + integer i + !$omp parallel default(private) + !$omp single + !DEF: /private_iv/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4) + do concurrent(i=1:2) + end do + !$omp end single + !$omp end parallel +end subroutine -- cgit v1.1 From 410de0c8c831a4a63075dd03f80ca83205860746 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 1 Jul 2024 21:35:21 -0700 Subject: [lldb/Commands] Alias `script` command to `scripting run` (#97263) This patch introduces a new top-level `scripting` command with an `run` sub-command, that basically replaces the `script` raw command. To avoid breaking the `script` command usages, this patch also adds an `script` alias to the `scripting run` sub-command. The reason behind this change is to have a top-level command that will cover scripting related subcommands. Signed-off-by: Med Ismail Bennani --- lldb/source/Commands/CMakeLists.txt | 2 +- lldb/source/Commands/CommandObjectScript.cpp | 113 ---------------- lldb/source/Commands/CommandObjectScript.h | 42 ------ lldb/source/Commands/CommandObjectScripting.cpp | 144 +++++++++++++++++++++ lldb/source/Commands/CommandObjectScripting.h | 25 ++++ lldb/source/Commands/Options.td | 2 +- lldb/source/Interpreter/CommandInterpreter.cpp | 13 +- .../abbreviation/TestAbbreviations.py | 8 +- 8 files changed, 189 insertions(+), 160 deletions(-) delete mode 100644 lldb/source/Commands/CommandObjectScript.cpp delete mode 100644 lldb/source/Commands/CommandObjectScript.h create mode 100644 lldb/source/Commands/CommandObjectScripting.cpp create mode 100644 lldb/source/Commands/CommandObjectScripting.h diff --git a/lldb/source/Commands/CMakeLists.txt b/lldb/source/Commands/CMakeLists.txt index 6a36c53..7639722 100644 --- a/lldb/source/Commands/CMakeLists.txt +++ b/lldb/source/Commands/CMakeLists.txt @@ -26,7 +26,7 @@ add_lldb_library(lldbCommands NO_PLUGIN_DEPENDENCIES CommandObjectQuit.cpp CommandObjectRegexCommand.cpp CommandObjectRegister.cpp - CommandObjectScript.cpp + CommandObjectScripting.cpp CommandObjectSession.cpp CommandObjectSettings.cpp CommandObjectSource.cpp diff --git a/lldb/source/Commands/CommandObjectScript.cpp b/lldb/source/Commands/CommandObjectScript.cpp deleted file mode 100644 index 25f25b8..0000000 --- a/lldb/source/Commands/CommandObjectScript.cpp +++ /dev/null @@ -1,113 +0,0 @@ -//===-- CommandObjectScript.cpp -------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "CommandObjectScript.h" -#include "lldb/Core/Debugger.h" -#include "lldb/DataFormatters/DataVisualization.h" -#include "lldb/Host/Config.h" -#include "lldb/Host/OptionParser.h" -#include "lldb/Interpreter/CommandInterpreter.h" -#include "lldb/Interpreter/CommandOptionArgumentTable.h" -#include "lldb/Interpreter/CommandReturnObject.h" -#include "lldb/Interpreter/OptionArgParser.h" -#include "lldb/Interpreter/ScriptInterpreter.h" -#include "lldb/Utility/Args.h" - -using namespace lldb; -using namespace lldb_private; - -#define LLDB_OPTIONS_script -#include "CommandOptions.inc" - -Status CommandObjectScript::CommandOptions::SetOptionValue( - uint32_t option_idx, llvm::StringRef option_arg, - ExecutionContext *execution_context) { - Status error; - const int short_option = m_getopt_table[option_idx].val; - - switch (short_option) { - case 'l': - language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum( - option_arg, GetDefinitions()[option_idx].enum_values, - eScriptLanguageNone, error); - if (!error.Success()) - error.SetErrorStringWithFormat("unrecognized value for language '%s'", - option_arg.str().c_str()); - break; - default: - llvm_unreachable("Unimplemented option"); - } - - return error; -} - -void CommandObjectScript::CommandOptions::OptionParsingStarting( - ExecutionContext *execution_context) { - language = lldb::eScriptLanguageNone; -} - -llvm::ArrayRef -CommandObjectScript::CommandOptions::GetDefinitions() { - return llvm::ArrayRef(g_script_options); -} - -CommandObjectScript::CommandObjectScript(CommandInterpreter &interpreter) - : CommandObjectRaw( - interpreter, "script", - "Invoke the script interpreter with provided code and display any " - "results. Start the interactive interpreter if no code is supplied.", - "script [--language --] []") {} - -CommandObjectScript::~CommandObjectScript() = default; - -void CommandObjectScript::DoExecute(llvm::StringRef command, - CommandReturnObject &result) { - // Try parsing the language option but when the command contains a raw part - // separated by the -- delimiter. - OptionsWithRaw raw_args(command); - if (raw_args.HasArgs()) { - if (!ParseOptions(raw_args.GetArgs(), result)) - return; - command = raw_args.GetRawPart(); - } - - lldb::ScriptLanguage language = - (m_options.language == lldb::eScriptLanguageNone) - ? m_interpreter.GetDebugger().GetScriptLanguage() - : m_options.language; - - if (language == lldb::eScriptLanguageNone) { - result.AppendError( - "the script-lang setting is set to none - scripting not available"); - return; - } - - ScriptInterpreter *script_interpreter = - GetDebugger().GetScriptInterpreter(true, language); - - if (script_interpreter == nullptr) { - result.AppendError("no script interpreter"); - return; - } - - // Script might change Python code we use for formatting. Make sure we keep - // up to date with it. - DataVisualization::ForceUpdate(); - - if (command.empty()) { - script_interpreter->ExecuteInterpreterLoop(); - result.SetStatus(eReturnStatusSuccessFinishNoResult); - return; - } - - // We can do better when reporting the status of one-liner script execution. - if (script_interpreter->ExecuteOneLine(command, &result)) - result.SetStatus(eReturnStatusSuccessFinishNoResult); - else - result.SetStatus(eReturnStatusFailed); -} diff --git a/lldb/source/Commands/CommandObjectScript.h b/lldb/source/Commands/CommandObjectScript.h deleted file mode 100644 index 3a8c4a8..0000000 --- a/lldb/source/Commands/CommandObjectScript.h +++ /dev/null @@ -1,42 +0,0 @@ -//===-- CommandObjectScript.h -----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H -#define LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H - -#include "lldb/Interpreter/CommandObject.h" - -namespace lldb_private { - -class CommandObjectScript : public CommandObjectRaw { -public: - CommandObjectScript(CommandInterpreter &interpreter); - ~CommandObjectScript() override; - Options *GetOptions() override { return &m_options; } - - class CommandOptions : public Options { - public: - CommandOptions() = default; - ~CommandOptions() override = default; - Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, - ExecutionContext *execution_context) override; - void OptionParsingStarting(ExecutionContext *execution_context) override; - llvm::ArrayRef GetDefinitions() override; - lldb::ScriptLanguage language = lldb::eScriptLanguageNone; - }; - -protected: - void DoExecute(llvm::StringRef command, CommandReturnObject &result) override; - -private: - CommandOptions m_options; -}; - -} // namespace lldb_private - -#endif // LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPT_H diff --git a/lldb/source/Commands/CommandObjectScripting.cpp b/lldb/source/Commands/CommandObjectScripting.cpp new file mode 100644 index 0000000..fee0565 --- /dev/null +++ b/lldb/source/Commands/CommandObjectScripting.cpp @@ -0,0 +1,144 @@ +//===-- CommandObjectScripting.cpp ----------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CommandObjectScripting.h" +#include "lldb/Core/Debugger.h" +#include "lldb/DataFormatters/DataVisualization.h" +#include "lldb/Host/Config.h" +#include "lldb/Host/OptionParser.h" +#include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Interpreter/CommandOptionArgumentTable.h" +#include "lldb/Interpreter/CommandReturnObject.h" +#include "lldb/Interpreter/OptionArgParser.h" +#include "lldb/Interpreter/ScriptInterpreter.h" +#include "lldb/Utility/Args.h" + +using namespace lldb; +using namespace lldb_private; + +#define LLDB_OPTIONS_scripting_run +#include "CommandOptions.inc" + +class CommandObjectScriptingRun : public CommandObjectRaw { +public: + CommandObjectScriptingRun(CommandInterpreter &interpreter) + : CommandObjectRaw( + interpreter, "scripting run", + "Invoke the script interpreter with provided code and display any " + "results. Start the interactive interpreter if no code is " + "supplied.", + "scripting run [--language --] " + "[]") {} + + ~CommandObjectScriptingRun() override = default; + + Options *GetOptions() override { return &m_options; } + + class CommandOptions : public Options { + public: + CommandOptions() = default; + ~CommandOptions() override = default; + Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, + ExecutionContext *execution_context) override { + Status error; + const int short_option = m_getopt_table[option_idx].val; + + switch (short_option) { + case 'l': + language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum( + option_arg, GetDefinitions()[option_idx].enum_values, + eScriptLanguageNone, error); + if (!error.Success()) + error.SetErrorStringWithFormat("unrecognized value for language '%s'", + option_arg.str().c_str()); + break; + default: + llvm_unreachable("Unimplemented option"); + } + + return error; + } + + void OptionParsingStarting(ExecutionContext *execution_context) override { + language = lldb::eScriptLanguageNone; + } + + llvm::ArrayRef GetDefinitions() override { + return llvm::ArrayRef(g_scripting_run_options); + } + + lldb::ScriptLanguage language = lldb::eScriptLanguageNone; + }; + +protected: + void DoExecute(llvm::StringRef command, + CommandReturnObject &result) override { + // Try parsing the language option but when the command contains a raw part + // separated by the -- delimiter. + OptionsWithRaw raw_args(command); + if (raw_args.HasArgs()) { + if (!ParseOptions(raw_args.GetArgs(), result)) + return; + command = raw_args.GetRawPart(); + } + + lldb::ScriptLanguage language = + (m_options.language == lldb::eScriptLanguageNone) + ? m_interpreter.GetDebugger().GetScriptLanguage() + : m_options.language; + + if (language == lldb::eScriptLanguageNone) { + result.AppendError( + "the script-lang setting is set to none - scripting not available"); + return; + } + + ScriptInterpreter *script_interpreter = + GetDebugger().GetScriptInterpreter(true, language); + + if (script_interpreter == nullptr) { + result.AppendError("no script interpreter"); + return; + } + + // Script might change Python code we use for formatting. Make sure we keep + // up to date with it. + DataVisualization::ForceUpdate(); + + if (command.empty()) { + script_interpreter->ExecuteInterpreterLoop(); + result.SetStatus(eReturnStatusSuccessFinishNoResult); + return; + } + + // We can do better when reporting the status of one-liner script execution. + if (script_interpreter->ExecuteOneLine(command, &result)) + result.SetStatus(eReturnStatusSuccessFinishNoResult); + else + result.SetStatus(eReturnStatusFailed); + } + +private: + CommandOptions m_options; +}; + +#pragma mark CommandObjectMultiwordScripting + +// CommandObjectMultiwordScripting + +CommandObjectMultiwordScripting::CommandObjectMultiwordScripting( + CommandInterpreter &interpreter) + : CommandObjectMultiword( + interpreter, "scripting", + "Commands for operating on the scripting functionnalities.", + "scripting []") { + LoadSubCommand("run", + CommandObjectSP(new CommandObjectScriptingRun(interpreter))); +} + +CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting() = default; diff --git a/lldb/source/Commands/CommandObjectScripting.h b/lldb/source/Commands/CommandObjectScripting.h new file mode 100644 index 0000000..0ccd579 --- /dev/null +++ b/lldb/source/Commands/CommandObjectScripting.h @@ -0,0 +1,25 @@ +//===-- CommandObjectScripting.h --------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPTING_H +#define LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPTING_H + +#include "lldb/Interpreter/CommandObjectMultiword.h" + +namespace lldb_private { + +class CommandObjectMultiwordScripting : public CommandObjectMultiword { +public: + CommandObjectMultiwordScripting(CommandInterpreter &interpreter); + + ~CommandObjectMultiwordScripting() override; +}; + +} // namespace lldb_private + +#endif // LLDB_SOURCE_INTERPRETER_COMMANDOBJECTSCRIPTING_H diff --git a/lldb/source/Commands/Options.td b/lldb/source/Commands/Options.td index fa8af7c..24e97f3 100644 --- a/lldb/source/Commands/Options.td +++ b/lldb/source/Commands/Options.td @@ -835,7 +835,7 @@ let Command = "container add" in { Desc<"Overwrite an existing command at this node.">; } -let Command = "script" in { +let Command = "scripting run" in { def script_language : Option<"language", "l">, EnumArg<"ScriptLang">, Desc<"Specify the scripting " " language. If none is specific the default scripting language is used.">; diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 40c915b..fc07168 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -33,7 +33,7 @@ #include "Commands/CommandObjectQuit.h" #include "Commands/CommandObjectRegexCommand.h" #include "Commands/CommandObjectRegister.h" -#include "Commands/CommandObjectScript.h" +#include "Commands/CommandObjectScripting.h" #include "Commands/CommandObjectSession.h" #include "Commands/CommandObjectSettings.h" #include "Commands/CommandObjectSource.h" @@ -518,6 +518,15 @@ void CommandInterpreter::Initialize() { AddAlias("re", cmd_obj_sp); } + cmd_obj_sp = GetCommandSPExact("scripting run"); + if (cmd_obj_sp) { + AddAlias("sc", cmd_obj_sp); + AddAlias("scr", cmd_obj_sp); + AddAlias("scri", cmd_obj_sp); + AddAlias("scrip", cmd_obj_sp); + AddAlias("script", cmd_obj_sp); + } + cmd_obj_sp = GetCommandSPExact("session history"); if (cmd_obj_sp) { AddAlias("history", cmd_obj_sp); @@ -569,7 +578,7 @@ void CommandInterpreter::LoadCommandDictionary() { REGISTER_COMMAND_OBJECT("process", CommandObjectMultiwordProcess); REGISTER_COMMAND_OBJECT("quit", CommandObjectQuit); REGISTER_COMMAND_OBJECT("register", CommandObjectRegister); - REGISTER_COMMAND_OBJECT("script", CommandObjectScript); + REGISTER_COMMAND_OBJECT("scripting", CommandObjectMultiwordScripting); REGISTER_COMMAND_OBJECT("settings", CommandObjectMultiwordSettings); REGISTER_COMMAND_OBJECT("session", CommandObjectSession); REGISTER_COMMAND_OBJECT("source", CommandObjectMultiwordSource); diff --git a/lldb/test/API/functionalities/abbreviation/TestAbbreviations.py b/lldb/test/API/functionalities/abbreviation/TestAbbreviations.py index 10431e4..02ee581 100644 --- a/lldb/test/API/functionalities/abbreviation/TestAbbreviations.py +++ b/lldb/test/API/functionalities/abbreviation/TestAbbreviations.py @@ -80,7 +80,13 @@ class AbbreviationsTestCase(TestBase): # Check a command that wants the raw input. command_interpreter.ResolveCommand(r"""sc print("\n\n\tHello!\n")""", result) self.assertTrue(result.Succeeded()) - self.assertEqual(r"""script print("\n\n\tHello!\n")""", result.GetOutput()) + self.assertEqual( + r"""scripting run print("\n\n\tHello!\n")""", result.GetOutput() + ) + + command_interpreter.ResolveCommand("script 1+1", result) + self.assertTrue(result.Succeeded()) + self.assertEqual("scripting run 1+1", result.GetOutput()) # Prompt changing stuff should be tested, but this doesn't seem like the # right test to do it in. It has nothing to do with aliases or abbreviations. -- cgit v1.1 From 6f60d2b807a4a719ac98288aec961dbb8433bb4b Mon Sep 17 00:00:00 2001 From: Job Henandez Lara Date: Mon, 1 Jul 2024 21:38:15 -0700 Subject: [libc] Add mpfr tests for fmul. (#97376) Fixes https://github.com/llvm/llvm-project/issues/94834 --- libc/test/src/math/CMakeLists.txt | 12 ++++ libc/test/src/math/FMulTest.h | 121 +++++++++++++++++++++++++++++++++++ libc/test/src/math/fmul_test.cpp | 13 ++++ libc/utils/MPFRWrapper/MPFRUtils.cpp | 15 +++++ libc/utils/MPFRWrapper/MPFRUtils.h | 18 ++++-- 5 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 libc/test/src/math/FMulTest.h create mode 100644 libc/test/src/math/fmul_test.cpp diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index c07c6d7..9eda5db 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1824,6 +1824,18 @@ add_fp_unittest( ) add_fp_unittest( + fmul_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + fmul_test.cpp + HDRS + FMulTest.h + DEPENDS + libc.src.math.fmul +) +add_fp_unittest( asinhf_test NEED_MPFR SUITE diff --git a/libc/test/src/math/FMulTest.h b/libc/test/src/math/FMulTest.h new file mode 100644 index 0000000..8ca33ea --- /dev/null +++ b/libc/test/src/math/FMulTest.h @@ -0,0 +1,121 @@ +//===-- Utility class to test fmul[f|l] -------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_MATH_FMULTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_FMULTEST_H + +#include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/FEnvSafeTest.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; + +template +class FmulMPFRTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { + + DECLARE_SPECIAL_CONSTANTS(InType) + +public: + typedef OutType (*FMulFunc)(InType, InType); + + void testFMulMPFR(FMulFunc func) { + constexpr int N = 10; + mpfr::BinaryInput INPUTS[N] = { + {3.0, 5.0}, + {0x1.0p1, 0x1.0p-131}, + {0x1.0p2, 0x1.0p-129}, + {1.0, 1.0}, + {-0.0, -0.0}, + {-0.0, 0.0}, + {0.0, -0.0}, + {0x1.0p100, 0x1.0p100}, + {1.0, 1.0 + 0x1.0p-128 + 0x1.0p-149 + 0x1.0p-150}, + {1.0, 0x1.0p-128 + 0x1.0p-149 + 0x1.0p-150}}; + + for (int i = 0; i < N; ++i) { + InType x = INPUTS[i].x; + InType y = INPUTS[i].y; + ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Fmul, INPUTS[i], + func(x, y), 0.5); + } + } + + void testSpecialInputsMPFR(FMulFunc func) { + constexpr int N = 27; + mpfr::BinaryInput INPUTS[N] = {{inf, 0x1.0p-129}, + {0x1.0p-129, inf}, + {inf, 2.0}, + {3.0, inf}, + {0.0, 0.0}, + {neg_inf, aNaN}, + {aNaN, neg_inf}, + {neg_inf, neg_inf}, + {0.0, neg_inf}, + {neg_inf, 0.0}, + {neg_inf, 1.0}, + {1.0, neg_inf}, + {neg_inf, 0x1.0p-129}, + {0x1.0p-129, neg_inf}, + {0.0, 0x1.0p-129}, + {inf, 0.0}, + {0.0, inf}, + {0.0, aNaN}, + {2.0, aNaN}, + {0x1.0p-129, aNaN}, + {inf, aNaN}, + {aNaN, aNaN}, + {0.0, sNaN}, + {2.0, sNaN}, + {0x1.0p-129, sNaN}, + {inf, sNaN}, + {sNaN, sNaN}}; + + for (int i = 0; i < N; ++i) { + InType x = INPUTS[i].x; + InType y = INPUTS[i].y; + ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Fmul, INPUTS[i], + func(x, y), 0.5); + } + } + + void testNormalRange(FMulFunc func) { + using FPBits = LIBC_NAMESPACE::fputil::FPBits; + using StorageType = typename FPBits::StorageType; + static constexpr StorageType MAX_NORMAL = FPBits::max_normal().uintval(); + static constexpr StorageType MIN_NORMAL = FPBits::min_normal().uintval(); + + constexpr StorageType COUNT = 10'001; + constexpr StorageType STEP = (MAX_NORMAL - MIN_NORMAL) / COUNT; + for (int signs = 0; signs < 4; ++signs) { + for (StorageType v = MIN_NORMAL, w = MAX_NORMAL; + v <= MAX_NORMAL && w >= MIN_NORMAL; v += STEP, w -= STEP) { + InType x = FPBits(v).get_val(), y = FPBits(w).get_val(); + if (signs % 2 == 1) { + x = -x; + } + if (signs >= 2) { + y = -y; + } + + mpfr::BinaryInput input{x, y}; + ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Fmul, input, func(x, y), + 0.5); + } + } + } +}; + +#define LIST_FMUL_MPFR_TESTS(OutType, InType, func) \ + using LlvmLibcFmulTest = FmulMPFRTest; \ + TEST_F(LlvmLibcFmulTest, MulMpfr) { testFMulMPFR(&func); } \ + TEST_F(LlvmLibcFmulTest, NanInfMpfr) { testSpecialInputsMPFR(&func); } \ + TEST_F(LlvmLibcFmulTest, NormalRange) { testNormalRange(&func); } + +#endif // LLVM_LIBC_TEST_SRC_MATH_FMULTEST_H diff --git a/libc/test/src/math/fmul_test.cpp b/libc/test/src/math/fmul_test.cpp new file mode 100644 index 0000000..16eaa1a --- /dev/null +++ b/libc/test/src/math/fmul_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for fmul-------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#include "FMulTest.h" + +#include "src/math/fmul.h" + +LIST_FMUL_MPFR_TESTS(float, double, LIBC_NAMESPACE::fmul) diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp index 379a631..c57cbe4 100644 --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -487,6 +487,12 @@ public: return result; } + MPFRNumber fmul(const MPFRNumber &b) { + MPFRNumber result(*this); + mpfr_mul(result.value, value, b.value, mpfr_rounding); + return result; + } + cpp::string str() const { // 200 bytes should be more than sufficient to hold a 100-digit number // plus additional bytes for the decimal point, '-' sign etc. @@ -738,6 +744,8 @@ binary_operation_one_output(Operation op, InputType x, InputType y, return inputX.hypot(inputY); case Operation::Pow: return inputX.pow(inputY); + case Operation::Fmul: + return inputX.fmul(inputY); default: __builtin_unreachable(); } @@ -951,6 +959,9 @@ template void explain_binary_operation_one_output_error(Operation, const BinaryInput &, long double, double, RoundingMode); + +template void explain_binary_operation_one_output_error( + Operation, const BinaryInput &, float, double, RoundingMode); #ifdef LIBC_TYPES_HAS_FLOAT16 template void explain_binary_operation_one_output_error( Operation, const BinaryInput &, float16, double, RoundingMode); @@ -1126,6 +1137,10 @@ template bool compare_binary_operation_one_output(Operation, template bool compare_binary_operation_one_output(Operation, const BinaryInput &, long double, double, RoundingMode); + +template bool compare_binary_operation_one_output(Operation, + const BinaryInput &, + float, double, RoundingMode); #ifdef LIBC_TYPES_HAS_FLOAT16 template bool compare_binary_operation_one_output(Operation, const BinaryInput &, diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h index 11e323b..743c06a 100644 --- a/libc/utils/MPFRWrapper/MPFRUtils.h +++ b/libc/utils/MPFRWrapper/MPFRUtils.h @@ -76,6 +76,7 @@ enum class Operation : int { Fmod, Hypot, Pow, + Fmul, EndBinaryOperationsSingleOutput, // Operations which take two floating point numbers of the same type as @@ -237,7 +238,8 @@ public: bool is_silent() const override { return silent; } private: - template bool match(T in, U out) { + template + bool match(InType in, OutType out) { return compare_unary_operation_single_output(op, in, out, ulp_tolerance, rounding); } @@ -259,13 +261,14 @@ private: rounding); } - template - bool match(const TernaryInput &in, U out) { + template + bool match(const TernaryInput &in, OutType out) { return compare_ternary_operation_one_output(op, in, out, ulp_tolerance, rounding); } - template void explain_error(T in, U out) { + template + void explain_error(InType in, OutType out) { explain_unary_operation_single_output_error(op, in, out, ulp_tolerance, rounding); } @@ -287,8 +290,8 @@ private: rounding); } - template - void explain_error(const TernaryInput &in, U out) { + template + void explain_error(const TernaryInput &in, OutType out) { explain_ternary_operation_one_output_error(op, in, out, ulp_tolerance, rounding); } @@ -304,7 +307,8 @@ constexpr bool is_valid_operation() { (op == Operation::Sqrt && cpp::is_floating_point_v && cpp::is_floating_point_v && sizeof(OutputType) <= sizeof(InputType)) || - (op == Operation::Div && internal::IsBinaryInput::VALUE && + ((op == Operation::Div || op == Operation::Fmul) && + internal::IsBinaryInput::VALUE && cpp::is_floating_point_v< typename internal::MakeScalarInput::type> && cpp::is_floating_point_v) || -- cgit v1.1 From 91c0ef6f67821eb7298cb05988045e92354ac77b Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Mon, 1 Jul 2024 21:56:33 -0700 Subject: [lldb] [ObjectFileMachO] BSS segments are loadable segments (#96983) ObjectFileMachO::SetLoadAddress sets the address of each segment in a binary in a Target, but it ignores segments that are not loaded in the virtual address space. It was marking segments that were purely BSS -- having no content in the file, but in zero-initialized memory when running in the virtual address space -- as not-loadable, unless they were named "DATA". This works pretty well for typical userland binaries, but in less Darwin environments, there may be BSS segments with other names, that ARE loadable. I looked at the origin of SectionIsLoadable's check for this, and it was a cleanup by Greg in 2018 where we had three different implementations of the idea in ObjectFileMachO and one of them skipped zero-file-size segments (BSS), which made it into the centralized SectionIsLoadable method. Also add some logging to the DynamicLoader log channel when loading a binary - it's the first place I look when debugging segment address setting bugs, and it wasn't emitting anything. rdar://129870649 --- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 2979bf69..0dcb1be 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -6159,10 +6159,6 @@ Section *ObjectFileMachO::GetMachHeaderSection() { bool ObjectFileMachO::SectionIsLoadable(const Section *section) { if (!section) return false; - const bool is_dsym = (m_header.filetype == MH_DSYM); - if (section->GetFileSize() == 0 && !is_dsym && - section->GetName() != GetSegmentNameDATA()) - return false; if (section->IsThreadSpecific()) return false; if (GetModule().get() != section->GetModule().get()) @@ -6202,6 +6198,7 @@ lldb::addr_t ObjectFileMachO::CalculateSectionLoadAddressForMemoryImage( bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value, bool value_is_offset) { + Log *log(GetLog(LLDBLog::DynamicLoader)); ModuleSP module_sp = GetModule(); if (!module_sp) return false; @@ -6217,17 +6214,33 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value, // malformed. const bool warn_multiple = true; + if (log) { + StreamString logmsg; + logmsg << "ObjectFileMachO::SetLoadAddress "; + if (GetFileSpec()) + logmsg << "path='" << GetFileSpec().GetPath() << "' "; + if (GetUUID()) { + logmsg << "uuid=" << GetUUID().GetAsString(); + } + LLDB_LOGF(log, "%s", logmsg.GetData()); + } if (value_is_offset) { // "value" is an offset to apply to each top level segment for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) { // Iterate through the object file sections to find all of the // sections that size on disk (to avoid __PAGEZERO) and load them SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx)); - if (SectionIsLoadable(section_sp.get())) + if (SectionIsLoadable(section_sp.get())) { + LLDB_LOGF(log, + "ObjectFileMachO::SetLoadAddress segment '%s' load addr is " + "0x%" PRIx64, + section_sp->GetName().AsCString(), + section_sp->GetFileAddress() + value); if (target.GetSectionLoadList().SetSectionLoadAddress( section_sp, section_sp->GetFileAddress() + value, warn_multiple)) ++num_loaded_sections; + } } } else { // "value" is the new base address of the mach_header, adjust each @@ -6242,6 +6255,10 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value, CalculateSectionLoadAddressForMemoryImage( value, mach_header_section, section_sp.get()); if (section_load_addr != LLDB_INVALID_ADDRESS) { + LLDB_LOGF(log, + "ObjectFileMachO::SetLoadAddress segment '%s' load addr is " + "0x%" PRIx64, + section_sp->GetName().AsCString(), section_load_addr); if (target.GetSectionLoadList().SetSectionLoadAddress( section_sp, section_load_addr, warn_multiple)) ++num_loaded_sections; -- cgit v1.1 From 7ee421d29612ae919edfe7250b87e3c738d66a26 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Tue, 2 Jul 2024 13:55:26 +0800 Subject: [C++20] [Modules] Skip calls to module initializer to modules if we know the module doesn't init anything Close https://github.com/llvm/llvm-project/issues/97244 This is an optimization allowed by the modules's ABI to skip calls to imported modules for which we know nothing will be initialized. --- clang/lib/CodeGen/CGDeclCXX.cpp | 4 ++++ clang/test/Modules/pr97244.cppm | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 clang/test/Modules/pr97244.cppm diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp index e18b339..05dd7dd 100644 --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -840,6 +840,10 @@ CodeGenModule::EmitCXXGlobalInitFunc() { // No Itanium initializer in header like modules. if (M->isHeaderLikeModule()) continue; + // We're allowed to skip the initialization if we are sure it doesn't + // do any thing. + if (!M->isNamedModuleInterfaceHasInit()) + continue; llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false); SmallString<256> FnName; { diff --git a/clang/test/Modules/pr97244.cppm b/clang/test/Modules/pr97244.cppm new file mode 100644 index 0000000..ad8b466 --- /dev/null +++ b/clang/test/Modules/pr97244.cppm @@ -0,0 +1,30 @@ +// REQUIRES: !system-windows +// +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Empty.cppm \ +// RUN: -emit-module-interface -o %t/Empty.pcm +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Empty2.cppm \ +// RUN: -fprebuilt-module-path=%t -emit-module-interface -o %t/Empty2.pcm +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/main.cpp \ +// RUN: -fprebuilt-module-path=%t -emit-llvm -o - | FileCheck %t/main.cpp +// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Empty2.pcm \ +// RUN: -fprebuilt-module-path=%t -emit-llvm -o - | FileCheck %t/Empty2.cppm + +//--- Empty.cppm +export module Empty; + +//--- Empty2.cppm +export module Empty2; +import Empty; + +// CHECK-NOT: _ZGIW5Empty + +//--- main.cpp +import Empty; +import Empty2; + +// CHECK-NOT: _ZGIW5Empty +// CHECK-NOT: _ZGIW6Empty2 -- cgit v1.1 From cd1e6a587be6352f63f180b1ff5e0a348a8da444 Mon Sep 17 00:00:00 2001 From: Yashwant Singh Date: Tue, 2 Jul 2024 11:59:39 +0530 Subject: [SROA] Propagate no-signed-zeros(nsz) fast-math flag on the phi node using function attribute (#83381) Its expected that the sequence `return X > 0.0 ? X : -X`, compiled with -Ofast, produces fabs intrinsic. However, at this point, LLVM is unable to do so. The above sequence goes through the following transformation during the pass pipeline: 1) SROA pass generates the phi node. Here, it does not infer the fast-math flags on the phi node unlike clang frontend typically does. 2) Phi node eventually gets translated into select instruction. Because of missing no-signed-zeros(nsz) fast-math flag on the select instruction, InstCombine pass fails to fold the sequence into fabs intrinsic. This patch, as a part of SROA, tries to propagate nsz fast-math flag on the phi node using function attribute enabling this folding. Closes #51601 Co-authored-by: Sushant Gokhale --- .../Transforms/Utils/PromoteMemoryToRegister.cpp | 12 ++++ .../test/Transforms/PhaseOrdering/generate-fabs.ll | 29 ++++++++ .../SROA/propagate-fast-math-flags-on-phi.ll | 79 ++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 llvm/test/Transforms/PhaseOrdering/generate-fabs.ll create mode 100644 llvm/test/Transforms/SROA/propagate-fast-math-flags-on-phi.ll diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index 6f62545..d2d50e5 100644 --- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -41,6 +41,7 @@ #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Operator.h" #include "llvm/IR/Type.h" #include "llvm/IR/User.h" #include "llvm/Support/Casting.h" @@ -1122,6 +1123,17 @@ NextIteration: for (unsigned i = 0; i != NumEdges; ++i) APN->addIncoming(IncomingVals[AllocaNo], Pred); + // For the sequence `return X > 0.0 ? X : -X`, it is expected that this + // results in fabs intrinsic. However, without no-signed-zeros(nsz) flag + // on the phi node generated at this stage, fabs folding does not + // happen. So, we try to infer nsz flag from the function attributes to + // enable this fabs folding. + if (APN->isComplete() && isa(APN) && + BB->getParent() + ->getFnAttribute("no-signed-zeros-fp-math") + .getValueAsBool()) + APN->setHasNoSignedZeros(true); + // The currently active variable for this block is now the PHI. IncomingVals[AllocaNo] = APN; AllocaATInfo[AllocaNo].updateForNewPhi(APN, DIB); diff --git a/llvm/test/Transforms/PhaseOrdering/generate-fabs.ll b/llvm/test/Transforms/PhaseOrdering/generate-fabs.ll new file mode 100644 index 0000000..25ac510 --- /dev/null +++ b/llvm/test/Transforms/PhaseOrdering/generate-fabs.ll @@ -0,0 +1,29 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt -passes='default' -S < %s | FileCheck %s + +; Following test must generate fabs intrinsic. It goes through following stages +; 1. SROA propagates the nsz function attribute on the phi node. +; 2. SimplifyCFG pass converts phi node to select. +; 3. InstCombine converts select with nsz flag into fabs intrinsic. + +define double @fabs_fcmp_olt_nsz_func_attr(double %0, double %1) "no-signed-zeros-fp-math"="true" { +; CHECK-LABEL: define double @fabs_fcmp_olt_nsz_func_attr( +; CHECK-SAME: double [[TMP0:%.*]], double [[TMP1:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: [[X_0:%.*]] = tail call nnan nsz double @llvm.fabs.f64(double [[TMP0]]) +; CHECK-NEXT: ret double [[X_0]] +entry: + %x = alloca double + store double %0, ptr %x + %cmp = fcmp nnan nsz olt double %0, 0.000000e+00 + br i1 %cmp, label %if.then, label %return + +if.then: ; preds = %entry + %fneg = fneg nnan nsz double %0 + store double %fneg, ptr %x + br label %return + +return: ; preds = %entry, %if.then + %ret = load double, ptr %x + ret double %ret +} diff --git a/llvm/test/Transforms/SROA/propagate-fast-math-flags-on-phi.ll b/llvm/test/Transforms/SROA/propagate-fast-math-flags-on-phi.ll new file mode 100644 index 0000000..2cc2636 --- /dev/null +++ b/llvm/test/Transforms/SROA/propagate-fast-math-flags-on-phi.ll @@ -0,0 +1,79 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 +; RUN: opt < %s -passes='sroa' -S | FileCheck %s +define double @phi_with_nsz(double %x) "no-signed-zeros-fp-math"="true" { +; CHECK-LABEL: define double @phi_with_nsz( +; CHECK-SAME: double [[X:%.*]]) #[[ATTR0:[0-9]+]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = fcmp olt double [[X]], 0.000000e+00 +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[RETURN:%.*]] +; CHECK: if.then: +; CHECK-NEXT: [[FNEG:%.*]] = fneg double [[X]] +; CHECK-NEXT: br label [[RETURN]] +; CHECK: return: +; CHECK-NEXT: [[X_ADDR_0:%.*]] = phi nsz double [ [[FNEG]], [[IF_THEN]] ], [ undef, [[ENTRY:%.*]] ] +; CHECK-NEXT: ret double [[X_ADDR_0]] +entry: + %x.addr = alloca double + %cmp = fcmp olt double %x, 0.0 + br i1 %cmp, label %if.then, label %return + +if.then: ; preds = %entry + %fneg = fneg double %x + store double %fneg, ptr %x.addr + br label %return + +return: ; preds = %entry,%if.then + %retval = load double, ptr %x.addr + ret double %retval +} + +define <2 x double> @vector_phi_with_nsz(<2 x double> %x, i1 %cmp, <2 x double> %a, <2 x double> %b) "no-signed-zeros-fp-math"="true" { +; CHECK-LABEL: define <2 x double> @vector_phi_with_nsz( +; CHECK-SAME: <2 x double> [[X:%.*]], i1 [[CMP:%.*]], <2 x double> [[A:%.*]], <2 x double> [[B:%.*]]) #[[ATTR0]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[RETURN:%.*]] +; CHECK: if.then: +; CHECK-NEXT: br label [[RETURN]] +; CHECK: return: +; CHECK-NEXT: [[X_ADDR_0:%.*]] = phi nsz <2 x double> [ [[B]], [[IF_THEN]] ], [ [[A]], [[ENTRY:%.*]] ] +; CHECK-NEXT: ret <2 x double> [[X_ADDR_0]] +entry: + %x.addr = alloca <2 x double> + store <2 x double> %a, ptr %x.addr + br i1 %cmp, label %if.then, label %return + +if.then: ; preds = %entry + store <2 x double> %b, ptr %x.addr + br label %return + +return: ; preds = %entry,%if.then + %retval = load <2 x double>, ptr %x.addr + ret <2 x double> %retval +} + +define double @phi_without_nsz(double %x) "no-signed-zeros-fp-math"="false" { +; CHECK-LABEL: define double @phi_without_nsz( +; CHECK-SAME: double [[X:%.*]]) #[[ATTR1:[0-9]+]] { +; CHECK-NEXT: entry: +; CHECK-NEXT: [[CMP:%.*]] = fcmp olt double [[X]], 0.000000e+00 +; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[RETURN:%.*]] +; CHECK: if.then: +; CHECK-NEXT: [[FNEG:%.*]] = fneg double [[X]] +; CHECK-NEXT: br label [[RETURN]] +; CHECK: return: +; CHECK-NEXT: [[X_ADDR_0:%.*]] = phi double [ [[FNEG]], [[IF_THEN]] ], [ undef, [[ENTRY:%.*]] ] +; CHECK-NEXT: ret double [[X_ADDR_0]] +entry: + %x.addr = alloca double + %cmp = fcmp olt double %x, 0.0 + br i1 %cmp, label %if.then, label %return + +if.then: ; preds = %entry + %fneg = fneg double %x + store double %fneg, ptr %x.addr + br label %return + +return: ; preds = %entry,%if.then + %retval = load double, ptr %x.addr + ret double %retval +} -- cgit v1.1 From 4468c3dd538b3ec6e4c32d0269d8e7ebbeb0bdc5 Mon Sep 17 00:00:00 2001 From: Pengcheng Wang Date: Tue, 2 Jul 2024 14:41:17 +0800 Subject: [NFC][RISCV] Simplify the dynamic linker construction logic The format of dynamic linker is `ld-linux-{arch}-{abi}.so.1`, so we can just get the arch name from arch type. Reviewers: asb, kito-cheng, MaskRay Reviewed By: MaskRay Pull Request: https://github.com/llvm/llvm-project/pull/97383 --- clang/lib/Driver/ToolChains/Linux.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 49e029e..98a878e 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -568,16 +568,12 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { Loader = (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2"; break; - case llvm::Triple::riscv32: { - StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple); - LibDir = "lib"; - Loader = ("ld-linux-riscv32-" + ABIName + ".so.1").str(); - break; - } + case llvm::Triple::riscv32: case llvm::Triple::riscv64: { + StringRef ArchName = llvm::Triple::getArchTypeName(Arch); StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple); LibDir = "lib"; - Loader = ("ld-linux-riscv64-" + ABIName + ".so.1").str(); + Loader = ("ld-linux-" + ArchName + "-" + ABIName + ".so.1").str(); break; } case llvm::Triple::sparc: -- cgit v1.1 From 135483bf968bc72a9544a9f2640f73f196ca8cbc Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 1 Jul 2024 23:47:24 -0700 Subject: [Driver] Support using toolchain libc and libc++ for baremetal (#96736) We want to support using a complete Clang/LLVM toolchain that includes LLVM libc and libc++ for baremetal targets. To do so, we need the driver to add the necessary include paths. --- clang/include/clang/Driver/ToolChain.h | 3 ++ clang/lib/Driver/ToolChain.cpp | 6 +++ clang/lib/Driver/ToolChains/BareMetal.cpp | 56 ++++++++++++++++++---- .../Driver/Inputs/basic_baremetal_tree/bin/.keep | 0 .../include/armv6m-unknown-none-eabi/.keep | 0 .../include/armv6m-unknown-none-eabi/c++/v1/.keep | 0 .../basic_baremetal_tree/include/c++/v1/.keep | 0 .../lib/armv6m-unknown-none-eabi/.keep | 0 clang/test/Driver/baremetal.cpp | 16 ++++++- 9 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 clang/test/Driver/Inputs/basic_baremetal_tree/bin/.keep create mode 100644 clang/test/Driver/Inputs/basic_baremetal_tree/include/armv6m-unknown-none-eabi/.keep create mode 100644 clang/test/Driver/Inputs/basic_baremetal_tree/include/armv6m-unknown-none-eabi/c++/v1/.keep create mode 100644 clang/test/Driver/Inputs/basic_baremetal_tree/include/c++/v1/.keep create mode 100644 clang/test/Driver/Inputs/basic_baremetal_tree/lib/armv6m-unknown-none-eabi/.keep diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 1f93bd6..ece1384 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -526,6 +526,9 @@ public: // Returns target specific standard library path if it exists. std::optional getStdlibPath() const; + // Returns target specific standard library include path if it exists. + std::optional getStdlibIncludePath() const; + // Returns /lib// or /lib/. // This is used by runtimes (such as OpenMP) to find arch-specific libraries. virtual path_list getArchSpecificLibPaths() const; diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 8f4cc47..977e083 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -811,6 +811,12 @@ std::optional ToolChain::getStdlibPath() const { return getTargetSubDirPath(P); } +std::optional ToolChain::getStdlibIncludePath() const { + SmallString<128> P(D.Dir); + llvm::sys::path::append(P, "..", "include"); + return getTargetSubDirPath(P); +} + ToolChain::path_list ToolChain::getArchSpecificLibPaths() const { path_list Paths; diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index dd365e6..11f9487 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -270,15 +270,19 @@ void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs, addSystemInclude(DriverArgs, CC1Args, Dir.str()); } - if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) { - const SmallString<128> SysRoot(computeSysRoot()); - if (!SysRoot.empty()) { - for (const Multilib &M : getOrderedMultilibs()) { - SmallString<128> Dir(SysRoot); - llvm::sys::path::append(Dir, M.includeSuffix()); - llvm::sys::path::append(Dir, "include"); - addSystemInclude(DriverArgs, CC1Args, Dir.str()); - } + if (DriverArgs.hasArg(options::OPT_nostdlibinc)) + return; + + if (std::optional Path = getStdlibIncludePath()) + addSystemInclude(DriverArgs, CC1Args, *Path); + + const SmallString<128> SysRoot(computeSysRoot()); + if (!SysRoot.empty()) { + for (const Multilib &M : getOrderedMultilibs()) { + SmallString<128> Dir(SysRoot); + llvm::sys::path::append(Dir, M.includeSuffix()); + llvm::sys::path::append(Dir, "include"); + addSystemInclude(DriverArgs, CC1Args, Dir.str()); } } } @@ -296,6 +300,40 @@ void BareMetal::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, return; const Driver &D = getDriver(); + std::string Target = getTripleString(); + + auto AddCXXIncludePath = [&](StringRef Path) { + std::string Version = detectLibcxxVersion(Path); + if (Version.empty()) + return; + + { + // First the per-target include dir: include//c++/v1. + SmallString<128> TargetDir(Path); + llvm::sys::path::append(TargetDir, Target, "c++", Version); + addSystemInclude(DriverArgs, CC1Args, TargetDir); + } + + { + // Then the generic dir: include/c++/v1. + SmallString<128> Dir(Path); + llvm::sys::path::append(Dir, "c++", Version); + addSystemInclude(DriverArgs, CC1Args, Dir); + } + }; + + switch (GetCXXStdlibType(DriverArgs)) { + case ToolChain::CST_Libcxx: { + SmallString<128> P(D.Dir); + llvm::sys::path::append(P, "..", "include"); + AddCXXIncludePath(P); + break; + } + case ToolChain::CST_Libstdcxx: + // We only support libc++ toolchain installation. + break; + } + std::string SysRoot(computeSysRoot()); if (SysRoot.empty()) return; diff --git a/clang/test/Driver/Inputs/basic_baremetal_tree/bin/.keep b/clang/test/Driver/Inputs/basic_baremetal_tree/bin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/Driver/Inputs/basic_baremetal_tree/include/armv6m-unknown-none-eabi/.keep b/clang/test/Driver/Inputs/basic_baremetal_tree/include/armv6m-unknown-none-eabi/.keep new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/Driver/Inputs/basic_baremetal_tree/include/armv6m-unknown-none-eabi/c++/v1/.keep b/clang/test/Driver/Inputs/basic_baremetal_tree/include/armv6m-unknown-none-eabi/c++/v1/.keep new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/Driver/Inputs/basic_baremetal_tree/include/c++/v1/.keep b/clang/test/Driver/Inputs/basic_baremetal_tree/include/c++/v1/.keep new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/Driver/Inputs/basic_baremetal_tree/lib/armv6m-unknown-none-eabi/.keep b/clang/test/Driver/Inputs/basic_baremetal_tree/lib/armv6m-unknown-none-eabi/.keep new file mode 100644 index 0000000..e69de29 diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp index cc14f04..de4e934 100644 --- a/clang/test/Driver/baremetal.cpp +++ b/clang/test/Driver/baremetal.cpp @@ -13,7 +13,7 @@ // CHECK-V6M-C-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK-V6M-C-SAME: "-isysroot" "[[SYSROOT:[^"]*]]" // CHECK-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1" -// CHECk-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include" +// CHECK-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include" // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp" // CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL" // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for" @@ -26,6 +26,20 @@ // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck --check-prefix=CHECK-V6M-LIBINC %s // CHECK-V6M-LIBINC-NOT: "-internal-isystem" +// RUN: %clang %s -### --target=armv6m-none-eabi -o %t.out 2>&1 \ +// RUN: -ccc-install-dir %S/Inputs/basic_baremetal_tree/bin \ +// RUN: | FileCheck --check-prefix=CHECK-V6M-TREE %s +// CHECK-V6M-TREE: InstalledDir: [[INSTALLED_DIR:.+]] +// CHECK-V6M-TREE: "-cc1" "-triple" "thumbv6m-unknown-none-eabi" +// CHECK-V6M-TREE-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" +// CHECK-V6M-TREE-SAME: "-internal-isystem" "[[INSTALLED_DIR]]{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}armv6m-unknown-none-eabi{{[/\\]+}}c++{{[/\\]+}}v1" +// CHECK-V6M-TREE-SAME: {{^}} "-internal-isystem" "[[INSTALLED_DIR]]{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1" +// CHECK-V6M-TREE-SAME: "-internal-isystem" "[[INSTALLED_DIR]]{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}armv6m-unknown-none-eabi" +// CHECK-V6M-TREE-SAME: "-x" "c++" "{{.*}}baremetal.cpp" +// CHECK-V6M-TREE-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL" +// CHECK-V6M-TREE-SAME: "-L[[INSTALLED_DIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}armv6m-unknown-none-eabi" +// CHECK-V6M-TREE-SAME: "-lc" "-lm" "{{[^"]*}}libclang_rt.builtins.a" "--target2=rel" "-o" "{{.*}}.tmp.out" + // RUN: %clang %s -### --target=armv7m-vendor-none-eabi -rtlib=compiler-rt 2>&1 \ // RUN: --sysroot=%S/Inputs/baremetal_arm \ // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \ -- cgit v1.1 From 54f040fff301a629f2ed032863408ed119789b0e Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Tue, 2 Jul 2024 01:00:14 -0600 Subject: [clang-format] Add SpacesInParensOption for filtering repeated parens (#77522) The __attribute((specifier-list)) currently is formatted based on the SpacesInParensOptions.Other (previously, SpacesInParentheses). This change allows finer control over addition of spaces between the consecutive parens, and between the inner parens and the list of attribute specifiers. Differential Revision: https://reviews.llvm.org/D155529 This is migrated from Phabricator, see more discussion there. --------- Co-authored-by: Owen Pan --- clang/docs/ClangFormatStyleOptions.rst | 23 ++++-- clang/docs/ReleaseNotes.rst | 3 + clang/include/clang/Format/Format.h | 35 ++++++--- clang/lib/Format/Format.cpp | 5 +- clang/lib/Format/TokenAnnotator.cpp | 9 +++ clang/unittests/Format/ConfigParseTest.cpp | 21 +++--- clang/unittests/Format/FormatTest.cpp | 109 +++++++++++++++++++++++++++++ 7 files changed, 182 insertions(+), 23 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index 080cba9..6c2e6da 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -6242,6 +6242,7 @@ the configuration (without a prefix: ``Auto``). # Example of usage: SpacesInParens: Custom SpacesInParensOptions: + ExceptDoubleParentheses: false InConditionalStatements: true InEmptyParentheses: true @@ -6254,9 +6255,22 @@ the configuration (without a prefix: ``Auto``). # Should be declared this way: SpacesInParens: Custom SpacesInParensOptions: + ExceptDoubleParentheses: false InConditionalStatements: true Other: true + * ``bool ExceptDoubleParentheses`` Override any of the following options to prevent addition of space + when both opening and closing parentheses use multiple parentheses. + + .. code-block:: c++ + + true: + __attribute__(( noreturn )) + __decltype__(( x )) + if (( a = b )) + false: + Uses the applicable option. + * ``bool InConditionalStatements`` Put a space in parentheses only inside conditional statements (``for/if/while/switch...``). @@ -6270,8 +6284,9 @@ the configuration (without a prefix: ``Auto``). .. code-block:: c++ - true: false: - x = ( int32 )y vs. x = (int32)y + true: false: + x = ( int32 )y vs. x = (int32)y + y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x); * ``bool InEmptyParentheses`` Insert a space in empty parentheses, i.e. ``()``. @@ -6289,8 +6304,8 @@ the configuration (without a prefix: ``Auto``). .. code-block:: c++ - true: false: - t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; + true: false: + t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; .. _SpacesInParentheses: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 90c2469..fd8d9ad 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1130,6 +1130,9 @@ clang-format - Adds ``LeftWithLastLine`` suboption to ``AlignEscapedNewlines``. - Adds ``KeepEmptyLines`` option to deprecate ``KeepEmptyLinesAtEOF`` and ``KeepEmptyLinesAtTheStartOfBlocks``. +- Add ``ExceptDoubleParentheses`` sub-option for ``SpacesInParensOptions`` + to override addition of spaces between multiple, non-redundant parentheses + similar to the rules used for ``RemoveParentheses``. libclang -------- diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index efc2e450..c454ab2 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -4679,10 +4679,22 @@ struct FormatStyle { /// # Should be declared this way: /// SpacesInParens: Custom /// SpacesInParensOptions: + /// ExceptDoubleParentheses: false /// InConditionalStatements: true /// Other: true /// \endcode struct SpacesInParensCustom { + /// Override any of the following options to prevent addition of space + /// when both opening and closing parentheses use multiple parentheses. + /// \code + /// true: + /// __attribute__(( noreturn )) + /// __decltype__(( x )) + /// if (( a = b )) + /// \endcode + /// false: + /// Uses the applicable option. + bool ExceptDoubleParentheses; /// Put a space in parentheses only inside conditional statements /// (``for/if/while/switch...``). /// \code @@ -4693,8 +4705,9 @@ struct FormatStyle { bool InConditionalStatements; /// Put a space in C style casts. /// \code - /// true: false: - /// x = ( int32 )y vs. x = (int32)y + /// true: false: + /// x = ( int32 )y vs. x = (int32)y + /// y = (( int (*)(int) )foo)(x); y = ((int (*)(int))foo)(x); /// \endcode bool InCStyleCasts; /// Insert a space in empty parentheses, i.e. ``()``. @@ -4710,23 +4723,26 @@ struct FormatStyle { bool InEmptyParentheses; /// Put a space in parentheses not covered by preceding options. /// \code - /// true: false: - /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; + /// true: false: + /// t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete; /// \endcode bool Other; SpacesInParensCustom() - : InConditionalStatements(false), InCStyleCasts(false), - InEmptyParentheses(false), Other(false) {} + : ExceptDoubleParentheses(false), InConditionalStatements(false), + InCStyleCasts(false), InEmptyParentheses(false), Other(false) {} - SpacesInParensCustom(bool InConditionalStatements, bool InCStyleCasts, + SpacesInParensCustom(bool ExceptDoubleParentheses, + bool InConditionalStatements, bool InCStyleCasts, bool InEmptyParentheses, bool Other) - : InConditionalStatements(InConditionalStatements), + : ExceptDoubleParentheses(ExceptDoubleParentheses), + InConditionalStatements(InConditionalStatements), InCStyleCasts(InCStyleCasts), InEmptyParentheses(InEmptyParentheses), Other(Other) {} bool operator==(const SpacesInParensCustom &R) const { - return InConditionalStatements == R.InConditionalStatements && + return ExceptDoubleParentheses == R.ExceptDoubleParentheses && + InConditionalStatements == R.InConditionalStatements && InCStyleCasts == R.InCStyleCasts && InEmptyParentheses == R.InEmptyParentheses && Other == R.Other; } @@ -4744,6 +4760,7 @@ struct FormatStyle { /// # Example of usage: /// SpacesInParens: Custom /// SpacesInParensOptions: + /// ExceptDoubleParentheses: false /// InConditionalStatements: true /// InEmptyParentheses: true /// \endcode diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 259ef1d..6a8883b 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -729,6 +729,7 @@ template <> struct MappingTraits { template <> struct MappingTraits { static void mapping(IO &IO, FormatStyle::SpacesInParensCustom &Spaces) { + IO.mapOptional("ExceptDoubleParentheses", Spaces.ExceptDoubleParentheses); IO.mapOptional("InCStyleCasts", Spaces.InCStyleCasts); IO.mapOptional("InConditionalStatements", Spaces.InConditionalStatements); IO.mapOptional("InEmptyParentheses", Spaces.InEmptyParentheses); @@ -1184,8 +1185,8 @@ template <> struct MappingTraits { (SpacesInParentheses || SpaceInEmptyParentheses || SpacesInConditionalStatement || SpacesInCStyleCastParentheses)) { if (SpacesInParentheses) { - // set all options except InCStyleCasts and InEmptyParentheses - // to true for backward compatibility. + // For backward compatibility. + Style.SpacesInParensOptions.ExceptDoubleParentheses = false; Style.SpacesInParensOptions.InConditionalStatements = true; Style.SpacesInParensOptions.InCStyleCasts = SpacesInCStyleCastParentheses; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 03082cd..0fd0214 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -4361,6 +4361,15 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, Right.is(tok::r_brace) && Right.isNot(BK_Block))) { return Style.SpacesInParensOptions.InEmptyParentheses; } + if (Style.SpacesInParens == FormatStyle::SIPO_Custom && + Style.SpacesInParensOptions.ExceptDoubleParentheses && + Left.is(tok::r_paren) && Right.is(tok::r_paren)) { + auto *InnerLParen = Left.MatchingParen; + if (InnerLParen && InnerLParen->Previous == Right.MatchingParen) { + InnerLParen->SpacesRequiredBefore = 0; + return false; + } + } if (Style.SpacesInParensOptions.InConditionalStatements) { const FormatToken *LeftParen = nullptr; if (Left.is(tok::l_paren)) diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index 2466677a..cc04415 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -240,6 +240,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) { CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator); CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterPlacementOperator); CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses); + CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, ExceptDoubleParentheses); CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts); CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements); CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InEmptyParentheses); @@ -626,20 +627,24 @@ TEST(ConfigParseTest, ParsesConfiguration) { FormatStyle::SIPO_Custom); Style.SpacesInParens = FormatStyle::SIPO_Never; Style.SpacesInParensOptions = {}; - CHECK_PARSE("SpacesInParentheses: true", SpacesInParensOptions, - FormatStyle::SpacesInParensCustom(true, false, false, true)); + CHECK_PARSE( + "SpacesInParentheses: true", SpacesInParensOptions, + FormatStyle::SpacesInParensCustom(false, true, false, false, true)); Style.SpacesInParens = FormatStyle::SIPO_Never; Style.SpacesInParensOptions = {}; - CHECK_PARSE("SpacesInConditionalStatement: true", SpacesInParensOptions, - FormatStyle::SpacesInParensCustom(true, false, false, false)); + CHECK_PARSE( + "SpacesInConditionalStatement: true", SpacesInParensOptions, + FormatStyle::SpacesInParensCustom(false, true, false, false, false)); Style.SpacesInParens = FormatStyle::SIPO_Never; Style.SpacesInParensOptions = {}; - CHECK_PARSE("SpacesInCStyleCastParentheses: true", SpacesInParensOptions, - FormatStyle::SpacesInParensCustom(false, true, false, false)); + CHECK_PARSE( + "SpacesInCStyleCastParentheses: true", SpacesInParensOptions, + FormatStyle::SpacesInParensCustom(false, false, true, false, false)); Style.SpacesInParens = FormatStyle::SIPO_Never; Style.SpacesInParensOptions = {}; - CHECK_PARSE("SpaceInEmptyParentheses: true", SpacesInParensOptions, - FormatStyle::SpacesInParensCustom(false, false, true, false)); + CHECK_PARSE( + "SpaceInEmptyParentheses: true", SpacesInParensOptions, + FormatStyle::SpacesInParensCustom(false, false, false, true, false)); Style.SpacesInParens = FormatStyle::SIPO_Never; Style.SpacesInParensOptions = {}; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5276e79..283843a 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -17129,6 +17129,23 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) { verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces); verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces); verifyFormat("void f() __attribute__((asdf));", Spaces); + verifyFormat("x = (int32)y;", Spaces); + verifyFormat("y = ((int (*)(int))foo)(x);", Spaces); + verifyFormat("decltype(x) y = 42;", Spaces); + verifyFormat("decltype((x)) y = z;", Spaces); + verifyFormat("decltype((foo())) a = foo();", Spaces); + verifyFormat("decltype((bar(10))) a = bar(11);", Spaces); + verifyFormat("if ((x - y) && (a ^ b))\n" + " f();", + Spaces); + verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n" + " foo(i);", + Spaces); + verifyFormat("switch (x / (y + z)) {\n" + "default:\n" + " break;\n" + "}", + Spaces); Spaces.SpacesInParens = FormatStyle::SIPO_Custom; Spaces.SpacesInParensOptions = {}; @@ -17163,6 +17180,23 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) { verifyFormat("SomeType *__attribute__( ( attr ) ) *a = NULL;", Spaces); verifyFormat("void __attribute__( ( naked ) ) foo( int bar )", Spaces); verifyFormat("void f() __attribute__( ( asdf ) );", Spaces); + verifyFormat("x = (int32)y;", Spaces); + verifyFormat("y = ( (int ( * )( int ))foo )( x );", Spaces); + verifyFormat("decltype( x ) y = 42;", Spaces); + verifyFormat("decltype( ( x ) ) y = z;", Spaces); + verifyFormat("decltype( ( foo() ) ) a = foo();", Spaces); + verifyFormat("decltype( ( bar( 10 ) ) ) a = bar( 11 );", Spaces); + verifyFormat("if ( ( x - y ) && ( a ^ b ) )\n" + " f();", + Spaces); + verifyFormat("for ( int i = 0; i < 10; i = ( i + 1 ) )\n" + " foo( i );", + Spaces); + verifyFormat("switch ( x / ( y + z ) ) {\n" + "default:\n" + " break;\n" + "}", + Spaces); Spaces.SpacesInParens = FormatStyle::SIPO_Custom; Spaces.SpacesInParensOptions = {}; @@ -17175,6 +17209,7 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) { verifyFormat("#define AA(X) sizeof((( X * )NULL)->a)", Spaces); verifyFormat("my_int a = ( my_int )sizeof(int);", Spaces); verifyFormat("#define x (( int )-1)", Spaces); + verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces); // Run the first set of tests again with: Spaces.SpacesInParens = FormatStyle::SIPO_Custom; @@ -17207,6 +17242,23 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) { verifyFormat("SomeType *__attribute__((attr)) *a = NULL;", Spaces); verifyFormat("void __attribute__((naked)) foo(int bar)", Spaces); verifyFormat("void f( ) __attribute__((asdf));", Spaces); + verifyFormat("x = ( int32 )y;", Spaces); + verifyFormat("y = (( int (*)(int) )foo)(x);", Spaces); + verifyFormat("decltype(x) y = 42;", Spaces); + verifyFormat("decltype((x)) y = z;", Spaces); + verifyFormat("decltype((foo( ))) a = foo( );", Spaces); + verifyFormat("decltype((bar(10))) a = bar(11);", Spaces); + verifyFormat("if ((x - y) && (a ^ b))\n" + " f( );", + Spaces); + verifyFormat("for (int i = 0; i < 10; i = (i + 1))\n" + " foo(i);", + Spaces); + verifyFormat("switch (x / (y + z)) {\n" + "default:\n" + " break;\n" + "}", + Spaces); // Run the first set of tests again with: Spaces.SpaceAfterCStyleCast = true; @@ -17314,6 +17366,63 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) { verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces); verifyFormat("size_t idx = (*foo)(a - 1);", Spaces); verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces); + + // Check ExceptDoubleParentheses spaces + Spaces.IndentWidth = 2; + Spaces.SpacesInParens = FormatStyle::SIPO_Custom; + Spaces.SpacesInParensOptions = {}; + Spaces.SpacesInParensOptions.Other = true; + Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true; + verifyFormat("SomeType *__attribute__(( attr )) *a = NULL;", Spaces); + verifyFormat("void __attribute__(( naked )) foo( int bar )", Spaces); + verifyFormat("void f() __attribute__(( asdf ));", Spaces); + verifyFormat("__attribute__(( __aligned__( x ) )) z;", Spaces); + verifyFormat("int x __attribute__(( aligned( 16 ) )) = 0;", Spaces); + verifyFormat("class __declspec( dllimport ) X {};", Spaces); + verifyFormat("class __declspec(( dllimport )) X {};", Spaces); + verifyFormat("int x = ( ( a - 1 ) * 3 );", Spaces); + verifyFormat("int x = ( 3 * ( a - 1 ) );", Spaces); + verifyFormat("decltype( x ) y = 42;", Spaces); + verifyFormat("decltype(( bar( 10 ) )) a = bar( 11 );", Spaces); + verifyFormat("if (( i = j ))\n" + " do_something( i );", + Spaces); + + Spaces.SpacesInParens = FormatStyle::SIPO_Custom; + Spaces.SpacesInParensOptions = {}; + Spaces.SpacesInParensOptions.InConditionalStatements = true; + Spaces.SpacesInParensOptions.ExceptDoubleParentheses = true; + verifyFormat("while ( (bool)1 )\n" + " continue;", + Spaces); + verifyFormat("while ((i = j))\n" + " continue;", + Spaces); + verifyFormat("do {\n" + " do_something((int)i);\n" + "} while ( something() );", + Spaces); + verifyFormat("do {\n" + " do_something((int)i);\n" + "} while ((i = i + 1));", + Spaces); + verifyFormat("if ( (x - y) && (a ^ b) )\n" + " f();", + Spaces); + verifyFormat("if ((i = j))\n" + " do_something(i);", + Spaces); + verifyFormat("for ( int i = 0; i < 10; i = (i + 1) )\n" + " foo(i);", + Spaces); + verifyFormat("switch ( x / (y + z) ) {\n" + "default:\n" + " break;\n" + "}", + Spaces); + verifyFormat("if constexpr ((a = b))\n" + " c;", + Spaces); } TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) { -- cgit v1.1 From 01e96c86497ac9670e1168134870beb99cbd4d8f Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 2 Jul 2024 10:08:03 +0200 Subject: [lldb] Don't unregister a listener that's being destroyed (#97300) It's not necessary because the broadcasters hold a weak_ptr (*) to it, and will delete the weak_ptr next time they try to lock it. Doing this prevents recursion in RemoveListener, where the function can end up holding the only shared_ptr to a listener, and its destruction can trigger another call to RemoveListener -- which will mess up the state of the first instance. This is the same bug that we've have fixed in https://reviews.llvm.org/D23406, but it was effectively undone in https://reviews.llvm.org/D157556. With the addition of a primary listener, a fix like D23406 becomes unwieldy (and it has already shown itself to be fragile), which is why this patch attempts a different approach. Like in 2016, I don't know a good way to unit test this bug, since it depends on precise timing, but the thing I like about this approach is that it enables us to change the broadcaster mutex into a non-recursive one. While that doesn't prevent the bug from happening again, it will make it much easier to spot in the future, as the code will hang with a smoking gun (instead of crashing a little while later). I'm going to attempt that in a separate patch to minimize disruption. (*) Technically a broadcaster holds the *primary* listener as a shared_ptr, but that's still ok as it means that listener will not get destroyed until it is explicitly removed. --- lldb/source/Utility/Listener.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/source/Utility/Listener.cpp b/lldb/source/Utility/Listener.cpp index 6a74c53..5aacb41 100644 --- a/lldb/source/Utility/Listener.cpp +++ b/lldb/source/Utility/Listener.cpp @@ -30,7 +30,7 @@ Listener::Listener(const char *name) Listener::~Listener() { Log *log = GetLog(LLDBLog::Object); - Clear(); + // Don't call Clear() from here as that can cause races. See #96750. LLDB_LOGF(log, "%p Listener::%s('%s')", static_cast(this), __FUNCTION__, m_name.c_str()); -- cgit v1.1 From 8a25bb9b391bd13d824b1df43187b4c304011cee Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 2 Jul 2024 09:37:51 +0200 Subject: [InstCombine] Add test for #97330 (NFC) --- llvm/test/Transforms/InstCombine/known-bits.ll | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/known-bits.ll b/llvm/test/Transforms/InstCombine/known-bits.ll index d7a8386..8520981 100644 --- a/llvm/test/Transforms/InstCombine/known-bits.ll +++ b/llvm/test/Transforms/InstCombine/known-bits.ll @@ -2025,6 +2025,33 @@ define i8 @simplifydemanded_context(i8 %x, i8 %y) { ret i8 %and2 } +; FIXME: This is a miscompile. +define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { +; CHECK-LABEL: @pr97330( +; CHECK-NEXT: entry: +; CHECK-NEXT: br i1 [[C:%.*]], label [[EXIT:%.*]], label [[IF:%.*]] +; CHECK: if: +; CHECK-NEXT: unreachable +; CHECK: exit: +; CHECK-NEXT: ret i16 1 +; +entry: + %v = load i64, ptr %p1, align 8 + %conv = trunc i64 %v to i16 + br i1 %c, label %exit, label %if + +if: + %cmp = icmp ne i16 %conv, 1 + %conv2 = zext i1 %cmp to i32 + store i32 %conv2, ptr %p2, align 4 + %cmp2 = icmp eq i64 %v, 1 + call void @llvm.assume(i1 %cmp2) + unreachable + +exit: + ret i16 %conv +} + declare void @dummy() declare void @use(i1) declare void @sink(i8) -- cgit v1.1 From 2dd14065571c7063d895108f3d5f57867dfe4de3 Mon Sep 17 00:00:00 2001 From: Konrad Kleine Date: Tue, 2 Jul 2024 10:19:37 +0200 Subject: [llvm] remove unusable llvm.spec.in (#96825) The `llvm.spec.in` is turned into `llvm.spec` through cmake. The spec file's `%build` section runs `./configure` which has been deprecated since 2016 (See e49730d4baa8443ad56f59bd8066bf4c1e56ea72). --- llvm/CMakeLists.txt | 19 --------------- llvm/llvm.spec.in | 68 ----------------------------------------------------- 2 files changed, 87 deletions(-) delete mode 100644 llvm/llvm.spec.in diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 91a2b61..1261896 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1135,25 +1135,6 @@ configure_file( ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/abi-breaking.h.cmake ${LLVM_INCLUDE_DIR}/llvm/Config/abi-breaking.h) -# Add target for generating source rpm package. -set(LLVM_SRPM_USER_BINARY_SPECFILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm.spec.in - CACHE FILEPATH ".spec file to use for srpm generation") -set(LLVM_SRPM_BINARY_SPECFILE ${CMAKE_CURRENT_BINARY_DIR}/llvm.spec) -set(LLVM_SRPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/srpm") - -get_source_info(${CMAKE_CURRENT_SOURCE_DIR} revision repository) -string(LENGTH "${revision}" revision_length) -set(LLVM_RPM_SPEC_REVISION "${revision}") - -configure_file( - ${LLVM_SRPM_USER_BINARY_SPECFILE} - ${LLVM_SRPM_BINARY_SPECFILE} @ONLY) - -add_custom_target(srpm - COMMAND cpack -G TGZ --config CPackSourceConfig.cmake -B ${LLVM_SRPM_DIR}/SOURCES - COMMAND rpmbuild -bs --define '_topdir ${LLVM_SRPM_DIR}' ${LLVM_SRPM_BINARY_SPECFILE}) -set_target_properties(srpm PROPERTIES FOLDER "LLVM/Misc") - if(APPLE AND DARWIN_LTO_LIBRARY) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}") diff --git a/llvm/llvm.spec.in b/llvm/llvm.spec.in deleted file mode 100644 index 8d6ae75..0000000 --- a/llvm/llvm.spec.in +++ /dev/null @@ -1,68 +0,0 @@ -Name: @PACKAGE_NAME@ -Version: @PACKAGE_VERSION@ -Release: 0 -Summary: LLVM (An Optimizing Compiler Infrastructure) -License: Apache-2.0 with LLVM exception -Vendor: None (open source) -Group: Development/Compilers -URL: http://llvm..org/ -Source: http://llvm.org/releases/@PACKAGE_VERSION@/@PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz -BuildRoot: %{_tmppath}/%{name}-root -Requires: /sbin/ldconfig -BuildRequires: gcc >= 3.4 - -%description -LLVM is a compiler infrastructure designed for compile-time, link-time, runtime, -and idle-time optimization of programs from arbitrary programming languages. -LLVM is written in C++ and has been developed since 2000 at the University of -Illinois and Apple. It currently supports compilation of C and C++ programs, -using front-ends derived from GCC 4.0.1. A new front-end for the C family of -languages is in development. The compiler infrastructure -includes mirror sets of programming tools as well as libraries with equivalent -functionality. - -%prep -%setup -q -n @PACKAGE_NAME@-@PACKAGE_VERSION@ - -%build -./configure \ ---prefix=%{_prefix} \ ---bindir=%{_bindir} \ ---datadir=%{_datadir} \ ---includedir=%{_includedir} \ ---libdir=%{_libdir} \ ---enable-optimized \ ---enable-assertions -make tools-only - -%install -rm -rf %{buildroot} -make install DESTDIR=%{buildroot} - -%clean -rm -rf %{buildroot} - -%post -p /sbin/ldconfig - -%postun -p /sbin/ldconfig - -%files -%defattr(-, root, root) -%doc CREDITS.TXT LICENSE.TXT README.txt docs/*.{html,css,gif,jpg} docs/CommandGuide -%{_bindir}/* -%{_libdir}/*.o -%{_libdir}/*.a -%{_libdir}/*.so -%{_includedir}/llvm - -%changelog -* Fri Aug 04 2006 Reid Spencer -- Updates for release 1.8 -* Fri Apr 07 2006 Reid Spencer -- Make the build be optimized+assertions -* Fri May 13 2005 Reid Spencer -- Minor adjustments for the 1.5 release -* Mon Feb 09 2003 Brian R. Gaeke -- Initial working version of RPM spec file. - - -- cgit v1.1 From fdcfb277465e4530e5837fb8a95031794e58cb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Tue, 2 Jul 2024 10:27:45 +0200 Subject: [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (#95550) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … because they were strangely worded and in a few cases outright incorrect. --- .../clang-tidy/bugprone/SizeofExpressionCheck.cpp | 21 +++--- clang-tools-extra/docs/ReleaseNotes.rst | 8 +-- .../checkers/bugprone/sizeof-expression-2.c | 12 ++-- .../bugprone/sizeof-expression-any-pointer.cpp | 76 +++++++++++----------- ...ression-warn-on-sizeof-pointer-to-aggregate.cpp | 2 +- .../checkers/bugprone/sizeof-expression.cpp | 74 ++++++++++----------- 6 files changed, 98 insertions(+), 95 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp index c25ee42..d517e84 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp @@ -296,7 +296,7 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) { } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-integer-call")) { diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression " - "that results in an integer") + "of integer type") << E->getSourceRange(); } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-this")) { diag(E->getBeginLoc(), @@ -314,7 +314,7 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) { << E->getSourceRange(); } else { diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression " - "that results in a pointer") + "of pointer type") << E->getSourceRange(); } } else if (const auto *E = Result.Nodes.getNodeAs( @@ -348,25 +348,28 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) { } else if (ElementSize > CharUnits::Zero() && DenominatorSize > CharUnits::Zero() && ElementSize != DenominatorSize) { - diag(E->getOperatorLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';" - " numerator is not a multiple of denominator") + // FIXME: Apparently there are no testcases that cover this branch! + diag(E->getOperatorLoc(), + "suspicious usage of 'sizeof(array)/sizeof(...)';" + " denominator differs from the size of array elements") << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange(); } else if (NumTy && DenomTy && NumTy == DenomTy) { - // FIXME: This message is wrong, it should not refer to sizeof "pointer" - // usage (and by the way, it would be to clarify all the messages). diag(E->getOperatorLoc(), - "suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'") + "suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions " + "have the same type") << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange(); } else if (!WarnOnSizeOfPointer) { // When 'WarnOnSizeOfPointer' is enabled, these messages become redundant: if (PointedTy && DenomTy && PointedTy == DenomTy) { diag(E->getOperatorLoc(), - "suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'") + "suspicious usage of 'sizeof(...)/sizeof(...)'; size of pointer " + "is divided by size of pointed type") << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange(); } else if (NumTy && DenomTy && NumTy->isPointerType() && DenomTy->isPointerType()) { diag(E->getOperatorLoc(), - "suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'") + "suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions " + "have pointer types") << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange(); } } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 4d2cd0a..fe81973 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -241,10 +241,10 @@ Changes in existing checks false positives resulting from use of optionals in unevaluated context. - Improved :doc:`bugprone-sizeof-expression - ` check by eliminating some - false positives and adding a new (off-by-default) option - `WarnOnSizeOfPointer` that reports all ``sizeof(pointer)`` expressions - (except for a few that are idiomatic). + ` check by clarifying the + diagnostics, eliminating some false positives and adding a new + (off-by-default) option `WarnOnSizeOfPointer` that reports all + ``sizeof(pointer)`` expressions (except for a few that are idiomatic). - Improved :doc:`bugprone-suspicious-include ` check by replacing the local diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-2.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-2.c index aef930f..b898071 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-2.c +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-2.c @@ -34,24 +34,24 @@ int Test5() { int sum = 0; sum += sizeof(&S); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(__typeof(&S)); sum += sizeof(&TS); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(__typeof(&TS)); sum += sizeof(STRKWD MyStruct*); sum += sizeof(__typeof(STRKWD MyStruct*)); sum += sizeof(TypedefStruct*); sum += sizeof(__typeof(TypedefStruct*)); sum += sizeof(PTTS); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PMyStruct); sum += sizeof(PS); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PS2); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&A10); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type #ifdef __cplusplus MyStruct &rS = S; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-any-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-any-pointer.cpp index bfb2ec3..4c65d25 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-any-pointer.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-any-pointer.cpp @@ -38,17 +38,17 @@ int Test1(const char* ptr) { sum += sizeof(sum, LEN); // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(..., ...)' sum += sizeof(AsBool()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(AsInt()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(AsEnum()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(AsEnumClass()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(M{}.AsInt()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(M{}.AsEnum()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(sizeof(X)); // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(sizeof(...))' sum += sizeof(LEN + sizeof(X)); @@ -62,7 +62,7 @@ int Test1(const char* ptr) { sum += sizeof(LEN + - + -sizeof(X)); // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(sizeof(...))' sum += sizeof(char) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type sum += sizeof(A) / sizeof(S); // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator sum += sizeof(char) / sizeof(int); @@ -72,21 +72,21 @@ int Test1(const char* ptr) { sum += sizeof(B[0]) / sizeof(A); // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator sum += sizeof(ptr) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(ptr) / sizeof(ptr[0]); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(ptr) / sizeof(char*); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(ptr) / sizeof(void*); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(ptr) / sizeof(const void volatile*); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(ptr) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(int) * sizeof(char); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious 'sizeof' by 'sizeof' multiplication sum += sizeof(ptr) * sizeof(ptr[0]); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type // CHECK-MESSAGES: :[[@LINE-2]]:22: warning: suspicious 'sizeof' by 'sizeof' multiplication sum += sizeof(int) * (2 * sizeof(char)); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious 'sizeof' by 'sizeof' multiplication @@ -127,54 +127,54 @@ int Test5() { int sum = 0; sum += sizeof(&S.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&kGlocalMyStruct.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&kGlocalMyStructPtr->arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(S.arr + 0); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(+ S.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof((int*)S.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(S.ptr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(kGlocalMyStruct.ptr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(kGlocalMyStructPtr->ptr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&kGlocalMyStruct); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&S); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(MyStruct*); sum += sizeof(PMyStruct); sum += sizeof(PS); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PS2); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&A10); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PtrArray) / sizeof(PtrArray[1]); - // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(A10) / sizeof(PtrArray[0]); sum += sizeof(PC) / sizeof(PtrArray[0]); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer - // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type + // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type sum += sizeof(ArrayC) / sizeof(PtrArray[0]); // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator sum += sizeof(PChar); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PInt); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PPInt); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PPMyStruct); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type return sum; } @@ -200,9 +200,9 @@ void GenericFunctionTest() { // reported by the `sizeof(pointer)` checks, but this causes some false // positives, so it would be good to create an exception for them. some_generic_function(&IntPP, sizeof(IntP)); - // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: suspicious usage of 'sizeof()' on an expression of pointer type some_generic_function(&ClassPP, sizeof(ClassP)); - // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: suspicious usage of 'sizeof()' on an expression of pointer type } int ValidExpressions() { @@ -222,7 +222,7 @@ int ValidExpressions() { sum += sizeof(A[sizeof(A) / sizeof(int)]); // Here the outer sizeof is reported, but the inner ones are accepted: sum += sizeof(&A[sizeof(A) / sizeof(int)]); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(sizeof(0)); // Special case: sizeof size_t. sum += sizeof(void*); sum += sizeof(void const *); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp index 5ef2c46..5c6b728 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp @@ -68,7 +68,7 @@ int Test5() { sum += sizeof(A10) / sizeof(PtrArray[0]); // No warning. sum += sizeof(PC) / sizeof(PtrArray[0]); - // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type sum += sizeof(ArrayC) / sizeof(PtrArray[0]); // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp index 064f31c..671fd83 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp @@ -48,13 +48,13 @@ bool TestTrait2() { template bool TestTrait3() { return sizeof(ReturnOverload(0)) == sizeof(T{}); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type } template bool TestTrait4() { return sizeof(ReturnTemplate(0)) == sizeof(T{}); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type } bool TestTemplates() { @@ -79,17 +79,17 @@ int Test1(const char* ptr) { sum += sizeof(sum, LEN); // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(..., ...)' sum += sizeof(AsBool()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(AsInt()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(AsEnum()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(AsEnumClass()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(M{}.AsInt()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(M{}.AsEnum()); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of integer type sum += sizeof(sizeof(X)); // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(sizeof(...))' sum += sizeof(LEN + sizeof(X)); @@ -103,7 +103,7 @@ int Test1(const char* ptr) { sum += sizeof(LEN + - + -sizeof(X)); // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(sizeof(...))' sum += sizeof(char) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type sum += sizeof(A) / sizeof(S); // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator sum += sizeof(char) / sizeof(int); @@ -113,17 +113,17 @@ int Test1(const char* ptr) { sum += sizeof(B[0]) / sizeof(A); // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator sum += sizeof(ptr) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; size of pointer is divided by size of pointed type sum += sizeof(ptr) / sizeof(ptr[0]); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; size of pointer is divided by size of pointed type sum += sizeof(ptr) / sizeof(char*); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)' + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have pointer types sum += sizeof(ptr) / sizeof(void*); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)' + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have pointer types sum += sizeof(ptr) / sizeof(const void volatile*); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)' + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have pointer types sum += sizeof(ptr) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; size of pointer is divided by size of pointed type sum += sizeof(int) * sizeof(char); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious 'sizeof' by 'sizeof' multiplication sum += sizeof(ptr) * sizeof(ptr[0]); @@ -156,11 +156,11 @@ int CE4 = sizeof sizeof(MyConstChar); int Test2(MyConstChar* A) { int sum = 0; sum += sizeof(MyConstChar) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type sum += sizeof(MyConstChar) / sizeof(MyChar); - // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type sum += sizeof(A[0]) / sizeof(char); - // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type return sum; } @@ -169,7 +169,7 @@ int Foo() { int A[T]; return sizeof(T); } // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(K)' template int Bar() { T A[5]; return sizeof(A[0]) / sizeof(T); } -// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' +// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type int Test3() { return Foo<42>() + Bar(); } static const char* kABC = "abc"; @@ -211,43 +211,43 @@ int Test5() { int sum = 0; sum += sizeof(&S.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&kGlocalMyStruct.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&kGlocalMyStructPtr->arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(S.arr + 0); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(+ S.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof((int*)S.arr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(S.ptr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(kGlocalMyStruct.ptr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(kGlocalMyStructPtr->ptr); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&kGlocalMyStruct); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&S); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(MyStruct*); sum += sizeof(PMyStruct); sum += sizeof(PS); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PS2); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(&A10); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(PtrArray) / sizeof(PtrArray[1]); - // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: suspicious usage of 'sizeof()' on an expression of pointer type sum += sizeof(A10) / sizeof(PtrArray[0]); sum += sizeof(PC) / sizeof(PtrArray[0]); - // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer - // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)' + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression of pointer type + // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; both expressions have the same type sum += sizeof(ArrayC) / sizeof(PtrArray[0]); // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator @@ -321,7 +321,7 @@ void GenericFunctionTest() { // NOTE: `sizeof(IntP)` is only reported with `WarnOnSizeOfPointer=true`. some_generic_function(&IntPP, sizeof(IntP)); some_generic_function(&ClassPP, sizeof(ClassP)); - // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: suspicious usage of 'sizeof()' on an expression that results in a pointer + // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: suspicious usage of 'sizeof()' on an expression of pointer type } int ValidExpressions() { -- cgit v1.1 From b558ac0eef57a3737b1e27844115fa91e0b32582 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 2 Jul 2024 10:08:45 +0200 Subject: [InstCombine] Fix context for multi-use demanded bits simplification When simplifying a multi-use root value, the demanded bits were reset to full, but we also need to reset the context extract. To make this convenient (without requiring by-value passing of SimplifyQuery), move the logic that that handles constants and dispatches to SimplifyDemandedUseBits/SimplifyMultipleUseDemandedBits into SimplifyDemandedBits. The SimplifyDemandedInstructionBits caller starts with full demanded bits and an appropriate context anyway. The different context instruction does mean that the ephemeral value protection no longer triggers in some cases, as the changes to assume tests show. An alternative, which I will explore in a followup, is to always use SimplifyMultipleUseDemandedBits() -- the previous root special case is only really intended for SimplifyDemandedInstructionBits(), which now no longer shares this code path. Fixes https://github.com/llvm/llvm-project/issues/97330. --- .../Transforms/InstCombine/InstCombineInternal.h | 7 +- .../InstCombine/InstCombineSimplifyDemanded.cpp | 93 ++++++++++++---------- .../Transforms/InstCombine/assume-inseltpoison.ll | 2 - llvm/test/Transforms/InstCombine/assume.ll | 2 - llvm/test/Transforms/InstCombine/known-bits.ll | 5 +- 5 files changed, 59 insertions(+), 50 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 318c455..64fbcc8 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -545,10 +545,11 @@ public: ConstantInt *&Less, ConstantInt *&Equal, ConstantInt *&Greater); - /// Attempts to replace V with a simpler value based on the demanded + /// Attempts to replace I with a simpler value based on the demanded /// bits. - Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known, - unsigned Depth, const SimplifyQuery &Q); + Value *SimplifyDemandedUseBits(Instruction *I, const APInt &DemandedMask, + KnownBits &Known, unsigned Depth, + const SimplifyQuery &Q); using InstCombiner::SimplifyDemandedBits; bool SimplifyDemandedBits(Instruction *I, unsigned Op, const APInt &DemandedMask, KnownBits &Known, diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 6cf2e71..b1d0378 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -91,8 +91,47 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { Use &U = I->getOperandUse(OpNo); - Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known, - Depth, Q); + Value *V = U.get(); + if (isa(V)) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Known.resetAll(); + if (DemandedMask.isZero()) { + // Not demanding any bits from V. + replaceUse(U, UndefValue::get(V->getType())); + return true; + } + + if (Depth == MaxAnalysisRecursionDepth) + return false; + + Instruction *VInst = dyn_cast(V); + if (!VInst) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Value *NewVal; + if (VInst->hasOneUse()) { + // If the instruction has one use, we can directly simplify it. + NewVal = SimplifyDemandedUseBits(VInst, DemandedMask, Known, Depth, Q); + } else if (Depth != 0) { + // If there are multiple uses of this instruction and we aren't at the root, + // then we can simplify VInst to some other value, but not modify the + // instruction. + NewVal = + SimplifyMultipleUseDemandedBits(VInst, DemandedMask, Known, Depth, Q); + } else { + // If this is the root being simplified, allow it to have multiple uses, + // just set the DemandedMask to all bits and reset the context instruction. + // This allows visitTruncInst (for example) to simplify the operand of a + // trunc without duplicating all the SimplifyDemandedUseBits() logic. + NewVal = + SimplifyDemandedUseBits(VInst, APInt::getAllOnes(Known.getBitWidth()), + Known, Depth, Q.getWithInstruction(VInst)); + } if (!NewVal) return false; if (Instruction* OpInst = dyn_cast(U)) salvageDebugInfo(*OpInst); @@ -124,50 +163,21 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, /// operands based on the information about what bits are demanded. This returns /// some other non-null value if it found out that V is equal to another value /// in the context where the specified bits are demanded, but not for all users. -Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, +Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, + const APInt &DemandedMask, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { - assert(V != nullptr && "Null pointer of Value???"); + assert(I != nullptr && "Null pointer of Value???"); assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth"); uint32_t BitWidth = DemandedMask.getBitWidth(); - Type *VTy = V->getType(); + Type *VTy = I->getType(); assert( (!VTy->isIntOrIntVectorTy() || VTy->getScalarSizeInBits() == BitWidth) && Known.getBitWidth() == BitWidth && "Value *V, DemandedMask and Known must have same BitWidth"); - if (isa(V)) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; - } - - Known.resetAll(); - if (DemandedMask.isZero()) // Not demanding any bits from V. - return UndefValue::get(VTy); - - if (Depth == MaxAnalysisRecursionDepth) - return nullptr; - - Instruction *I = dyn_cast(V); - if (!I) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; // Only analyze instructions. - } - - // If there are multiple uses of this value and we aren't at the root, then - // we can't do any simplifications of the operands, because DemandedMask - // only reflects the bits demanded by *one* of the users. - if (Depth != 0 && !I->hasOneUse()) - return SimplifyMultipleUseDemandedBits(I, DemandedMask, Known, Depth, Q); - KnownBits LHSKnown(BitWidth), RHSKnown(BitWidth); - // If this is the root being simplified, allow it to have multiple uses, - // just set the DemandedMask to all bits so that we can try to simplify the - // operands. This allows visitTruncInst (for example) to simplify the - // operand of a trunc without duplicating all the logic below. - if (Depth == 0 && !V->hasOneUse()) - DemandedMask.setAllBits(); // Update flags after simplifying an operand based on the fact that some high // order bits are not demanded. @@ -1105,13 +1115,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, } if (!KnownBitsComputed) - llvm::computeKnownBits(V, Known, Depth, Q); + llvm::computeKnownBits(I, Known, Depth, Q); break; } } - if (V->getType()->isPointerTy()) { - Align Alignment = V->getPointerAlignment(DL); + if (I->getType()->isPointerTy()) { + Align Alignment = I->getPointerAlignment(DL); Known.Zero.setLowBits(Log2(Alignment)); } @@ -1119,13 +1129,14 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // constant. We can't directly simplify pointers as a constant because of // pointer provenance. // TODO: We could return `(inttoptr const)` for pointers. - if (!V->getType()->isPointerTy() && DemandedMask.isSubsetOf(Known.Zero | Known.One)) + if (!I->getType()->isPointerTy() && + DemandedMask.isSubsetOf(Known.Zero | Known.One)) return Constant::getIntegerValue(VTy, Known.One); if (VerifyKnownBits) { - KnownBits ReferenceKnown = llvm::computeKnownBits(V, Depth, Q); + KnownBits ReferenceKnown = llvm::computeKnownBits(I, Depth, Q); if (Known != ReferenceKnown) { - errs() << "Mismatched known bits for " << *V << " in " + errs() << "Mismatched known bits for " << *I << " in " << I->getFunction()->getName() << "\n"; errs() << "computeKnownBits(): " << ReferenceKnown << "\n"; errs() << "SimplifyDemandedBits(): " << Known << "\n"; diff --git a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll index 79a1ec2..a03ff3e 100644 --- a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll +++ b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll @@ -15,8 +15,6 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 -; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 -; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll index 474da99..2ef7433 100644 --- a/llvm/test/Transforms/InstCombine/assume.ll +++ b/llvm/test/Transforms/InstCombine/assume.ll @@ -428,8 +428,6 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 -; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 -; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> diff --git a/llvm/test/Transforms/InstCombine/known-bits.ll b/llvm/test/Transforms/InstCombine/known-bits.ll index 8520981..c7445a6 100644 --- a/llvm/test/Transforms/InstCombine/known-bits.ll +++ b/llvm/test/Transforms/InstCombine/known-bits.ll @@ -2025,7 +2025,6 @@ define i8 @simplifydemanded_context(i8 %x, i8 %y) { ret i8 %and2 } -; FIXME: This is a miscompile. define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { ; CHECK-LABEL: @pr97330( ; CHECK-NEXT: entry: @@ -2033,7 +2032,9 @@ define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { ; CHECK: if: ; CHECK-NEXT: unreachable ; CHECK: exit: -; CHECK-NEXT: ret i16 1 +; CHECK-NEXT: [[V:%.*]] = load i64, ptr [[P1:%.*]], align 8 +; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[V]] to i16 +; CHECK-NEXT: ret i16 [[CONV]] ; entry: %v = load i64, ptr %p1, align 8 -- cgit v1.1 From 12c1156207e8c0d63701487f210ce90c4b7da938 Mon Sep 17 00:00:00 2001 From: Daniil Fukalov <1671137+dfukalov@users.noreply.github.com> Date: Tue, 2 Jul 2024 10:43:49 +0200 Subject: [NFC][AlwaysInliner] Reduce AlwaysInliner memory consumption. (#96958) Refactored AlwaysInliner to remove some of inlined functions earlier. Before the change AlwaysInliner walked through all functions in the module and inlined them into calls where it is appropriate. Removing of the dead inlined functions was performed only after all of inlining. For the test case from the issue [59126](https://github.com/llvm/llvm-project/issues/59126) compiler consumes all of the memory on 64GB machine, so is killed. The change checks if just inlined function can be removed from the module and removes it. --- llvm/lib/Transforms/IPO/AlwaysInliner.cpp | 123 +++++++++------------ .../Inline/always-inline-phase-ordering.ll | 1 - 2 files changed, 55 insertions(+), 69 deletions(-) diff --git a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp index cc375f9..1f787c7 100644 --- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp +++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp @@ -15,12 +15,12 @@ #include "llvm/ADT/SetVector.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/InlineAdvisor.h" #include "llvm/Analysis/InlineCost.h" #include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/IR/Module.h" #include "llvm/InitializePasses.h" -#include "llvm/Transforms/IPO/Inliner.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/ModuleUtils.h" @@ -37,86 +37,73 @@ bool AlwaysInlineImpl( function_ref GetBFI) { SmallSetVector Calls; bool Changed = false; - SmallVector InlinedFunctions; - for (Function &F : M) { - // When callee coroutine function is inlined into caller coroutine function - // before coro-split pass, - // coro-early pass can not handle this quiet well. - // So we won't inline the coroutine function if it have not been unsplited + SmallVector InlinedComdatFunctions; + + for (Function &F : make_early_inc_range(M)) { if (F.isPresplitCoroutine()) continue; - if (!F.isDeclaration() && isInlineViable(F).isSuccess()) { - Calls.clear(); - - for (User *U : F.users()) - if (auto *CB = dyn_cast(U)) - if (CB->getCalledFunction() == &F && - CB->hasFnAttr(Attribute::AlwaysInline) && - !CB->getAttributes().hasFnAttr(Attribute::NoInline)) - Calls.insert(CB); - - for (CallBase *CB : Calls) { - Function *Caller = CB->getCaller(); - OptimizationRemarkEmitter ORE(Caller); - DebugLoc DLoc = CB->getDebugLoc(); - BasicBlock *Block = CB->getParent(); - - InlineFunctionInfo IFI(GetAssumptionCache, &PSI, - GetBFI ? &GetBFI(*Caller) : nullptr, - GetBFI ? &GetBFI(F) : nullptr); - - InlineResult Res = InlineFunction(*CB, IFI, /*MergeAttributes=*/true, - &GetAAR(F), InsertLifetime); - if (!Res.isSuccess()) { - ORE.emit([&]() { - return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, - Block) - << "'" << ore::NV("Callee", &F) << "' is not inlined into '" - << ore::NV("Caller", Caller) - << "': " << ore::NV("Reason", Res.getFailureReason()); - }); - continue; - } - - emitInlinedIntoBasedOnCost( - ORE, DLoc, Block, F, *Caller, - InlineCost::getAlways("always inline attribute"), - /*ForProfileContext=*/false, DEBUG_TYPE); + if (F.isDeclaration() || !isInlineViable(F).isSuccess()) + continue; - Changed = true; + Calls.clear(); + + for (User *U : F.users()) + if (auto *CB = dyn_cast(U)) + if (CB->getCalledFunction() == &F && + CB->hasFnAttr(Attribute::AlwaysInline) && + !CB->getAttributes().hasFnAttr(Attribute::NoInline)) + Calls.insert(CB); + + for (CallBase *CB : Calls) { + Function *Caller = CB->getCaller(); + OptimizationRemarkEmitter ORE(Caller); + DebugLoc DLoc = CB->getDebugLoc(); + BasicBlock *Block = CB->getParent(); + + InlineFunctionInfo IFI(GetAssumptionCache, &PSI, + GetBFI ? &GetBFI(*Caller) : nullptr, + GetBFI ? &GetBFI(F) : nullptr); + + InlineResult Res = InlineFunction(*CB, IFI, /*MergeAttributes=*/true, + &GetAAR(F), InsertLifetime); + if (!Res.isSuccess()) { + ORE.emit([&]() { + return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block) + << "'" << ore::NV("Callee", &F) << "' is not inlined into '" + << ore::NV("Caller", Caller) + << "': " << ore::NV("Reason", Res.getFailureReason()); + }); + continue; } - if (F.hasFnAttribute(Attribute::AlwaysInline)) { - // Remember to try and delete this function afterward. This both avoids - // re-walking the rest of the module and avoids dealing with any - // iterator invalidation issues while deleting functions. - InlinedFunctions.push_back(&F); - } + emitInlinedIntoBasedOnCost( + ORE, DLoc, Block, F, *Caller, + InlineCost::getAlways("always inline attribute"), + /*ForProfileContext=*/false, DEBUG_TYPE); + + Changed = true; } - } - // Remove any live functions. - erase_if(InlinedFunctions, [&](Function *F) { - F->removeDeadConstantUsers(); - return !F->isDefTriviallyDead(); - }); - - // Delete the non-comdat ones from the module and also from our vector. - auto NonComdatBegin = partition( - InlinedFunctions, [&](Function *F) { return F->hasComdat(); }); - for (Function *F : make_range(NonComdatBegin, InlinedFunctions.end())) { - M.getFunctionList().erase(F); - Changed = true; + F.removeDeadConstantUsers(); + if (F.hasFnAttribute(Attribute::AlwaysInline) && F.isDefTriviallyDead()) { + // Remember to try and delete this function afterward. This allows to call + // filterDeadComdatFunctions() only once. + if (F.hasComdat()) { + InlinedComdatFunctions.push_back(&F); + } else { + M.getFunctionList().erase(F); + Changed = true; + } + } } - InlinedFunctions.erase(NonComdatBegin, InlinedFunctions.end()); - if (!InlinedFunctions.empty()) { + if (!InlinedComdatFunctions.empty()) { // Now we just have the comdat functions. Filter out the ones whose comdats // are not actually dead. - filterDeadComdatFunctions(InlinedFunctions); + filterDeadComdatFunctions(InlinedComdatFunctions); // The remaining functions are actually dead. - for (Function *F : InlinedFunctions) { + for (Function *F : InlinedComdatFunctions) { M.getFunctionList().erase(F); Changed = true; } diff --git a/llvm/test/Transforms/Inline/always-inline-phase-ordering.ll b/llvm/test/Transforms/Inline/always-inline-phase-ordering.ll index e69ca48..defd1f4 100644 --- a/llvm/test/Transforms/Inline/always-inline-phase-ordering.ll +++ b/llvm/test/Transforms/Inline/always-inline-phase-ordering.ll @@ -6,7 +6,6 @@ target triple = "arm64e-apple-macosx13" ; CHECK: remark: :0:0: 'wibble' inlined into 'pluto' with (cost=always): always inline attribute ; CHECK: remark: :0:0: 'snork' inlined into 'blam' with (cost=always): always inline attribute ; CHECK: remark: :0:0: 'wobble' inlined into 'blam' with (cost=always): always inline attribute -; CHECK: remark: :0:0: 'wobble' inlined into 'snork' with (cost=always): always inline attribute ; CHECK: remark: :0:0: 'spam' inlined into 'blam' with (cost=65, threshold=75) ; CHECK: remark: :0:0: 'wibble.1' inlined into 'widget' with (cost=30, threshold=75) ; CHECK: remark: :0:0: 'widget' inlined into 'bar.8' with (cost=30, threshold=75) -- cgit v1.1 From 167c860ba209fc584f72d04c48091b40ae3a5610 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 2 Jul 2024 10:44:10 +0200 Subject: Revert "[InstCombine] Fix context for multi-use demanded bits simplification" This reverts commit b558ac0eef57a3737b1e27844115fa91e0b32582. This breaks a clang test, reverting for now. --- .../Transforms/InstCombine/InstCombineInternal.h | 7 +- .../InstCombine/InstCombineSimplifyDemanded.cpp | 93 ++++++++++------------ .../Transforms/InstCombine/assume-inseltpoison.ll | 2 + llvm/test/Transforms/InstCombine/assume.ll | 2 + llvm/test/Transforms/InstCombine/known-bits.ll | 5 +- 5 files changed, 50 insertions(+), 59 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 64fbcc8..318c455 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -545,11 +545,10 @@ public: ConstantInt *&Less, ConstantInt *&Equal, ConstantInt *&Greater); - /// Attempts to replace I with a simpler value based on the demanded + /// Attempts to replace V with a simpler value based on the demanded /// bits. - Value *SimplifyDemandedUseBits(Instruction *I, const APInt &DemandedMask, - KnownBits &Known, unsigned Depth, - const SimplifyQuery &Q); + Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known, + unsigned Depth, const SimplifyQuery &Q); using InstCombiner::SimplifyDemandedBits; bool SimplifyDemandedBits(Instruction *I, unsigned Op, const APInt &DemandedMask, KnownBits &Known, diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index b1d0378..6cf2e71 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -91,47 +91,8 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { Use &U = I->getOperandUse(OpNo); - Value *V = U.get(); - if (isa(V)) { - llvm::computeKnownBits(V, Known, Depth, Q); - return false; - } - - Known.resetAll(); - if (DemandedMask.isZero()) { - // Not demanding any bits from V. - replaceUse(U, UndefValue::get(V->getType())); - return true; - } - - if (Depth == MaxAnalysisRecursionDepth) - return false; - - Instruction *VInst = dyn_cast(V); - if (!VInst) { - llvm::computeKnownBits(V, Known, Depth, Q); - return false; - } - - Value *NewVal; - if (VInst->hasOneUse()) { - // If the instruction has one use, we can directly simplify it. - NewVal = SimplifyDemandedUseBits(VInst, DemandedMask, Known, Depth, Q); - } else if (Depth != 0) { - // If there are multiple uses of this instruction and we aren't at the root, - // then we can simplify VInst to some other value, but not modify the - // instruction. - NewVal = - SimplifyMultipleUseDemandedBits(VInst, DemandedMask, Known, Depth, Q); - } else { - // If this is the root being simplified, allow it to have multiple uses, - // just set the DemandedMask to all bits and reset the context instruction. - // This allows visitTruncInst (for example) to simplify the operand of a - // trunc without duplicating all the SimplifyDemandedUseBits() logic. - NewVal = - SimplifyDemandedUseBits(VInst, APInt::getAllOnes(Known.getBitWidth()), - Known, Depth, Q.getWithInstruction(VInst)); - } + Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known, + Depth, Q); if (!NewVal) return false; if (Instruction* OpInst = dyn_cast(U)) salvageDebugInfo(*OpInst); @@ -163,21 +124,50 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, /// operands based on the information about what bits are demanded. This returns /// some other non-null value if it found out that V is equal to another value /// in the context where the specified bits are demanded, but not for all users. -Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, - const APInt &DemandedMask, +Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { - assert(I != nullptr && "Null pointer of Value???"); + assert(V != nullptr && "Null pointer of Value???"); assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth"); uint32_t BitWidth = DemandedMask.getBitWidth(); - Type *VTy = I->getType(); + Type *VTy = V->getType(); assert( (!VTy->isIntOrIntVectorTy() || VTy->getScalarSizeInBits() == BitWidth) && Known.getBitWidth() == BitWidth && "Value *V, DemandedMask and Known must have same BitWidth"); + if (isa(V)) { + llvm::computeKnownBits(V, Known, Depth, Q); + return nullptr; + } + + Known.resetAll(); + if (DemandedMask.isZero()) // Not demanding any bits from V. + return UndefValue::get(VTy); + + if (Depth == MaxAnalysisRecursionDepth) + return nullptr; + + Instruction *I = dyn_cast(V); + if (!I) { + llvm::computeKnownBits(V, Known, Depth, Q); + return nullptr; // Only analyze instructions. + } + + // If there are multiple uses of this value and we aren't at the root, then + // we can't do any simplifications of the operands, because DemandedMask + // only reflects the bits demanded by *one* of the users. + if (Depth != 0 && !I->hasOneUse()) + return SimplifyMultipleUseDemandedBits(I, DemandedMask, Known, Depth, Q); + KnownBits LHSKnown(BitWidth), RHSKnown(BitWidth); + // If this is the root being simplified, allow it to have multiple uses, + // just set the DemandedMask to all bits so that we can try to simplify the + // operands. This allows visitTruncInst (for example) to simplify the + // operand of a trunc without duplicating all the logic below. + if (Depth == 0 && !V->hasOneUse()) + DemandedMask.setAllBits(); // Update flags after simplifying an operand based on the fact that some high // order bits are not demanded. @@ -1115,13 +1105,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, } if (!KnownBitsComputed) - llvm::computeKnownBits(I, Known, Depth, Q); + llvm::computeKnownBits(V, Known, Depth, Q); break; } } - if (I->getType()->isPointerTy()) { - Align Alignment = I->getPointerAlignment(DL); + if (V->getType()->isPointerTy()) { + Align Alignment = V->getPointerAlignment(DL); Known.Zero.setLowBits(Log2(Alignment)); } @@ -1129,14 +1119,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, // constant. We can't directly simplify pointers as a constant because of // pointer provenance. // TODO: We could return `(inttoptr const)` for pointers. - if (!I->getType()->isPointerTy() && - DemandedMask.isSubsetOf(Known.Zero | Known.One)) + if (!V->getType()->isPointerTy() && DemandedMask.isSubsetOf(Known.Zero | Known.One)) return Constant::getIntegerValue(VTy, Known.One); if (VerifyKnownBits) { - KnownBits ReferenceKnown = llvm::computeKnownBits(I, Depth, Q); + KnownBits ReferenceKnown = llvm::computeKnownBits(V, Depth, Q); if (Known != ReferenceKnown) { - errs() << "Mismatched known bits for " << *I << " in " + errs() << "Mismatched known bits for " << *V << " in " << I->getFunction()->getName() << "\n"; errs() << "computeKnownBits(): " << ReferenceKnown << "\n"; errs() << "SimplifyDemandedBits(): " << Known << "\n"; diff --git a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll index a03ff3e..79a1ec2 100644 --- a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll +++ b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll @@ -15,6 +15,8 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 +; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 +; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll index 2ef7433..474da99 100644 --- a/llvm/test/Transforms/InstCombine/assume.ll +++ b/llvm/test/Transforms/InstCombine/assume.ll @@ -428,6 +428,8 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 +; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 +; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> diff --git a/llvm/test/Transforms/InstCombine/known-bits.ll b/llvm/test/Transforms/InstCombine/known-bits.ll index c7445a6..8520981 100644 --- a/llvm/test/Transforms/InstCombine/known-bits.ll +++ b/llvm/test/Transforms/InstCombine/known-bits.ll @@ -2025,6 +2025,7 @@ define i8 @simplifydemanded_context(i8 %x, i8 %y) { ret i8 %and2 } +; FIXME: This is a miscompile. define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { ; CHECK-LABEL: @pr97330( ; CHECK-NEXT: entry: @@ -2032,9 +2033,7 @@ define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { ; CHECK: if: ; CHECK-NEXT: unreachable ; CHECK: exit: -; CHECK-NEXT: [[V:%.*]] = load i64, ptr [[P1:%.*]], align 8 -; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[V]] to i16 -; CHECK-NEXT: ret i16 [[CONV]] +; CHECK-NEXT: ret i16 1 ; entry: %v = load i64, ptr %p1, align 8 -- cgit v1.1 From 86b37944a70229b07626e63bdb9a46b4bc3d1460 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 2 Jul 2024 10:08:45 +0200 Subject: Reapply [InstCombine] Fix context for multi-use demanded bits simplification Repplied with a clang test fix. ----- When simplifying a multi-use root value, the demanded bits were reset to full, but we also need to reset the context instruction. To make this convenient (without requiring by-value passing of SimplifyQuery), move the logic that handles constants and dispatches to SimplifyDemandedUseBits/SimplifyMultipleUseDemandedBits into SimplifyDemandedBits. The SimplifyDemandedInstructionBits caller starts with full demanded bits and an appropriate context anyway. The different context instruction does mean that the ephemeral value protection no longer triggers in some cases, as the changes to assume tests show. An alternative, which I will explore in a followup, is to always use SimplifyMultipleUseDemandedBits() -- the previous root special case is only really intended for SimplifyDemandedInstructionBits(), which now no longer shares this code path. Fixes https://github.com/llvm/llvm-project/issues/97330. --- clang/test/CodeGen/inline-asm-x86-flag-output.c | 4 +- .../Transforms/InstCombine/InstCombineInternal.h | 7 +- .../InstCombine/InstCombineSimplifyDemanded.cpp | 93 ++++++++++++---------- .../Transforms/InstCombine/assume-inseltpoison.ll | 2 - llvm/test/Transforms/InstCombine/assume.ll | 2 - llvm/test/Transforms/InstCombine/known-bits.ll | 5 +- 6 files changed, 60 insertions(+), 53 deletions(-) diff --git a/clang/test/CodeGen/inline-asm-x86-flag-output.c b/clang/test/CodeGen/inline-asm-x86-flag-output.c index 243dc37..7ca6dc7a 100644 --- a/clang/test/CodeGen/inline-asm-x86-flag-output.c +++ b/clang/test/CodeGen/inline-asm-x86-flag-output.c @@ -380,10 +380,8 @@ int test_assume_boolean_flag(long nr, volatile long *addr) { //CHECK: %0 = tail call { i32, i32 } asm "cmp $2,$1", "={@cca},={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr) //CHECK: [[RES1:%.*]] = extractvalue { i32, i32 } %0, 0 //CHECK: [[RES2:%.*]] = extractvalue { i32, i32 } %0, 1 - //CHECK: %1 = icmp ult i32 [[RES1]], 2 + //CHECK: %1 = icmp ult i32 [[RES2]], 2 //CHECK: tail call void @llvm.assume(i1 %1) - //CHECK: %2 = icmp ult i32 [[RES2]], 2 - //CHECK: tail call void @llvm.assume(i1 %2) int x,y; asm("cmp %2,%1" : "=@cca"(x), "=@ccae"(y), "=m"(*(volatile long *)(addr)) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 318c455..64fbcc8 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -545,10 +545,11 @@ public: ConstantInt *&Less, ConstantInt *&Equal, ConstantInt *&Greater); - /// Attempts to replace V with a simpler value based on the demanded + /// Attempts to replace I with a simpler value based on the demanded /// bits. - Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known, - unsigned Depth, const SimplifyQuery &Q); + Value *SimplifyDemandedUseBits(Instruction *I, const APInt &DemandedMask, + KnownBits &Known, unsigned Depth, + const SimplifyQuery &Q); using InstCombiner::SimplifyDemandedBits; bool SimplifyDemandedBits(Instruction *I, unsigned Op, const APInt &DemandedMask, KnownBits &Known, diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 6cf2e71..b1d0378 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -91,8 +91,47 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { Use &U = I->getOperandUse(OpNo); - Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known, - Depth, Q); + Value *V = U.get(); + if (isa(V)) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Known.resetAll(); + if (DemandedMask.isZero()) { + // Not demanding any bits from V. + replaceUse(U, UndefValue::get(V->getType())); + return true; + } + + if (Depth == MaxAnalysisRecursionDepth) + return false; + + Instruction *VInst = dyn_cast(V); + if (!VInst) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Value *NewVal; + if (VInst->hasOneUse()) { + // If the instruction has one use, we can directly simplify it. + NewVal = SimplifyDemandedUseBits(VInst, DemandedMask, Known, Depth, Q); + } else if (Depth != 0) { + // If there are multiple uses of this instruction and we aren't at the root, + // then we can simplify VInst to some other value, but not modify the + // instruction. + NewVal = + SimplifyMultipleUseDemandedBits(VInst, DemandedMask, Known, Depth, Q); + } else { + // If this is the root being simplified, allow it to have multiple uses, + // just set the DemandedMask to all bits and reset the context instruction. + // This allows visitTruncInst (for example) to simplify the operand of a + // trunc without duplicating all the SimplifyDemandedUseBits() logic. + NewVal = + SimplifyDemandedUseBits(VInst, APInt::getAllOnes(Known.getBitWidth()), + Known, Depth, Q.getWithInstruction(VInst)); + } if (!NewVal) return false; if (Instruction* OpInst = dyn_cast(U)) salvageDebugInfo(*OpInst); @@ -124,50 +163,21 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, /// operands based on the information about what bits are demanded. This returns /// some other non-null value if it found out that V is equal to another value /// in the context where the specified bits are demanded, but not for all users. -Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, +Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, + const APInt &DemandedMask, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { - assert(V != nullptr && "Null pointer of Value???"); + assert(I != nullptr && "Null pointer of Value???"); assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth"); uint32_t BitWidth = DemandedMask.getBitWidth(); - Type *VTy = V->getType(); + Type *VTy = I->getType(); assert( (!VTy->isIntOrIntVectorTy() || VTy->getScalarSizeInBits() == BitWidth) && Known.getBitWidth() == BitWidth && "Value *V, DemandedMask and Known must have same BitWidth"); - if (isa(V)) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; - } - - Known.resetAll(); - if (DemandedMask.isZero()) // Not demanding any bits from V. - return UndefValue::get(VTy); - - if (Depth == MaxAnalysisRecursionDepth) - return nullptr; - - Instruction *I = dyn_cast(V); - if (!I) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; // Only analyze instructions. - } - - // If there are multiple uses of this value and we aren't at the root, then - // we can't do any simplifications of the operands, because DemandedMask - // only reflects the bits demanded by *one* of the users. - if (Depth != 0 && !I->hasOneUse()) - return SimplifyMultipleUseDemandedBits(I, DemandedMask, Known, Depth, Q); - KnownBits LHSKnown(BitWidth), RHSKnown(BitWidth); - // If this is the root being simplified, allow it to have multiple uses, - // just set the DemandedMask to all bits so that we can try to simplify the - // operands. This allows visitTruncInst (for example) to simplify the - // operand of a trunc without duplicating all the logic below. - if (Depth == 0 && !V->hasOneUse()) - DemandedMask.setAllBits(); // Update flags after simplifying an operand based on the fact that some high // order bits are not demanded. @@ -1105,13 +1115,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, } if (!KnownBitsComputed) - llvm::computeKnownBits(V, Known, Depth, Q); + llvm::computeKnownBits(I, Known, Depth, Q); break; } } - if (V->getType()->isPointerTy()) { - Align Alignment = V->getPointerAlignment(DL); + if (I->getType()->isPointerTy()) { + Align Alignment = I->getPointerAlignment(DL); Known.Zero.setLowBits(Log2(Alignment)); } @@ -1119,13 +1129,14 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // constant. We can't directly simplify pointers as a constant because of // pointer provenance. // TODO: We could return `(inttoptr const)` for pointers. - if (!V->getType()->isPointerTy() && DemandedMask.isSubsetOf(Known.Zero | Known.One)) + if (!I->getType()->isPointerTy() && + DemandedMask.isSubsetOf(Known.Zero | Known.One)) return Constant::getIntegerValue(VTy, Known.One); if (VerifyKnownBits) { - KnownBits ReferenceKnown = llvm::computeKnownBits(V, Depth, Q); + KnownBits ReferenceKnown = llvm::computeKnownBits(I, Depth, Q); if (Known != ReferenceKnown) { - errs() << "Mismatched known bits for " << *V << " in " + errs() << "Mismatched known bits for " << *I << " in " << I->getFunction()->getName() << "\n"; errs() << "computeKnownBits(): " << ReferenceKnown << "\n"; errs() << "SimplifyDemandedBits(): " << Known << "\n"; diff --git a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll index 79a1ec2..a03ff3e 100644 --- a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll +++ b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll @@ -15,8 +15,6 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 -; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 -; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll index 474da99..2ef7433 100644 --- a/llvm/test/Transforms/InstCombine/assume.ll +++ b/llvm/test/Transforms/InstCombine/assume.ll @@ -428,8 +428,6 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 -; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 -; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> diff --git a/llvm/test/Transforms/InstCombine/known-bits.ll b/llvm/test/Transforms/InstCombine/known-bits.ll index 8520981..c7445a6 100644 --- a/llvm/test/Transforms/InstCombine/known-bits.ll +++ b/llvm/test/Transforms/InstCombine/known-bits.ll @@ -2025,7 +2025,6 @@ define i8 @simplifydemanded_context(i8 %x, i8 %y) { ret i8 %and2 } -; FIXME: This is a miscompile. define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { ; CHECK-LABEL: @pr97330( ; CHECK-NEXT: entry: @@ -2033,7 +2032,9 @@ define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) { ; CHECK: if: ; CHECK-NEXT: unreachable ; CHECK: exit: -; CHECK-NEXT: ret i16 1 +; CHECK-NEXT: [[V:%.*]] = load i64, ptr [[P1:%.*]], align 8 +; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[V]] to i16 +; CHECK-NEXT: ret i16 [[CONV]] ; entry: %v = load i64, ptr %p1, align 8 -- cgit v1.1 From 05670b42f5b45710bfdba48dcb7e8c30c8c7478f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 2 Jul 2024 10:38:28 +0200 Subject: [InstCombine] Remove root special case in demanded bits simplification When calling SimplifyDemandedBits (as opposed to SimplifyDemandedInstructionBits), and there are multiple uses, always use SimplifyMultipleUseDemandedBits and drop the special case for root values. This fixes the ephemeral value detection, as seen by the restored assumes in tests. It may result in more or less simplification, depending on whether we get more out of having demanded bits or the ability to perform non-multi-use transforms. The change in the phi-known-bits.ll test is because the icmp operand now gets simplified based on demanded bits, which then prevents a different known bits simplification later. This also makes the code safe against future changes like https://github.com/llvm/llvm-project/pull/97289, which add more context that would have to be discarded for the multi-use case. --- clang/test/CodeGen/inline-asm-x86-flag-output.c | 4 +++- .../InstCombine/InstCombineSimplifyDemanded.cpp | 15 +++------------ llvm/test/Analysis/ValueTracking/phi-known-bits.ll | 7 +++++-- llvm/test/Transforms/InstCombine/assume-inseltpoison.ll | 2 ++ llvm/test/Transforms/InstCombine/assume.ll | 2 ++ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clang/test/CodeGen/inline-asm-x86-flag-output.c b/clang/test/CodeGen/inline-asm-x86-flag-output.c index 7ca6dc7a..243dc37 100644 --- a/clang/test/CodeGen/inline-asm-x86-flag-output.c +++ b/clang/test/CodeGen/inline-asm-x86-flag-output.c @@ -380,8 +380,10 @@ int test_assume_boolean_flag(long nr, volatile long *addr) { //CHECK: %0 = tail call { i32, i32 } asm "cmp $2,$1", "={@cca},={@ccae},=*m,r,~{cc},~{dirflag},~{fpsr},~{flags}"(ptr elementtype(i64) %addr, i64 %nr) //CHECK: [[RES1:%.*]] = extractvalue { i32, i32 } %0, 0 //CHECK: [[RES2:%.*]] = extractvalue { i32, i32 } %0, 1 - //CHECK: %1 = icmp ult i32 [[RES2]], 2 + //CHECK: %1 = icmp ult i32 [[RES1]], 2 //CHECK: tail call void @llvm.assume(i1 %1) + //CHECK: %2 = icmp ult i32 [[RES2]], 2 + //CHECK: tail call void @llvm.assume(i1 %2) int x,y; asm("cmp %2,%1" : "=@cca"(x), "=@ccae"(y), "=m"(*(volatile long *)(addr)) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index b1d0378..98f085a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -117,20 +117,11 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, if (VInst->hasOneUse()) { // If the instruction has one use, we can directly simplify it. NewVal = SimplifyDemandedUseBits(VInst, DemandedMask, Known, Depth, Q); - } else if (Depth != 0) { - // If there are multiple uses of this instruction and we aren't at the root, - // then we can simplify VInst to some other value, but not modify the - // instruction. - NewVal = - SimplifyMultipleUseDemandedBits(VInst, DemandedMask, Known, Depth, Q); } else { - // If this is the root being simplified, allow it to have multiple uses, - // just set the DemandedMask to all bits and reset the context instruction. - // This allows visitTruncInst (for example) to simplify the operand of a - // trunc without duplicating all the SimplifyDemandedUseBits() logic. + // If there are multiple uses of this instruction, then we can simplify + // VInst to some other value, but not modify the instruction. NewVal = - SimplifyDemandedUseBits(VInst, APInt::getAllOnes(Known.getBitWidth()), - Known, Depth, Q.getWithInstruction(VInst)); + SimplifyMultipleUseDemandedBits(VInst, DemandedMask, Known, Depth, Q); } if (!NewVal) return false; if (Instruction* OpInst = dyn_cast(U)) diff --git a/llvm/test/Analysis/ValueTracking/phi-known-bits.ll b/llvm/test/Analysis/ValueTracking/phi-known-bits.ll index 7b5e143..3728e41 100644 --- a/llvm/test/Analysis/ValueTracking/phi-known-bits.ll +++ b/llvm/test/Analysis/ValueTracking/phi-known-bits.ll @@ -375,10 +375,13 @@ F: define i8 @phi_ugt_high_bits_and_known(i8 %xx) { ; CHECK-LABEL: @phi_ugt_high_bits_and_known( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[XX:%.*]], -65 +; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 1 +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[XX]], -65 ; CHECK-NEXT: br i1 [[CMP]], label [[T:%.*]], label [[F:%.*]] ; CHECK: T: -; CHECK-NEXT: ret i8 65 +; CHECK-NEXT: [[V:%.*]] = phi i8 [ [[X]], [[ENTRY:%.*]] ], [ -1, [[F]] ] +; CHECK-NEXT: [[R:%.*]] = and i8 [[V]], 65 +; CHECK-NEXT: ret i8 [[R]] ; CHECK: F: ; CHECK-NEXT: br label [[T]] ; diff --git a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll index a03ff3e..79a1ec2 100644 --- a/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll +++ b/llvm/test/Transforms/InstCombine/assume-inseltpoison.ll @@ -15,6 +15,8 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 +; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 +; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> diff --git a/llvm/test/Transforms/InstCombine/assume.ll b/llvm/test/Transforms/InstCombine/assume.ll index 2ef7433..474da99 100644 --- a/llvm/test/Transforms/InstCombine/assume.ll +++ b/llvm/test/Transforms/InstCombine/assume.ll @@ -428,6 +428,8 @@ define i32 @PR40940(<4 x i8> %x) { ; CHECK-LABEL: @PR40940( ; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> poison, <4 x i32> ; CHECK-NEXT: [[T2:%.*]] = bitcast <4 x i8> [[SHUF]] to i32 +; CHECK-NEXT: [[T3:%.*]] = icmp ult i32 [[T2]], 65536 +; CHECK-NEXT: call void @llvm.assume(i1 [[T3]]) ; CHECK-NEXT: ret i32 [[T2]] ; %shuf = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> -- cgit v1.1 From 54811a9b1194d8239cc28c2a974228ffadf80100 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Tue, 2 Jul 2024 09:19:59 +0000 Subject: [lldb][test] Mark dwp foreign type units test unsupported on Windows This test has been flaky on Linaro's Windows on Arm bot: https://lab.llvm.org/buildbot/#/builders/141/builds/425 --- lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp index 4df1b33..ef15d41 100644 --- a/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp +++ b/lldb/test/Shell/SymbolFile/DWARF/x86/dwp-foreign-type-units.cpp @@ -1,4 +1,6 @@ // REQUIRES: lld +// Is flaky on Windows. +// UNSUPPORTED: system-windows // This test will make a type that will be compiled differently into two // different .dwo files in a type unit with the same type hash, but with -- cgit v1.1 From d7da0ae4f46cb8731910cc30251105c88aeae12c Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 2 Jul 2024 11:31:12 +0200 Subject: [MLIR][NVVM] Reduce the scope of the LLVM_HAS_NVPTX_TARGET guard (#97349) Most of the code here does not depend on the NVPTX target. In particular the simple offload can just emit LLVM IR and we can use this without the NVVM backend being built, which can be useful for a frontend that just need to serialize the IR and leave it up to the runtime to JIT further. --- mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp | 15 --------------- mlir/lib/Target/LLVM/NVVM/Target.cpp | 14 ++++++-------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp index 1e7596e..adae3be 100644 --- a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp @@ -38,25 +38,10 @@ class GpuModuleToBinaryPass : public impl::GpuModuleToBinaryPassBase { public: using Base::Base; - void getDependentDialects(DialectRegistry ®istry) const override; void runOnOperation() final; }; } // namespace -void GpuModuleToBinaryPass::getDependentDialects( - DialectRegistry ®istry) const { - // Register all GPU related translations. - registry.insert(); - registry.insert(); -#if LLVM_HAS_NVPTX_TARGET - registry.insert(); -#endif -#if MLIR_ENABLE_ROCM_CONVERSIONS - registry.insert(); -#endif - registry.insert(); -} - void GpuModuleToBinaryPass::runOnOperation() { RewritePatternSet patterns(&getContext()); auto targetFormat = diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp index acb903a..e608d26 100644 --- a/mlir/lib/Target/LLVM/NVVM/Target.cpp +++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp @@ -157,7 +157,6 @@ SerializeGPUModuleBase::loadBitcodeFiles(llvm::Module &module) { return std::move(bcFiles); } -#if LLVM_HAS_NVPTX_TARGET namespace { class NVPTXSerializer : public SerializeGPUModuleBase { public: @@ -532,6 +531,12 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) { if (targetOptions.getCompilationTarget() == gpu::CompilationTarget::Offload) return SerializeGPUModuleBase::moduleToObject(llvmModule); +#if !LLVM_HAS_NVPTX_TARGET + getOperation()->emitError( + "The `NVPTX` target was not built. Please enable it when building LLVM."); + return std::nullopt; +#endif // LLVM_HAS_NVPTX_TARGET + // Emit PTX code. std::optional targetMachine = getOrCreateTargetMachine(); @@ -569,7 +574,6 @@ NVPTXSerializer::moduleToObject(llvm::Module &llvmModule) { return compileToBinary(*serializedISA); #endif // MLIR_ENABLE_NVPTXCOMPILER } -#endif // LLVM_HAS_NVPTX_TARGET std::optional> NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module, @@ -581,15 +585,9 @@ NVVMTargetAttrImpl::serializeToObject(Attribute attribute, Operation *module, module->emitError("Module must be a GPU module."); return std::nullopt; } -#if LLVM_HAS_NVPTX_TARGET NVPTXSerializer serializer(*module, cast(attribute), options); serializer.init(); return serializer.run(); -#else - module->emitError( - "The `NVPTX` target was not built. Please enable it when building LLVM."); - return std::nullopt; -#endif // LLVM_HAS_NVPTX_TARGET } Attribute -- cgit v1.1 From 9ceb45cc191628926496bd33b4d52011ed519151 Mon Sep 17 00:00:00 2001 From: Lukacma Date: Tue, 2 Jul 2024 11:37:52 +0200 Subject: [AArch64][SVE] optimisation for unary SVE store intrinsics with no active lanes (#95793) This patch extends https://github.com/llvm/llvm-project/pull/73964 and adds optimisation of store SVE intrinsics when predicate is zero. --- .../Target/AArch64/AArch64TargetTransformInfo.cpp | 36 +++ .../sve-intrinsic-comb-no-active-lanes-stores.ll | 310 +++++++++++++++++++++ 2 files changed, 346 insertions(+) create mode 100644 llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-comb-no-active-lanes-stores.ll diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index c0abbd3..eb60b96 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -985,6 +985,16 @@ static bool isAllActivePredicate(Value *Pred) { m_ConstantInt())); } +// Erase unary operation where predicate has all inactive lanes +static std::optional +instCombineSVENoActiveUnaryErase(InstCombiner &IC, IntrinsicInst &II, + int PredPos) { + if (match(II.getOperand(PredPos), m_ZeroInt())) { + return IC.eraseInstFromFunction(II); + } + return std::nullopt; +} + // Simplify unary operation where predicate has all inactive lanes by replacing // instruction with zeroed object static std::optional @@ -2007,6 +2017,32 @@ AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC, default: break; + case Intrinsic::aarch64_sve_st1_scatter: + case Intrinsic::aarch64_sve_st1_scatter_scalar_offset: + case Intrinsic::aarch64_sve_st1_scatter_sxtw: + case Intrinsic::aarch64_sve_st1_scatter_sxtw_index: + case Intrinsic::aarch64_sve_st1_scatter_uxtw: + case Intrinsic::aarch64_sve_st1_scatter_uxtw_index: + case Intrinsic::aarch64_sve_st1dq: + case Intrinsic::aarch64_sve_st1q_scatter_index: + case Intrinsic::aarch64_sve_st1q_scatter_scalar_offset: + case Intrinsic::aarch64_sve_st1q_scatter_vector_offset: + case Intrinsic::aarch64_sve_st1wq: + case Intrinsic::aarch64_sve_stnt1: + case Intrinsic::aarch64_sve_stnt1_scatter: + case Intrinsic::aarch64_sve_stnt1_scatter_index: + case Intrinsic::aarch64_sve_stnt1_scatter_scalar_offset: + case Intrinsic::aarch64_sve_stnt1_scatter_uxtw: + return instCombineSVENoActiveUnaryErase(IC, II, 1); + case Intrinsic::aarch64_sve_st2: + case Intrinsic::aarch64_sve_st2q: + return instCombineSVENoActiveUnaryErase(IC, II, 2); + case Intrinsic::aarch64_sve_st3: + case Intrinsic::aarch64_sve_st3q: + return instCombineSVENoActiveUnaryErase(IC, II, 3); + case Intrinsic::aarch64_sve_st4: + case Intrinsic::aarch64_sve_st4q: + return instCombineSVENoActiveUnaryErase(IC, II, 4); case Intrinsic::aarch64_sve_ld1_gather: case Intrinsic::aarch64_sve_ld1_gather_scalar_offset: case Intrinsic::aarch64_sve_ld1_gather_sxtw: diff --git a/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-comb-no-active-lanes-stores.ll b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-comb-no-active-lanes-stores.ll new file mode 100644 index 0000000..5908dd1 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-comb-no-active-lanes-stores.ll @@ -0,0 +1,310 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +;RUN: opt -S -passes=instcombine < %s | FileCheck %s +target triple = "aarch64-unknown-linux-gnu" + +define void @test_st1(ptr %a, %b) { +; CHECK-LABEL: define void @test_st1( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1.nxv16i8( %b, zeroinitializer, ptr %a) + ret void +} + +define void @test_st1_scatter( %data_trunc, ptr %base, %b) { +; CHECK-LABEL: define void @test_st1_scatter( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1.scatter.nxv2i16( %data_trunc, + zeroinitializer, + ptr %base, + %b) + ret void +} + +define void @test_st1_scatter_index( %data_trunc, ptr %base, %offsets) { +; CHECK-LABEL: define void @test_st1_scatter_index( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[OFFSETS:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: call void @llvm.aarch64.sve.st1.scatter.index.nxv2i32( [[DATA_TRUNC]], zeroinitializer, ptr [[BASE]], [[OFFSETS]]) +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1.scatter.index.nxv2i32( %data_trunc, + zeroinitializer, + ptr %base, + %offsets) + ret void +} + +define void @test_st1_scatter_scalar_offset( %data_trunc, %base) { +; CHECK-LABEL: define void @test_st1_scatter_scalar_offset( +; CHECK-SAME: [[DATA_TRUNC:%.*]], [[BASE:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1.scatter.scalar.offset.nxv4i8.nxv4i32( %data_trunc, + zeroinitializer, + %base, + i64 16) + ret void +} + +define void @test_st1_scatter_sxtw( %data_trunc, ptr %base, %offsets) { +; CHECK-LABEL: define void @test_st1_scatter_sxtw( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[OFFSETS:%.*]]) { +; CHECK-NEXT: ret void +; + call void @llvm.aarch64.sve.st1.scatter.sxtw.nxv4i8( %data_trunc, + zeroinitializer, + ptr %base, + %offsets) + ret void +} + +define void @test_st1_scatter_sxtw_index( %data_trunc, ptr %base, %indices) { +; CHECK-LABEL: define void @test_st1_scatter_sxtw_index( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[INDICES:%.*]]) { +; CHECK-NEXT: ret void +; + call void @llvm.aarch64.sve.st1.scatter.sxtw.index.nxv4i16( %data_trunc, + zeroinitializer, + ptr %base, + %indices) + ret void +} + +define void @test_st1_scatter_uxtw( %data_trunc, ptr %base, %offsets) { +; CHECK-LABEL: define void @test_st1_scatter_uxtw( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[OFFSETS:%.*]]) { +; CHECK-NEXT: ret void +; + call void @llvm.aarch64.sve.st1.scatter.uxtw.nxv4i8( %data_trunc, + zeroinitializer, + ptr %base, + %offsets) + ret void +} + +define void @test_st1_scatter_uxtw_index( %data_trunc, ptr %base, %indices) { +; CHECK-LABEL: define void @test_st1_scatter_uxtw_index( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[INDICES:%.*]]) { +; CHECK-NEXT: ret void +; + call void @llvm.aarch64.sve.st1.scatter.uxtw.index.nxv4i16( %data_trunc, + zeroinitializer, + ptr %base, + %indices) + ret void +} + +define void @test_st1dq( %zt, ptr %gep1) { +; CHECK-LABEL: define void @test_st1dq( +; CHECK-SAME: [[ZT:%.*]], ptr [[GEP1:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1dq.nxv2i64( %zt, zeroinitializer, ptr %gep1) + ret void +} + +define void @test_st1q_scatter_index( %data, %pg, ptr %base, %idx) { +; CHECK-LABEL: define void @test_st1q_scatter_index( +; CHECK-SAME: [[DATA:%.*]], [[PG:%.*]], ptr [[BASE:%.*]], [[IDX:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1q.scatter.index.nxv8i16( %data, zeroinitializer, ptr %base, %idx) + ret void +} + +define void @test_st1q_scatter_scalar_offset( %data, %base) { +; CHECK-LABEL: define void @test_st1q_scatter_scalar_offset( +; CHECK-SAME: [[DATA:%.*]], [[BASE:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1q.scatter.scalar.offset.nxv2i64.nxv2i64( %data, zeroinitializer, %base, i64 0) + ret void +} + +define void @test_st1q_scatter_vector_offset( %data, ptr %base, %off) { +; CHECK-LABEL: define void @test_st1q_scatter_vector_offset( +; CHECK-SAME: [[DATA:%.*]], ptr [[BASE:%.*]], [[OFF:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1q.scatter.vector.offset.nxv8i16( %data, zeroinitializer, ptr %base, %off) + ret void +} + +define void @test_st1wq(ptr %a, %b) { +; CHECK-LABEL: define void @test_st1wq( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.st1wq.nxv4i32( %b, zeroinitializer, ptr %a) + ret void +} + + +define void @test_st2(ptr %a, %b) { +; CHECK-LABEL: define void @test_st2( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + %0 = tail call @llvm.vector.extract.nxv4i32.nxv8i32( %b, i64 0) + %1 = tail call @llvm.vector.extract.nxv4i32.nxv8i32( %b, i64 4) + tail call void @llvm.aarch64.sve.st2.nxv4i32( %0, %1, zeroinitializer, ptr %a) + ret void +} + +define void @test_st2q(ptr %a, %b) { +; CHECK-LABEL: define void @test_st2q( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + %0 = tail call @llvm.vector.extract.nxv4i32.nxv8i32( %b, i64 0) + %1 = tail call @llvm.vector.extract.nxv4i32.nxv8i32( %b, i64 4) + tail call void @llvm.aarch64.sve.st2q.nxv4i32( %0, %1, zeroinitializer, ptr %a) + ret void +} + +define void @test_st3(ptr %a, %b) { +; CHECK-LABEL: define void @test_st3( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + %0 = tail call @llvm.vector.extract.nxv4i32.nxv12i32( %b, i64 0) + %1 = tail call @llvm.vector.extract.nxv4i32.nxv12i32( %b, i64 4) + %2 = tail call @llvm.vector.extract.nxv4i32.nxv12i32( %b, i64 8) + tail call void @llvm.aarch64.sve.st3.nxv4i32( %0, %1, %2, zeroinitializer, ptr %a) + ret void +} + +define void @test_st3q(ptr %a, %b) { +; CHECK-LABEL: define void @test_st3q( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + %0 = tail call @llvm.vector.extract.nxv4i32.nxv12i32( %b, i64 0) + %1 = tail call @llvm.vector.extract.nxv4i32.nxv12i32( %b, i64 4) + %2 = tail call @llvm.vector.extract.nxv4i32.nxv12i32( %b, i64 8) + tail call void @llvm.aarch64.sve.st3q.nxv4i32( %0, %1, %2, zeroinitializer, ptr %a) + ret void +} + +define void @test_st4(ptr %a, %b) { +; CHECK-LABEL: define void @test_st4( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + %0 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 0) + %1 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 4) + %2 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 8) + %3 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 12) + tail call void @llvm.aarch64.sve.st4.nxv4i32( %0, %1, %2, %3, zeroinitializer, ptr %a) + ret void +} + +define void @test_st4q(ptr %a, %b) { +; CHECK-LABEL: define void @test_st4q( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + %0 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 0) + %1 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 4) + %2 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 8) + %3 = tail call @llvm.vector.extract.nxv4i32.nxv16i32( %b, i64 12) + tail call void @llvm.aarch64.sve.st4q.nxv4i32( %0, %1, %2, %3, zeroinitializer, ptr %a) + ret void +} + +define void @test_stnt1(ptr %a, %b) { +; CHECK-LABEL: define void @test_stnt1( +; CHECK-SAME: ptr [[A:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.stnt1.nxv16i8( %b, zeroinitializer, ptr %a) + ret void +} + +define void @test_stnt1_scatter( %data_trunc, ptr %base, %b) { +; CHECK-LABEL: define void @test_stnt1_scatter( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[B:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.stnt1.scatter.nxv2i16( %data_trunc, + zeroinitializer, + ptr %base, + %b) + ret void +} + +define void @test_stnt1_scatter_index( %data_trunc, ptr %base, %offsets) { +; CHECK-LABEL: define void @test_stnt1_scatter_index( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[OFFSETS:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.stnt1.scatter.index.nxv2i32( %data_trunc, + zeroinitializer, + ptr %base, + %offsets) + ret void +} + +define void @test_stnt1_scatter_scalar_offset( %data_trunc, %base) { +; CHECK-LABEL: define void @test_stnt1_scatter_scalar_offset( +; CHECK-SAME: [[DATA_TRUNC:%.*]], [[BASE:%.*]]) { +; CHECK-NEXT: [[ENTRY:.*:]] +; CHECK-NEXT: ret void +; +entry: + call void @llvm.aarch64.sve.stnt1.scatter.scalar.offset.nxv4i8.nxv4i32( %data_trunc, + zeroinitializer, + %base, + i64 16) + ret void +} + +define void @test_stnt1_scatter_uxtw( %data_trunc, ptr %base, %offsets) { +; CHECK-LABEL: define void @test_stnt1_scatter_uxtw( +; CHECK-SAME: [[DATA_TRUNC:%.*]], ptr [[BASE:%.*]], [[OFFSETS:%.*]]) { +; CHECK-NEXT: ret void +; + call void @llvm.aarch64.sve.stnt1.scatter.uxtw.nxv4i8( %data_trunc, + zeroinitializer, + ptr %base, + %offsets) + ret void +} -- cgit v1.1 From 01134e69d29370ee9dbd7d281abaa27063f21396 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Tue, 2 Jul 2024 10:38:24 +0100 Subject: Presburger/test: increase coverage of parser (#95705) In preparation to write a free-standing parser for Presburger, improve the test coverage of the existing parser. --- mlir/unittests/Analysis/Presburger/ParserTest.cpp | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/mlir/unittests/Analysis/Presburger/ParserTest.cpp b/mlir/unittests/Analysis/Presburger/ParserTest.cpp index 4c9f54f..06b728c 100644 --- a/mlir/unittests/Analysis/Presburger/ParserTest.cpp +++ b/mlir/unittests/Analysis/Presburger/ParserTest.cpp @@ -45,6 +45,18 @@ static bool parseAndCompare(StringRef str, const IntegerPolyhedron &ex) { } TEST(ParseFACTest, ParseAndCompareTest) { + // constant-fold addition + EXPECT_TRUE(parseAndCompare("() : (4 + 3 >= 0)", + makeFACFromConstraints(0, 0, {}, {}))); + + // constant-fold addition + multiplication + EXPECT_TRUE(parseAndCompare("()[a] : (4 * 3 == 10 + 2)", + makeFACFromConstraints(0, 1, {}, {}))); + + // constant-fold ceildiv + floordiv + EXPECT_TRUE(parseAndCompare("(x) : (11 ceildiv 3 == 13 floordiv 3)", + makeFACFromConstraints(1, 0, {}, {}))); + // simple ineq EXPECT_TRUE(parseAndCompare("(x)[] : (x >= 0)", makeFACFromConstraints(1, 0, {{1, 0}}))); @@ -57,6 +69,11 @@ TEST(ParseFACTest, ParseAndCompareTest) { EXPECT_TRUE(parseAndCompare("(x)[] : (7 * x >= 0, -7 * x + 5 >= 0)", makeFACFromConstraints(1, 0, {{7, 0}, {-7, 5}}))); + // multiplication distribution + EXPECT_TRUE( + parseAndCompare("(x) : (2 * x >= 2, (-7 + x * 9) * 5 >= 0)", + makeFACFromConstraints(1, 0, {{2, -2}, {45, -35}}))); + // multiple dimensions EXPECT_TRUE(parseAndCompare("(x,y,z)[] : (x + y - z >= 0)", makeFACFromConstraints(3, 0, {{1, 1, -1, 0}}))); @@ -70,20 +87,61 @@ TEST(ParseFACTest, ParseAndCompareTest) { EXPECT_TRUE(parseAndCompare("()[a] : (2 * a - 4 == 0)", makeFACFromConstraints(0, 1, {}, {{2, -4}}))); + // no linear terms + EXPECT_TRUE(parseAndCompare( + "(x, y) : (26 * (x floordiv 6) == y floordiv 3)", + makeFACFromConstraints(2, 0, {}, {{0, 0, 26, -1, 0}}, + {{{1, 0, 0}, 6}, {{0, 1, 0, 0}, 3}}))); + // simple floordiv EXPECT_TRUE(parseAndCompare( "(x, y) : (y - 3 * ((x + y - 13) floordiv 3) - 42 == 0)", makeFACFromConstraints(2, 0, {}, {{0, 1, -3, -42}}, {{{1, 1, -13}, 3}}))); + // simple ceildiv + EXPECT_TRUE(parseAndCompare( + "(x, y) : (y - 3 * ((x + y - 13) ceildiv 3) - 42 == 0)", + makeFACFromConstraints(2, 0, {}, {{0, 1, -3, -42}}, {{{1, 1, -11}, 3}}))); + + // simple mod + EXPECT_TRUE(parseAndCompare( + "(x, y) : (y - 3 * ((x + y - 13) mod 3) - 42 == 0)", + makeFACFromConstraints(2, 0, {}, {{-3, -2, 9, -3}}, {{{1, 1, -13}, 3}}))); + // multiple floordiv EXPECT_TRUE(parseAndCompare( "(x, y) : (y - x floordiv 3 - y floordiv 2 == 0)", makeFACFromConstraints(2, 0, {}, {{0, 1, -1, -1, 0}}, {{{1, 0, 0}, 3}, {{0, 1, 0, 0}, 2}}))); + // multiple ceildiv + EXPECT_TRUE(parseAndCompare( + "(x, y) : (y - x ceildiv 3 - y ceildiv 2 == 0)", + makeFACFromConstraints(2, 0, {}, {{0, 1, -1, -1, 0}}, + {{{1, 0, 2}, 3}, {{0, 1, 0, 1}, 2}}))); + + // multiple mod + EXPECT_TRUE(parseAndCompare( + "(x, y) : (y - x mod 3 - y mod 2 == 0)", + makeFACFromConstraints(2, 0, {}, {{-1, 0, 3, 2, 0}}, + {{{1, 0, 0}, 3}, {{0, 1, 0, 0}, 2}}))); + // nested floordiv EXPECT_TRUE(parseAndCompare( "(x, y) : (y - (x + y floordiv 2) floordiv 3 == 0)", makeFACFromConstraints(2, 0, {}, {{0, 1, 0, -1, 0}}, {{{0, 1, 0}, 2}, {{1, 0, 1, 0}, 3}}))); + + // nested mod + EXPECT_TRUE(parseAndCompare( + "(x, y) : (y - (x + y mod 2) mod 3 == 0)", + makeFACFromConstraints(2, 0, {}, {{-1, 0, 2, 3, 0}}, + {{{0, 1, 0}, 2}, {{1, 1, -2, 0}, 3}}))); + + // nested floordiv + ceildiv + mod + EXPECT_TRUE(parseAndCompare( + "(x, y) : ((2 * x + 3 * (y floordiv 2) + x mod 7 + 1) ceildiv 3 == 42)", + makeFACFromConstraints( + 2, 0, {}, {{0, 0, 0, 0, 1, -42}}, + {{{0, 1, 0}, 2}, {{1, 0, 0, 0}, 7}, {{3, 0, 3, -7, 3}, 3}}))); } -- cgit v1.1 From db791b278a414fb6df1acc1799adcf11d8fb9169 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Tue, 2 Jul 2024 10:42:33 +0100 Subject: mlir/LogicalResult: move into llvm (#97309) This patch is part of a project to move the Presburger library into LLVM. --- .../flang/Optimizer/CodeGen/FIROpPatterns.h | 12 +- .../flang/Optimizer/CodeGen/TypeConverter.h | 2 +- .../Optimizer/Dialect/FirAliasTagOpInterface.h | 4 +- .../Optimizer/Dialect/FortranVariableInterface.td | 2 +- .../flang/Optimizer/Dialect/Support/KindMapping.h | 2 +- flang/include/flang/Optimizer/HLFIR/HLFIROps.td | 8 +- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 138 ++++++++++----------- flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp | 2 +- flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp | 14 +-- flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 2 +- flang/lib/Optimizer/CodeGen/TypeConverter.cpp | 2 +- flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp | 14 +-- flang/lib/Optimizer/Dialect/FIROps.cpp | 86 ++++++------- flang/lib/Optimizer/Dialect/FIRType.cpp | 22 ++-- .../Optimizer/Dialect/FirAliasTagOpInterface.cpp | 6 +- .../Optimizer/Dialect/FortranVariableInterface.cpp | 2 +- .../lib/Optimizer/Dialect/Support/KindMapping.cpp | 4 +- flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp | 84 ++++++------- .../Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp | 27 ++-- .../Optimizer/HLFIR/Transforms/ConvertToFIR.cpp | 18 +-- .../HLFIR/Transforms/InlineElementals.cpp | 2 +- .../HLFIR/Transforms/LowerHLFIRIntrinsics.cpp | 13 +- .../Transforms/LowerHLFIROrderedAssignments.cpp | 8 +- .../HLFIR/Transforms/OptimizedBufferization.cpp | 16 +-- .../HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp | 2 +- flang/lib/Optimizer/Transforms/AbstractResult.cpp | 10 +- flang/lib/Optimizer/Transforms/AffineDemotion.cpp | 4 +- flang/lib/Optimizer/Transforms/AffinePromotion.cpp | 4 +- flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp | 14 +-- .../Transforms/AssumedRankOpConversion.cpp | 4 +- .../Optimizer/Transforms/CharacterConversion.cpp | 2 +- .../Transforms/ConstantArgumentGlobalisation.cpp | 2 +- .../Optimizer/Transforms/ControlFlowConverter.cpp | 6 +- .../lib/Optimizer/Transforms/MemoryAllocation.cpp | 2 +- .../Transforms/PolymorphicOpConversion.cpp | 14 +-- flang/lib/Optimizer/Transforms/StackArrays.cpp | 9 +- flang/tools/bbc/bbc.cpp | 4 +- flang/tools/tco/tco.cpp | 2 +- llvm/include/llvm/Support/LogicalResult.h | 128 +++++++++++++++++++ mlir/docs/PDLL.md | 14 +-- mlir/docs/Tutorials/Toy/Ch-2.md | 6 +- mlir/docs/Tutorials/Toy/Ch-3.md | 6 +- mlir/docs/Tutorials/Toy/Ch-5.md | 2 +- .../standalone/lib/Standalone/StandalonePasses.cpp | 1 - .../standalone-translate/standalone-translate.cpp | 3 +- mlir/examples/toy/Ch2/mlir/Dialect.cpp | 7 +- mlir/examples/toy/Ch2/mlir/MLIRGen.cpp | 9 +- mlir/examples/toy/Ch3/mlir/Dialect.cpp | 7 +- mlir/examples/toy/Ch3/mlir/MLIRGen.cpp | 9 +- mlir/examples/toy/Ch3/mlir/ToyCombine.cpp | 3 +- mlir/examples/toy/Ch3/toyc.cpp | 1 - mlir/examples/toy/Ch4/mlir/Dialect.cpp | 7 +- mlir/examples/toy/Ch4/mlir/MLIRGen.cpp | 9 +- mlir/examples/toy/Ch4/mlir/ToyCombine.cpp | 3 +- mlir/examples/toy/Ch4/toyc.cpp | 1 - mlir/examples/toy/Ch5/mlir/Dialect.cpp | 7 +- mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp | 1 - mlir/examples/toy/Ch5/mlir/MLIRGen.cpp | 9 +- mlir/examples/toy/Ch5/mlir/ToyCombine.cpp | 3 +- mlir/examples/toy/Ch5/toyc.cpp | 1 - mlir/examples/toy/Ch6/mlir/Dialect.cpp | 7 +- mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp | 1 - mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp | 1 - mlir/examples/toy/Ch6/mlir/MLIRGen.cpp | 9 +- mlir/examples/toy/Ch6/mlir/ToyCombine.cpp | 3 +- mlir/examples/toy/Ch6/toyc.cpp | 1 - mlir/examples/toy/Ch7/mlir/Dialect.cpp | 13 +- mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp | 1 - mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp | 1 - mlir/examples/toy/Ch7/mlir/MLIRGen.cpp | 11 +- mlir/examples/toy/Ch7/mlir/ToyCombine.cpp | 3 +- mlir/examples/toy/Ch7/toyc.cpp | 1 - mlir/examples/transform-opt/mlir-transform-opt.cpp | 10 +- mlir/examples/transform/Ch4/lib/MyExtension.cpp | 2 +- .../mlir/Analysis/FlatLinearValueConstraints.h | 1 - .../include/mlir/Bytecode/BytecodeImplementation.h | 1 - mlir/include/mlir/Bytecode/BytecodeOpInterface.h | 1 - mlir/include/mlir/Bytecode/BytecodeReader.h | 1 - mlir/include/mlir/Bytecode/BytecodeReaderConfig.h | 1 - mlir/include/mlir/CAPI/Support.h | 6 +- .../Conversion/AffineToStandard/AffineToStandard.h | 1 - .../Conversion/ConvertToLLVM/ToLLVMInterface.h | 1 - .../mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h | 1 - .../mlir/Conversion/GPUCommon/GPUCommonPass.h | 1 - mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h | 1 - .../mlir/Conversion/VectorToGPU/VectorToGPU.h | 1 - mlir/include/mlir/Debug/CLOptionsSetup.h | 1 - mlir/include/mlir/Dialect/AMDGPU/Utils/Chipset.h | 2 +- .../Dialect/Affine/Analysis/AffineStructures.h | 1 - .../Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h | 2 +- mlir/include/mlir/Dialect/Affine/LoopUtils.h | 1 - .../mlir/Dialect/Affine/Transforms/Transforms.h | 1 - mlir/include/mlir/Dialect/Affine/Utils.h | 2 - .../mlir/Dialect/Arith/Transforms/Transforms.h | 1 - .../Bufferization/IR/BufferizableOpInterface.td | 8 +- .../Transforms/OneShotModuleBufferize.h | 19 +-- .../Dialect/GPU/IR/CompilationAttrInterfaces.td | 4 +- .../Dialect/GPU/Transforms/ParallelLoopMapper.h | 1 - mlir/include/mlir/Dialect/GPU/Transforms/Utils.h | 1 - mlir/include/mlir/Dialect/IRDL/IR/IRDLInterfaces.h | 1 - mlir/include/mlir/Dialect/IRDL/IR/IRDLTraits.h | 1 - mlir/include/mlir/Dialect/IRDL/IRDLLoading.h | 7 +- mlir/include/mlir/Dialect/IRDL/IRDLVerifiers.h | 1 - .../Dialect/Linalg/TransformOps/GPUHeuristics.h | 1 - .../mlir/Dialect/Linalg/TransformOps/Syntax.h | 1 - .../mlir/Dialect/Linalg/Transforms/Transforms.h | 1 - .../mlir/Dialect/MemRef/Transforms/Transforms.h | 2 +- .../mlir/Dialect/Mesh/Transforms/Spmdization.h | 1 - .../mlir/Dialect/NVGPU/Transforms/Transforms.h | 3 +- .../OpenACCMPCommon/Interfaces/AtomicInterfaces.td | 24 ++-- .../mlir/Dialect/Polynomial/IR/Polynomial.h | 1 - .../mlir/Dialect/SCF/Transforms/Transforms.h | 2 - .../SCF/Utils/AffineCanonicalizationUtils.h | 2 - mlir/include/mlir/Dialect/SCF/Utils/Utils.h | 1 - .../SparseTensor/IR/SparseTensorInterfaces.td | 2 +- .../Transform/Interfaces/TransformInterfaces.h | 3 +- .../Transform/Interfaces/TransformInterfaces.td | 2 +- .../Transforms/TransformInterpreterUtils.h | 1 - .../Vector/Transforms/VectorRewritePatterns.h | 1 - mlir/include/mlir/ExecutionEngine/JitRunner.h | 6 +- mlir/include/mlir/IR/Action.h | 1 - mlir/include/mlir/IR/AffineExpr.h | 1 - mlir/include/mlir/IR/AffineExprVisitor.h | 2 +- mlir/include/mlir/IR/AffineMap.h | 1 - mlir/include/mlir/IR/BuiltinAttributeInterfaces.h | 1 - mlir/include/mlir/IR/BuiltinAttributeInterfaces.td | 2 +- mlir/include/mlir/IR/Diagnostics.h | 1 - mlir/include/mlir/IR/Dialect.h | 3 - mlir/include/mlir/IR/EnumAttr.td | 4 +- mlir/include/mlir/IR/ExtensibleDialect.h | 1 - mlir/include/mlir/IR/OperationSupport.h | 1 - mlir/include/mlir/IR/StorageUniquerSupport.h | 1 - mlir/include/mlir/IR/SymbolInterfaces.td | 4 +- mlir/include/mlir/IR/TensorEncoding.td | 2 +- mlir/include/mlir/IR/Verifier.h | 3 +- mlir/include/mlir/IR/Visitors.h | 1 - .../mlir/Interfaces/DataLayoutInterfaces.td | 10 +- mlir/include/mlir/Interfaces/FoldInterfaces.h | 1 - mlir/include/mlir/Interfaces/FunctionInterfaces.td | 4 +- .../mlir/Interfaces/InferTypeOpInterface.td | 20 +-- mlir/include/mlir/Interfaces/LoopLikeInterface.td | 2 +- .../mlir/Interfaces/MemorySlotInterfaces.td | 6 +- mlir/include/mlir/Interfaces/TilingInterface.td | 20 +-- mlir/include/mlir/Pass/Pass.h | 1 - mlir/include/mlir/Pass/PassManager.h | 1 - mlir/include/mlir/Pass/PassOptions.h | 1 - mlir/include/mlir/Query/Query.h | 13 +- mlir/include/mlir/Reducer/ReductionNode.h | 1 - mlir/include/mlir/Support/LLVM.h | 14 ++- mlir/include/mlir/Support/LogicalResult.h | 127 ++----------------- mlir/include/mlir/Support/StorageUniquer.h | 1 - mlir/include/mlir/Support/ToolUtilities.h | 2 - mlir/include/mlir/Target/Cpp/CppEmitter.h | 1 - mlir/include/mlir/Target/LLVM/ROCDL/Utils.h | 1 + .../mlir/Target/LLVMIR/LLVMImportInterface.h | 1 - .../mlir/Target/LLVMIR/LLVMTranslationInterface.h | 1 - mlir/include/mlir/Target/SPIRV/Serialization.h | 1 - mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h | 1 - mlir/include/mlir/Tools/PDLL/CodeGen/MLIRGen.h | 2 - mlir/include/mlir/Tools/PDLL/Parser/Parser.h | 2 +- .../Tools/lsp-server-support/CompilationDatabase.h | 1 + .../mlir/Tools/lsp-server-support/Protocol.h | 3 - .../mlir/Tools/lsp-server-support/Transport.h | 1 - .../mlir/Tools/mlir-lsp-server/MlirLspServerMain.h | 9 +- mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h | 1 - .../mlir-pdll-lsp-server/MlirPdllLspServerMain.h | 6 +- mlir/include/mlir/Tools/mlir-query/MlirQueryMain.h | 2 +- .../mlir/Tools/mlir-reduce/MlirReduceMain.h | 2 +- .../mlir/Tools/mlir-translate/MlirTranslateMain.h | 2 +- .../tblgen-lsp-server/TableGenLspServerMain.h | 7 +- .../mlir/Transforms/HomomorphismSimplification.h | 1 - mlir/include/mlir/Transforms/Inliner.h | 1 - mlir/include/mlir/Transforms/LocationSnapshot.h | 1 - mlir/include/mlir/Transforms/SROA.h | 2 +- .../Analysis/AliasAnalysis/LocalAliasAnalysis.cpp | 1 - .../DataFlow/ConstantPropagationAnalysis.cpp | 1 - mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp | 1 - mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp | 1 - mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 1 - mlir/lib/Analysis/DataFlowFramework.cpp | 1 - mlir/lib/Analysis/FlatLinearValueConstraints.cpp | 1 - mlir/lib/AsmParser/AffineParser.cpp | 1 - mlir/lib/AsmParser/AsmParserState.cpp | 1 - mlir/lib/AsmParser/DialectSymbolParser.cpp | 1 - mlir/lib/AsmParser/LocationParser.cpp | 1 - mlir/lib/AsmParser/Parser.cpp | 1 - mlir/lib/AsmParser/TypeParser.cpp | 1 - mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 1 - mlir/lib/Bytecode/Writer/BytecodeWriter.cpp | 1 - mlir/lib/CAPI/IR/BuiltinTypes.cpp | 1 - .../lib/Conversion/ArithToAMDGPU/ArithToAMDGPU.cpp | 1 - mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp | 1 - .../BufferizationToMemRef.cpp | 1 - .../ControlFlowToSPIRV/ControlFlowToSPIRV.cpp | 1 - mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp | 1 - mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRV.cpp | 1 - mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp | 1 - .../lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp | 1 - mlir/lib/Conversion/NVVMToLLVM/NVVMToLLVM.cpp | 1 - mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp | 1 - .../Conversion/TensorToLinalg/TensorToLinalg.cpp | 1 - .../lib/Conversion/TensorToSPIRV/TensorToSPIRV.cpp | 1 - mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp | 1 - .../lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp | 1 - .../Affine/Transforms/AffineScalarReplacement.cpp | 1 - mlir/lib/Dialect/Arith/IR/ArithOps.cpp | 1 - .../Dialect/Arith/Transforms/EmulateNarrowType.cpp | 1 - .../Dialect/Arith/Transforms/EmulateWideInt.cpp | 1 - mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp | 1 - .../Transforms/LowerContractionToSMMLAPattern.cpp | 1 - .../Transforms/LowerDeallocations.cpp | 1 - mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 1 - .../GPU/Transforms/SubgroupReduceLowering.cpp | 1 - mlir/lib/Dialect/IRDL/IR/IRDL.cpp | 1 - mlir/lib/Dialect/IRDL/IRDLLoading.cpp | 1 - mlir/lib/Dialect/IRDL/IRDLVerifiers.cpp | 1 - .../Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp | 1 - mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp | 1 - .../Transforms/MeshShardingInterfaceImpl.cpp | 1 - .../Dialect/Linalg/Transforms/TransposeConv2D.cpp | 1 - mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp | 1 - .../MemRef/Transforms/EmulateNarrowType.cpp | 1 - mlir/lib/Dialect/Mesh/IR/MeshOps.cpp | 1 - .../Dialect/Mesh/Interfaces/ShardingInterface.cpp | 1 - .../Mesh/Transforms/ShardingPropagation.cpp | 1 - .../Dialect/Mesh/Transforms/Simplifications.cpp | 1 - mlir/lib/Dialect/Mesh/Transforms/Spmdization.cpp | 1 - .../NVGPU/Transforms/MmaSyncTF32Transform.cpp | 1 - .../NVGPU/Transforms/OptimizeSharedMemory.cpp | 3 +- mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp | 1 - mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp | 1 - .../Dialect/Polynomial/IR/PolynomialAttributes.cpp | 1 - .../Dialect/Polynomial/IR/PolynomialDialect.cpp | 1 - mlir/lib/Dialect/Polynomial/IR/PolynomialOps.cpp | 1 - mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp | 1 - mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp | 1 - .../SPIRV/Transforms/SPIRVWebGPUTransforms.cpp | 1 - mlir/lib/Dialect/Tosa/IR/TosaOps.cpp | 2 +- mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp | 1 - .../Transform/Interfaces/TransformInterfaces.cpp | 1 - .../Vector/Transforms/LowerVectorBitCast.cpp | 1 - .../Vector/Transforms/LowerVectorBroadcast.cpp | 1 - .../Vector/Transforms/LowerVectorContract.cpp | 1 - .../Vector/Transforms/LowerVectorGather.cpp | 1 - .../Vector/Transforms/LowerVectorInterleave.cpp | 1 - .../Dialect/Vector/Transforms/LowerVectorScan.cpp | 1 - .../Vector/Transforms/LowerVectorShapeCast.cpp | 1 - .../Vector/Transforms/LowerVectorTranspose.cpp | 1 - .../Dialect/Vector/Transforms/VectorLinearize.cpp | 1 - .../Dialect/Vector/Transforms/VectorTransforms.cpp | 1 - mlir/lib/IR/AffineMap.cpp | 1 - mlir/lib/IR/ExtensibleDialect.cpp | 1 - mlir/lib/Query/Query.cpp | 16 +-- mlir/lib/Support/ToolUtilities.cpp | 1 - mlir/lib/TableGen/CodeGenHelpers.cpp | 12 +- .../Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp | 4 +- .../Dialect/NVVM/NVVMToLLVMIRTranslation.cpp | 1 - .../Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 1 - mlir/lib/Target/LLVMIR/ModuleTranslation.cpp | 1 - .../Target/SPIRV/Deserialization/Deserializer.cpp | 1 - .../Target/SPIRV/Serialization/SerializeOps.cpp | 1 - mlir/lib/Target/SPIRV/Serialization/Serializer.cpp | 1 - mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp | 2 +- mlir/lib/Tools/PDLL/Parser/Lexer.cpp | 1 - mlir/lib/Tools/PDLL/Parser/Lexer.h | 2 - mlir/lib/Tools/PDLL/Parser/Parser.cpp | 1 - mlir/lib/Tools/lsp-server-support/Protocol.cpp | 1 - mlir/lib/Tools/mlir-lsp-server/LSPServer.h | 7 +- mlir/lib/Tools/mlir-opt/MlirOptMain.cpp | 1 - mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h | 7 +- mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h | 3 +- mlir/lib/Tools/mlir-query/MlirQueryMain.cpp | 3 +- mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp | 1 - .../lib/Tools/mlir-translate/MlirTranslateMain.cpp | 1 - mlir/lib/Tools/tblgen-lsp-server/LSPServer.h | 8 +- .../lib/Tools/tblgen-lsp-server/TableGenServer.cpp | 4 - mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h | 3 +- .../lib/Analysis/DataFlow/TestLivenessAnalysis.cpp | 1 - .../lib/Dialect/ArmNeon/TestLowerToArmNeon.cpp | 1 - mlir/test/lib/Dialect/Mesh/TestOpLowering.cpp | 1 - .../lib/Dialect/Mesh/TestReshardingSpmdization.cpp | 1 - mlir/test/lib/Dialect/Test/TestAttributes.cpp | 1 - mlir/test/lib/Dialect/Test/TestDialect.cpp | 1 - mlir/test/lib/Dialect/Test/TestOpDefs.cpp | 2 +- mlir/test/lib/Dialect/Test/TestOps.h | 10 +- mlir/test/lib/Dialect/Test/TestOps.td | 12 +- mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp | 2 +- mlir/test/lib/Dialect/Test/TestOpsSyntax.td | 8 +- mlir/test/lib/Dialect/Test/TestTypeDefs.td | 2 +- mlir/test/lib/Dialect/Test/TestTypes.h | 4 +- mlir/test/mlir-pdll/CodeGen/CPP/general.pdll | 2 +- mlir/test/mlir-tblgen/attrdefs.td | 2 +- mlir/test/mlir-tblgen/constraint-unique.td | 18 +-- mlir/test/mlir-tblgen/interfaces-as-constraints.td | 8 +- mlir/test/mlir-tblgen/op-attribute.td | 4 +- mlir/test/mlir-tblgen/op-decl-and-defs.td | 10 +- mlir/test/mlir-tblgen/predicate.td | 6 +- mlir/test/mlir-tblgen/rewriter-static-matcher.td | 6 +- mlir/test/mlir-tblgen/typedefs.td | 2 +- mlir/test/python/python_test_ops.td | 6 +- .../mlir-pdll-lsp-server/mlir-pdll-lsp-server.cpp | 2 +- mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp | 2 +- mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp | 6 +- mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp | 1 - mlir/tools/mlir-tblgen/DialectGen.cpp | 6 +- mlir/tools/mlir-tblgen/FormatGen.h | 1 - mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp | 1 - mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 22 ++-- mlir/tools/mlir-tblgen/OpFormatGen.cpp | 2 +- mlir/tools/mlir-tblgen/OpInterfacesGen.cpp | 2 +- mlir/tools/mlir-tblgen/RewriterGen.cpp | 4 +- mlir/tools/mlir-translate/mlir-translate.cpp | 2 +- mlir/tools/mlir-vulkan-runner/VulkanRuntime.h | 2 +- mlir/tools/tblgen-lsp-server/tblgen-lsp-server.cpp | 2 +- mlir/unittests/Rewrite/PatternBenefit.cpp | 4 +- 315 files changed, 737 insertions(+), 894 deletions(-) create mode 100644 llvm/include/llvm/Support/LogicalResult.h diff --git a/flang/include/flang/Optimizer/CodeGen/FIROpPatterns.h b/flang/include/flang/Optimizer/CodeGen/FIROpPatterns.h index ac09566..91b20251 100644 --- a/flang/include/flang/Optimizer/CodeGen/FIROpPatterns.h +++ b/flang/include/flang/Optimizer/CodeGen/FIROpPatterns.h @@ -205,10 +205,10 @@ public: rewrite(mlir::cast(op), OpAdaptor(operands, mlir::cast(op)), rewriter); } - mlir::LogicalResult match(mlir::Operation *op) const final { + llvm::LogicalResult match(mlir::Operation *op) const final { return match(mlir::cast(op)); } - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::Operation *op, mlir::ArrayRef operands, mlir::ConversionPatternRewriter &rewriter) const final { return matchAndRewrite(mlir::cast(op), @@ -218,14 +218,14 @@ public: /// Rewrite and Match methods that operate on the SourceOp type. These must be /// overridden by the derived pattern class. - virtual mlir::LogicalResult match(SourceOp op) const { + virtual llvm::LogicalResult match(SourceOp op) const { llvm_unreachable("must override match or matchAndRewrite"); } virtual void rewrite(SourceOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const { llvm_unreachable("must override rewrite or matchAndRewrite"); } - virtual mlir::LogicalResult + virtual llvm::LogicalResult matchAndRewrite(SourceOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const { if (mlir::failed(match(op))) @@ -246,14 +246,14 @@ public: using FIROpConversion::FIROpConversion; using OpAdaptor = typename FromOp::Adaptor; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(FromOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const final { mlir::Type ty = this->convertType(op.getType()); return doRewrite(op, ty, adaptor, rewriter); } - virtual mlir::LogicalResult + virtual llvm::LogicalResult doRewrite(FromOp addr, mlir::Type ty, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const = 0; }; diff --git a/flang/include/flang/Optimizer/CodeGen/TypeConverter.h b/flang/include/flang/Optimizer/CodeGen/TypeConverter.h index 58803a5..ece3e4e 100644 --- a/flang/include/flang/Optimizer/CodeGen/TypeConverter.h +++ b/flang/include/flang/Optimizer/CodeGen/TypeConverter.h @@ -60,7 +60,7 @@ public: mlir::Type indexType() const; // fir.type --> llvm<"%name = { ty... }"> - std::optional + std::optional convertRecordType(fir::RecordType derived, llvm::SmallVectorImpl &results); diff --git a/flang/include/flang/Optimizer/Dialect/FirAliasTagOpInterface.h b/flang/include/flang/Optimizer/Dialect/FirAliasTagOpInterface.h index f2d5b39..1e3728e 100644 --- a/flang/include/flang/Optimizer/Dialect/FirAliasTagOpInterface.h +++ b/flang/include/flang/Optimizer/Dialect/FirAliasTagOpInterface.h @@ -16,10 +16,10 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/IR/Operation.h" -#include "mlir/Support/LogicalResult.h" +#include "llvm/Support/LogicalResult.h" namespace fir::detail { -mlir::LogicalResult verifyFirAliasTagOpInterface(mlir::Operation *op); +llvm::LogicalResult verifyFirAliasTagOpInterface(mlir::Operation *op); } // namespace fir::detail #include "flang/Optimizer/Dialect/FirAliasTagOpInterface.h.inc" diff --git a/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td b/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td index 3f78a93..926e00c 100644 --- a/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td +++ b/flang/include/flang/Optimizer/Dialect/FortranVariableInterface.td @@ -192,7 +192,7 @@ def fir_FortranVariableOpInterface : OpInterface<"FortranVariableOpInterface"> { } /// Interface verifier imlementation for declare operations. - mlir::LogicalResult verifyDeclareLikeOpImpl(mlir::Value memRef); + llvm::LogicalResult verifyDeclareLikeOpImpl(mlir::Value memRef); }]; diff --git a/flang/include/flang/Optimizer/Dialect/Support/KindMapping.h b/flang/include/flang/Optimizer/Dialect/Support/KindMapping.h index 138123b..083526f 100644 --- a/flang/include/flang/Optimizer/Dialect/Support/KindMapping.h +++ b/flang/include/flang/Optimizer/Dialect/Support/KindMapping.h @@ -124,7 +124,7 @@ public: private: MatchResult badMapString(const llvm::Twine &ptr); MatchResult parse(llvm::StringRef kindMap); - mlir::LogicalResult setDefaultKinds(llvm::ArrayRef defs); + llvm::LogicalResult setDefaultKinds(llvm::ArrayRef defs); mlir::MLIRContext *context; llvm::DenseMap, Bitsize> intMap; diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td index e9915e89..fdf0db9 100644 --- a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td +++ b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td @@ -733,7 +733,7 @@ def hlfir_AssociateOp : hlfir_Op<"associate", [AttrSizedOperandSegments, CArg<"mlir::Value", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$typeparams, CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs)>, OpBuilder<(ins "mlir::Value":$memref, CArg<"mlir::Value", "{}">:$shape, - CArg<"mlir::ValueRange", "{}">:$typeparams, + CArg<"mlir::ValueRange", "{}">:$typeparams, CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs, CArg<"llvm::ArrayRef", "{}">:$attributes)>]; @@ -1258,7 +1258,7 @@ def hlfir_OrderedAssignmentTreeOpInterface : OpInterface<"OrderedAssignmentTreeO let extraClassDeclaration = [{ /// Interface verifier imlementation. - mlir::LogicalResult verifyImpl(); + llvm::LogicalResult verifyImpl(); mlir::Block* getSubTreeBlock() { mlir::Region* region = getSubTreeRegion(); @@ -1733,8 +1733,8 @@ def hlfir_CharExtremumOp : hlfir_Op<"char_extremum", [DeclareOpInterfaceMethods]> { let summary = "Find max/min from given character strings"; let description = [{ - Find the lexicographical minimum or maximum of two or more character - strings of the same character kind and return the string with the lexicographical + Find the lexicographical minimum or maximum of two or more character + strings of the same character kind and return the string with the lexicographical minimum or maximum number of characters. Example: %0 = hlfir.char_extremum min, %arg0, %arg1 : (!fir.ref>, !fir.ref>) -> !hlfir.expr> diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 5f35825..7483acf 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -113,7 +113,7 @@ namespace { struct AddrOfOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AddrOfOp addr, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto ty = convertType(addr.getType()); @@ -174,7 +174,7 @@ namespace { struct DeclareOpConversion : public fir::FIROpConversion { public: using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::cg::XDeclareOp declareOp, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto memRef = adaptor.getOperands()[0]; @@ -197,7 +197,7 @@ namespace { struct AllocaOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AllocaOp alloc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -294,7 +294,7 @@ namespace { struct BoxAddrOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxAddrOp boxaddr, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value a = adaptor.getOperands()[0]; @@ -316,7 +316,7 @@ struct BoxAddrOpConversion : public fir::FIROpConversion { struct BoxCharLenOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxCharLenOp boxCharLen, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value boxChar = adaptor.getOperands()[0]; @@ -339,7 +339,7 @@ struct BoxCharLenOpConversion : public fir::FIROpConversion { struct BoxDimsOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxDimsOp boxdims, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { llvm::SmallVector resultTypes = { @@ -361,7 +361,7 @@ struct BoxDimsOpConversion : public fir::FIROpConversion { struct BoxEleSizeOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxEleSizeOp boxelesz, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value box = adaptor.getOperands()[0]; @@ -379,7 +379,7 @@ struct BoxEleSizeOpConversion : public fir::FIROpConversion { struct BoxIsAllocOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxIsAllocOp boxisalloc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value box = adaptor.getOperands()[0]; @@ -397,7 +397,7 @@ struct BoxIsAllocOpConversion : public fir::FIROpConversion { struct BoxIsArrayOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxIsArrayOp boxisarray, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value a = adaptor.getOperands()[0]; @@ -416,7 +416,7 @@ struct BoxIsArrayOpConversion : public fir::FIROpConversion { struct BoxIsPtrOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxIsPtrOp boxisptr, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value box = adaptor.getOperands()[0]; @@ -434,7 +434,7 @@ struct BoxIsPtrOpConversion : public fir::FIROpConversion { struct BoxRankOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxRankOp boxrank, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value a = adaptor.getOperands()[0]; @@ -456,7 +456,7 @@ struct BoxProcHostOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxProcHostOp boxprochost, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(boxprochost.getLoc(), "fir.boxproc_host codegen"); @@ -470,7 +470,7 @@ struct BoxTypeDescOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxTypeDescOp boxtypedesc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value box = adaptor.getOperands()[0]; @@ -488,7 +488,7 @@ struct BoxTypeCodeOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxTypeCodeOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Value box = adaptor.getOperands()[0]; @@ -506,7 +506,7 @@ struct BoxTypeCodeOpConversion struct StringLitOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::StringLitOp constop, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto ty = convertType(constop.getType()); @@ -547,7 +547,7 @@ struct StringLitOpConversion : public fir::FIROpConversion { struct CallOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::CallOp call, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { llvm::SmallVector resultTys; @@ -578,7 +578,7 @@ namespace { struct CmpcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::CmpcOp cmp, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -616,7 +616,7 @@ struct CmpcOpConversion : public fir::FIROpConversion { struct ConstcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ConstcOp conc, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = conc.getLoc(); @@ -647,7 +647,7 @@ struct ConvertOpConversion : public fir::FIROpConversion { return mlir::isa(ty); } - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ConvertOp convert, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto fromFirTy = convert.getValue().getType(); @@ -814,7 +814,7 @@ struct ConvertOpConversion : public fir::FIROpConversion { struct TypeInfoOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::TypeInfoOp op, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.eraseOp(op); @@ -827,7 +827,7 @@ struct TypeInfoOpConversion : public fir::FIROpConversion { struct DTEntryOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::DTEntryOp op, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.eraseOp(op); @@ -839,7 +839,7 @@ struct DTEntryOpConversion : public fir::FIROpConversion { struct GlobalLenOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::GlobalLenOp globalLen, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(globalLen.getLoc(), "fir.global_len codegen"); @@ -853,7 +853,7 @@ struct LenParamIndexOpConversion using FIROpConversion::FIROpConversion; // FIXME: this should be specialized by the runtime target - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::LenParamIndexOp lenp, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(lenp.getLoc(), "fir.len_param_index codegen"); @@ -867,7 +867,7 @@ struct LenParamIndexOpConversion struct EmboxCharOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::EmboxCharOp emboxChar, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -960,7 +960,7 @@ namespace { struct AllocMemOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AllocMemOp heap, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type heapTy = heap.getType(); @@ -1030,7 +1030,7 @@ namespace { struct FreeMemOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::FreeMemOp freemem, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = freemem.getLoc(); @@ -1481,7 +1481,7 @@ computeTripletExtent(mlir::ConversionPatternRewriter &rewriter, struct EmboxOpConversion : public EmboxCommonConversion { using EmboxCommonConversion::EmboxCommonConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::EmboxOp embox, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -1513,7 +1513,7 @@ struct EmboxOpConversion : public EmboxCommonConversion { struct XEmboxOpConversion : public EmboxCommonConversion { using EmboxCommonConversion::EmboxCommonConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::cg::XEmboxOp xbox, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -1711,7 +1711,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion { struct XReboxOpConversion : public EmboxCommonConversion { using EmboxCommonConversion::EmboxCommonConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::cg::XReboxOp rebox, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = rebox.getLoc(); @@ -1794,7 +1794,7 @@ struct XReboxOpConversion : public EmboxCommonConversion { private: /// Write resulting shape and base address in descriptor, and replace rebox /// op. - mlir::LogicalResult + llvm::LogicalResult finalizeRebox(fir::cg::XReboxOp rebox, mlir::Type destBoxTy, mlir::Value dest, mlir::Value base, mlir::ValueRange lbounds, mlir::ValueRange extents, mlir::ValueRange strides, @@ -1825,7 +1825,7 @@ private: } // Apply slice given the base address, extents and strides of the input box. - mlir::LogicalResult + llvm::LogicalResult sliceBox(fir::cg::XReboxOp rebox, mlir::Type destBoxTy, mlir::Value dest, mlir::Value base, mlir::ValueRange inputExtents, mlir::ValueRange inputStrides, mlir::ValueRange operands, @@ -1908,7 +1908,7 @@ private: /// Apply a new shape to the data described by a box given the base address, /// extents and strides of the box. - mlir::LogicalResult + llvm::LogicalResult reshapeBox(fir::cg::XReboxOp rebox, mlir::Type destBoxTy, mlir::Value dest, mlir::Value base, mlir::ValueRange inputExtents, mlir::ValueRange inputStrides, mlir::ValueRange operands, @@ -1960,7 +1960,7 @@ private: struct EmboxProcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::EmboxProcOp emboxproc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(emboxproc.getLoc(), "fir.emboxproc codegen"); @@ -2027,7 +2027,7 @@ struct ExtractValueOpConversion public ValueOpCommon { using FIROpAndTypeConversion::FIROpAndTypeConversion; - mlir::LogicalResult + llvm::LogicalResult doRewrite(fir::ExtractValueOp extractVal, mlir::Type ty, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -2046,7 +2046,7 @@ struct InsertValueOpConversion public ValueOpCommon { using FIROpAndTypeConversion::FIROpAndTypeConversion; - mlir::LogicalResult + llvm::LogicalResult doRewrite(fir::InsertValueOp insertVal, mlir::Type ty, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -2074,7 +2074,7 @@ struct InsertOnRangeOpConversion } } - mlir::LogicalResult + llvm::LogicalResult doRewrite(fir::InsertOnRangeOp range, mlir::Type ty, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { @@ -2127,7 +2127,7 @@ struct XArrayCoorOpConversion : public fir::FIROpAndTypeConversion { using FIROpAndTypeConversion::FIROpAndTypeConversion; - mlir::LogicalResult + llvm::LogicalResult doRewrite(fir::cg::XArrayCoorOp coor, mlir::Type llvmPtrTy, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto loc = coor.getLoc(); @@ -2296,7 +2296,7 @@ struct CoordinateOpConversion : public fir::FIROpAndTypeConversion { using FIROpAndTypeConversion::FIROpAndTypeConversion; - mlir::LogicalResult + llvm::LogicalResult doRewrite(fir::CoordinateOp coor, mlir::Type ty, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::ValueRange operands = adaptor.getOperands(); @@ -2396,7 +2396,7 @@ struct CoordinateOpConversion } private: - mlir::LogicalResult + llvm::LogicalResult doRewriteBox(fir::CoordinateOp coor, mlir::ValueRange operands, mlir::Location loc, mlir::ConversionPatternRewriter &rewriter) const { @@ -2482,7 +2482,7 @@ private: return mlir::success(); } - mlir::LogicalResult + llvm::LogicalResult doRewriteRefOrPtr(fir::CoordinateOp coor, mlir::Type llvmObjectTy, mlir::ValueRange operands, mlir::Location loc, mlir::ConversionPatternRewriter &rewriter) const { @@ -2593,7 +2593,7 @@ struct FieldIndexOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; // NB: most field references should be resolved by this point - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::FieldIndexOp field, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { auto recTy = mlir::cast(field.getOnType()); @@ -2633,7 +2633,7 @@ struct FieldIndexOpConversion : public fir::FIROpConversion { struct FirEndOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::FirEndOp firEnd, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(firEnd.getLoc(), "fir.end codegen"); @@ -2645,7 +2645,7 @@ struct FirEndOpConversion : public fir::FIROpConversion { struct TypeDescOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::TypeDescOp typeDescOp, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type inTy = typeDescOp.getInType(); @@ -2672,7 +2672,7 @@ struct TypeDescOpConversion : public fir::FIROpConversion { struct HasValueOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::HasValueOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(op, @@ -2725,7 +2725,7 @@ static inline bool attributeTypeIsCompatible(mlir::MLIRContext *ctx, struct GlobalOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::GlobalOp global, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { @@ -2867,7 +2867,7 @@ private: struct LoadOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::LoadOp load, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type llvmLoadTy = convertObjectType(load.getType()); @@ -2925,7 +2925,7 @@ struct LoadOpConversion : public fir::FIROpConversion { struct NoReassocOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::NoReassocOp noreassoc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.replaceOp(noreassoc, adaptor.getOperands()[0]); @@ -2986,7 +2986,7 @@ static void genCaseLadderStep(mlir::Location loc, mlir::Value cmp, struct SelectCaseOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::SelectCaseOp caseOp, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { unsigned conds = caseOp.getNumConditions(); @@ -3101,7 +3101,7 @@ static void selectMatchAndRewrite(const fir::LLVMTypeConverter &lowering, struct SelectOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::SelectOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { selectMatchAndRewrite(lowerTy(), op, adaptor, rewriter); @@ -3113,7 +3113,7 @@ struct SelectOpConversion : public fir::FIROpConversion { struct SelectRankOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::SelectRankOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { selectMatchAndRewrite(lowerTy(), op, adaptor, rewriter); @@ -3125,7 +3125,7 @@ struct SelectRankOpConversion : public fir::FIROpConversion { struct SelectTypeOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::SelectTypeOp select, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::emitError(select.getLoc(), @@ -3138,7 +3138,7 @@ struct SelectTypeOpConversion : public fir::FIROpConversion { struct StoreOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::StoreOp store, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = store.getLoc(); @@ -3181,7 +3181,7 @@ namespace { struct UnboxCharOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::UnboxCharOp unboxchar, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type lenTy = convertType(unboxchar.getType(1)); @@ -3206,7 +3206,7 @@ struct UnboxCharOpConversion : public fir::FIROpConversion { struct UnboxProcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::UnboxProcOp unboxproc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { TODO(unboxproc.getLoc(), "fir.unboxproc codegen"); @@ -3218,7 +3218,7 @@ struct UnboxProcOpConversion : public fir::FIROpConversion { struct UndefOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::UndefOp undef, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp( @@ -3230,7 +3230,7 @@ struct UndefOpConversion : public fir::FIROpConversion { struct ZeroOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ZeroOp zero, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type ty = convertType(zero.getType()); @@ -3244,7 +3244,7 @@ struct UnreachableOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::UnreachableOp unreach, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(unreach); @@ -3261,7 +3261,7 @@ struct UnreachableOpConversion struct IsPresentOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::IsPresentOp isPresent, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type idxTy = lowerTy().indexType(); @@ -3290,7 +3290,7 @@ struct IsPresentOpConversion : public fir::FIROpConversion { struct AbsentOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AbsentOp absent, OpAdaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Type ty = convertType(absent.getType()); @@ -3350,7 +3350,7 @@ namespace { struct AddcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AddcOp addc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { // given: (x + iy) + (x' + iy') @@ -3365,7 +3365,7 @@ struct AddcOpConversion : public fir::FIROpConversion { struct SubcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::SubcOp subc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { // given: (x + iy) - (x' + iy') @@ -3381,7 +3381,7 @@ struct SubcOpConversion : public fir::FIROpConversion { struct MulcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::MulcOp mulc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { // TODO: Can we use a call to __muldc3 ? @@ -3415,7 +3415,7 @@ struct MulcOpConversion : public fir::FIROpConversion { struct DivcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::DivcOp divc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { // TODO: Can we use a call to __divdc3 instead? @@ -3455,7 +3455,7 @@ struct DivcOpConversion : public fir::FIROpConversion { struct NegcOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::NegcOp neg, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { // given: -(x + iy) @@ -3476,7 +3476,7 @@ struct NegcOpConversion : public fir::FIROpConversion { struct BoxOffsetOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::BoxOffsetOp boxOffset, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { @@ -3505,7 +3505,7 @@ struct MustBeDeadConversion : public fir::FIROpConversion { : fir::FIROpConversion(lowering, options) {} using OpAdaptor = typename FromOp::Adaptor; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(FromOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const final { if (!op->getUses().empty()) @@ -3519,7 +3519,7 @@ struct UnrealizedConversionCastOpConversion : public fir::FIROpConversion { using FIROpConversion::FIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::UnrealizedConversionCastOp op, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { assert(op.getOutputs().getTypes().size() == 1 && "expect a single type"); @@ -3562,7 +3562,7 @@ class RenameMSVCLibmCallees public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::LLVM::CallOp op, mlir::PatternRewriter &rewriter) const override { rewriter.startOpModification(op); @@ -3581,7 +3581,7 @@ class RenameMSVCLibmFuncs public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::LLVM::LLVMFuncOp op, mlir::PatternRewriter &rewriter) const override { rewriter.startOpModification(op); diff --git a/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp b/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp index a6fa05f..48d6c000e 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp @@ -59,7 +59,7 @@ struct MapInfoOpConversion : public OpenMPFIROpConversion { using OpenMPFIROpConversion::OpenMPFIROpConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::omp::MapInfoOp curOp, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { const mlir::TypeConverter *converter = getTypeConverter(); diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp index 6a0cd5e..c57f514 100644 --- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp @@ -80,7 +80,7 @@ class EmboxConversion : public mlir::OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::EmboxOp embox, mlir::PatternRewriter &rewriter) const override { // If the embox does not include a shape, then do not convert it @@ -95,7 +95,7 @@ public: return mlir::failure(); } - mlir::LogicalResult rewriteStaticShape(fir::EmboxOp embox, + llvm::LogicalResult rewriteStaticShape(fir::EmboxOp embox, mlir::PatternRewriter &rewriter, fir::SequenceType seqTy) const { auto loc = embox.getLoc(); @@ -115,7 +115,7 @@ public: return mlir::success(); } - mlir::LogicalResult rewriteDynamicShape(fir::EmboxOp embox, + llvm::LogicalResult rewriteDynamicShape(fir::EmboxOp embox, mlir::PatternRewriter &rewriter, mlir::Value shapeVal) const { auto loc = embox.getLoc(); @@ -168,7 +168,7 @@ class ReboxConversion : public mlir::OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ReboxOp rebox, mlir::PatternRewriter &rewriter) const override { auto loc = rebox.getLoc(); @@ -227,7 +227,7 @@ class ArrayCoorConversion : public mlir::OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ArrayCoorOp arrCoor, mlir::PatternRewriter &rewriter) const override { auto loc = arrCoor.getLoc(); @@ -277,7 +277,7 @@ public: DeclareOpConversion(mlir::MLIRContext *ctx, bool preserveDecl) : OpRewritePattern(ctx), preserveDeclare(preserveDecl) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::DeclareOp declareOp, mlir::PatternRewriter &rewriter) const override { if (!preserveDeclare) { @@ -316,7 +316,7 @@ class DummyScopeOpConversion public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::DummyScopeOp dummyScopeOp, mlir::PatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(dummyScopeOp, diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp index 8199c5e..561d700 100644 --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -667,7 +667,7 @@ public: /// Convert the type signatures on all the functions present in the module. /// As the type signature is being changed, this must also update the /// function itself to use any new arguments, etc. - mlir::LogicalResult convertTypes(mlir::ModuleOp mod) { + llvm::LogicalResult convertTypes(mlir::ModuleOp mod) { mlir::MLIRContext *ctx = mod->getContext(); auto targetCPU = specifics->getTargetCPU(); mlir::StringAttr targetCPUAttr = diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp index 501a36f..ce86c62 100644 --- a/flang/lib/Optimizer/CodeGen/TypeConverter.cpp +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.cpp @@ -170,7 +170,7 @@ mlir::Type LLVMTypeConverter::indexType() const { } // fir.type --> llvm<"%name = { ty... }"> -std::optional LLVMTypeConverter::convertRecordType( +std::optional LLVMTypeConverter::convertRecordType( fir::RecordType derived, llvm::SmallVectorImpl &results) { auto name = fir::NameUniquer::dropTypeConversionMarkers(derived.getName()); auto st = mlir::LLVM::LLVMStructType::getIdentified(&getContext(), name); diff --git a/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp b/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp index 4fa1d39..53092be 100644 --- a/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp +++ b/flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp @@ -51,7 +51,7 @@ void cuf::AllocOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, } template -static mlir::LogicalResult checkCudaAttr(Op op) { +static llvm::LogicalResult checkCudaAttr(Op op) { if (op.getDataAttr() == cuf::DataAttribute::Device || op.getDataAttr() == cuf::DataAttribute::Managed || op.getDataAttr() == cuf::DataAttribute::Unified) @@ -59,19 +59,19 @@ static mlir::LogicalResult checkCudaAttr(Op op) { return op.emitOpError("expect device, managed or unified cuda attribute"); } -mlir::LogicalResult cuf::AllocOp::verify() { return checkCudaAttr(*this); } +llvm::LogicalResult cuf::AllocOp::verify() { return checkCudaAttr(*this); } //===----------------------------------------------------------------------===// // FreeOp //===----------------------------------------------------------------------===// -mlir::LogicalResult cuf::FreeOp::verify() { return checkCudaAttr(*this); } +llvm::LogicalResult cuf::FreeOp::verify() { return checkCudaAttr(*this); } //===----------------------------------------------------------------------===// // AllocateOp //===----------------------------------------------------------------------===// -mlir::LogicalResult cuf::AllocateOp::verify() { +llvm::LogicalResult cuf::AllocateOp::verify() { if (getPinned() && getStream()) return emitOpError("pinned and stream cannot appears at the same time"); if (!mlir::isa(fir::unwrapRefType(getBox().getType()))) @@ -94,7 +94,7 @@ mlir::LogicalResult cuf::AllocateOp::verify() { // DataTransferOp //===----------------------------------------------------------------------===// -mlir::LogicalResult cuf::DataTransferOp::verify() { +llvm::LogicalResult cuf::DataTransferOp::verify() { mlir::Type srcTy = getSrc().getType(); mlir::Type dstTy = getDst().getType(); if ((fir::isa_ref_type(srcTy) && fir::isa_ref_type(dstTy)) || @@ -114,7 +114,7 @@ mlir::LogicalResult cuf::DataTransferOp::verify() { // DeallocateOp //===----------------------------------------------------------------------===// -mlir::LogicalResult cuf::DeallocateOp::verify() { +llvm::LogicalResult cuf::DeallocateOp::verify() { if (!mlir::isa(fir::unwrapRefType(getBox().getType()))) return emitOpError( "expect box to be a reference to class or box type value"); @@ -225,7 +225,7 @@ void printCUFKernelLoopControl( p.printRegion(region, /*printEntryBlockArgs=*/false); } -mlir::LogicalResult cuf::KernelOp::verify() { +llvm::LogicalResult cuf::KernelOp::verify() { if (getLowerbound().size() != getUpperbound().size() || getLowerbound().size() != getStep().size()) return emitOpError( diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index 84711c5..fd3aa2a 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -263,7 +263,7 @@ void fir::AllocaOp::print(mlir::OpAsmPrinter &p) { printAllocatableOp(p, *this); } -mlir::LogicalResult fir::AllocaOp::verify() { +llvm::LogicalResult fir::AllocaOp::verify() { llvm::SmallVector visited; if (verifyInType(getInType(), visited, numShapeOperands())) return emitOpError("invalid type for allocation"); @@ -339,7 +339,7 @@ void fir::AllocMemOp::print(mlir::OpAsmPrinter &p) { printAllocatableOp(p, *this); } -mlir::LogicalResult fir::AllocMemOp::verify() { +llvm::LogicalResult fir::AllocMemOp::verify() { llvm::SmallVector visited; if (verifyInType(getInType(), visited, numShapeOperands())) return emitOpError("invalid type for allocation"); @@ -375,7 +375,7 @@ static bool validTypeParams(mlir::Type dynTy, mlir::ValueRange typeParams) { return typeParams.size() == 0; } -mlir::LogicalResult fir::ArrayCoorOp::verify() { +llvm::LogicalResult fir::ArrayCoorOp::verify() { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); auto arrTy = mlir::dyn_cast(eleTy); if (!arrTy) @@ -424,7 +424,7 @@ mlir::LogicalResult fir::ArrayCoorOp::verify() { // Pull in fir.embox and fir.rebox into fir.array_coor when possible. struct SimplifyArrayCoorOp : public mlir::OpRewritePattern { using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ArrayCoorOp op, mlir::PatternRewriter &rewriter) const override { mlir::Value memref = op.getMemref(); @@ -821,7 +821,7 @@ std::vector fir::ArrayLoadOp::getExtents() { return {}; } -mlir::LogicalResult fir::ArrayLoadOp::verify() { +llvm::LogicalResult fir::ArrayLoadOp::verify() { auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(getMemref().getType()); auto arrTy = mlir::dyn_cast(eleTy); if (!arrTy) @@ -864,7 +864,7 @@ mlir::LogicalResult fir::ArrayLoadOp::verify() { // ArrayMergeStoreOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ArrayMergeStoreOp::verify() { +llvm::LogicalResult fir::ArrayMergeStoreOp::verify() { if (!mlir::isa(getOriginal().getDefiningOp())) return emitOpError("operand #0 must be result of a fir.array_load op"); if (auto sl = getSlice()) { @@ -914,7 +914,7 @@ mlir::Type validArraySubobject(A op) { return fir::applyPathToType(ty, op.getIndices()); } -mlir::LogicalResult fir::ArrayFetchOp::verify() { +llvm::LogicalResult fir::ArrayFetchOp::verify() { auto arrTy = mlir::cast(getSequence().getType()); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) @@ -936,7 +936,7 @@ mlir::LogicalResult fir::ArrayFetchOp::verify() { // ArrayAccessOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ArrayAccessOp::verify() { +llvm::LogicalResult fir::ArrayAccessOp::verify() { auto arrTy = mlir::cast(getSequence().getType()); std::size_t indSize = getIndices().size(); if (indSize < arrTy.getDimension()) @@ -956,7 +956,7 @@ mlir::LogicalResult fir::ArrayAccessOp::verify() { // ArrayUpdateOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ArrayUpdateOp::verify() { +llvm::LogicalResult fir::ArrayUpdateOp::verify() { if (fir::isa_ref_type(getMerge().getType())) return emitOpError("does not support reference type for merge"); auto arrTy = mlir::cast(getSequence().getType()); @@ -978,7 +978,7 @@ mlir::LogicalResult fir::ArrayUpdateOp::verify() { // ArrayModifyOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ArrayModifyOp::verify() { +llvm::LogicalResult fir::ArrayModifyOp::verify() { auto arrTy = mlir::cast(getSequence().getType()); auto indSize = getIndices().size(); if (indSize < arrTy.getDimension()) @@ -1171,7 +1171,7 @@ void fir::CallOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, // CharConvertOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::CharConvertOp::verify() { +llvm::LogicalResult fir::CharConvertOp::verify() { auto unwrap = [&](mlir::Type t) { t = fir::unwrapSequenceType(fir::dyn_cast_ptrEleTy(t)); return mlir::dyn_cast(t); @@ -1294,7 +1294,7 @@ void fir::ConstcOp::print(mlir::OpAsmPrinter &p) { p.printType(getType()); } -mlir::LogicalResult fir::ConstcOp::verify() { +llvm::LogicalResult fir::ConstcOp::verify() { if (!mlir::isa(getType())) return emitOpError("must be a !fir.complex type"); return mlir::success(); @@ -1427,7 +1427,7 @@ bool fir::ConvertOp::canBeConverted(mlir::Type inType, mlir::Type outType) { areVectorsCompatible(inType, outType); } -mlir::LogicalResult fir::ConvertOp::verify() { +llvm::LogicalResult fir::ConvertOp::verify() { if (canBeConverted(getValue().getType(), getType())) return mlir::success(); return emitOpError("invalid type conversion") @@ -1468,7 +1468,7 @@ mlir::ParseResult fir::CoordinateOp::parse(mlir::OpAsmParser &parser, return mlir::success(); } -mlir::LogicalResult fir::CoordinateOp::verify() { +llvm::LogicalResult fir::CoordinateOp::verify() { const mlir::Type refTy = getRef().getType(); if (fir::isa_ref_type(refTy)) { auto eleTy = fir::dyn_cast_ptrEleTy(refTy); @@ -1551,7 +1551,7 @@ mlir::LogicalResult fir::CoordinateOp::verify() { // DispatchOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::DispatchOp::verify() { +llvm::LogicalResult fir::DispatchOp::verify() { // Check that pass_arg_pos is in range of actual operands. pass_arg_pos is // unsigned so check for less than zero is not needed. if (getPassArgPos() && *getPassArgPos() > (getArgOperands().size() - 1)) @@ -1588,7 +1588,7 @@ void fir::TypeInfoOp::build(mlir::OpBuilder &builder, result.addAttributes(attrs); } -mlir::LogicalResult fir::TypeInfoOp::verify() { +llvm::LogicalResult fir::TypeInfoOp::verify() { if (!getDispatchTable().empty()) for (auto &op : getDispatchTable().front().without_terminator()) if (!mlir::isa(op)) @@ -1606,7 +1606,7 @@ mlir::LogicalResult fir::TypeInfoOp::verify() { // EmboxOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::EmboxOp::verify() { +llvm::LogicalResult fir::EmboxOp::verify() { auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); bool isArray = false; if (auto seqTy = mlir::dyn_cast(eleTy)) { @@ -1642,7 +1642,7 @@ mlir::LogicalResult fir::EmboxOp::verify() { // EmboxCharOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::EmboxCharOp::verify() { +llvm::LogicalResult fir::EmboxCharOp::verify() { auto eleTy = fir::dyn_cast_ptrEleTy(getMemref().getType()); if (!mlir::dyn_cast_or_null(eleTy)) return mlir::failure(); @@ -1653,7 +1653,7 @@ mlir::LogicalResult fir::EmboxCharOp::verify() { // EmboxProcOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::EmboxProcOp::verify() { +llvm::LogicalResult fir::EmboxProcOp::verify() { // host bindings (optional) must be a reference to a tuple if (auto h = getHost()) { if (auto r = mlir::dyn_cast(h.getType())) @@ -1691,7 +1691,7 @@ void fir::TypeDescOp::print(mlir::OpAsmPrinter &p) { p.printOptionalAttrDict(getOperation()->getAttrs(), {"in_type"}); } -mlir::LogicalResult fir::TypeDescOp::verify() { +llvm::LogicalResult fir::TypeDescOp::verify() { mlir::Type resultTy = getType(); if (auto tdesc = mlir::dyn_cast(resultTy)) { if (tdesc.getOfTy() != getInType()) @@ -2036,7 +2036,7 @@ static void printCustomRangeSubscript(mlir::OpAsmPrinter &printer, } /// Range bounds must be nonnegative, and the range must not be empty. -mlir::LogicalResult fir::InsertOnRangeOp::verify() { +llvm::LogicalResult fir::InsertOnRangeOp::verify() { if (fir::hasDynamicSize(getSeq().getType())) return emitOpError("must have constant shape and size"); mlir::DenseIntElementsAttr coorAttr = getCoor(); @@ -2079,7 +2079,7 @@ struct UndoComplexPattern : public mlir::RewritePattern { UndoComplexPattern(mlir::MLIRContext *ctx) : mlir::RewritePattern("fir.insert_value", 2, ctx) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::Operation *op, mlir::PatternRewriter &rewriter) const override { auto insval = mlir::dyn_cast_or_null(op); @@ -2250,7 +2250,7 @@ mlir::ParseResult fir::IterWhileOp::parse(mlir::OpAsmParser &parser, return mlir::success(); } -mlir::LogicalResult fir::IterWhileOp::verify() { +llvm::LogicalResult fir::IterWhileOp::verify() { // Check that the body defines as single block argument for the induction // variable. auto *body = getBody(); @@ -2610,7 +2610,7 @@ fir::DoLoopOp fir::getForInductionVarOwner(mlir::Value val) { } // Lifted from loop.loop -mlir::LogicalResult fir::DoLoopOp::verify() { +llvm::LogicalResult fir::DoLoopOp::verify() { // Check that the body defines as single block argument for the induction // variable. auto *body = getBody(); @@ -2785,7 +2785,7 @@ static bool areCompatibleCharacterTypes(mlir::Type t1, mlir::Type t2) { return c1.getLen() == c2.getLen(); } -mlir::LogicalResult fir::ReboxOp::verify() { +llvm::LogicalResult fir::ReboxOp::verify() { auto inputBoxTy = getBox().getType(); if (fir::isa_unknown_size_box(inputBoxTy)) return emitOpError("box operand must not have unknown rank or type"); @@ -2883,7 +2883,7 @@ static bool areCompatibleAssumedRankElementType(mlir::Type inputEleTy, return false; } -mlir::LogicalResult fir::ReboxAssumedRankOp::verify() { +llvm::LogicalResult fir::ReboxAssumedRankOp::verify() { mlir::Type inputType = getBox().getType(); if (!mlir::isa(inputType) && !fir::isBoxAddress(inputType)) return emitOpError("input must be a box or box address"); @@ -2911,7 +2911,7 @@ void fir::ReboxAssumedRankOp::getEffects( // ResultOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ResultOp::verify() { +llvm::LogicalResult fir::ResultOp::verify() { auto *parentOp = (*this)->getParentOp(); auto results = parentOp->getResults(); auto operands = (*this)->getOperands(); @@ -2928,7 +2928,7 @@ mlir::LogicalResult fir::ResultOp::verify() { // SaveResultOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::SaveResultOp::verify() { +llvm::LogicalResult fir::SaveResultOp::verify() { auto resultType = getValue().getType(); if (resultType != fir::dyn_cast_ptrEleTy(getMemref().getType())) return emitOpError("value type must match memory reference type"); @@ -2992,7 +2992,7 @@ static constexpr llvm::StringRef getTargetOffsetAttr() { } template -static mlir::LogicalResult verifyIntegralSwitchTerminator(OpT op) { +static llvm::LogicalResult verifyIntegralSwitchTerminator(OpT op) { if (!mlir::isa( op.getSelector().getType())) return op.emitOpError("must be an integer"); @@ -3086,7 +3086,7 @@ static void printIntegralSwitchTerminator(OpT op, mlir::OpAsmPrinter &p) { // SelectOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::SelectOp::verify() { +llvm::LogicalResult fir::SelectOp::verify() { return verifyIntegralSwitchTerminator(*this); } @@ -3412,7 +3412,7 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder, destOperands, attributes); } -mlir::LogicalResult fir::SelectCaseOp::verify() { +llvm::LogicalResult fir::SelectCaseOp::verify() { if (!mlir::isa(getSelector().getType())) return emitOpError("must be an integer, character, or logical"); @@ -3443,7 +3443,7 @@ mlir::LogicalResult fir::SelectCaseOp::verify() { // SelectRankOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::SelectRankOp::verify() { +llvm::LogicalResult fir::SelectRankOp::verify() { return verifyIntegralSwitchTerminator(*this); } @@ -3608,7 +3608,7 @@ void fir::SelectTypeOp::print(mlir::OpAsmPrinter &p) { fir::SelectTypeOp::getOperandSegmentSizeAttr()}); } -mlir::LogicalResult fir::SelectTypeOp::verify() { +llvm::LogicalResult fir::SelectTypeOp::verify() { if (!mlir::isa(getSelector().getType())) return emitOpError("must be a fir.class or fir.box type"); if (auto boxType = mlir::dyn_cast(getSelector().getType())) @@ -3670,7 +3670,7 @@ void fir::SelectTypeOp::build(mlir::OpBuilder &builder, // ShapeOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ShapeOp::verify() { +llvm::LogicalResult fir::ShapeOp::verify() { auto size = getExtents().size(); auto shapeTy = mlir::dyn_cast(getType()); assert(shapeTy && "must be a shape type"); @@ -3689,7 +3689,7 @@ void fir::ShapeOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, // ShapeShiftOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ShapeShiftOp::verify() { +llvm::LogicalResult fir::ShapeShiftOp::verify() { auto size = getPairs().size(); if (size < 2 || size > 16 * 2) return emitOpError("incorrect number of args"); @@ -3706,7 +3706,7 @@ mlir::LogicalResult fir::ShapeShiftOp::verify() { // ShiftOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::ShiftOp::verify() { +llvm::LogicalResult fir::ShiftOp::verify() { auto size = getOrigins().size(); auto shiftTy = mlir::dyn_cast(getType()); assert(shiftTy && "must be a shift type"); @@ -3742,7 +3742,7 @@ unsigned fir::SliceOp::getOutputRank(mlir::ValueRange triples) { return rank; } -mlir::LogicalResult fir::SliceOp::verify() { +llvm::LogicalResult fir::SliceOp::verify() { auto size = getTriples().size(); if (size < 3 || size > 16 * 3) return emitOpError("incorrect number of args for triple"); @@ -3788,7 +3788,7 @@ void fir::StoreOp::print(mlir::OpAsmPrinter &p) { p << " : " << getMemref().getType(); } -mlir::LogicalResult fir::StoreOp::verify() { +llvm::LogicalResult fir::StoreOp::verify() { if (getValue().getType() != fir::dyn_cast_ptrEleTy(getMemref().getType())) return emitOpError("store value type must match memory reference type"); return mlir::success(); @@ -3920,7 +3920,7 @@ void fir::StringLitOp::print(mlir::OpAsmPrinter &p) { p.printType(getType()); } -mlir::LogicalResult fir::StringLitOp::verify() { +llvm::LogicalResult fir::StringLitOp::verify() { if (mlir::cast(getSize()).getValue().isNegative()) return emitOpError("size must be non-negative"); if (auto xl = getOperation()->getAttr(fir::StringLitOp::xlist())) { @@ -3941,7 +3941,7 @@ mlir::LogicalResult fir::StringLitOp::verify() { // UnboxProcOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::UnboxProcOp::verify() { +llvm::LogicalResult fir::UnboxProcOp::verify() { if (auto eleTy = fir::dyn_cast_ptrEleTy(getRefTuple().getType())) if (mlir::isa(eleTy)) return mlir::success(); @@ -4067,7 +4067,7 @@ mlir::ParseResult fir::IfOp::parse(mlir::OpAsmParser &parser, return mlir::success(); } -mlir::LogicalResult fir::IfOp::verify() { +llvm::LogicalResult fir::IfOp::verify() { if (getNumResults() != 0 && getElseRegion().empty()) return emitOpError("must have an else block if defining values"); @@ -4109,7 +4109,7 @@ void fir::IfOp::resultToSourceOps(llvm::SmallVectorImpl &results, // BoxOffsetOp //===----------------------------------------------------------------------===// -mlir::LogicalResult fir::BoxOffsetOp::verify() { +llvm::LogicalResult fir::BoxOffsetOp::verify() { auto boxType = mlir::dyn_cast_or_null( fir::dyn_cast_ptrEleTy(getBoxRef().getType())); if (!boxType) @@ -4402,7 +4402,7 @@ mlir::Type fir::applyPathToType(mlir::Type eleTy, mlir::ValueRange path) { return eleTy; } -mlir::LogicalResult fir::DeclareOp::verify() { +llvm::LogicalResult fir::DeclareOp::verify() { auto fortranVar = mlir::cast(this->getOperation()); return fortranVar.verifyDeclareLikeOpImpl(getMemref()); diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp index b3f2ec8..dbccacf 100644 --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -683,7 +683,7 @@ void fir::BoxProcType::print(mlir::AsmPrinter &printer) const { printer << "<" << getEleTy() << '>'; } -mlir::LogicalResult +llvm::LogicalResult BoxProcType::verify(llvm::function_ref emitError, mlir::Type eleTy) { if (mlir::isa(eleTy)) @@ -704,7 +704,7 @@ static bool cannotBePointerOrHeapElementType(mlir::Type eleTy) { // BoxType //===----------------------------------------------------------------------===// -mlir::LogicalResult +llvm::LogicalResult fir::BoxType::verify(llvm::function_ref emitError, mlir::Type eleTy) { if (mlir::isa(eleTy)) @@ -773,7 +773,7 @@ void fir::CharacterType::print(mlir::AsmPrinter &printer) const { // ClassType //===----------------------------------------------------------------------===// -mlir::LogicalResult +llvm::LogicalResult fir::ClassType::verify(llvm::function_ref emitError, mlir::Type eleTy) { if (mlir::isa'; } -mlir::LogicalResult +llvm::LogicalResult fir::HeapType::verify(llvm::function_ref emitError, mlir::Type eleTy) { if (cannotBePointerOrHeapElementType(eleTy)) @@ -868,7 +868,7 @@ void fir::PointerType::print(mlir::AsmPrinter &printer) const { printer << "<" << getEleTy() << '>'; } -mlir::LogicalResult fir::PointerType::verify( +llvm::LogicalResult fir::PointerType::verify( llvm::function_ref emitError, mlir::Type eleTy) { if (cannotBePointerOrHeapElementType(eleTy)) @@ -889,7 +889,7 @@ void fir::RealType::print(mlir::AsmPrinter &printer) const { printer << "<" << getFKind() << '>'; } -mlir::LogicalResult +llvm::LogicalResult fir::RealType::verify(llvm::function_ref emitError, KindTy fKind) { // TODO @@ -1012,7 +1012,7 @@ detail::RecordTypeStorage const *fir::RecordType::uniqueKey() const { return getImpl(); } -mlir::LogicalResult fir::RecordType::verify( +llvm::LogicalResult fir::RecordType::verify( llvm::function_ref emitError, llvm::StringRef name) { if (name.size() == 0) @@ -1047,7 +1047,7 @@ void fir::ReferenceType::print(mlir::AsmPrinter &printer) const { printer << "<" << getEleTy() << '>'; } -mlir::LogicalResult fir::ReferenceType::verify( +llvm::LogicalResult fir::ReferenceType::verify( llvm::function_ref emitError, mlir::Type eleTy) { if (mlir::isa emitError, llvm::ArrayRef shape, mlir::Type eleTy, mlir::AffineMapAttr layoutMap) { @@ -1196,7 +1196,7 @@ void fir::TypeDescType::print(mlir::AsmPrinter &printer) const { printer << "<" << getOfTy() << '>'; } -mlir::LogicalResult fir::TypeDescType::verify( +llvm::LogicalResult fir::TypeDescType::verify( llvm::function_ref emitError, mlir::Type eleTy) { if (mlir::isa'; } -mlir::LogicalResult fir::VectorType::verify( +llvm::LogicalResult fir::VectorType::verify( llvm::function_ref emitError, uint64_t len, mlir::Type eleTy) { if (!(fir::isa_real(eleTy) || fir::isa_integer(eleTy))) diff --git a/flang/lib/Optimizer/Dialect/FirAliasTagOpInterface.cpp b/flang/lib/Optimizer/Dialect/FirAliasTagOpInterface.cpp index 648f490..bf058c1 100644 --- a/flang/lib/Optimizer/Dialect/FirAliasTagOpInterface.cpp +++ b/flang/lib/Optimizer/Dialect/FirAliasTagOpInterface.cpp @@ -15,17 +15,17 @@ #include "flang/Optimizer/Dialect/FirAliasTagOpInterface.cpp.inc" -mlir::LogicalResult +llvm::LogicalResult fir::detail::verifyFirAliasTagOpInterface(mlir::Operation *op) { auto iface = mlir::cast(op); mlir::ArrayAttr tags = iface.getTBAATagsOrNull(); if (!tags) - return mlir::success(); + return llvm::success(); for (mlir::Attribute iter : tags) if (!mlir::isa(iter)) return op->emitOpError("expected op to return array of ") << mlir::LLVM::TBAATagAttr::getMnemonic() << " attributes"; - return mlir::success(); + return llvm::success(); } diff --git a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp index 70b1a2f..034f8c7 100644 --- a/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp +++ b/flang/lib/Optimizer/Dialect/FortranVariableInterface.cpp @@ -14,7 +14,7 @@ #include "flang/Optimizer/Dialect/FortranVariableInterface.cpp.inc" -mlir::LogicalResult +llvm::LogicalResult fir::FortranVariableOpInterface::verifyDeclareLikeOpImpl(mlir::Value memref) { const unsigned numExplicitTypeParams = getExplicitTypeParams().size(); mlir::Type memType = memref.getType(); diff --git a/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp b/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp index bcb1121..30c6030 100644 --- a/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp +++ b/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp @@ -177,7 +177,7 @@ static MatchResult parseInt(unsigned &result, const char *&ptr, return mlir::success(); } -static mlir::LogicalResult matchString(const char *&ptr, const char *endPtr, +static llvm::LogicalResult matchString(const char *&ptr, const char *endPtr, llvm::StringRef literal) { llvm::StringRef s(ptr, endPtr - ptr); if (s.starts_with(literal)) { @@ -351,7 +351,7 @@ std::string fir::KindMapping::mapToString() const { return result; } -mlir::LogicalResult +llvm::LogicalResult fir::KindMapping::setDefaultKinds(llvm::ArrayRef defs) { if (defs.empty()) { // generic front-end defaults diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp index cbe789f..ae62aff 100644 --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -78,7 +78,7 @@ static bool isAllocatableBoxRef(mlir::Type type) { return boxType && mlir::isa(boxType.getEleTy()); } -mlir::LogicalResult hlfir::AssignOp::verify() { +llvm::LogicalResult hlfir::AssignOp::verify() { mlir::Type lhsType = getLhs().getType(); if (isAllocatableAssignment() && !isAllocatableBoxRef(lhsType)) return emitOpError("lhs must be an allocatable when `realloc` is set"); @@ -137,7 +137,7 @@ void hlfir::DeclareOp::build(mlir::OpBuilder &builder, typeparams, dummy_scope, nameAttr, fortran_attrs, data_attr); } -mlir::LogicalResult hlfir::DeclareOp::verify() { +llvm::LogicalResult hlfir::DeclareOp::verify() { if (getMemref().getType() != getResult(1).getType()) return emitOpError("second result type must match input memref type"); mlir::Type hlfirVariableType = getHLFIRVariableType( @@ -278,7 +278,7 @@ static void printDesignatorComplexPart(mlir::OpAsmPrinter &p, } } -mlir::LogicalResult hlfir::DesignateOp::verify() { +llvm::LogicalResult hlfir::DesignateOp::verify() { mlir::Type memrefType = getMemref().getType(); mlir::Type baseType = getFortranElementOrSequenceType(memrefType); mlir::Type baseElementType = fir::unwrapSequenceType(baseType); @@ -433,7 +433,7 @@ mlir::LogicalResult hlfir::DesignateOp::verify() { // ParentComponentOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::ParentComponentOp::verify() { +llvm::LogicalResult hlfir::ParentComponentOp::verify() { mlir::Type baseType = hlfir::getFortranElementOrSequenceType(getMemref().getType()); auto maybeInputSeqType = mlir::dyn_cast(baseType); @@ -488,7 +488,7 @@ mlir::LogicalResult hlfir::ParentComponentOp::verify() { // LogicalReductionOp //===----------------------------------------------------------------------===// template -static mlir::LogicalResult +static llvm::LogicalResult verifyLogicalReductionOp(LogicalReductionOp reductionOp) { mlir::Operation *op = reductionOp->getOperation(); @@ -539,7 +539,7 @@ verifyLogicalReductionOp(LogicalReductionOp reductionOp) { // AllOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::AllOp::verify() { +llvm::LogicalResult hlfir::AllOp::verify() { return verifyLogicalReductionOp(this); } @@ -554,7 +554,7 @@ void hlfir::AllOp::getEffects( // AnyOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::AnyOp::verify() { +llvm::LogicalResult hlfir::AnyOp::verify() { return verifyLogicalReductionOp(this); } @@ -569,7 +569,7 @@ void hlfir::AnyOp::getEffects( // CountOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::CountOp::verify() { +llvm::LogicalResult hlfir::CountOp::verify() { mlir::Operation *op = getOperation(); auto results = op->getResultTypes(); @@ -626,7 +626,7 @@ getCharacterLengthIfStatic(mlir::Type t) { return std::nullopt; } -mlir::LogicalResult hlfir::ConcatOp::verify() { +llvm::LogicalResult hlfir::ConcatOp::verify() { if (getStrings().size() < 2) return emitOpError("must be provided at least two string operands"); unsigned kind = getCharacterKind(getResult().getType()); @@ -668,7 +668,7 @@ void hlfir::ConcatOp::getEffects( //===----------------------------------------------------------------------===// template -static mlir::LogicalResult +static llvm::LogicalResult verifyArrayAndMaskForReductionOp(NumericalReductionOp reductionOp) { mlir::Value array = reductionOp->getArray(); mlir::Value mask = reductionOp->getMask(); @@ -707,7 +707,7 @@ verifyArrayAndMaskForReductionOp(NumericalReductionOp reductionOp) { } template -static mlir::LogicalResult +static llvm::LogicalResult verifyNumericalReductionOp(NumericalReductionOp reductionOp) { mlir::Operation *op = reductionOp->getOperation(); auto results = op->getResultTypes(); @@ -760,7 +760,7 @@ verifyNumericalReductionOp(NumericalReductionOp reductionOp) { // ProductOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::ProductOp::verify() { +llvm::LogicalResult hlfir::ProductOp::verify() { return verifyNumericalReductionOp(this); } @@ -776,7 +776,7 @@ void hlfir::ProductOp::getEffects( //===----------------------------------------------------------------------===// template -static mlir::LogicalResult +static llvm::LogicalResult verifyCharacterReductionOp(CharacterReductionOp reductionOp) { mlir::Operation *op = reductionOp->getOperation(); auto results = op->getResultTypes(); @@ -821,7 +821,7 @@ verifyCharacterReductionOp(CharacterReductionOp reductionOp) { // MaxvalOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::MaxvalOp::verify() { +llvm::LogicalResult hlfir::MaxvalOp::verify() { mlir::Operation *op = getOperation(); auto results = op->getResultTypes(); @@ -845,7 +845,7 @@ void hlfir::MaxvalOp::getEffects( // MinvalOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::MinvalOp::verify() { +llvm::LogicalResult hlfir::MinvalOp::verify() { mlir::Operation *op = getOperation(); auto results = op->getResultTypes(); @@ -870,7 +870,7 @@ void hlfir::MinvalOp::getEffects( //===----------------------------------------------------------------------===// template -static mlir::LogicalResult +static llvm::LogicalResult verifyResultForMinMaxLoc(NumericalReductionOp reductionOp) { mlir::Operation *op = reductionOp->getOperation(); auto results = op->getResultTypes(); @@ -908,7 +908,7 @@ verifyResultForMinMaxLoc(NumericalReductionOp reductionOp) { return mlir::success(); } -mlir::LogicalResult hlfir::MinlocOp::verify() { +llvm::LogicalResult hlfir::MinlocOp::verify() { auto res = verifyArrayAndMaskForReductionOp(this); if (failed(res)) return res; @@ -927,7 +927,7 @@ void hlfir::MinlocOp::getEffects( // MaxlocOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::MaxlocOp::verify() { +llvm::LogicalResult hlfir::MaxlocOp::verify() { auto res = verifyArrayAndMaskForReductionOp(this); if (failed(res)) return res; @@ -971,7 +971,7 @@ void hlfir::SetLengthOp::getEffects( // SumOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::SumOp::verify() { +llvm::LogicalResult hlfir::SumOp::verify() { return verifyNumericalReductionOp(this); } @@ -986,7 +986,7 @@ void hlfir::SumOp::getEffects( // DotProductOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::DotProductOp::verify() { +llvm::LogicalResult hlfir::DotProductOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); fir::SequenceType lhsTy = mlir::cast( @@ -1042,7 +1042,7 @@ void hlfir::DotProductOp::getEffects( // MatmulOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::MatmulOp::verify() { +llvm::LogicalResult hlfir::MatmulOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); fir::SequenceType lhsTy = mlir::cast( @@ -1111,7 +1111,7 @@ mlir::LogicalResult hlfir::MatmulOp::verify() { return mlir::success(); } -mlir::LogicalResult +llvm::LogicalResult hlfir::MatmulOp::canonicalize(MatmulOp matmulOp, mlir::PatternRewriter &rewriter) { // the only two uses of the transposed matrix should be for the hlfir.matmul @@ -1170,7 +1170,7 @@ void hlfir::MatmulOp::getEffects( // TransposeOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::TransposeOp::verify() { +llvm::LogicalResult hlfir::TransposeOp::verify() { mlir::Value array = getArray(); fir::SequenceType arrayTy = mlir::cast( hlfir::getFortranElementOrSequenceType(array.getType())); @@ -1212,7 +1212,7 @@ void hlfir::TransposeOp::getEffects( // MatmulTransposeOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::MatmulTransposeOp::verify() { +llvm::LogicalResult hlfir::MatmulTransposeOp::verify() { mlir::Value lhs = getLhs(); mlir::Value rhs = getRhs(); fir::SequenceType lhsTy = mlir::cast( @@ -1350,7 +1350,7 @@ void hlfir::EndAssociateOp::build(mlir::OpBuilder &builder, associate.getMustFreeStrorageFlag()); } -mlir::LogicalResult hlfir::EndAssociateOp::verify() { +llvm::LogicalResult hlfir::EndAssociateOp::verify() { mlir::Value var = getVar(); if (hlfir::mayHaveAllocatableComponent(var.getType()) && !hlfir::isFortranEntity(var)) @@ -1438,7 +1438,7 @@ mlir::Value hlfir::ElementalOp::getElementEntity() { return mlir::cast(getBody()->back()).getElementValue(); } -mlir::LogicalResult hlfir::ElementalOp::verify() { +llvm::LogicalResult hlfir::ElementalOp::verify() { mlir::Value mold = getMold(); hlfir::ExprType resultType = mlir::cast(getType()); if (!!mold != resultType.isPolymorphic()) @@ -1476,7 +1476,7 @@ void hlfir::NullOp::build(mlir::OpBuilder &builder, // DestroyOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::DestroyOp::verify() { +llvm::LogicalResult hlfir::DestroyOp::verify() { if (mustFinalizeExpr()) { mlir::Value expr = getExpr(); hlfir::ExprType exprTy = mlir::cast(expr.getType()); @@ -1517,7 +1517,7 @@ std::size_t hlfir::ShapeOfOp::getRank() { return shape.getRank(); } -mlir::LogicalResult hlfir::ShapeOfOp::verify() { +llvm::LogicalResult hlfir::ShapeOfOp::verify() { mlir::Value expr = getExpr(); hlfir::ExprType exprTy = mlir::cast(expr.getType()); std::size_t exprRank = exprTy.getShape().size(); @@ -1532,7 +1532,7 @@ mlir::LogicalResult hlfir::ShapeOfOp::verify() { return mlir::success(); } -mlir::LogicalResult +llvm::LogicalResult hlfir::ShapeOfOp::canonicalize(ShapeOfOp shapeOf, mlir::PatternRewriter &rewriter) { // if extent information is available at compile time, immediately fold the @@ -1544,11 +1544,11 @@ hlfir::ShapeOfOp::canonicalize(ShapeOfOp shapeOf, mlir::Value shape = hlfir::genExprShape(rewriter, loc, expr); if (!shape) // shape information is not available at compile time - return mlir::LogicalResult::failure(); + return llvm::LogicalResult::failure(); rewriter.replaceAllUsesWith(shapeOf.getResult(), shape); rewriter.eraseOp(shapeOf); - return mlir::LogicalResult::success(); + return llvm::LogicalResult::success(); } //===----------------------------------------------------------------------===// @@ -1563,7 +1563,7 @@ void hlfir::GetExtentOp::build(mlir::OpBuilder &builder, build(builder, result, indexTy, shape, dimAttr); } -mlir::LogicalResult hlfir::GetExtentOp::verify() { +llvm::LogicalResult hlfir::GetExtentOp::verify() { fir::ShapeType shapeTy = mlir::cast(getShape().getType()); std::uint64_t rank = shapeTy.getRank(); llvm::APInt dim = getDim(); @@ -1640,7 +1640,7 @@ static mlir::Operation *getTerminator(mlir::Region ®ion) { return ®ion.back().back(); } -mlir::LogicalResult hlfir::RegionAssignOp::verify() { +llvm::LogicalResult hlfir::RegionAssignOp::verify() { if (!mlir::isa_and_nonnull(getTerminator(getRhsRegion()))) return emitOpError( "right-hand side region must be terminated by an hlfir.yield"); @@ -1692,7 +1692,7 @@ void hlfir::ElementalAddrOp::build(mlir::OpBuilder &builder, odsState.addRegion(); } -mlir::LogicalResult hlfir::ElementalAddrOp::verify() { +llvm::LogicalResult hlfir::ElementalAddrOp::verify() { hlfir::YieldOp yieldOp = mlir::dyn_cast_or_null(getTerminator(getBody())); if (!yieldOp) @@ -1729,7 +1729,7 @@ mlir::Region *hlfir::ElementalAddrOp::getElementCleanup() { // OrderedAssignmentTreeOpInterface //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::OrderedAssignmentTreeOpInterface::verifyImpl() { +llvm::LogicalResult hlfir::OrderedAssignmentTreeOpInterface::verifyImpl() { if (mlir::Region *body = getSubTreeRegion()) if (!body->empty()) for (mlir::Operation &op : body->front()) @@ -1812,7 +1812,7 @@ static bool yieldsLogical(mlir::Region ®ion, bool mustBeScalarI1) { hlfir::getFortranElementOrSequenceType(yieldType)); } -mlir::LogicalResult hlfir::ForallMaskOp::verify() { +llvm::LogicalResult hlfir::ForallMaskOp::verify() { if (!yieldsLogical(getMaskRegion(), /*mustBeScalarI1=*/true)) return emitOpError("mask region must yield a scalar i1"); mlir::Operation *op = getOperation(); @@ -1828,7 +1828,7 @@ mlir::LogicalResult hlfir::ForallMaskOp::verify() { //===----------------------------------------------------------------------===// template -static mlir::LogicalResult verifyWhereAndElseWhereBody(ConcreteOp &concreteOp) { +static llvm::LogicalResult verifyWhereAndElseWhereBody(ConcreteOp &concreteOp) { for (mlir::Operation &op : concreteOp.getBody().front()) if (mlir::isa(op)) return concreteOp.emitOpError( @@ -1836,13 +1836,13 @@ static mlir::LogicalResult verifyWhereAndElseWhereBody(ConcreteOp &concreteOp) { return mlir::success(); } -mlir::LogicalResult hlfir::WhereOp::verify() { +llvm::LogicalResult hlfir::WhereOp::verify() { if (!yieldsLogical(getMaskRegion(), /*mustBeScalarI1=*/false)) return emitOpError("mask region must yield a logical array"); return verifyWhereAndElseWhereBody(*this); } -mlir::LogicalResult hlfir::ElseWhereOp::verify() { +llvm::LogicalResult hlfir::ElseWhereOp::verify() { if (!getMaskRegion().empty()) if (!yieldsLogical(getMaskRegion(), /*mustBeScalarI1=*/false)) return emitOpError( @@ -1854,7 +1854,7 @@ mlir::LogicalResult hlfir::ElseWhereOp::verify() { // ForallIndexOp //===----------------------------------------------------------------------===// -mlir::LogicalResult +llvm::LogicalResult hlfir::ForallIndexOp::canonicalize(hlfir::ForallIndexOp indexOp, mlir::PatternRewriter &rewriter) { for (mlir::Operation *user : indexOp->getResult(0).getUsers()) @@ -1878,7 +1878,7 @@ hlfir::ForallIndexOp::canonicalize(hlfir::ForallIndexOp indexOp, // CharExtremumOp //===----------------------------------------------------------------------===// -mlir::LogicalResult hlfir::CharExtremumOp::verify() { +llvm::LogicalResult hlfir::CharExtremumOp::verify() { if (getStrings().size() < 2) return emitOpError("must be provided at least two string operands"); unsigned kind = getCharacterKind(getResult().getType()); @@ -1922,7 +1922,7 @@ void hlfir::CharExtremumOp::getEffects( // GetLength //===----------------------------------------------------------------------===// -mlir::LogicalResult +llvm::LogicalResult hlfir::GetLengthOp::canonicalize(GetLengthOp getLength, mlir::PatternRewriter &rewriter) { mlir::Location loc = getLength.getLoc(); diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp index e292b56..a70a6b3 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp @@ -30,7 +30,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/ADT/TypeSwitch.h" @@ -180,7 +179,7 @@ struct AsExprOpConversion : public mlir::OpConversionPattern { using mlir::OpConversionPattern::OpConversionPattern; explicit AsExprOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::AsExprOp asExpr, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = asExpr->getLoc(); @@ -205,7 +204,7 @@ struct ShapeOfOpConversion : public mlir::OpConversionPattern { using mlir::OpConversionPattern::OpConversionPattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ShapeOfOp shapeOf, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = shapeOf.getLoc(); @@ -237,7 +236,7 @@ struct ApplyOpConversion : public mlir::OpConversionPattern { using mlir::OpConversionPattern::OpConversionPattern; explicit ApplyOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ApplyOp apply, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = apply->getLoc(); @@ -262,7 +261,7 @@ struct AssignOpConversion : public mlir::OpConversionPattern { using mlir::OpConversionPattern::OpConversionPattern; explicit AssignOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::AssignOp assign, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { llvm::SmallVector newOperands; @@ -279,7 +278,7 @@ struct ConcatOpConversion : public mlir::OpConversionPattern { using mlir::OpConversionPattern::OpConversionPattern; explicit ConcatOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ConcatOp concat, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = concat->getLoc(); @@ -318,7 +317,7 @@ struct SetLengthOpConversion using mlir::OpConversionPattern::OpConversionPattern; explicit SetLengthOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::SetLengthOp setLength, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = setLength->getLoc(); @@ -351,7 +350,7 @@ struct GetLengthOpConversion using mlir::OpConversionPattern::OpConversionPattern; explicit GetLengthOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::GetLengthOp getLength, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = getLength->getLoc(); @@ -441,7 +440,7 @@ struct AssociateOpConversion using mlir::OpConversionPattern::OpConversionPattern; explicit AssociateOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::AssociateOp associate, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = associate->getLoc(); @@ -660,7 +659,7 @@ struct EndAssociateOpConversion using mlir::OpConversionPattern::OpConversionPattern; explicit EndAssociateOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::EndAssociateOp endAssociate, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = endAssociate->getLoc(); @@ -677,7 +676,7 @@ struct DestroyOpConversion using mlir::OpConversionPattern::OpConversionPattern; explicit DestroyOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::DestroyOp destroy, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { // If expr was bufferized on the heap, now is time to deallocate the buffer. @@ -706,7 +705,7 @@ struct NoReassocOpConversion using mlir::OpConversionPattern::OpConversionPattern; explicit NoReassocOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::NoReassocOp noreassoc, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = noreassoc->getLoc(); @@ -767,7 +766,7 @@ struct ElementalOpConversion // by the nesting level of ElementalOp's. setHasBoundedRewriteRecursion(); } - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ElementalOp elemental, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = elemental->getLoc(); @@ -860,7 +859,7 @@ struct CharExtremumOpConversion using mlir::OpConversionPattern::OpConversionPattern; explicit CharExtremumOpConversion(mlir::MLIRContext *ctx) : mlir::OpConversionPattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::CharExtremumOp char_extremum, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = char_extremum->getLoc(); diff --git a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp index 74bbab0..9820595 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp @@ -38,7 +38,7 @@ class AssignOpConversion : public mlir::OpRewritePattern { public: explicit AssignOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::AssignOp assignOp, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = assignOp->getLoc(); @@ -231,7 +231,7 @@ public: return {res[0], res[1]}; } - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::CopyInOp copyInOp, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = copyInOp.getLoc(); @@ -249,7 +249,7 @@ public: explicit CopyOutOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::CopyOutOp copyOutOp, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = copyOutOp.getLoc(); @@ -290,7 +290,7 @@ public: explicit DeclareOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::DeclareOp declareOp, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = declareOp->getLoc(); @@ -428,7 +428,7 @@ public: explicit DesignateOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::DesignateOp designate, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = designate.getLoc(); @@ -648,7 +648,7 @@ public: explicit ParentComponentOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ParentComponentOp parentComponent, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = parentComponent.getLoc(); @@ -696,7 +696,7 @@ public: explicit NoReassocOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::NoReassocOp noreassoc, mlir::PatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(noreassoc, @@ -709,7 +709,7 @@ class NullOpConversion : public mlir::OpRewritePattern { public: explicit NullOpConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::NullOp nullop, mlir::PatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(nullop, nullop.getType()); @@ -722,7 +722,7 @@ class GetExtentOpConversion public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::GetExtentOp getExtentOp, mlir::PatternRewriter &rewriter) const override { mlir::Value shape = getExtentOp.getShape(); diff --git a/flang/lib/Optimizer/HLFIR/Transforms/InlineElementals.cpp b/flang/lib/Optimizer/HLFIR/Transforms/InlineElementals.cpp index 4b0b859..769e14b1 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/InlineElementals.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/InlineElementals.cpp @@ -73,7 +73,7 @@ class InlineElementalConversion public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ElementalOp elemental, mlir::PatternRewriter &rewriter) const override { std::optional> maybeTuple = diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp index 0347bec..bfb4148 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp @@ -22,7 +22,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include @@ -235,7 +234,7 @@ protected: }; public: - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(OP operation, mlir::PatternRewriter &rewriter) const override { std::string opName; @@ -311,7 +310,7 @@ using AllOpConversion = HlfirReductionIntrinsicConversion; struct CountOpConversion : public HlfirIntrinsicConversion { using HlfirIntrinsicConversion::HlfirIntrinsicConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::CountOp count, mlir::PatternRewriter &rewriter) const override { fir::FirOpBuilder builder{rewriter, count.getOperation()}; @@ -345,7 +344,7 @@ struct CountOpConversion : public HlfirIntrinsicConversion { struct MatmulOpConversion : public HlfirIntrinsicConversion { using HlfirIntrinsicConversion::HlfirIntrinsicConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::MatmulOp matmul, mlir::PatternRewriter &rewriter) const override { fir::FirOpBuilder builder{rewriter, matmul.getOperation()}; @@ -376,7 +375,7 @@ struct DotProductOpConversion : public HlfirIntrinsicConversion { using HlfirIntrinsicConversion::HlfirIntrinsicConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::DotProductOp dotProduct, mlir::PatternRewriter &rewriter) const override { fir::FirOpBuilder builder{rewriter, dotProduct.getOperation()}; @@ -407,7 +406,7 @@ class TransposeOpConversion : public HlfirIntrinsicConversion { using HlfirIntrinsicConversion::HlfirIntrinsicConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::TransposeOp transpose, mlir::PatternRewriter &rewriter) const override { fir::FirOpBuilder builder{rewriter, transpose.getOperation()}; @@ -437,7 +436,7 @@ struct MatmulTransposeOpConversion using HlfirIntrinsicConversion< hlfir::MatmulTransposeOp>::HlfirIntrinsicConversion; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::MatmulTransposeOp multranspose, mlir::PatternRewriter &rewriter) const override { fir::FirOpBuilder builder{rewriter, multranspose.getOperation()}; diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp index a1a89bb..85dd517 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp @@ -1309,7 +1309,7 @@ static void lower(hlfir::OrderedAssignmentTreeOpInterface root, /// Shared rewrite entry point for all the ordered assignment tree root /// operations. It calls the scheduler and then apply the schedule. -static mlir::LogicalResult rewrite(hlfir::OrderedAssignmentTreeOpInterface root, +static llvm::LogicalResult rewrite(hlfir::OrderedAssignmentTreeOpInterface root, bool tryFusingAssignments, mlir::PatternRewriter &rewriter) { hlfir::Schedule schedule = @@ -1337,7 +1337,7 @@ public: explicit ForallOpConversion(mlir::MLIRContext *ctx, bool tryFusingAssignments) : OpRewritePattern{ctx}, tryFusingAssignments{tryFusingAssignments} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ForallOp forallOp, mlir::PatternRewriter &rewriter) const override { auto root = mlir::cast( @@ -1354,7 +1354,7 @@ public: explicit WhereOpConversion(mlir::MLIRContext *ctx, bool tryFusingAssignments) : OpRewritePattern{ctx}, tryFusingAssignments{tryFusingAssignments} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::WhereOp whereOp, mlir::PatternRewriter &rewriter) const override { auto root = mlir::cast( @@ -1370,7 +1370,7 @@ public: explicit RegionAssignConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::RegionAssignOp regionAssignOp, mlir::PatternRewriter &rewriter) const override { auto root = mlir::cast( diff --git a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp index 1dfa2f9..c5b8095 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp @@ -89,7 +89,7 @@ private: public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::ElementalOp elemental, mlir::PatternRewriter &rewriter) const override; }; @@ -465,7 +465,7 @@ ElementalAssignBufferization::findMatch(hlfir::ElementalOp elemental) { return match; } -mlir::LogicalResult ElementalAssignBufferization::matchAndRewrite( +llvm::LogicalResult ElementalAssignBufferization::matchAndRewrite( hlfir::ElementalOp elemental, mlir::PatternRewriter &rewriter) const { std::optional match = findMatch(elemental); if (!match) @@ -519,12 +519,12 @@ private: public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::AssignOp assign, mlir::PatternRewriter &rewriter) const override; }; -mlir::LogicalResult BroadcastAssignBufferization::matchAndRewrite( +llvm::LogicalResult BroadcastAssignBufferization::matchAndRewrite( hlfir::AssignOp assign, mlir::PatternRewriter &rewriter) const { // Since RHS is a scalar and LHS is an array, LHS must be allocated // in a conforming Fortran program, and LHS cannot be reallocated @@ -587,12 +587,12 @@ private: public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::AssignOp assign, mlir::PatternRewriter &rewriter) const override; }; -mlir::LogicalResult VariableAssignBufferization::matchAndRewrite( +llvm::LogicalResult VariableAssignBufferization::matchAndRewrite( hlfir::AssignOp assign, mlir::PatternRewriter &rewriter) const { if (assign.isAllocatableAssignment()) return rewriter.notifyMatchFailure(assign, "AssignOp may imply allocation"); @@ -716,7 +716,7 @@ class ReductionElementalConversion : public mlir::OpRewritePattern { public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(Op op, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = op.getLoc(); hlfir::ElementalOp elemental = @@ -817,7 +817,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern { public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(Op mloc, mlir::PatternRewriter &rewriter) const override { if (!mloc.getMask() || mloc.getDim() || mloc.getBack()) return rewriter.notifyMatchFailure(mloc, diff --git a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp index 6153c82..60b06437 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/SimplifyHLFIRIntrinsics.cpp @@ -35,7 +35,7 @@ class TransposeAsElementalConversion public: using mlir::OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(hlfir::TransposeOp transpose, mlir::PatternRewriter &rewriter) const override { mlir::Location loc = transpose.getLoc(); diff --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp index 85472cd..3906aa5 100644 --- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp +++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp @@ -84,7 +84,7 @@ public: CallConversion(mlir::MLIRContext *context, bool shouldBoxResult) : OpRewritePattern(context, 1), shouldBoxResult{shouldBoxResult} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(Op op, mlir::PatternRewriter &rewriter) const override { auto loc = op.getLoc(); auto result = op->getResult(0); @@ -192,7 +192,7 @@ public: using OpRewritePattern::OpRewritePattern; SaveResultOpConversion(mlir::MLIRContext *context) : OpRewritePattern(context) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::SaveResultOp op, mlir::PatternRewriter &rewriter) const override { rewriter.eraseOp(op); @@ -205,7 +205,7 @@ public: using OpRewritePattern::OpRewritePattern; ReturnOpConversion(mlir::MLIRContext *context, mlir::Value newArg) : OpRewritePattern(context), newArg{newArg} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::func::ReturnOp ret, mlir::PatternRewriter &rewriter) const override { auto loc = ret.getLoc(); @@ -258,7 +258,7 @@ public: using OpRewritePattern::OpRewritePattern; AddrOfOpConversion(mlir::MLIRContext *context, bool shouldBoxResult) : OpRewritePattern(context), shouldBoxResult{shouldBoxResult} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AddrOfOp addrOf, mlir::PatternRewriter &rewriter) const override { auto oldFuncTy = mlir::cast(addrOf.getType()); @@ -432,4 +432,4 @@ public: }; } // end anonymous namespace -} // namespace fir \ No newline at end of file +} // namespace fir diff --git a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp index b4523a0..c416302d 100644 --- a/flang/lib/Optimizer/Transforms/AffineDemotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffineDemotion.cpp @@ -95,7 +95,7 @@ public: class ConvertConversion : public mlir::OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ConvertOp op, mlir::PatternRewriter &rewriter) const override { if (mlir::isa(op.getRes().getType())) { @@ -133,7 +133,7 @@ mlir::Type convertMemRef(mlir::MemRefType type) { class StdAllocConversion : public mlir::OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(memref::AllocOp op, mlir::PatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp(op, convertMemRef(op.getType()), diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp index 7d0131a..43fccf5 100644 --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -453,7 +453,7 @@ public: AffineLoopConversion(mlir::MLIRContext *context, AffineFunctionAnalysis &afa) : OpRewritePattern(context), functionAnalysis(afa) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::DoLoopOp loop, mlir::PatternRewriter &rewriter) const override { LLVM_DEBUG(llvm::dbgs() << "AffineLoopConversion: rewriting loop:\n"; @@ -546,7 +546,7 @@ public: using OpRewritePattern::OpRewritePattern; AffineIfConversion(mlir::MLIRContext *context, AffineFunctionAnalysis &afa) : OpRewritePattern(context) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::IfOp op, mlir::PatternRewriter &rewriter) const override { LLVM_DEBUG(llvm::dbgs() << "AffineIfConversion: rewriting if:\n"; diff --git a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp index ebc1862..8544d17 100644 --- a/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp +++ b/flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp @@ -796,7 +796,7 @@ class ArrayLoadConversion : public mlir::OpRewritePattern { public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ArrayLoadOp load, mlir::PatternRewriter &rewriter) const override { LLVM_DEBUG(llvm::dbgs() << "replace load " << load << " with undef.\n"); @@ -810,7 +810,7 @@ class ArrayMergeStoreConversion public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ArrayMergeStoreOp store, mlir::PatternRewriter &rewriter) const override { LLVM_DEBUG(llvm::dbgs() << "marking store " << store << " as dead.\n"); @@ -1248,7 +1248,7 @@ public: const OperationUseMapT &m) : ArrayUpdateConversionBase{ctx, a, m} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ArrayUpdateOp update, mlir::PatternRewriter &rewriter) const override { auto loc = update.getLoc(); @@ -1276,7 +1276,7 @@ public: const OperationUseMapT &m) : ArrayUpdateConversionBase{ctx, a, m} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ArrayModifyOp modify, mlir::PatternRewriter &rewriter) const override { auto loc = modify.getLoc(); @@ -1298,7 +1298,7 @@ public: const OperationUseMapT &m) : OpRewritePattern{ctx}, useMap{m} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ArrayFetchOp fetch, mlir::PatternRewriter &rewriter) const override { auto *op = fetch.getOperation(); @@ -1329,7 +1329,7 @@ public: const OperationUseMapT &m) : ArrayUpdateConversionBase{ctx, a, m} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ArrayAccessOp access, mlir::PatternRewriter &rewriter) const override { auto *op = access.getOperation(); @@ -1362,7 +1362,7 @@ public: explicit ArrayAmendConversion(mlir::MLIRContext *ctx) : OpRewritePattern{ctx} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ArrayAmendOp amend, mlir::PatternRewriter &rewriter) const override { auto *op = amend.getOperation(); diff --git a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp index 5dfc5009..2c9c73e 100644 --- a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp @@ -63,7 +63,7 @@ public: : mlir::OpRewritePattern(context), symbolTable{symbolTable}, kindMap{kindMap} {}; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::ReboxAssumedRankOp rebox, mlir::PatternRewriter &rewriter) const override { fir::FirOpBuilder builder{rewriter, kindMap, symbolTable}; @@ -123,7 +123,7 @@ public: : mlir::OpRewritePattern(context), symbolTable{symbolTable}, kindMap{kindMap} {}; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::IsAssumedSizeOp isAssumedSizeOp, mlir::PatternRewriter &rewriter) const override { fir::FirOpBuilder builder{rewriter, kindMap, symbolTable}; diff --git a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp index 44baad7..aee7e8c 100644 --- a/flang/lib/Optimizer/Transforms/CharacterConversion.cpp +++ b/flang/lib/Optimizer/Transforms/CharacterConversion.cpp @@ -38,7 +38,7 @@ class CharacterConvertConversion public: using OpRewritePattern::OpRewritePattern; - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::CharConvertOp conv, mlir::PatternRewriter &rewriter) const override { auto kindMap = fir::getKindMapping(conv->getParentOfType()); diff --git a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp index f7074a7..7d0b8b3 100644 --- a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp +++ b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp @@ -37,7 +37,7 @@ public: CallOpRewriter(mlir::MLIRContext *ctx, const mlir::DominanceInfo &_di) : OpRewritePattern(ctx), di(_di) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::CallOp callOp, mlir::PatternRewriter &rewriter) const override { LLVM_DEBUG(llvm::dbgs() << "Processing call op: " << callOp << "\n"); diff --git a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp index 1af5a68..3b79d6d 100644 --- a/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp +++ b/flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp @@ -47,7 +47,7 @@ public: : mlir::OpRewritePattern(ctx), forceLoopToExecuteOnce(forceLoopToExecuteOnce), setNSW(setNSW) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(DoLoopOp loop, mlir::PatternRewriter &rewriter) const override { auto loc = loop.getLoc(); @@ -162,7 +162,7 @@ public: CfgIfConv(mlir::MLIRContext *ctx, bool forceLoopToExecuteOnce, bool setNSW) : mlir::OpRewritePattern(ctx) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(IfOp ifOp, mlir::PatternRewriter &rewriter) const override { auto loc = ifOp.getLoc(); @@ -228,7 +228,7 @@ public: bool setNSW) : mlir::OpRewritePattern(ctx), setNSW(setNSW) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::IterWhileOp whileOp, mlir::PatternRewriter &rewriter) const override { auto loc = whileOp.getLoc(); diff --git a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp index ada67b4..03b1ae8 100644 --- a/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp +++ b/flang/lib/Optimizer/Transforms/MemoryAllocation.cpp @@ -100,7 +100,7 @@ public: llvm::ArrayRef rets) : OpRewritePattern(ctx), returnOps(rets) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AllocaOp alloca, mlir::PatternRewriter &rewriter) const override { auto loc = alloca.getLoc(); diff --git a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp index 76c12d2..57f19f2 100644 --- a/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp +++ b/flang/lib/Optimizer/Transforms/PolymorphicOpConversion.cpp @@ -50,7 +50,7 @@ public: SelectTypeConv(mlir::MLIRContext *ctx) : mlir::OpConversionPattern(ctx) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::SelectTypeOp selectType, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override; @@ -60,7 +60,7 @@ private: mlir::Type ty, mlir::ModuleOp mod, mlir::PatternRewriter &rewriter) const; - mlir::LogicalResult genTypeLadderStep(mlir::Location loc, + llvm::LogicalResult genTypeLadderStep(mlir::Location loc, mlir::Value selector, mlir::Attribute attr, mlir::Block *dest, std::optional destOps, @@ -81,7 +81,7 @@ struct DispatchOpConv : public OpConversionPattern { : mlir::OpConversionPattern(ctx), bindingTables(bindingTables) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::DispatchOp dispatch, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const override { mlir::Location loc = dispatch.getLoc(); @@ -135,7 +135,7 @@ struct DispatchOpConv : public OpConversionPattern { // %18 = fir.field_index proc, !fir.type<_QM__fortran_type_infoTbinding> // %19 = fir.coordinate_of %17, %18 : (!fir.ref>, !fir.field) -> !fir.ref> // %20 = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_funptr> - // %21 = fir.coordinate_of %19, %20 : (!fir.ref>, !fir.field) -> !fir.ref + // %21 = fir.coordinate_of %19, %20 : (!fir.ref>, !fir.field) -> !fir.ref // %22 = fir.load %21 : !fir.ref // %23 = fir.convert %22 : (i64) -> (() -> ()) // fir.call %23() : () -> () @@ -217,7 +217,7 @@ private: class PolymorphicOpConversion : public fir::impl::PolymorphicOpConversionBase { public: - mlir::LogicalResult initialize(mlir::MLIRContext *ctx) override { + llvm::LogicalResult initialize(mlir::MLIRContext *ctx) override { return mlir::success(); } @@ -250,7 +250,7 @@ public: }; } // namespace -mlir::LogicalResult SelectTypeConv::matchAndRewrite( +llvm::LogicalResult SelectTypeConv::matchAndRewrite( fir::SelectTypeOp selectType, OpAdaptor adaptor, mlir::ConversionPatternRewriter &rewriter) const { auto operands = adaptor.getOperands(); @@ -341,7 +341,7 @@ mlir::LogicalResult SelectTypeConv::matchAndRewrite( return mlir::success(); } -mlir::LogicalResult SelectTypeConv::genTypeLadderStep( +llvm::LogicalResult SelectTypeConv::genTypeLadderStep( mlir::Location loc, mlir::Value selector, mlir::Attribute attr, mlir::Block *dest, std::optional destOps, mlir::ModuleOp mod, mlir::PatternRewriter &rewriter, diff --git a/flang/lib/Optimizer/Transforms/StackArrays.cpp b/flang/lib/Optimizer/Transforms/StackArrays.cpp index 7157b55..e8fa70eb 100644 --- a/flang/lib/Optimizer/Transforms/StackArrays.cpp +++ b/flang/lib/Optimizer/Transforms/StackArrays.cpp @@ -25,7 +25,6 @@ #include "mlir/IR/Value.h" #include "mlir/Interfaces/LoopLikeInterface.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "mlir/Transforms/Passes.h" #include "llvm/ADT/DenseMap.h" @@ -180,7 +179,7 @@ public: private: llvm::DenseMap funcMaps; - mlir::LogicalResult analyseFunction(mlir::Operation *func); + llvm::LogicalResult analyseFunction(mlir::Operation *func); }; /// Converts a fir.allocmem to a fir.alloca @@ -191,7 +190,7 @@ public: const StackArraysAnalysisWrapper::AllocMemMap &candidateOps) : OpRewritePattern(ctx), candidateOps{candidateOps} {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(fir::AllocMemOp allocmem, mlir::PatternRewriter &rewriter) const override; @@ -415,7 +414,7 @@ void AllocationAnalysis::processOperation(mlir::Operation *op) { visitOperationImpl(op, *before, after); } -mlir::LogicalResult +llvm::LogicalResult StackArraysAnalysisWrapper::analyseFunction(mlir::Operation *func) { assert(mlir::isa(func)); size_t nAllocs = 0; @@ -507,7 +506,7 @@ static mlir::Value convertAllocationType(mlir::PatternRewriter &rewriter, return conv; } -mlir::LogicalResult +llvm::LogicalResult AllocMemConversion::matchAndRewrite(fir::AllocMemOp allocmem, mlir::PatternRewriter &rewriter) const { auto oldInsertionPt = rewriter.saveInsertionPoint(); diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp index 3485c14..e5e41ad 100644 --- a/flang/tools/bbc/bbc.cpp +++ b/flang/tools/bbc/bbc.cpp @@ -269,7 +269,7 @@ createTargetMachine(llvm::StringRef targetTriple, std::string &error) { /// of the pass manager, allowing it to be invoked as soon as it's /// required without impacting the main pass pipeline that may be invoked /// more than once for verification. -static mlir::LogicalResult runOpenMPPasses(mlir::ModuleOp mlirModule) { +static llvm::LogicalResult runOpenMPPasses(mlir::ModuleOp mlirModule) { mlir::PassManager pm(mlirModule->getName(), mlir::OpPassManager::Nesting::Implicit); fir::createOpenMPFIRPassPipeline(pm, enableOpenMPDevice); @@ -285,7 +285,7 @@ static mlir::LogicalResult runOpenMPPasses(mlir::ModuleOp mlirModule) { // Translate Fortran input to FIR, a dialect of MLIR. //===----------------------------------------------------------------------===// -static mlir::LogicalResult convertFortranSourceToMLIR( +static llvm::LogicalResult convertFortranSourceToMLIR( std::string path, Fortran::parser::Options options, const ProgramName &programPrefix, Fortran::semantics::SemanticsContext &semanticsContext, diff --git a/flang/tools/tco/tco.cpp b/flang/tools/tco/tco.cpp index 399ea13..34ac0e1 100644 --- a/flang/tools/tco/tco.cpp +++ b/flang/tools/tco/tco.cpp @@ -74,7 +74,7 @@ static void printModule(mlir::ModuleOp mod, raw_ostream &output) { } // compile a .fir file -static mlir::LogicalResult +static llvm::LogicalResult compileFIR(const mlir::PassPipelineCLParser &passPipeline) { // check that there is a file to load ErrorOr> fileOrErr = diff --git a/llvm/include/llvm/Support/LogicalResult.h b/llvm/include/llvm/Support/LogicalResult.h new file mode 100644 index 0000000..2cfd866b --- /dev/null +++ b/llvm/include/llvm/Support/LogicalResult.h @@ -0,0 +1,128 @@ +//===- LogicalResult.h - Utilities for handling success/failure -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_LOGICALRESULT_H +#define LLVM_SUPPORT_LOGICALRESULT_H + +#include +#include + +namespace llvm { +/// This class represents an efficient way to signal success or failure. It +/// should be preferred over the use of `bool` when appropriate, as it avoids +/// all of the ambiguity that arises in interpreting a boolean result. This +/// class is marked as NODISCARD to ensure that the result is processed. Users +/// may explicitly discard a result by using `(void)`, e.g. +/// `(void)functionThatReturnsALogicalResult();`. Given the intended nature of +/// this class, it generally shouldn't be used as the result of functions that +/// very frequently have the result ignored. This class is intended to be used +/// in conjunction with the utility functions below. +struct [[nodiscard]] LogicalResult { +public: + /// If isSuccess is true a `success` result is generated, otherwise a + /// 'failure' result is generated. + static LogicalResult success(bool IsSuccess = true) { + return LogicalResult(IsSuccess); + } + + /// If isFailure is true a `failure` result is generated, otherwise a + /// 'success' result is generated. + static LogicalResult failure(bool IsFailure = true) { + return LogicalResult(!IsFailure); + } + + /// Returns true if the provided LogicalResult corresponds to a success value. + constexpr bool succeeded() const { return IsSuccess; } + + /// Returns true if the provided LogicalResult corresponds to a failure value. + constexpr bool failed() const { return !IsSuccess; } + +private: + LogicalResult(bool IsSuccess) : IsSuccess(IsSuccess) {} + + /// Boolean indicating if this is a success result, if false this is a + /// failure result. + bool IsSuccess; +}; + +/// Utility function to generate a LogicalResult. If isSuccess is true a +/// `success` result is generated, otherwise a 'failure' result is generated. +inline LogicalResult success(bool IsSuccess = true) { + return LogicalResult::success(IsSuccess); +} + +/// Utility function to generate a LogicalResult. If isFailure is true a +/// `failure` result is generated, otherwise a 'success' result is generated. +inline LogicalResult failure(bool IsFailure = true) { + return LogicalResult::failure(IsFailure); +} + +/// Utility function that returns true if the provided LogicalResult corresponds +/// to a success value. +inline bool succeeded(LogicalResult Result) { return Result.succeeded(); } + +/// Utility function that returns true if the provided LogicalResult corresponds +/// to a failure value. +inline bool failed(LogicalResult Result) { return Result.failed(); } + +/// This class provides support for representing a failure result, or a valid +/// value of type `T`. This allows for integrating with LogicalResult, while +/// also providing a value on the success path. +template class [[nodiscard]] FailureOr : public std::optional { +public: + /// Allow constructing from a LogicalResult. The result *must* be a failure. + /// Success results should use a proper instance of type `T`. + FailureOr(LogicalResult Result) { + assert(failed(Result) && + "success should be constructed with an instance of 'T'"); + } + FailureOr() : FailureOr(failure()) {} + FailureOr(T &&Y) : std::optional(std::forward(Y)) {} + FailureOr(const T &Y) : std::optional(Y) {} + template ::value> * = nullptr> + FailureOr(const FailureOr &Other) + : std::optional(failed(Other) ? std::optional() + : std::optional(*Other)) {} + + operator LogicalResult() const { return success(has_value()); } + +private: + /// Hide the bool conversion as it easily creates confusion. + using std::optional::operator bool; + using std::optional::has_value; +}; + +/// Wrap a value on the success path in a FailureOr of the same value type. +template >> +inline auto success(T &&Y) { + return FailureOr>(std::forward(Y)); +} + +/// This class represents success/failure for parsing-like operations that find +/// it important to chain together failable operations with `||`. This is an +/// extended version of `LogicalResult` that allows for explicit conversion to +/// bool. +/// +/// This class should not be used for general error handling cases - we prefer +/// to keep the logic explicit with the `succeeded`/`failed` predicates. +/// However, traditional monadic-style parsing logic can sometimes get +/// swallowed up in boilerplate without this, so we provide this for narrow +/// cases where it is important. +/// +class [[nodiscard]] ParseResult : public LogicalResult { +public: + ParseResult(LogicalResult Result = success()) : LogicalResult(Result) {} + + /// Failure is true in a boolean context. + constexpr explicit operator bool() const { return failed(); } +}; +} // namespace llvm + +#endif // LLVM_SUPPORT_LOGICALRESULT_H diff --git a/mlir/docs/PDLL.md b/mlir/docs/PDLL.md index 340940f..f565115 100644 --- a/mlir/docs/PDLL.md +++ b/mlir/docs/PDLL.md @@ -277,7 +277,7 @@ Pattern { // * Match Section // - Describes the input IR. let root = op(op(arg: Value)); - + // * Rewrite Section // - Describes how to transform the IR. // - Last statement starts the rewrite. @@ -1009,7 +1009,7 @@ Pattern { // Return a tuple of values. let result = ExtractMultipleResults(op: op); - // Index the tuple elements by index, or by name. + // Index the tuple elements by index, or by name. replace op with (result.0, result.1, result.result1); } ``` @@ -1150,7 +1150,7 @@ same name. See the ["type translation"](#native-constraint-type-translations) be detailed information on how PDLL types are converted to native types. In addition to the PDLL arguments, the code block may also access the current `PatternRewriter` using `rewriter`. The result type of the native constraint function is implicitly defined -as a `::mlir::LogicalResult`. +as a `::llvm::LogicalResult`. Taking the constraints defined above as an example, these function would roughly be translated into: @@ -1220,7 +1220,7 @@ was imported: * `Attr` constraints - Imported `Attr` constraints utilize the `storageType` field for native type translation. - + * `Type` constraints - Imported `Type` constraints utilize the `cppClassName` field for native type translation. @@ -1310,7 +1310,7 @@ Pattern { // A pattern that replaces the root operation with another operation. // Note that when an operation is used as the replacement, we can infer its // result types from the input operation. In these cases, the result -// types of replacement operation may be elided. +// types of replacement operation may be elided. Pattern { // Note: In this pattern we also inlined the `root` expression. replace op with op; @@ -1385,7 +1385,7 @@ Pattern { // Invoke the rewrite, which returns a tuple of values. let result = CreateRewriteOps(); - // Index the tuple elements by index, or by name. + // Index the tuple elements by index, or by name. replace root with (result.0, result.1, result.result1); } } @@ -1466,7 +1466,7 @@ the C++ PDL API. For example, the rewrite above may be registered as: ```c++ static Operation *buildOpImpl(PDLResultList &results, Value value) { // insert special rewrite logic here. - Operation *resultOp = ...; + Operation *resultOp = ...; return resultOp; } diff --git a/mlir/docs/Tutorials/Toy/Ch-2.md b/mlir/docs/Tutorials/Toy/Ch-2.md index 6801369..b807ee3 100644 --- a/mlir/docs/Tutorials/Toy/Ch-2.md +++ b/mlir/docs/Tutorials/Toy/Ch-2.md @@ -243,7 +243,7 @@ operation. This operation will represent a constant value in the Toy language. This operation takes zero operands, a [dense elements](../../Dialects/Builtin.md/#denseintorfpelementsattr) attribute named `value` to represent the constant value, and returns a single result of -[RankedTensorType](../../Dialects/Builtin.md/#rankedtensortype). An operation class +[RankedTensorType](../../Dialects/Builtin.md/#rankedtensortype). An operation class inherits from the [CRTP](https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern) `mlir::Op` class which also takes some optional [*traits*](../../Traits) to customize its behavior. `Traits` are a mechanism with which we can inject @@ -497,10 +497,10 @@ def ConstantOp : Toy_Op<"constant"> { let results = (outs F64Tensor); // Add additional verification logic to the constant operation. Setting this bit - // to `1` will generate a `::mlir::LogicalResult verify()` declaration on the + // to `1` will generate a `::llvm::LogicalResult verify()` declaration on the // operation class that is called after ODS constructs have been verified, for // example the types of arguments and results. We implement additional verification - // in the definition of this `verify` method in the C++ source file. + // in the definition of this `verify` method in the C++ source file. let hasVerifier = 1; } ``` diff --git a/mlir/docs/Tutorials/Toy/Ch-3.md b/mlir/docs/Tutorials/Toy/Ch-3.md index ac38cbe..4cde64d 100644 --- a/mlir/docs/Tutorials/Toy/Ch-3.md +++ b/mlir/docs/Tutorials/Toy/Ch-3.md @@ -86,7 +86,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern { /// This method is attempting to match a pattern and rewrite it. The rewriter /// argument is the orchestrator of the sequence of rewrites. It is expected /// to interact with it to perform any changes to the IR from here. - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(TransposeOp op, mlir::PatternRewriter &rewriter) const override { // Look through the input of the current transpose. @@ -128,7 +128,7 @@ similar way to LLVM: pm.addNestedPass(mlir::createCanonicalizerPass()); ``` -Finally, we can run `toyc-ch3 test/Examples/Toy/Ch3/transpose_transpose.toy +Finally, we can run `toyc-ch3 test/Examples/Toy/Ch3/transpose_transpose.toy -emit=mlir -opt` and observe our pattern in action: ```mlir @@ -239,7 +239,7 @@ module { } ``` -We can try to run `toyc-ch3 test/Examples/Toy/Ch3/trivial_reshape.toy -emit=mlir +We can try to run `toyc-ch3 test/Examples/Toy/Ch3/trivial_reshape.toy -emit=mlir -opt` and observe our pattern in action: ```mlir diff --git a/mlir/docs/Tutorials/Toy/Ch-5.md b/mlir/docs/Tutorials/Toy/Ch-5.md index 6fe0080..7d4f95e 100644 --- a/mlir/docs/Tutorials/Toy/Ch-5.md +++ b/mlir/docs/Tutorials/Toy/Ch-5.md @@ -113,7 +113,7 @@ struct TransposeOpLowering : public mlir::ConversionPattern { /// Match and rewrite the given `toy.transpose` operation, with the given /// operands that have been remapped from `tensor<...>` to `memref<...>`. - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(mlir::Operation *op, ArrayRef operands, mlir::ConversionPatternRewriter &rewriter) const final { auto loc = op->getLoc(); diff --git a/mlir/examples/standalone/lib/Standalone/StandalonePasses.cpp b/mlir/examples/standalone/lib/Standalone/StandalonePasses.cpp index a23d042..8166aa2 100644 --- a/mlir/examples/standalone/lib/Standalone/StandalonePasses.cpp +++ b/mlir/examples/standalone/lib/Standalone/StandalonePasses.cpp @@ -8,7 +8,6 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Rewrite/FrozenRewritePatternSet.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "Standalone/StandalonePasses.h" diff --git a/mlir/examples/standalone/standalone-translate/standalone-translate.cpp b/mlir/examples/standalone/standalone-translate/standalone-translate.cpp index a4da328..46b9c77 100644 --- a/mlir/examples/standalone/standalone-translate/standalone-translate.cpp +++ b/mlir/examples/standalone/standalone-translate/standalone-translate.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/DialectRegistry.h" #include "mlir/IR/Operation.h" #include "mlir/InitAllTranslations.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Tools/mlir-translate/MlirTranslateMain.h" #include "mlir/Tools/mlir-translate/Translation.h" #include "llvm/Support/raw_ostream.h" @@ -27,7 +26,7 @@ int main(int argc, char **argv) { mlir::TranslateFromMLIRRegistration withdescription( "option", "different from option", [](mlir::Operation *op, llvm::raw_ostream &output) { - return mlir::LogicalResult::success(); + return llvm::LogicalResult::success(); }, [](mlir::DialectRegistry &a) {}); diff --git a/mlir/examples/toy/Ch2/mlir/Dialect.cpp b/mlir/examples/toy/Ch2/mlir/Dialect.cpp index d35bd9f..489f348 100644 --- a/mlir/examples/toy/Ch2/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch2/mlir/Dialect.cpp @@ -22,7 +22,6 @@ #include "mlir/IR/Value.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" @@ -142,7 +141,7 @@ void ConstantOp::print(mlir::OpAsmPrinter &printer) { /// Verifier for the constant operation. This corresponds to the /// `let hasVerifier = 1` in the op definition. -mlir::LogicalResult ConstantOp::verify() { +llvm::LogicalResult ConstantOp::verify() { // If the return type of the constant is not an unranked tensor, the shape // must match the shape of the attribute holding the data. auto resultType = llvm::dyn_cast(getResult().getType()); @@ -257,7 +256,7 @@ void MulOp::print(mlir::OpAsmPrinter &p) { printBinaryOp(p, *this); } // ReturnOp //===----------------------------------------------------------------------===// -mlir::LogicalResult ReturnOp::verify() { +llvm::LogicalResult ReturnOp::verify() { // We know that the parent operation is a function, because of the 'HasParent' // trait attached to the operation definition. auto function = cast((*this)->getParentOp()); @@ -300,7 +299,7 @@ void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state, state.addOperands(value); } -mlir::LogicalResult TransposeOp::verify() { +llvm::LogicalResult TransposeOp::verify() { auto inputType = llvm::dyn_cast(getOperand().getType()); auto resultType = llvm::dyn_cast(getType()); if (!inputType || !resultType) diff --git a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp index 2f0a88f..bf4c099 100644 --- a/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch2/mlir/MLIRGen.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Block.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" @@ -105,7 +104,7 @@ private: /// Declare a variable in the current scope, return success if the variable /// wasn't declared yet. - mlir::LogicalResult declare(llvm::StringRef var, mlir::Value value) { + llvm::LogicalResult declare(llvm::StringRef var, mlir::Value value) { if (symbolTable.count(var)) return mlir::failure(); symbolTable.insert(var, value); @@ -225,7 +224,7 @@ private: } /// Emit a return operation. This will return failure if any generation fails. - mlir::LogicalResult mlirGen(ReturnExprAST &ret) { + llvm::LogicalResult mlirGen(ReturnExprAST &ret) { auto location = loc(ret.loc()); // 'return' takes an optional expression, handle that case here. @@ -337,7 +336,7 @@ private: /// Emit a print expression. It emits specific operations for two builtins: /// transpose(x) and print(x). - mlir::LogicalResult mlirGen(PrintExprAST &call) { + llvm::LogicalResult mlirGen(PrintExprAST &call) { auto arg = mlirGen(*call.getArg()); if (!arg) return mlir::failure(); @@ -403,7 +402,7 @@ private: } /// Codegen a list of expression, return failure if one of them hit an error. - mlir::LogicalResult mlirGen(ExprASTList &blockAST) { + llvm::LogicalResult mlirGen(ExprASTList &blockAST) { ScopedHashTableScope varScope(symbolTable); for (auto &expr : blockAST) { // Specific handling for variable declarations, return statement, and diff --git a/mlir/examples/toy/Ch3/mlir/Dialect.cpp b/mlir/examples/toy/Ch3/mlir/Dialect.cpp index 79d82e5..708855f 100644 --- a/mlir/examples/toy/Ch3/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch3/mlir/Dialect.cpp @@ -22,7 +22,6 @@ #include "mlir/IR/Value.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" @@ -142,7 +141,7 @@ void ConstantOp::print(mlir::OpAsmPrinter &printer) { /// Verifier for the constant operation. This corresponds to the /// `let hasVerifier = 1` in the op definition. -mlir::LogicalResult ConstantOp::verify() { +llvm::LogicalResult ConstantOp::verify() { // If the return type of the constant is not an unranked tensor, the shape // must match the shape of the attribute holding the data. auto resultType = llvm::dyn_cast(getResult().getType()); @@ -257,7 +256,7 @@ void MulOp::print(mlir::OpAsmPrinter &p) { printBinaryOp(p, *this); } // ReturnOp //===----------------------------------------------------------------------===// -mlir::LogicalResult ReturnOp::verify() { +llvm::LogicalResult ReturnOp::verify() { // We know that the parent operation is a function, because of the 'HasParent' // trait attached to the operation definition. auto function = cast((*this)->getParentOp()); @@ -300,7 +299,7 @@ void TransposeOp::build(mlir::OpBuilder &builder, mlir::OperationState &state, state.addOperands(value); } -mlir::LogicalResult TransposeOp::verify() { +llvm::LogicalResult TransposeOp::verify() { auto inputType = llvm::dyn_cast(getOperand().getType()); auto resultType = llvm::dyn_cast(getType()); if (!inputType || !resultType) diff --git a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp index 2f0a88f..bf4c099 100644 --- a/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch3/mlir/MLIRGen.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Block.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" @@ -105,7 +104,7 @@ private: /// Declare a variable in the current scope, return success if the variable /// wasn't declared yet. - mlir::LogicalResult declare(llvm::StringRef var, mlir::Value value) { + llvm::LogicalResult declare(llvm::StringRef var, mlir::Value value) { if (symbolTable.count(var)) return mlir::failure(); symbolTable.insert(var, value); @@ -225,7 +224,7 @@ private: } /// Emit a return operation. This will return failure if any generation fails. - mlir::LogicalResult mlirGen(ReturnExprAST &ret) { + llvm::LogicalResult mlirGen(ReturnExprAST &ret) { auto location = loc(ret.loc()); // 'return' takes an optional expression, handle that case here. @@ -337,7 +336,7 @@ private: /// Emit a print expression. It emits specific operations for two builtins: /// transpose(x) and print(x). - mlir::LogicalResult mlirGen(PrintExprAST &call) { + llvm::LogicalResult mlirGen(PrintExprAST &call) { auto arg = mlirGen(*call.getArg()); if (!arg) return mlir::failure(); @@ -403,7 +402,7 @@ private: } /// Codegen a list of expression, return failure if one of them hit an error. - mlir::LogicalResult mlirGen(ExprASTList &blockAST) { + llvm::LogicalResult mlirGen(ExprASTList &blockAST) { ScopedHashTableScope varScope(symbolTable); for (auto &expr : blockAST) { // Specific handling for variable declarations, return statement, and diff --git a/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp index 3ce35c8..f8397c2 100644 --- a/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp @@ -14,7 +14,6 @@ #include "mlir/IR/MLIRContext.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/Dialect.h" using namespace mlir; using namespace toy; @@ -36,7 +35,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern { /// This method attempts to match a pattern and rewrite it. The rewriter /// argument is the orchestrator of the sequence of rewrites. The pattern is /// expected to interact with it to perform any changes to the IR from here. - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(TransposeOp op, mlir::PatternRewriter &rewriter) const override { // Look through the input of the current transpose. diff --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp index c2c5f1f..f8aa846 100644 --- a/mlir/examples/toy/Ch3/toyc.cpp +++ b/mlir/examples/toy/Ch3/toyc.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/Diagnostics.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" #include "toy/Lexer.h" diff --git a/mlir/examples/toy/Ch4/mlir/Dialect.cpp b/mlir/examples/toy/Ch4/mlir/Dialect.cpp index 86a0e1d..6c6cdd9 100644 --- a/mlir/examples/toy/Ch4/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch4/mlir/Dialect.cpp @@ -23,7 +23,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" @@ -204,7 +203,7 @@ void ConstantOp::print(mlir::OpAsmPrinter &printer) { /// Verifier for the constant operation. This corresponds to the /// `let hasVerifier = 1` in the op definition. -mlir::LogicalResult ConstantOp::verify() { +llvm::LogicalResult ConstantOp::verify() { // If the return type of the constant is not an unranked tensor, the shape // must match the shape of the attribute holding the data. auto resultType = llvm::dyn_cast(getResult().getType()); @@ -372,7 +371,7 @@ void MulOp::inferShapes() { getResult().setType(getLhs().getType()); } // ReturnOp //===----------------------------------------------------------------------===// -mlir::LogicalResult ReturnOp::verify() { +llvm::LogicalResult ReturnOp::verify() { // We know that the parent operation is a function, because of the 'HasParent' // trait attached to the operation definition. auto function = cast((*this)->getParentOp()); @@ -421,7 +420,7 @@ void TransposeOp::inferShapes() { getResult().setType(RankedTensorType::get(dims, arrayTy.getElementType())); } -mlir::LogicalResult TransposeOp::verify() { +llvm::LogicalResult TransposeOp::verify() { auto inputType = llvm::dyn_cast(getOperand().getType()); auto resultType = llvm::dyn_cast(getType()); if (!inputType || !resultType) diff --git a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp index 6c5474a..b56e2f7c 100644 --- a/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch4/mlir/MLIRGen.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Block.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" @@ -105,7 +104,7 @@ private: /// Declare a variable in the current scope, return success if the variable /// wasn't declared yet. - mlir::LogicalResult declare(llvm::StringRef var, mlir::Value value) { + llvm::LogicalResult declare(llvm::StringRef var, mlir::Value value) { if (symbolTable.count(var)) return mlir::failure(); symbolTable.insert(var, value); @@ -229,7 +228,7 @@ private: } /// Emit a return operation. This will return failure if any generation fails. - mlir::LogicalResult mlirGen(ReturnExprAST &ret) { + llvm::LogicalResult mlirGen(ReturnExprAST &ret) { auto location = loc(ret.loc()); // 'return' takes an optional expression, handle that case here. @@ -341,7 +340,7 @@ private: /// Emit a print expression. It emits specific operations for two builtins: /// transpose(x) and print(x). - mlir::LogicalResult mlirGen(PrintExprAST &call) { + llvm::LogicalResult mlirGen(PrintExprAST &call) { auto arg = mlirGen(*call.getArg()); if (!arg) return mlir::failure(); @@ -407,7 +406,7 @@ private: } /// Codegen a list of expression, return failure if one of them hit an error. - mlir::LogicalResult mlirGen(ExprASTList &blockAST) { + llvm::LogicalResult mlirGen(ExprASTList &blockAST) { ScopedHashTableScope varScope(symbolTable); for (auto &expr : blockAST) { // Specific handling for variable declarations, return statement, and diff --git a/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp index 3ce35c8..f8397c2 100644 --- a/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp @@ -14,7 +14,6 @@ #include "mlir/IR/MLIRContext.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/Dialect.h" using namespace mlir; using namespace toy; @@ -36,7 +35,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern { /// This method attempts to match a pattern and rewrite it. The rewriter /// argument is the orchestrator of the sequence of rewrites. The pattern is /// expected to interact with it to perform any changes to the IR from here. - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(TransposeOp op, mlir::PatternRewriter &rewriter) const override { // Look through the input of the current transpose. diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp index a1534ed..ae02bc4 100644 --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "mlir/IR/Diagnostics.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" #include "toy/Lexer.h" diff --git a/mlir/examples/toy/Ch5/mlir/Dialect.cpp b/mlir/examples/toy/Ch5/mlir/Dialect.cpp index c587dd2..72072f9 100644 --- a/mlir/examples/toy/Ch5/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch5/mlir/Dialect.cpp @@ -23,7 +23,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" @@ -204,7 +203,7 @@ void ConstantOp::print(mlir::OpAsmPrinter &printer) { /// Verifier for the constant operation. This corresponds to the /// `let hasVerifier = 1` in the op definition. -mlir::LogicalResult ConstantOp::verify() { +llvm::LogicalResult ConstantOp::verify() { // If the return type of the constant is not an unranked tensor, the shape // must match the shape of the attribute holding the data. auto resultType = llvm::dyn_cast(getResult().getType()); @@ -372,7 +371,7 @@ void MulOp::inferShapes() { getResult().setType(getLhs().getType()); } // ReturnOp //===----------------------------------------------------------------------===// -mlir::LogicalResult ReturnOp::verify() { +llvm::LogicalResult ReturnOp::verify() { // We know that the parent operation is a function, because of the 'HasParent' // trait attached to the operation definition. auto function = cast((*this)->getParentOp()); @@ -421,7 +420,7 @@ void TransposeOp::inferShapes() { getResult().setType(RankedTensorType::get(dims, arrayTy.getElementType())); } -mlir::LogicalResult TransposeOp::verify() { +llvm::LogicalResult TransposeOp::verify() { auto inputType = llvm::dyn_cast(getOperand().getType()); auto resultType = llvm::dyn_cast(getType()); if (!inputType || !resultType) diff --git a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp index bded615..7413214 100644 --- a/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp @@ -21,7 +21,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/ValueRange.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "toy/Dialect.h" #include "toy/Passes.h" diff --git a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp index 6c5474a..b56e2f7c 100644 --- a/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch5/mlir/MLIRGen.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Block.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" @@ -105,7 +104,7 @@ private: /// Declare a variable in the current scope, return success if the variable /// wasn't declared yet. - mlir::LogicalResult declare(llvm::StringRef var, mlir::Value value) { + llvm::LogicalResult declare(llvm::StringRef var, mlir::Value value) { if (symbolTable.count(var)) return mlir::failure(); symbolTable.insert(var, value); @@ -229,7 +228,7 @@ private: } /// Emit a return operation. This will return failure if any generation fails. - mlir::LogicalResult mlirGen(ReturnExprAST &ret) { + llvm::LogicalResult mlirGen(ReturnExprAST &ret) { auto location = loc(ret.loc()); // 'return' takes an optional expression, handle that case here. @@ -341,7 +340,7 @@ private: /// Emit a print expression. It emits specific operations for two builtins: /// transpose(x) and print(x). - mlir::LogicalResult mlirGen(PrintExprAST &call) { + llvm::LogicalResult mlirGen(PrintExprAST &call) { auto arg = mlirGen(*call.getArg()); if (!arg) return mlir::failure(); @@ -407,7 +406,7 @@ private: } /// Codegen a list of expression, return failure if one of them hit an error. - mlir::LogicalResult mlirGen(ExprASTList &blockAST) { + llvm::LogicalResult mlirGen(ExprASTList &blockAST) { ScopedHashTableScope varScope(symbolTable); for (auto &expr : blockAST) { // Specific handling for variable declarations, return statement, and diff --git a/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp index 3ce35c8..f8397c2 100644 --- a/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp @@ -14,7 +14,6 @@ #include "mlir/IR/MLIRContext.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/Dialect.h" using namespace mlir; using namespace toy; @@ -36,7 +35,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern { /// This method attempts to match a pattern and rewrite it. The rewriter /// argument is the orchestrator of the sequence of rewrites. The pattern is /// expected to interact with it to perform any changes to the IR from here. - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(TransposeOp op, mlir::PatternRewriter &rewriter) const override { // Look through the input of the current transpose. diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp index 4eb6fde..6a0c631 100644 --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -12,7 +12,6 @@ #include "mlir/Dialect/Func/Extensions/AllExtensions.h" #include "mlir/IR/Diagnostics.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" #include "toy/Lexer.h" diff --git a/mlir/examples/toy/Ch6/mlir/Dialect.cpp b/mlir/examples/toy/Ch6/mlir/Dialect.cpp index c587dd2..72072f9 100644 --- a/mlir/examples/toy/Ch6/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch6/mlir/Dialect.cpp @@ -23,7 +23,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" @@ -204,7 +203,7 @@ void ConstantOp::print(mlir::OpAsmPrinter &printer) { /// Verifier for the constant operation. This corresponds to the /// `let hasVerifier = 1` in the op definition. -mlir::LogicalResult ConstantOp::verify() { +llvm::LogicalResult ConstantOp::verify() { // If the return type of the constant is not an unranked tensor, the shape // must match the shape of the attribute holding the data. auto resultType = llvm::dyn_cast(getResult().getType()); @@ -372,7 +371,7 @@ void MulOp::inferShapes() { getResult().setType(getLhs().getType()); } // ReturnOp //===----------------------------------------------------------------------===// -mlir::LogicalResult ReturnOp::verify() { +llvm::LogicalResult ReturnOp::verify() { // We know that the parent operation is a function, because of the 'HasParent' // trait attached to the operation definition. auto function = cast((*this)->getParentOp()); @@ -421,7 +420,7 @@ void TransposeOp::inferShapes() { getResult().setType(RankedTensorType::get(dims, arrayTy.getElementType())); } -mlir::LogicalResult TransposeOp::verify() { +llvm::LogicalResult TransposeOp::verify() { auto inputType = llvm::dyn_cast(getOperand().getType()); auto resultType = llvm::dyn_cast(getType()); if (!inputType || !resultType) diff --git a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp index bded615..7413214 100644 --- a/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp @@ -21,7 +21,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/ValueRange.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "toy/Dialect.h" #include "toy/Passes.h" diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp index f91d880..3ad70e7 100644 --- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp @@ -28,7 +28,6 @@ #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "toy/Dialect.h" #include "toy/Passes.h" diff --git a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp index 6c5474a..b56e2f7c 100644 --- a/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch6/mlir/MLIRGen.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Block.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" @@ -105,7 +104,7 @@ private: /// Declare a variable in the current scope, return success if the variable /// wasn't declared yet. - mlir::LogicalResult declare(llvm::StringRef var, mlir::Value value) { + llvm::LogicalResult declare(llvm::StringRef var, mlir::Value value) { if (symbolTable.count(var)) return mlir::failure(); symbolTable.insert(var, value); @@ -229,7 +228,7 @@ private: } /// Emit a return operation. This will return failure if any generation fails. - mlir::LogicalResult mlirGen(ReturnExprAST &ret) { + llvm::LogicalResult mlirGen(ReturnExprAST &ret) { auto location = loc(ret.loc()); // 'return' takes an optional expression, handle that case here. @@ -341,7 +340,7 @@ private: /// Emit a print expression. It emits specific operations for two builtins: /// transpose(x) and print(x). - mlir::LogicalResult mlirGen(PrintExprAST &call) { + llvm::LogicalResult mlirGen(PrintExprAST &call) { auto arg = mlirGen(*call.getArg()); if (!arg) return mlir::failure(); @@ -407,7 +406,7 @@ private: } /// Codegen a list of expression, return failure if one of them hit an error. - mlir::LogicalResult mlirGen(ExprASTList &blockAST) { + llvm::LogicalResult mlirGen(ExprASTList &blockAST) { ScopedHashTableScope varScope(symbolTable); for (auto &expr : blockAST) { // Specific handling for variable declarations, return statement, and diff --git a/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp index 3ce35c8..f8397c2 100644 --- a/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp @@ -14,7 +14,6 @@ #include "mlir/IR/MLIRContext.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/Dialect.h" using namespace mlir; using namespace toy; @@ -36,7 +35,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern { /// This method attempts to match a pattern and rewrite it. The rewriter /// argument is the orchestrator of the sequence of rewrites. The pattern is /// expected to interact with it to perform any changes to the IR from here. - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(TransposeOp op, mlir::PatternRewriter &rewriter) const override { // Look through the input of the current transpose. diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp index ddc0c25..c244b31 100644 --- a/mlir/examples/toy/Ch6/toyc.cpp +++ b/mlir/examples/toy/Ch6/toyc.cpp @@ -12,7 +12,6 @@ #include "mlir/Dialect/Func/Extensions/AllExtensions.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" #include "toy/Lexer.h" diff --git a/mlir/examples/toy/Ch7/mlir/Dialect.cpp b/mlir/examples/toy/Ch7/mlir/Dialect.cpp index b268b1e..7e030ff 100644 --- a/mlir/examples/toy/Ch7/mlir/Dialect.cpp +++ b/mlir/examples/toy/Ch7/mlir/Dialect.cpp @@ -27,7 +27,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Hashing.h" @@ -195,7 +194,7 @@ void ConstantOp::print(mlir::OpAsmPrinter &printer) { } /// Verify that the given attribute value is valid for the given type. -static mlir::LogicalResult verifyConstantForType(mlir::Type type, +static llvm::LogicalResult verifyConstantForType(mlir::Type type, mlir::Attribute opaqueValue, mlir::Operation *op) { if (llvm::isa(type)) { @@ -252,11 +251,11 @@ static mlir::LogicalResult verifyConstantForType(mlir::Type type, /// Verifier for the constant operation. This corresponds to the `::verify(...)` /// in the op definition. -mlir::LogicalResult ConstantOp::verify() { +llvm::LogicalResult ConstantOp::verify() { return verifyConstantForType(getResult().getType(), getValue(), *this); } -mlir::LogicalResult StructConstantOp::verify() { +llvm::LogicalResult StructConstantOp::verify() { return verifyConstantForType(getResult().getType(), getValue(), *this); } @@ -406,7 +405,7 @@ void MulOp::inferShapes() { getResult().setType(getLhs().getType()); } // ReturnOp //===----------------------------------------------------------------------===// -mlir::LogicalResult ReturnOp::verify() { +llvm::LogicalResult ReturnOp::verify() { // We know that the parent operation is a function, because of the 'HasParent' // trait attached to the operation definition. auto function = cast((*this)->getParentOp()); @@ -454,7 +453,7 @@ void StructAccessOp::build(mlir::OpBuilder &b, mlir::OperationState &state, build(b, state, resultType, input, b.getI64IntegerAttr(index)); } -mlir::LogicalResult StructAccessOp::verify() { +llvm::LogicalResult StructAccessOp::verify() { StructType structTy = llvm::cast(getInput().getType()); size_t indexValue = getIndex(); if (indexValue >= structTy.getNumElementTypes()) @@ -483,7 +482,7 @@ void TransposeOp::inferShapes() { getResult().setType(RankedTensorType::get(dims, arrayTy.getElementType())); } -mlir::LogicalResult TransposeOp::verify() { +llvm::LogicalResult TransposeOp::verify() { auto inputType = llvm::dyn_cast(getOperand().getType()); auto resultType = llvm::dyn_cast(getType()); if (!inputType || !resultType) diff --git a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp index bded615..7413214 100644 --- a/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp @@ -21,7 +21,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/ValueRange.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "toy/Dialect.h" #include "toy/Passes.h" diff --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp index f91d880..3ad70e7 100644 --- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp @@ -28,7 +28,6 @@ #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "toy/Dialect.h" #include "toy/Passes.h" diff --git a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp index 0f8e8df..090e5ff 100644 --- a/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp +++ b/mlir/examples/toy/Ch7/mlir/MLIRGen.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Block.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" @@ -133,7 +132,7 @@ private: /// Declare a variable in the current scope, return success if the variable /// wasn't declared yet. - mlir::LogicalResult declare(VarDeclExprAST &var, mlir::Value value) { + llvm::LogicalResult declare(VarDeclExprAST &var, mlir::Value value) { if (symbolTable.count(var.getName())) return mlir::failure(); symbolTable.insert(var.getName(), {value, &var}); @@ -141,7 +140,7 @@ private: } /// Create an MLIR type for the given struct. - mlir::LogicalResult mlirGen(StructAST &str) { + llvm::LogicalResult mlirGen(StructAST &str) { if (structMap.count(str.getName())) return emitError(loc(str.loc())) << "error: struct type with name `" << str.getName() << "' already exists"; @@ -368,7 +367,7 @@ private: } /// Emit a return operation. This will return failure if any generation fails. - mlir::LogicalResult mlirGen(ReturnExprAST &ret) { + llvm::LogicalResult mlirGen(ReturnExprAST &ret) { auto location = loc(ret.loc()); // 'return' takes an optional expression, handle that case here. @@ -542,7 +541,7 @@ private: /// Emit a print expression. It emits specific operations for two builtins: /// transpose(x) and print(x). - mlir::LogicalResult mlirGen(PrintExprAST &call) { + llvm::LogicalResult mlirGen(PrintExprAST &call) { auto arg = mlirGen(*call.getArg()); if (!arg) return mlir::failure(); @@ -626,7 +625,7 @@ private: } /// Codegen a list of expression, return failure if one of them hit an error. - mlir::LogicalResult mlirGen(ExprASTList &blockAST) { + llvm::LogicalResult mlirGen(ExprASTList &blockAST) { SymbolTableScopeT varScope(symbolTable); for (auto &expr : blockAST) { // Specific handling for variable declarations, return statement, and diff --git a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp index 72f5e4b..1d8cf74 100644 --- a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp @@ -16,7 +16,6 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "toy/Dialect.h" #include "llvm/Support/Casting.h" #include @@ -57,7 +56,7 @@ struct SimplifyRedundantTranspose : public mlir::OpRewritePattern { /// This method attempts to match a pattern and rewrite it. The rewriter /// argument is the orchestrator of the sequence of rewrites. The pattern is /// expected to interact with it to perform any changes to the IR from here. - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(TransposeOp op, mlir::PatternRewriter &rewriter) const override { // Look through the input of the current transpose. diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp index 5eb40b7..fea5679 100644 --- a/mlir/examples/toy/Ch7/toyc.cpp +++ b/mlir/examples/toy/Ch7/toyc.cpp @@ -12,7 +12,6 @@ #include "mlir/Dialect/Func/Extensions/AllExtensions.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" -#include "mlir/Support/LogicalResult.h" #include "toy/AST.h" #include "toy/Dialect.h" #include "toy/Lexer.h" diff --git a/mlir/examples/transform-opt/mlir-transform-opt.cpp b/mlir/examples/transform-opt/mlir-transform-opt.cpp index 41a17f1..65615fb 100644 --- a/mlir/examples/transform-opt/mlir-transform-opt.cpp +++ b/mlir/examples/transform-opt/mlir-transform-opt.cpp @@ -118,7 +118,7 @@ public: DiagnosticHandlerWrapper &operator=(DiagnosticHandlerWrapper &&) = default; /// Verifies the captured "expected-*" diagnostics if required. - mlir::LogicalResult verify() const { + llvm::LogicalResult verify() const { if (auto *ptr = handler.dyn_cast()) { return ptr->verify(); @@ -192,7 +192,7 @@ public: /// If diagnostic message verification has been requested upon construction of /// this source manager, performs the verification, reports errors and returns /// the result of the verification. Otherwise passes through the given value. - mlir::LogicalResult checkResult(mlir::LogicalResult result) { + llvm::LogicalResult checkResult(llvm::LogicalResult result) { resultChecked = true; if (!verifyDiagnostics) return result; @@ -222,7 +222,7 @@ private: /// Trivial wrapper around `applyTransforms` that doesn't support extra mapping /// and doesn't enforce the entry point transform ops being top-level. -static mlir::LogicalResult +static llvm::LogicalResult applyTransforms(mlir::Operation *payloadRoot, mlir::transform::TransformOpInterface transformRoot, const mlir::transform::TransformOptions &options) { @@ -237,7 +237,7 @@ applyTransforms(mlir::Operation *payloadRoot, /// application is successful, prints the transformed input buffer into the /// given output stream. Additional configuration options are derived from /// command-line options. -static mlir::LogicalResult processPayloadBuffer( +static llvm::LogicalResult processPayloadBuffer( raw_ostream &os, std::unique_ptr inputBuffer, std::unique_ptr transformBuffer, MutableArrayRef> transformLibraries, @@ -309,7 +309,7 @@ static mlir::LogicalResult processPayloadBuffer( } /// Tool entry point. -static mlir::LogicalResult runMain(int argc, char **argv) { +static llvm::LogicalResult runMain(int argc, char **argv) { // Register all upstream dialects and extensions. Specific uses are advised // not to register all dialects indiscriminately but rather hand-pick what is // necessary for their use case. diff --git a/mlir/examples/transform/Ch4/lib/MyExtension.cpp b/mlir/examples/transform/Ch4/lib/MyExtension.cpp index 0790736..38c8ca1 100644 --- a/mlir/examples/transform/Ch4/lib/MyExtension.cpp +++ b/mlir/examples/transform/Ch4/lib/MyExtension.cpp @@ -166,7 +166,7 @@ void mlir::transform::HasOperandSatisfyingOp::getEffects( // Verify well-formedness of the operation and emit diagnostics if it is // ill-formed. -mlir::LogicalResult mlir::transform::HasOperandSatisfyingOp::verify() { +llvm::LogicalResult mlir::transform::HasOperandSatisfyingOp::verify() { mlir::Block &bodyBlock = getBody().front(); if (bodyBlock.getNumArguments() != 1 || !isa( diff --git a/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h b/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h index cc6ab64..63305e0 100644 --- a/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h +++ b/mlir/include/mlir/Analysis/FlatLinearValueConstraints.h @@ -13,7 +13,6 @@ #include "mlir/Analysis/Presburger/Matrix.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/OpDefinition.h" -#include "mlir/Support/LogicalResult.h" #include namespace mlir { diff --git a/mlir/include/mlir/Bytecode/BytecodeImplementation.h b/mlir/include/mlir/Bytecode/BytecodeImplementation.h index bc91318c..0ddc531 100644 --- a/mlir/include/mlir/Bytecode/BytecodeImplementation.h +++ b/mlir/include/mlir/Bytecode/BytecodeImplementation.h @@ -19,7 +19,6 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/DialectInterface.h" #include "mlir/IR/OpImplementation.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Twine.h" diff --git a/mlir/include/mlir/Bytecode/BytecodeOpInterface.h b/mlir/include/mlir/Bytecode/BytecodeOpInterface.h index 10f5be0..c9c6060 100644 --- a/mlir/include/mlir/Bytecode/BytecodeOpInterface.h +++ b/mlir/include/mlir/Bytecode/BytecodeOpInterface.h @@ -18,7 +18,6 @@ #include "mlir/Bytecode/BytecodeReader.h" #include "mlir/Bytecode/BytecodeWriter.h" #include "mlir/IR/OpDefinition.h" -#include "mlir/Support/LogicalResult.h" /// Include the generated interface declarations. #include "mlir/Bytecode/BytecodeOpInterface.h.inc" diff --git a/mlir/include/mlir/Bytecode/BytecodeReader.h b/mlir/include/mlir/Bytecode/BytecodeReader.h index 9f26506..19f74a0 100644 --- a/mlir/include/mlir/Bytecode/BytecodeReader.h +++ b/mlir/include/mlir/Bytecode/BytecodeReader.h @@ -15,7 +15,6 @@ #include "mlir/IR/AsmState.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include #include diff --git a/mlir/include/mlir/Bytecode/BytecodeReaderConfig.h b/mlir/include/mlir/Bytecode/BytecodeReaderConfig.h index d623d0d..47be732 100644 --- a/mlir/include/mlir/Bytecode/BytecodeReaderConfig.h +++ b/mlir/include/mlir/Bytecode/BytecodeReaderConfig.h @@ -14,7 +14,6 @@ #define MLIR_BYTECODE_BYTECODEREADERCONFIG_H #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" diff --git a/mlir/include/mlir/CAPI/Support.h b/mlir/include/mlir/CAPI/Support.h index 6227452..89a4603 100644 --- a/mlir/include/mlir/CAPI/Support.h +++ b/mlir/include/mlir/CAPI/Support.h @@ -17,9 +17,9 @@ #include "mlir-c/Support.h" #include "mlir/CAPI/Wrap.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/LogicalResult.h" namespace llvm { class ThreadPoolInterface; @@ -35,13 +35,13 @@ inline llvm::StringRef unwrap(MlirStringRef ref) { return llvm::StringRef(ref.data, ref.length); } -inline MlirLogicalResult wrap(mlir::LogicalResult res) { +inline MlirLogicalResult wrap(llvm::LogicalResult res) { if (mlir::succeeded(res)) return mlirLogicalResultSuccess(); return mlirLogicalResultFailure(); } -inline mlir::LogicalResult unwrap(MlirLogicalResult res) { +inline llvm::LogicalResult unwrap(MlirLogicalResult res) { return mlir::success(mlirLogicalResultIsSuccess(res)); } diff --git a/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h b/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h index 3850a00..96ee4f0 100644 --- a/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h +++ b/mlir/include/mlir/Conversion/AffineToStandard/AffineToStandard.h @@ -13,7 +13,6 @@ namespace mlir { class Location; -struct LogicalResult; class OpBuilder; class Pass; class RewritePattern; diff --git a/mlir/include/mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h b/mlir/include/mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h index 424ab38..00aeed9 100644 --- a/mlir/include/mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h +++ b/mlir/include/mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h @@ -11,7 +11,6 @@ #include "mlir/IR/DialectInterface.h" #include "mlir/IR/MLIRContext.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { class ConversionTarget; diff --git a/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h b/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h index 107718e..76eb3b5 100644 --- a/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h +++ b/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h @@ -15,7 +15,6 @@ #define MLIR_CONVERSION_FUNCTOLLVM_CONVERTFUNCTOLLVM_H #include "mlir/Interfaces/FunctionInterfaces.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { diff --git a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h index 2d5e9d2..5f40315 100644 --- a/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h +++ b/mlir/include/mlir/Conversion/GPUCommon/GPUCommonPass.h @@ -26,7 +26,6 @@ namespace mlir { class LLVMTypeConverter; class Location; -struct LogicalResult; class ModuleOp; class Operation; class RewritePatternSet; diff --git a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h index a180a12..69e3f70 100644 --- a/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h +++ b/mlir/include/mlir/Conversion/SCFToGPU/SCFToGPU.h @@ -12,7 +12,6 @@ namespace mlir { class ConversionTarget; -struct LogicalResult; class MLIRContext; class Value; class Operation; diff --git a/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h b/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h index 3530eb5..10467e6 100644 --- a/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h +++ b/mlir/include/mlir/Conversion/VectorToGPU/VectorToGPU.h @@ -12,7 +12,6 @@ #include "mlir/IR/PatternMatch.h" namespace mlir { -struct LogicalResult; class MLIRContext; class Pass; class RewritePatternSet; diff --git a/mlir/include/mlir/Debug/CLOptionsSetup.h b/mlir/include/mlir/Debug/CLOptionsSetup.h index a30ffe0..e7e9727 100644 --- a/mlir/include/mlir/Debug/CLOptionsSetup.h +++ b/mlir/include/mlir/Debug/CLOptionsSetup.h @@ -10,7 +10,6 @@ #define MLIR_DEBUG_CLOPTIONSSETUP_H #include "mlir/Debug/BreakpointManagers/FileLineColLocBreakpointManager.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/StringRef.h" #include diff --git a/mlir/include/mlir/Dialect/AMDGPU/Utils/Chipset.h b/mlir/include/mlir/Dialect/AMDGPU/Utils/Chipset.h index 5031dc4..38e0ebe 100644 --- a/mlir/include/mlir/Dialect/AMDGPU/Utils/Chipset.h +++ b/mlir/include/mlir/Dialect/AMDGPU/Utils/Chipset.h @@ -8,7 +8,7 @@ #ifndef MLIR_DIALECT_AMDGPU_UTILS_CHIPSET_H_ #define MLIR_DIALECT_AMDGPU_UTILS_CHIPSET_H_ -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" namespace mlir { namespace amdgpu { diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h index c9d3dc1..707eec7 100644 --- a/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/AffineStructures.h @@ -18,7 +18,6 @@ #include "mlir/Analysis/Presburger/Matrix.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/OpDefinition.h" -#include "mlir/Support/LogicalResult.h" #include namespace mlir { diff --git a/mlir/include/mlir/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h b/mlir/include/mlir/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h index 6e617ef4..451c466 100644 --- a/mlir/include/mlir/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h +++ b/mlir/include/mlir/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.h @@ -9,7 +9,7 @@ #ifndef MLIR_DIALECT_AFFINE_IR_VALUEBOUNDSOPINTERFACEIMPL_H #define MLIR_DIALECT_AFFINE_IR_VALUEBOUNDSOPINTERFACEIMPL_H -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" namespace mlir { class DialectRegistry; diff --git a/mlir/include/mlir/Dialect/Affine/LoopUtils.h b/mlir/include/mlir/Dialect/Affine/LoopUtils.h index d143954..99c500c 100644 --- a/mlir/include/mlir/Dialect/Affine/LoopUtils.h +++ b/mlir/include/mlir/Dialect/Affine/LoopUtils.h @@ -17,7 +17,6 @@ #include "mlir/IR/Block.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/RegionUtils.h" #include diff --git a/mlir/include/mlir/Dialect/Affine/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Affine/Transforms/Transforms.h index 1ea7375..b244d37 100644 --- a/mlir/include/mlir/Dialect/Affine/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Affine/Transforms/Transforms.h @@ -16,7 +16,6 @@ #include "mlir/Interfaces/ValueBoundsOpInterface.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { class AffineMap; diff --git a/mlir/include/mlir/Dialect/Affine/Utils.h b/mlir/include/mlir/Dialect/Affine/Utils.h index 7f25db0..9a2767e 100644 --- a/mlir/include/mlir/Dialect/Affine/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Utils.h @@ -33,8 +33,6 @@ namespace memref { class AllocOp; } // namespace memref -struct LogicalResult; - namespace affine { class AffineForOp; class AffineIfOp; diff --git a/mlir/include/mlir/Dialect/Arith/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Arith/Transforms/Transforms.h index bbc7e5d..8d6c68c 100644 --- a/mlir/include/mlir/Dialect/Arith/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Arith/Transforms/Transforms.h @@ -10,7 +10,6 @@ #define MLIR_DIALECT_ARITH_TRANSFORMS_TRANSFORMS_H #include "mlir/Interfaces/ValueBoundsOpInterface.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { class Location; diff --git a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.td b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.td index 007c05a..80cd13d 100644 --- a/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.td +++ b/mlir/include/mlir/Dialect/Bufferization/IR/BufferizableOpInterface.td @@ -378,7 +378,7 @@ def BufferizableOpInterface : OpInterface<"BufferizableOpInterface"> { This method can query analysis information from the given analysis state. }], - /*retType=*/"::mlir::LogicalResult", + /*retType=*/"::llvm::LogicalResult", /*methodName=*/"resolveConflicts", /*args=*/(ins "::mlir::RewriterBase &":$rewriter, "const ::mlir::bufferization::AnalysisState &":$state), @@ -423,7 +423,7 @@ def BufferizableOpInterface : OpInterface<"BufferizableOpInterface"> { suggestion to make sure IR is valid at every point in time and could be done differently). }], - /*retType=*/"::mlir::LogicalResult", + /*retType=*/"::llvm::LogicalResult", /*methodName=*/"bufferize", /*args=*/(ins "::mlir::RewriterBase &":$rewriter, "const ::mlir::bufferization::BufferizationOptions &":$options), @@ -490,7 +490,7 @@ def BufferizableOpInterface : OpInterface<"BufferizableOpInterface"> { This method can be used to check expected invariants and limitations of the current bufferization implementation. }], - /*retType=*/"::mlir::LogicalResult", + /*retType=*/"::llvm::LogicalResult", /*methodName=*/"verifyAnalysis", /*args=*/(ins "const ::mlir::bufferization::AnalysisState &":$state), /*methodBody=*/"", @@ -613,7 +613,7 @@ def BufferizableOpInterface : OpInterface<"BufferizableOpInterface"> { let extraClassDeclaration = [{ /// Resolve out-of-place tensor OpOperands with explicit allocations in the /// form of `bufferization.alloc_tensor` ops. - ::mlir::LogicalResult resolveTensorOpOperandConflicts( + ::llvm::LogicalResult resolveTensorOpOperandConflicts( ::mlir::RewriterBase &rewriter, const ::mlir::bufferization::AnalysisState &state); diff --git a/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h b/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h index cd4c009..4e5f5e9 100644 --- a/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h +++ b/mlir/include/mlir/Dialect/Bufferization/Transforms/OneShotModuleBufferize.h @@ -9,9 +9,11 @@ #ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTMODULEBUFFERIZE_H #define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTMODULEBUFFERIZE_H -namespace mlir { - +namespace llvm { struct LogicalResult; +} // namespace llvm + +namespace mlir { class ModuleOp; namespace bufferization { @@ -21,8 +23,9 @@ struct OneShotBufferizationOptions; /// Analyze `moduleOp` and its nested ops. Bufferization decisions are stored in /// `state`. -LogicalResult analyzeModuleOp(ModuleOp moduleOp, OneShotAnalysisState &state, - BufferizationStatistics *statistics = nullptr); +llvm::LogicalResult +analyzeModuleOp(ModuleOp moduleOp, OneShotAnalysisState &state, + BufferizationStatistics *statistics = nullptr); /// Bufferize `op` and its nested ops that implement `BufferizableOpInterface`. /// @@ -33,9 +36,9 @@ LogicalResult analyzeModuleOp(ModuleOp moduleOp, OneShotAnalysisState &state, /// - `options.copyBeforeWrite` is not set and `options.noAnalysisFuncFilter` /// is not empty. The FuncOps it contains were not analyzed. Buffer copies /// will be inserted only to these FuncOps. -LogicalResult bufferizeModuleOp(ModuleOp moduleOp, - const OneShotBufferizationOptions &options, - BufferizationStatistics *statistics = nullptr); +llvm::LogicalResult +bufferizeModuleOp(ModuleOp moduleOp, const OneShotBufferizationOptions &options, + BufferizationStatistics *statistics = nullptr); /// Remove bufferization attributes on every FuncOp arguments in the ModuleOp. void removeBufferizationAttributesInModule(ModuleOp moduleOp); @@ -44,7 +47,7 @@ void removeBufferizationAttributesInModule(ModuleOp moduleOp); /// function call analysis to determine which function arguments are /// inplaceable. Then analyzes and bufferizes FuncOps one-by-one with One-Shot /// Bufferize. -LogicalResult runOneShotModuleBufferize( +llvm::LogicalResult runOneShotModuleBufferize( ModuleOp moduleOp, const bufferization::OneShotBufferizationOptions &options, BufferizationStatistics *statistics = nullptr); diff --git a/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td b/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td index 582ab91..43ca533 100644 --- a/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td +++ b/mlir/include/mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td @@ -113,7 +113,7 @@ def OffloadingLLVMTranslationAttrInterface : The first argument has to be a GPU binary operation. If the function fails at any point, it must return `failure`. }], - "::mlir::LogicalResult", "embedBinary", + "::llvm::LogicalResult", "embedBinary", (ins "::mlir::Operation*":$binaryOp, "::llvm::IRBuilderBase&":$hostBuilder, "::mlir::LLVM::ModuleTranslation&":$hostModuleTranslation) @@ -130,7 +130,7 @@ def OffloadingLLVMTranslationAttrInterface : respectively. If the function fails at any point, it must return `failure`. }], - "::mlir::LogicalResult", "launchKernel", + "::llvm::LogicalResult", "launchKernel", (ins "::mlir::Operation*":$launchFunc, "::mlir::Operation*":$binaryOp, "::llvm::IRBuilderBase&":$hostBuilder, "::mlir::LLVM::ModuleTranslation&":$hostModuleTranslation) diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h b/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h index 74b78f9..30511e7 100644 --- a/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h +++ b/mlir/include/mlir/Dialect/GPU/Transforms/ParallelLoopMapper.h @@ -21,7 +21,6 @@ namespace mlir { class AffineMap; -struct LogicalResult; class Operation; class Region; diff --git a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h index f8c018e..0734939 100644 --- a/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h +++ b/mlir/include/mlir/Dialect/GPU/Transforms/Utils.h @@ -20,7 +20,6 @@ #include namespace mlir { -struct LogicalResult; class Operation; class Value; diff --git a/mlir/include/mlir/Dialect/IRDL/IR/IRDLInterfaces.h b/mlir/include/mlir/Dialect/IRDL/IR/IRDLInterfaces.h index 6455385..554fccec 100644 --- a/mlir/include/mlir/Dialect/IRDL/IR/IRDLInterfaces.h +++ b/mlir/include/mlir/Dialect/IRDL/IR/IRDLInterfaces.h @@ -19,7 +19,6 @@ #include "mlir/IR/ExtensibleDialect.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/Types.h" -#include "mlir/Support/LogicalResult.h" #include namespace mlir { diff --git a/mlir/include/mlir/Dialect/IRDL/IR/IRDLTraits.h b/mlir/include/mlir/Dialect/IRDL/IR/IRDLTraits.h index 1755341..98bedbf 100644 --- a/mlir/include/mlir/Dialect/IRDL/IR/IRDLTraits.h +++ b/mlir/include/mlir/Dialect/IRDL/IR/IRDLTraits.h @@ -15,7 +15,6 @@ #define MLIR_DIALECT_IRDL_IR_IRDLTRAITS_H_ #include "mlir/IR/OpDefinition.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/Casting.h" namespace mlir { diff --git a/mlir/include/mlir/Dialect/IRDL/IRDLLoading.h b/mlir/include/mlir/Dialect/IRDL/IRDLLoading.h index 64ad72b..13c2799 100644 --- a/mlir/include/mlir/Dialect/IRDL/IRDLLoading.h +++ b/mlir/include/mlir/Dialect/IRDL/IRDLLoading.h @@ -13,8 +13,11 @@ #ifndef MLIR_DIALECT_IRDL_IRDLREGISTRATION_H #define MLIR_DIALECT_IRDL_IRDLREGISTRATION_H -namespace mlir { +namespace llvm { struct LogicalResult; +} // namespace llvm + +namespace mlir { class ModuleOp; } // namespace mlir @@ -22,7 +25,7 @@ namespace mlir { namespace irdl { /// Load all the dialects defined in the module. -LogicalResult loadDialects(ModuleOp op); +llvm::LogicalResult loadDialects(ModuleOp op); } // namespace irdl } // namespace mlir diff --git a/mlir/include/mlir/Dialect/IRDL/IRDLVerifiers.h b/mlir/include/mlir/Dialect/IRDL/IRDLVerifiers.h index 89e99a6..bad52bb 100644 --- a/mlir/include/mlir/Dialect/IRDL/IRDLVerifiers.h +++ b/mlir/include/mlir/Dialect/IRDL/IRDLVerifiers.h @@ -21,7 +21,6 @@ #include namespace mlir { -struct LogicalResult; class InFlightDiagnostic; class DynamicAttrDefinition; class DynamicTypeDefinition; diff --git a/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h b/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h index f9fd32c..5430fd9 100644 --- a/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h +++ b/mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h @@ -11,7 +11,6 @@ #include "mlir/IR/Attributes.h" #include "mlir/IR/MLIRContext.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { namespace transform { diff --git a/mlir/include/mlir/Dialect/Linalg/TransformOps/Syntax.h b/mlir/include/mlir/Dialect/Linalg/TransformOps/Syntax.h index 13b0dc0..50e55e7 100644 --- a/mlir/include/mlir/Dialect/Linalg/TransformOps/Syntax.h +++ b/mlir/include/mlir/Dialect/Linalg/TransformOps/Syntax.h @@ -12,7 +12,6 @@ #include "mlir/Support/LLVM.h" namespace mlir { -class ParseResult; class OpAsmParser; class OpAsmPrinter; class Type; diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h index 3812eb5..2a58d02 100644 --- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h @@ -22,7 +22,6 @@ #include "mlir/Dialect/X86Vector/Transforms.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/TilingInterface.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallSet.h" diff --git a/mlir/include/mlir/Dialect/MemRef/Transforms/Transforms.h b/mlir/include/mlir/Dialect/MemRef/Transforms/Transforms.h index a918f62..4444a76 100644 --- a/mlir/include/mlir/Dialect/MemRef/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/MemRef/Transforms/Transforms.h @@ -14,7 +14,7 @@ #ifndef MLIR_DIALECT_MEMREF_TRANSFORMS_TRANSFORMS_H #define MLIR_DIALECT_MEMREF_TRANSFORMS_TRANSFORMS_H -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "llvm/ADT/STLFunctionalExtras.h" namespace mlir { diff --git a/mlir/include/mlir/Dialect/Mesh/Transforms/Spmdization.h b/mlir/include/mlir/Dialect/Mesh/Transforms/Spmdization.h index f847ce3..2f6de3e 100644 --- a/mlir/include/mlir/Dialect/Mesh/Transforms/Spmdization.h +++ b/mlir/include/mlir/Dialect/Mesh/Transforms/Spmdization.h @@ -11,7 +11,6 @@ #include "mlir/Dialect/Mesh/IR/MeshOps.h" #include "mlir/IR/DialectRegistry.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { namespace mesh { diff --git a/mlir/include/mlir/Dialect/NVGPU/Transforms/Transforms.h b/mlir/include/mlir/Dialect/NVGPU/Transforms/Transforms.h index 4bac898..2ff9ac4 100644 --- a/mlir/include/mlir/Dialect/NVGPU/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/NVGPU/Transforms/Transforms.h @@ -14,7 +14,6 @@ #define MLIR_DIALECT_NVGPU_TRANSFORMS_TRANSFORMS_H_ #include "mlir/IR/Operation.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { class RewriterBase; @@ -44,7 +43,7 @@ namespace nvgpu { /// function that depends on the row Index. The permutation function is chosen /// to ensure that sequential distributed+vectorized reads/writes down a single /// dimension of the memref have minimal conflicts. -mlir::LogicalResult optimizeSharedMemoryReadsAndWrites(Operation *parentOp, +llvm::LogicalResult optimizeSharedMemoryReadsAndWrites(Operation *parentOp, Value memrefValue); /// diff --git a/mlir/include/mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td b/mlir/include/mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td index 57063ca..223bee9 100644 --- a/mlir/include/mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.td @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// // -// Defines the operation interface for atomic operations used in OpenACC and +// Defines the operation interface for atomic operations used in OpenACC and // OpenMP. // //===----------------------------------------------------------------------===// @@ -34,7 +34,7 @@ def AtomicReadOpInterface : OpInterface<"AtomicReadOpInterface"> { InterfaceMethod<[{ Common verifier for operation that implements atomic read interface. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyCommon", /*args=*/(ins), /*methodBody=*/"", @@ -81,7 +81,7 @@ def AtomicWriteOpInterface : OpInterface<"AtomicWriteOpInterface"> { InterfaceMethod<[{ Common verifier for operation that implements atomic write interface. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyCommon", /*args=*/(ins), /*methodBody=*/"", @@ -118,7 +118,7 @@ def AtomicUpdateOpInterface : OpInterface<"AtomicUpdateOpInterface"> { The interface terminology uses `x` to specify the address where a value is atomically written/read. - + Since atomic update expression comes in many forms, this interface requires that the operation uses a region with a single argument to capture the expression. @@ -162,9 +162,9 @@ def AtomicUpdateOpInterface : OpInterface<"AtomicUpdateOpInterface"> { /*defaultImplementation=*/[{ // The atomic update is a no-op if the terminator is the first and only // operation in its region. - mlir::Operation* terminator = + mlir::Operation* terminator = llvm::dyn_cast($_op.getFirstOp()); - return terminator && terminator->getOperands().front() == + return terminator && terminator->getOperands().front() == $_op.getRegion().front().getArgument(0); }] >, @@ -177,9 +177,9 @@ def AtomicUpdateOpInterface : OpInterface<"AtomicUpdateOpInterface"> { /*args=*/(ins), /*methodBody=*/"", /*defaultImplementation=*/[{ - mlir::Operation* terminator = + mlir::Operation* terminator = llvm::dyn_cast($_op.getFirstOp()); - if (terminator && terminator->getOperands().front() != + if (terminator && terminator->getOperands().front() != $_op.getRegion().front().getArgument(0)) { return terminator->getOperands().front(); } @@ -189,7 +189,7 @@ def AtomicUpdateOpInterface : OpInterface<"AtomicUpdateOpInterface"> { InterfaceMethod<[{ Common verifier for operation that implements atomic update interface. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyCommon", /*args=*/(ins), /*methodBody=*/"", @@ -210,7 +210,7 @@ def AtomicUpdateOpInterface : OpInterface<"AtomicUpdateOpInterface"> { Common verifier of the required region for operation that implements atomic update interface. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyRegionsCommon", /*args=*/(ins), /*methodBody=*/"", @@ -219,7 +219,7 @@ def AtomicUpdateOpInterface : OpInterface<"AtomicUpdateOpInterface"> { if (terminator->getOperands().size() != 1) return $_op.emitError("only updated value must be returned"); - + if (terminator->getOperands().front().getType() != $_op.getRegion().getArgument(0).getType()) return $_op.emitError("input and yielded value must have the same type"); @@ -272,7 +272,7 @@ def AtomicCaptureOpInterface : OpInterface<"AtomicCaptureOpInterface"> { Common verifier of the required region for operation that implements atomic capture interface. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyRegionsCommon", /*args=*/(ins), /*methodBody=*/"", diff --git a/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h b/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h index e14cef5..3f206cd 100644 --- a/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h +++ b/mlir/include/mlir/Dialect/Polynomial/IR/Polynomial.h @@ -10,7 +10,6 @@ #define MLIR_DIALECT_POLYNOMIAL_IR_POLYNOMIAL_H_ #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" diff --git a/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h b/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h index 1863317..71835cd 100644 --- a/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h +++ b/mlir/include/mlir/Dialect/SCF/Transforms/Transforms.h @@ -18,8 +18,6 @@ #include "llvm/ADT/ArrayRef.h" namespace mlir { - -struct LogicalResult; class Region; class RewriterBase; class Operation; diff --git a/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h b/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h index 5022cbf..2913a74 100644 --- a/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h +++ b/mlir/include/mlir/Dialect/SCF/Utils/AffineCanonicalizationUtils.h @@ -15,11 +15,9 @@ #define MLIR_DIALECT_SCF_UTILS_AFFINECANONICALIZATIONUTILS_H_ #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" namespace mlir { class AffineMap; -struct LogicalResult; class Operation; class OpFoldResult; class RewriterBase; diff --git a/mlir/include/mlir/Dialect/SCF/Utils/Utils.h b/mlir/include/mlir/Dialect/SCF/Utils/Utils.h index fea151b..de807c3 100644 --- a/mlir/include/mlir/Dialect/SCF/Utils/Utils.h +++ b/mlir/include/mlir/Dialect/SCF/Utils/Utils.h @@ -16,7 +16,6 @@ #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorInterfaces.td b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorInterfaces.td index 05eed04..5c07e81 100644 --- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorInterfaces.td +++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorInterfaces.td @@ -32,7 +32,7 @@ def StageWithSortSparseOpInterface : OpInterface<"StageWithSortSparseOp"> { /*methodBody=*/"">, InterfaceMethod< /*desc=*/"Stage the operation, return the final result value after staging.", - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"stageWithSort", /*args=*/(ins "::mlir::PatternRewriter &":$rewriter, "Value &":$tmpBuf), diff --git a/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h b/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h index b835304..842e244 100644 --- a/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h +++ b/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h @@ -14,7 +14,6 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "mlir/Dialect/Transform/Interfaces/TransformTypeInterfaces.h.inc" @@ -1595,7 +1594,7 @@ mlir::transform::TransformEachOpTrait::apply( } template -mlir::LogicalResult +llvm::LogicalResult mlir::transform::TransformEachOpTrait::verifyTrait(Operation *op) { static_assert(OpTy::template hasTrait(), "expected single-operand op"); diff --git a/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.td b/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.td index c5c4c61..9439104 100644 --- a/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.td +++ b/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.td @@ -401,7 +401,7 @@ def ConversionPatternDescriptorOpInterface Verify the default type converter that is provided by the enclosing "apply_conversion_patterns" op. }], - /*returnType=*/"::mlir::LogicalResult", + /*returnType=*/"::llvm::LogicalResult", /*name=*/"verifyTypeConverter", /*arguments=*/(ins "TypeConverterBuilderOpInterface":$builder), /*methodBody=*/"", diff --git a/mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h b/mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h index 4c16d40..e78cf77 100644 --- a/mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h +++ b/mlir/include/mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h @@ -16,7 +16,6 @@ #include namespace mlir { -struct LogicalResult; class MLIRContext; class ModuleOp; class Operation; diff --git a/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h b/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h index fa2912a..8e6d36f 100644 --- a/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h +++ b/mlir/include/mlir/Dialect/Vector/Transforms/VectorRewritePatterns.h @@ -15,7 +15,6 @@ #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/Dialect/Vector/Utils/VectorUtils.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Dialect/Vector/Transforms/VectorTransformsEnums.h.inc" diff --git a/mlir/include/mlir/ExecutionEngine/JitRunner.h b/mlir/include/mlir/ExecutionEngine/JitRunner.h index 2dde094..b4210f6 100644 --- a/mlir/include/mlir/ExecutionEngine/JitRunner.h +++ b/mlir/include/mlir/ExecutionEngine/JitRunner.h @@ -24,6 +24,7 @@ namespace llvm { class Module; class LLVMContext; +struct LogicalResult; namespace orc { class MangleAndInterner; @@ -34,7 +35,6 @@ namespace mlir { class DialectRegistry; class Operation; -struct LogicalResult; /// JitRunner command line options used by JitRunnerConfig methods struct JitRunnerOptions { @@ -48,8 +48,8 @@ struct JitRunnerOptions { struct JitRunnerConfig { /// MLIR transformer applied after parsing the input into MLIR IR and before /// passing the MLIR IR to the ExecutionEngine. - llvm::function_ref + llvm::function_ref mlirTransformer = nullptr; /// A custom function that is passed to ExecutionEngine. It processes MLIR and diff --git a/mlir/include/mlir/IR/Action.h b/mlir/include/mlir/IR/Action.h index 9359324d..2fad477 100644 --- a/mlir/include/mlir/IR/Action.h +++ b/mlir/include/mlir/IR/Action.h @@ -16,7 +16,6 @@ #define MLIR_IR_ACTION_H #include "mlir/IR/Unit.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Sequence.h" diff --git a/mlir/include/mlir/IR/AffineExpr.h b/mlir/include/mlir/IR/AffineExpr.h index 63314cc..a93e74b 100644 --- a/mlir/include/mlir/IR/AffineExpr.h +++ b/mlir/include/mlir/IR/AffineExpr.h @@ -20,7 +20,6 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" -#include #include namespace mlir { diff --git a/mlir/include/mlir/IR/AffineExprVisitor.h b/mlir/include/mlir/IR/AffineExprVisitor.h index fc4cd915..1826f5f 100644 --- a/mlir/include/mlir/IR/AffineExprVisitor.h +++ b/mlir/include/mlir/IR/AffineExprVisitor.h @@ -14,7 +14,7 @@ #define MLIR_IR_AFFINEEXPRVISITOR_H #include "mlir/IR/AffineExpr.h" -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "llvm/ADT/ArrayRef.h" namespace mlir { diff --git a/mlir/include/mlir/IR/AffineMap.h b/mlir/include/mlir/IR/AffineMap.h index cce1412..264c1c8 100644 --- a/mlir/include/mlir/IR/AffineMap.h +++ b/mlir/include/mlir/IR/AffineMap.h @@ -35,7 +35,6 @@ struct AffineMapStorage; class Attribute; class Builder; -struct LogicalResult; class OpFoldResult; class MLIRContext; diff --git a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h index b0b9493..c4a4202 100644 --- a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h +++ b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h @@ -13,7 +13,6 @@ #include "mlir/IR/Attributes.h" #include "mlir/IR/BuiltinTypeInterfaces.h" #include "mlir/IR/Types.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/raw_ostream.h" #include #include diff --git a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td index c741db9..954429c 100644 --- a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td +++ b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td @@ -483,7 +483,7 @@ def MemRefLayoutAttrInterface : AttrInterface<"MemRefLayoutAttrInterface"> { InterfaceMethod< "Check if the current layout is applicable to the provided shape", - "::mlir::LogicalResult", "verifyLayout", + "::llvm::LogicalResult", "verifyLayout", (ins "::llvm::ArrayRef":$shape, "::llvm::function_ref<::mlir::InFlightDiagnostic()>":$emitError), [{}], diff --git a/mlir/include/mlir/IR/Diagnostics.h b/mlir/include/mlir/IR/Diagnostics.h index 205c5d9..bb2e1bb 100644 --- a/mlir/include/mlir/IR/Diagnostics.h +++ b/mlir/include/mlir/IR/Diagnostics.h @@ -25,7 +25,6 @@ class SourceMgr; namespace mlir { class DiagnosticEngine; -struct LogicalResult; class MLIRContext; class Operation; class OperationName; diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h index f7c1f4d..f3e5f6d 100644 --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -17,9 +17,6 @@ #include "mlir/IR/OperationSupport.h" #include "mlir/Support/TypeID.h" -#include -#include - namespace mlir { class DialectAsmParser; class DialectAsmPrinter; diff --git a/mlir/include/mlir/IR/EnumAttr.td b/mlir/include/mlir/IR/EnumAttr.td index f4dc480..9fec28f 100644 --- a/mlir/include/mlir/IR/EnumAttr.td +++ b/mlir/include/mlir/IR/EnumAttr.td @@ -227,7 +227,7 @@ class IntEnumAttr { symbol 'newSymbol' that are nested within the given operation 'from'. Note: See mlir::SymbolTable::replaceAllSymbolUses for more details. }], - "::mlir::LogicalResult", "replaceAllSymbolUses", + "::llvm::LogicalResult", "replaceAllSymbolUses", (ins "::mlir::StringAttr":$newSymbol, "::mlir::Operation *":$from), [{}], /*defaultImplementation=*/[{ return ::mlir::SymbolTable::replaceAllSymbolUses(this->getOperation(), @@ -214,7 +214,7 @@ def SymbolUserOpInterface : OpInterface<"SymbolUserOpInterface"> { let methods = [ InterfaceMethod<"Verify the symbol uses held by this operation.", - "::mlir::LogicalResult", "verifySymbolUses", + "::llvm::LogicalResult", "verifySymbolUses", (ins "::mlir::SymbolTableCollection &":$symbolTable) >, ]; diff --git a/mlir/include/mlir/IR/TensorEncoding.td b/mlir/include/mlir/IR/TensorEncoding.td index 4907dcb..d8ccd1f 100644 --- a/mlir/include/mlir/IR/TensorEncoding.td +++ b/mlir/include/mlir/IR/TensorEncoding.td @@ -31,7 +31,7 @@ def VerifiableTensorEncoding : AttrInterface<"VerifiableTensorEncoding"> { given shape and element type. Generates a diagnostic using the supplied callback on failure. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyEncoding", /*args=*/(ins "::mlir::ArrayRef":$shape, diff --git a/mlir/include/mlir/IR/Verifier.h b/mlir/include/mlir/IR/Verifier.h index 1fcc99e..eb96d11 100644 --- a/mlir/include/mlir/IR/Verifier.h +++ b/mlir/include/mlir/IR/Verifier.h @@ -9,8 +9,9 @@ #ifndef MLIR_IR_VERIFIER_H #define MLIR_IR_VERIFIER_H +#include "mlir/Support/LLVM.h" + namespace mlir { -struct LogicalResult; class Operation; /// Perform (potentially expensive) checks of invariants, used to detect diff --git a/mlir/include/mlir/IR/Visitors.h b/mlir/include/mlir/IR/Visitors.h index fe98774..15abf25 100644 --- a/mlir/include/mlir/IR/Visitors.h +++ b/mlir/include/mlir/IR/Visitors.h @@ -14,7 +14,6 @@ #define MLIR_IR_VISITORS_H #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" namespace mlir { diff --git a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td index d4b8999..bc5080c 100644 --- a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td +++ b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td @@ -52,7 +52,7 @@ def DataLayoutEntryInterface : AttrInterface<"DataLayoutEntryInterface"> { InterfaceMethod< /*description=*/"Checks that the entry is well-formed, reports errors " "at the provided location.", - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyEntry", /*args=*/(ins "::mlir::Location":$loc), /*methodBody=*/"", @@ -166,7 +166,7 @@ def DataLayoutSpecInterface : AttrInterface<"DataLayoutSpecInterface"> { InterfaceMethod< /*description=*/"Verifies the validity of the specification and reports " "any errors at the given location.", - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifySpec", /*args=*/(ins "::mlir::Location":$loc), /*methodBody=*/"", @@ -232,7 +232,7 @@ def TargetDeviceSpecInterface : AttrInterface<"TargetDeviceSpecInterface"> { InterfaceMethod< /*description=*/"Checks that the entry is well-formed, reports errors " "at the provided location.", - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyEntry", /*args=*/(ins "::mlir::Location":$loc), /*methodBody=*/"", @@ -275,7 +275,7 @@ def TargetSystemSpecInterface : AttrInterface<"TargetSystemSpecInterface"> { InterfaceMethod< /*description=*/"Verifies the validity of the specification and " "reports any errors at the given location.", - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifySpec", /*args=*/(ins "::mlir::Location":$loc), /*methodBody=*/"", @@ -574,7 +574,7 @@ def DataLayoutTypeInterface : TypeInterface<"DataLayoutTypeInterface"> { InterfaceMethod< /*description=*/"Verifies that the given list of entries is valid for " "this type.", - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"verifyEntries", /*args=*/(ins "::mlir::DataLayoutEntryListRef":$entries, "::mlir::Location":$loc), diff --git a/mlir/include/mlir/Interfaces/FoldInterfaces.h b/mlir/include/mlir/Interfaces/FoldInterfaces.h index 6278e31..b3d1161 100644 --- a/mlir/include/mlir/Interfaces/FoldInterfaces.h +++ b/mlir/include/mlir/Interfaces/FoldInterfaces.h @@ -9,7 +9,6 @@ #define MLIR_INTERFACES_FOLDINTERFACES_H_ #include "mlir/IR/DialectInterface.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/include/mlir/Interfaces/FunctionInterfaces.td b/mlir/include/mlir/Interfaces/FunctionInterfaces.td index 873853e..697f951 100644 --- a/mlir/include/mlir/Interfaces/FunctionInterfaces.td +++ b/mlir/include/mlir/Interfaces/FunctionInterfaces.td @@ -83,7 +83,7 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [ Note: The default implementation merely checks that if the entry block exists, it has the same number and type of arguments as the function type. }], - "::mlir::LogicalResult", "verifyBody", (ins), + "::llvm::LogicalResult", "verifyBody", (ins), /*methodBody=*/[{}], /*defaultImplementation=*/[{ if ($_op.isExternal()) return success(); @@ -114,7 +114,7 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [ Verify the type attribute of the function for derived op-specific invariants. }], - "::mlir::LogicalResult", "verifyType", (ins), + "::llvm::LogicalResult", "verifyType", (ins), /*methodBody=*/[{}], /*defaultImplementation=*/[{ return success(); }]>, diff --git a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td index a009e21..92d4a99 100644 --- a/mlir/include/mlir/Interfaces/InferTypeOpInterface.td +++ b/mlir/include/mlir/Interfaces/InferTypeOpInterface.td @@ -38,7 +38,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { called with valid arguments, e.g., operands are verified, or it may result in an undefined behavior. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"inferReturnTypes", /*args=*/(ins "::mlir::MLIRContext *":$context, "::std::optional<::mlir::Location>":$location, @@ -72,7 +72,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { represent fully valid IR and are responsible for checking inputs for validity to the degree necessary to perform the return type inference. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"refineReturnTypes", /*args=*/(ins "::mlir::MLIRContext *":$context, "::std::optional<::mlir::Location>":$location, @@ -150,7 +150,7 @@ def InferShapedTypeOpInterface : OpInterface<"InferShapedTypeOpInterface"> { represent fully valid IR and are responsible for checking inputs for validity to the degree necessary to perform the return type inference. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"inferReturnTypeComponents", /*args=*/(ins "::mlir::MLIRContext*":$context, "::std::optional<::mlir::Location>":$location, @@ -180,7 +180,7 @@ def InferShapedTypeOpInterface : OpInterface<"InferShapedTypeOpInterface"> { operands to avoid calling `getOperand` directly inside the interface implementation. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"reifyReturnTypeShapes", /*args=*/(ins "::mlir::OpBuilder&":$builder, "::mlir::ValueRange":$operands, @@ -201,14 +201,14 @@ class InferTypeOpAdaptorBase : TraitList< /*name=*/"InferTypeOpAdaptor", /*traits=*/[], /*extraOpDeclaration=*/[{ - static ::mlir::LogicalResult + static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, Adaptor adaptor, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes); }] # additionalDecls, /*extraOpDefinition=*/[{ - ::mlir::LogicalResult + ::llvm::LogicalResult $cppClass::inferReturnTypes(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, @@ -239,14 +239,14 @@ class InferShapedTypeOpAdaptorBase overridenMethods = []> : TraitLi /*name=*/"InferShapedTypeOpAdaptor", /*traits=*/[], /*extraOpDeclaration=*/[{ - static ::mlir::LogicalResult + static ::llvm::LogicalResult inferReturnTypeComponents(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, Adaptor adaptor, ::llvm::SmallVectorImpl<::mlir::ShapedTypeComponents> &inferredReturnShapes); }], /*extraOpDefinition=*/[{ - ::mlir::LogicalResult + ::llvm::LogicalResult $cppClass::inferReturnTypeComponents(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, ::mlir::ValueShapeRange operands, ::mlir::DictionaryAttr attributes, @@ -281,7 +281,7 @@ class InferTensorTypeBase overridenMethods = []> : TraitList< /*traits=*/[], /*extraOpDeclaration=*/[{}], /*extraOpDefinition=*/[{ - ::mlir::LogicalResult + ::llvm::LogicalResult $cppClass::inferReturnTypes(::mlir::MLIRContext *context, std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, @@ -364,7 +364,7 @@ def ReifyRankedShapedTypeOpInterface : If the shape of a particular result cannot be computed it must be empty. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"reifyResultShapes", /*args=*/(ins "::mlir::OpBuilder &":$builder, "::mlir::ReifiedRankedShapedTypeDims &":$reifiedReturnShapes) diff --git a/mlir/include/mlir/Interfaces/LoopLikeInterface.td b/mlir/include/mlir/Interfaces/LoopLikeInterface.td index 7db624b..c6bffe3 100644 --- a/mlir/include/mlir/Interfaces/LoopLikeInterface.td +++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.td @@ -84,7 +84,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> { have a single iteration. Returns "success" if the promotion was successful. }], - /*retTy=*/"::mlir::LogicalResult", + /*retTy=*/"::llvm::LogicalResult", /*methodName=*/"promoteIfSingleIteration", /*args=*/(ins "::mlir::RewriterBase &":$rewriter), /*methodBody=*/"", diff --git a/mlir/include/mlir/Interfaces/MemorySlotInterfaces.td b/mlir/include/mlir/Interfaces/MemorySlotInterfaces.td index 6f023f0..fbce2fa 100644 --- a/mlir/include/mlir/Interfaces/MemorySlotInterfaces.td +++ b/mlir/include/mlir/Interfaces/MemorySlotInterfaces.td @@ -75,7 +75,7 @@ def PromotableAllocationOpInterface "::std::optional<::mlir::PromotableAllocationOpInterface>", "handlePromotionComplete", (ins - "const ::mlir::MemorySlot &":$slot, + "const ::mlir::MemorySlot &":$slot, "::mlir::Value":$defaultValue, "::mlir::OpBuilder &":$builder) >, @@ -308,7 +308,7 @@ def DestructurableAllocationOpInterface This will only be called for slots declared by this operation. Must return a new destructurable allocation op if this hook creates - a new destructurable op, nullopt otherwise. + a new destructurable op, nullopt otherwise. }], "::std::optional<::mlir::DestructurableAllocationOpInterface>", "handleDestructuringComplete", @@ -338,7 +338,7 @@ def SafeMemorySlotAccessOpInterface No IR mutation is allowed in this method. }], - "::mlir::LogicalResult", + "::llvm::LogicalResult", "ensureOnlySafeAccesses", (ins "const ::mlir::MemorySlot &":$slot, "::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed, diff --git a/mlir/include/mlir/Interfaces/TilingInterface.td b/mlir/include/mlir/Interfaces/TilingInterface.td index ad0af0a..4868dad 100644 --- a/mlir/include/mlir/Interfaces/TilingInterface.td +++ b/mlir/include/mlir/Interfaces/TilingInterface.td @@ -26,7 +26,7 @@ def TilingInterface : OpInterface<"TilingInterface"> { the tiling algorithm (like `scf::tileUsingSCF`) can generate the inter-tile loop structure, and call into the methods of the interface to be able to tile any operation that implements the interface. - + This interface is also meant to help with "tile and fuse", i.e. the process of fusing a producer with a consumer by a) Tiling the consumer @@ -50,7 +50,7 @@ def TilingInterface : OpInterface<"TilingInterface"> { For an operation to be "tiled and fused" with its (already tiled) consumer, an operation has to implement the following additional method (see - description below): + description below): - `generateResultTileValue` - `getIterationDomainTileFromResultTile` @@ -146,7 +146,7 @@ def TilingInterface : OpInterface<"TilingInterface"> { Note: It is undefined behaviour if there is overlap between the tiles of the result generated by the tiled implementation. }], - /*retType=*/"::mlir::LogicalResult", + /*retType=*/"::llvm::LogicalResult", /*methodName=*/"getResultTilePosition", /*args=*/(ins "OpBuilder &":$b, @@ -289,7 +289,7 @@ def TilingInterface : OpInterface<"TilingInterface"> { implemented using `getIterationDomainTileFromOperandTile` + `getTiledImplementation` methods. }], - /*retType=*/"::mlir::LogicalResult", + /*retType=*/"::llvm::LogicalResult", /*methodName=*/"getIterationDomainTileFromOperandTile", /*args=*/(ins "OpBuilder &":$b, @@ -317,14 +317,14 @@ def TilingInterface : OpInterface<"TilingInterface"> { - `sizes` is the size of the slice of the producer result used by the consumer. If fusion of the producer with the consumer is not legal for the - result, or if this mapping cannot be computed, the implementation + result, or if this mapping cannot be computed, the implementation should return a failure. - - For most cases `generateResultTileValue` could be a implemented using - `getIterationDomainTileFromResultTile` + `getTiledImplementation` + + For most cases `generateResultTileValue` could be a implemented using + `getIterationDomainTileFromResultTile` + `getTiledImplementation` methods. }], - /*retType=*/"::mlir::LogicalResult", + /*retType=*/"::llvm::LogicalResult", /*methodName=*/"getIterationDomainTileFromResultTile", /*args=*/(ins "OpBuilder &":$b, @@ -349,7 +349,7 @@ def TilingInterface : OpInterface<"TilingInterface"> { transformations are done, this method can be used to lower to scalar code that can then be lowered to LLVM or SPIR-V dialects. }], - /*retType=*/"::mlir::LogicalResult", + /*retType=*/"::llvm::LogicalResult", /*methodName=*/"generateScalarImplementation", /*args=*/(ins "OpBuilder &":$b, diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index e71c49a..7725a3a 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -12,7 +12,6 @@ #include "mlir/IR/Action.h" #include "mlir/Pass/AnalysisManager.h" #include "mlir/Pass/PassRegistry.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/Statistic.h" #include diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h index b3e4275..d9bab43 100644 --- a/mlir/include/mlir/Pass/PassManager.h +++ b/mlir/include/mlir/Pass/PassManager.h @@ -11,7 +11,6 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/OperationSupport.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/Timing.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/iterator.h" diff --git a/mlir/include/mlir/Pass/PassOptions.h b/mlir/include/mlir/Pass/PassOptions.h index 3a5e322..b99d91f 100644 --- a/mlir/include/mlir/Pass/PassOptions.h +++ b/mlir/include/mlir/Pass/PassOptions.h @@ -15,7 +15,6 @@ #define MLIR_PASS_PASSOPTIONS_H_ #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/FunctionExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/CommandLine.h" diff --git a/mlir/include/mlir/Query/Query.h b/mlir/include/mlir/Query/Query.h index 447fc7c..18f2172 100644 --- a/mlir/include/mlir/Query/Query.h +++ b/mlir/include/mlir/Query/Query.h @@ -10,7 +10,6 @@ #define MLIR_TOOLS_MLIRQUERY_QUERY_H #include "Matcher/VariantValue.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/LineEditor/LineEditor.h" @@ -27,7 +26,7 @@ struct Query : llvm::RefCountedBase { virtual ~Query(); // Perform the query on qs and print output to os. - virtual mlir::LogicalResult run(llvm::raw_ostream &os, + virtual llvm::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const = 0; llvm::StringRef remainingContent; @@ -45,7 +44,7 @@ complete(llvm::StringRef line, size_t pos, const QuerySession &qs); struct InvalidQuery : Query { InvalidQuery(const llvm::Twine &errStr) : Query(QueryKind::Invalid), errStr(errStr.str()) {} - mlir::LogicalResult run(llvm::raw_ostream &os, + llvm::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override; std::string errStr; @@ -58,7 +57,7 @@ struct InvalidQuery : Query { // No-op query (i.e. a blank line). struct NoOpQuery : Query { NoOpQuery() : Query(QueryKind::NoOp) {} - mlir::LogicalResult run(llvm::raw_ostream &os, + llvm::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override; static bool classof(const Query *query) { @@ -69,7 +68,7 @@ struct NoOpQuery : Query { // Query for "help". struct HelpQuery : Query { HelpQuery() : Query(QueryKind::Help) {} - mlir::LogicalResult run(llvm::raw_ostream &os, + llvm::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override; static bool classof(const Query *query) { @@ -80,7 +79,7 @@ struct HelpQuery : Query { // Query for "quit". struct QuitQuery : Query { QuitQuery() : Query(QueryKind::Quit) {} - mlir::LogicalResult run(llvm::raw_ostream &os, + llvm::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override; static bool classof(const Query *query) { @@ -92,7 +91,7 @@ struct QuitQuery : Query { struct MatchQuery : Query { MatchQuery(llvm::StringRef source, const matcher::DynMatcher &matcher) : Query(QueryKind::Match), matcher(matcher), source(source) {} - mlir::LogicalResult run(llvm::raw_ostream &os, + llvm::LogicalResult run(llvm::raw_ostream &os, QuerySession &qs) const override; const matcher::DynMatcher matcher; diff --git a/mlir/include/mlir/Reducer/ReductionNode.h b/mlir/include/mlir/Reducer/ReductionNode.h index 814c885..6ca4e13 100644 --- a/mlir/include/mlir/Reducer/ReductionNode.h +++ b/mlir/include/mlir/Reducer/ReductionNode.h @@ -22,7 +22,6 @@ #include "mlir/IR/OwningOpRef.h" #include "mlir/Reducer/Tester.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/ToolOutputFile.h" diff --git a/mlir/include/mlir/Support/LLVM.h b/mlir/include/mlir/Support/LLVM.h index 7baca03..020c0fb 100644 --- a/mlir/include/mlir/Support/LLVM.h +++ b/mlir/include/mlir/Support/LLVM.h @@ -21,7 +21,10 @@ // We include this header because it cannot be practically forward // declared, and are effectively language features. #include "llvm/Support/Casting.h" -#include + +// We include this header because large portions of mlir would have to include +// it anyway. +#include "llvm/Support/LogicalResult.h" // Workaround for clang-5 (PR41549) #if defined(__clang_major__) @@ -151,6 +154,15 @@ using llvm::iterator_range; using llvm::raw_ostream; using llvm::SMLoc; using llvm::SMRange; + +// LogicalResult. +using llvm::failed; +using llvm::failure; +using llvm::FailureOr; +using llvm::LogicalResult; +using llvm::ParseResult; +using llvm::succeeded; +using llvm::success; } // namespace mlir #endif // MLIR_SUPPORT_LLVM_H diff --git a/mlir/include/mlir/Support/LogicalResult.h b/mlir/include/mlir/Support/LogicalResult.h index 7ee7046..c7da8de 100644 --- a/mlir/include/mlir/Support/LogicalResult.h +++ b/mlir/include/mlir/Support/LogicalResult.h @@ -1,4 +1,4 @@ -//===- LogicalResult.h - Utilities for handling success/failure -*- C++ -*-===// +//===- LogicalResult.h - Stub aliasing to llvm/LogicalResult ----*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,123 +9,18 @@ #ifndef MLIR_SUPPORT_LOGICALRESULT_H #define MLIR_SUPPORT_LOGICALRESULT_H -#include "mlir/Support/LLVM.h" -#include +#include "llvm/Support/LogicalResult.h" +// TODO: This header is a stop-gap to avoid breaking downstream, and is to be +// removed eventually. namespace mlir { - -/// This class represents an efficient way to signal success or failure. It -/// should be preferred over the use of `bool` when appropriate, as it avoids -/// all of the ambiguity that arises in interpreting a boolean result. This -/// class is marked as NODISCARD to ensure that the result is processed. Users -/// may explicitly discard a result by using `(void)`, e.g. -/// `(void)functionThatReturnsALogicalResult();`. Given the intended nature of -/// this class, it generally shouldn't be used as the result of functions that -/// very frequently have the result ignored. This class is intended to be used -/// in conjunction with the utility functions below. -struct [[nodiscard]] LogicalResult { -public: - /// If isSuccess is true a `success` result is generated, otherwise a - /// 'failure' result is generated. - static LogicalResult success(bool isSuccess = true) { - return LogicalResult(isSuccess); - } - - /// If isFailure is true a `failure` result is generated, otherwise a - /// 'success' result is generated. - static LogicalResult failure(bool isFailure = true) { - return LogicalResult(!isFailure); - } - - /// Returns true if the provided LogicalResult corresponds to a success value. - bool succeeded() const { return isSuccess; } - - /// Returns true if the provided LogicalResult corresponds to a failure value. - bool failed() const { return !isSuccess; } - -private: - LogicalResult(bool isSuccess) : isSuccess(isSuccess) {} - - /// Boolean indicating if this is a success result, if false this is a - /// failure result. - bool isSuccess; -}; - -/// Utility function to generate a LogicalResult. If isSuccess is true a -/// `success` result is generated, otherwise a 'failure' result is generated. -inline LogicalResult success(bool isSuccess = true) { - return LogicalResult::success(isSuccess); -} - -/// Utility function to generate a LogicalResult. If isFailure is true a -/// `failure` result is generated, otherwise a 'success' result is generated. -inline LogicalResult failure(bool isFailure = true) { - return LogicalResult::failure(isFailure); -} - -/// Utility function that returns true if the provided LogicalResult corresponds -/// to a success value. -inline bool succeeded(LogicalResult result) { return result.succeeded(); } - -/// Utility function that returns true if the provided LogicalResult corresponds -/// to a failure value. -inline bool failed(LogicalResult result) { return result.failed(); } - -/// This class provides support for representing a failure result, or a valid -/// value of type `T`. This allows for integrating with LogicalResult, while -/// also providing a value on the success path. -template -class [[nodiscard]] FailureOr : public std::optional { -public: - /// Allow constructing from a LogicalResult. The result *must* be a failure. - /// Success results should use a proper instance of type `T`. - FailureOr(LogicalResult result) { - assert(failed(result) && - "success should be constructed with an instance of 'T'"); - } - FailureOr() : FailureOr(failure()) {} - FailureOr(T &&y) : std::optional(std::forward(y)) {} - FailureOr(const T &y) : std::optional(y) {} - template ::value> * = nullptr> - FailureOr(const FailureOr &other) - : std::optional(failed(other) ? std::optional() - : std::optional(*other)) {} - - operator LogicalResult() const { return success(this->has_value()); } - -private: - /// Hide the bool conversion as it easily creates confusion. - using std::optional::operator bool; - using std::optional::has_value; -}; - -/// Wrap a value on the success path in a FailureOr of the same value type. -template >> -inline auto success(T &&t) { - return FailureOr>(std::forward(t)); -} - -/// This class represents success/failure for parsing-like operations that find -/// it important to chain together failable operations with `||`. This is an -/// extended version of `LogicalResult` that allows for explicit conversion to -/// bool. -/// -/// This class should not be used for general error handling cases - we prefer -/// to keep the logic explicit with the `succeeded`/`failed` predicates. -/// However, traditional monadic-style parsing logic can sometimes get -/// swallowed up in boilerplate without this, so we provide this for narrow -/// cases where it is important. -/// -class [[nodiscard]] ParseResult : public LogicalResult { -public: - ParseResult(LogicalResult result = success()) : LogicalResult(result) {} - - /// Failure is true in a boolean context. - explicit operator bool() const { return failed(); } -}; - +using llvm::failed; +using llvm::failure; +using llvm::FailureOr; +using llvm::LogicalResult; +using llvm::ParseResult; +using llvm::succeeded; +using llvm::success; } // namespace mlir #endif // MLIR_SUPPORT_LOGICALRESULT_H diff --git a/mlir/include/mlir/Support/StorageUniquer.h b/mlir/include/mlir/Support/StorageUniquer.h index 2369d9c..26bdf09 100644 --- a/mlir/include/mlir/Support/StorageUniquer.h +++ b/mlir/include/mlir/Support/StorageUniquer.h @@ -10,7 +10,6 @@ #define MLIR_SUPPORT_STORAGEUNIQUER_H #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" diff --git a/mlir/include/mlir/Support/ToolUtilities.h b/mlir/include/mlir/Support/ToolUtilities.h index 511cb11..cb6ba29 100644 --- a/mlir/include/mlir/Support/ToolUtilities.h +++ b/mlir/include/mlir/Support/ToolUtilities.h @@ -24,8 +24,6 @@ class MemoryBuffer; } // namespace llvm namespace mlir { -struct LogicalResult; - using ChunkBufferHandler = function_ref chunkBuffer, raw_ostream &os)>; diff --git a/mlir/include/mlir/Target/Cpp/CppEmitter.h b/mlir/include/mlir/Target/Cpp/CppEmitter.h index d3c0810..99d8696 100644 --- a/mlir/include/mlir/Target/Cpp/CppEmitter.h +++ b/mlir/include/mlir/Target/Cpp/CppEmitter.h @@ -16,7 +16,6 @@ #include "mlir/Support/LLVM.h" namespace mlir { -struct LogicalResult; class Operation; namespace emitc { diff --git a/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h b/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h index 44c9ded..3c637a0 100644 --- a/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h +++ b/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h @@ -15,6 +15,7 @@ #include "mlir/Dialect/GPU/IR/CompilationInterfaces.h" #include "mlir/Dialect/LLVMIR/ROCDLDialect.h" +#include "mlir/Support/LLVM.h" #include "mlir/Target/LLVM/ModuleToObject.h" namespace mlir { diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h b/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h index 86bcd58..74b5454 100644 --- a/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h +++ b/mlir/include/mlir/Target/LLVMIR/LLVMImportInterface.h @@ -19,7 +19,6 @@ #include "mlir/IR/Diagnostics.h" #include "mlir/IR/DialectInterface.h" #include "mlir/IR/Location.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/Support/FormatVariadic.h" diff --git a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h index 4a8ee06..11cb836 100644 --- a/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h +++ b/mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h @@ -16,7 +16,6 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/DialectInterface.h" -#include "mlir/Support/LogicalResult.h" namespace llvm { class Instruction; diff --git a/mlir/include/mlir/Target/SPIRV/Serialization.h b/mlir/include/mlir/Target/SPIRV/Serialization.h index 498f390..613f0a4 100644 --- a/mlir/include/mlir/Target/SPIRV/Serialization.h +++ b/mlir/include/mlir/Target/SPIRV/Serialization.h @@ -16,7 +16,6 @@ #include "mlir/Support/LLVM.h" namespace mlir { -struct LogicalResult; class MLIRContext; namespace spirv { diff --git a/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h b/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h index a8bae32..aaba810 100644 --- a/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h +++ b/mlir/include/mlir/Tools/PDLL/AST/Diagnostic.h @@ -13,7 +13,6 @@ #include #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/FunctionExtras.h" #include "llvm/Support/SourceMgr.h" diff --git a/mlir/include/mlir/Tools/PDLL/CodeGen/MLIRGen.h b/mlir/include/mlir/Tools/PDLL/CodeGen/MLIRGen.h index c691c39..c106f6d 100644 --- a/mlir/include/mlir/Tools/PDLL/CodeGen/MLIRGen.h +++ b/mlir/include/mlir/Tools/PDLL/CodeGen/MLIRGen.h @@ -11,8 +11,6 @@ #include -#include "mlir/Support/LogicalResult.h" - namespace llvm { class SourceMgr; } // namespace llvm diff --git a/mlir/include/mlir/Tools/PDLL/Parser/Parser.h b/mlir/include/mlir/Tools/PDLL/Parser/Parser.h index 1a43a3b..6f62aaf 100644 --- a/mlir/include/mlir/Tools/PDLL/Parser/Parser.h +++ b/mlir/include/mlir/Tools/PDLL/Parser/Parser.h @@ -11,7 +11,7 @@ #include -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" namespace llvm { class SourceMgr; diff --git a/mlir/include/mlir/Tools/lsp-server-support/CompilationDatabase.h b/mlir/include/mlir/Tools/lsp-server-support/CompilationDatabase.h index 84807ec..588c136 100644 --- a/mlir/include/mlir/Tools/lsp-server-support/CompilationDatabase.h +++ b/mlir/include/mlir/Tools/lsp-server-support/CompilationDatabase.h @@ -20,6 +20,7 @@ #include "llvm/ADT/StringMap.h" #include #include +#include namespace mlir { namespace lsp { diff --git a/mlir/include/mlir/Tools/lsp-server-support/Protocol.h b/mlir/include/mlir/Tools/lsp-server-support/Protocol.h index 1d22b8a..5d2eb01 100644 --- a/mlir/include/mlir/Tools/lsp-server-support/Protocol.h +++ b/mlir/include/mlir/Tools/lsp-server-support/Protocol.h @@ -28,15 +28,12 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" #include -#include #include #include #include #include namespace mlir { -struct LogicalResult; - namespace lsp { enum class ErrorCode { diff --git a/mlir/include/mlir/Tools/lsp-server-support/Transport.h b/mlir/include/mlir/Tools/lsp-server-support/Transport.h index 83fff92..6843bc7 100644 --- a/mlir/include/mlir/Tools/lsp-server-support/Transport.h +++ b/mlir/include/mlir/Tools/lsp-server-support/Transport.h @@ -17,7 +17,6 @@ #include "mlir/Support/DebugStringHelper.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Tools/lsp-server-support/Logging.h" #include "mlir/Tools/lsp-server-support/Protocol.h" #include "llvm/ADT/FunctionExtras.h" diff --git a/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h b/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h index 5207106..66d5d40 100644 --- a/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h +++ b/mlir/include/mlir/Tools/mlir-lsp-server/MlirLspServerMain.h @@ -13,15 +13,18 @@ #ifndef MLIR_TOOLS_MLIR_LSP_SERVER_MLIRLSPSERVERMAIN_H #define MLIR_TOOLS_MLIR_LSP_SERVER_MLIRLSPSERVERMAIN_H +namespace llvm { +struct LogicalResult; +} // namespace llvm + namespace mlir { class DialectRegistry; -struct LogicalResult; /// Implementation for tools like `mlir-lsp-server`. /// - registry should contain all the dialects that can be parsed in source IR /// passed to the server. -LogicalResult MlirLspServerMain(int argc, char **argv, - DialectRegistry ®istry); +llvm::LogicalResult MlirLspServerMain(int argc, char **argv, + DialectRegistry ®istry); } // namespace mlir diff --git a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h index 4f7f83c..d0ca188 100644 --- a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h +++ b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h @@ -14,7 +14,6 @@ #define MLIR_TOOLS_MLIROPT_MLIROPTMAIN_H #include "mlir/Debug/CLOptionsSetup.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/ToolUtilities.h" #include "llvm/ADT/StringRef.h" diff --git a/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h b/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h index a193732..c45ddb6 100644 --- a/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h +++ b/mlir/include/mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h @@ -14,11 +14,13 @@ #ifndef MLIR_TOOLS_MLIR_PDLL_LSP_SERVER_MLIRPDLLLSPSERVERMAIN_H #define MLIR_TOOLS_MLIR_PDLL_LSP_SERVER_MLIRPDLLLSPSERVERMAIN_H -namespace mlir { +namespace llvm { struct LogicalResult; +} // namespace llvm +namespace mlir { /// Implementation for tools like `mlir-pdll-lsp-server`. -LogicalResult MlirPdllLspServerMain(int argc, char **argv); +llvm::LogicalResult MlirPdllLspServerMain(int argc, char **argv); } // namespace mlir diff --git a/mlir/include/mlir/Tools/mlir-query/MlirQueryMain.h b/mlir/include/mlir/Tools/mlir-query/MlirQueryMain.h index fa1cd5d..44d5c8d 100644 --- a/mlir/include/mlir/Tools/mlir-query/MlirQueryMain.h +++ b/mlir/include/mlir/Tools/mlir-query/MlirQueryMain.h @@ -15,7 +15,7 @@ #define MLIR_TOOLS_MLIRQUERY_MLIRQUERYMAIN_H #include "mlir/Query/Matcher/Registry.h" -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" namespace mlir { diff --git a/mlir/include/mlir/Tools/mlir-reduce/MlirReduceMain.h b/mlir/include/mlir/Tools/mlir-reduce/MlirReduceMain.h index fccff9e..cb215b3 100644 --- a/mlir/include/mlir/Tools/mlir-reduce/MlirReduceMain.h +++ b/mlir/include/mlir/Tools/mlir-reduce/MlirReduceMain.h @@ -9,7 +9,7 @@ #ifndef MLIR_TOOLS_MLIR_REDUCE_MLIRREDUCEMAIN_H #define MLIR_TOOLS_MLIR_REDUCE_MLIRREDUCEMAIN_H -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" namespace mlir { diff --git a/mlir/include/mlir/Tools/mlir-translate/MlirTranslateMain.h b/mlir/include/mlir/Tools/mlir-translate/MlirTranslateMain.h index 4776987..c9bc58b 100644 --- a/mlir/include/mlir/Tools/mlir-translate/MlirTranslateMain.h +++ b/mlir/include/mlir/Tools/mlir-translate/MlirTranslateMain.h @@ -13,7 +13,7 @@ #ifndef MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H #define MLIR_TOOLS_MLIRTRANSLATE_MLIRTRANSLATEMAIN_H -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "llvm/ADT/StringRef.h" namespace mlir { diff --git a/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h b/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h index 6859300..f0799c5 100644 --- a/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h +++ b/mlir/include/mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h @@ -13,12 +13,13 @@ #ifndef MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENLSPSERVERMAIN_H #define MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENLSPSERVERMAIN_H -namespace mlir { +namespace llvm { struct LogicalResult; +} // namespace llvm +namespace mlir { /// Implementation for tools like `tblgen-lsp-server`. -LogicalResult TableGenLspServerMain(int argc, char **argv); - +llvm::LogicalResult TableGenLspServerMain(int argc, char **argv); } // namespace mlir #endif // MLIR_TOOLS_TBLGENLSPSERVER_TABLEGENLSPSERVERMAIN_H diff --git a/mlir/include/mlir/Transforms/HomomorphismSimplification.h b/mlir/include/mlir/Transforms/HomomorphismSimplification.h index d273260..386a315 100644 --- a/mlir/include/mlir/Transforms/HomomorphismSimplification.h +++ b/mlir/include/mlir/Transforms/HomomorphismSimplification.h @@ -13,7 +13,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Value.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" #include diff --git a/mlir/include/mlir/Transforms/Inliner.h b/mlir/include/mlir/Transforms/Inliner.h index 073b83f..ec77319 100644 --- a/mlir/include/mlir/Transforms/Inliner.h +++ b/mlir/include/mlir/Transforms/Inliner.h @@ -17,7 +17,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Pass/AnalysisManager.h" #include "mlir/Pass/PassManager.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/StringMap.h" namespace mlir { diff --git a/mlir/include/mlir/Transforms/LocationSnapshot.h b/mlir/include/mlir/Transforms/LocationSnapshot.h index a2b4200..ccfdbac 100644 --- a/mlir/include/mlir/Transforms/LocationSnapshot.h +++ b/mlir/include/mlir/Transforms/LocationSnapshot.h @@ -21,7 +21,6 @@ namespace mlir { class Location; -struct LogicalResult; class Operation; class OpPrintingFlags; class Pass; diff --git a/mlir/include/mlir/Transforms/SROA.h b/mlir/include/mlir/Transforms/SROA.h index d48f809..88e4bab 100644 --- a/mlir/include/mlir/Transforms/SROA.h +++ b/mlir/include/mlir/Transforms/SROA.h @@ -10,7 +10,7 @@ #define MLIR_TRANSFORMS_SROA_H #include "mlir/Interfaces/MemorySlotInterfaces.h" -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "llvm/ADT/Statistic.h" namespace mlir { diff --git a/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp b/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp index b22f3fd..6cece46 100644 --- a/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp +++ b/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp @@ -22,7 +22,6 @@ #include "mlir/Interfaces/SideEffectInterfaces.h" #include "mlir/Interfaces/ViewLikeInterface.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/Casting.h" #include #include diff --git a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp index 99c0419..16799d3 100644 --- a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp @@ -13,7 +13,6 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/Value.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp index 64df74e..fab2bd8 100644 --- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp @@ -21,7 +21,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/Casting.h" #include #include diff --git a/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp index d4b9134..9894810 100644 --- a/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp @@ -16,7 +16,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Casting.h" #include diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp index b47bba1..ad956b7 100644 --- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp +++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp @@ -18,7 +18,6 @@ #include "mlir/Interfaces/CallInterfaces.h" #include "mlir/Interfaces/ControlFlowInterfaces.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Casting.h" #include diff --git a/mlir/lib/Analysis/DataFlowFramework.cpp b/mlir/lib/Analysis/DataFlowFramework.cpp index 5ef24f2..d0e827a 100644 --- a/mlir/lib/Analysis/DataFlowFramework.cpp +++ b/mlir/lib/Analysis/DataFlowFramework.cpp @@ -10,7 +10,6 @@ #include "mlir/IR/Location.h" #include "mlir/IR/Operation.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/iterator.h" #include "llvm/Config/abi-breaking.h" #include "llvm/Support/Casting.h" diff --git a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp index 18047a6..746cff5 100644 --- a/mlir/lib/Analysis/FlatLinearValueConstraints.cpp +++ b/mlir/lib/Analysis/FlatLinearValueConstraints.cpp @@ -16,7 +16,6 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/IntegerSet.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/lib/AsmParser/AffineParser.cpp b/mlir/lib/AsmParser/AffineParser.cpp index 54c2a1ff..1797611 100644 --- a/mlir/lib/AsmParser/AffineParser.cpp +++ b/mlir/lib/AsmParser/AffineParser.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/IntegerSet.h" #include "mlir/IR/OpImplementation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" diff --git a/mlir/lib/AsmParser/AsmParserState.cpp b/mlir/lib/AsmParser/AsmParserState.cpp index 47cfb52..589bf6a 100644 --- a/mlir/lib/AsmParser/AsmParserState.cpp +++ b/mlir/lib/AsmParser/AsmParserState.cpp @@ -13,7 +13,6 @@ #include "mlir/IR/Types.h" #include "mlir/IR/Value.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/lib/AsmParser/DialectSymbolParser.cpp b/mlir/lib/AsmParser/DialectSymbolParser.cpp index 80cce7e..9f4a87a 100644 --- a/mlir/lib/AsmParser/DialectSymbolParser.cpp +++ b/mlir/lib/AsmParser/DialectSymbolParser.cpp @@ -23,7 +23,6 @@ #include "mlir/IR/DialectImplementation.h" #include "mlir/IR/MLIRContext.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include diff --git a/mlir/lib/AsmParser/LocationParser.cpp b/mlir/lib/AsmParser/LocationParser.cpp index fed65c0..1365da0 100644 --- a/mlir/lib/AsmParser/LocationParser.cpp +++ b/mlir/lib/AsmParser/LocationParser.cpp @@ -12,7 +12,6 @@ #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/Location.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" using namespace mlir; using namespace mlir::detail; diff --git a/mlir/lib/AsmParser/Parser.cpp b/mlir/lib/AsmParser/Parser.cpp index 1b8b4ba..7181f13 100644 --- a/mlir/lib/AsmParser/Parser.cpp +++ b/mlir/lib/AsmParser/Parser.cpp @@ -34,7 +34,6 @@ #include "mlir/IR/Verifier.h" #include "mlir/IR/Visitors.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/TypeID.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/DenseMap.h" diff --git a/mlir/lib/AsmParser/TypeParser.cpp b/mlir/lib/AsmParser/TypeParser.cpp index 5da931b..0b46c96 100644 --- a/mlir/lib/AsmParser/TypeParser.cpp +++ b/mlir/lib/AsmParser/TypeParser.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/TensorEncoding.h" #include "mlir/IR/Types.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include #include diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp index dd1e4ab..f767740 100644 --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -17,7 +17,6 @@ #include "mlir/IR/Verifier.h" #include "mlir/IR/Visitors.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp index 9493a6c..449d754 100644 --- a/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp +++ b/mlir/lib/Bytecode/Writer/BytecodeWriter.cpp @@ -14,7 +14,6 @@ #include "mlir/IR/Attributes.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/OpImplementation.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/MapVector.h" diff --git a/mlir/lib/CAPI/IR/BuiltinTypes.cpp b/mlir/lib/CAPI/IR/BuiltinTypes.cpp index c94c070..01bb71d 100644 --- a/mlir/lib/CAPI/IR/BuiltinTypes.cpp +++ b/mlir/lib/CAPI/IR/BuiltinTypes.cpp @@ -16,7 +16,6 @@ #include "mlir/IR/AffineMap.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Types.h" -#include "mlir/Support/LogicalResult.h" #include diff --git a/mlir/lib/Conversion/ArithToAMDGPU/ArithToAMDGPU.cpp b/mlir/lib/Conversion/ArithToAMDGPU/ArithToAMDGPU.cpp index 3d3ff00..58764ad 100644 --- a/mlir/lib/Conversion/ArithToAMDGPU/ArithToAMDGPU.cpp +++ b/mlir/lib/Conversion/ArithToAMDGPU/ArithToAMDGPU.cpp @@ -16,7 +16,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" namespace mlir { diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp index 93717e3..7c6fdab 100644 --- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp +++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp @@ -17,7 +17,6 @@ #include "mlir/Dialect/EmitC/IR/EmitC.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" using namespace mlir; diff --git a/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp b/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp index 810f82f..2aae39f 100644 --- a/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp +++ b/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp @@ -21,7 +21,6 @@ #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" namespace mlir { diff --git a/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.cpp b/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.cpp index 995eecf..f96bfd6 100644 --- a/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.cpp +++ b/mlir/lib/Conversion/ControlFlowToSPIRV/ControlFlowToSPIRV.cpp @@ -19,7 +19,6 @@ #include "mlir/Dialect/SPIRV/Utils/LayoutUtils.h" #include "mlir/IR/AffineMap.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FormatVariadic.h" diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp index efb8046..059acb2 100644 --- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp +++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp @@ -35,7 +35,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/SymbolTable.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "mlir/Transforms/Passes.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRV.cpp b/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRV.cpp index a575551..4740b7c 100644 --- a/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRV.cpp +++ b/mlir/lib/Conversion/FuncToSPIRV/FuncToSPIRV.cpp @@ -18,7 +18,6 @@ #include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h" #include "mlir/Dialect/SPIRV/Utils/LayoutUtils.h" #include "mlir/IR/AffineMap.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE "func-to-spirv-pattern" diff --git a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp index d7885e0..98340bf 100644 --- a/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp +++ b/mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp @@ -21,7 +21,6 @@ #include "mlir/Dialect/SPIRV/Transforms/SPIRVConversion.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Matchers.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include diff --git a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp index 81b9f55..90b0d72 100644 --- a/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp +++ b/mlir/lib/Conversion/MemRefToSPIRV/MemRefToSPIRV.cpp @@ -21,7 +21,6 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Visitors.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/Debug.h" #include #include diff --git a/mlir/lib/Conversion/NVVMToLLVM/NVVMToLLVM.cpp b/mlir/lib/Conversion/NVVMToLLVM/NVVMToLLVM.cpp index d1d68e3..662ee9e 100644 --- a/mlir/lib/Conversion/NVVMToLLVM/NVVMToLLVM.cpp +++ b/mlir/lib/Conversion/NVVMToLLVM/NVVMToLLVM.cpp @@ -25,7 +25,6 @@ #include "mlir/IR/Value.h" #include "mlir/Pass/Pass.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/raw_ostream.h" #define DEBUG_TYPE "nvvm-to-llvm" diff --git a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp index 885bb5a..da09384 100644 --- a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp +++ b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp @@ -20,7 +20,6 @@ #include "mlir/Dialect/SPIRV/Utils/LayoutUtils.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FormatVariadic.h" diff --git a/mlir/lib/Conversion/TensorToLinalg/TensorToLinalg.cpp b/mlir/lib/Conversion/TensorToLinalg/TensorToLinalg.cpp index 0458073..5bb79d4 100644 --- a/mlir/lib/Conversion/TensorToLinalg/TensorToLinalg.cpp +++ b/mlir/lib/Conversion/TensorToLinalg/TensorToLinalg.cpp @@ -14,7 +14,6 @@ #include "mlir/Dialect/Linalg/Transforms/Transforms.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/IR/AffineMap.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE "tensor-to-linalg-pattern" diff --git a/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRV.cpp b/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRV.cpp index 373952c..0fb5862 100644 --- a/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRV.cpp +++ b/mlir/lib/Conversion/TensorToSPIRV/TensorToSPIRV.cpp @@ -18,7 +18,6 @@ #include "mlir/Dialect/SPIRV/Utils/LayoutUtils.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/IR/AffineMap.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE "tensor-to-spirv-pattern" diff --git a/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp b/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp index 0fd91b27..0150ff6 100644 --- a/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp +++ b/mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp @@ -31,7 +31,6 @@ #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/Region.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "mlir/Transforms/Passes.h" #include "llvm/ADT/STLExtras.h" diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp index 8baa31a..c936329 100644 --- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp +++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp @@ -25,7 +25,6 @@ #include "mlir/IR/Matchers.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" diff --git a/mlir/lib/Dialect/Affine/Transforms/AffineScalarReplacement.cpp b/mlir/lib/Dialect/Affine/Transforms/AffineScalarReplacement.cpp index 707bba2..16c0d3d 100644 --- a/mlir/lib/Dialect/Affine/Transforms/AffineScalarReplacement.cpp +++ b/mlir/lib/Dialect/Affine/Transforms/AffineScalarReplacement.cpp @@ -17,7 +17,6 @@ #include "mlir/Dialect/Affine/Utils.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/IR/Dominance.h" -#include "mlir/Support/LogicalResult.h" #include namespace mlir { diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp index 0e7beff..aa5eb95 100644 --- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp +++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp @@ -21,7 +21,6 @@ #include "mlir/IR/OpImplementation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" diff --git a/mlir/lib/Dialect/Arith/Transforms/EmulateNarrowType.cpp b/mlir/lib/Dialect/Arith/Transforms/EmulateNarrowType.cpp index e0e1385..1c1f65e 100644 --- a/mlir/lib/Dialect/Arith/Transforms/EmulateNarrowType.cpp +++ b/mlir/lib/Dialect/Arith/Transforms/EmulateNarrowType.cpp @@ -15,7 +15,6 @@ #include "mlir/Dialect/Func/Transforms/FuncConversions.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/ADT/APInt.h" #include "llvm/Support/FormatVariadic.h" diff --git a/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp b/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp index 8a4080e..9c91dd7 100644 --- a/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp +++ b/mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp @@ -16,7 +16,6 @@ #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/ADT/APInt.h" #include "llvm/Support/FormatVariadic.h" diff --git a/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp b/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp index f87f3d6..e2d42e9 100644 --- a/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp +++ b/mlir/lib/Dialect/Arith/Transforms/IntNarrowing.cpp @@ -21,7 +21,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/ValueBoundsOpInterface.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/lib/Dialect/ArmNeon/Transforms/LowerContractionToSMMLAPattern.cpp b/mlir/lib/Dialect/ArmNeon/Transforms/LowerContractionToSMMLAPattern.cpp index 3635cd3..2c0c84d 100644 --- a/mlir/lib/Dialect/ArmNeon/Transforms/LowerContractionToSMMLAPattern.cpp +++ b/mlir/lib/Dialect/ArmNeon/Transforms/LowerContractionToSMMLAPattern.cpp @@ -20,7 +20,6 @@ #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/IR/AffineMap.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #define DEBUG_TYPE "lower-contract-to-arm-neon" diff --git a/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp b/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp index 982d955..7fb4691 100644 --- a/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp +++ b/mlir/lib/Dialect/Bufferization/Transforms/LowerDeallocations.cpp @@ -19,7 +19,6 @@ #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" namespace mlir { diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp index 3abaa3b..7bc2668 100644 --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -29,7 +29,6 @@ #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/TypeSwitch.h" diff --git a/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp b/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp index b00c65c..561a7e5 100644 --- a/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SubgroupReduceLowering.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/Location.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/MathExtras.h" #include diff --git a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp index 1f5584f..c5c44d9 100644 --- a/mlir/lib/Dialect/IRDL/IR/IRDL.cpp +++ b/mlir/lib/Dialect/IRDL/IR/IRDL.cpp @@ -17,7 +17,6 @@ #include "mlir/IR/OpImplementation.h" #include "mlir/IR/Operation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/IR/Metadata.h" diff --git a/mlir/lib/Dialect/IRDL/IRDLLoading.cpp b/mlir/lib/Dialect/IRDL/IRDLLoading.cpp index 5f623e8..9a2754f 100644 --- a/mlir/lib/Dialect/IRDL/IRDLLoading.cpp +++ b/mlir/lib/Dialect/IRDL/IRDLLoading.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/ExtensibleDialect.h" #include "mlir/IR/OperationSupport.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/SMLoc.h" diff --git a/mlir/lib/Dialect/IRDL/IRDLVerifiers.cpp b/mlir/lib/Dialect/IRDL/IRDLVerifiers.cpp index 05dc154..50f04d0 100644 --- a/mlir/lib/Dialect/IRDL/IRDLVerifiers.cpp +++ b/mlir/lib/Dialect/IRDL/IRDLVerifiers.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/Location.h" #include "mlir/IR/Region.h" #include "mlir/IR/Value.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/FormatVariadic.h" using namespace mlir; diff --git a/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp b/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp index 3dacc70..961944c 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "mlir/Dialect/LLVMIR/BasicPtxBuilderInterface.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "ptx-builder" #define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ") diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp index 94197e4..036a9a1 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -28,7 +28,6 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/OperationSupport.h" #include "mlir/IR/Types.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/AsmParser/Parser.h" diff --git a/mlir/lib/Dialect/Linalg/Transforms/MeshShardingInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/Transforms/MeshShardingInterfaceImpl.cpp index 24001c5..36b6088 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/MeshShardingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/MeshShardingInterfaceImpl.cpp @@ -30,7 +30,6 @@ #include "mlir/IR/SymbolTable.h" #include "mlir/IR/Value.h" #include "mlir/Interfaces/TilingInterface.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/lib/Dialect/Linalg/Transforms/TransposeConv2D.cpp b/mlir/lib/Dialect/Linalg/Transforms/TransposeConv2D.cpp index 9e0829e..1294043 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/TransposeConv2D.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/TransposeConv2D.cpp @@ -13,7 +13,6 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/ValueRange.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp index 847c2f3..f630c48 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp @@ -20,7 +20,6 @@ #include "mlir/IR/Value.h" #include "mlir/Interfaces/InferTypeOpInterface.h" #include "mlir/Interfaces/MemorySlotInterfaces.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/Support/ErrorHandling.h" diff --git a/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp b/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp index f140c04..20ce1b1 100644 --- a/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp +++ b/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/OpDefinition.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/Support/FormatVariadic.h" #include "llvm/Support/MathExtras.h" diff --git a/mlir/lib/Dialect/Mesh/IR/MeshOps.cpp b/mlir/lib/Dialect/Mesh/IR/MeshOps.cpp index ec1acbb..75fceee 100644 --- a/mlir/lib/Dialect/Mesh/IR/MeshOps.cpp +++ b/mlir/lib/Dialect/Mesh/IR/MeshOps.cpp @@ -23,7 +23,6 @@ #include "mlir/IR/Value.h" #include "mlir/Interfaces/ViewLikeInterface.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" diff --git a/mlir/lib/Dialect/Mesh/Interfaces/ShardingInterface.cpp b/mlir/lib/Dialect/Mesh/Interfaces/ShardingInterface.cpp index a233847..bcd0e15 100644 --- a/mlir/lib/Dialect/Mesh/Interfaces/ShardingInterface.cpp +++ b/mlir/lib/Dialect/Mesh/Interfaces/ShardingInterface.cpp @@ -13,7 +13,6 @@ #include "mlir/IR/AffineMap.h" #include "mlir/IR/IRMapping.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" diff --git a/mlir/lib/Dialect/Mesh/Transforms/ShardingPropagation.cpp b/mlir/lib/Dialect/Mesh/Transforms/ShardingPropagation.cpp index 870ac4a..511c910 100644 --- a/mlir/lib/Dialect/Mesh/Transforms/ShardingPropagation.cpp +++ b/mlir/lib/Dialect/Mesh/Transforms/ShardingPropagation.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/Verifier.h" #include "mlir/Interfaces/FunctionInterfaces.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/iterator_range.h" diff --git a/mlir/lib/Dialect/Mesh/Transforms/Simplifications.cpp b/mlir/lib/Dialect/Mesh/Transforms/Simplifications.cpp index a29551a..4c14b1c 100644 --- a/mlir/lib/Dialect/Mesh/Transforms/Simplifications.cpp +++ b/mlir/lib/Dialect/Mesh/Transforms/Simplifications.cpp @@ -14,7 +14,6 @@ #include "mlir/IR/ImplicitLocOpBuilder.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/SymbolTable.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include diff --git a/mlir/lib/Dialect/Mesh/Transforms/Spmdization.cpp b/mlir/lib/Dialect/Mesh/Transforms/Spmdization.cpp index 4ecc897..1df3cf6 100644 --- a/mlir/lib/Dialect/Mesh/Transforms/Spmdization.cpp +++ b/mlir/lib/Dialect/Mesh/Transforms/Spmdization.cpp @@ -28,7 +28,6 @@ #include "mlir/Interfaces/FunctionInterfaces.h" #include "mlir/Pass/Pass.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" diff --git a/mlir/lib/Dialect/NVGPU/Transforms/MmaSyncTF32Transform.cpp b/mlir/lib/Dialect/NVGPU/Transforms/MmaSyncTF32Transform.cpp index 8163f42..6222cc7 100644 --- a/mlir/lib/Dialect/NVGPU/Transforms/MmaSyncTF32Transform.cpp +++ b/mlir/lib/Dialect/NVGPU/Transforms/MmaSyncTF32Transform.cpp @@ -19,7 +19,6 @@ #include "mlir/Dialect/NVGPU/IR/NVGPUDialect.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/MathExtras.h" diff --git a/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp b/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp index 693bb53..31ffacb 100644 --- a/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp +++ b/mlir/lib/Dialect/NVGPU/Transforms/OptimizeSharedMemory.cpp @@ -20,7 +20,6 @@ #include "mlir/Dialect/NVGPU/Transforms/Utils.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/MathExtras.h" @@ -146,7 +145,7 @@ getShmReadAndWriteOps(Operation *parentOp, Value shmMemRef, return success(); } -mlir::LogicalResult +llvm::LogicalResult mlir::nvgpu::optimizeSharedMemoryReadsAndWrites(Operation *parentOp, Value memrefValue) { auto memRefType = dyn_cast(memrefValue.getType()); diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp index b13c8d1..abbd857 100644 --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -38,7 +38,6 @@ #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc" #include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.cpp.inc" #include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.cpp.inc" -#include "mlir/Support/LogicalResult.h" using namespace mlir; using namespace mlir::omp; diff --git a/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp b/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp index e85bced..650a369 100644 --- a/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp +++ b/mlir/lib/Dialect/Polynomial/IR/Polynomial.cpp @@ -8,7 +8,6 @@ #include "mlir/Dialect/Polynomial/IR/Polynomial.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/SmallVector.h" namespace mlir { diff --git a/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp b/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp index cc7d317..93c7f9e 100644 --- a/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp +++ b/mlir/lib/Dialect/Polynomial/IR/PolynomialAttributes.cpp @@ -9,7 +9,6 @@ #include "mlir/Dialect/Polynomial/IR/Polynomial.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" diff --git a/mlir/lib/Dialect/Polynomial/IR/PolynomialDialect.cpp b/mlir/lib/Dialect/Polynomial/IR/PolynomialDialect.cpp index 825b80d..7f8ba06 100644 --- a/mlir/lib/Dialect/Polynomial/IR/PolynomialDialect.cpp +++ b/mlir/lib/Dialect/Polynomial/IR/PolynomialDialect.cpp @@ -18,7 +18,6 @@ #include "mlir/IR/Dialect.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/InferTypeOpInterface.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/TypeSwitch.h" diff --git a/mlir/lib/Dialect/Polynomial/IR/PolynomialOps.cpp b/mlir/lib/Dialect/Polynomial/IR/PolynomialOps.cpp index 40fa97d..2ba13bb 100644 --- a/mlir/lib/Dialect/Polynomial/IR/PolynomialOps.cpp +++ b/mlir/lib/Dialect/Polynomial/IR/PolynomialOps.cpp @@ -15,7 +15,6 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APInt.h" using namespace mlir; diff --git a/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp b/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp index ee6be25..c0c00fb 100644 --- a/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp +++ b/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp @@ -12,7 +12,6 @@ #include "mlir/Dialect/Quant/QuantOps.h" #include "mlir/Dialect/Quant/QuantTypes.h" #include "mlir/IR/Diagnostics.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/TypeSwitch.h" diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp index 3841562..d9bc05a 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp @@ -29,7 +29,6 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/FunctionImplementation.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVWebGPUTransforms.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVWebGPUTransforms.cpp index 5d4dd5b..d75c855 100644 --- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVWebGPUTransforms.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVWebGPUTransforms.cpp @@ -17,7 +17,6 @@ #include "mlir/IR/Location.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp index 288cbac..4337787 100644 --- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp +++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp @@ -955,7 +955,7 @@ LogicalResult tosa::ReshapeOp::inferReturnTypeComponents( return success(); } -mlir::LogicalResult tosa::ReshapeOp::verify() { +llvm::LogicalResult tosa::ReshapeOp::verify() { TensorType inputType = getInput1().getType(); RankedTensorType outputType = getType(); diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp index 6eef2c5..403ac48 100644 --- a/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp +++ b/mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp @@ -20,7 +20,6 @@ #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Matchers.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/FloatingPointMode.h" #include "llvm/ADT/SmallVector.h" diff --git a/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp b/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp index ff02cb2..e2b314f9 100644 --- a/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp +++ b/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp @@ -12,7 +12,6 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/Interfaces/CastInterfaces.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBitCast.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBitCast.cpp index e5f11d8..d8c4939 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBitCast.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBitCast.cpp @@ -16,7 +16,6 @@ #include "mlir/Dialect/Vector/Utils/VectorUtils.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "vector-bitcast-lowering" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp index 44e3f76..32e7eb2 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp @@ -32,7 +32,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/VectorInterfaces.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "vector-broadcast-lowering" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorContract.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorContract.cpp index ba1c968..3a799ce 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorContract.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorContract.cpp @@ -31,7 +31,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/VectorInterfaces.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "vector-contract-lowering" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorGather.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorGather.cpp index a0df03c..f1a5aa7 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorGather.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorGather.cpp @@ -31,7 +31,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/VectorInterfaces.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "vector-broadcast-lowering" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp index f7e01c7..cab0f21 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorInterleave.cpp @@ -16,7 +16,6 @@ #include "mlir/Dialect/Vector/Utils/VectorUtils.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/PatternMatch.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "vector-interleave-lowering" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp index c4e8ddc..92fddc1 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp @@ -31,7 +31,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/VectorInterfaces.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "vector-broadcast-lowering" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorShapeCast.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorShapeCast.cpp index 85c4c03..95ebd4e 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorShapeCast.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorShapeCast.cpp @@ -32,7 +32,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/VectorInterfaces.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "vector-shape-cast-lowering" diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp index ca8a6f6..3c92b22 100644 --- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorTranspose.cpp @@ -31,7 +31,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/VectorInterfaces.h" -#include "mlir/Support/LogicalResult.h" #define DEBUG_TYPE "lower-vector-transpose" diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp index a1bb81e..4a3ae1b 100644 --- a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp @@ -18,7 +18,6 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/DialectConversion.h" #include "llvm/ADT/ArrayRef.h" #include diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp index da3d964..c7d3022 100644 --- a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp @@ -38,7 +38,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/IR/TypeUtilities.h" #include "mlir/Interfaces/VectorInterfaces.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/MapVector.h" diff --git a/mlir/lib/IR/AffineMap.cpp b/mlir/lib/IR/AffineMap.cpp index e5993eb..62f5952 100644 --- a/mlir/lib/IR/AffineMap.cpp +++ b/mlir/lib/IR/AffineMap.cpp @@ -12,7 +12,6 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallSet.h" diff --git a/mlir/lib/IR/ExtensibleDialect.cpp b/mlir/lib/IR/ExtensibleDialect.cpp index ca7b0e1..8a7d747 100644 --- a/mlir/lib/IR/ExtensibleDialect.cpp +++ b/mlir/lib/IR/ExtensibleDialect.cpp @@ -11,7 +11,6 @@ #include "mlir/IR/DialectImplementation.h" #include "mlir/IR/OperationSupport.h" #include "mlir/IR/StorageUniquerSupport.h" -#include "mlir/Support/LogicalResult.h" using namespace mlir; diff --git a/mlir/lib/Query/Query.cpp b/mlir/lib/Query/Query.cpp index 7495e70..7d9f360 100644 --- a/mlir/lib/Query/Query.cpp +++ b/mlir/lib/Query/Query.cpp @@ -12,7 +12,6 @@ #include "mlir/IR/IRMapping.h" #include "mlir/Query/Matcher/MatchFinder.h" #include "mlir/Query/QuerySession.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" @@ -102,19 +101,16 @@ static Operation *extractFunction(std::vector &ops, Query::~Query() = default; -mlir::LogicalResult InvalidQuery::run(llvm::raw_ostream &os, - QuerySession &qs) const { +LogicalResult InvalidQuery::run(llvm::raw_ostream &os, QuerySession &qs) const { os << errStr << "\n"; return mlir::failure(); } -mlir::LogicalResult NoOpQuery::run(llvm::raw_ostream &os, - QuerySession &qs) const { +LogicalResult NoOpQuery::run(llvm::raw_ostream &os, QuerySession &qs) const { return mlir::success(); } -mlir::LogicalResult HelpQuery::run(llvm::raw_ostream &os, - QuerySession &qs) const { +LogicalResult HelpQuery::run(llvm::raw_ostream &os, QuerySession &qs) const { os << "Available commands:\n\n" " match MATCHER, m MATCHER " "Match the mlir against the given matcher.\n" @@ -123,14 +119,12 @@ mlir::LogicalResult HelpQuery::run(llvm::raw_ostream &os, return mlir::success(); } -mlir::LogicalResult QuitQuery::run(llvm::raw_ostream &os, - QuerySession &qs) const { +LogicalResult QuitQuery::run(llvm::raw_ostream &os, QuerySession &qs) const { qs.terminate = true; return mlir::success(); } -mlir::LogicalResult MatchQuery::run(llvm::raw_ostream &os, - QuerySession &qs) const { +LogicalResult MatchQuery::run(llvm::raw_ostream &os, QuerySession &qs) const { Operation *rootOp = qs.getRootOp(); int matchCount = 0; std::vector matches = diff --git a/mlir/lib/Support/ToolUtilities.cpp b/mlir/lib/Support/ToolUtilities.cpp index f05b4f5..748f928 100644 --- a/mlir/lib/Support/ToolUtilities.cpp +++ b/mlir/lib/Support/ToolUtilities.cpp @@ -12,7 +12,6 @@ #include "mlir/Support/ToolUtilities.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/raw_ostream.h" diff --git a/mlir/lib/TableGen/CodeGenHelpers.cpp b/mlir/lib/TableGen/CodeGenHelpers.cpp index 5986514..718a813 100644 --- a/mlir/lib/TableGen/CodeGenHelpers.cpp +++ b/mlir/lib/TableGen/CodeGenHelpers.cpp @@ -111,7 +111,7 @@ StringRef StaticVerifierFunctionEmitter::getRegionConstraintFn( /// Code for a type constraint. These may be called on the type of either /// operands or results. static const char *const typeConstraintCode = R"( -static ::mlir::LogicalResult {0}( +static ::llvm::LogicalResult {0}( ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, unsigned valueIndex) { if (!({1})) { @@ -129,14 +129,14 @@ static ::mlir::LogicalResult {0}( /// TODO: Unique constraints for adaptors. However, most Adaptor::verify /// functions are stripped anyways. static const char *const attrConstraintCode = R"( -static ::mlir::LogicalResult {0}( +static ::llvm::LogicalResult {0}( ::mlir::Attribute attr, ::llvm::StringRef attrName, llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) {{ if (attr && !({1})) return emitError() << "attribute '" << attrName << "' failed to satisfy constraint: {2}"; return ::mlir::success(); } -static ::mlir::LogicalResult {0}( +static ::llvm::LogicalResult {0}( ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) {{ return {0}(attr, attrName, [op]() {{ return op->emitOpError(); @@ -146,7 +146,7 @@ static ::mlir::LogicalResult {0}( /// Code for a successor constraint. static const char *const successorConstraintCode = R"( -static ::mlir::LogicalResult {0}( +static ::llvm::LogicalResult {0}( ::mlir::Operation *op, ::mlir::Block *successor, ::llvm::StringRef successorName, unsigned successorIndex) { if (!({1})) { @@ -160,7 +160,7 @@ static ::mlir::LogicalResult {0}( /// Code for a region constraint. Callers will need to pass in the region's name /// for emitting an error message. static const char *const regionConstraintCode = R"( -static ::mlir::LogicalResult {0}( +static ::llvm::LogicalResult {0}( ::mlir::Operation *op, ::mlir::Region ®ion, ::llvm::StringRef regionName, unsigned regionIndex) { if (!({1})) { @@ -176,7 +176,7 @@ static ::mlir::LogicalResult {0}( /// /// {3}: "Type type" or "Attribute attr". static const char *const patternAttrOrTypeConstraintCode = R"( -static ::mlir::LogicalResult {0}( +static ::llvm::LogicalResult {0}( ::mlir::PatternRewriter &rewriter, ::mlir::Operation *op, ::mlir::{3}, ::llvm::StringRef failureStr) { if (!({1})) { diff --git a/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp b/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp index 0eb3328..b023c4c 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/GPU/SelectObjectAttr.cpp @@ -167,7 +167,7 @@ public: Value *createKernelArgArray(mlir::gpu::LaunchFuncOp op); // Create the full kernel launch. - mlir::LogicalResult createKernelLaunch(mlir::gpu::LaunchFuncOp op, + llvm::LogicalResult createKernelLaunch(mlir::gpu::LaunchFuncOp op, mlir::gpu::ObjectAttr object); private: @@ -345,7 +345,7 @@ llvm::LaunchKernel::createKernelArgArray(mlir::gpu::LaunchFuncOp op) { // call %streamSynchronize(%4) // call %streamDestroy(%4) // call %moduleUnload(%1) -mlir::LogicalResult +llvm::LogicalResult llvm::LaunchKernel::createKernelLaunch(mlir::gpu::LaunchFuncOp op, mlir::gpu::ObjectAttr object) { auto llvmValue = [&](mlir::Value value) -> Value * { diff --git a/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp index ea9fe26..a09c24d 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp @@ -15,7 +15,6 @@ #include "mlir/Dialect/LLVMIR/NVVMDialect.h" #include "mlir/Dialect/Utils/StaticValueUtils.h" #include "mlir/IR/Operation.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Target/LLVMIR/ModuleTranslation.h" #include "llvm/IR/IRBuilder.h" diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index fe257a4..35971fb 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -18,7 +18,6 @@ #include "mlir/IR/IRMapping.h" #include "mlir/IR/Operation.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Target/LLVMIR/Dialect/OpenMPCommon.h" #include "mlir/Target/LLVMIR/ModuleTranslation.h" #include "mlir/Transforms/RegionUtils.h" diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 6e8b2de..e0b1816e 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -31,7 +31,6 @@ #include "mlir/IR/DialectResourceBlobManager.h" #include "mlir/IR/RegionGraphTraits.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Target/LLVMIR/LLVMTranslationInterface.h" #include "mlir/Target/LLVMIR/TypeToLLVM.h" diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp index faaa420..d7a3085 100644 --- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp +++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/Builders.h" #include "mlir/IR/IRMapping.h" #include "mlir/IR/Location.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Target/SPIRV/SPIRVBinaryUtils.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Sequence.h" diff --git a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp index c283e64..6c28c04 100644 --- a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp +++ b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp @@ -15,7 +15,6 @@ #include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h" #include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h" #include "mlir/IR/RegionGraphTraits.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Target/SPIRV/SPIRVBinaryUtils.h" #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp index 200abdf..4c4fef1 100644 --- a/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp +++ b/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp @@ -16,7 +16,6 @@ #include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h" #include "mlir/Dialect/SPIRV/IR/SPIRVEnums.h" #include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Target/SPIRV/SPIRVBinaryUtils.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Sequence.h" diff --git a/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp b/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp index b02edc6..611b734 100644 --- a/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp +++ b/mlir/lib/Tools/PDLL/CodeGen/CPPGen.cpp @@ -216,7 +216,7 @@ void CodeGen::generateConstraintOrRewrite(const ast::CallableDecl *decl, // TODO: This will need to change if we allow Constraints to return values as // well. if (isConstraint) { - os << "::mlir::LogicalResult"; + os << "::llvm::LogicalResult"; } else { // Otherwise, generate a type based on the results of the callable. // If the callable has explicit results, use those to build the result. diff --git a/mlir/lib/Tools/PDLL/Parser/Lexer.cpp b/mlir/lib/Tools/PDLL/Parser/Lexer.cpp index 4673a73b..cc111a0 100644 --- a/mlir/lib/Tools/PDLL/Parser/Lexer.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Lexer.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "Lexer.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Tools/PDLL/AST/Diagnostic.h" #include "mlir/Tools/PDLL/Parser/CodeComplete.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/lib/Tools/PDLL/Parser/Lexer.h b/mlir/lib/Tools/PDLL/Parser/Lexer.h index c80cb36..cd9c2b7 100644 --- a/mlir/lib/Tools/PDLL/Parser/Lexer.h +++ b/mlir/lib/Tools/PDLL/Parser/Lexer.h @@ -18,8 +18,6 @@ class SourceMgr; } // namespace llvm namespace mlir { -struct LogicalResult; - namespace pdll { class CodeCompleteContext; diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index 45f9e2f..1f0df03 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -9,7 +9,6 @@ #include "mlir/Tools/PDLL/Parser/Parser.h" #include "Lexer.h" #include "mlir/Support/IndentedOstream.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/TableGen/Argument.h" #include "mlir/TableGen/Attribute.h" #include "mlir/TableGen/Constraint.h" diff --git a/mlir/lib/Tools/lsp-server-support/Protocol.cpp b/mlir/lib/Tools/lsp-server-support/Protocol.cpp index 188f525..e4eb251 100644 --- a/mlir/lib/Tools/lsp-server-support/Protocol.cpp +++ b/mlir/lib/Tools/lsp-server-support/Protocol.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "mlir/Tools/lsp-server-support/Protocol.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Tools/lsp-server-support/Logging.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallString.h" diff --git a/mlir/lib/Tools/mlir-lsp-server/LSPServer.h b/mlir/lib/Tools/mlir-lsp-server/LSPServer.h index faf5936..2c50c6b 100644 --- a/mlir/lib/Tools/mlir-lsp-server/LSPServer.h +++ b/mlir/lib/Tools/mlir-lsp-server/LSPServer.h @@ -11,16 +11,19 @@ #include -namespace mlir { +namespace llvm { struct LogicalResult; +} // namespace llvm +namespace mlir { namespace lsp { class JSONTransport; class MLIRServer; /// Run the main loop of the LSP server using the given MLIR server and /// transport. -LogicalResult runMlirLSPServer(MLIRServer &server, JSONTransport &transport); +llvm::LogicalResult runMlirLSPServer(MLIRServer &server, + JSONTransport &transport); } // namespace lsp } // namespace mlir diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp index a1b2893..831e1e6 100644 --- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp +++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp @@ -31,7 +31,6 @@ #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" #include "mlir/Support/FileUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/Timing.h" #include "mlir/Support/ToolUtilities.h" #include "mlir/Tools/ParseUtilities.h" diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h index 5551c4e..78c4c31 100644 --- a/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.h @@ -11,16 +11,19 @@ #include -namespace mlir { +namespace llvm { struct LogicalResult; +} // namespace llvm +namespace mlir { namespace lsp { class JSONTransport; class PDLLServer; /// Run the main loop of the LSP server using the given PDLL server and /// transport. -LogicalResult runPdllLSPServer(PDLLServer &server, JSONTransport &transport); +llvm::LogicalResult runPdllLSPServer(PDLLServer &server, + JSONTransport &transport); } // namespace lsp } // namespace mlir diff --git a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h index 682c7b5..134431f 100644 --- a/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h +++ b/mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.h @@ -12,8 +12,9 @@ #include "mlir/Support/LLVM.h" #include "llvm/ADT/StringRef.h" #include -#include #include +#include +#include namespace mlir { namespace lsp { diff --git a/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp b/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp index 15de16a..9950050 100644 --- a/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp +++ b/mlir/lib/Tools/mlir-query/MlirQueryMain.cpp @@ -18,7 +18,6 @@ #include "mlir/Query/Query.h" #include "mlir/Query/QuerySession.h" #include "mlir/Support/FileUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/LineEditor/LineEditor.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" @@ -28,7 +27,7 @@ // Query Parser //===----------------------------------------------------------------------===// -mlir::LogicalResult +llvm::LogicalResult mlir::mlirQueryMain(int argc, char **argv, MLIRContext &context, const mlir::query::matcher::Registry &matcherRegistry) { diff --git a/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp b/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp index 2f0ab8a..a9cde4a 100644 --- a/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp +++ b/mlir/lib/Tools/mlir-reduce/MlirReduceMain.cpp @@ -21,7 +21,6 @@ #include "mlir/Reducer/Passes.h" #include "mlir/Rewrite/FrozenRewritePatternSet.h" #include "mlir/Support/FileUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Tools/ParseUtilities.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/SourceMgr.h" diff --git a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp index bd992895..56773f5 100644 --- a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp +++ b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp @@ -13,7 +13,6 @@ #include "mlir/IR/Verifier.h" #include "mlir/Parser/Parser.h" #include "mlir/Support/FileUtilities.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Support/Timing.h" #include "mlir/Support/ToolUtilities.h" #include "mlir/Tools/mlir-translate/Translation.h" diff --git a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h index bc85de1..501a9da 100644 --- a/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h +++ b/mlir/lib/Tools/tblgen-lsp-server/LSPServer.h @@ -11,17 +11,19 @@ #include -namespace mlir { +namespace llvm { struct LogicalResult; +} // namespace llvm +namespace mlir { namespace lsp { class JSONTransport; class TableGenServer; /// Run the main loop of the LSP server using the given TableGen server and /// transport. -LogicalResult runTableGenLSPServer(TableGenServer &server, - JSONTransport &transport); +llvm::LogicalResult runTableGenLSPServer(TableGenServer &server, + JSONTransport &transport); } // namespace lsp } // namespace mlir diff --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp index 5ea91a2..f7cf4de 100644 --- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp +++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.cpp @@ -9,7 +9,6 @@ #include "TableGenServer.h" #include "mlir/Support/IndentedOstream.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Tools/lsp-server-support/CompilationDatabase.h" #include "mlir/Tools/lsp-server-support/Logging.h" #include "mlir/Tools/lsp-server-support/Protocol.h" @@ -17,9 +16,6 @@ #include "llvm/ADT/IntervalMap.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringSet.h" -#include "llvm/ADT/TypeSwitch.h" -#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/TableGen/Parser.h" #include "llvm/TableGen/Record.h" diff --git a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h index d749a4f..bdc8510 100644 --- a/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h +++ b/mlir/lib/Tools/tblgen-lsp-server/TableGenServer.h @@ -12,8 +12,9 @@ #include "mlir/Support/LLVM.h" #include "llvm/ADT/StringRef.h" #include -#include #include +#include +#include namespace mlir { namespace lsp { diff --git a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp index 6a67ddd..43005e2 100644 --- a/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp +++ b/mlir/test/lib/Analysis/DataFlow/TestLivenessAnalysis.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include using namespace mlir; diff --git a/mlir/test/lib/Dialect/ArmNeon/TestLowerToArmNeon.cpp b/mlir/test/lib/Dialect/ArmNeon/TestLowerToArmNeon.cpp index 2e5a4a9..f6bfd9f 100644 --- a/mlir/test/lib/Dialect/ArmNeon/TestLowerToArmNeon.cpp +++ b/mlir/test/lib/Dialect/ArmNeon/TestLowerToArmNeon.cpp @@ -17,7 +17,6 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" #define PASS_NAME "test-lower-to-arm-neon" diff --git a/mlir/test/lib/Dialect/Mesh/TestOpLowering.cpp b/mlir/test/lib/Dialect/Mesh/TestOpLowering.cpp index 321b6a4..1f836be 100644 --- a/mlir/test/lib/Dialect/Mesh/TestOpLowering.cpp +++ b/mlir/test/lib/Dialect/Mesh/TestOpLowering.cpp @@ -11,7 +11,6 @@ #include "mlir/Dialect/Utils/IndexingUtils.h" #include "mlir/IR/SymbolTable.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" using namespace mlir; diff --git a/mlir/test/lib/Dialect/Mesh/TestReshardingSpmdization.cpp b/mlir/test/lib/Dialect/Mesh/TestReshardingSpmdization.cpp index 5e3918f..f964102 100644 --- a/mlir/test/lib/Dialect/Mesh/TestReshardingSpmdization.cpp +++ b/mlir/test/lib/Dialect/Mesh/TestReshardingSpmdization.cpp @@ -19,7 +19,6 @@ #include "mlir/IR/SymbolTable.h" #include "mlir/IR/Value.h" #include "mlir/Pass/Pass.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/GreedyPatternRewriteDriver.h" using namespace mlir; diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp index d7e40d3..b66dfbf 100644 --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -17,7 +17,6 @@ #include "mlir/IR/DialectImplementation.h" #include "mlir/IR/ExtensibleDialect.h" #include "mlir/IR/Types.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/Hashing.h" #include "llvm/ADT/StringExtras.h" diff --git a/mlir/test/lib/Dialect/Test/TestDialect.cpp b/mlir/test/lib/Dialect/Test/TestDialect.cpp index bfb9592..1bbf2cc 100644 --- a/mlir/test/lib/Dialect/Test/TestDialect.cpp +++ b/mlir/test/lib/Dialect/Test/TestDialect.cpp @@ -28,7 +28,6 @@ #include "mlir/Interfaces/FunctionImplementation.h" #include "mlir/Interfaces/InferIntRangeInterface.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/Transforms/FoldUtils.h" #include "mlir/Transforms/InliningUtils.h" #include "llvm/ADT/STLFunctionalExtras.h" diff --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp index b86f692..fbaa102 100644 --- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp +++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp @@ -1193,7 +1193,7 @@ void TestVersionedOpA::writeProperties(mlir::DialectBytecodeWriter &writer) { // TestOpWithVersionedProperties //===----------------------------------------------------------------------===// -mlir::LogicalResult TestOpWithVersionedProperties::readFromMlirBytecode( +llvm::LogicalResult TestOpWithVersionedProperties::readFromMlirBytecode( mlir::DialectBytecodeReader &reader, test::VersionedProperties &prop) { uint64_t value1, value2 = 0; if (failed(reader.readVarInt(value1))) diff --git a/mlir/test/lib/Dialect/Test/TestOps.h b/mlir/test/lib/Dialect/Test/TestOps.h index 837ccca..f070c3b 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.h +++ b/mlir/test/lib/Dialect/Test/TestOps.h @@ -70,7 +70,7 @@ struct PropertiesWithCustomPrint { } }; -mlir::LogicalResult setPropertiesFromAttribute( +llvm::LogicalResult setPropertiesFromAttribute( PropertiesWithCustomPrint &prop, mlir::Attribute attr, llvm::function_ref emitError); mlir::DictionaryAttr @@ -92,7 +92,7 @@ public: // These three methods are invoked through the `MyStructProperty` wrapper // defined in TestOps.td mlir::Attribute asAttribute(mlir::MLIRContext *ctx) const; - static mlir::LogicalResult + static llvm::LogicalResult setFromAttr(MyPropStruct &prop, mlir::Attribute attr, llvm::function_ref emitError); llvm::hash_code hash() const; @@ -101,7 +101,7 @@ public: } }; -mlir::LogicalResult readFromMlirBytecode(mlir::DialectBytecodeReader &reader, +llvm::LogicalResult readFromMlirBytecode(mlir::DialectBytecodeReader &reader, MyPropStruct &prop); void writeToMlirBytecode(mlir::DialectBytecodeWriter &writer, MyPropStruct &prop); @@ -122,7 +122,7 @@ struct VersionedProperties { } }; -mlir::LogicalResult setPropertiesFromAttribute( +llvm::LogicalResult setPropertiesFromAttribute( VersionedProperties &prop, mlir::Attribute attr, llvm::function_ref emitError); mlir::DictionaryAttr getPropertiesAsAttribute(mlir::MLIRContext *ctx, @@ -137,7 +137,7 @@ mlir::ParseResult customParseProperties(mlir::OpAsmParser &parser, // Bytecode Support //===----------------------------------------------------------------------===// -mlir::LogicalResult readFromMlirBytecode(mlir::DialectBytecodeReader &reader, +llvm::LogicalResult readFromMlirBytecode(mlir::DialectBytecodeReader &reader, llvm::MutableArrayRef prop); void writeToMlirBytecode(mlir::DialectBytecodeWriter &writer, llvm::ArrayRef prop); diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index c77f76d..e1ec142 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -462,7 +462,7 @@ def VariadicRegionInferredTypesOp : TEST_Op<"variadic_region_inferred", let results = (outs Variadic); let extraClassDeclaration = [{ - static mlir::LogicalResult inferReturnTypes(mlir::MLIRContext *context, + static llvm::LogicalResult inferReturnTypes(mlir::MLIRContext *context, std::optional<::mlir::Location> location, mlir::ValueRange operands, mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, mlir::RegionRange regions, llvm::SmallVectorImpl &inferredReturnTypes) { @@ -1368,7 +1368,7 @@ def TestOpInPlaceFoldSuccess : TEST_Op<"op_in_place_fold_success"> { let results = (outs Variadic); let hasFolder = 1; let extraClassDefinition = [{ - ::mlir::LogicalResult $cppClass::fold(FoldAdaptor adaptor, + ::llvm::LogicalResult $cppClass::fold(FoldAdaptor adaptor, SmallVectorImpl &results) { return success(); } @@ -2408,7 +2408,7 @@ class TableGenBuildInferReturnTypeBaseOp location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { @@ -3037,7 +3037,7 @@ def TestOpWithNiceProperties : TEST_Op<"with_nice_properties"> { ::mlir::ArrayRef<::llvm::StringRef> elidedProps); static ::mlir::ParseResult parseProperties(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - static ::mlir::LogicalResult readFromMlirBytecode( + static ::llvm::LogicalResult readFromMlirBytecode( ::mlir::DialectBytecodeReader &, test::PropertiesWithCustomPrint &prop); static void writeToMlirBytecode( @@ -3045,7 +3045,7 @@ def TestOpWithNiceProperties : TEST_Op<"with_nice_properties"> { const test::PropertiesWithCustomPrint &prop); }]; let extraClassDefinition = [{ - ::mlir::LogicalResult TestOpWithNiceProperties::readFromMlirBytecode( + ::llvm::LogicalResult TestOpWithNiceProperties::readFromMlirBytecode( ::mlir::DialectBytecodeReader &reader, test::PropertiesWithCustomPrint &prop) { StringRef label; @@ -3101,7 +3101,7 @@ def TestOpWithVersionedProperties : TEST_Op<"with_versioned_properties"> { ::mlir::ArrayRef<::llvm::StringRef> elidedProps); static ::mlir::ParseResult parseProperties(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); - static ::mlir::LogicalResult readFromMlirBytecode( + static ::llvm::LogicalResult readFromMlirBytecode( ::mlir::DialectBytecodeReader &, test::VersionedProperties &prop); static void writeToMlirBytecode( diff --git a/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp b/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp index ebaced5..664951f 100644 --- a/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp +++ b/mlir/test/lib/Dialect/Test/TestOpsSyntax.cpp @@ -280,7 +280,7 @@ void ParseB64BytesOp::print(OpAsmPrinter &p) { p << " \"" << llvm::encodeBase64(getB64()) << "\""; } -::mlir::LogicalResult FormatInferType2Op::inferReturnTypes( +::llvm::LogicalResult FormatInferType2Op::inferReturnTypes( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, OpaqueProperties properties, ::mlir::RegionRange regions, diff --git a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td index 9522a77..3129085 100644 --- a/mlir/test/lib/Dialect/Test/TestOpsSyntax.td +++ b/mlir/test/lib/Dialect/Test/TestOpsSyntax.td @@ -632,7 +632,7 @@ def FormatInferTypeOp : TEST_Op<"format_infer_type", [InferTypeOpInterface]> { let assemblyFormat = "attr-dict"; let extraClassDeclaration = [{ - static ::mlir::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, + static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { @@ -655,7 +655,7 @@ class FormatInferAllTypesBaseOp traits = []> let arguments = (ins Variadic:$args); let results = (outs Variadic:$outs); let extraClassDeclaration = [{ - static ::mlir::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, + static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { @@ -702,7 +702,7 @@ def FormatInferTypeRegionsOp let regions = (region AnyRegion:$region); let assemblyFormat = "$region attr-dict"; let extraClassDeclaration = [{ - static ::mlir::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, + static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { @@ -723,7 +723,7 @@ def FormatInferTypeVariadicOperandsOp let results = (outs Variadic:$outs); let assemblyFormat = "`(` $a `:` type($a) `)` `(` $b `:` type($b) `)` attr-dict"; let extraClassDeclaration = [{ - static ::mlir::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, + static ::llvm::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, mlir::OpaqueProperties properties, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type> &inferredReturnTypes) { diff --git a/mlir/test/lib/Dialect/Test/TestTypeDefs.td b/mlir/test/lib/Dialect/Test/TestTypeDefs.td index 492642b..d96152a 100644 --- a/mlir/test/lib/Dialect/Test/TestTypeDefs.td +++ b/mlir/test/lib/Dialect/Test/TestTypeDefs.td @@ -154,7 +154,7 @@ def TestTypeWithLayoutType : Test_Type<"TestTypeWithLayout", [ let mnemonic = "test_type_with_layout"; let parameters = (ins "unsigned":$key); let extraClassDeclaration = [{ - ::mlir::LogicalResult verifyEntries(::mlir::DataLayoutEntryListRef params, + ::llvm::LogicalResult verifyEntries(::mlir::DataLayoutEntryListRef params, ::mlir::Location loc) const; private: diff --git a/mlir/test/lib/Dialect/Test/TestTypes.h b/mlir/test/lib/Dialect/Test/TestTypes.h index da56049..cef3f05 100644 --- a/mlir/test/lib/Dialect/Test/TestTypes.h +++ b/mlir/test/lib/Dialect/Test/TestTypes.h @@ -108,7 +108,7 @@ struct TestRecursiveTypeStorage : public ::mlir::TypeStorage { TestRecursiveTypeStorage(allocator.copyInto(key)); } - ::mlir::LogicalResult mutate(::mlir::TypeStorageAllocator &allocator, + ::llvm::LogicalResult mutate(::mlir::TypeStorageAllocator &allocator, ::mlir::Type newBody) { // Cannot set a different body than before. if (body && body != newBody) @@ -140,7 +140,7 @@ public: } /// Body getter and setter. - ::mlir::LogicalResult setBody(Type body) { return Base::mutate(body); } + ::llvm::LogicalResult setBody(Type body) { return Base::mutate(body); } ::mlir::Type getBody() const { return getImpl()->body; } /// Name/key getter. diff --git a/mlir/test/mlir-pdll/CodeGen/CPP/general.pdll b/mlir/test/mlir-pdll/CodeGen/CPP/general.pdll index 21a8966..4e869e5 100644 --- a/mlir/test/mlir-pdll/CodeGen/CPP/general.pdll +++ b/mlir/test/mlir-pdll/CodeGen/CPP/general.pdll @@ -46,7 +46,7 @@ Pattern => erase op; #include "include/ods.td" -// CHECK: static ::mlir::LogicalResult TestCstPDLFn(::mlir::PatternRewriter &rewriter, +// CHECK: static ::llvm::LogicalResult TestCstPDLFn(::mlir::PatternRewriter &rewriter, // CHECK-SAME: ::mlir::Attribute attr, ::mlir::Operation * op, ::mlir::Type type, // CHECK-SAME: ::mlir::Value value, ::mlir::TypeRange typeRange, ::mlir::ValueRange valueRange) { // CHECK-NEXT: return success(); diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td index 5683f34..35d2c49 100644 --- a/mlir/test/mlir-tblgen/attrdefs.td +++ b/mlir/test/mlir-tblgen/attrdefs.td @@ -86,7 +86,7 @@ def B_CompoundAttrA : TestAttr<"CompoundA"> { // DECL-LABEL: class CompoundAAttr : public ::mlir::Attribute // DECL: static CompoundAAttr getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, int widthOfSomething, ::test::SimpleTypeA exampleTdType, ::llvm::APFloat apFloat, ::llvm::ArrayRef dims, ::mlir::Type inner); -// DECL: static ::mlir::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::test::SimpleTypeA exampleTdType, ::llvm::APFloat apFloat, ::llvm::ArrayRef dims, ::mlir::Type inner); +// DECL: static ::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::test::SimpleTypeA exampleTdType, ::llvm::APFloat apFloat, ::llvm::ArrayRef dims, ::mlir::Type inner); // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return {"cmpnd_a"}; // DECL: } diff --git a/mlir/test/mlir-tblgen/constraint-unique.td b/mlir/test/mlir-tblgen/constraint-unique.td index cd41efa..214cd6c 100644 --- a/mlir/test/mlir-tblgen/constraint-unique.td +++ b/mlir/test/mlir-tblgen/constraint-unique.td @@ -54,7 +54,7 @@ def OpC : NS_Op<"op_c"> { } /// Test that a type contraint was generated. -// CHECK: static ::mlir::LogicalResult [[$A_TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$A_TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( // CHECK: if (!((typePred(type, *op)))) { // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NEXT: << " must be a type, but got " << type; @@ -63,13 +63,13 @@ def OpC : NS_Op<"op_c"> { // CHECK-NOT: << " must be a type, but got " << type; /// Test that a type constraint with a different description was generated. -// CHECK: static ::mlir::LogicalResult [[$O_TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$O_TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( // CHECK: if (!((typePred(type, *op)))) { // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NEXT: << " must be another type, but got " << type; /// Test that an attribute contraint was generated. -// CHECK: static ::mlir::LogicalResult [[$A_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$A_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( // CHECK: if (attr && !((attrPred(attr, *op)))) // CHECK-NEXT: return emitError() << "attribute '" << attrName // CHECK-NEXT: << "' failed to satisfy constraint: an attribute"; @@ -78,14 +78,14 @@ def OpC : NS_Op<"op_c"> { // CHECK-NOT: << "' failed to satisfy constraint: an attribute"; /// Test that a attribute constraint with a different description was generated. -// CHECK: static ::mlir::LogicalResult [[$O_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( -// CHECK: static ::mlir::LogicalResult [[$O_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$O_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$O_ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( // CHECK: if (attr && !((attrPred(attr, *op)))) // CHECK-NEXT: return emitError() << "attribute '" << attrName // CHECK-NEXT: << "' failed to satisfy constraint: another attribute"; /// Test that a successor contraint was generated. -// CHECK: static ::mlir::LogicalResult [[$A_SUCCESSOR_CONSTRAINT:__mlir_ods_local_successor_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$A_SUCCESSOR_CONSTRAINT:__mlir_ods_local_successor_constraint.*]]( // CHECK: if (!((successorPred(successor, *op)))) { // CHECK-NEXT: return op->emitOpError("successor #") << successorIndex << " ('" // CHECK-NEXT: << successorName << ")' failed to verify constraint: a successor"; @@ -94,13 +94,13 @@ def OpC : NS_Op<"op_c"> { // CHECK-NOT: << successorName << ")' failed to verify constraint: a successor"; /// Test that a successor constraint with a different description was generated. -// CHECK: static ::mlir::LogicalResult [[$O_SUCCESSOR_CONSTRAINT:__mlir_ods_local_successor_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$O_SUCCESSOR_CONSTRAINT:__mlir_ods_local_successor_constraint.*]]( // CHECK: if (!((successorPred(successor, *op)))) { // CHECK-NEXT: return op->emitOpError("successor #") << successorIndex << " ('" // CHECK-NEXT: << successorName << ")' failed to verify constraint: another successor"; /// Test that a region contraint was generated. -// CHECK: static ::mlir::LogicalResult [[$A_REGION_CONSTRAINT:__mlir_ods_local_region_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$A_REGION_CONSTRAINT:__mlir_ods_local_region_constraint.*]]( // CHECK: if (!((regionPred(region, *op)))) { // CHECK-NEXT: return op->emitOpError("region #") << regionIndex // CHECK-NEXT: << (regionName.empty() ? " " : " ('" + regionName + "') ") @@ -110,7 +110,7 @@ def OpC : NS_Op<"op_c"> { // CHECK-NOT: << "failed to verify constraint: a region"; /// Test that a region constraint with a different description was generated. -// CHECK: static ::mlir::LogicalResult [[$O_REGION_CONSTRAINT:__mlir_ods_local_region_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$O_REGION_CONSTRAINT:__mlir_ods_local_region_constraint.*]]( // CHECK: if (!((regionPred(region, *op)))) { // CHECK-NEXT: return op->emitOpError("region #") << regionIndex // CHECK-NEXT: << (regionName.empty() ? " " : " ('" + regionName + "') ") diff --git a/mlir/test/mlir-tblgen/interfaces-as-constraints.td b/mlir/test/mlir-tblgen/interfaces-as-constraints.td index 109bf07..b0438c2 100644 --- a/mlir/test/mlir-tblgen/interfaces-as-constraints.td +++ b/mlir/test/mlir-tblgen/interfaces-as-constraints.td @@ -23,22 +23,22 @@ def OpUsingAllOfThose : Op { let results = (outs TopLevelTypeInterface:$res1, TypeInterfaceInNamespace:$res2); } -// CHECK: static ::mlir::LogicalResult {{__mlir_ods_local_type_constraint.*}}( +// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_type_constraint.*}}( // CHECK: if (!((::llvm::isa(type)))) { // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NEXT: << " must be TopLevelTypeInterface instance, but got " << type; -// CHECK: static ::mlir::LogicalResult {{__mlir_ods_local_type_constraint.*}}( +// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_type_constraint.*}}( // CHECK: if (!((::llvm::isa(type)))) { // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NEXT: << " must be TypeInterfaceInNamespace instance, but got " << type; -// CHECK: static ::mlir::LogicalResult {{__mlir_ods_local_attr_constraint.*}}( +// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_attr_constraint.*}}( // CHECK: if (attr && !((::llvm::isa(attr)))) // CHECK-NEXT: return emitError() << "attribute '" << attrName // CHECK-NEXT: << "' failed to satisfy constraint: TopLevelAttrInterface instance"; -// CHECK: static ::mlir::LogicalResult {{__mlir_ods_local_attr_constraint.*}}( +// CHECK: static ::llvm::LogicalResult {{__mlir_ods_local_attr_constraint.*}}( // CHECK: if (attr && !((::llvm::isa(attr)))) // CHECK-NEXT: return emitError() << "attribute '" << attrName // CHECK-NEXT: << "' failed to satisfy constraint: AttrInterfaceInNamespace instance"; diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td index 6f2d430..a82cd2e 100644 --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -68,7 +68,7 @@ def AOp : NS_Op<"a_op", []> { // Test verify method // --- -// DEF: ::mlir::LogicalResult AOpAdaptor::verify +// DEF: ::llvm::LogicalResult AOpAdaptor::verify // DEF: ::mlir::Attribute tblgen_aAttr; // DEF: while (true) { // DEF-NEXT: if (namedAttrIt == namedAttrRange.end()) @@ -220,7 +220,7 @@ def AgetOp : Op { // Test verify method // --- -// DEF: ::mlir::LogicalResult AgetOpAdaptor::verify +// DEF: ::llvm::LogicalResult AgetOpAdaptor::verify // DEF: ::mlir::Attribute tblgen_aAttr; // DEF: while (true) // DEF: ::mlir::Attribute tblgen_bAttr; diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td index 836ddca..f6fe450 100644 --- a/mlir/test/mlir-tblgen/op-decl-and-defs.td +++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td @@ -84,7 +84,7 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> { // CHECK: class AOpAdaptor : public AOpGenericAdaptor<::mlir::ValueRange> { // CHECK: public: // CHECK: AOpAdaptor(AOp -// CHECK: ::mlir::LogicalResult verify( +// CHECK: ::llvm::LogicalResult verify( // CHECK: }; // CHECK: class AOp : public ::mlir::Op::Impl, ::mlir::OpTrait::AtLeastNResults<1>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::AtLeastNOperands<1>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::OpTrait::IsIsolatedFromAbove @@ -120,9 +120,9 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> { // CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) // CHECK: static ::mlir::ParseResult parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result); // CHECK: void print(::mlir::OpAsmPrinter &p); -// CHECK: ::mlir::LogicalResult verifyInvariants(); +// CHECK: ::llvm::LogicalResult verifyInvariants(); // CHECK: static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); -// CHECK: ::mlir::LogicalResult fold(FoldAdaptor adaptor, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results); +// CHECK: ::llvm::LogicalResult fold(FoldAdaptor adaptor, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results); // CHECK: // Display a graph for debugging purposes. // CHECK: void displayGraph(); // CHECK: }; @@ -205,7 +205,7 @@ def NS_FOp : NS_Op<"op_with_all_types_constraint", } // CHECK-LABEL: class FOp : -// CHECK: static ::mlir::LogicalResult inferReturnTypes +// CHECK: static ::llvm::LogicalResult inferReturnTypes def NS_GOp : NS_Op<"op_with_fixed_return_type", []> { let arguments = (ins AnyType:$a); @@ -213,7 +213,7 @@ def NS_GOp : NS_Op<"op_with_fixed_return_type", []> { } // CHECK-LABEL: class GOp : -// CHECK: static ::mlir::LogicalResult inferReturnTypes +// CHECK: static ::llvm::LogicalResult inferReturnTypes // Check default value for collective params builder. Check that other builders // are generated as well. diff --git a/mlir/test/mlir-tblgen/predicate.td b/mlir/test/mlir-tblgen/predicate.td index 44f395d..c1fcd3f 100644 --- a/mlir/test/mlir-tblgen/predicate.td +++ b/mlir/test/mlir-tblgen/predicate.td @@ -16,7 +16,7 @@ def OpA : NS_Op<"op_for_CPred_containing_multiple_same_placeholder", []> { let results = (outs Variadic:$y); } -// CHECK: static ::mlir::LogicalResult [[$INTEGER_FLOAT_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$INTEGER_FLOAT_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( // CHECK: if (!((type.isInteger(32) || type.isF32()))) { // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NEXT: << " must be 32-bit integer or floating-point type, but got " << type; @@ -26,12 +26,12 @@ def OpA : NS_Op<"op_for_CPred_containing_multiple_same_placeholder", []> { // CHECK-NOT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NOT. << " must be 32-bit integer or floating-point type, but got " << type; -// CHECK: static ::mlir::LogicalResult [[$TENSOR_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$TENSOR_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( // CHECK: if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return (true); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NEXT: << " must be tensor of any type values, but got " << type; -// CHECK: static ::mlir::LogicalResult [[$TENSOR_INTEGER_FLOAT_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$TENSOR_INTEGER_FLOAT_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( // CHECK: if (!(((::llvm::isa<::mlir::TensorType>(type))) && ([](::mlir::Type elementType) { return ((elementType.isF32())) || ((elementType.isSignlessInteger(32))); }(::llvm::cast<::mlir::ShapedType>(type).getElementType())))) { // CHECK-NEXT: return op->emitOpError(valueKind) << " #" << valueIndex // CHECK-NEXT: << " must be tensor of 32-bit float or 32-bit signless integer values, but got " << type; diff --git a/mlir/test/mlir-tblgen/rewriter-static-matcher.td b/mlir/test/mlir-tblgen/rewriter-static-matcher.td index 7a84dfd..c5debf5 100644 --- a/mlir/test/mlir-tblgen/rewriter-static-matcher.td +++ b/mlir/test/mlir-tblgen/rewriter-static-matcher.td @@ -48,11 +48,11 @@ def Foo : NativeCodeCall<"foo($_builder, $0)">; // Test static matcher for duplicate DagNode // --- -// CHECK: static ::mlir::LogicalResult [[$TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$TYPE_CONSTRAINT:__mlir_ods_local_type_constraint.*]]( // CHECK-NEXT: {{.*::mlir::Type type}} -// CHECK: static ::mlir::LogicalResult [[$ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( +// CHECK: static ::llvm::LogicalResult [[$ATTR_CONSTRAINT:__mlir_ods_local_attr_constraint.*]]( // CHECK-NEXT: {{.*::mlir::Attribute attr}} -// CHECK: static ::mlir::LogicalResult [[$DAG_MATCHER:static_dag_matcher.*]]( +// CHECK: static ::llvm::LogicalResult [[$DAG_MATCHER:static_dag_matcher.*]]( // CHECK: if(::mlir::failed([[$ATTR_CONSTRAINT]] // CHECK: if(::mlir::failed([[$TYPE_CONSTRAINT]] diff --git a/mlir/test/mlir-tblgen/typedefs.td b/mlir/test/mlir-tblgen/typedefs.td index 705da4e..b9e3a79 100644 --- a/mlir/test/mlir-tblgen/typedefs.td +++ b/mlir/test/mlir-tblgen/typedefs.td @@ -70,7 +70,7 @@ def B_CompoundTypeA : TestType<"CompoundA"> { // DECL-LABEL: class CompoundAType : public ::mlir::Type // DECL: static CompoundAType getChecked(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, ::mlir::MLIRContext *context, int widthOfSomething, ::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef dims, ::mlir::Type inner); -// DECL: static ::mlir::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef dims, ::mlir::Type inner); +// DECL: static ::llvm::LogicalResult verify(::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError, int widthOfSomething, ::test::SimpleTypeA exampleTdType, SomeCppStruct exampleCppType, ::llvm::ArrayRef dims, ::mlir::Type inner); // DECL: static constexpr ::llvm::StringLiteral getMnemonic() { // DECL: return {"cmpnd_a"}; // DECL: } diff --git a/mlir/test/python/python_test_ops.td b/mlir/test/python/python_test_ops.td index 9530198..c0bc184 100644 --- a/mlir/test/python/python_test_ops.td +++ b/mlir/test/python/python_test_ops.td @@ -128,7 +128,7 @@ def InferResultsOp : TestOp<"infer_results_op", [InferTypeOpInterface]> { let results = (outs AnyInteger:$single, AnyInteger:$doubled); let extraClassDeclaration = [{ - static ::mlir::LogicalResult inferReturnTypes( + static ::llvm::LogicalResult inferReturnTypes( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties, @@ -151,7 +151,7 @@ def InferResultsVariadicInputsOp : TestOp<"infer_results_variadic_inputs_op", let results = (outs I32OrF32:$res); let extraClassDeclaration = [{ - static ::mlir::LogicalResult inferReturnTypes( + static ::llvm::LogicalResult inferReturnTypes( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties, @@ -180,7 +180,7 @@ def InferShapedTypeComponentsOp : TestOp<"infer_shaped_type_components_op", let results = (outs AnyTensor:$result); let extraClassDefinition = [{ - ::mlir::LogicalResult $cppClass::inferReturnTypeComponents( + ::llvm::LogicalResult $cppClass::inferReturnTypeComponents( ::mlir::MLIRContext *context, ::std::optional<::mlir::Location> location, ::mlir::ValueShapeRange operands, ::mlir::DictionaryAttr attributes, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions, diff --git a/mlir/tools/mlir-pdll-lsp-server/mlir-pdll-lsp-server.cpp b/mlir/tools/mlir-pdll-lsp-server/mlir-pdll-lsp-server.cpp index de50fd3..ffda7c8 100644 --- a/mlir/tools/mlir-pdll-lsp-server/mlir-pdll-lsp-server.cpp +++ b/mlir/tools/mlir-pdll-lsp-server/mlir-pdll-lsp-server.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h" using namespace mlir; diff --git a/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp b/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp index b15f2ce..2f92ff2 100644 --- a/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp +++ b/mlir/tools/mlir-src-sharder/mlir-src-sharder.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Support/FileUtilities.h" -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/MemoryBuffer.h" diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp index 55bc071..ea0d152 100644 --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -297,7 +297,7 @@ void DefGen::emitBuilders() { void DefGen::emitVerifier() { defCls.declare("Base::getChecked"); defCls.declareStaticMethod( - "::mlir::LogicalResult", "verify", + "::llvm::LogicalResult", "verify", getBuilderParams({{"::llvm::function_ref<::mlir::InFlightDiagnostic()>", "emitError"}})); } @@ -819,7 +819,7 @@ void DefGenerator::emitParsePrintDispatch(ArrayRef defs) { strfmt("generated{0}Parser", valueType), Method::StaticInline, std::move(params)); // Declare the printer. - Method printer("::mlir::LogicalResult", + Method printer("::llvm::LogicalResult", strfmt("generated{0}Printer", valueType), Method::StaticInline, {{strfmt("::mlir::{0}", valueType), "def"}, {"::mlir::AsmPrinter &", "printer"}}); @@ -839,7 +839,7 @@ void DefGenerator::emitParsePrintDispatch(ArrayRef defs) { // The printer dispatch uses llvm::TypeSwitch to find and call the correct // printer. printer.body() << " return ::llvm::TypeSwitch<::mlir::" << valueType - << ", ::mlir::LogicalResult>(def)"; + << ", ::llvm::LogicalResult>(def)"; const char *const printValue = R"( .Case<{0}>([&](auto t) {{ printer << {0}::getMnemonic();{1} return ::mlir::success(); diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp index 50378fe..ffd5a39 100644 --- a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp @@ -9,7 +9,6 @@ #include "AttrOrTypeFormatGen.h" #include "FormatGen.h" #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "mlir/TableGen/AttrOrTypeDef.h" #include "mlir/TableGen/Format.h" #include "mlir/TableGen/GenInfo.h" diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp index 46e585a..2412876 100644 --- a/mlir/tools/mlir-tblgen/DialectGen.cpp +++ b/mlir/tools/mlir-tblgen/DialectGen.cpp @@ -166,7 +166,7 @@ static const char *const constantMaterializerDecl = R"( static const char *const opAttrVerifierDecl = R"( /// Provides a hook for verifying dialect attributes attached to the given /// op. - ::mlir::LogicalResult verifyOperationAttribute( + ::llvm::LogicalResult verifyOperationAttribute( ::mlir::Operation *op, ::mlir::NamedAttribute attribute) override; )"; @@ -174,7 +174,7 @@ static const char *const opAttrVerifierDecl = R"( static const char *const regionArgAttrVerifierDecl = R"( /// Provides a hook for verifying dialect attributes attached to the given /// op's region argument. - ::mlir::LogicalResult verifyRegionArgAttribute( + ::llvm::LogicalResult verifyRegionArgAttribute( ::mlir::Operation *op, unsigned regionIndex, unsigned argIndex, ::mlir::NamedAttribute attribute) override; )"; @@ -183,7 +183,7 @@ static const char *const regionArgAttrVerifierDecl = R"( static const char *const regionResultAttrVerifierDecl = R"( /// Provides a hook for verifying dialect attributes attached to the given /// op's region result. - ::mlir::LogicalResult verifyRegionResultAttribute( + ::llvm::LogicalResult verifyRegionResultAttribute( ::mlir::Operation *op, unsigned regionIndex, unsigned resultIndex, ::mlir::NamedAttribute attribute) override; )"; diff --git a/mlir/tools/mlir-tblgen/FormatGen.h b/mlir/tools/mlir-tblgen/FormatGen.h index b061d4d..1dc2cb3 100644 --- a/mlir/tools/mlir-tblgen/FormatGen.h +++ b/mlir/tools/mlir-tblgen/FormatGen.h @@ -15,7 +15,6 @@ #define MLIR_TOOLS_MLIRTBLGEN_FORMATGEN_H_ #include "mlir/Support/LLVM.h" -#include "mlir/Support/LogicalResult.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Allocator.h" diff --git a/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp b/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp index 2c7acec..ebadfe4 100644 --- a/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp +++ b/mlir/tools/mlir-tblgen/LLVMIRConversionGen.cpp @@ -11,7 +11,6 @@ // //===----------------------------------------------------------------------===// -#include "mlir/Support/LogicalResult.h" #include "mlir/TableGen/Argument.h" #include "mlir/TableGen/Attribute.h" #include "mlir/TableGen/GenInfo.h" diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 3146e65..0fc750c 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1250,7 +1250,7 @@ void OpEmitter::genPropertiesSupport() { auto &setPropMethod = opClass .addStaticMethod( - "::mlir::LogicalResult", "setPropertiesFromAttr", + "::llvm::LogicalResult", "setPropertiesFromAttr", MethodParameter("Properties &", "prop"), MethodParameter("::mlir::Attribute", "attr"), MethodParameter( @@ -1292,7 +1292,7 @@ void OpEmitter::genPropertiesSupport() { auto &verifyInherentAttrsMethod = opClass .addStaticMethod( - "::mlir::LogicalResult", "verifyInherentAttrs", + "::llvm::LogicalResult", "verifyInherentAttrs", MethodParameter("::mlir::OperationName", "opName"), MethodParameter("::mlir::NamedAttrList &", "attrs"), MethodParameter( @@ -1597,7 +1597,7 @@ void OpEmitter::genPropertiesSupportForBytecode( ArrayRef attrOrProperties) { if (op.useCustomPropertiesEncoding()) { opClass.declareStaticMethod( - "::mlir::LogicalResult", "readProperties", + "::llvm::LogicalResult", "readProperties", MethodParameter("::mlir::DialectBytecodeReader &", "reader"), MethodParameter("::mlir::OperationState &", "state")); opClass.declareMethod( @@ -1609,7 +1609,7 @@ void OpEmitter::genPropertiesSupportForBytecode( auto &readPropertiesMethod = opClass .addStaticMethod( - "::mlir::LogicalResult", "readProperties", + "::llvm::LogicalResult", "readProperties", MethodParameter("::mlir::DialectBytecodeReader &", "reader"), MethodParameter("::mlir::OperationState &", "state")) ->body(); @@ -3226,7 +3226,7 @@ void OpEmitter::genCanonicalizerDecls() { SmallVector paramList; paramList.emplace_back(op.getCppClassName(), "op"); paramList.emplace_back("::mlir::PatternRewriter &", "rewriter"); - auto *m = opClass.declareStaticMethod("::mlir::LogicalResult", + auto *m = opClass.declareStaticMethod("::llvm::LogicalResult", "canonicalize", std::move(paramList)); ERROR_IF_PRUNED(m, "canonicalize", op); } @@ -3272,7 +3272,7 @@ void OpEmitter::genFolderDecls() { } else { paramList.emplace_back("::llvm::SmallVectorImpl<::mlir::OpFoldResult> &", "results"); - retType = "::mlir::LogicalResult"; + retType = "::llvm::LogicalResult"; } auto *m = opClass.declareMethod(retType, "fold", std::move(paramList)); @@ -3563,7 +3563,7 @@ void OpEmitter::genPrinter() { void OpEmitter::genVerifier() { auto *implMethod = - opClass.addMethod("::mlir::LogicalResult", "verifyInvariantsImpl"); + opClass.addMethod("::llvm::LogicalResult", "verifyInvariantsImpl"); ERROR_IF_PRUNED(implMethod, "verifyInvariantsImpl", op); auto &implBody = implMethod->body(); bool useProperties = emitHelper.hasProperties(); @@ -3592,7 +3592,7 @@ void OpEmitter::genVerifier() { // This may not act as their expectation because this doesn't call any // verifiers of native/interface traits. Needs to review those use cases and // see if we should use the mlir::verify() instead. - auto *method = opClass.addMethod("::mlir::LogicalResult", "verifyInvariants"); + auto *method = opClass.addMethod("::llvm::LogicalResult", "verifyInvariants"); ERROR_IF_PRUNED(method, "verifyInvariants", op); auto &body = method->body(); if (def.getValueAsBit("hasVerifier")) { @@ -3607,13 +3607,13 @@ void OpEmitter::genVerifier() { void OpEmitter::genCustomVerifier() { if (def.getValueAsBit("hasVerifier")) { - auto *method = opClass.declareMethod("::mlir::LogicalResult", "verify"); + auto *method = opClass.declareMethod("::llvm::LogicalResult", "verify"); ERROR_IF_PRUNED(method, "verify", op); } if (def.getValueAsBit("hasRegionVerifier")) { auto *method = - opClass.declareMethod("::mlir::LogicalResult", "verifyRegions"); + opClass.declareMethod("::llvm::LogicalResult", "verifyRegions"); ERROR_IF_PRUNED(method, "verifyRegions", op); } } @@ -4334,7 +4334,7 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter( } void OpOperandAdaptorEmitter::addVerification() { - auto *method = adaptor.addMethod("::mlir::LogicalResult", "verify", + auto *method = adaptor.addMethod("::llvm::LogicalResult", "verify", MethodParameter("::mlir::Location", "loc")); ERROR_IF_PRUNED(method, "verify", op); auto &body = method->body(); diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp index f7cc0a2..a97d876 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -1200,7 +1200,7 @@ static void genParsedAttrPropertiesSetter(OperationFormat &fmt, Operator &op, paramList.emplace_back("::llvm::function_ref<::mlir::InFlightDiagnostic()>", "emitError"); - Method *method = opClass.addStaticMethod("::mlir::LogicalResult", + Method *method = opClass.addStaticMethod("::llvm::LogicalResult", "setPropertiesFromParsedAttr", std::move(paramList)); MethodBody &body = method->body().indent(); diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp index 2a7406f..4b06b92 100644 --- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp +++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp @@ -480,7 +480,7 @@ void InterfaceGenerator::emitTraitDecl(const Interface &interface, tblgen::FmtContext verifyCtx; verifyCtx.addSubst("_op", "op"); os << llvm::formatv( - " static ::mlir::LogicalResult {0}(::mlir::Operation *op) ", + " static ::llvm::LogicalResult {0}(::mlir::Operation *op) ", (interface.verifyWithRegions() ? "verifyRegionTrait" : "verifyTrait")) << "{\n " << tblgen::tgfmt(verify->trim(), &verifyCtx) diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp index 0d3b29c..2c79ba2 100644 --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -366,7 +366,7 @@ std::string PatternEmitter::handleConstantAttr(Attribute attr, void PatternEmitter::emitStaticMatcher(DagNode tree, std::string funcName) { os << formatv( - "static ::mlir::LogicalResult {0}(::mlir::PatternRewriter &rewriter, " + "static ::llvm::LogicalResult {0}(::mlir::PatternRewriter &rewriter, " "::mlir::Operation *op0, ::llvm::SmallVector<::mlir::Operation " "*, 4> &tblgen_ops", funcName); @@ -1081,7 +1081,7 @@ void PatternEmitter::emit(StringRef rewriteName) { { auto classScope = os.scope(); os.printReindented(R"( - ::mlir::LogicalResult matchAndRewrite(::mlir::Operation *op0, + ::llvm::LogicalResult matchAndRewrite(::mlir::Operation *op0, ::mlir::PatternRewriter &rewriter) const override {)") << '\n'; { diff --git a/mlir/tools/mlir-translate/mlir-translate.cpp b/mlir/tools/mlir-translate/mlir-translate.cpp index 309def8..9d2dd88 100644 --- a/mlir/tools/mlir-translate/mlir-translate.cpp +++ b/mlir/tools/mlir-translate/mlir-translate.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "mlir/InitAllTranslations.h" -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "mlir/Tools/mlir-translate/MlirTranslateMain.h" using namespace mlir; diff --git a/mlir/tools/mlir-vulkan-runner/VulkanRuntime.h b/mlir/tools/mlir-vulkan-runner/VulkanRuntime.h index 9fa52b0..17db8d0 100644 --- a/mlir/tools/mlir-vulkan-runner/VulkanRuntime.h +++ b/mlir/tools/mlir-vulkan-runner/VulkanRuntime.h @@ -13,7 +13,7 @@ #ifndef VULKAN_RUNTIME_H #define VULKAN_RUNTIME_H -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include #include diff --git a/mlir/tools/tblgen-lsp-server/tblgen-lsp-server.cpp b/mlir/tools/tblgen-lsp-server/tblgen-lsp-server.cpp index 90b2d98..e8fdbfc 100644 --- a/mlir/tools/tblgen-lsp-server/tblgen-lsp-server.cpp +++ b/mlir/tools/tblgen-lsp-server/tblgen-lsp-server.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "mlir/Support/LogicalResult.h" +#include "mlir/Support/LLVM.h" #include "mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h" using namespace mlir; diff --git a/mlir/unittests/Rewrite/PatternBenefit.cpp b/mlir/unittests/Rewrite/PatternBenefit.cpp index 79552f0..65ea4ee 100644 --- a/mlir/unittests/Rewrite/PatternBenefit.cpp +++ b/mlir/unittests/Rewrite/PatternBenefit.cpp @@ -27,7 +27,7 @@ TEST(PatternBenefitTest, BenefitOrder) { Pattern1(mlir::MLIRContext *context, bool *called) : OpRewritePattern(context, /*benefit*/ 1), called(called) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(ModuleOp /*op*/, mlir::PatternRewriter & /*rewriter*/) const override { *called = true; @@ -43,7 +43,7 @@ TEST(PatternBenefitTest, BenefitOrder) { : RewritePattern(MatchAnyOpTypeTag(), /*benefit=*/2, context), called(called) {} - mlir::LogicalResult + llvm::LogicalResult matchAndRewrite(Operation * /*op*/, mlir::PatternRewriter & /*rewriter*/) const override { *called = true; -- cgit v1.1 From 030ea6d38b7c6afc191bc721be9d59e89bbf7631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Mon, 1 Jul 2024 14:26:14 +0200 Subject: [clang][Interp] Only check toplevel declarations --- clang/lib/AST/Interp/Compiler.cpp | 10 +++++----- clang/lib/AST/Interp/Compiler.h | 2 +- clang/test/AST/Interp/c.c | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 5ae36da..77c7e20 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -3460,7 +3460,7 @@ bool Compiler::visitDecl(const VarDecl *VD, bool ConstantContext) { } // Create and initialize the variable. - if (!this->visitVarDecl(VD)) + if (!this->visitVarDecl(VD, /*Toplevel=*/true)) return false; // Get a pointer to the variable @@ -3507,7 +3507,7 @@ bool Compiler::visitDecl(const VarDecl *VD, bool ConstantContext) { } template -VarCreationState Compiler::visitVarDecl(const VarDecl *VD) { +VarCreationState Compiler::visitVarDecl(const VarDecl *VD, bool Toplevel) { // We don't know what to do with these, so just return false. if (VD->getType().isNull()) return false; @@ -3521,7 +3521,7 @@ VarCreationState Compiler::visitVarDecl(const VarDecl *VD) { std::optional VarT = classify(VD->getType()); auto checkDecl = [&]() -> bool { - bool NeedsOp = VD->isLocalVarDecl() && VD->isStaticLocal(); + bool NeedsOp = !Toplevel && VD->isLocalVarDecl() && VD->isStaticLocal(); return !NeedsOp || this->emitCheckDecl(VD, VD); }; @@ -4991,7 +4991,7 @@ bool Compiler::visitDeclRef(const ValueDecl *D, const Expr *E) { if ((VD->hasGlobalStorage() || VD->isLocalVarDecl() || VD->isStaticDataMember()) && typeShouldBeVisited(VD->getType())) { - auto VarState = this->visitVarDecl(VD); + auto VarState = this->visitVarDecl(VD, true); if (VarState.notCreated()) return true; if (!VarState) @@ -5004,7 +5004,7 @@ bool Compiler::visitDeclRef(const ValueDecl *D, const Expr *E) { if (const auto *VD = dyn_cast(D); VD && VD->getAnyInitializer() && VD->getType().isConstant(Ctx.getASTContext()) && !VD->isWeak()) { - auto VarState = this->visitVarDecl(VD); + auto VarState = this->visitVarDecl(VD, true); if (VarState.notCreated()) return true; if (!VarState) diff --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h index d188ce2..67bd7ef 100644 --- a/clang/lib/AST/Interp/Compiler.h +++ b/clang/lib/AST/Interp/Compiler.h @@ -260,7 +260,7 @@ protected: /// intact. bool delegate(const Expr *E); /// Creates and initializes a variable from the given decl. - VarCreationState visitVarDecl(const VarDecl *VD); + VarCreationState visitVarDecl(const VarDecl *VD, bool Toplevel = false); /// Visit an APValue. bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E); bool visitAPValueInitializer(const APValue &Val, const Expr *E); diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c index 684658d..9ec305d 100644 --- a/clang/test/AST/Interp/c.c +++ b/clang/test/AST/Interp/c.c @@ -293,3 +293,11 @@ void SuperSpecialFunc(void) { const int SuperSpecialCase = 10; _Static_assert((sizeof(SuperSpecialCase) == 12 && SuperSpecialCase == 3) || SuperSpecialCase == 10, ""); // pedantic-warning {{GNU extension}} } + + +void T1(void) { + static int *y[1] = {({ static int _x = 20; (void*)0;})}; // all-error {{initializer element is not a compile-time constant}} \ + // pedantic-warning {{use of GNU statement expression extension}} +} + + -- cgit v1.1 From 62e6255a58eb0e9bb31e366a9e30d5c1eaadd004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Mon, 1 Jul 2024 17:39:23 +0200 Subject: [clang][Interp] Add missing fallthrough in loops --- clang/lib/AST/Interp/Compiler.cpp | 11 +++++++++++ clang/test/AST/Interp/literals.cpp | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 77c7e20..3d9c72e 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -4139,6 +4139,7 @@ bool Compiler::visitWhileStmt(const WhileStmt *S) { LabelTy EndLabel = this->getLabel(); // Label after the loop. LoopScope LS(this, EndLabel, CondLabel); + this->fallthrough(CondLabel); this->emitLabel(CondLabel); if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt()) @@ -4174,12 +4175,14 @@ template bool Compiler::visitDoStmt(const DoStmt *S) { LoopScope LS(this, EndLabel, CondLabel); LocalScope Scope(this); + this->fallthrough(StartLabel); this->emitLabel(StartLabel); { DestructorScope DS(Scope); if (!this->visitLoopBody(Body)) return false; + this->fallthrough(CondLabel); this->emitLabel(CondLabel); if (!this->visitBool(Cond)) return false; @@ -4187,6 +4190,7 @@ template bool Compiler::visitDoStmt(const DoStmt *S) { if (!this->jumpTrue(StartLabel)) return false; + this->fallthrough(EndLabel); this->emitLabel(EndLabel); return true; } @@ -4207,6 +4211,7 @@ bool Compiler::visitForStmt(const ForStmt *S) { if (Init && !this->visitStmt(Init)) return false; + this->fallthrough(CondLabel); this->emitLabel(CondLabel); if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt()) @@ -4225,6 +4230,7 @@ bool Compiler::visitForStmt(const ForStmt *S) { if (Body && !this->visitLoopBody(Body)) return false; + this->fallthrough(IncLabel); this->emitLabel(IncLabel); if (Inc && !this->discard(Inc)) return false; @@ -4232,6 +4238,7 @@ bool Compiler::visitForStmt(const ForStmt *S) { if (!this->jump(CondLabel)) return false; + this->fallthrough(EndLabel); this->emitLabel(EndLabel); return true; } @@ -4263,6 +4270,7 @@ bool Compiler::visitCXXForRangeStmt(const CXXForRangeStmt *S) { return false; // Now the condition as well as the loop variable assignment. + this->fallthrough(CondLabel); this->emitLabel(CondLabel); if (!this->visitBool(Cond)) return false; @@ -4279,13 +4287,16 @@ bool Compiler::visitCXXForRangeStmt(const CXXForRangeStmt *S) { if (!this->visitLoopBody(Body)) return false; + this->fallthrough(IncLabel); this->emitLabel(IncLabel); if (!this->discard(Inc)) return false; } + if (!this->jump(CondLabel)) return false; + this->fallthrough(EndLabel); this->emitLabel(EndLabel); return true; } diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index a7a602e..3abaf89 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -1243,3 +1243,16 @@ namespace Extern { static_assert(&ExternNonLiteralVarDecl() == &nl, ""); #endif } + +#if __cplusplus >= 201402L +constexpr int StmtExprEval() { + if (({ + while (0); + true; + })) { + return 2; + } + return 1; +} +static_assert(StmtExprEval() == 2, ""); +#endif -- cgit v1.1 From 2da10959e00a81b983a0ea6d5c1ba9e0f2e1f192 Mon Sep 17 00:00:00 2001 From: Kendal Harland <3987220+kendalharland@users.noreply.github.com> Date: Tue, 2 Jul 2024 03:06:12 -0700 Subject: [lldb][test] Disable TestUseSourceCache on Windows (#97324) This test also fails on Windows amd64, although it is only disabled for aarch64. Co-authored-by: kendal --- lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py index c54345a..4215990 100644 --- a/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py +++ b/lldb/test/API/commands/settings/use_source_cache/TestUseSourceCache.py @@ -18,7 +18,7 @@ class SettingsUseSourceCacheTestCase(TestBase): self.set_use_source_cache_and_test(False) @skipIf(hostoslist=no_match(["windows"])) - @skipIf(oslist=["windows"], archs=["aarch64"]) # Fails on windows 11 + @skipIf(oslist=["windows"]) # Fails on windows 11 def test_set_use_source_cache_true(self): """Test that after 'set use-source-cache false', files are locked.""" self.set_use_source_cache_and_test(True) -- cgit v1.1 From 17bd3120adc51dbb0bef2dda26f39ef96fa4cd00 Mon Sep 17 00:00:00 2001 From: Slava Zakharin Date: Tue, 2 Jul 2024 03:14:44 -0700 Subject: [flang] Use 0 for unknown function pointer result length. (#97035) --- flang/lib/Lower/ConvertProcedureDesignator.cpp | 8 +++++++- flang/test/Lower/HLFIR/procedure-pointer.f90 | 4 ++-- flang/test/Lower/dummy-procedure-character.f90 | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/flang/lib/Lower/ConvertProcedureDesignator.cpp b/flang/lib/Lower/ConvertProcedureDesignator.cpp index aa0d7ce..b528544 100644 --- a/flang/lib/Lower/ConvertProcedureDesignator.cpp +++ b/flang/lib/Lower/ConvertProcedureDesignator.cpp @@ -89,9 +89,15 @@ fir::ExtendedValue Fortran::lower::convertProcedureDesignator( fir::factory::genMaxWithZero(builder, loc, rawLen); } } + // The caller of the function pointer will have to allocate + // the function result with the character length specified + // by the boxed value. If the result length cannot be + // computed statically, set it to zero (we used to use -1, + // but this could cause assertions in LLVM after inlining + // exposed alloca of size -1). if (!funcPtrResultLength) funcPtrResultLength = builder.createIntegerConstant( - loc, builder.getCharacterLengthType(), -1); + loc, builder.getCharacterLengthType(), 0); return fir::CharBoxValue{funcPtr, funcPtrResultLength}; } return funcPtr; diff --git a/flang/test/Lower/HLFIR/procedure-pointer.f90 b/flang/test/Lower/HLFIR/procedure-pointer.f90 index ce20f19..69b215e 100644 --- a/flang/test/Lower/HLFIR/procedure-pointer.f90 +++ b/flang/test/Lower/HLFIR/procedure-pointer.f90 @@ -128,7 +128,7 @@ use m ! CHECK: fir.store %[[VAL_2]] to %[[VAL_0]] : !fir.ref) -> !fir.box>>>> ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFsub4Ep2"} : (!fir.ref) -> !fir.box>>>>) -> (!fir.ref) -> !fir.box>>>>, !fir.ref) -> !fir.box>>>>) ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QPchar_func) : (!fir.ref) -> !fir.box>> -! CHECK: %[[VAL_12:.*]] = arith.constant -1 : index +! CHECK: %[[VAL_12:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_5:.*]] = fir.emboxproc %[[VAL_4]] : ((!fir.ref) -> !fir.box>>) -> !fir.boxproc<() -> ()> ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_12]] : (index) -> i64 ! CHECK: %[[VAL_7:.*]] = fir.undefined tuple ()>, i64> @@ -375,7 +375,7 @@ end subroutine ! CHECK-LABEL: fir.global internal @_QFsub1Ep7 : !fir.boxproc<(!fir.ref) -> !fir.box>>> { ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPchar_func) : (!fir.ref) -> !fir.box>> -! CHECK: %[[VAL_11:.*]] = arith.constant -1 : index +! CHECK: %[[VAL_11:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_1:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref) -> !fir.box>>) -> !fir.boxproc<() -> ()> ! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_11]] : (index) -> i64 ! CHECK: %[[VAL_3:.*]] = fir.undefined tuple ()>, i64> diff --git a/flang/test/Lower/dummy-procedure-character.f90 b/flang/test/Lower/dummy-procedure-character.f90 index 72d5485..9a2710f 100644 --- a/flang/test/Lower/dummy-procedure-character.f90 +++ b/flang/test/Lower/dummy-procedure-character.f90 @@ -82,7 +82,7 @@ subroutine cannot_compute_len_yet() end function end interface ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPbar4) : (!fir.ref>, index, !fir.ref) -> !fir.boxchar<1> -! CHECK: %[[VAL_1:.*]] = arith.constant -1 : index +! CHECK: %[[VAL_1:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_2:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref>, index, !fir.ref) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()> ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_1]] : (index) -> i64 ! CHECK: %[[VAL_4:.*]] = fir.undefined tuple ()>, i64> @@ -97,7 +97,7 @@ subroutine cannot_compute_len_yet_2() character(*) :: bar5 external :: bar5 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPbar5) : (!fir.ref>, index) -> !fir.boxchar<1> -! CHECK: %[[VAL_1:.*]] = arith.constant -1 : index +! CHECK: %[[VAL_1:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_2:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref>, index) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()> ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_1]] : (index) -> i64 ! CHECK: %[[VAL_4:.*]] = fir.undefined tuple ()>, i64> -- cgit v1.1 From c49c386caaf7132908995749fed4894cfa1b62d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Tue, 2 Jul 2024 08:48:23 +0200 Subject: [clang][Interp] Reject StmtExprs containing return statements --- clang/lib/AST/Interp/Compiler.cpp | 17 +++++++++++++++++ clang/lib/AST/Interp/Compiler.h | 4 ++++ clang/lib/AST/Interp/Interp.h | 7 +++++++ clang/lib/AST/Interp/Opcodes.td | 1 + clang/test/AST/Interp/literals.cpp | 10 ++++++++++ 5 files changed, 39 insertions(+) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 3d9c72e..739a650 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -154,6 +154,19 @@ private: CaseMap OldCaseLabels; }; +template class StmtExprScope final { +public: + StmtExprScope(Compiler *Ctx) : Ctx(Ctx), OldFlag(Ctx->InStmtExpr) { + Ctx->InStmtExpr = true; + } + + ~StmtExprScope() { Ctx->InStmtExpr = OldFlag; } + +private: + Compiler *Ctx; + bool OldFlag; +}; + } // namespace interp } // namespace clang @@ -3028,6 +3041,7 @@ bool Compiler::VisitCXXStdInitializerListExpr( template bool Compiler::VisitStmtExpr(const StmtExpr *E) { BlockScope BS(this); + StmtExprScope SS(this); const CompoundStmt *CS = E->getSubStmt(); const Stmt *Result = CS->getStmtExprResult(); @@ -4056,6 +4070,9 @@ bool Compiler::visitDeclStmt(const DeclStmt *DS) { template bool Compiler::visitReturnStmt(const ReturnStmt *RS) { + if (this->InStmtExpr) + return this->emitUnsupported(RS); + if (const Expr *RE = RS->getRetValue()) { ExprScope RetScope(this); if (ReturnType) { diff --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h index 67bd7ef..d28526c 100644 --- a/clang/lib/AST/Interp/Compiler.h +++ b/clang/lib/AST/Interp/Compiler.h @@ -39,6 +39,7 @@ template class SourceLocScope; template class LoopScope; template class LabelScope; template class SwitchScope; +template class StmtExprScope; template class Compiler; struct InitLink { @@ -334,6 +335,7 @@ private: friend class LoopScope; friend class LabelScope; friend class SwitchScope; + friend class StmtExprScope; /// Emits a zero initializer. bool visitZeroInitializer(PrimType T, QualType QT, const Expr *E); @@ -398,6 +400,8 @@ protected: /// Flag indicating if return value is to be discarded. bool DiscardResult = false; + bool InStmtExpr = false; + /// Flag inidicating if we're initializing an already created /// variable. This is set in visitInitializer(). bool Initializing = false; diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index ff6d50a..328db21 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -2618,6 +2618,13 @@ inline bool Invalid(InterpState &S, CodePtr OpPC) { return false; } +inline bool Unsupported(InterpState &S, CodePtr OpPC) { + const SourceLocation &Loc = S.Current->getLocation(OpPC); + S.FFDiag(Loc, diag::note_constexpr_stmt_expr_unsupported) + << S.Current->getRange(OpPC); + return false; +} + /// Do nothing and just abort execution. inline bool Error(InterpState &S, CodePtr OpPC) { return false; } diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td index 81e7b81..8d01fe1 100644 --- a/clang/lib/AST/Interp/Opcodes.td +++ b/clang/lib/AST/Interp/Opcodes.td @@ -714,6 +714,7 @@ def Dup : Opcode { // [] -> [] def Invalid : Opcode {} +def Unsupported : Opcode {} def Error : Opcode {} def InvalidCast : Opcode { let Args = [ArgCastKind]; diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp index 3abaf89..f70ca79e 100644 --- a/clang/test/AST/Interp/literals.cpp +++ b/clang/test/AST/Interp/literals.cpp @@ -1255,4 +1255,14 @@ constexpr int StmtExprEval() { return 1; } static_assert(StmtExprEval() == 2, ""); + +constexpr int ReturnInStmtExpr() { // both-error {{never produces a constant expression}} + return ({ + return 1; // both-note 2{{this use of statement expressions is not supported in a constant expression}} + 2; + }); +} +static_assert(ReturnInStmtExpr() == 1, ""); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} + #endif -- cgit v1.1 From a616f57c1f5f64ee6013c01b6cfe8c587b4cd1f8 Mon Sep 17 00:00:00 2001 From: Poseydon42 Date: Tue, 2 Jul 2024 11:18:52 +0100 Subject: [CorrelatedValuePropagation] Fold calls to UCMP/SCMP when we know that ranges of operands do not overlap (#97235) This patch adds folds for calls to `ucmp`/`scmp` intrinsics where we can establish that the range of the first operand is strictly to the left or strictly to the right of the range of the second operand. --- .../Scalar/CorrelatedValuePropagation.cpp | 35 +++ .../Transforms/CorrelatedValuePropagation/uscmp.ll | 258 +++++++++++++++++++++ 2 files changed, 293 insertions(+) create mode 100644 llvm/test/Transforms/CorrelatedValuePropagation/uscmp.ll diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 88adeb5..875d3ea 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -85,6 +85,7 @@ STATISTIC(NumOverflows, "Number of overflow checks removed"); STATISTIC(NumSaturating, "Number of saturating arithmetics converted to normal arithmetics"); STATISTIC(NumNonNull, "Number of function pointer arguments marked non-null"); +STATISTIC(NumCmpIntr, "Number of llvm.[us]cmp intrinsics removed"); STATISTIC(NumMinMax, "Number of llvm.[us]{min,max} intrinsics removed"); STATISTIC(NumSMinMax, "Number of llvm.s{min,max} intrinsics simplified to unsigned"); @@ -548,6 +549,35 @@ static bool processAbsIntrinsic(IntrinsicInst *II, LazyValueInfo *LVI) { return false; } +static bool processCmpIntrinsic(IntrinsicInst *II, LazyValueInfo *LVI) { + bool IsSigned = II->getIntrinsicID() == Intrinsic::scmp; + ConstantRange LHS_CR = LVI->getConstantRangeAtUse(II->getOperandUse(0), + /*UndefAllowed*/ false); + ConstantRange RHS_CR = LVI->getConstantRangeAtUse(II->getOperandUse(1), + /*UndefAllowed*/ false); + + if (LHS_CR.icmp(IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT, RHS_CR)) { + ++NumCmpIntr; + II->replaceAllUsesWith(ConstantInt::get(II->getType(), 1)); + II->eraseFromParent(); + return true; + } + if (LHS_CR.icmp(IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, RHS_CR)) { + ++NumCmpIntr; + II->replaceAllUsesWith(ConstantInt::getSigned(II->getType(), -1)); + II->eraseFromParent(); + return true; + } + if (LHS_CR.icmp(ICmpInst::ICMP_EQ, RHS_CR)) { + ++NumCmpIntr; + II->replaceAllUsesWith(ConstantInt::get(II->getType(), 0)); + II->eraseFromParent(); + return true; + } + + return false; +} + // See if this min/max intrinsic always picks it's one specific operand. // If not, check whether we can canonicalize signed minmax into unsigned version static bool processMinMaxIntrinsic(MinMaxIntrinsic *MM, LazyValueInfo *LVI) { @@ -639,6 +669,11 @@ static bool processCallSite(CallBase &CB, LazyValueInfo *LVI) { return processAbsIntrinsic(&cast(CB), LVI); } + if (CB.getIntrinsicID() == Intrinsic::scmp || + CB.getIntrinsicID() == Intrinsic::ucmp) { + return processCmpIntrinsic(&cast(CB), LVI); + } + if (auto *MM = dyn_cast(&CB)) { return processMinMaxIntrinsic(MM, LVI); } diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/uscmp.ll b/llvm/test/Transforms/CorrelatedValuePropagation/uscmp.ll new file mode 100644 index 0000000..efe4235 --- /dev/null +++ b/llvm/test/Transforms/CorrelatedValuePropagation/uscmp.ll @@ -0,0 +1,258 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s + +; If nothing is known we can't change anything +define i8 @ucmp_0(i32 %x, i32 %y) { +; CHECK-LABEL: @ucmp_0( +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[X:%.*]], i32 [[Y:%.*]]) +; CHECK-NEXT: ret i8 [[TMP1]] +; + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %1 +} + +define i8 @scmp_0(i32 %x, i32 %y) { +; CHECK-LABEL: @scmp_0( +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[X:%.*]], i32 [[Y:%.*]]) +; CHECK-NEXT: ret i8 [[TMP1]] +; + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %1 +} + +; If we know that range of LHS < range of RHS then return -1 +define i8 @ucmp_1(i32 %x, i32 %y) { + ; X is within [4, 8) +; CHECK-LABEL: @ucmp_1( +; CHECK-NEXT: [[COND1:%.*]] = icmp uge i32 [[X:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp ult i32 [[X]], 8 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: [[COND3:%.*]] = icmp uge i32 [[Y:%.*]], 8 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND3]]) +; CHECK-NEXT: ret i8 -1 +; + %cond1 = icmp uge i32 %x, 4 + call void @llvm.assume(i1 %cond1) + %cond2 = icmp ult i32 %x, 8 + call void @llvm.assume(i1 %cond2) + ; Y is within [8, UNSIGNED_MAX) + %cond3 = icmp uge i32 %y, 8 + call void @llvm.assume(i1 %cond3) + + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %1 +} + +define i8 @scmp_1(i32 %x, i32 %y) { + ; X is within [-5, 3) +; CHECK-LABEL: @scmp_1( +; CHECK-NEXT: [[COND1:%.*]] = icmp sge i32 [[X:%.*]], -5 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp slt i32 [[X]], 3 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: [[COND3:%.*]] = icmp sge i32 [[Y:%.*]], 3 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND3]]) +; CHECK-NEXT: ret i8 -1 +; + %cond1 = icmp sge i32 %x, -5 + call void @llvm.assume(i1 %cond1) + %cond2 = icmp slt i32 %x, 3 + call void @llvm.assume(i1 %cond2) + ; Y is within [3, SIGNED_MAX) + %cond3 = icmp sge i32 %y, 3 + call void @llvm.assume(i1 %cond3) + + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %1 +} + +; If we know that range of LHS > range of RHS then return 1 +define i8 @ucmp_2(i32 %x, i32 %y) { + ; X is within [4, UNSIGNED_MAX) +; CHECK-LABEL: @ucmp_2( +; CHECK-NEXT: [[COND1:%.*]] = icmp uge i32 [[X:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp ult i32 [[Y:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: ret i8 1 +; + %cond1 = icmp uge i32 %x, 4 + call void @llvm.assume(i1 %cond1) + ; Y is within [0, 4) + %cond2 = icmp ult i32 %y, 4 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %1 +} + +define i8 @scmp_2(i32 %x, i32 %y) { + ; X is within [4, SIGNED_MAX) +; CHECK-LABEL: @scmp_2( +; CHECK-NEXT: [[COND1:%.*]] = icmp sge i32 [[X:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp slt i32 [[Y:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: ret i8 1 +; + %cond1 = icmp sge i32 %x, 4 + call void @llvm.assume(i1 %cond1) + ; Y is within [SIGNED_MIN, 4) + %cond2 = icmp slt i32 %y, 4 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %1 +} + +; If we know that LHS and RHS are both constants then return 0 +define i8 @ucmp_5(i32 %x, i32 %y) { +; CHECK-LABEL: @ucmp_5( +; CHECK-NEXT: [[COND1:%.*]] = icmp eq i32 [[X:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp eq i32 [[Y:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: ret i8 0 +; + %cond1 = icmp eq i32 %x, 4 + call void @llvm.assume(i1 %cond1) + %cond2 = icmp eq i32 %y, 4 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %1 +} + +define i8 @scmp_5(i32 %x, i32 %y) { +; CHECK-LABEL: @scmp_5( +; CHECK-NEXT: [[COND1:%.*]] = icmp eq i32 [[X:%.*]], -5 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp eq i32 [[Y:%.*]], -5 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: ret i8 0 +; + %cond1 = icmp eq i32 %x, -5 + call void @llvm.assume(i1 %cond1) + %cond2 = icmp eq i32 %y, -5 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %1 +} + +; We can infer ranges based on the location where a UCMP/SCMP result is used +define i8 @scmp_6(i32 noundef %x) { +; CHECK-LABEL: @scmp_6( +; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 10 +; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i8 -1, i8 5 +; CHECK-NEXT: ret i8 [[TMP2]] +; + %1 = icmp slt i32 %x, 10 + %2 = call i8 @llvm.scmp(i32 %x, i32 10) + %3 = select i1 %1, i8 %2, i8 5 + ret i8 %3 +} + +; Negative test: ranges overlap +define i8 @ucmp_3(i32 %x, i32 %y) { + ; X is within [4, UNSIGNED_MAX) +; CHECK-LABEL: @ucmp_3( +; CHECK-NEXT: [[COND1:%.*]] = icmp uge i32 [[X:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp ult i32 [[Y:%.*]], 6 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: ret i8 [[TMP1]] +; + %cond1 = icmp uge i32 %x, 4 + call void @llvm.assume(i1 %cond1) + ; Y is within [0, 6) + %cond2 = icmp ult i32 %y, 6 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %1 +} + +define i8 @scmp_3(i32 %x, i32 %y) { + ; X is within [2, SIGNED_MAX) +; CHECK-LABEL: @scmp_3( +; CHECK-NEXT: [[COND1:%.*]] = icmp sge i32 [[X:%.*]], 2 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp slt i32 [[Y:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: ret i8 [[TMP1]] +; + %cond1 = icmp sge i32 %x, 2 + call void @llvm.assume(i1 %cond1) + ; Y is within [SIGNED_MIN, 4) + %cond2 = icmp slt i32 %y, 4 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %1 +} + +; Negative test: mismatched signedness of range-establishing comparisons and +; of the intrinsic +define i8 @ucmp_4(i32 %x, i32 %y) { + ; X is within [4, SIGNED_MAX) +; CHECK-LABEL: @ucmp_4( +; CHECK-NEXT: [[COND1:%.*]] = icmp sge i32 [[X:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp slt i32 [[Y:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: ret i8 [[TMP1]] +; + %cond1 = icmp sge i32 %x, 4 + call void @llvm.assume(i1 %cond1) + ; Y is within [0, 4) + %cond2 = icmp slt i32 %y, 4 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %1 +} + +define i8 @scmp_4(i32 %x, i32 %y) { + ; X is within [4, UNSIGNED_MAX) +; CHECK-LABEL: @scmp_4( +; CHECK-NEXT: [[COND1:%.*]] = icmp uge i32 [[X:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp ult i32 [[Y:%.*]], 4 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: ret i8 [[TMP1]] +; + %cond1 = icmp uge i32 %x, 4 + call void @llvm.assume(i1 %cond1) + ; Y is within [0, 4) + %cond2 = icmp ult i32 %y, 4 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.scmp(i32 %x, i32 %y) + ret i8 %1 +} + +; Negative test: ranges are the same, but we can't be sure the values are equal +define i8 @ucmp_6(i32 %x, i32 %y) { + ; Both X and Y are within [0, 10] +; CHECK-LABEL: @ucmp_6( +; CHECK-NEXT: [[COND1:%.*]] = icmp ule i32 [[X:%.*]], 10 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND1]]) +; CHECK-NEXT: [[COND2:%.*]] = icmp ule i32 [[Y:%.*]], 10 +; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]]) +; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[X]], i32 [[Y]]) +; CHECK-NEXT: ret i8 [[TMP1]] +; + %cond1 = icmp ule i32 %x, 10 + call void @llvm.assume(i1 %cond1) + %cond2 = icmp ule i32 %y, 10 + call void @llvm.assume(i1 %cond2) + + %1 = call i8 @llvm.ucmp(i32 %x, i32 %y) + ret i8 %1 +} -- cgit v1.1 From 253a76261901d966cc803077294bf3fc9ef9ea18 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 2 Jul 2024 12:26:11 +0200 Subject: AMDGPU: Consolidiate f16 med3 patterns (#97399) --- llvm/lib/Target/AMDGPU/AMDGPU.td | 1 + llvm/lib/Target/AMDGPU/SIInstructions.td | 15 ++++----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td index 63d8334..2f3890e 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPU.td +++ b/llvm/lib/Target/AMDGPU/AMDGPU.td @@ -2013,6 +2013,7 @@ def HasVOP3PInsts : Predicate<"Subtarget->hasVOP3PInsts()">, AssemblerPredicate<(all_of FeatureVOP3P)>; def NotHasMed3_16 : Predicate<"!Subtarget->hasMed3_16()">; +def HasMed3_16 : Predicate<"Subtarget->hasMed3_16()">; def HasMinMaxDenormModes : Predicate<"Subtarget->supportsMinMaxDenormModes()">; def NotHasMinMaxDenormModes : Predicate<"!Subtarget->supportsMinMaxDenormModes()">; diff --git a/llvm/lib/Target/AMDGPU/SIInstructions.td b/llvm/lib/Target/AMDGPU/SIInstructions.td index 835f44f..77b17a0 100644 --- a/llvm/lib/Target/AMDGPU/SIInstructions.td +++ b/llvm/lib/Target/AMDGPU/SIInstructions.td @@ -3534,16 +3534,6 @@ multiclass FPMed3Pat; } -class FP16Med3Pat : GCNPat< - (fmaxnum_like_nnan (fminnum_like (VOP3Mods vt:$src0, i32:$src0_mods), - (VOP3Mods vt:$src1, i32:$src1_mods)), - (fminnum_like (fmaxnum_like (VOP3Mods vt:$src0, i32:$src0_mods), - (VOP3Mods vt:$src1, i32:$src1_mods)), - (vt (VOP3Mods vt:$src2, i32:$src2_mods)))), - (med3Inst $src0_mods, $src0, $src1_mods, $src1, $src2_mods, $src2, DSTCLAMP.NONE) ->; - multiclass Int16Med3Pat { @@ -3566,6 +3556,10 @@ multiclass Int16Med3Pat; +let SubtargetPredicate = HasMed3_16 in { +defm : FPMed3Pat; +} + class IntMinMaxPat : AMDGPUPat < @@ -3611,7 +3605,6 @@ def : FPMinCanonMaxPat } let OtherPredicates = [isGFX9Plus] in { -def : FP16Med3Pat; defm : Int16Med3Pat; defm : Int16Med3Pat; } // End Predicates = [isGFX9Plus] -- cgit v1.1 From 9a9546e30cbce764fb96de1ae0b4f8f01f6d223f Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 2 Jul 2024 13:29:31 +0300 Subject: [clang-repl] Support wasm execution (#86402) This commit introduces support for running clang-repl and executing C++ code interactively inside a Javascript engine using WebAssembly when built with Emscripten. This is achieved by producing WASM "shared libraries" that can be loaded by the Emscripten runtime using dlopen() More discussion is available in https://reviews.llvm.org/D158140 Co-authored-by: Anubhab Ghosh --- clang/lib/Interpreter/CMakeLists.txt | 6 ++ clang/lib/Interpreter/IncrementalExecutor.cpp | 2 + clang/lib/Interpreter/IncrementalExecutor.h | 11 ++- clang/lib/Interpreter/Interpreter.cpp | 13 +++ clang/lib/Interpreter/Wasm.cpp | 114 ++++++++++++++++++++++++++ clang/lib/Interpreter/Wasm.h | 37 +++++++++ 6 files changed, 179 insertions(+), 4 deletions(-) create mode 100644 clang/lib/Interpreter/Wasm.cpp create mode 100644 clang/lib/Interpreter/Wasm.h diff --git a/clang/lib/Interpreter/CMakeLists.txt b/clang/lib/Interpreter/CMakeLists.txt index 9065f99..6a06965 100644 --- a/clang/lib/Interpreter/CMakeLists.txt +++ b/clang/lib/Interpreter/CMakeLists.txt @@ -12,6 +12,10 @@ set(LLVM_LINK_COMPONENTS TargetParser ) +if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS) + set(WASM_SRC Wasm.cpp) +endif() + add_clang_library(clangInterpreter DeviceOffload.cpp CodeCompletion.cpp @@ -20,6 +24,8 @@ add_clang_library(clangInterpreter Interpreter.cpp InterpreterUtils.cpp Value.cpp + ${WASM_SRC} + PARTIAL_SOURCES_INTENDED DEPENDS intrinsics_gen diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 6f03610..1824a5b 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -36,6 +36,8 @@ LLVM_ATTRIBUTE_USED void linkComponents() { } namespace clang { +IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC) + : TSCtx(TSC) {} llvm::Expected> IncrementalExecutor::createDefaultJITBuilder( diff --git a/clang/lib/Interpreter/IncrementalExecutor.h b/clang/lib/Interpreter/IncrementalExecutor.h index b434720..7954cde 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.h +++ b/clang/lib/Interpreter/IncrementalExecutor.h @@ -43,16 +43,19 @@ class IncrementalExecutor { llvm::DenseMap ResourceTrackers; +protected: + IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC); + public: enum SymbolNameKind { IRName, LinkerName }; IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC, llvm::orc::LLJITBuilder &JITBuilder, llvm::Error &Err); - ~IncrementalExecutor(); + virtual ~IncrementalExecutor(); - llvm::Error addModule(PartialTranslationUnit &PTU); - llvm::Error removeModule(PartialTranslationUnit &PTU); - llvm::Error runCtors() const; + virtual llvm::Error addModule(PartialTranslationUnit &PTU); + virtual llvm::Error removeModule(PartialTranslationUnit &PTU); + virtual llvm::Error runCtors() const; llvm::Error cleanUp(); llvm::Expected getSymbolAddress(llvm::StringRef Name, SymbolNameKind NameKind) const; diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 7a95278..49dc92d 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -15,6 +15,9 @@ #include "IncrementalExecutor.h" #include "IncrementalParser.h" #include "InterpreterUtils.h" +#ifdef __EMSCRIPTEN__ +#include "Wasm.h" +#endif // __EMSCRIPTEN__ #include "clang/AST/ASTContext.h" #include "clang/AST/Mangle.h" @@ -186,6 +189,12 @@ IncrementalCompilerBuilder::CreateCpp() { std::vector Argv; Argv.reserve(5 + 1 + UserArgs.size()); Argv.push_back("-xc++"); +#ifdef __EMSCRIPTEN__ + Argv.push_back("-target"); + Argv.push_back("wasm32-unknown-emscripten"); + Argv.push_back("-pie"); + Argv.push_back("-shared"); +#endif Argv.insert(Argv.end(), UserArgs.begin(), UserArgs.end()); std::string TT = TargetTriple ? *TargetTriple : llvm::sys::getProcessTriple(); @@ -426,8 +435,12 @@ llvm::Error Interpreter::CreateExecutor() { } llvm::Error Err = llvm::Error::success(); +#ifdef __EMSCRIPTEN__ + auto Executor = std::make_unique(*TSCtx); +#else auto Executor = std::make_unique(*TSCtx, *JITBuilder, Err); +#endif if (!Err) IncrExecutor = std::move(Executor); diff --git a/clang/lib/Interpreter/Wasm.cpp b/clang/lib/Interpreter/Wasm.cpp new file mode 100644 index 0000000..1001410 --- /dev/null +++ b/clang/lib/Interpreter/Wasm.cpp @@ -0,0 +1,114 @@ +//===----------------- Wasm.cpp - Wasm Interpreter --------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements interpreter support for code execution in WebAssembly. +// +//===----------------------------------------------------------------------===// + +#include "Wasm.h" +#include "IncrementalExecutor.h" + +#include +#include +#include +#include + +#include + +#include + +namespace lld { +namespace wasm { +bool link(llvm::ArrayRef args, llvm::raw_ostream &stdoutOS, + llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput); +} // namespace wasm +} // namespace lld + +#include + +namespace clang { + +WasmIncrementalExecutor::WasmIncrementalExecutor( + llvm::orc::ThreadSafeContext &TSC) + : IncrementalExecutor(TSC) {} + +llvm::Error WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) { + std::string ErrorString; + + const llvm::Target *Target = llvm::TargetRegistry::lookupTarget( + PTU.TheModule->getTargetTriple(), ErrorString); + if (!Target) { + return llvm::make_error("Failed to create Wasm Target: ", + llvm::inconvertibleErrorCode()); + } + + llvm::TargetOptions TO = llvm::TargetOptions(); + llvm::TargetMachine *TargetMachine = Target->createTargetMachine( + PTU.TheModule->getTargetTriple(), "", "", TO, llvm::Reloc::Model::PIC_); + PTU.TheModule->setDataLayout(TargetMachine->createDataLayout()); + std::string OutputFileName = PTU.TheModule->getName().str() + ".wasm"; + + std::error_code Error; + llvm::raw_fd_ostream OutputFile(llvm::StringRef(OutputFileName), Error); + + llvm::legacy::PassManager PM; + if (TargetMachine->addPassesToEmitFile(PM, OutputFile, nullptr, + llvm::CodeGenFileType::ObjectFile)) { + return llvm::make_error( + "Wasm backend cannot produce object.", llvm::inconvertibleErrorCode()); + } + + if (!PM.run(*PTU.TheModule)) { + + return llvm::make_error("Failed to emit Wasm object.", + llvm::inconvertibleErrorCode()); + } + + OutputFile.close(); + + std::vector LinkerArgs = {"wasm-ld", + "-pie", + "--import-memory", + "--no-entry", + "--export-all", + "--experimental-pic", + "--no-export-dynamic", + "--stack-first", + OutputFileName.c_str(), + "-o", + OutputFileName.c_str()}; + int Result = + lld::wasm::link(LinkerArgs, llvm::outs(), llvm::errs(), false, false); + if (!Result) + return llvm::make_error( + "Failed to link incremental module", llvm::inconvertibleErrorCode()); + + void *LoadedLibModule = + dlopen(OutputFileName.c_str(), RTLD_NOW | RTLD_GLOBAL); + if (LoadedLibModule == nullptr) { + llvm::errs() << dlerror() << '\n'; + return llvm::make_error( + "Failed to load incremental module", llvm::inconvertibleErrorCode()); + } + + return llvm::Error::success(); +} + +llvm::Error WasmIncrementalExecutor::removeModule(PartialTranslationUnit &PTU) { + return llvm::make_error("Not implemented yet", + llvm::inconvertibleErrorCode()); +} + +llvm::Error WasmIncrementalExecutor::runCtors() const { + // This seems to be automatically done when using dlopen() + return llvm::Error::success(); +} + +WasmIncrementalExecutor::~WasmIncrementalExecutor() = default; + +} // namespace clang diff --git a/clang/lib/Interpreter/Wasm.h b/clang/lib/Interpreter/Wasm.h new file mode 100644 index 0000000..b1fd880 --- /dev/null +++ b/clang/lib/Interpreter/Wasm.h @@ -0,0 +1,37 @@ +//===------------------ Wasm.h - Wasm Interpreter ---------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements interpreter support for code execution in WebAssembly. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_INTERPRETER_WASM_H +#define LLVM_CLANG_LIB_INTERPRETER_WASM_H + +#ifndef __EMSCRIPTEN__ +#error "This requires emscripten." +#endif // __EMSCRIPTEN__ + +#include "IncrementalExecutor.h" + +namespace clang { + +class WasmIncrementalExecutor : public IncrementalExecutor { +public: + WasmIncrementalExecutor(llvm::orc::ThreadSafeContext &TSC); + + llvm::Error addModule(PartialTranslationUnit &PTU) override; + llvm::Error removeModule(PartialTranslationUnit &PTU) override; + llvm::Error runCtors() const override; + + ~WasmIncrementalExecutor() override; +}; + +} // namespace clang + +#endif // LLVM_CLANG_LIB_INTERPRETER_WASM_H -- cgit v1.1 From b7e157cab173e56c68872cc84522c24b8d6ee635 Mon Sep 17 00:00:00 2001 From: Ilia Sergachev <1894984+sergachev@users.noreply.github.com> Date: Tue, 2 Jul 2024 12:30:21 +0200 Subject: [Transforms][NFC] Tiny fixes in SplitModule (#95903) Fix repeated map lookup, variable name, formatting and a missing space. --- llvm/lib/Transforms/Utils/SplitModule.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp index 9c39c26d..55db373 100644 --- a/llvm/lib/Transforms/Utils/SplitModule.cpp +++ b/llvm/lib/Transforms/Utils/SplitModule.cpp @@ -105,7 +105,8 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap, // At this point module should have the proper mix of globals and locals. // As we attempt to partition this module, we must not change any // locals to globals. - LLVM_DEBUG(dbgs() << "Partition module with (" << M.size() << ")functions\n"); + LLVM_DEBUG(dbgs() << "Partition module with (" << M.size() + << ") functions\n"); ClusterMapType GVtoClusterMap; ComdatMembersType ComdatMembers; @@ -164,10 +165,10 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap, std::priority_queue, std::vector>, decltype(CompareClusters)> - BalancinQueue(CompareClusters); + BalancingQueue(CompareClusters); // Pre-populate priority queue with N slot blanks. for (unsigned i = 0; i < N; ++i) - BalancinQueue.push(std::make_pair(i, 0)); + BalancingQueue.push(std::make_pair(i, 0)); using SortType = std::pair; @@ -177,11 +178,13 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap, // To guarantee determinism, we have to sort SCC according to size. // When size is the same, use leader's name. for (ClusterMapType::iterator I = GVtoClusterMap.begin(), - E = GVtoClusterMap.end(); I != E; ++I) + E = GVtoClusterMap.end(); + I != E; ++I) if (I->isLeader()) Sets.push_back( std::make_pair(std::distance(GVtoClusterMap.member_begin(I), - GVtoClusterMap.member_end()), I)); + GVtoClusterMap.member_end()), + I)); llvm::sort(Sets, [](const SortType &a, const SortType &b) { if (a.first == b.first) @@ -191,9 +194,9 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap, }); for (auto &I : Sets) { - unsigned CurrentClusterID = BalancinQueue.top().first; - unsigned CurrentClusterSize = BalancinQueue.top().second; - BalancinQueue.pop(); + unsigned CurrentClusterID = BalancingQueue.top().first; + unsigned CurrentClusterSize = BalancingQueue.top().second; + BalancingQueue.pop(); LLVM_DEBUG(dbgs() << "Root[" << CurrentClusterID << "] cluster_size(" << I.first << ") ----> " << I.second->getData()->getName() @@ -211,7 +214,7 @@ static void findPartitions(Module &M, ClusterIDMapType &ClusterIDMap, CurrentClusterSize++; } // Add this set size to the number of entries in this cluster. - BalancinQueue.push(std::make_pair(CurrentClusterID, CurrentClusterSize)); + BalancingQueue.push(std::make_pair(CurrentClusterID, CurrentClusterSize)); } } @@ -275,8 +278,8 @@ void llvm::SplitModule( ValueToValueMapTy VMap; std::unique_ptr MPart( CloneModule(M, VMap, [&](const GlobalValue *GV) { - if (ClusterIDMap.count(GV)) - return (ClusterIDMap[GV] == I); + if (auto It = ClusterIDMap.find(GV); It != ClusterIDMap.end()) + return It->second == I; else return isInPartition(GV, I, N); })); -- cgit v1.1 From 6ad82fcc7d418e6e4cac9e0f82a35d8021f61ffa Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Tue, 2 Jul 2024 11:53:15 +0100 Subject: [FileCheck][Docs] Fix regex for FileCheck variable names (#97301) This fixes a minor oversight in the FileCheck documentation on what is considered a valid variable name. Global variables are prefixed with a `$`, which is explained two paragraphs below, but this was omitted in the presented regex in this paragraph. --- llvm/docs/CommandGuide/FileCheck.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/docs/CommandGuide/FileCheck.rst b/llvm/docs/CommandGuide/FileCheck.rst index 432dafa..af49304 100644 --- a/llvm/docs/CommandGuide/FileCheck.rst +++ b/llvm/docs/CommandGuide/FileCheck.rst @@ -731,7 +731,7 @@ The first check line matches a regex ``%[a-z]+`` and captures it into the string variable ``REGISTER``. The second line verifies that whatever is in ``REGISTER`` occurs later in the file after an "``andw``". :program:`FileCheck` string substitution blocks are always contained in ``[[ ]]`` pairs, and string -variable names can be formed with the regex ``[a-zA-Z_][a-zA-Z0-9_]*``. If a +variable names can be formed with the regex ``\$[a-zA-Z_][a-zA-Z0-9_]*``. If a colon follows the name, then it is a definition of the variable; otherwise, it is a substitution. -- cgit v1.1 From b67d557bd3627a428d5041edec129587d6d3972c Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 2 Jul 2024 06:58:41 -0400 Subject: [C2y] Add -std=c2y and -std=gnu2y This adds a language standard mode for the latest C standard. While WG14 is hoping for a three-year cycle, it is not clear that the next revision of C will be in 2026 and so a flag was not created for c26 specifically. --- clang/docs/ReleaseNotes.rst | 6 ++++++ clang/docs/UsersManual.rst | 10 +++++++--- clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Basic/LangStandard.h | 28 ++++++++++++++++------------ clang/include/clang/Basic/LangStandards.def | 9 +++++++++ clang/lib/Basic/LangOptions.cpp | 1 + clang/lib/Frontend/InitPreprocessor.cpp | 4 +++- clang/test/Driver/unknown-std.c | 2 ++ clang/www/c_status.html | 5 ++--- 9 files changed, 47 insertions(+), 19 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index fd8d9ad..e4707bf 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -320,6 +320,12 @@ Resolutions to C++ Defect Reports C Language Changes ------------------ +C2y Feature Support +^^^^^^^^^^^^^^^^^^^ +- Clang now enables C2y mode with ``-std=c2y``. This sets ``__STDC_VERSION__`` + to ``202400L`` so that it's greater than the value for C23. The value of this + macro is subject to change in the future. + C23 Feature Support ^^^^^^^^^^^^^^^^^^^ - No longer diagnose use of binary literals as an extension in C23 mode. Fixes diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index d273102..087c75b 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -3458,9 +3458,9 @@ Differences between various standard modes clang supports the -std option, which changes what language mode clang uses. The supported modes for C are c89, gnu89, c94, c99, gnu99, c11, gnu11, c17, -gnu17, c23, gnu23, and various aliases for those modes. If no -std option is -specified, clang defaults to gnu17 mode. Many C99 and C11 features are -supported in earlier modes as a conforming extension, with a warning. Use +gnu17, c23, gnu23, c2y, gnu2y, and various aliases for those modes. If no -std +option is specified, clang defaults to gnu17 mode. Many C99 and C11 features +are supported in earlier modes as a conforming extension, with a warning. Use ``-pedantic-errors`` to request an error if a feature from a later standard revision is used in an earlier mode. @@ -3523,6 +3523,10 @@ Differences between ``*17`` and ``*23`` modes: - ``[[]]`` attributes are supported by default in ``*23`` mode, and as an extension in ``*17`` and earlier modes. +Differences between ``*23`` and ``*2y`` modes: + +- ``__STDC_VERSION__`` is defined to ``202400L`` rather than ``202311L``. + GCC extensions not implemented yet ---------------------------------- diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 6dd6b56..491759e 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -87,6 +87,7 @@ LANGOPT(C99 , 1, 0, "C99") LANGOPT(C11 , 1, 0, "C11") LANGOPT(C17 , 1, 0, "C17") LANGOPT(C23 , 1, 0, "C23") +LANGOPT(C2y , 1, 0, "C2y") LANGOPT(MSVCCompat , 1, 0, "Microsoft Visual C++ full compatibility mode") LANGOPT(Kernel , 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") diff --git a/clang/include/clang/Basic/LangStandard.h b/clang/include/clang/Basic/LangStandard.h index 8e25afc..f79b4aa 100644 --- a/clang/include/clang/Basic/LangStandard.h +++ b/clang/include/clang/Basic/LangStandard.h @@ -52,18 +52,19 @@ enum LangFeatures { C11 = (1 << 2), C17 = (1 << 3), C23 = (1 << 4), - CPlusPlus = (1 << 5), - CPlusPlus11 = (1 << 6), - CPlusPlus14 = (1 << 7), - CPlusPlus17 = (1 << 8), - CPlusPlus20 = (1 << 9), - CPlusPlus23 = (1 << 10), - CPlusPlus26 = (1 << 11), - Digraphs = (1 << 12), - GNUMode = (1 << 13), - HexFloat = (1 << 14), - OpenCL = (1 << 15), - HLSL = (1 << 16) + C2y = (1 << 5), + CPlusPlus = (1 << 6), + CPlusPlus11 = (1 << 7), + CPlusPlus14 = (1 << 8), + CPlusPlus17 = (1 << 9), + CPlusPlus20 = (1 << 10), + CPlusPlus23 = (1 << 11), + CPlusPlus26 = (1 << 12), + Digraphs = (1 << 13), + GNUMode = (1 << 14), + HexFloat = (1 << 15), + OpenCL = (1 << 16), + HLSL = (1 << 17) }; /// LangStandard - Information about the properties of a particular language @@ -106,6 +107,9 @@ public: /// isC23 - Language is a superset of C23. bool isC23() const { return Flags & C23; } + /// isC2y - Language is a superset of C2y. + bool isC2y() const { return Flags & C2y; } + /// isCPlusPlus - Language is a C++ variant. bool isCPlusPlus() const { return Flags & CPlusPlus; } diff --git a/clang/include/clang/Basic/LangStandards.def b/clang/include/clang/Basic/LangStandards.def index b6192e4..f0c2593 100644 --- a/clang/include/clang/Basic/LangStandards.def +++ b/clang/include/clang/Basic/LangStandards.def @@ -99,6 +99,15 @@ LANGSTANDARD_ALIAS_DEPR(gnu23, "gnu2x") // FIXME: Add the alias for iso9899:202* once we know the year ISO publishes // the document (expected to be 2024). +// C2y modes +LANGSTANDARD(c2y, "c2y", + C, "Working Draft for ISO C2y", + LineComment | C99 | C11 | C17 | C23 | C2y | Digraphs | HexFloat) +LANGSTANDARD(gnu2y, "gnu2y", + C, "Working Draft for ISO C2y with GNU extensions", + LineComment | C99 | C11 | C17 | C23 | C2y | Digraphs | GNUMode | HexFloat) + + // C++ modes LANGSTANDARD(cxx98, "c++98", CXX, "ISO C++ 1998 with amendments", diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp index 2b90646..61072b7 100644 --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -112,6 +112,7 @@ void LangOptions::setLangDefaults(LangOptions &Opts, Language Lang, Opts.C11 = Std.isC11(); Opts.C17 = Std.isC17(); Opts.C23 = Std.isC23(); + Opts.C2y = Std.isC2y(); Opts.CPlusPlus = Std.isCPlusPlus(); Opts.CPlusPlus11 = Std.isCPlusPlus11(); Opts.CPlusPlus14 = Std.isCPlusPlus14(); diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 55ec460..5e52555 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -448,7 +448,9 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI, // value is, are implementation-defined. // (Removed in C++20.) if (!LangOpts.CPlusPlus) { - if (LangOpts.C23) + if (LangOpts.C2y) + Builder.defineMacro("__STDC_VERSION__", "202400L"); + else if (LangOpts.C23) Builder.defineMacro("__STDC_VERSION__", "202311L"); else if (LangOpts.C17) Builder.defineMacro("__STDC_VERSION__", "201710L"); diff --git a/clang/test/Driver/unknown-std.c b/clang/test/Driver/unknown-std.c index 564c633..8f9047b 100644 --- a/clang/test/Driver/unknown-std.c +++ b/clang/test/Driver/unknown-std.c @@ -18,6 +18,8 @@ // CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU extensions' standard // CHECK-NEXT: note: use 'c23' for 'Working Draft for ISO C23' standard // CHECK-NEXT: note: use 'gnu23' for 'Working Draft for ISO C23 with GNU extensions' standard +// CHECK-NEXT: note: use 'c2y' for 'Working Draft for ISO C2y' standard +// CHECK-NEXT: note: use 'gnu2y' for 'Working Draft for ISO C2y with GNU extensions' standard // Make sure that no other output is present. // CHECK-NOT: {{^.+$}} diff --git a/clang/www/c_status.html b/clang/www/c_status.html index 8e42b81..ccb39a1 100644 --- a/clang/www/c_status.html +++ b/clang/www/c_status.html @@ -71,7 +71,7 @@ C2y - (Flag currently unavailable) + -std=c2y Partial @@ -1229,8 +1229,7 @@ conforms by not defining the __STDC_IEC_559_COMPLEX__ macro.

Clang has support for some of the features of the C standard following C23, informally referred to as C2y.

-

Clang currently does not expose a language standard mode flag for C2y. -

+

You can use Clang in C2y mode with the -std=c2y option (available in Clang 19 and later).

List of features and minimum Clang version with support -- cgit v1.1 From 1f9bb8515569ab091bfb98704c5c21147deb61bd Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 2 Jul 2024 13:02:04 +0200 Subject: [bazel][clang] Exclude wasm interpreter These only work under emscripten. Introduced in 9a9546e30cbce764fb96de1ae0b4f8f01f6d223f. --- utils/bazel/llvm-project-overlay/clang/BUILD.bazel | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel index 725ac6b..caebcd0 100644 --- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel @@ -1869,11 +1869,19 @@ cc_library( cc_library( name = "interpreter", - srcs = glob([ - "lib/Interpreter/*.cpp", - "lib/Interpreter/*.h", - ]), - hdrs = glob(["include/clang/Interpreter/*.h"]), + srcs = glob( + [ + "lib/Interpreter/*.cpp", + "lib/Interpreter/*.h", + ], + exclude = ["lib/Interpreter/Wasm.cpp"], + ), + hdrs = glob( + [ + "include/clang/Interpreter/*.h", + ], + exclude = ["lib/Interpreter/Wasm.cpp"], + ), includes = ["include"], deps = [ ":analysis", -- cgit v1.1 From c5f7f380314c7d290e039e9c35562e1cedc01268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Tue, 2 Jul 2024 08:50:36 +0200 Subject: [clang][Interp][NFC] Make some local pointers const --- clang/lib/AST/Interp/Compiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 739a650..9ca71e0 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -4033,7 +4033,7 @@ template bool Compiler::visitLoopBody(const Stmt *S) { return true; if (const auto *CS = dyn_cast(S)) { - for (auto *InnerStmt : CS->body()) + for (const auto *InnerStmt : CS->body()) if (!visitStmt(InnerStmt)) return false; return true; @@ -4045,7 +4045,7 @@ template bool Compiler::visitLoopBody(const Stmt *S) { template bool Compiler::visitCompoundStmt(const CompoundStmt *S) { BlockScope Scope(this); - for (auto *InnerStmt : S->body()) + for (const auto *InnerStmt : S->body()) if (!visitStmt(InnerStmt)) return false; return true; -- cgit v1.1 From 0f387ec7d502e51fd5ac074f1f1037b44aa686fc Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 2 Jul 2024 07:24:18 -0400 Subject: Add missed test coverage This amends b67d557bd3627a428d5041edec129587d6d3972c to add the test coverage for those changes. --- clang/test/Preprocessor/c2y.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 clang/test/Preprocessor/c2y.c diff --git a/clang/test/Preprocessor/c2y.c b/clang/test/Preprocessor/c2y.c new file mode 100644 index 0000000..1d659d2 --- /dev/null +++ b/clang/test/Preprocessor/c2y.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c2y %s +// expected-no-diagnostics + +// FIXME: Set this to test the correct value once that value is set by WG14. +static_assert(__STDC_VERSION__ > 202311L, "Incorrect __STDC_VERSION__"); + -- cgit v1.1 From 7d0656d734bdc19f2478b394b15378a637cc43ee Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Tue, 2 Jul 2024 07:25:01 -0400 Subject: [C2y] Add test coverage for WG14 N3192 Clang has always supported sequential hexdigits. --- clang/test/C/C2y/n3192.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 clang/test/C/C2y/n3192.c diff --git a/clang/test/C/C2y/n3192.c b/clang/test/C/C2y/n3192.c new file mode 100644 index 0000000..b6f61d5 --- /dev/null +++ b/clang/test/C/C2y/n3192.c @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -verify -Wno-c23-extensions %s + +/* WG14 N3192: Yes + * Sequential hexdigits + */ + +// expected-no-diagnostics + +// Demonstrate that hex digits are already sequential in all targets Clang +// supports. + +#define TEST_VAL(ch) ((ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) +#define GET_VAL(ch) (((ch >= 'A' && ch <= 'F') ? (ch - 'A') : (ch - 'a')) + 10) + +_Static_assert(TEST_VAL('A')); +_Static_assert(TEST_VAL('B')); +_Static_assert(TEST_VAL('C')); +_Static_assert(TEST_VAL('D')); +_Static_assert(TEST_VAL('E')); +_Static_assert(TEST_VAL('F')); +_Static_assert(TEST_VAL('a')); +_Static_assert(TEST_VAL('b')); +_Static_assert(TEST_VAL('c')); +_Static_assert(TEST_VAL('d')); +_Static_assert(TEST_VAL('e')); +_Static_assert(TEST_VAL('f')); + +_Static_assert(!TEST_VAL('G')); +_Static_assert(!TEST_VAL('h')); + +_Static_assert(GET_VAL('A') == 0xA); +_Static_assert(GET_VAL('B') == 0xB); +_Static_assert(GET_VAL('C') == 0xC); +_Static_assert(GET_VAL('D') == 0xD); +_Static_assert(GET_VAL('E') == 0xE); +_Static_assert(GET_VAL('F') == 0xF); +_Static_assert(GET_VAL('a') == 0xA); +_Static_assert(GET_VAL('b') == 0xB); +_Static_assert(GET_VAL('c') == 0xC); +_Static_assert(GET_VAL('d') == 0xD); +_Static_assert(GET_VAL('e') == 0xE); +_Static_assert(GET_VAL('f') == 0xF); + -- cgit v1.1 From 3b639d7d1d9b9f352c57460deaf70aaad238f8d9 Mon Sep 17 00:00:00 2001 From: Younan Zhang Date: Tue, 2 Jul 2024 19:34:48 +0800 Subject: [Clang] Clarify diagnostic notes for implicitly generated deduction guides (#96084) Given the following invalid code, ```cpp template struct S { T *a; }; S s = {1}; ``` we produce such diagnostics currently: ``` :2:8: note: candidate template ignored: could not match 'S' against 'int' 2 | struct S { | ^ :2:8: note: candidate template ignored: could not match 'T *' against 'int' ``` Which I think is confusing because there's no `S` nor `T *` at the location it points to. This is because we're deducing the initializer against implicitly generated deduction guides, and their source locations just point to the corresponding `RecordDecl`. Hence the misleading notes. This patch alleviates the issue by adding extra notes demonstrating which implicit deduction guide we're deducing against. In other words, in addition to the note of `could not match 'T *' against 'int'`, we would also say the implicit deduction guide we're trying to use: `template S(T *) -> S`, which looks clearer IMO. --------- Co-authored-by: Sirraide --- clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/DiagnosticSemaKinds.td | 1 + clang/lib/Sema/SemaOverload.cpp | 52 ++++++++++++++++++++++ clang/test/CXX/drs/cwg26xx.cpp | 3 ++ .../test/CXX/expr/expr.post/expr.type.conv/p1.cpp | 2 +- .../over.match.class.deduct/p2.cpp | 5 ++- .../temp.deduct/temp.deduct.call/p3-0x.cpp | 12 ++--- clang/test/Modules/template_name_lookup.cpp | 2 + clang/test/PCH/cxx-explicit-specifier.cpp | 4 +- clang/test/Sema/tls_alignment.cpp | 4 +- .../cxx1z-class-template-argument-deduction.cpp | 12 +++-- clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 21 +++++++-- clang/test/SemaCXX/cxx2a-explicit-bool.cpp | 4 ++ clang/test/SemaCXX/gh65522.cpp | 6 ++- ...alid-deduction-guide-as-template-candidates.cpp | 4 +- .../SemaCXX/lookup-template-name-extern-CXX.cpp | 6 ++- .../SemaTemplate/aggregate-deduction-candidate.cpp | 24 +++++----- clang/test/SemaTemplate/class-template-id.cpp | 2 + clang/test/SemaTemplate/ctad.cpp | 12 +++-- clang/test/SemaTemplate/deduction-crash.cpp | 3 +- clang/test/SemaTemplate/deduction-guide.cpp | 12 +++-- .../nested-implicit-deduction-guides.cpp | 3 ++ clang/test/SemaTemplate/temp_arg.cpp | 4 +- 23 files changed, 156 insertions(+), 44 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e4707bf..9741730 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -651,6 +651,8 @@ Improvements to Clang's diagnostics that will be destroyed at the end of the full expression. Fixes #GH54492. +- Clang now shows implicit deduction guides when diagnosing overload resolution failure. #GH92393. + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 64f7935d..c852f18 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -2419,6 +2419,7 @@ def err_selected_explicit_constructor : Error< "chosen constructor is explicit in copy-initialization">; def note_explicit_ctor_deduction_guide_here : Note< "explicit %select{constructor|deduction guide}0 declared here">; +def note_implicit_deduction_guide : Note<"implicit deduction guide declared as '%0'">; // C++11 auto def warn_cxx98_compat_auto_type_specifier : Warning< diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 982cca6..5ea6b06 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -40,6 +40,7 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLForwardCompat.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" @@ -11884,6 +11885,46 @@ static void DiagnoseFailedExplicitSpec(Sema &S, OverloadCandidate *Cand) { << (ES.getExpr() ? ES.getExpr()->getSourceRange() : SourceRange()); } +static void NoteImplicitDeductionGuide(Sema &S, FunctionDecl *Fn) { + auto *DG = dyn_cast(Fn); + if (!DG) + return; + TemplateDecl *OriginTemplate = + DG->getDeclName().getCXXDeductionGuideTemplate(); + // We want to always print synthesized deduction guides for type aliases. + // They would retain the explicit bit of the corresponding constructor. + if (!(DG->isImplicit() || (OriginTemplate && OriginTemplate->isTypeAlias()))) + return; + std::string FunctionProto; + llvm::raw_string_ostream OS(FunctionProto); + FunctionTemplateDecl *Template = DG->getDescribedFunctionTemplate(); + if (!Template) { + // This also could be an instantiation. Find out the primary template. + FunctionDecl *Pattern = + DG->getTemplateInstantiationPattern(/*ForDefinition=*/false); + if (!Pattern) { + // The implicit deduction guide is built on an explicit non-template + // deduction guide. Currently, this might be the case only for type + // aliases. + // FIXME: Add a test once https://github.com/llvm/llvm-project/pull/96686 + // gets merged. + assert(OriginTemplate->isTypeAlias() && + "Non-template implicit deduction guides are only possible for " + "type aliases"); + DG->print(OS); + S.Diag(DG->getLocation(), diag::note_implicit_deduction_guide) + << FunctionProto; + return; + } + Template = Pattern->getDescribedFunctionTemplate(); + assert(Template && "Cannot find the associated function template of " + "CXXDeductionGuideDecl?"); + } + Template->print(OS); + S.Diag(DG->getLocation(), diag::note_implicit_deduction_guide) + << FunctionProto; +} + /// Generates a 'note' diagnostic for an overload candidate. We've /// already generated a primary error at the call site. /// @@ -11941,6 +11982,17 @@ static void NoteFunctionCandidate(Sema &S, OverloadCandidate *Cand, return; } + // If this is a synthesized deduction guide we're deducing against, add a note + // for it. These deduction guides are not explicitly spelled in the source + // code, so simply printing a deduction failure note mentioning synthesized + // template parameters or pointing to the header of the surrounding RecordDecl + // would be confusing. + // + // We prefer adding such notes at the end of the deduction failure because + // duplicate code snippets appearing in the diagnostic would likely become + // noisy. + auto _ = llvm::make_scope_exit([&] { NoteImplicitDeductionGuide(S, Fn); }); + switch (Cand->FailureKind) { case ovl_fail_too_many_arguments: case ovl_fail_too_few_arguments: diff --git a/clang/test/CXX/drs/cwg26xx.cpp b/clang/test/CXX/drs/cwg26xx.cpp index e180c93..d843b09 100644 --- a/clang/test/CXX/drs/cwg26xx.cpp +++ b/clang/test/CXX/drs/cwg26xx.cpp @@ -193,8 +193,11 @@ static_assert(__is_same(decltype(i), I)); J j = { "ghi" }; // since-cxx20-error@-1 {{no viable constructor or deduction guide}} // since-cxx20-note@#cwg2681-J {{candidate template ignored: could not match 'J' against 'const char *'}} +// since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template J(J) -> J'}} // since-cxx20-note@#cwg2681-J {{candidate template ignored: could not match 'const unsigned char' against 'const char'}} +// since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template J(const unsigned char (&)[N]) -> J'}} // since-cxx20-note@#cwg2681-J {{candidate function template not viable: requires 0 arguments, but 1 was provided}} +// since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template J() -> J'}} #endif } diff --git a/clang/test/CXX/expr/expr.post/expr.type.conv/p1.cpp b/clang/test/CXX/expr/expr.post/expr.type.conv/p1.cpp index f3608bc3..f8d88e1 100644 --- a/clang/test/CXX/expr/expr.post/expr.type.conv/p1.cpp +++ b/clang/test/CXX/expr/expr.post/expr.type.conv/p1.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -std=c++1z -verify %s -template struct A { // expected-note 2{{candidate}} +template struct A { // expected-note 2{{candidate}} expected-note 2{{implicit deduction guide}} T t, u; }; template A(T, T) -> A; // expected-note {{deduced conflicting types for parameter 'T'}} diff --git a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp index 49fde29..d192070 100644 --- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp +++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp @@ -35,8 +35,9 @@ namespace std { } namespace p0702r1 { - template struct X { // expected-note {{candidate}} - X(std::initializer_list); // expected-note {{candidate template ignored: could not match 'std::initializer_list' against 'Z'}} + template struct X { // expected-note {{candidate}} expected-note {{implicit deduction guide}} + X(std::initializer_list); // expected-note {{candidate template ignored: could not match 'std::initializer_list' against 'Z'}} \ + // expected-note {{implicit deduction guide declared as 'template X(std::initializer_list) -> X'}} }; X xi = {0}; diff --git a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp index 8592626..ed44536 100644 --- a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp +++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp @@ -6,8 +6,8 @@ #if __cplusplus > 201402L namespace ClassTemplateParamNotForwardingRef { // This is not a forwarding reference. - template struct A { // expected-note {{candidate}} - A(T&&); // expected-note {{expects an rvalue}} + template struct A { // expected-note {{candidate}} expected-note {{implicit deduction guide}} + A(T&&); // expected-note {{expects an rvalue}} expected-note {{implicit deduction guide}} }; int n; A a = n; // expected-error {{no viable constructor or deduction guide}} @@ -75,10 +75,12 @@ namespace std_example { int n3 = g(i); // expected-error{{no matching function for call to 'g'}} #if __cplusplus > 201402L - template struct A { // expected-note {{candidate}} + template struct A { // expected-note {{candidate}} expected-note {{implicit deduction guide}} template - A(T &&, U &&, int *); // expected-note {{[with T = int, U = int] not viable: expects an rvalue}} - A(T &&, int *); // expected-note {{requires 2}} + A(T &&, U &&, int *); // expected-note {{[with T = int, U = int] not viable: expects an rvalue}} \ + // expected-note {{implicit deduction guide declared as 'template A(T &&, type-parameter-0-1 &&, int *) -> A'}} + A(T &&, int *); // expected-note {{requires 2}} \ + // expected-note {{implicit deduction guide declared as 'template A(T &&, int *) -> A'}} }; template A(T &&, int *) -> A; // expected-note {{requires 2}} diff --git a/clang/test/Modules/template_name_lookup.cpp b/clang/test/Modules/template_name_lookup.cpp index 29375e5..82b06e8 100644 --- a/clang/test/Modules/template_name_lookup.cpp +++ b/clang/test/Modules/template_name_lookup.cpp @@ -7,5 +7,7 @@ import foo; void use() { X x; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'X'}} // expected-note@Inputs/template_name_lookup/foo.cppm:3 {{candidate template ignored: couldn't infer template argument 'T'}} + // expected-note@Inputs/template_name_lookup/foo.cppm:3 {{implicit deduction guide declared as 'template X(X) -> X'}} // expected-note@Inputs/template_name_lookup/foo.cppm:3 {{candidate function template not viable: requires 1 argument, but 0 were provided}} + // expected-note@Inputs/template_name_lookup/foo.cppm:3 {{implicit deduction guide declared as 'template X() -> X'}} } diff --git a/clang/test/PCH/cxx-explicit-specifier.cpp b/clang/test/PCH/cxx-explicit-specifier.cpp index 94ca9f7..84548fa 100644 --- a/clang/test/PCH/cxx-explicit-specifier.cpp +++ b/clang/test/PCH/cxx-explicit-specifier.cpp @@ -79,8 +79,8 @@ struct A { B b_true; B b_false; #else -//expected-note@-8 {{candidate template ignored}} -//expected-note@-8 {{explicit constructor declared here}} +//expected-note@-8 {{candidate template ignored}} expected-note@-8 {{implicit deduction guide declared as 'template A(A) -> A'}} +//expected-note@-8 {{explicit constructor declared here}} expected-note@-8 {{implicit deduction guide declared as 'template explicit(b) A(B) -> A'}} //expected-note@-15+ {{candidate constructor}} //expected-note@-8+ {{explicit conversion function is not a candidate (explicit specifier}} //expected-note@-11 {{explicit constructor is not a candidate (explicit specifier}} diff --git a/clang/test/Sema/tls_alignment.cpp b/clang/test/Sema/tls_alignment.cpp index c5c79aa..65b6b03 100644 --- a/clang/test/Sema/tls_alignment.cpp +++ b/clang/test/Sema/tls_alignment.cpp @@ -22,7 +22,9 @@ struct struct_with_aligned_field { template struct templated_struct {}; // expected-note@-1{{candidate template ignored: couldn't infer template argument ''}} -// expected-note@-2{{candidate function template not viable: requires 1 argument, but 0 were provided}} +// expected-note@-2{{implicit deduction guide declared as 'template templated_struct() -> templated_struct'}} +// expected-note@-3{{candidate function template not viable: requires 1 argument, but 0 were provided}} +// expected-note@-4{{implicit deduction guide declared as 'template templated_struct(templated_struct) -> templated_struct'}} // A typedef of the aligned struct. typedef aligned_struct another_aligned_struct; diff --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index 90404f1..9ef5303 100644 --- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -139,11 +139,13 @@ namespace look_into_current_instantiation { // templates, and members of the current instantiation A &r = a; - template struct B { // expected-note {{could not match 'B' against 'int'}} + template struct B { // expected-note {{could not match 'B' against 'int'}} \ + // expected-note {{implicit deduction guide declared as 'template B(B) -> B'}} struct X { typedef T type; }; - B(typename X::type); // expected-note {{couldn't infer template argument 'T'}} + B(typename X::type); // expected-note {{couldn't infer template argument 'T'}} \ + // expected-note {{implicit deduction guide declared as 'template B(typename X::type) -> B'}} }; B b = 0; // expected-error {{no viable}} @@ -564,8 +566,10 @@ namespace PR47175 { // Ensure we don't crash when CTAD fails. template -struct Foo { // expected-note{{candidate function template not viable}} - Foo(T1, T2); // expected-note{{candidate function template not viable}} +struct Foo { // expected-note {{candidate function template not viable}} \ + // expected-note {{implicit deduction guide declared as 'template Foo(Foo) -> Foo'}} + Foo(T1, T2); // expected-note {{candidate function template not viable}} \ + // expected-note {{implicit deduction guide declared as 'template Foo(T1, T2) -> Foo'}} }; template diff --git a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp index b71dfc6..3dafe82 100644 --- a/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp +++ b/clang/test/SemaCXX/cxx20-ctad-type-alias.cpp @@ -110,6 +110,8 @@ struct Foo { template using Bar = Foo; // expected-note {{candidate template ignored: couldn't infer template argument 'X'}} \ + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test9::Bar, Foo) Bar(Foo) -> Foo'}} \ + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test9::Bar, Foo) Bar(const type-parameter-0-0 (&)[sizeof(type-parameter-0-0)]) -> Foo'}} \ // expected-note {{candidate template ignored: constraints not satisfied [with X = int]}} \ // expected-note {{cannot deduce template arguments for 'Bar' from 'Foo'}} @@ -137,9 +139,12 @@ struct A {}; template struct Foo { T c; }; template using AFoo = Foo; // expected-note {{candidate template ignored: could not match 'Foo' against 'int'}} \ + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test11::AFoo, Foo) AFoo(Foo) -> Foo'}} \ // expected-note {{candidate template ignored: constraints not satisfied [with Y = int]}} \ // expected-note {{cannot deduce template arguments for 'AFoo' from 'Foo'}} \ - // expected-note {{candidate function template not viable: requires 0 arguments, but 1 was provided}} + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test11::AFoo, Foo) AFoo(type-parameter-0-0) -> Foo'}} \ + // expected-note {{candidate function template not viable: requires 0 arguments, but 1 was provided}} \ + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test11::AFoo, Foo) AFoo() -> Foo'}} AFoo s = {1}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'AFoo'}} } // namespace test11 @@ -192,6 +197,8 @@ struct Foo { template using Bar = Foo; // expected-note {{constraints not satisfied for class template 'Foo'}} // expected-note@-1 {{candidate template ignored: could not match}} +// expected-note@-2 {{implicit deduction guide declared as 'template requires __is_deducible(test14::Bar, Foo) Bar(Foo) -> Foo'}} +// expected-note@-3 {{implicit deduction guide declared as 'template requires __is_deducible(test14::Bar, Foo) Bar(const double (&)[K]) -> Foo'}} double abc[3]; Bar s2 = {abc}; // expected-error {{no viable constructor or deduction guide for deduction }} } // namespace test14 @@ -204,7 +211,9 @@ template concept False = false; template using BFoo = AFoo; // expected-note {{candidate template ignored: constraints not satisfied [with V = int]}} \ // expected-note {{cannot deduce template arguments for 'BFoo' from 'Foo'}} \ - // expected-note {{candidate template ignored: could not match 'Foo' against 'int *'}} + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(AFoo, Foo) && __is_deducible(test15::BFoo, Foo) BFoo(type-parameter-0-0 *) -> Foo}} \ + // expected-note {{candidate template ignored: could not match 'Foo' against 'int *'}} \ + // expected-note {{template requires __is_deducible(AFoo, Foo) && __is_deducible(test15::BFoo, Foo) BFoo(Foo) -> Foo}} int i = 0; AFoo a1(&i); // OK, deduce Foo @@ -255,8 +264,11 @@ Foo(T) -> Foo; template using Bar = Foo; // expected-note {{could not match 'Foo' against 'int'}} \ + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test18::Bar, Foo) Bar(Foo) -> Foo'}} \ // expected-note {{candidate template ignored: constraints not satisfied}} \ - // expected-note {{candidate function template not viable}} + // expected-note {{implicit deduction guide declared as 'template requires False && __is_deducible(test18::Bar, Foo) Bar(type-parameter-0-0) -> Foo'}} \ + // expected-note {{candidate function template not viable}} \ + // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test18::Bar, Foo) Bar() -> Foo'}} Bar s = {1}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments}} } // namespace test18 @@ -284,7 +296,8 @@ class Foo {}; // Verify that template template type parameter TTP is referenced/used in the // template arguments of the RHS. template typename TTP> -using Bar = Foo>; // expected-note {{candidate template ignored: could not match 'Foo>' against 'int'}} +using Bar = Foo>; // expected-note {{candidate template ignored: could not match 'Foo>' against 'int'}} \ + // expected-note {{implicit deduction guide declared as 'template