diff --git a/llvm/test/CAS/emit-casid-file.ll b/llvm/test/CAS/emit-casid-file.ll new file mode 100644 index 0000000000000..317e838d32e91 --- /dev/null +++ b/llvm/test/CAS/emit-casid-file.ll @@ -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 (git@github.com:apple/llvm-project.git bd5fc55041b3dfab2de1640638ce4b5e8a016998)"} diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 9edc09b778b74..28d88b18da7d6 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -202,6 +202,12 @@ static cl::opt MCCASBackendMode( "Native object without verifier"), clEnumValN(CASBackendMode::CASID, "mccas-casid", "CASID file output"))); + +static cl::opt + 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 { @@ -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 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(OutputPathCASIDFile, EC, + sys::fs::OF_None); + if (EC) { + reportError(EC.message()); + return 1; + } + } + std::unique_ptr DwoOut; if (!SplitDwarfOutputFile.empty()) { std::error_code EC; @@ -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"); } @@ -838,6 +862,8 @@ static int compileModule(char **argv, LLVMContext &Context) { Out->keep(); if (DwoOut) DwoOut->keep(); + if (CasIDOS) + CasIDOS->keep(); return 0; }