diff options
author | Kito Cheng <kito.cheng@sifive.com> | 2025-03-07 14:09:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-07 14:09:26 +0800 |
commit | 733ad3fdebf782be5afffdb8310a0ce15675086c (patch) | |
tree | d46669d7366337a7b14dcfffb180e2974068efd9 /llvm/lib/IR/Module.cpp | |
parent | bedb9077c38cf01a3f9303d68599ea95677be5b7 (diff) | |
download | llvm-733ad3fdebf782be5afffdb8310a0ce15675086c.zip llvm-733ad3fdebf782be5afffdb8310a0ce15675086c.tar.gz llvm-733ad3fdebf782be5afffdb8310a0ce15675086c.tar.bz2 |
[LTO] Override TargetABI from module flags if present when creating TargetMachine (#126497)
…argetMachine
RISC-V's data layout is determined by the ABI, not just the target
triple. However, the TargetMachine is created using the data layout from
the target triple, which is not always correct. This patch uses the
target ABI from the module and passes it to the TargetMachine, ensuring
that the data layout is set correctly according to the ABI.
The same problem will happen with other targets like MIPS, but
unfortunately, MIPS didn't emit the target-abi into the module flags, so
this patch only fixes the issue for RISC-V.
NOTE: MIPS with -mabi=n32 can trigger the same issue.
Another possible solution is add new parameter to the TargetMachine
constructor, but that would require changes in all the targets.
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index c7b9f87..c7daaaf 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -915,3 +915,11 @@ VersionTuple Module::getDarwinTargetVariantSDKVersion() const { void Module::setDarwinTargetVariantSDKVersion(VersionTuple Version) { addSDKVersionMD(Version, *this, "darwin.target_variant.SDK Version"); } + +StringRef Module::getTargetABIFromMD() { + StringRef TargetABI; + if (auto *TargetABIMD = + dyn_cast_or_null<MDString>(getModuleFlag("target-abi"))) + TargetABI = TargetABIMD->getString(); + return TargetABI; +} |