From b717c84c39c2cc17edd0021506b3a26cd2c7a226 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Thu, 31 Jul 2025 11:25:40 -0700 Subject: [PATCH 01/22] Revert "[MCCAS] Add configuration LLVM_ENABLE_MCCAS" This reverts commit 1d94ada9141d7c162eb4327daa12fd33dbe33080. --- clang/include/clang/Driver/Options.td | 5 ----- clang/lib/Frontend/CMakeLists.txt | 9 +------- clang/lib/Frontend/CompileJobCache.cpp | 6 ----- clang/test/CAS/cas-backend.c | 1 - clang/test/CAS/cas-emit-casid.c | 2 +- clang/test/CAS/depscan-update-mccas.c | 1 - .../CAS/remote-cache-incompatible-options.c | 1 - clang/test/CMakeLists.txt | 9 +------- llvm/CMakeLists.txt | 1 - llvm/lib/CMakeLists.txt | 4 +--- llvm/lib/CodeGen/CMakeLists.txt | 9 +------- llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp | 14 +++--------- llvm/lib/MC/CMakeLists.txt | 4 ---- llvm/lib/MC/MachOCASWriter.cpp | 22 ++----------------- llvm/test/CAS/emit-casid-file.ll | 2 +- llvm/test/CMakeLists.txt | 11 ++-------- llvm/test/DebugInfo/CAS/AArch64/lit.local.cfg | 4 +--- llvm/test/MC/CAS/lit.local.cfg | 2 -- llvm/test/lit.cfg.py | 3 --- llvm/test/lit.site.cfg.py.in | 1 - llvm/test/tools/llvm-cas-dump/lit.local.cfg | 2 -- .../llvm-cas-object-format/lit.local.cfg | 2 -- .../tools/llvm-cas/ingest-blobs-casid.test | 2 +- llvm/tools/CMakeLists.txt | 8 +------ llvm/tools/llvm-mc/CMakeLists.txt | 9 +------- llvm/tools/llvm-mc/llvm-mc.cpp | 7 ------ 26 files changed, 17 insertions(+), 124 deletions(-) delete mode 100644 llvm/test/tools/llvm-cas-dump/lit.local.cfg delete mode 100644 llvm/test/tools/llvm-cas-object-format/lit.local.cfg diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 1ac067f96e8a8..53588ebdcd1ac 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -9092,15 +9092,10 @@ defm include_tree_preserve_pch_path : BoolFOption<"include-tree-preserve-pch-pat NegFlag>; /// BEGIN MCCAS -#ifdef LLVM_EMABLE_MCCAS defm cas_backend : BoolFOption<"cas-backend", CodeGenOpts<"UseCASBackend">, DefaultFalse, PosFlag, NegFlag>; -#else -def cas_backend : Flag<["-"], "fcas-backend">, Group; -def no_cas_backend : Flag<["-"], "fno-cas-backend">, Group; -#endif defm cas_emit_casid_file : BoolFOption<"cas-emit-casid-file", CodeGenOpts<"EmitCASIDFile">, DefaultFalse, diff --git a/clang/lib/Frontend/CMakeLists.txt b/clang/lib/Frontend/CMakeLists.txt index 2db35e619649f..4831919f5c50a 100644 --- a/clang/lib/Frontend/CMakeLists.txt +++ b/clang/lib/Frontend/CMakeLists.txt @@ -1,18 +1,11 @@ add_subdirectory(Rewrite) -if (LLVM_ENABLE_MCCAS) - add_definitions(-DLLVM_ENABLE_MCCAS=1) - set(MCCAS_DEPS - MCCAS - ) -endif() - set(LLVM_LINK_COMPONENTS BitReader BitstreamReader CAS CASUtil - ${MCCAS_DEPS} + MCCAS Option ProfileData RemoteCachingService diff --git a/clang/lib/Frontend/CompileJobCache.cpp b/clang/lib/Frontend/CompileJobCache.cpp index a8063996b76db..6e32eb80edb87 100644 --- a/clang/lib/Frontend/CompileJobCache.cpp +++ b/clang/lib/Frontend/CompileJobCache.cpp @@ -18,9 +18,7 @@ #include "llvm/CAS/ActionCache.h" #include "llvm/CAS/CASOutputBackend.h" #include "llvm/CASUtil/Utils.h" -#if LLVM_ENABLE_MCCAS #include "llvm/MCCAS/MCCASObjectV1.h" -#endif #include "llvm/RemoteCachingService/Client.h" #include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/Path.h" @@ -824,7 +822,6 @@ Expected> ObjectStoreCachingOutputs::replayCachedResult( if (WriteOutputAsCASID) llvm::cas::writeCASIDBuffer(CAS.getID(O.Object), *Output); else if (UseCASBackend) { -#if LLVM_ENABLE_MCCAS // Replay by write out object file. // When the environmental variable is set, save the backend CASID for // analysis later. @@ -841,9 +838,6 @@ Expected> ObjectStoreCachingOutputs::replayCachedResult( auto Schema = std::make_unique(CAS); if (auto E = Schema->serializeObjectFile(*Obj, *Output)) return E; -#else - llvm_unreachable("MCCAS disabled"); -#endif } return Output->keep(); } diff --git a/clang/test/CAS/cas-backend.c b/clang/test/CAS/cas-backend.c index de7589c2dafe1..662c45b0f7212 100644 --- a/clang/test/CAS/cas-backend.c +++ b/clang/test/CAS/cas-backend.c @@ -1,4 +1,3 @@ -// REQUIRES: mccas // RUN: rm -rf %t && mkdir -p %t // RUN: llvm-cas --cas %t/cas --ingest %s > %t/casid // diff --git a/clang/test/CAS/cas-emit-casid.c b/clang/test/CAS/cas-emit-casid.c index 3b1811592d3ad..e5598a161d923 100644 --- a/clang/test/CAS/cas-emit-casid.c +++ b/clang/test/CAS/cas-emit-casid.c @@ -1,4 +1,4 @@ -// REQUIRES: aarch64-registered-target && mccas +// REQUIRES: aarch64-registered-target // RUN: rm -rf %t && mkdir -p %t // RUN: %clang -target arm64-apple-macosx12.0.0 -c -Xclang -fcas-backend -Xclang -fcas-path -Xclang %t/cas -Xclang -fcas-backend-mode=native -Xclang -fcas-emit-casid-file %s -o %t/test.o // RUN: cat %t/test.o.casid | FileCheck %s --check-prefix=NATIVE_FILENAME diff --git a/clang/test/CAS/depscan-update-mccas.c b/clang/test/CAS/depscan-update-mccas.c index 4b16f758bcdc3..c9cd52c67f6eb 100644 --- a/clang/test/CAS/depscan-update-mccas.c +++ b/clang/test/CAS/depscan-update-mccas.c @@ -1,4 +1,3 @@ -// REQUIRES: mccas // RUN: %clang -cc1depscan -o - -cc1-args -cc1 -triple \ // RUN: x86_64-apple-darwin10 -debug-info-kind=standalone -dwarf-version=4 \ // RUN: -debugger-tuning=lldb -emit-obj -fcas-backend -fcas-path %t/cas \ diff --git a/clang/test/CAS/remote-cache-incompatible-options.c b/clang/test/CAS/remote-cache-incompatible-options.c index 61c4fc4a1b197..b15a3c98b18f6 100644 --- a/clang/test/CAS/remote-cache-incompatible-options.c +++ b/clang/test/CAS/remote-cache-incompatible-options.c @@ -1,4 +1,3 @@ -// REQUIRES: mccas // RUN: not %clang_cc1 -triple x86_64-apple-macos11 -fcompilation-caching-service-path %t -fcas-backend -fcasid-output -emit-obj %s -o %t.o 2>&1 | FileCheck %s // CHECK: error: '-fcas-backend' is incompatible with remote caching backend // CHECK: error: '-fcasid-output' is incompatible with remote caching backend diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 90e008bd365df..f752bf10648ca 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -149,13 +149,6 @@ if(LLVM_INCLUDE_SPIRV_TOOLS_TESTS) ) endif() -if (LLVM_ENABLE_MCCAS) - set(MCCAS_DEPS - llvm-cas-object-format - llvm-cas-dump - ) -endif() - if( NOT CLANG_BUILT_STANDALONE ) list(APPEND CLANG_TEST_DEPS llvm-config @@ -166,7 +159,7 @@ if( NOT CLANG_BUILT_STANDALONE ) llvm-as llvm-bcanalyzer llvm-cas - ${MCCAS_DEPS} + llvm-cas-dump llvm-cat llvm-cxxfilt llvm-dis diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt index 3f3b80e7901a8..10a24b2cbe764 100644 --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -905,7 +905,6 @@ option(LLVM_CAS_ENABLE_REMOTE_CACHE "Build remote CAS service" OFF) if(LLVM_CAS_ENABLE_REMOTE_CACHE) include(FindGRPC) endif() -option(LLVM_ENABLE_MCCAS "Build MCCAS backend" OFF) set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/llvm/doxygen-html" CACHE STRING "Doxygen-generated HTML documentation install directory") diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt index d9c387a8a65c9..080c435e98cf9 100644 --- a/llvm/lib/CMakeLists.txt +++ b/llvm/lib/CMakeLists.txt @@ -25,9 +25,7 @@ add_subdirectory(Linker) add_subdirectory(Analysis) add_subdirectory(LTO) add_subdirectory(MC) -if (LLVM_ENABLE_MCCAS) - add_subdirectory(MCCAS) -endif() +add_subdirectory(MCCAS) add_subdirectory(MCA) add_subdirectory(ObjCopy) add_subdirectory(Object) diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt index a47b482e748ac..f3c33db6a3fac 100644 --- a/llvm/lib/CodeGen/CMakeLists.txt +++ b/llvm/lib/CodeGen/CMakeLists.txt @@ -1,10 +1,3 @@ -if (LLVM_ENABLE_MCCAS) - add_definitions(-DLLVM_ENABLE_MCCAS=1) - set(MCCAS_DEPS - MCCAS - ) -endif() - if (DEFINED LLVM_HAVE_TF_AOT OR LLVM_HAVE_TFLITE) include(TensorFlowCompile) set(LLVM_RAEVICT_MODEL_PATH_DEFAULT "models/regalloc-eviction") @@ -286,7 +279,7 @@ add_llvm_component_library(LLVMCodeGen Core MC ObjCARC - ${MCCAS_DEPS} + MCCAS ProfileData Scalar Support diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp index 3584a2ccc1a26..03aa2b84e1a5b 100644 --- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp +++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp @@ -23,20 +23,18 @@ #include "llvm/MC/MCContext.h" #include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCMachOCASWriter.h" #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/TargetRegistry.h" +#include "llvm/MCCAS/MCCASObjectV1.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Target/RegisterTargetPassConfigCallback.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -#if LLVM_ENABLE_MCCAS -#include "llvm/MC/MCMachOCASWriter.h" -#include "llvm/MCCAS/MCCASObjectV1.h" -#endif using namespace llvm; static cl::opt @@ -210,9 +208,7 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out, inconvertibleErrorCode()); Triple T(getTargetTriple()); -#if LLVM_ENABLE_MCCAS // BEGIN MCCAS - bool UseCASBackend = Options.UseCASBackend; std::unique_ptr CASBackendWriter; if (Options.UseCASBackend) { std::function CASBackendWriter; -#endif // END MCCAS AsmStreamer.reset(getTarget().createMCObjectStreamer( T, Context, std::unique_ptr(MAB), - UseCASBackend ? std::move(CASBackendWriter) // MCCAS + Options.UseCASBackend ? std::move(CASBackendWriter) // MCCAS : DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut) : MAB->createObjectWriter(Out), std::unique_ptr(MCE), STI)); diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt index 154ba367da8f3..4828ddd4811d5 100644 --- a/llvm/lib/MC/CMakeLists.txt +++ b/llvm/lib/MC/CMakeLists.txt @@ -1,7 +1,3 @@ -if (LLVM_ENABLE_MCCAS) - add_definitions(-DLLVM_ENABLE_MCCAS=1) -endif() - add_llvm_component_library(LLVMMC ConstantPools.cpp DXContainerPSVInfo.cpp diff --git a/llvm/lib/MC/MachOCASWriter.cpp b/llvm/lib/MC/MachOCASWriter.cpp index 23d8cd341bd80..921cddfa06539 100644 --- a/llvm/lib/MC/MachOCASWriter.cpp +++ b/llvm/lib/MC/MachOCASWriter.cpp @@ -23,6 +23,8 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbolMachO.h" #include "llvm/MC/MCValue.h" +#include "llvm/MCCAS/MCCASFormatSchemaBase.h" +#include "llvm/MCCAS/MCCASObjectV1.h" #include "llvm/Support/Alignment.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Casting.h" @@ -31,10 +33,6 @@ #include "llvm/Support/raw_ostream.h" #include -#if LLVM_ENABLE_MCCAS -#include "llvm/MCCAS/MCCASFormatSchemaBase.h" -#include "llvm/MCCAS/MCCASObjectV1.h" - using namespace llvm; using namespace llvm::cas; using namespace llvm::mccasformats; @@ -124,19 +122,3 @@ std::unique_ptr llvm::createMachOCASWriter( std::move(MOTW), TT, CAS, Mode, OS, IsLittleEndian, CreateFromMcAssembler, SerializeObjectFile, ResultCallBack, CasIDOS); } -#else -std::unique_ptr llvm::createMachOCASWriter( - std::unique_ptr MOTW, const Triple &TT, - cas::ObjectStore &CAS, CASBackendMode Mode, raw_pwrite_stream &OS, - bool IsLittleEndian, - std::function - CreateFromMcAssembler, - std::function - SerializeObjectFile, - std::optional ResultCallBack, - raw_pwrite_stream *CasIDOS) { - llvm_unreachable("unsupported"); -} -#endif diff --git a/llvm/test/CAS/emit-casid-file.ll b/llvm/test/CAS/emit-casid-file.ll index 7be885edee5c8..7c262cd84385b 100644 --- a/llvm/test/CAS/emit-casid-file.ll +++ b/llvm/test/CAS/emit-casid-file.ll @@ -24,7 +24,7 @@ ; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=%t/cas --mccas-casid %s --mccas-emit-casid-file -o - ; RUN: not cat %t/test.o.casid -; REQUIRES: aarch64-registered-target && mccas +; REQUIRES: aarch64-registered-target ; ModuleID = '/Users/shubham/Development/test109275485/a.cpp' source_filename = "/Users/shubham/Development/test109275485/a.cpp" diff --git a/llvm/test/CMakeLists.txt b/llvm/test/CMakeLists.txt index 1e13f0d452671..ba57b1047629f 100644 --- a/llvm/test/CMakeLists.txt +++ b/llvm/test/CMakeLists.txt @@ -27,7 +27,6 @@ llvm_canonicalize_cmake_booleans( LLVM_INCLUDE_DXIL_TESTS LLVM_ENABLE_ONDISK_CAS LLVM_CAS_ENABLE_REMOTE_CACHE - LLVM_ENABLE_MCCAS LLVM_TOOL_LLVM_DRIVER_BUILD LLVM_INCLUDE_SPIRV_SIMULATOR_TESTS LLVM_INCLUDE_SPIRV_TOOLS_TESTS @@ -60,13 +59,6 @@ configure_lit_site_cfg( "SHLIBDIR" ) -if (LLVM_ENABLE_MCCAS) - set(MCCAS_DEPS - llvm-cas-object-format - llvm-cas-dump - ) -endif() - # Set the depends list as a variable so that it can grow conditionally. # NOTE: Sync the substitutions in test/lit.cfg when adding to this list. set(LLVM_TEST_DEPENDS @@ -87,7 +79,8 @@ set(LLVM_TEST_DEPENDS llvm-bitcode-strip llvm-c-test llvm-cas - ${MCCAS_DEPS} + llvm-cas-dump + llvm-cas-object-format llvm-cas-test llvm-cat llvm-cfi-verify diff --git a/llvm/test/DebugInfo/CAS/AArch64/lit.local.cfg b/llvm/test/DebugInfo/CAS/AArch64/lit.local.cfg index 49c5885fcf191..102671146a4ae 100644 --- a/llvm/test/DebugInfo/CAS/AArch64/lit.local.cfg +++ b/llvm/test/DebugInfo/CAS/AArch64/lit.local.cfg @@ -1,4 +1,2 @@ if not "AArch64" in config.root.targets: - config.unsupported = True -if not config.have_mccas: - config.unsupported = True + config.unsupported = True \ No newline at end of file diff --git a/llvm/test/MC/CAS/lit.local.cfg b/llvm/test/MC/CAS/lit.local.cfg index 0928c4be89f1d..379945b68925d 100644 --- a/llvm/test/MC/CAS/lit.local.cfg +++ b/llvm/test/MC/CAS/lit.local.cfg @@ -1,4 +1,2 @@ if not config.have_ondisk_cas: config.unsupported = True -if not config.have_mccas: - config.unsupported = True diff --git a/llvm/test/lit.cfg.py b/llvm/test/lit.cfg.py index 118564ab93a14..bd74f6147df52 100644 --- a/llvm/test/lit.cfg.py +++ b/llvm/test/lit.cfg.py @@ -706,9 +706,6 @@ def host_unwind_supports_jit(): if config.have_ondisk_cas: config.available_features.add('ondisk_cas') -if config.have_mccas: - config.available_features.add('mccas') - if "MemoryWithOrigins" in config.llvm_use_sanitizer: config.available_features.add("use_msan_with_origins") diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in index 8fc6dc01825b2..db34a7812b6e2 100644 --- a/llvm/test/lit.site.cfg.py.in +++ b/llvm/test/lit.site.cfg.py.in @@ -63,7 +63,6 @@ config.reverse_iteration = @LLVM_ENABLE_REVERSE_ITERATION@ config.dxil_tests = @LLVM_INCLUDE_DXIL_TESTS@ config.have_ondisk_cas = @LLVM_ENABLE_ONDISK_CAS@ config.enable_remote_cache = @LLVM_CAS_ENABLE_REMOTE_CACHE@ -config.have_mccas = @LLVM_ENABLE_MCCAS@ config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@ config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@ config.have_vc_rev = @LLVM_APPEND_VC_REV@ diff --git a/llvm/test/tools/llvm-cas-dump/lit.local.cfg b/llvm/test/tools/llvm-cas-dump/lit.local.cfg deleted file mode 100644 index d3b98db1f755a..0000000000000 --- a/llvm/test/tools/llvm-cas-dump/lit.local.cfg +++ /dev/null @@ -1,2 +0,0 @@ -if not config.have_mccas: - config.unsupported = True diff --git a/llvm/test/tools/llvm-cas-object-format/lit.local.cfg b/llvm/test/tools/llvm-cas-object-format/lit.local.cfg deleted file mode 100644 index d3b98db1f755a..0000000000000 --- a/llvm/test/tools/llvm-cas-object-format/lit.local.cfg +++ /dev/null @@ -1,2 +0,0 @@ -if not config.have_mccas: - config.unsupported = True diff --git a/llvm/test/tools/llvm-cas/ingest-blobs-casid.test b/llvm/test/tools/llvm-cas/ingest-blobs-casid.test index bbac4269e1b48..b3ee24b89f00b 100644 --- a/llvm/test/tools/llvm-cas/ingest-blobs-casid.test +++ b/llvm/test/tools/llvm-cas/ingest-blobs-casid.test @@ -1,4 +1,4 @@ -; REQUIRES: aarch64-registered-target && mccas +; REQUIRES: aarch64-registered-target ; RUN: rm -rf %t && mkdir -p %t ; RUN: split-file %s %t diff --git a/llvm/tools/CMakeLists.txt b/llvm/tools/CMakeLists.txt index 385d177d2f0f7..73d4993194ece 100644 --- a/llvm/tools/CMakeLists.txt +++ b/llvm/tools/CMakeLists.txt @@ -40,18 +40,12 @@ add_llvm_tool_subdirectory(llvm-config) add_llvm_tool_subdirectory(llvm-ctxprof-util) add_llvm_tool_subdirectory(llvm-lto) add_llvm_tool_subdirectory(llvm-profdata) +add_llvm_tool_subdirectory(llvm-cas-dump) if(LLVM_CAS_ENABLE_REMOTE_CACHE) add_llvm_tool_subdirectory(llvm-remote-cache-test) else() set(LLVM_TOOL_LLVM_REMOTE_CACHE_TEST_BUILD Off) endif() -if(LLVM_ENABLE_MCCAS) - add_llvm_tool_subdirectory(llvm-cas-object-format) - add_llvm_tool_subdirectory(llvm-cas-dump) -else() - set(LLVM_TOOL_LLVM_CAS_OBJECT_FORMAT_BUILD Off) - set(LLVM_TOOL_LLVM_CAS_DUMP_BUILD Off) -endif() # Projects supported via LLVM_EXTERNAL_*_SOURCE_DIR need to be explicitly # specified. diff --git a/llvm/tools/llvm-mc/CMakeLists.txt b/llvm/tools/llvm-mc/CMakeLists.txt index 70004ceb4d4bf..55d8d9a779f59 100644 --- a/llvm/tools/llvm-mc/CMakeLists.txt +++ b/llvm/tools/llvm-mc/CMakeLists.txt @@ -1,10 +1,3 @@ -if (LLVM_ENABLE_MCCAS) - add_definitions(-DLLVM_ENABLE_MCCAS=1) - set(LLVM_LINK_MCCAS - MCCAS - ) -endif() - set(LLVM_LINK_COMPONENTS AllTargetsAsmParsers AllTargetsDescs @@ -12,7 +5,7 @@ set(LLVM_LINK_COMPONENTS AllTargetsInfos CAS MC - ${LLVM_LINK_MCCAS} + MCCAS MCParser Support TargetParser diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index 56feb139a8888..2c5bad9d6aeea 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -31,9 +31,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/MCTargetOptionsCommandFlags.h" #include "llvm/MC/TargetRegistry.h" -#if LLVM_ENABLE_MCCAS #include "llvm/MCCAS/MCCASObjectV1.h" -#endif #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compression.h" #include "llvm/Support/FileUtilities.h" @@ -681,7 +679,6 @@ int main(int argc, char **argv) { MCCodeEmitter *CE = TheTarget->createMCCodeEmitter(*MCII, Ctx); MCAsmBackend *MAB = TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions); -#if LLVM_ENABLE_MCCAS // BEGIN MCCAS std::unique_ptr CASBackendWriter; bool UseCASBackend = UseMCCASBackend || @@ -712,10 +709,6 @@ int main(int argc, char **argv) { CasIDOS ? &CasIDOS->os() : nullptr); } // END MCCAS -#else - bool UseCASBackend = false; - std::unique_ptr CASBackendWriter; -#endif Str.reset(TheTarget->createMCObjectStreamer( TheTriple, Ctx, std::unique_ptr(MAB), UseCASBackend ? std::move(CASBackendWriter) // MCCAS From d153b52d40724012a99607269c6112c21050951e Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Thu, 14 Aug 2025 12:00:35 -0700 Subject: [PATCH 02/22] Remove MCPseudoProbeAddrFragment from MCCASObjectV1.def The MCPseudoProbeAddrFragment type has been removed as a type of fragment and has been merged with the MCLEBFragment. --- llvm/include/llvm/MCCAS/MCCASObjectV1.def | 1 - 1 file changed, 1 deletion(-) diff --git a/llvm/include/llvm/MCCAS/MCCASObjectV1.def b/llvm/include/llvm/MCCAS/MCCASObjectV1.def index df630e851dd35..aab14eda7012f 100644 --- a/llvm/include/llvm/MCCAS/MCCASObjectV1.def +++ b/llvm/include/llvm/MCCAS/MCCASObjectV1.def @@ -88,7 +88,6 @@ MCFRAGMENT_NODE_REF(MCRelaxableFragment, FT_Relaxable, mc:relaxable) MCFRAGMENT_NODE_REF(MCDwarfLineAddrFragment, FT_Dwarf, mc:dwarf) MCFRAGMENT_NODE_REF(MCDwarfCallFrameFragment, FT_DwarfFrame, mc:dwarf_frame) MCFRAGMENT_NODE_REF(MCCVDefRangeFragment, FT_CVDefRange, mc:cv_def_range) -MCFRAGMENT_NODE_REF(MCPseudoProbeAddrFragment, FT_PseudoProbe, mc:presudo_pro) #undef MCFRAGMENT_NODE_REF #endif /* MCFRAGMENT_NODE_REF */ From 123de10c741df4cad2b75a85372d8fdbeef10b70 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Thu, 14 Aug 2025 12:03:29 -0700 Subject: [PATCH 03/22] Remove MCSectionCAS class functions that no longer exist in the base class The MCSection class has been refactored to no longer have printSwitchToSection, and useCodeAlign function. It also no longer can contain a classof function. This change removes these functions to make it compile properly again. --- llvm/include/llvm/MCCAS/MCCASReader.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/llvm/include/llvm/MCCAS/MCCASReader.h b/llvm/include/llvm/MCCAS/MCCASReader.h index 161a22fabfd63..bc06165690312 100644 --- a/llvm/include/llvm/MCCAS/MCCASReader.h +++ b/llvm/include/llvm/MCCAS/MCCASReader.h @@ -44,18 +44,6 @@ class MCSectionCAS : public MCSection { public: MCSectionCAS(StringRef Name, SectionKind K); virtual ~MCSectionCAS() {} - - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override { - llvm_unreachable("unsupported from CAS"); - } - - bool useCodeAlign() const override { - llvm_unreachable("unsupported from CAS"); - } - - static bool classof(const MCSection *S) { return S->getVariant() == SV_CAS; } }; class MCFragmentCAS : public MCFragment { From d110481975d7079240ea249e9659484a4ff055f1 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 09:31:33 -0700 Subject: [PATCH 04/22] Change MCFRAGMENT_NODE_REF to use MCFragment The create function in the MCFRAGMENT_NODE_REF macro has to take an MCFragment object because of the changes in MCFragment which removed the concept that different fragment types would have their own class. --- llvm/include/llvm/MCCAS/MCCASObjectV1.h | 4 ++-- llvm/lib/MCCAS/MCCASObjectV1.cpp | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/MCCAS/MCCASObjectV1.h b/llvm/include/llvm/MCCAS/MCCASObjectV1.h index 6cce778a8e803..2aaf858ebd247 100644 --- a/llvm/include/llvm/MCCAS/MCCASObjectV1.h +++ b/llvm/include/llvm/MCCAS/MCCASObjectV1.h @@ -392,7 +392,7 @@ class SpecificRef : public MCObjectProxy { public: \ static constexpr StringLiteral KindString = #MCEnumIdentifier; \ static Expected \ - create(MCCASBuilder &MB, const MCFragmentName &Fragment, \ + create(MCCASBuilder &MB, const MCFragment &Fragment, \ unsigned FragmentSize, ArrayRef FragmentContents); \ static Expected get(Expected Ref) { \ auto Specific = SpecificRefT::getSpecific(std::move(Ref)); \ @@ -404,7 +404,7 @@ class SpecificRef : public MCObjectProxy { cas::ObjectRef ID) { \ return get(Schema.get(ID)); \ } \ - static std::optional Cast(MCObjectProxy Ref) { \ + static std::optional Cast(MCObjectProxy Ref) { \ auto Specific = SpecificRefT::Cast(Ref); \ if (!Specific) \ return std::nullopt; \ diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 0d4861d4a5f94..c2883325c5ec1 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1776,7 +1776,7 @@ MCSymbolIdFragmentRef::materialize(MCCASReader &Reader, #define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \ Expected MCFragmentName##Ref::create( \ - MCCASBuilder &MB, const MCFragmentName &F, unsigned FragmentSize, \ + MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, \ ArrayRef FragmentContents) { \ Expected B = Builder::startNode(MB.Schema, KindString); \ if (!B) \ @@ -1849,8 +1849,7 @@ Error MCCASBuilder::buildFragment(const MCFragment &F, unsigned Size, switch (F.getKind()) { #define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \ case MCFragment::MCEnumName: { \ - const MCFragmentName &SF = cast(F); \ - auto FN = MCFragmentName##Ref::create(*this, SF, Size, FragmentContents); \ + auto FN = MCFragmentName##Ref::create(*this, F, Size, FragmentContents); \ if (!FN) \ return FN.takeError(); \ addNode(*FN); \ From 503da2761d868b92f44d96c3511bd146593561ee Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 09:43:30 -0700 Subject: [PATCH 05/22] Fix the MCAlignFramgnetRef class. The MCAlignFragment class has been removed from MCSection.h and the Align Fragment is now part of the MCFragment class. The Align fragment has also been significantly changed. In the past, the Align fragment would only contain alignment data, however, now it can also contain regular data as well (similar to an MCDataFragment, but with alignment data as well). This patch makes the necessary changes to make MCCAS work properly with the new MCAlignFragment. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 74 +++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index c2883325c5ec1..41ab21389a894 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1532,17 +1532,19 @@ Expected AtomRef::materialize(MCCASReader &Reader, } Expected -MCAlignFragmentRef::create(MCCASBuilder &MB, const MCAlignFragment &F, +MCAlignFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, ArrayRef FragmentContents) { Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); - uint64_t Count = FragmentSize / F.getFillLen(); - if (F.hasEmitNops()) { - // Write 0 as size and use backend to emit nop. - writeVBR8(0, B->Data); + writeVBR8(FragmentContents.size(), B->Data); + B->Data.append(FragmentContents.begin(), FragmentContents.end()); + uint64_t Count = (FragmentSize - F.getFixedSize()) / F.getAlignFillLen(); + if (F.hasAlignEmitNops()) { + // Write 1 to signify that it has nops. + B->Data.push_back(1); if (!MB.Asm.getBackend().writeNopData(MB.FragmentOS, Count, F.getSubtargetInfo())) report_fatal_error("unable to write nop sequence of " + Twine(Count) + @@ -1550,25 +1552,37 @@ MCAlignFragmentRef::create(MCCASBuilder &MB, const MCAlignFragment &F, B->Data.append(MB.FragmentData); return get(B->build()); } + // Write 0 to signify that it doesn't have nops. + B->Data.push_back(0); writeVBR8(Count, B->Data); - writeVBR8(F.getFill(), B->Data); - writeVBR8(F.getFillLen(), B->Data); + writeVBR8(F.getAlignFill(), B->Data); + writeVBR8(F.getAlignFillLen(), B->Data); return get(B->build()); } Expected MCAlignFragmentRef::materialize(MCCASReader &Reader, raw_ostream *Stream) const { - uint64_t Count; + uint64_t Count, FragContentSize, HasNops; auto Remaining = getData(); auto Endian = Reader.getEndian(); - if (auto E = consumeVBR8(Remaining, Count)) + if (auto E = consumeVBR8(Remaining, FragContentSize)) return std::move(E); + *Stream << Remaining.substr(0, FragContentSize); + Remaining = Remaining.drop_front(FragContentSize); + + HasNops = Remaining[0]; + Remaining = Remaining.drop_front(); + // hasEmitNops. - if (!Count) { + if (HasNops) { *Stream << Remaining; - return Remaining.size(); + return Remaining.size() + FragContentSize; } + + if (auto E = consumeVBR8(Remaining, Count)) + return std::move(E); + int64_t Value; unsigned ValueSize; if (auto E = consumeVBR8(Remaining, Value)) @@ -1594,7 +1608,7 @@ Expected MCAlignFragmentRef::materialize(MCCASReader &Reader, break; } } - return Count * ValueSize; + return (Count * ValueSize) + FragContentSize; } Expected MCBoundaryAlignFragmentRef::create( @@ -1918,11 +1932,16 @@ Error MCDataFragmentMerger::tryMerge(const MCFragment &F, unsigned Size, return Error::success(); } -static Error writeAlignFragment(MCCASBuilder &Builder, - const MCAlignFragment &AF, raw_ostream &OS, - unsigned FragmentSize) { - uint64_t Count = FragmentSize / AF.getFillLen(); - if (AF.hasEmitNops()) { +static Error writeAlignFragment(MCCASBuilder &Builder, const MCFragment &AF, + raw_ostream &OS, unsigned FragmentSize, + bool WriteFragmentContents = true) { + // Do not always write the contents of the FT_Align fragment into the OS, this + // is because that data can contain addend values as well and is undesirable + // when creating AlignFragment CAS Objects. + if (WriteFragmentContents) + OS << StringRef(AF.getContents().data(), AF.getContents().size()); + uint64_t Count = (FragmentSize - AF.getFixedSize()) / AF.getAlignFillLen(); + if (AF.hasAlignEmitNops()) { if (!Builder.Asm.getBackend().writeNopData(OS, Count, AF.getSubtargetInfo())) return createStringError(inconvertibleErrorCode(), @@ -1933,20 +1952,20 @@ static Error writeAlignFragment(MCCASBuilder &Builder, auto Endian = Builder.ObjectWriter.Target.isLittleEndian() ? endianness::little : endianness::big; for (uint64_t I = 0; I != Count; ++I) { - switch (AF.getFillLen()) { + switch (AF.getAlignFillLen()) { default: llvm_unreachable("Invalid size!"); case 1: - OS << char(AF.getFill()); + OS << char(AF.getAlignFill()); break; case 2: - support::endian::write(OS, AF.getFill(), Endian); + support::endian::write(OS, AF.getAlignFill(), Endian); break; case 4: - support::endian::write(OS, AF.getFill(), Endian); + support::endian::write(OS, AF.getAlignFill(), Endian); break; case 8: - support::endian::write(OS, AF.getFill(), Endian); + support::endian::write(OS, AF.getAlignFill(), Endian); break; } } @@ -1978,9 +1997,14 @@ Error MCDataFragmentMerger::emitMergedFragments() { #define MCFRAGMENT_ENCODED_FRAGMENT_ONLY #include "llvm/MCCAS/MCCASObjectV1.def" case MCFragment::FT_Align: { - const MCAlignFragment *AF = cast(Candidate.first); - if (auto E = - writeAlignFragment(Builder, *AF, FragmentOS, Candidate.second)) + // Since an FT_Align can contain Addend Values, only write the + // post-fragment partitioned contents into the FragmentData and make sure + // that the writeAlignFragment function doesn't write any of the fragment + // data into FragmentData. + FragmentData.append(CandidateContents); + if (auto E = writeAlignFragment(Builder, *Candidate.first, FragmentOS, + Candidate.second, + false /*WriteFragmentContents*/)) return E; break; } From a056b21ae63e606a7753f186bd4d668142c018d9 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 09:59:39 -0700 Subject: [PATCH 06/22] Fix MCBoundaryAlignFragmentRef::create. Since the create function in MCFRAGMENT_NODE_REF just takes an MCFragment object as an argument, this change just makes the change for MCBoundaryAlignFragmentRef::create. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 41ab21389a894..6053be4cca8f3 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1611,9 +1611,10 @@ Expected MCAlignFragmentRef::materialize(MCCASReader &Reader, return (Count * ValueSize) + FragContentSize; } -Expected MCBoundaryAlignFragmentRef::create( - MCCASBuilder &MB, const MCBoundaryAlignFragment &F, unsigned FragmentSize, - ArrayRef FragmentContents) { +Expected +MCBoundaryAlignFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, + unsigned FragmentSize, + ArrayRef FragmentContents) { Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); From 7d40b407a11526a6d165ae4b8ce4742909765299 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:01:18 -0700 Subject: [PATCH 07/22] Fix MCCVInlineLineTableFragmentRef::create. Since the create function in MCFRAGMENT_NODE_REF just takes an MCFragment object as an argument, this change just makes the change for MCCVInlineLineTableFragmentRef::create. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 6053be4cca8f3..222c7688c3899 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1633,9 +1633,10 @@ MCBoundaryAlignFragmentRef::materialize(MCCASReader &Reader, return getData().size(); } -Expected MCCVInlineLineTableFragmentRef::create( - MCCASBuilder &MB, const MCCVInlineLineTableFragment &F, - unsigned FragmentSize, ArrayRef FragmentContents) { +Expected +MCCVInlineLineTableFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, + unsigned FragmentSize, + ArrayRef FragmentContents) { Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); From f4591522b6825f02fbdfac907b41fd169ed40974 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:05:53 -0700 Subject: [PATCH 08/22] Fix MCFillFragmentRef::create. Since the create function in MCFRAGMENT_NODE_REF just takes an MCFragment object as an argument, this change just makes the necessary changes for MCFillFragmentRef::create. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 222c7688c3899..142b37c6e28b5 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1652,15 +1652,16 @@ MCCVInlineLineTableFragmentRef::materialize(MCCASReader &Reader, } Expected -MCFillFragmentRef::create(MCCASBuilder &MB, const MCFillFragment &F, +MCFillFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, ArrayRef FragmentContents) { + auto *FillFrag = cast(&F); Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); writeVBR8(FragmentSize, B->Data); - writeVBR8(F.getValue(), B->Data); - writeVBR8(F.getValueSize(), B->Data); + writeVBR8(FillFrag->getValue(), B->Data); + writeVBR8(FillFrag->getValueSize(), B->Data); return get(B->build()); } From 938bd1a175410d643481fb6c52eb7cfccd1cad41 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:07:24 -0700 Subject: [PATCH 09/22] Fix MCLEBFragmentRef::create. Since the create function in MCFRAGMENT_NODE_REF just takes an MCFragment object as an argument, this change just makes the change for MCLEBFragmentRef::create. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 142b37c6e28b5..bb137e0a2c3af 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1703,7 +1703,7 @@ Expected MCFillFragmentRef::materialize(MCCASReader &Reader, } Expected -MCLEBFragmentRef::create(MCCASBuilder &MB, const MCLEBFragment &F, +MCLEBFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, ArrayRef FragmentContents) { Expected B = Builder::startNode(MB.Schema, KindString); From 90bbe0e146264a8e1018112c84ff7aaab2abef3a Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:09:09 -0700 Subject: [PATCH 10/22] Fix MCNopsFragmentRef::create. Since the create function in MCFRAGMENT_NODE_REF just takes an MCFragment object as an argument, this change just makes the necessary changes for MCNopsFragmentRef::create. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index bb137e0a2c3af..fad750521f0b2 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1720,14 +1720,15 @@ Expected MCLEBFragmentRef::materialize(MCCASReader &Reader, } Expected -MCNopsFragmentRef::create(MCCASBuilder &MB, const MCNopsFragment &F, +MCNopsFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, ArrayRef FragmentContents) { + auto *NopsFrag = dyn_cast(&F); Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); - int64_t NumBytes = F.getNumBytes(); - int64_t ControlledNopLength = F.getControlledNopLength(); + int64_t NumBytes = NopsFrag->getNumBytes(); + int64_t ControlledNopLength = NopsFrag->getControlledNopLength(); int64_t MaximumNopLength = MB.Asm.getBackend().getMaximumNopSize(*F.getSubtargetInfo()); if (ControlledNopLength > MaximumNopLength) From 1820640a6676c9f72d2a744258d8ba7d373ef804 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Tue, 19 Aug 2025 14:33:24 -0700 Subject: [PATCH 11/22] MCNopsFragment change dyn_cast to cast --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index fad750521f0b2..5e5d422e2349c 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1723,7 +1723,7 @@ Expected MCNopsFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, ArrayRef FragmentContents) { - auto *NopsFrag = dyn_cast(&F); + auto *NopsFrag = cast(&F); Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); From f89dc82f58e28714a86acac566dba015aec3a92b Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:10:52 -0700 Subject: [PATCH 12/22] Fix MCOrgFragmentRef::create. Since the create function in MCFRAGMENT_NODE_REF just takes an MCFragment object as an argument, this change just makes the necessary changes for MCOrgFragmentRef::create. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 5e5d422e2349c..0540b5ce7701b 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1757,14 +1757,15 @@ Expected MCNopsFragmentRef::materialize(MCCASReader &Reader, } Expected -MCOrgFragmentRef::create(MCCASBuilder &MB, const MCOrgFragment &F, +MCOrgFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, ArrayRef FragmentContents) { + auto *OrgFrag = cast(&F); Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); writeVBR8(FragmentSize, B->Data); - writeVBR8((char)F.getValue(), B->Data); + writeVBR8((char)OrgFrag->getValue(), B->Data); return get(B->build()); } From c713356a964ca7ea35623ac516e913e3d45f5473 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:14:00 -0700 Subject: [PATCH 13/22] Fix MCSymbolIdFragmentRef::create. Since the create function in MCFRAGMENT_NODE_REF just takes an MCFragment object as an argument, this change just makes the necessary changes for MCSymbolIdFragmentRef::create. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 0540b5ce7701b..51fb07c4fc59b 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1776,13 +1776,14 @@ Expected MCOrgFragmentRef::materialize(MCCASReader &Reader, } Expected -MCSymbolIdFragmentRef::create(MCCASBuilder &MB, const MCSymbolIdFragment &F, +MCSymbolIdFragmentRef::create(MCCASBuilder &MB, const MCFragment &F, unsigned FragmentSize, ArrayRef FragmentContents) { + auto *SymbolIDFrag = cast(&F); Expected B = Builder::startNode(MB.Schema, KindString); if (!B) return B.takeError(); - writeVBR8(F.getSymbol()->getIndex(), B->Data); + writeVBR8(SymbolIDFrag->getSymbol()->getIndex(), B->Data); return get(B->build()); } From c31be192e619a0f78071449ba8bd42fa211fa25a Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:21:00 -0700 Subject: [PATCH 14/22] Fix getFragmentContents() function. The MCFragments have been changed, they can now have both a fixed content and a variable content as well. This patch makes the necessary changes to the getFragmentContents() function to make it work properly. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 51fb07c4fc59b..05b011cb6a6a3 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -2889,26 +2889,40 @@ Error MCCASBuilder::createAppleObjCSection() { return finalizeSection(); } -static ArrayRef getFragmentContents(const MCFragment &Fragment) { +static void getFragmentContents(const MCFragment &Fragment, + SmallVectorImpl &FragContents) { switch (Fragment.getKind()) { #define MCFRAGMENT_NODE_REF(MCFragmentName, MCEnumName, MCEnumIdentifier) \ case MCFragment::MCEnumName: { \ - const MCFragmentName &SF = cast(Fragment); \ - return SF.getContents(); \ + FragContents.append(Fragment.getContents().begin(), \ + Fragment.getContents().end()); \ + FragContents.append(Fragment.getVarContents().begin(), \ + Fragment.getVarContents().end()); \ + return; \ } #define MCFRAGMENT_ENCODED_FRAGMENT_ONLY #include "llvm/MCCAS/MCCASObjectV1.def" case MCFragment::FT_CVInlineLines: { const MCCVInlineLineTableFragment &SF = cast(Fragment); - return SF.getContents(); + FragContents.append(SF.getContents().begin(), SF.getContents().end()); + FragContents.append(SF.getVarContents().begin(), SF.getVarContents().end()); + return; } case MCFragment::FT_LEB: { - const MCLEBFragment &SF = cast(Fragment); - return SF.getContents(); + FragContents.append(Fragment.getContents().begin(), + Fragment.getContents().end()); + FragContents.append(Fragment.getVarContents().begin(), + Fragment.getVarContents().end()); + return; + } + case MCFragment::FT_Align: { + FragContents.append(Fragment.getContents().begin(), + Fragment.getContents().end()); + return; } default: - return ArrayRef(); + return; } } @@ -2940,7 +2954,8 @@ partitionFragment(MCAssembler &Asm, SmallVector &Addends, ArrayRef RelocationBuffer, const MCFragment &Fragment, uint64_t &RelocationBufferIndex, bool IsLittleEndian) { - auto FragmentContents = getFragmentContents(Fragment); + SmallVector FragmentContents; + getFragmentContents(Fragment, FragmentContents); /// FragmentIndex: It denotes the index into the FragmentContents that is used /// to copy the data that deduplicates in the \p FinalFragmentContents. uint64_t FragmentIndex = 0; From 13f4493cf317cd0fadfb569789f03862414a90e2 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:33:51 -0700 Subject: [PATCH 15/22] Fix MCCASBuilder::mergeMCFragmentContents MCCASBuilder::mergeMCFragmentContents merges all content from all the fragments in a section into one buffer. However, since the way content is stored in a fragemnts has changed, this function had to be updated as well. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 52 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 05b011cb6a6a3..3e5f70fd36a67 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -2153,43 +2153,37 @@ Expected> MCCASBuilder::mergeMCFragmentContents(const MCSection *Section, bool IsDebugLineSection) { SmallVector mergedData; + if (!Section->curFragList()) + return mergedData; for (const MCFragment &Fragment : *Section) { - if (const auto *DataFragment = dyn_cast(&Fragment)) - llvm::append_range(mergedData, DataFragment->getContents()); - else if (const auto *RelaxableFragment = - dyn_cast(&Fragment)) - llvm::append_range(mergedData, RelaxableFragment->getContents()); - else if (const auto *DwarfLineAddrFrag = - dyn_cast(&Fragment)) - if (IsDebugLineSection) - llvm::append_range(mergedData, DwarfLineAddrFrag->getContents()); - else + if (Fragment.getKind() == MCFragment::FT_Dwarf) { + if (IsDebugLineSection) { + llvm::append_range(mergedData, Fragment.getContents()); + llvm::append_range(mergedData, Fragment.getVarContents()); + } else return createStringError( inconvertibleErrorCode(), - "Invalid MCDwarfLineAddrFragment in a non debug line section"); - else if (const auto *DwarfCallFrameFragment = - dyn_cast(&Fragment)) - llvm::append_range(mergedData, DwarfCallFrameFragment->getContents()); - else if (const auto *CVDefRangeFragment = - dyn_cast(&Fragment)) + "Invalid MCFragment::FT_Dwarf type in a non debug line section"); + } else if (const auto *CVDefRangeFragment = + dyn_cast(&Fragment)) { llvm::append_range(mergedData, CVDefRangeFragment->getContents()); - else if (const auto *PseudoProbeAddrFragment = - dyn_cast(&Fragment)) - llvm::append_range(mergedData, PseudoProbeAddrFragment->getContents()); - else if (const auto *LEBFragment = dyn_cast(&Fragment)) - llvm::append_range(mergedData, LEBFragment->getContents()); - else if (const auto *CVInlineLineTableFragment = - dyn_cast(&Fragment)) + llvm::append_range(mergedData, CVDefRangeFragment->getVarContents()); + } else if (const auto *CVInlineLineTableFragment = + dyn_cast(&Fragment)) { llvm::append_range(mergedData, CVInlineLineTableFragment->getContents()); - else if (const auto *AlignFragment = dyn_cast(&Fragment)) { + llvm::append_range(mergedData, + CVInlineLineTableFragment->getVarContents()); + } else if (Fragment.getKind() == MCFragment::FT_Align) { auto FragmentSize = Asm.computeFragmentSize(Fragment); raw_svector_ostream OS(mergedData); - if (auto E = writeAlignFragment(*this, *AlignFragment, OS, FragmentSize)) + if (auto E = writeAlignFragment(*this, Fragment, OS, FragmentSize)) return std::move(E); - } else - // All other fragment types can be considered empty, see - // getFragmentContents() for all fragments that have contents. - continue; + } else { + if (Fragment.getFixedSize() != 0) + llvm::append_range(mergedData, Fragment.getContents()); + if (Fragment.getVarSize() != 0) + llvm::append_range(mergedData, Fragment.getVarContents()); + } } return mergedData; } From 15a9813558ce11f7b355cae282b5e6ad712435f4 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:38:39 -0700 Subject: [PATCH 16/22] Update bool IsMergeableFragment. There is no concept on an EncodedFragment anymore, hence we have to list all fragments that are mergeable. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 3e5f70fd36a67..fbcf72c653411 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -1905,8 +1905,12 @@ Error MCDataFragmentMerger::tryMerge(const MCFragment &F, unsigned Size, bool IsSameAtom = Builder.getCurrentAtom() == F.getAtom(); bool Oversized = CurrentSize + Size > MCDataMergeThreshold; // TODO: Try merge align fragment? - bool IsMergeableFragment = - isa(F) || isa(F); + bool IsMergeableFragment = F.getKind() == MCFragment::FT_Relaxable || + F.getKind() == MCFragment::FT_Data || + F.getKind() == MCFragment::FT_Dwarf || + F.getKind() == MCFragment::FT_DwarfFrame || + F.getKind() == MCFragment::FT_Align; + // If not the same atom, flush merge candidate and return false. if (!IsSameAtom || !IsMergeableFragment || Oversized) { if (auto E = emitMergedFragments()) From d2de518aeeae09f8b3fcdddaf7f0b7328a0e0e9c Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:40:35 -0700 Subject: [PATCH 17/22] Remove cast to MCDataFragment. There is no class called MCDataFragment, it has been folded into the MCFragment class. Change the cast to cast. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index fbcf72c653411..7251e9beb5e8b 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -2635,7 +2635,7 @@ Expected> MCCASBuilder::createDebugStringRefs() { SmallVector DebugStringRefs; ArrayRef DebugStrData = - cast(*DwarfSections.Str->begin()).getContents(); + cast(*DwarfSections.Str->begin()).getContents(); StringRef S(DebugStrData.data(), DebugStrData.size()); if (auto E = createStringSection(S, [&](StringRef S) -> Error { auto Sym = DebugStrRef::create(*this, S); From 0ee0638149de558cf77850d9cbea9c4261f47322 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:41:51 -0700 Subject: [PATCH 18/22] Change isVirtualSection to isBssSection --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index 7251e9beb5e8b..e6eb53887eb8e 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -3002,7 +3002,7 @@ Error MCCASBuilder::buildFragments() { startGroup(); for (const MCSection &Sec : Asm) { - if (Sec.isVirtualSection()) + if (Sec.isBssSection()) continue; // Handle Debug Info sections separately. From 9a11cc172e646a0df3482c01053ee1787b9cc5ff Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 10:44:11 -0700 Subject: [PATCH 19/22] Fix any broken tests --- .../test/DebugInfo/CAS/AArch64/debug_unopt.ll | 86 +++++++++---------- llvm/test/tools/llvm-cas-dump/stats-dump.test | 2 + 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/llvm/test/DebugInfo/CAS/AArch64/debug_unopt.ll b/llvm/test/DebugInfo/CAS/AArch64/debug_unopt.ll index 7fc30b245fae2..651cb0fe58397 100644 --- a/llvm/test/DebugInfo/CAS/AArch64/debug_unopt.ll +++ b/llvm/test/DebugInfo/CAS/AArch64/debug_unopt.ll @@ -2,49 +2,49 @@ ; RUN: llc -debug-info-unopt -O0 --filetype=obj --cas-backend --cas=%t/cas --mccas-casid --mtriple=arm64-apple-darwin %s -o %t/debug_unopt.id ; RUN: llvm-cas-dump --cas=%t/cas --casid-file %t/debug_unopt.id | FileCheck %s -; CHECK: mc:assembler llvmcas:// -; CHECK-NEXT: mc:header llvmcas:// -; CHECK-NEXT: mc:group llvmcas:// -; CHECK-NEXT: mc:section llvmcas:// -; CHECK-NEXT: mc:atom llvmcas:// -; CHECK-NEXT: mc:atom llvmcas:// -; CHECK-NEXT: mc:data llvmcas:// -; CHECK-NEXT: mc:atom llvmcas:// -; CHECK-NEXT: mc:data llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:debug_abbrev_section llvmcas:// -; CHECK-NEXT: mc:debug_abbrev_unopt llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:debug_info_section llvmcas:// -; CHECK-NEXT: mc:debug_info_unopt llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:debug_string_section llvmcas:// -; CHECK-NEXT: mc:debug_string llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:apple_names_section llvmcas:// -; CHECK-NEXT: mc:apple_names llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:apple_objc_section llvmcas:// -; CHECK-NEXT: mc:apple_objc llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:apple_namepsac_section llvmcas:// -; CHECK-NEXT: mc:apple_namespac llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:apple_types_section llvmcas:// -; CHECK-NEXT: mc:apple_types llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:section llvmcas:// -; CHECK-NEXT: mc:atom llvmcas:// -; CHECK-NEXT: mc:atom llvmcas:// -; CHECK-NEXT: mc:data llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:addends llvmcas:// -; CHECK-NEXT: mc:debug_line_section llvmcas:// -; CHECK-NEXT: mc:debug_line_unopt llvmcas:// -; CHECK-NEXT: mc:padding llvmcas:// -; CHECK-NEXT: mc:data_in_code llvmcas:// -; CHECK-NEXT: mc:symbol_table llvmcas:// -; CHECK-NEXT: mc:cstring llvmcas:// +;CHECK: mc:assembler llvmcas:// +;CHECK-NEXT: mc:header llvmcas:// +;CHECK-NEXT: mc:group llvmcas:// +;CHECK-NEXT: mc:section llvmcas:// +;CHECK-NEXT: mc:atom llvmcas:// +;CHECK-NEXT: mc:atom llvmcas:// +;CHECK-NEXT: mc:align llvmcas:// +;CHECK-NEXT: mc:atom llvmcas:// +;CHECK-NEXT: mc:data llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:debug_abbrev_section llvmcas:// +;CHECK-NEXT: mc:debug_abbrev_unopt llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:debug_info_section llvmcas:// +;CHECK-NEXT: mc:debug_info_unopt llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:debug_string_section llvmcas:// +;CHECK-NEXT: mc:debug_string llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:apple_names_section llvmcas:// +;CHECK-NEXT: mc:apple_names llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:apple_objc_section llvmcas:// +;CHECK-NEXT: mc:apple_objc llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:apple_namepsac_section llvmcas:// +;CHECK-NEXT: mc:apple_namespac llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:apple_types_section llvmcas:// +;CHECK-NEXT: mc:apple_types llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:section llvmcas:// +;CHECK-NEXT: mc:atom llvmcas:// +;CHECK-NEXT: mc:atom llvmcas:// +;CHECK-NEXT: mc:data llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:addends llvmcas:// +;CHECK-NEXT: mc:debug_line_section llvmcas:// +;CHECK-NEXT: mc:debug_line_unopt llvmcas:// +;CHECK-NEXT: mc:padding llvmcas:// +;CHECK-NEXT: mc:data_in_code llvmcas:// +;CHECK-NEXT: mc:symbol_table llvmcas:// +;CHECK-NEXT: mc:cstring llvmcas:// define i32 @_Z3fooj(i32 noundef %0) #0 !dbg !10 { ret i32 1, !dbg !18 diff --git a/llvm/test/tools/llvm-cas-dump/stats-dump.test b/llvm/test/tools/llvm-cas-dump/stats-dump.test index cb9053a20155a..4e58b2b27ce91 100644 --- a/llvm/test/tools/llvm-cas-dump/stats-dump.test +++ b/llvm/test/tools/llvm-cas-dump/stats-dump.test @@ -18,6 +18,7 @@ CSV: Kind, Count, Parents, Children, Data (B), Cost (B) CSV-NEXT: builtin:node, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}} CSV-NEXT: builtin:tree, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}} CSV-NEXT: mc:addends, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}} +CSV-NEXT: mc:align, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}} CSV-NEXT: mc:assembler, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}} CSV-NEXT: mc:atom, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}} CSV-NEXT: mc:cstring, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}} @@ -46,6 +47,7 @@ PRETTY-NEXT: ==== ===== ======= ==== PRETTY: builtin:node {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% PRETTY-NEXT: builtin:tree {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% PRETTY-NEXT: mc:addends {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% +PRETTY-NEXT: mc:align {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% PRETTY-NEXT: mc:assembler {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% PRETTY-NEXT: mc:atom {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% PRETTY-NEXT: mc:cstring {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% {{([0-9]+,)?[0-9]+}} {{[0-9]+\.[0-9]+}}% From 8d6a93d30978394aa2d486950ac0874b616bca56 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 12:58:43 -0700 Subject: [PATCH 20/22] Added TotalFragmentWithoutAddendsSize to make debugging easier. --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index e6eb53887eb8e..fe8e98a409ca8 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -41,6 +41,8 @@ using namespace llvm::casobjectformats::encoding; constexpr StringLiteral MCAssemblerRef::KindString; constexpr StringLiteral PaddingRef::KindString; +#define DEBUG_TYPE "mccas" + #define CASV1_SIMPLE_DATA_REF(RefName, IdentifierName) \ constexpr StringLiteral RefName::KindString; #define CASV1_SIMPLE_GROUP_REF(RefName, IdentifierName) \ @@ -3120,6 +3122,12 @@ Error MCCASBuilder::buildFragments() { ArrayRef RelocationBuffer; MCDataFragmentMerger Merger(*this, &Sec); uint64_t RelocationBufferIndex = 0; + // This is here for debugging purposes only, it is useful to know what the + // total size of all fragments without a section have been converted to + // CASObjects, one can use a conditional breakpoint to find the Fragment + // which might have a bug. + uint64_t TotalFragmentWithoutAddendsSize = 0; + (void)TotalFragmentWithoutAddendsSize; for (const MCFragment &F : Sec) { auto Relocs = RelMap.find(&F); if (RelocLocation == Atom) { @@ -3163,6 +3171,9 @@ Error MCCASBuilder::buildFragments() { partitionFragment(Asm, Addends, FinalFragmentContents, RelocationBuffer, F, RelocationBufferIndex, ObjectWriter.Target.isLittleEndian()); + TotalFragmentWithoutAddendsSize += FinalFragmentContents.size(); + LLVM_DEBUG(dbgs() << "Size of all fragment data without addends: " + << TotalFragmentWithoutAddendsSize << "\n"); if (auto E = Merger.tryMerge(F, Size, FinalFragmentContents)) return E; @@ -3187,6 +3198,7 @@ Error MCCASBuilder::buildFragments() { if (auto E = finalizeSection()) return E; + TotalFragmentWithoutAddendsSize = 0; } return finalizeGroup(); } From 29258cd717b399cc650885d3e9d534e8c3c45052 Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Fri, 15 Aug 2025 17:59:21 -0700 Subject: [PATCH 21/22] Remove DebugStringOffsets section from InMemoryCASDWARFObject. In rare cases (like in the case of armv7-cas.ll), where we still produce DWARF4, we are still trying to read the information from a non-existent DebugStringOffsets section. We do not need the data from that section to partition compile units. That code has been removed --- llvm/lib/MCCAS/MCCASObjectV1.cpp | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/llvm/lib/MCCAS/MCCASObjectV1.cpp b/llvm/lib/MCCAS/MCCASObjectV1.cpp index fe8e98a409ca8..ef2a8a28f43f3 100644 --- a/llvm/lib/MCCAS/MCCASObjectV1.cpp +++ b/llvm/lib/MCCAS/MCCASObjectV1.cpp @@ -83,27 +83,20 @@ class AbbrevSetWriter; /// debug info. class InMemoryCASDWARFObject : public DWARFObject { ArrayRef DebugAbbrevSection; - DWARFSection DebugStringOffsetsSection; bool IsLittleEndian; uint8_t AddressSize; public: - InMemoryCASDWARFObject(ArrayRef AbbrevContents, - ArrayRef StringOffsetsContents, - bool IsLittleEndian, uint8_t AddressSize) - : DebugAbbrevSection(AbbrevContents), - DebugStringOffsetsSection({toStringRef(StringOffsetsContents)}), - IsLittleEndian(IsLittleEndian), AddressSize(AddressSize) {} + InMemoryCASDWARFObject(ArrayRef AbbrevContents, bool IsLittleEndian, + uint8_t AddressSize) + : DebugAbbrevSection(AbbrevContents), IsLittleEndian(IsLittleEndian), + AddressSize(AddressSize) {} bool isLittleEndian() const override { return IsLittleEndian; } StringRef getAbbrevSection() const override { return toStringRef(DebugAbbrevSection); } - const DWARFSection &getStrOffsetsSection() const override { - return DebugStringOffsetsSection; - } - std::optional find(const DWARFSection &Sec, uint64_t Pos) const override { return {}; @@ -2159,7 +2152,7 @@ Expected> MCCASBuilder::mergeMCFragmentContents(const MCSection *Section, bool IsDebugLineSection) { SmallVector mergedData; - if (!Section->curFragList()) + if (!Section) return mergedData; for (const MCFragment &Fragment : *Section) { if (Fragment.getKind() == MCFragment::FT_Dwarf) { @@ -2443,15 +2436,7 @@ Error MCCASBuilder::splitDebugInfoAndAbbrevSections() { if (!FullAbbrevData) return FullAbbrevData.takeError(); - const MCSection *StringOffsetsFragmentList = DwarfSections.StrOffsets; - - Expected> FullStringOffsetsData = - mergeMCFragmentContents(StringOffsetsFragmentList); - - if (!FullStringOffsetsData) - return FullStringOffsetsData.takeError(); - - InMemoryCASDWARFObject CASObj(*FullAbbrevData, *FullStringOffsetsData, + InMemoryCASDWARFObject CASObj(*FullAbbrevData, Asm.getBackend().Endian == endianness::little, ObjectWriter.getAddressSize()); auto DWARFObj = std::make_unique(CASObj); From 09fab032f50c40ff62e2dc7007ae55a72474b7dd Mon Sep 17 00:00:00 2001 From: Shubham Sandeep Rastogi Date: Thu, 21 Aug 2025 10:55:54 -0700 Subject: [PATCH 22/22] Add test to make sure LEB fragments are handled correctly. --- llvm/test/CAS/LEB-mccas.ll | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 llvm/test/CAS/LEB-mccas.ll diff --git a/llvm/test/CAS/LEB-mccas.ll b/llvm/test/CAS/LEB-mccas.ll new file mode 100644 index 0000000000000..1ccc7d7a735f4 --- /dev/null +++ b/llvm/test/CAS/LEB-mccas.ll @@ -0,0 +1,28 @@ +; This test was reduced using delta and llvm-reduce on a crash in MCCAS because +; of an FT_LEB fragment which was attempted to be merged into an +; MCMergedFragmentRef. If MCCAS behaves correctly, llc should not crash when +; trying to create an MCCAS representation of this LLVM IR file. + +; RUN: rm -rf %t && mkdir -p %t +; RUN: llc --filetype=obj --mccas-verify --cas-backend --cas-friendly-debug-info --cas=%t/cas %s -o %t/LEB.o + +target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32" +target triple = "arm64-apple-macosx14.0.0" + +; Function Attrs: noinline optnone +define { ptr, i32 } @appendAnimation() #0 personality ptr @__objc_personality_v0 { + %1 = invoke ptr null(ptr null, ptr null) + to label %2 unwind label %3 + +2: ; preds = %0 + ret { ptr, i32 } zeroinitializer + +3: ; preds = %0 + %4 = landingpad { ptr, i32 } + catch ptr null + ret { ptr, i32 } %4 +} + +declare i32 @__objc_personality_v0(...) + +attributes #0 = { noinline optnone } \ No newline at end of file