Skip to content

[RISCV] Add canonical ISA string as Module metadata in IR. #80760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/RISCVISAInfo.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/xxhash.h"
#include "llvm/TargetParser/Triple.h"
Expand Down Expand Up @@ -1056,6 +1057,19 @@ void CodeGenModule::Release() {
llvm::LLVMContext &Ctx = TheModule.getContext();
getModule().addModuleFlag(llvm::Module::Error, "target-abi",
llvm::MDString::get(Ctx, ABIStr));

// Add the canonical ISA string as metadata so the backend can set the ELF
// attributes correctly. We use AppendUnique so LTO will keep all of the
// unique ISA strings that were linked together.
const std::vector<std::string> &Features =
getTarget().getTargetOpts().Features;
auto ParseResult =
llvm::RISCVISAInfo::parseFeatures(T.isRISCV64() ? 64 : 32, Features);
if (!errorToBool(ParseResult.takeError()))
getModule().addModuleFlag(
llvm::Module::AppendUnique, "riscv-isa",
llvm::MDNode::get(
Ctx, llvm::MDString::get(Ctx, (*ParseResult)->toString())));
}

if (CodeGenOpts.SanitizeCfiCrossDso) {
Expand Down
Loading