================ @@ -0,0 +1,181 @@ +//===- LTOConfigBitcodeTest.cpp - LTO config bitcode tests --------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/LTO/LTOConfigBitcode.h" +#include "llvm/Bitcode/BitcodeReader.h" +#include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/LTO/TargetOptionsBitcode.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/FileUtilities.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/MemoryBufferRef.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Testing/Support/Error.h" +#include "gtest/gtest.h" + +#include <limits> + +using namespace llvm; +using namespace llvm::lto; + +TEST(TargetOptionsBitcodeTest, RoundTripThroughBitcode) { + TargetOptions Input; + Input.MCOptions.BinutilsVersion = {2, 41}; + Input.FunctionSections = true; + Input.DataSections = true; + Input.GlobalISelAbort = GlobalISelAbortMode::DisableWithDiag; + Input.TLSSize = 64; + Input.BBSections = BasicBlockSection::List; + Input.BBSectionsFuncListBuf = MemoryBuffer::getMemBufferCopy( + "v1\nf foo\nc 0 1\n", "basic-block-sections.profile"); + Input.EnableDefaultMachineVerifier = false; + Input.StackUsageFile = "output.su"; + Input.LoopAlignment = std::numeric_limits<unsigned>::max(); + Input.ExceptionModel = ExceptionHandling::Wasm; + Input.MCOptions.MCRelaxAll = true; + Input.MCOptions.RelocSectionSym = RelocSectionSymType::Internal; + Input.MCOptions.DwarfVersion = 5; + Input.MCOptions.ABIName = "test-abi"; + Input.MCOptions.OutputAsmVariant = std::numeric_limits<unsigned>::max(); + Input.MCOptions.IASSearchPaths = {"include/one", "include/two"}; + Input.MCOptions.InstPrinterOptions = {"no-aliases"}; + Input.MCOptions.LargeEHEncoding = true; + + LLVMContext WriteCtx; + Module M("target-options", WriteCtx); + ASSERT_THAT_ERROR(encodeTargetOptionsToModule(M, Input), Succeeded()); + EXPECT_TRUE(hasEncodedTargetOptions(M)); + + SmallString<0> Storage; + raw_svector_ostream OS(Storage); + WriteBitcodeToFile(M, OS); + + LLVMContext ReadCtx; + Expected<std::unique_ptr<Module>> Parsed = parseBitcodeFile( + MemoryBufferRef(StringRef(Storage.data(), Storage.size()), "options.bc"), + ReadCtx); + ASSERT_THAT_EXPECTED(Parsed, Succeeded()); + Expected<TargetOptions> Output = decodeTargetOptionsFromModule(**Parsed); + ASSERT_THAT_EXPECTED(Output, Succeeded()); + + EXPECT_EQ(Output->MCOptions.BinutilsVersion, Input.MCOptions.BinutilsVersion); + EXPECT_TRUE(Output->FunctionSections); + EXPECT_TRUE(Output->DataSections); + EXPECT_EQ(Output->GlobalISelAbort, GlobalISelAbortMode::DisableWithDiag); ---------------- kbelochapka wrote:
Hi @arsenm , Can you please be more specific, what stuff needs to be serialized. For DTLTO, we are addressing a very specific goal: ensuring that the object file generated from a bitcode file through the ThinLTO pipeline is identical to the object file produced by the DTLTO pipeline. In this context, the FunctionSections and DataSections fields are important because they have a direct impact on the layout and contents of the resulting object file. https://github.com/llvm/llvm-project/pull/219894 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
