File: import-constant.ll

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (61 lines) | stat: -rw-r--r-- 2,661 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
; Check that we promote constant object in the source module and import it
; even when it is referenced in some other GV initializer and/or is used
; by store instructions.
; RUN: opt -thinlto-bc %s -o %t1.bc
; RUN: opt -thinlto-bc %p/Inputs/import-constant.ll -o %t2.bc
; RUN: llvm-lto2 run -save-temps %t1.bc %t2.bc -o %t-out \
; RUN:    -import-constants-with-refs \
; RUN:    -r=%t1.bc,main,plx \
; RUN:    -r=%t1.bc,_Z6getObjv,l \
; RUN:    -r=%t2.bc,_Z6getObjv,pl \
; RUN:    -r=%t2.bc,val,pl \
; RUN:    -r=%t2.bc,outer,pl
; RUN: llvm-dis %t-out.2.1.promote.bc -o - | FileCheck %s --check-prefix=PROMOTE
; RUN: llvm-dis %t-out.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT
; RUN: llvm-dis %t-out.1.4.opt.bc -o - | FileCheck %s --check-prefix=OPT

; Check when importing references is prohibited
; RUN: llvm-lto2 run -save-temps %t1.bc %t2.bc -o %t-out-norefs \
; RUN:    -import-constants-with-refs=false \
; RUN:    -r=%t1.bc,main,plx \
; RUN:    -r=%t1.bc,_Z6getObjv,l \
; RUN:    -r=%t2.bc,_Z6getObjv,pl \
; RUN:    -r=%t2.bc,val,pl \
; RUN:    -r=%t2.bc,outer,pl
; RUN: llvm-dis %t-out-norefs.1.3.import.bc -o - | FileCheck %s --check-prefix=NOREFS

; Check that variable has been promoted in the source module
; PROMOTE: @_ZL3Obj.llvm.{{.*}} = hidden constant %struct.S { i32 4, i32 8, ptr @val }

; @outer is a write-only variable, so it's been converted to zeroinitializer.
; IMPORT:      @val = available_externally global i32 42
; IMPORT-NEXT: @_ZL3Obj.llvm.{{.*}} = available_externally hidden constant %struct.S { i32 4, i32 8, ptr @val }
; IMPORT-NEXT: @outer = internal local_unnamed_addr global %struct.Q zeroinitializer

; OPT: @outer = internal unnamed_addr global %struct.Q zeroinitializer

; OPT:      define dso_local i32 @main()
; OPT-NEXT: entry:
; OPT-NEXT:   store ptr null, ptr getelementptr inbounds (%struct.Q, ptr @outer, i64 1, i32 0)
; OPT-NEXT:   ret i32 12

; NOREFS:      @_ZL3Obj.llvm.{{.*}} = external hidden constant %struct.S
; NOREFS-NEXT: @outer = internal local_unnamed_addr global %struct.Q zeroinitializer

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"

%struct.S = type { i32, i32, i32* }

define dso_local i32 @main() local_unnamed_addr {
entry:
  %call = tail call %struct.S* @_Z6getObjv()
  %d = getelementptr inbounds %struct.S, %struct.S* %call, i64 0, i32 0
  %0 = load i32, i32* %d, align 8
  %v = getelementptr inbounds %struct.S, %struct.S* %call, i64 0, i32 1
  %1 = load i32, i32* %v, align 4
  %add = add nsw i32 %1, %0
  ret i32 %add
}

declare dso_local %struct.S* @_Z6getObjv() local_unnamed_addr