Skip to content

Commit e3a6e56

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f45b9d987dfc' from llvm.org/main into next
2 parents f1cc735 + f45b9d9 commit e3a6e56

File tree

3 files changed

+209
-175
lines changed

3 files changed

+209
-175
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "llvm/Support/CommandLine.h"
6969
#include "llvm/Support/ConvertUTF.h"
7070
#include "llvm/Support/ErrorHandling.h"
71+
#include "llvm/Support/RISCVISAInfo.h"
7172
#include "llvm/Support/TimeProfiler.h"
7273
#include "llvm/Support/xxhash.h"
7374
#include "llvm/TargetParser/Triple.h"
@@ -1059,6 +1060,19 @@ void CodeGenModule::Release() {
10591060
llvm::LLVMContext &Ctx = TheModule.getContext();
10601061
getModule().addModuleFlag(llvm::Module::Error, "target-abi",
10611062
llvm::MDString::get(Ctx, ABIStr));
1063+
1064+
// Add the canonical ISA string as metadata so the backend can set the ELF
1065+
// attributes correctly. We use AppendUnique so LTO will keep all of the
1066+
// unique ISA strings that were linked together.
1067+
const std::vector<std::string> &Features =
1068+
getTarget().getTargetOpts().Features;
1069+
auto ParseResult =
1070+
llvm::RISCVISAInfo::parseFeatures(T.isRISCV64() ? 64 : 32, Features);
1071+
if (!errorToBool(ParseResult.takeError()))
1072+
getModule().addModuleFlag(
1073+
llvm::Module::AppendUnique, "riscv-isa",
1074+
llvm::MDNode::get(
1075+
Ctx, llvm::MDString::get(Ctx, (*ParseResult)->toString())));
10621076
}
10631077

10641078
if (CodeGenOpts.SanitizeCfiCrossDso) {

0 commit comments

Comments
 (0)