Skip to content

Fix MCCAS after changed made to MC layer upstream #11184

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

Open
wants to merge 22 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b717c84
Revert "[MCCAS] Add configuration LLVM_ENABLE_MCCAS"
rastogishubham Jul 31, 2025
d153b52
Remove MCPseudoProbeAddrFragment from MCCASObjectV1.def
rastogishubham Aug 14, 2025
123de10
Remove MCSectionCAS class functions that no longer exist in the base …
rastogishubham Aug 14, 2025
d110481
Change MCFRAGMENT_NODE_REF to use MCFragment
rastogishubham Aug 15, 2025
503da27
Fix the MCAlignFramgnetRef class.
rastogishubham Aug 15, 2025
a056b21
Fix MCBoundaryAlignFragmentRef::create.
rastogishubham Aug 15, 2025
7d40b40
Fix MCCVInlineLineTableFragmentRef::create.
rastogishubham Aug 15, 2025
f459152
Fix MCFillFragmentRef::create.
rastogishubham Aug 15, 2025
938bd1a
Fix MCLEBFragmentRef::create.
rastogishubham Aug 15, 2025
90bbe0e
Fix MCNopsFragmentRef::create.
rastogishubham Aug 15, 2025
1820640
MCNopsFragment change dyn_cast to cast
rastogishubham Aug 19, 2025
f89dc82
Fix MCOrgFragmentRef::create.
rastogishubham Aug 15, 2025
c713356
Fix MCSymbolIdFragmentRef::create.
rastogishubham Aug 15, 2025
c31be19
Fix getFragmentContents() function.
rastogishubham Aug 15, 2025
13f4493
Fix MCCASBuilder::mergeMCFragmentContents
rastogishubham Aug 15, 2025
15a9813
Update bool IsMergeableFragment.
rastogishubham Aug 15, 2025
d2de518
Remove cast to MCDataFragment.
rastogishubham Aug 15, 2025
0ee0638
Change isVirtualSection to isBssSection
rastogishubham Aug 15, 2025
9a11cc1
Fix any broken tests
rastogishubham Aug 15, 2025
8d6a93d
Added TotalFragmentWithoutAddendsSize to make debugging easier.
rastogishubham Aug 15, 2025
29258cd
Remove DebugStringOffsets section from InMemoryCASDWARFObject.
rastogishubham Aug 16, 2025
09fab03
Add test to make sure LEB fragments are handled correctly.
rastogishubham Aug 21, 2025
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
5 changes: 0 additions & 5 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -9092,15 +9092,10 @@ defm include_tree_preserve_pch_path : BoolFOption<"include-tree-preserve-pch-pat
NegFlag<SetFalse>>;

/// BEGIN MCCAS
#ifdef LLVM_EMABLE_MCCAS
defm cas_backend : BoolFOption<"cas-backend",
CodeGenOpts<"UseCASBackend">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption], "Enable using CASBackend for object file output">,
NegFlag<SetFalse>>;
#else
def cas_backend : Flag<["-"], "fcas-backend">, Group<clang_ignored_legacy_options_Group>;
def no_cas_backend : Flag<["-"], "fno-cas-backend">, Group<clang_ignored_legacy_options_Group>;
#endif

