================
@@ -43,50 +43,67 @@ static std::string getThinLTOOutputFile(Ctx &ctx, StringRef
modulePath) {
ctx.arg.thinLTOPrefixReplaceNew);
}
+static std::shared_ptr<MemoryBuffer> getMemoryBuffer(Ctx &ctx) {
+ if (ctx.arg.ltoBasicBlockSections.empty() ||
+ ctx.arg.ltoBasicBlockSections == "all" ||
+ ctx.arg.ltoBasicBlockSections == "labels" ||
+ ctx.arg.ltoBasicBlockSections == "none")
+ return nullptr;
+
+ ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr =
+ MemoryBuffer::getFile(ctx.arg.ltoBasicBlockSections.str());
+ if (!mbOrErr) {
+ ErrAlways(ctx) << "cannot open " << ctx.arg.ltoBasicBlockSections << ":"
+ << mbOrErr.getError().message();
+ }
+ return std::move(*mbOrErr);
+}
+
static lto::Config createConfig(Ctx &ctx) {
lto::Config c;
- // LLD supports the new relocations and address-significance tables.
- c.Options = initTargetOptionsFromCodeGenFlags();
- c.Options.EmitAddrsig = true;
- for (StringRef C : ctx.arg.mllvmOpts)
- c.MllvmArgs.emplace_back(C.str());
-
- // Always emit a section per function/datum with LTO.
- c.Options.FunctionSections = true;
- c.Options.DataSections = true;
-
- // Check if basic block sections must be used.
- // Allowed values for --lto-basic-block-sections are "all",
- // "<file name specifying basic block ids>", or none. This is the equivalent
- // of -fbasic-block-sections= flag in clang.
- if (!ctx.arg.ltoBasicBlockSections.empty()) {
- if (ctx.arg.ltoBasicBlockSections == "all") {
- c.Options.BBSections = BasicBlockSection::All;
- } else if (ctx.arg.ltoBasicBlockSections == "labels") {
- c.Options.BBAddrMap = true;
- Warn(ctx)
- << "'--lto-basic-block-sections=labels' is deprecated; Please use "
- "'--lto-basic-block-address-map' instead";
- } else if (ctx.arg.ltoBasicBlockSections == "none") {
- c.Options.BBSections = BasicBlockSection::None;
- } else {
- ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
- MemoryBuffer::getFile(ctx.arg.ltoBasicBlockSections.str());
- if (!MBOrErr) {
- ErrAlways(ctx) << "cannot open " << ctx.arg.ltoBasicBlockSections <<
":"
- << MBOrErr.getError().message();
+ std::shared_ptr<MemoryBuffer> mbPtr = getMemoryBuffer(ctx);
+
+ // Set up the callback to modify TargetOptions.
+ c.ModifyTargetOptions =
+ [&ctx, mb = std::move(mbPtr)](TargetOptions &options) -> void {
+ // LLD supports the new relocations and address-significance tables.
+ options.EmitAddrsig = true;
+ // Always emit a section per function/datum with LTO.
+ options.FunctionSections = true;
+ options.DataSections = true;
+
+ // Check if basic block sections must be used.
+ // Allowed values for --lto-basic-block-sections are "all",
+ // "<file name specifying basic block ids>", or none. This is the
+ // equivalent of -fbasic-block-sections= flag in clang.
+ if (!ctx.arg.ltoBasicBlockSections.empty()) {
+ if (ctx.arg.ltoBasicBlockSections == "all") {
+ options.BBSections = BasicBlockSection::All;
+ } else if (ctx.arg.ltoBasicBlockSections == "labels") {
+ options.BBAddrMap = true;
+ Warn(ctx)
+ << "'--lto-basic-block-sections=labels' is deprecated; Please use "
+ "'--lto-basic-block-address-map' instead";
----------------
nikic wrote:
This should probably not be inside the lambda, otherwise it may appear multiple
times?
https://github.com/llvm/llvm-project/pull/179509
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits