Skip to content

Instantly share code, notes, and snippets.

@nickdesaulniers
Created February 28, 2023 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdesaulniers/a6c234b56218bbcb21aabbd5521d9615 to your computer and use it in GitHub Desktop.
Save nickdesaulniers/a6c234b56218bbcb21aabbd5521d9615 to your computer and use it in GitHub Desktop.
llc -run-pass=regallocfast regallocfast.g.mir -o - -verify-machineinstrs
--- |
; ModuleID = 'regallocfast.g.mir'
source_filename = "x.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: noinline nounwind optnone
define dso_local i32 @main() #0 !dbg !9 {
entry:
%retval = alloca i32, align 4
%x = alloca i32, align 4
store i32 0, ptr %retval, align 4
call void @llvm.dbg.declare(metadata ptr %x, metadata !14, metadata !DIExpression()), !dbg !15
store i32 123, ptr %x, align 4, !dbg !15
%0 = callbr i32 asm "mov $1, $0\0A\09jmp ${2:l}", "=r,r,!i,~{dirflag},~{fpsr},~{flags}"(i32 45) #3
to label %asm.fallthrough [label %label.split], !dbg !16, !srcloc !17
asm.fallthrough: ; preds = %entry
store i32 %0, ptr %x, align 4, !dbg !16
store i32 6, ptr %x, align 4, !dbg !18
br label %label, !dbg !19
label: ; preds = %label.split, %asm.fallthrough
call void @llvm.dbg.label(metadata !20), !dbg !21
%1 = load i32, ptr %x, align 4, !dbg !22
ret i32 %1, !dbg !23
label.split: ; preds = %entry
%2 = call i32 @llvm.callbr.landingpad.i32(i32 %0), !dbg !16
store i32 %2, ptr %x, align 4, !dbg !16
br label %label, !dbg !16
}
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare void @llvm.dbg.label(metadata) #1
; Function Attrs: nomerge nounwind
declare i32 @llvm.callbr.landingpad.i32(i32) #2
attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nomerge nounwind }
attributes #3 = { nounwind memory(none) }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
!llvm.ident = !{!8}
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.0 (git@github.com:llvm/llvm-project.git 7de8ebde4f8f92129d47fda1c05d4b3d9a4d99d8)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "x.c", directory: "/android0/llvm-project", checksumkind: CSK_MD5, checksum: "a7d7b4f8bb9445eef3bb86a226401f5c")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"wchar_size", i32 4}
!5 = !{i32 8, !"PIC Level", i32 2}
!6 = !{i32 7, !"PIE Level", i32 2}
!7 = !{i32 7, !"frame-pointer", i32 2}
!8 = !{!"clang version 17.0.0 (git@github.com:llvm/llvm-project.git 7de8ebde4f8f92129d47fda1c05d4b3d9a4d99d8)"}
!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !10, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
!10 = !DISubroutineType(types: !11)
!11 = !{!12}
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!13 = !{}
!14 = !DILocalVariable(name: "x", scope: !9, file: !1, line: 5, type: !12)
!15 = !DILocation(line: 5, column: 9, scope: !9)
!16 = !DILocation(line: 6, column: 5, scope: !9)
!17 = !{i64 166, i64 179}
!18 = !DILocation(line: 7, column: 7, scope: !9)
!19 = !DILocation(line: 7, column: 5, scope: !9)
!20 = !DILabel(scope: !9, name: "label", file: !1, line: 8)
!21 = !DILocation(line: 8, column: 5, scope: !9)
!22 = !DILocation(line: 9, column: 12, scope: !9)
!23 = !DILocation(line: 9, column: 5, scope: !9)
...
---
name: main
alignment: 16
exposesReturnsTwice: false
legalized: false
regBankSelected: false
selected: false
failedISel: false
tracksRegLiveness: true
hasWinCFI: false
callsEHReturn: false
callsUnwindInit: false
hasEHCatchret: false
hasEHScopes: false
hasEHFunclets: false
debugInstrRef: false
failsVerification: false
tracksDebugUserValues: false
registers: []
liveins: []
frameInfo:
isFrameAddressTaken: false
isReturnAddressTaken: false
hasStackMap: false
hasPatchPoint: false
stackSize: 0
offsetAdjustment: 0
maxAlignment: 4
adjustsStack: false
hasCalls: false
stackProtector: ''
functionContext: ''
maxCallFrameSize: 4294967295
cvBytesOfCalleeSavedRegisters: 0
hasOpaqueSPAdjustment: false
hasVAStart: false
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
savePoint: ''
restorePoint: ''
fixedStack: []
stack:
- { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
- { id: 1, name: x, type: default, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '!14', debug-info-expression: '!DIExpression()',
debug-info-location: '!15' }
- { id: 2, name: '', type: spill-slot, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
- { id: 3, name: '', type: spill-slot, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
callSites: []
debugValueSubstitutions: []
constants: []
machineFunctionInfo: {}
body: |
bb.0.entry:
successors: %bb.1(0x40000000), %bb.3(0x40000000)
MOV32mi %stack.0.retval, 1, $noreg, 0, $noreg, 0 :: (store (s32) into %ir.retval)
MOV32mi %stack.1.x, 1, $noreg, 0, $noreg, 123, debug-location !15 :: (store (s32) into %ir.x)
renamable $eax = MOV32ri 45
INLINEASM_BR &"mov $1, $0\0A\09jmp ${2:l}", 0 /* attdialect */, 2359306 /* regdef:GR32 */, def renamable $eax, 2359305 /* reguse:GR32 */, killed renamable $eax, 13 /* imm */, %bb.3, 12 /* clobber */, implicit-def dead early-clobber $df, 12 /* clobber */, implicit-def early-clobber $fpsw, 12 /* clobber */, implicit-def dead early-clobber $eflags, !17, debug-location !16
MOV32mr %stack.3, 1, $noreg, 0, $noreg, $eax :: (store (s32) into %stack.3)
MOV32mr %stack.2, 1, $noreg, 0, $noreg, killed $eax :: (store (s32) into %stack.2)
JMP_1 %bb.1, debug-location !16
bb.1.asm.fallthrough:
successors: %bb.2(0x80000000)
$eax = MOV32rm %stack.2, 1, $noreg, 0, $noreg :: (load (s32) from %stack.2)
MOV32mr %stack.1.x, 1, $noreg, 0, $noreg, renamable $eax, debug-location !16 :: (store (s32) into %ir.x)
MOV32mi %stack.1.x, 1, $noreg, 0, $noreg, 6, debug-location !18 :: (store (s32) into %ir.x)
bb.2.label:
DBG_LABEL !20, debug-location !21
renamable $eax = MOV32rm %stack.1.x, 1, $noreg, 0, $noreg, debug-location !22 :: (load (s32) from %ir.x)
RET64 implicit killed $eax, debug-location !23
bb.3.label.split (machine-block-address-taken, inlineasm-br-indirect-target):
successors: %bb.2(0x80000000)
liveins: $eax
MOV32mr %stack.3, 1, $noreg, 0, $noreg, $eax :: (store (s32) into %stack.3)
$eax = MOV32rm %stack.3, 1, $noreg, 0, $noreg :: (load (s32) from %stack.3)
MOV32mr %stack.1.x, 1, $noreg, 0, $noreg, killed renamable $eax, debug-location !16 :: (store (s32) into %ir.x)
JMP_1 %bb.2, debug-location !16
...
@nickdesaulniers
Copy link
Author

Of the above, it looks like the following are missing debug-location:

    MOV32mi %stack.0.retval, 1, $noreg, 0, $noreg, 0 :: (store (s32) into %ir.retval)
    renamable $eax = MOV32ri 45
    MOV32mr %stack.3, 1, $noreg, 0, $noreg, $eax :: (store (s32) into %stack.3)
    MOV32mr %stack.2, 1, $noreg, 0, $noreg, killed $eax :: (store (s32) into %stack.2)
    $eax = MOV32rm %stack.2, 1, $noreg, 0, $noreg :: (load (s32) from %stack.2)
    MOV32mr %stack.3, 1, $noreg, 0, $noreg, $eax :: (store (s32) into %stack.3)
    $eax = MOV32rm %stack.3, 1, $noreg, 0, $noreg :: (load (s32) from %stack.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment