Skip to content

Fix mccasv2 #11118

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

Draft
wants to merge 29 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9069e5b
Revert "[MCCAS] Add configuration LLVM_ENABLE_MCCAS"
rastogishubham Jul 31, 2025
d77c802
WIP fix MCCAS from MaskRay MC changes, remove obsolete fragment types…
rastogishubham Jul 25, 2025
79adaf5
WIP MCCAS MaskRay Fix, fix MCRelaxableFragment
rastogishubham Jul 25, 2025
c00daef
WIP MCCAS MaskRay Fix, fix MCDwarfCallFrameFragment
rastogishubham Jul 25, 2025
50c5933
WIP MCCAS MaskRay Fix, fix MCPseudoProbeFragment
rastogishubham Jul 25, 2025
cf745f9
WIP MCCAS MaskRay Fix, fix MCLEBFragment
rastogishubham Jul 25, 2025
0b16ed9
WIP MCCAS MaskRay Fix, fix MCDwarfLineAddrFragment
rastogishubham Jul 25, 2025
6b49396
WIP MCCAS MaskRay Fix, do some work for MCAlignFragment
rastogishubham Jul 25, 2025
707de72
WIP MCCAS MaskRay Fix, Fix some stuff for MCDataFragment
rastogishubham Jul 25, 2025
1089577
WIP MCCAS MaskRay Fix, Fix some more stuff for MCDataFragment
rastogishubham Jul 25, 2025
1182f9b
WIP MCCAS MaskRayFix, Replace isVirtualSection with isBssSection
rastogishubham Jul 25, 2025
e2119b2
WIP MCCAS MaskRay Fix, Change isa<MCAlignFragment> to F.getKind() == …
rastogishubham Jul 25, 2025
8834a8a
WIP MCCAS MaskRay Fix, some more work for MCAlignFragment
rastogishubham Jul 25, 2025
9dbbf28
MCCAS MaskRay Fix, a little more MCLEBFragment fix
rastogishubham Jul 25, 2025
4b0281f
WIP MCCAS MaskRay Fix, fixed bug with no more classof function in MCE…
rastogishubham Jul 25, 2025
a5bc917
WIP fix MCCAS, builds but round trip verification error due to FragTy…
rastogishubham Jul 25, 2025
9564339
Revert "WIP fix MCCAS, builds but round trip verification error due t…
rastogishubham Jul 25, 2025
c2427d8
WIP MCCAS MaskRay Fix, works for small cpp file but not on bootstrap …
rastogishubham Jul 25, 2025
1d653c7
Edit MCAlignFragmentRef::create and materialize to match what is ther…
rastogishubham Jul 25, 2025
ab47e76
Fix getFragmentContents to match what we see in MCAssembler.cpp write…
rastogishubham Jul 25, 2025
e3ccba2
Fix MCAlignFragmentRef Size calc
rastogishubham Jul 25, 2025
4968925
Fix MCCAS, Add variable contents to getFragmentsContents function
rastogishubham Jul 31, 2025
72d723f
Fix FT_Align creation and materialization for Nops
rastogishubham Aug 1, 2025
54a5fbb
Make it work after rebase
rastogishubham Aug 5, 2025
784c95e
WIP MCCAS, early exit if Section has no fragments
rastogishubham Aug 5, 2025
ce7f285
add var fragment handline
rastogishubham Aug 5, 2025
af08d1c
Fixup some tests
rastogishubham Aug 5, 2025
eb19d4a
Added this to make debugging easier
rastogishubham Aug 7, 2025
7612921
Make sure we don't write non-partitioned data into align fragment
rastogishubham Aug 7, 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 @@ -150,13 +150,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 @@ -167,7 +160,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 @@ -907,7 +907,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