llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-risc-v Author: Alexander Richardson (arichardson) <details> <summary>Changes</summary> This adds a new pointer address space to the data layout when RVY is enabled, making use of the new 'e' flag for pointers with [external state](https://github.com/llvm/llvm-project/pull/105735). I chose address space 200 since that is what has been used in the downstream CHERI forks for the past decade and therefore makes it slightly easier to upstream tests, etc. but am happy to use any other value if that is preferred. This extends computeRISCVDataLayout() to also accept the LLVM features string so that we can detect whether Y is enabled or not. Once RVY ABIs are upstreamed, we can look at the ABI name parameter to detect pure-capability ABIs, but we still need the feature string/ISAInfo to handle the "hybrid" case where only some pointers use Y registers. --- Full diff: https://github.com/llvm/llvm-project/pull/177249.diff 5 Files Affected: - (modified) llvm/include/llvm/TargetParser/Triple.h (+3-2) - (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+2-2) - (modified) llvm/lib/TargetParser/TargetDataLayout.cpp (+21-8) - (added) llvm/test/CodeGen/RISCV/rvy/datalayout.ll (+8) - (modified) llvm/tools/opt/optdriver.cpp (+1-1) ``````````diff diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h index 8559d7b088ee1..ae85689685c2c 100644 --- a/llvm/include/llvm/TargetParser/Triple.h +++ b/llvm/include/llvm/TargetParser/Triple.h @@ -1372,8 +1372,9 @@ class Triple { LLVM_ABI ExceptionHandling getDefaultExceptionHandling() const; /// Compute the LLVM IR data layout string based on the triple. Some targets - /// customize the layout based on the ABIName string. - LLVM_ABI std::string computeDataLayout(StringRef ABIName = "") const; + /// customize the layout based on the ABIName string and/or target features. + LLVM_ABI std::string computeDataLayout(StringRef ABIName = "", + StringRef FS = "") const; }; } // End llvm namespace diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp index 62a5cd3a7c840..a58505ae4f383 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp @@ -166,8 +166,8 @@ RISCVTargetMachine::RISCVTargetMachine(const Target &T, const Triple &TT, std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT) : CodeGenTargetMachineImpl( - T, TT.computeDataLayout(Options.MCOptions.getABIName()), TT, CPU, FS, - Options, getEffectiveRelocModel(RM), + T, TT.computeDataLayout(Options.MCOptions.getABIName(), FS), TT, CPU, + FS, Options, getEffectiveRelocModel(RM), getEffectiveCodeModel(CM, CodeModel::Small), OL), TLOF(createTLOF(TT)) { initAsmInfo(); diff --git a/llvm/lib/TargetParser/TargetDataLayout.cpp b/llvm/lib/TargetParser/TargetDataLayout.cpp index b985c1eec4244..20f9987a4782a 100644 --- a/llvm/lib/TargetParser/TargetDataLayout.cpp +++ b/llvm/lib/TargetParser/TargetDataLayout.cpp @@ -6,9 +6,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/CommandLine.h" #include "llvm/TargetParser/ARMTargetParser.h" +#include "llvm/TargetParser/RISCVISAInfo.h" #include "llvm/TargetParser/Triple.h" #include <cstring> using namespace llvm; @@ -279,14 +281,14 @@ static std::string computeAMDDataLayout(const Triple &TT) { "v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9"; } -static std::string computeRISCVDataLayout(const Triple &TT, StringRef ABIName) { +static std::string computeRISCVDataLayout(const Triple &TT, StringRef ABIName, + StringRef FS) { if (TT.isOSBinFormatMachO()) { assert(TT.isLittleEndian() && "Invalid endianness"); assert(TT.isArch32Bit() && "Invalid triple"); assert((ABIName != "ilp32e") && "Invalid ABI."); return "e-m:o-p:32:32-i64:64-n32-S128"; } - std::string Ret; if (TT.isLittleEndian()) @@ -296,14 +298,25 @@ static std::string computeRISCVDataLayout(const Triple &TT, StringRef ABIName) { Ret += "-m:e"; + std::vector<std::string> Features; + if (!FS.empty()) + llvm::append_range(Features, llvm::split(FS, ',')); + auto ISAInfo = cantFail( + llvm::RISCVISAInfo::parseFeatures(TT.isArch64Bit() ? 64 : 32, Features)); + bool HasRVY = ISAInfo->hasExtension("experimental-y"); + // Pointer and integer sizes. if (TT.isRISCV64()) { - Ret += "-p:64:64-i64:64-i128:128"; - Ret += "-n32:64"; + Ret += "-p:64:64"; + if (HasRVY) + Ret += "-pe200:128:128:128:64"; + Ret += "-i64:64-i128:128-n32:64"; } else { assert(TT.isRISCV32() && "only RV32 and RV64 are currently supported"); - Ret += "-p:32:32-i64:64"; - Ret += "-n32"; + Ret += "-p:32:32"; + if (HasRVY) + Ret += "-pe200:64:64:64:32"; + Ret += "-i64:64-n32"; } // Stack alignment based on ABI. @@ -541,7 +554,7 @@ static std::string computeVEDataLayout(const Triple &T) { return Ret; } -std::string Triple::computeDataLayout(StringRef ABIName) const { +std::string Triple::computeDataLayout(StringRef ABIName, StringRef FS) const { switch (getArch()) { case Triple::arm: case Triple::armeb: @@ -596,7 +609,7 @@ std::string Triple::computeDataLayout(StringRef ABIName) const { case Triple::riscv64: case Triple::riscv32be: case Triple::riscv64be: - return computeRISCVDataLayout(*this, ABIName); + return computeRISCVDataLayout(*this, ABIName, FS); case Triple::sparc: case Triple::sparcv9: case Triple::sparcel: diff --git a/llvm/test/CodeGen/RISCV/rvy/datalayout.ll b/llvm/test/CodeGen/RISCV/rvy/datalayout.ll new file mode 100644 index 0000000000000..336a51f6e98e5 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvy/datalayout.ll @@ -0,0 +1,8 @@ +;; Check that we infer the appropriate datalayout components for RVY (p200 for capabilities). +; RUN: llc < %s -mtriple=riscv32 -mattr=+experimental-y --stop-after=pre-isel-intrinsic-lowering | FileCheck %s --check-prefix=CHECK32 +; RUN: llc < %s -mtriple=riscv64 -mattr=+experimental-y --stop-after=pre-isel-intrinsic-lowering | FileCheck %s --check-prefix=CHECK64 +; RUN: opt -S < %s -mtriple=riscv32 -mattr=+experimental-y | FileCheck %s --check-prefix=CHECK32 +; RUN: opt -S < %s -mtriple=riscv64 -mattr=+experimental-y | FileCheck %s --check-prefix=CHECK64 + +; CHECK32: target datalayout = "e-m:e-p:32:32-pe200:64:64:64:32-i64:64-n32-S128" +; CHECK64: target datalayout = "e-m:e-p:64:64-pe200:128:128:128:64-i64:64-i128:128-n32:64-S128" diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp index b0c2733758948..ff27c00df4c9f 100644 --- a/llvm/tools/opt/optdriver.cpp +++ b/llvm/tools/opt/optdriver.cpp @@ -542,7 +542,7 @@ optMain(int argc, char **argv, Triple TT(TripleStr); - std::string Str = TT.computeDataLayout(ABIName); + std::string Str = TT.computeDataLayout(ABIName, codegen::getFeaturesStr()); if (Str.empty()) { errs() << argv[0] << ": warning: failed to infer data layout from target triple\n"; `````````` </details> https://github.com/llvm/llvm-project/pull/177249 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
