[clang] [llvm] Pass TargetMachine from from Clang to `BitcodeWriter`and `ThinLTOBitcodeWriter` pass for thin and fat LTO respectively. (PR #143692)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 11 05:46:09 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions c,cpp,h -- clang/test/CodeGen/RISCV/include.c clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h llvm/include/llvm/Bitcode/BitcodeWriter.h llvm/include/llvm/Bitcode/BitcodeWriterPass.h llvm/include/llvm/Object/IRSymtab.h llvm/include/llvm/Object/ModuleSymbolTable.h llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h llvm/lib/Analysis/ModuleSummaryAnalysis.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp llvm/lib/Object/IRSymtab.cpp llvm/lib/Object/ModuleSymbolTable.cpp llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
index 25cc2cc93..4939f974d 100644
--- a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
+++ b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h
@@ -38,8 +38,7 @@ class TargetMachine;
LLVM_ABI ModuleSummaryIndex buildModuleSummaryIndex(
const Module &M,
std::function<BlockFrequencyInfo *(const Function &F)> GetBFICallback,
- ProfileSummaryInfo *PSI,
- const TargetMachine *TM = nullptr,
+ ProfileSummaryInfo *PSI, const TargetMachine *TM = nullptr,
std::function<const StackSafetyInfo *(const Function &F)> GetSSICallback =
[](const Function &F) -> const StackSafetyInfo * { return nullptr; });
diff --git a/llvm/include/llvm/Bitcode/BitcodeWriter.h b/llvm/include/llvm/Bitcode/BitcodeWriter.h
index 3265d15f2..b8c1d57f4 100644
--- a/llvm/include/llvm/Bitcode/BitcodeWriter.h
+++ b/llvm/include/llvm/Bitcode/BitcodeWriter.h
@@ -47,6 +47,7 @@ class BitcodeWriter {
std::vector<Module *> Mods;
const TargetMachine *TM;
+
public:
/// Create a BitcodeWriter that writes to Buffer.
LLVM_ABI BitcodeWriter(SmallVectorImpl<char> &Buffer,
diff --git a/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h b/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
index d0d34b65d..4a169b9cd 100644
--- a/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
+++ b/llvm/include/llvm/Transforms/IPO/ThinLTOBitcodeWriter.h
@@ -36,7 +36,7 @@ public:
// it's not nullptr.
ThinLTOBitcodeWriterPass(raw_ostream &OS, raw_ostream *ThinLinkOS,
bool ShouldPreserveUseListOrder = false,
- const TargetMachine* TM = nullptr)
+ const TargetMachine *TM = nullptr)
: OS(OS), ThinLinkOS(ThinLinkOS),
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder), TM(TM) {}
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index 8d5ac051c..a2fa2a44a 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -978,7 +978,8 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
// be listed on the llvm.used or llvm.compiler.used global and marked as
// referenced from there.
ModuleSymbolTable::CollectAsmSymbols(
- M, [&](StringRef Name, object::BasicSymbolRef::Flags Flags) {
+ M,
+ [&](StringRef Name, object::BasicSymbolRef::Flags Flags) {
// Symbols not marked as Weak or Global are local definitions.
if (Flags & (object::BasicSymbolRef::SF_Weak |
object::BasicSymbolRef::SF_Global))
@@ -1031,7 +1032,8 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex(
SmallVector<ValueInfo, 0>{});
Index.addGlobalValueSummary(*GV, std::move(Summary));
}
- }, TM);
+ },
+ TM);
}
bool IsThinLTO = true;
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index fa9ad8f76..c6ce2dd69 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -5675,7 +5675,7 @@ void BitcodeWriter::writeThinLinkBitcode(const Module &M,
void llvm::writeThinLinkBitcodeToFile(const Module &M, raw_ostream &Out,
const ModuleSummaryIndex &Index,
const ModuleHash &ModHash,
- const TargetMachine* TM) {
+ const TargetMachine *TM) {
SmallVector<char, 0> Buffer;
Buffer.reserve(256 * 1024);
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp
index f6d282b3d..8071af0b9 100644
--- a/llvm/lib/Object/IRSymtab.cpp
+++ b/llvm/lib/Object/IRSymtab.cpp
@@ -76,7 +76,7 @@ struct Builder {
SmallVector<char, 0> &Symtab;
StringTableBuilder &StrtabBuilder;
StringSaver Saver;
- const TargetMachine* TM;
+ const TargetMachine *TM;
// This ctor initializes a StringSaver using the passed in BumpPtrAllocator.
// The StringTableBuilder does not create a copy of any strings added to it,
@@ -377,8 +377,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
Error irsymtab::build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab,
StringTableBuilder &StrtabBuilder,
- BumpPtrAllocator &Alloc,
- const TargetMachine *TM) {
+ BumpPtrAllocator &Alloc, const TargetMachine *TM) {
return Builder(Symtab, StrtabBuilder, Alloc, TM).build(Mods);
}
diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp
index 836ab9698..b151b9360 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -59,10 +59,13 @@ void ModuleSymbolTable::addModule(Module *M, const TargetMachine *TM) {
for (GlobalValue &GV : M->global_values())
SymTab.push_back(&GV);
- CollectAsmSymbols(*M, [this](StringRef Name, BasicSymbolRef::Flags Flags) {
- SymTab.push_back(new (AsmSymbols.Allocate())
- AsmSymbol(std::string(Name), Flags));
- }, TM);
+ CollectAsmSymbols(
+ *M,
+ [this](StringRef Name, BasicSymbolRef::Flags Flags) {
+ SymTab.push_back(new (AsmSymbols.Allocate())
+ AsmSymbol(std::string(Name), Flags));
+ },
+ TM);
}
static void initializeRecordStreamer(const Module &M,
@@ -145,38 +148,41 @@ void ModuleSymbolTable::CollectAsmSymbols(
const Module &M,
function_ref<void(StringRef, BasicSymbolRef::Flags)> AsmSymbol,
const TargetMachine *TM) {
- initializeRecordStreamer(M, [&](RecordStreamer &Streamer) {
- Streamer.flushSymverDirectives();
+ initializeRecordStreamer(
+ M,
+ [&](RecordStreamer &Streamer) {
+ Streamer.flushSymverDirectives();
- for (auto &KV : Streamer) {
- StringRef Key = KV.first();
- RecordStreamer::State Value = KV.second;
- // FIXME: For now we just assume that all asm symbols are executable.
- uint32_t Res = BasicSymbolRef::SF_Executable;
- switch (Value) {
- case RecordStreamer::NeverSeen:
- llvm_unreachable("NeverSeen should have been replaced earlier");
- case RecordStreamer::DefinedGlobal:
- Res |= BasicSymbolRef::SF_Global;
- break;
- case RecordStreamer::Defined:
- break;
- case RecordStreamer::Global:
- case RecordStreamer::Used:
- Res |= BasicSymbolRef::SF_Undefined;
- Res |= BasicSymbolRef::SF_Global;
- break;
- case RecordStreamer::DefinedWeak:
- Res |= BasicSymbolRef::SF_Weak;
- Res |= BasicSymbolRef::SF_Global;
- break;
- case RecordStreamer::UndefinedWeak:
- Res |= BasicSymbolRef::SF_Weak;
- Res |= BasicSymbolRef::SF_Undefined;
- }
- AsmSymbol(Key, BasicSymbolRef::Flags(Res));
- }
- }, TM);
+ for (auto &KV : Streamer) {
+ StringRef Key = KV.first();
+ RecordStreamer::State Value = KV.second;
+ // FIXME: For now we just assume that all asm symbols are executable.
+ uint32_t Res = BasicSymbolRef::SF_Executable;
+ switch (Value) {
+ case RecordStreamer::NeverSeen:
+ llvm_unreachable("NeverSeen should have been replaced earlier");
+ case RecordStreamer::DefinedGlobal:
+ Res |= BasicSymbolRef::SF_Global;
+ break;
+ case RecordStreamer::Defined:
+ break;
+ case RecordStreamer::Global:
+ case RecordStreamer::Used:
+ Res |= BasicSymbolRef::SF_Undefined;
+ Res |= BasicSymbolRef::SF_Global;
+ break;
+ case RecordStreamer::DefinedWeak:
+ Res |= BasicSymbolRef::SF_Weak;
+ Res |= BasicSymbolRef::SF_Global;
+ break;
+ case RecordStreamer::UndefinedWeak:
+ Res |= BasicSymbolRef::SF_Weak;
+ Res |= BasicSymbolRef::SF_Undefined;
+ }
+ AsmSymbol(Key, BasicSymbolRef::Flags(Res));
+ }
+ },
+ TM);
// In ELF, object code generated for x86-32 and some code models of x86-64 may
// reference the special symbol _GLOBAL_OFFSET_TABLE_ that is not used in the
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index 3e1dbfedc..f4760e194 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -8,13 +8,13 @@
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
-#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/StackSafetyAnalysis.h"
#include "llvm/Analysis/TypeMetadataUtils.h"
#include "llvm/Bitcode/BitcodeWriter.h"
+#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Instructions.h"
``````````
</details>
https://github.com/llvm/llvm-project/pull/143692
More information about the llvm-commits
mailing list