Skip to content

Commit e4be09b

Browse files
Merge pull request #7328 from rastogishubham/EmitCASIDLLVMMCStable
Add option --mccas-emit-casid-file to llc
2 parents 2c8084c + 1a142d8 commit e4be09b

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

llvm/test/CAS/emit-casid-file.ll

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; RUN: rm -rf %t && mkdir -p %t
2+
; 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
3+
; RUN: cat %t/test.o.casid | FileCheck %s --check-prefix=NATIVE_FILENAME
4+
; NATIVE_FILENAME: CASID:Jllvmcas://{{.*}}
5+
;
6+
; RUN: rm -rf %t && mkdir -p %t
7+
; 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
8+
; RUN: cat %t/test.o.casid | FileCheck %s --check-prefix=VERIFY_FILENAME
9+
; VERIFY_FILENAME: CASID:Jllvmcas://{{.*}}
10+
;
11+
; RUN: rm -rf %t && mkdir -p %t
12+
; 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
13+
; RUN: not cat %t/test.o.casid
14+
;
15+
; RUN: rm -rf %t && mkdir -p %t
16+
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-native %s --mccas-emit-casid-file -o -
17+
; RUN: not cat %t/test.o.casid
18+
;
19+
; RUN: rm -rf %t && mkdir -p %t
20+
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-verify %s --mccas-emit-casid-file -o -
21+
; RUN: not cat %t/test.o.casid
22+
;
23+
; RUN: rm -rf %t && mkdir -p %t
24+
; RUN: llc -O0 -cas-friendly-debug-info --filetype=obj --cas-backend --cas=/tmp/cas --mccas-casid %s --mccas-emit-casid-file -o -
25+
; RUN: not cat %t/test.o.casid
26+
27+
; ModuleID = '/Users/shubham/Development/test109275485/a.cpp'
28+
source_filename = "/Users/shubham/Development/test109275485/a.cpp"
29+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
30+
target triple = "arm64-apple-macosx14.0.0"
31+
32+
; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
33+
define noundef i32 @_Z3fooi(i32 noundef %x) #0 {
34+
entry:
35+
%x.addr = alloca i32, align 4
36+
store i32 %x, ptr %x.addr, align 4
37+
%0 = load i32, ptr %x.addr, align 4
38+
%add = add nsw i32 %0, 2
39+
ret i32 %add
40+
}
41+
42+
!llvm.module.flags = !{!0, !1, !2, !3}
43+
!llvm.ident = !{!4}
44+
45+
!0 = !{i32 1, !"wchar_size", i32 4}
46+
!1 = !{i32 8, !"PIC Level", i32 2}
47+
!2 = !{i32 7, !"uwtable", i32 1}
48+
!3 = !{i32 7, !"frame-pointer", i32 1}
49+
!4 = !{!"clang version 18.0.0 ([email protected]:apple/llvm-project.git bd5fc55041b3dfab2de1640638ce4b5e8a016998)"}

llvm/tools/llc/llc.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ static cl::opt<CASBackendMode> MCCASBackendMode(
202202
"Native object without verifier"),
203203
clEnumValN(CASBackendMode::CASID, "mccas-casid",
204204
"CASID file output")));
205+
206+
static cl::opt<bool>
207+
EmitCASIDFile("mccas-emit-casid-file",
208+
cl::desc("Emit a .casid file next to the generated .o file "
209+
"when MC CAS is enabled"),
210+
cl::init(false));
205211
// END MCCAS
206212

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

703+
std::unique_ptr<ToolOutputFile> CasIDOS;
704+
std::string OutputPathCASIDFile;
705+
StringRef OutputFile = StringRef(Out->outputFilename());
706+
if (UseMCCASBackend && EmitCASIDFile &&
707+
MCCASBackendMode != CASBackendMode::CASID &&
708+
codegen::getFileType() == CGFT_ObjectFile && OutputFile != "-") {
709+
OutputPathCASIDFile = std::string(OutputFile);
710+
OutputPathCASIDFile.append(".casid");
711+
std::error_code EC;
712+
CasIDOS = std::make_unique<ToolOutputFile>(OutputPathCASIDFile, EC,
713+
sys::fs::OF_None);
714+
if (EC) {
715+
reportError(EC.message());
716+
return 1;
717+
}
718+
}
719+
697720
std::unique_ptr<ToolOutputFile> DwoOut;
698721
if (!SplitDwarfOutputFile.empty()) {
699722
std::error_code EC;
@@ -779,7 +802,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
779802
PM.add(createFreeMachineFunctionPass());
780803
} else if (Target->addPassesToEmitFile(
781804
PM, *OS, DwoOut ? &DwoOut->os() : nullptr,
782-
codegen::getFileType(), NoVerify, MMIWP)) {
805+
codegen::getFileType(), NoVerify, MMIWP,
806+
CasIDOS ? &CasIDOS->os() : nullptr)) {
783807
reportError("target does not support generation of this file type");
784808
}
785809

@@ -838,6 +862,8 @@ static int compileModule(char **argv, LLVMContext &Context) {
838862
Out->keep();
839863
if (DwoOut)
840864
DwoOut->keep();
865+
if (CasIDOS)
866+
CasIDOS->keep();
841867

842868
return 0;
843869
}

0 commit comments

Comments
 (0)