defm cas_emit_casid_file : BoolFOption<"cas-emit-casid-file",
CodeGenOpts<"EmitCASIDFile">, DefaultFalse,
Expand Down
9 changes: 1 addition & 8 deletions clang/lib/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions clang/lib/Frontend/CompileJobCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -824,7 +822,6 @@ Expected<std::optional<int>> 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.
Expand All @@ -841,9 +838,6 @@ Expected<std::optional<int>> ObjectStoreCachingOutputs::replayCachedResult(
auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
if (auto E = Schema->serializeObjectFile(*Obj, *Output))
return E;
#else
llvm_unreachable("MCCAS disabled");
#endif
}
return Output->keep();
}
Expand Down
1 change: 0 additions & 1 deletion clang/test/CAS/cas-backend.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// REQUIRES: mccas
// RUN: rm -rf %t && mkdir -p %t
// RUN: llvm-cas --cas %t/cas --ingest %s > %t/casid
//
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CAS/cas-emit-casid.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion clang/test/CAS/depscan-update-mccas.c
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
1 change: 0 additions & 1 deletion clang/test/CAS/remote-cache-incompatible-options.c
Original file line number Diff line number Diff line change
@@ -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
9 changes: 1 addition & 8 deletions clang/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/MCCAS/MCCASObjectV1.def
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions llvm/include/llvm/MCCAS/MCCASObjectV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class SpecificRef : public MCObjectProxy {
public: \
static constexpr StringLiteral KindString = #MCEnumIdentifier; \
static Expected<MCFragmentName##Ref> \
create(MCCASBuilder &MB, const MCFragmentName &Fragment, \
create(MCCASBuilder &MB, const MCFragment &Fragment, \
unsigned FragmentSize, ArrayRef<char> FragmentContents); \
static Expected<MCFragmentName##Ref> get(Expected<MCObjectProxy> Ref) { \
auto Specific = SpecificRefT::getSpecific(std::move(Ref)); \
Expand All @@ -404,7 +404,7 @@ class SpecificRef : public MCObjectProxy {
cas::ObjectRef ID) { \
return get(Schema.get(ID)); \
} \
static std::optional<MCFragmentName##Ref> Cast(MCObjectProxy Ref) { \
static std::optional<MCFragmentName##Ref> Cast(MCObjectProxy Ref) { \
auto Specific = SpecificRefT::Cast(Ref); \
if (!Specific) \
return std::nullopt; \
Expand Down
12 changes: 0 additions & 12 deletions llvm/include/llvm/MCCAS/MCCASReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 1 addition & 8 deletions llvm/lib/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -286,7 +279,7 @@ add_llvm_component_library(LLVMCodeGen
Core
MC
ObjCARC
${MCCAS_DEPS}
MCCAS
ProfileData
Scalar
Support
Expand Down
14 changes: 3 additions & 11 deletions llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>
Expand Down Expand Up @@ -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<MCObjectWriter> CASBackendWriter;
if (Options.UseCASBackend) {
std::function<const cas::ObjectProxy(llvm::MachOCASWriter &,
Expand All @@ -237,14 +233,10 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
Options.MCOptions.CASObjMode, CreateFromMcAssembler,
SerializeObjectFile, CasIDOS);
}
#else
bool UseCASBackend = false;
std::unique_ptr<MCObjectWriter> CASBackendWriter;
#endif
// END MCCAS
AsmStreamer.reset(getTarget().createMCObjectStreamer(
T, Context, std::unique_ptr<MCAsmBackend>(MAB),
UseCASBackend ? std::move(CASBackendWriter) // MCCAS
Options.UseCASBackend ? std::move(CASBackendWriter) // MCCAS
: DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)
: MAB->createObjectWriter(Out),
std::unique_ptr<MCCodeEmitter>(MCE), STI));
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/MC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
if (LLVM_ENABLE_MCCAS)
add_definitions(-DLLVM_ENABLE_MCCAS=1)
endif()

add_llvm_component_library(LLVMMC
ConstantPools.cpp
DXContainerPSVInfo.cpp
Expand Down
22 changes: 2 additions & 20 deletions llvm/lib/MC/MachOCASWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,10 +33,6 @@
#include "llvm/Support/raw_ostream.h"
#include <memory>

#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;
Expand Down Expand Up @@ -124,19 +122,3 @@ std::unique_ptr<MCObjectWriter> llvm::createMachOCASWriter(
std::move(MOTW), TT, CAS, Mode, OS, IsLittleEndian, CreateFromMcAssembler,
SerializeObjectFile, ResultCallBack, CasIDOS);
}
#else
std::unique_ptr<llvm::MCObjectWriter> llvm::createMachOCASWriter(
std::unique_ptr<MCMachObjectTargetWriter> MOTW, const Triple &TT,
cas::ObjectStore &CAS, CASBackendMode Mode, raw_pwrite_stream &OS,
bool IsLittleEndian,
std::function<const cas::ObjectProxy(llvm::MachOCASWriter &,
llvm::MCAssembler &,
cas::ObjectStore &, raw_ostream *)>
CreateFromMcAssembler,
std::function<Error(cas::ObjectProxy, cas::ObjectStore &, raw_ostream &)>
SerializeObjectFile,
std::optional<MCTargetOptions::ResultCallBackTy> ResultCallBack,
raw_pwrite_stream *CasIDOS) {
llvm_unreachable("unsupported");
}
#endif
Loading