Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 49 additions & 0 deletions llvm/test/CAS/emit-casid-file.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
; RUN: rm -rf %t && mkdir -p %t
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-native %s --mccas-emit-casid-file -o %t/test.o
; RUN: cat %t/test.o.casid | FileCheck %s --check-prefix=NATIVE_FILENAME
; NATIVE_FILENAME: CASID:Jllvmcas://{{.*}}
;
; RUN: rm -rf %t && mkdir -p %t
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-verify %s --mccas-emit-casid-file -o %t/test.o
; RUN: cat %t/test.o.casid | FileCheck %s --check-prefix=VERIFY_FILENAME
; VERIFY_FILENAME: CASID:Jllvmcas://{{.*}}
;
; RUN: rm -rf %t && mkdir -p %t
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-casid %s --mccas-emit-casid-file -o %t/test.o
; RUN: not cat %t/test.o.casid
;
; RUN: rm -rf %t && mkdir -p %t
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-native %s --mccas-emit-casid-file -o -
; RUN: not cat %t/test.o.casid
;
; RUN: rm -rf %t && mkdir -p %t
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-verify %s --mccas-emit-casid-file -o -
; RUN: not cat %t/test.o.casid
;
; RUN: rm -rf %t && mkdir -p %t
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-casid %s --mccas-emit-casid-file -o -
; RUN: not cat %t/test.o.casid

; ModuleID = '/Users/shubham/Development/test109275485/a.cpp'
source_filename = "/Users/shubham/Development/test109275485/a.cpp"
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-macosx14.0.0"

; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
define noundef i32 @_Z3fooi(i32 noundef %x) #0 {
entry:
%x.addr = alloca i32, align 4
store i32 %x, ptr %x.addr, align 4
%0 = load i32, ptr %x.addr, align 4
%add = add nsw i32 %0, 2
ret i32 %add
}

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"uwtable", i32 1}
!3 = !{i32 7, !"frame-pointer", i32 1}
!4 = !{!"clang version 18.0.0 ([email protected]:apple/llvm-project.git bd5fc55041b3dfab2de1640638ce4b5e8a016998)"}
28 changes: 27 additions & 1 deletion llvm/tools/llc/llc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ static cl::opt<CASBackendMode> MCCASBackendMode(
"Native object without verifier"),
clEnumValN(CASBackendMode::CASID, "mccas-casid",
"CASID file output")));

static cl::opt<bool>
EmitCASIDFile("mccas-emit-casid-file",
cl::desc("Emit a .casid file next to the generated .o file "
"when MC CAS is enabled"),
cl::init(false));
// END MCCAS

namespace {
Expand Down Expand Up @@ -694,6 +700,23 @@ static int compileModule(char **argv, LLVMContext &Context) {
// Ensure the filename is passed down to CodeViewDebug.
Target->Options.ObjectFilenameForDebug = Out->outputFilename();

std::unique_ptr<ToolOutputFile> CasIDOS;
std::string OutputPathCASIDFile;
StringRef OutputFile = StringRef(Out->outputFilename());
if (UseMCCASBackend && EmitCASIDFile &&
MCCASBackendMode != CASBackendMode::CASID &&
codegen::getFileType() == CGFT_ObjectFile && OutputFile != "-") {
OutputPathCASIDFile = std::string(OutputFile);
OutputPathCASIDFile.append(".casid");
std::error_code EC;
CasIDOS = std::make_unique<ToolOutputFile>(OutputPathCASIDFile, EC,
sys::fs::OF_None);
if (EC) {
reportError(EC.message());
return 1;
}
}

std::unique_ptr<ToolOutputFile> DwoOut;
if (!SplitDwarfOutputFile.empty()) {
std::error_code EC;
Expand Down Expand Up @@ -779,7 +802,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
PM.add(createFreeMachineFunctionPass());
} else if (Target->addPassesToEmitFile(
PM, *OS, DwoOut ? &DwoOut->os() : nullptr,
codegen::getFileType(), NoVerify, MMIWP)) {
codegen::getFileType(), NoVerify, MMIWP,
CasIDOS ? &CasIDOS->os() : nullptr)) {
reportError("target does not support generation of this file type");
}

Expand Down Expand Up @@ -838,6 +862,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
Out->keep();
if (DwoOut)
DwoOut->keep();
if (CasIDOS)
CasIDOS->keep();

return 0;
}