14 changes: 0 additions & 14 deletions lld/test/ELF/linkerscript/diag4.test

This file was deleted.

14 changes: 0 additions & 14 deletions lld/test/ELF/linkerscript/diag5.test

This file was deleted.

7 changes: 0 additions & 7 deletions lld/test/ELF/linkerscript/diag6.test

This file was deleted.

File renamed without changes.
26 changes: 26 additions & 0 deletions lld/test/ELF/linkerscript/unquoted.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# REQUIRES: x86
# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o 0.o

#--- empty.lds
#--- 1.lds

SECTIONS /*
#--- 1a.lds
foo = 3;
INCLUDE "empty.lds"
INCLUDE "1.lds"

# RUN: not ld.lld -shared 0.o -T 1.lds 2>&1 | FileCheck %s --check-prefix=CHECK1 --match-full-lines --strict-whitespace
# RUN: not ld.lld -shared 0.o -T 1a.lds 2>&1 | FileCheck %s --check-prefix=CHECK1A --match-full-lines --strict-whitespace
# CHECK1:{{.*}}error: 1.lds:1: unclosed comment in a linker script
# CHECK1A:{{.*}}error: 1a.lds:3: unclosed comment in a linker script
#CHECK1A-NEXT:>>> INCLUDE "1.lds"
#CHECK1A-NEXT:>>> ^

#--- 2.lds
INCLUDE "empty.lds"
"
# RUN: not ld.lld -shared 0.o -T 2.lds 2>&1 | FileCheck %s --check-prefix=CHECK2 --match-full-lines --strict-whitespace
# CHECK2:{{.*}}error: 2.lds:2: unclosed quote
# CHECK2-NOT:{{.}}
129 changes: 129 additions & 0 deletions lld/test/ELF/loongarch-tls-gd-pcrel20-s2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# REQUIRES: loongarch
# RUN: rm -rf %t && split-file %s %t

# RUN: llvm-mc --filetype=obj --triple=loongarch32 %t/a.s -o %t/a.32.o
# RUN: llvm-mc --filetype=obj --triple=loongarch32 %t/bc.s -o %t/bc.32.o
# RUN: ld.lld -shared -soname=bc.so %t/bc.32.o -o %t/bc.32.so
# RUN: llvm-mc --filetype=obj --triple=loongarch32 %t/tga.s -o %t/tga.32.o
# RUN: llvm-mc --filetype=obj --triple=loongarch64 %t/a.s -o %t/a.64.o
# RUN: llvm-mc --filetype=obj --triple=loongarch64 %t/bc.s -o %t/bc.64.o
# RUN: ld.lld -shared -soname=bc.so %t/bc.64.o -o %t/bc.64.so
# RUN: llvm-mc --filetype=obj --triple=loongarch64 %t/tga.s -o %t/tga.64.o

## LA32 GD
# RUN: ld.lld -shared %t/a.32.o %t/bc.32.o -o %t/gd.32.so
# RUN: llvm-readobj -r %t/gd.32.so | FileCheck --check-prefix=GD32-REL %s
# RUN: llvm-objdump -d --no-show-raw-insn %t/gd.32.so | FileCheck --check-prefix=GD32 %s

## LA32 GD -> LE
# RUN: ld.lld %t/a.32.o %t/bc.32.o %t/tga.32.o -o %t/le.32
# RUN: llvm-readelf -r %t/le.32 | FileCheck --check-prefix=NOREL %s
# RUN: llvm-readelf -x .got %t/le.32 | FileCheck --check-prefix=LE32-GOT %s
# RUN: ld.lld -pie %t/a.32.o %t/bc.32.o %t/tga.32.o -o %t/le-pie.32
# RUN: llvm-readelf -r %t/le-pie.32 | FileCheck --check-prefix=NOREL %s
# RUN: llvm-readelf -x .got %t/le-pie.32 | FileCheck --check-prefix=LE32-GOT %s

## LA32 GD -> IE
# RUN: ld.lld %t/a.32.o %t/bc.32.so %t/tga.32.o -o %t/ie.32
# RUN: llvm-readobj -r %t/ie.32 | FileCheck --check-prefix=IE32-REL %s
# RUN: llvm-readelf -x .got %t/ie.32 | FileCheck --check-prefix=IE32-GOT %s

## LA64 GD
# RUN: ld.lld -shared %t/a.64.o %t/bc.64.o -o %t/gd.64.so
# RUN: llvm-readobj -r %t/gd.64.so | FileCheck --check-prefix=GD64-REL %s
# RUN: llvm-objdump -d --no-show-raw-insn %t/gd.64.so | FileCheck --check-prefix=GD64 %s

## LA64 GD -> LE
# RUN: ld.lld %t/a.64.o %t/bc.64.o %t/tga.64.o -o %t/le.64
# RUN: llvm-readelf -r %t/le.64 | FileCheck --check-prefix=NOREL %s
# RUN: llvm-readelf -x .got %t/le.64 | FileCheck --check-prefix=LE64-GOT %s
# RUN: ld.lld -pie %t/a.64.o %t/bc.64.o %t/tga.64.o -o %t/le-pie.64
# RUN: llvm-readelf -r %t/le-pie.64 | FileCheck --check-prefix=NOREL %s
# RUN: llvm-readelf -x .got %t/le-pie.64 | FileCheck --check-prefix=LE64-GOT %s

## LA64 GD -> IE
# RUN: ld.lld %t/a.64.o %t/bc.64.so %t/tga.64.o -o %t/ie.64
# RUN: llvm-readobj -r %t/ie.64 | FileCheck --check-prefix=IE64-REL %s
# RUN: llvm-readelf -x .got %t/ie.64 | FileCheck --check-prefix=IE64-GOT %s

# GD32-REL: .rela.dyn {
# GD32-REL-NEXT: 0x20300 R_LARCH_TLS_DTPMOD32 a 0x0
# GD32-REL-NEXT: 0x20304 R_LARCH_TLS_DTPREL32 a 0x0
# GD32-REL-NEXT: 0x20308 R_LARCH_TLS_DTPMOD32 b 0x0
# GD32-REL-NEXT: 0x2030C R_LARCH_TLS_DTPREL32 b 0x0
# GD32-REL-NEXT: }

## &DTPMOD(a) - . = 0x20300 - 0x10250 = 16428<<2
# GD32: 10250: pcaddi $a0, 16428
# GD32-NEXT: bl 44

## &DTPMOD(b) - . = 0x20308 - 0x10258 = 16428<<2
# GD32: 10258: pcaddi $a0, 16428
# GD32-NEXT: bl 36

# GD64-REL: .rela.dyn {
# GD64-REL-NEXT: 0x204C0 R_LARCH_TLS_DTPMOD64 a 0x0
# GD64-REL-NEXT: 0x204C8 R_LARCH_TLS_DTPREL64 a 0x0
# GD64-REL-NEXT: 0x204D0 R_LARCH_TLS_DTPMOD64 b 0x0
# GD64-REL-NEXT: 0x204D8 R_LARCH_TLS_DTPREL64 b 0x0
# GD64-REL-NEXT: }

## &DTPMOD(a) - . = 0x204c0 - 0x10398 = 16458<<2
# GD64: 10398: pcaddi $a0, 16458
# GD64-NEXT: bl 52

## &DTPMOD(b) - . = 0x204d0 - 0x103a4 = 16460<<2
# GD64: 103a0: pcaddi $a0, 16460
# GD64-NEXT: bl 44

# NOREL: no relocations

## .got contains pre-populated values: [a@dtpmod, a@dtprel, b@dtpmod, b@dtprel]
## a@dtprel = st_value(a) = 0x8
## b@dtprel = st_value(b) = 0xc
# LE32-GOT: section '.got':
# LE32-GOT-NEXT: 0x[[#%x,A:]] 01000000 08000000 01000000 0c000000
# LE64-GOT: section '.got':
# LE64-GOT-NEXT: 0x[[#%x,A:]] 01000000 00000000 08000000 00000000
# LE64-GOT-NEXT: 0x[[#%x,A:]] 01000000 00000000 0c000000 00000000

## a is local - relaxed to LE - its DTPMOD/DTPREL slots are link-time constants.
## b is external - DTPMOD/DTPREL dynamic relocations are required.
# IE32-REL: .rela.dyn {
# IE32-REL-NEXT: 0x30220 R_LARCH_TLS_DTPMOD32 b 0x0
# IE32-REL-NEXT: 0x30224 R_LARCH_TLS_DTPREL32 b 0x0
# IE32-REL-NEXT: }
# IE32-GOT: section '.got':
# IE32-GOT-NEXT: 0x00030218 01000000 08000000 00000000 00000000

# IE64-REL: .rela.dyn {
# IE64-REL-NEXT: 0x30380 R_LARCH_TLS_DTPMOD64 b 0x0
# IE64-REL-NEXT: 0x30388 R_LARCH_TLS_DTPREL64 b 0x0
# IE64-REL-NEXT: }
# IE64-GOT: section '.got':
# IE64-GOT-NEXT: 0x00030370 01000000 00000000 08000000 00000000
# IE64-GOT-NEXT: 0x00030380 00000000 00000000 00000000 00000000

#--- a.s
pcaddi $a0, %gd_pcrel_20(a)
bl %plt(__tls_get_addr)

pcaddi $a0, %gd_pcrel_20(b)
bl %plt(__tls_get_addr)

.section .tbss,"awT",@nobits
.globl a
.zero 8
a:
.zero 4

#--- bc.s
.section .tbss,"awT",@nobits
.globl b, c
b:
.zero 4
c:

#--- tga.s
.globl __tls_get_addr
__tls_get_addr:
82 changes: 82 additions & 0 deletions lld/test/ELF/loongarch-tls-ld-pcrel20-s2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# REQUIRES: loongarch
# RUN: rm -rf %t && split-file %s %t

# RUN: llvm-mc --filetype=obj --triple=loongarch32 --position-independent %t/a.s -o %t/a.32.o
# RUN: llvm-mc --filetype=obj --triple=loongarch32 %t/tga.s -o %t/tga.32.o
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --position-independent %t/a.s -o %t/a.64.o
# RUN: llvm-mc --filetype=obj --triple=loongarch64 %t/tga.s -o %t/tga.64.o

## LA32 LD
# RUN: ld.lld -shared %t/a.32.o -o %t/ld.32.so
# RUN: llvm-readobj -r %t/ld.32.so | FileCheck --check-prefix=LD32-REL %s
# RUN: llvm-readelf -x .got %t/ld.32.so | FileCheck --check-prefix=LD32-GOT %s
# RUN: llvm-objdump -d --no-show-raw-insn %t/ld.32.so | FileCheck --check-prefixes=LD32 %s

## LA32 LD -> LE
# RUN: ld.lld %t/a.32.o %t/tga.32.o -o %t/le.32
# RUN: llvm-readelf -r %t/le.32 | FileCheck --check-prefix=NOREL %s
# RUN: llvm-readelf -x .got %t/le.32 | FileCheck --check-prefix=LE32-GOT %s
# RUN: llvm-objdump -d --no-show-raw-insn %t/le.32 | FileCheck --check-prefixes=LE32 %s

## LA64 LD
# RUN: ld.lld -shared %t/a.64.o -o %t/ld.64.so
# RUN: llvm-readobj -r %t/ld.64.so | FileCheck --check-prefix=LD64-REL %s
# RUN: llvm-readelf -x .got %t/ld.64.so | FileCheck --check-prefix=LD64-GOT %s
# RUN: llvm-objdump -d --no-show-raw-insn %t/ld.64.so | FileCheck --check-prefixes=LD64 %s

## LA64 LD -> LE
# RUN: ld.lld %t/a.64.o %t/tga.64.o -o %t/le.64
# RUN: llvm-readelf -r %t/le.64 | FileCheck --check-prefix=NOREL %s
# RUN: llvm-readelf -x .got %t/le.64 | FileCheck --check-prefix=LE64-GOT %s
# RUN: llvm-objdump -d --no-show-raw-insn %t/le.64 | FileCheck --check-prefixes=LE64 %s

## a@dtprel = st_value(a) = 0 is a link-time constant.
# LD32-REL: .rela.dyn {
# LD32-REL-NEXT: 0x20280 R_LARCH_TLS_DTPMOD32 - 0x0
# LD32-REL-NEXT: }
# LD32-GOT: section '.got':
# LD32-GOT-NEXT: 0x00020280 00000000 00000000

# LD64-REL: .rela.dyn {
# LD64-REL-NEXT: 0x20400 R_LARCH_TLS_DTPMOD64 - 0x0
# LD64-REL-NEXT: }
# LD64-GOT: section '.got':
# LD64-GOT-NEXT: 0x00020400 00000000 00000000 00000000 00000000

## LA32: &DTPMOD(a) - . = 0x20280 - 0x101cc = 16429<<2
# LD32: 101cc: pcaddi $a0, 16429
# LD32-NEXT: bl 48

## LA64: &DTPMOD(a) - . = 0x20400 - 0x102e0 = 16456<<2
# LD64: 102e0: pcaddi $a0, 16456
# LD64-NEXT: bl 44

# NOREL: no relocations

## a is local - its DTPMOD/DTPREL slots are link-time constants.
## a@dtpmod = 1 (main module)
# LE32-GOT: section '.got':
# LE32-GOT-NEXT: 0x0003011c 01000000 00000000

# LE64-GOT: section '.got':
# LE64-GOT-NEXT: 0x000301d0 01000000 00000000 00000000 00000000

## LA32: DTPMOD(.LANCHOR0) - . = 0x3011c - 0x20114 = 16386<<2
# LE32: 20114: pcaddi $a0, 16386
# LE32-NEXT: bl 4

## LA64: DTPMOD(.LANCHOR0) - . = 0x301d0 - 0x201c8 = 16386<<2
# LE64: 201c8: pcaddi $a0, 16386
# LE64-NEXT: bl 4

#--- a.s
pcaddi $a0, %ld_pcrel_20(.LANCHOR0)
bl %plt(__tls_get_addr)

.section .tbss,"awT",@nobits
.set .LANCHOR0, . + 0
.zero 8

#--- tga.s
.globl __tls_get_addr
__tls_get_addr:
142 changes: 142 additions & 0 deletions lld/test/ELF/loongarch-tlsdesc-pcrel20-s2.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# REQUIRES: loongarch
# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple=loongarch64 a.s -o a.64.o
# RUN: llvm-mc -filetype=obj -triple=loongarch64 c.s -o c.64.o
# RUN: ld.lld -shared -soname=c.64.so c.64.o -o c.64.so
# RUN: llvm-mc -filetype=obj -triple=loongarch32 --defsym ELF32=1 a.s -o a.32.o
# RUN: llvm-mc -filetype=obj -triple=loongarch32 --defsym ELF32=1 c.s -o c.32.o
# RUN: ld.lld -shared -soname=c.32.so c.32.o -o c.32.so

# RUN: ld.lld -shared -z now a.64.o c.64.o -o a.64.so
# RUN: llvm-readobj -r -x .got a.64.so | FileCheck --check-prefix=GD64-RELA %s
# RUN: llvm-objdump --no-show-raw-insn -h -d a.64.so | FileCheck %s --check-prefix=GD64

# RUN: ld.lld -shared -z now a.64.o c.64.o -o rel.64.so -z rel
# RUN: llvm-readobj -r -x .got rel.64.so | FileCheck --check-prefix=GD64-REL %s

## FIXME: The transition frome TLSDESC to IE/LE has not yet been implemented.
## Keep the dynamic relocations and hand them over to dynamic linker.

# RUN: ld.lld -e 0 -z now a.64.o c.64.o -o a.64.le
# RUN: llvm-readobj -r -x .got a.64.le | FileCheck --check-prefix=LE64-RELA %s

# RUN: ld.lld -e 0 -z now a.64.o c.64.so -o a.64.ie
# RUN: llvm-readobj -r -x .got a.64.ie | FileCheck --check-prefix=IE64-RELA %s

## 32-bit code is mostly the same. We only test a few variants.

# RUN: ld.lld -shared -z now a.32.o c.32.o -o rel.32.so -z rel
# RUN: llvm-readobj -r -x .got rel.32.so | FileCheck --check-prefix=GD32-REL %s

# GD64-RELA: .rela.dyn {
# GD64-RELA-NEXT: 0x203F0 R_LARCH_TLS_DESC64 - 0x7FF
# GD64-RELA-NEXT: 0x203D0 R_LARCH_TLS_DESC64 a 0x0
# GD64-RELA-NEXT: 0x203E0 R_LARCH_TLS_DESC64 c 0x0
# GD64-RELA-NEXT: }
# GD64-RELA: Hex dump of section '.got':
# GD64-RELA-NEXT: 0x000203d0 00000000 00000000 00000000 00000000 .
# GD64-RELA-NEXT: 0x000203e0 00000000 00000000 00000000 00000000 .
# GD64-RELA-NEXT: 0x000203f0 00000000 00000000 00000000 00000000 .

# GD64-REL: .rel.dyn {
# GD64-REL-NEXT: 0x203D8 R_LARCH_TLS_DESC64 -
# GD64-REL-NEXT: 0x203B8 R_LARCH_TLS_DESC64 a
# GD64-REL-NEXT: 0x203C8 R_LARCH_TLS_DESC64 c
# GD64-REL-NEXT: }
# GD64-REL: Hex dump of section '.got':
# GD64-REL-NEXT: 0x000203b8 00000000 00000000 00000000 00000000 .
# GD64-REL-NEXT: 0x000203c8 00000000 00000000 00000000 00000000 .
# GD64-REL-NEXT: 0x000203d8 00000000 00000000 ff070000 00000000 .

# GD64: .got 00000030 00000000000203d0

## &.got[a]-. = 0x203d0 - 0x102e0 = 16444<<2
# GD64: 102e0: pcaddi $a0, 16444
# GD64-NEXT: ld.d $ra, $a0, 0
# GD64-NEXT: jirl $ra, $ra, 0
# GD64-NEXT: add.d $a1, $a0, $tp

## &.got[b]-. = 0x203d0+32 - 0x102f0 = 16448<<2
# GD64: 102f0: pcaddi $a0, 16448
# GD64-NEXT: ld.d $ra, $a0, 0
# GD64-NEXT: jirl $ra, $ra, 0
# GD64-NEXT: add.d $a2, $a0, $tp

## &.got[c]-. = 0x203d0+16 - 0x10300 = 16440<<2
# GD64: 10300: pcaddi $a0, 16440
# GD64-NEXT: ld.d $ra, $a0, 0
# GD64-NEXT: jirl $ra, $ra, 0
# GD64-NEXT: add.d $a3, $a0, $tp

# LE64-RELA: .rela.dyn {
# LE64-RELA-NEXT: 0x30240 R_LARCH_TLS_DESC64 - 0x8
# LE64-RELA-NEXT: 0x30250 R_LARCH_TLS_DESC64 - 0x800
# LE64-RELA-NEXT: 0x30260 R_LARCH_TLS_DESC64 - 0x7FF
# LE64-RELA-NEXT: }
# LE64-RELA: Hex dump of section '.got':
# LE64-RELA-NEXT: 0x00030240 00000000 00000000 00000000 00000000 .
# LE64-RELA-NEXT: 0x00030250 00000000 00000000 00000000 00000000 .
# LE64-RELA-NEXT: 0x00030260 00000000 00000000 00000000 00000000 .

# IE64-RELA: .rela.dyn {
# IE64-RELA-NEXT: 0x303C8 R_LARCH_TLS_DESC64 - 0x8
# IE64-RELA-NEXT: 0x303E8 R_LARCH_TLS_DESC64 - 0x7FF
# IE64-RELA-NEXT: 0x303D8 R_LARCH_TLS_DESC64 c 0x0
# IE64-RELA-NEXT: }
# IE64-RELA: Hex dump of section '.got':
# IE64-RELA-NEXT: 0x000303c8 00000000 00000000 00000000 00000000 .
# IE64-RELA-NEXT: 0x000303d8 00000000 00000000 00000000 00000000 .
# IE64-RELA-NEXT: 0x000303e8 00000000 00000000 00000000 00000000 .

# GD32-REL: .rel.dyn {
# GD32-REL-NEXT: 0x20264 R_LARCH_TLS_DESC32 -
# GD32-REL-NEXT: 0x20254 R_LARCH_TLS_DESC32 a
# GD32-REL-NEXT: 0x2025C R_LARCH_TLS_DESC32 c
# GD32-REL-NEXT: }
# GD32-REL: Hex dump of section '.got':
# GD32-REL-NEXT: 0x00020254 00000000 00000000 00000000 00000000 .
# GD32-REL-NEXT: 0x00020264 00000000 ff070000 .

#--- a.s
.macro add dst, src1, src2
.ifdef ELF32
add.w \dst, \src1, \src2
.else
add.d \dst, \src1, \src2
.endif
.endm
.macro load dst, src1, src2
.ifdef ELF32
ld.w \dst, \src1, \src2
.else
ld.d \dst, \src1, \src2
.endif
.endm

pcaddi $a0, %desc_pcrel_20(a)
load $ra, $a0, %desc_ld(a)
jirl $ra, $ra, %desc_call(a)
add $a1, $a0, $tp

pcaddi $a0, %desc_pcrel_20(b)
load $ra, $a0, %desc_ld(b)
jirl $ra, $ra, %desc_call(b)
add $a2, $a0, $tp

pcaddi $a0, %desc_pcrel_20(c)
load $ra, $a0, %desc_ld(c)
jirl $ra, $ra, %desc_call(c)
add $a3, $a0, $tp

.section .tbss,"awT",@nobits
.globl a
.zero 8
a:
.zero 2039 ## Place b at 0x7ff
b:
.zero 1

#--- c.s
.section .tbss,"awT",@nobits
.globl c
c: .zero 4
20 changes: 0 additions & 20 deletions lldb/include/lldb/Core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define LLDB_CORE_PLUGINMANAGER_H

#include "lldb/Core/Architecture.h"
#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
#include "lldb/Symbol/TypeSystem.h"
#include "lldb/Utility/CompletionRequest.h"
#include "lldb/Utility/FileSpec.h"
Expand Down Expand Up @@ -488,25 +487,6 @@ class PluginManager {

static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();

// Scripted Interface
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
ScriptedInterfaceCreateInstance create_callback,
lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages);

static bool UnregisterPlugin(ScriptedInterfaceCreateInstance create_callback);

static uint32_t GetNumScriptedInterfaces();

static llvm::StringRef GetScriptedInterfaceNameAtIndex(uint32_t idx);

static llvm::StringRef GetScriptedInterfaceDescriptionAtIndex(uint32_t idx);

static lldb::ScriptLanguage GetScriptedInterfaceLanguageAtIndex(uint32_t idx);

static ScriptedInterfaceUsages
GetScriptedInterfaceUsagesAtIndex(uint32_t idx);

// REPL
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
REPLCreateInstance create_callback,
Expand Down
7 changes: 0 additions & 7 deletions lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#ifndef LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
#define LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H

#include "ScriptedInterfaceUsages.h"

#include "lldb/Core/StructuredDataImpl.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
Expand Down Expand Up @@ -70,11 +68,6 @@ class ScriptedInterface {
return true;
}

static bool CreateInstance(lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages) {
return false;
}

protected:
StructuredData::GenericSP m_object_instance_sp;
};
Expand Down
43 changes: 0 additions & 43 deletions lldb/include/lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h

This file was deleted.

3 changes: 0 additions & 3 deletions lldb/include/lldb/lldb-private-interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Value;
} // namespace llvm

namespace lldb_private {
class ScriptedInterfaceUsages;
typedef lldb::ABISP (*ABICreateInstance)(lldb::ProcessSP process_sp,
const ArchSpec &arch);
typedef std::unique_ptr<Architecture> (*ArchitectureCreateInstance)(
Expand Down Expand Up @@ -125,8 +124,6 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error,
lldb::LanguageType language,
Debugger *debugger, Target *target,
const char *repl_options);
typedef bool (*ScriptedInterfaceCreateInstance)(lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages);
typedef int (*ComparisonFunction)(const void *, const void *);
typedef void (*DebuggerInitializeCallback)(Debugger &debugger);
/// Trace
Expand Down
126 changes: 2 additions & 124 deletions lldb/source/Commands/CommandObjectScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

#include "CommandObjectScripting.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/DataFormatters/DataVisualization.h"
#include "lldb/Host/Config.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandOptionArgumentTable.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Utility/Args.h"
Expand Down Expand Up @@ -129,126 +127,9 @@ class CommandObjectScriptingRun : public CommandObjectRaw {
CommandOptions m_options;
};

#define LLDB_OPTIONS_scripting_template_list
#include "CommandOptions.inc"

class CommandObjectScriptingTemplateList : public CommandObjectParsed {
public:
CommandObjectScriptingTemplateList(CommandInterpreter &interpreter)
: CommandObjectParsed(
interpreter, "scripting template list",
"List all the available scripting extension templates. ",
"scripting template list [--language <scripting-language> --]") {}

~CommandObjectScriptingTemplateList() override = default;

Options *GetOptions() override { return &m_options; }

class CommandOptions : public Options {
public:
CommandOptions() = default;
~CommandOptions() override = default;
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
ExecutionContext *execution_context) override {
Status error;
const int short_option = m_getopt_table[option_idx].val;
#pragma mark CommandObjectMultiwordScripting

switch (short_option) {
case 'l':
m_language = (lldb::ScriptLanguage)OptionArgParser::ToOptionEnum(
option_arg, GetDefinitions()[option_idx].enum_values,
eScriptLanguageNone, error);
if (!error.Success())
error.SetErrorStringWithFormatv(
"unrecognized value for language '{0}'", option_arg);
break;
default:
llvm_unreachable("Unimplemented option");
}

return error;
}

void OptionParsingStarting(ExecutionContext *execution_context) override {
m_language = lldb::eScriptLanguageDefault;
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
return llvm::ArrayRef(g_scripting_template_list_options);
}

lldb::ScriptLanguage m_language = lldb::eScriptLanguageDefault;
};

protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Stream &s = result.GetOutputStream();
s.Printf("Available scripted extension templates:");

auto print_field = [&s](llvm::StringRef key, llvm::StringRef value) {
if (!value.empty()) {
s.IndentMore();
s.Indent();
s << key << ": " << value << '\n';
s.IndentLess();
}
};

size_t num_listed_interface = 0;
size_t num_templates = PluginManager::GetNumScriptedInterfaces();
for (size_t i = 0; i < num_templates; i++) {
llvm::StringRef plugin_name =
PluginManager::GetScriptedInterfaceNameAtIndex(i);
if (plugin_name.empty())
break;

lldb::ScriptLanguage lang =
PluginManager::GetScriptedInterfaceLanguageAtIndex(i);
if (lang != m_options.m_language)
continue;

if (!num_listed_interface)
s.EOL();

num_listed_interface++;

llvm::StringRef desc =
PluginManager::GetScriptedInterfaceDescriptionAtIndex(i);
ScriptedInterfaceUsages usages =
PluginManager::GetScriptedInterfaceUsagesAtIndex(i);

print_field("Name", plugin_name);
print_field("Language", ScriptInterpreter::LanguageToString(lang));
print_field("Description", desc);
usages.Dump(s, ScriptedInterfaceUsages::UsageKind::API);
usages.Dump(s, ScriptedInterfaceUsages::UsageKind::CommandInterpreter);

if (i != num_templates - 1)
s.EOL();
}

if (!num_listed_interface)
s << " None\n";
}

private:
CommandOptions m_options;
};

class CommandObjectMultiwordScriptingTemplate : public CommandObjectMultiword {
public:
CommandObjectMultiwordScriptingTemplate(CommandInterpreter &interpreter)
: CommandObjectMultiword(
interpreter, "scripting template",
"Commands for operating on the scripting templates.",
"scripting template [<subcommand-options>]") {
LoadSubCommand(
"list",
CommandObjectSP(new CommandObjectScriptingTemplateList(interpreter)));
}

~CommandObjectMultiwordScriptingTemplate() override = default;
};
// CommandObjectMultiwordScripting

CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
CommandInterpreter &interpreter)
Expand All @@ -258,9 +139,6 @@ CommandObjectMultiwordScripting::CommandObjectMultiwordScripting(
"scripting <subcommand> [<subcommand-options>]") {
LoadSubCommand("run",
CommandObjectSP(new CommandObjectScriptingRun(interpreter)));
LoadSubCommand("template",
CommandObjectSP(
new CommandObjectMultiwordScriptingTemplate(interpreter)));
}

CommandObjectMultiwordScripting::~CommandObjectMultiwordScripting() = default;
6 changes: 0 additions & 6 deletions lldb/source/Commands/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -841,12 +841,6 @@ let Command = "scripting run" in {
" language. If none is specific the default scripting language is used.">;
}

let Command = "scripting template list" in {
def scripting_template_list_language : Option<"language", "l">,
EnumArg<"ScriptLang">, Desc<"Specify the scripting "
" language. If none is specified the default scripting language is used.">;
}

let Command = "source info" in {
def source_info_count : Option<"count", "c">, Arg<"Count">,
Desc<"The number of line entries to display.">;
Expand Down
65 changes: 0 additions & 65 deletions lldb/source/Core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,70 +1505,6 @@ LanguageSet PluginManager::GetAllTypeSystemSupportedLanguagesForExpressions() {
return all;
}

#pragma mark ScriptedInterfaces

struct ScriptedInterfaceInstance
: public PluginInstance<ScriptedInterfaceCreateInstance> {
ScriptedInterfaceInstance(llvm::StringRef name, llvm::StringRef description,
ScriptedInterfaceCreateInstance create_callback,
lldb::ScriptLanguage language,
ScriptedInterfaceUsages usages)
: PluginInstance<ScriptedInterfaceCreateInstance>(name, description,
create_callback),
language(language), usages(usages) {}

lldb::ScriptLanguage language;
ScriptedInterfaceUsages usages;
};

typedef PluginInstances<ScriptedInterfaceInstance> ScriptedInterfaceInstances;

static ScriptedInterfaceInstances &GetScriptedInterfaceInstances() {
static ScriptedInterfaceInstances g_instances;
return g_instances;
}

bool PluginManager::RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
ScriptedInterfaceCreateInstance create_callback,
lldb::ScriptLanguage language, ScriptedInterfaceUsages usages) {
return GetScriptedInterfaceInstances().RegisterPlugin(
name, description, create_callback, language, usages);
}

bool PluginManager::UnregisterPlugin(
ScriptedInterfaceCreateInstance create_callback) {
return GetScriptedInterfaceInstances().UnregisterPlugin(create_callback);
}

uint32_t PluginManager::GetNumScriptedInterfaces() {
return GetScriptedInterfaceInstances().GetInstances().size();
}

llvm::StringRef PluginManager::GetScriptedInterfaceNameAtIndex(uint32_t index) {
return GetScriptedInterfaceInstances().GetNameAtIndex(index);
}

llvm::StringRef
PluginManager::GetScriptedInterfaceDescriptionAtIndex(uint32_t index) {
return GetScriptedInterfaceInstances().GetDescriptionAtIndex(index);
}

lldb::ScriptLanguage
PluginManager::GetScriptedInterfaceLanguageAtIndex(uint32_t idx) {
const auto &instances = GetScriptedInterfaceInstances().GetInstances();
return idx < instances.size() ? instances[idx].language
: ScriptLanguage::eScriptLanguageNone;
}

ScriptedInterfaceUsages
PluginManager::GetScriptedInterfaceUsagesAtIndex(uint32_t idx) {
const auto &instances = GetScriptedInterfaceInstances().GetInstances();
if (idx >= instances.size())
return {};
return instances[idx].usages;
}

#pragma mark REPL

struct REPLInstance : public PluginInstance<REPLCreateInstance> {
Expand Down Expand Up @@ -1629,7 +1565,6 @@ void PluginManager::DebuggerInitialize(Debugger &debugger) {
GetOperatingSystemInstances().PerformDebuggerCallback(debugger);
GetStructuredDataPluginInstances().PerformDebuggerCallback(debugger);
GetTracePluginInstances().PerformDebuggerCallback(debugger);
GetScriptedInterfaceInstances().PerformDebuggerCallback(debugger);
}

// This is the preferred new way to register plugin specific settings. e.g.
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ lldb_tablegen(InterpreterPropertiesEnum.inc -gen-lldb-property-enum-defs
SOURCE InterpreterProperties.td
TARGET LLDBInterpreterPropertiesEnumGen)

add_subdirectory(Interfaces)

add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
CommandAlias.cpp
CommandHistory.cpp
Expand Down Expand Up @@ -56,7 +54,6 @@ add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
ScriptInterpreter.cpp

LINK_LIBS
lldbInterpreterInterfaces
lldbCommands
lldbCore
lldbDataFormatters
Expand All @@ -69,7 +66,6 @@ add_lldb_library(lldbInterpreter NO_PLUGIN_DEPENDENCIES
)

add_dependencies(lldbInterpreter
lldbInterpreterInterfaces
LLDBInterpreterPropertiesGen
LLDBInterpreterPropertiesEnumGen)

10 changes: 0 additions & 10 deletions lldb/source/Interpreter/Interfaces/CMakeLists.txt

This file was deleted.

37 changes: 0 additions & 37 deletions lldb/source/Interpreter/Interfaces/ScriptedInterfaceUsages.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ if (LLDB_ENABLE_LIBEDIT)
endif()

add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
OperatingSystemPythonInterface.cpp
ScriptedPythonInterface.cpp
ScriptedProcessPythonInterface.cpp
ScriptedThreadPythonInterface.cpp
ScriptedThreadPlanPythonInterface.cpp
ScriptedPlatformPythonInterface.cpp

LINK_LIBS
lldbCore
Expand All @@ -34,9 +38,3 @@ add_lldb_library(lldbPluginScriptInterpreterPythonInterfaces
LINK_COMPONENTS
Support
)

add_subdirectory(OperatingSystemPythonInterface)
add_subdirectory(ScriptedPlatformPythonInterface)
add_subdirectory(ScriptedProcessPythonInterface)
add_subdirectory(ScriptedThreadPlanPythonInterface)

Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,25 @@
//
//===----------------------------------------------------------------------===//

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/Log.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#include "../lldb-python.h"

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "OperatingSystemPythonInterface.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;
using Locker = ScriptInterpreterPythonImpl::Locker;

LLDB_PLUGIN_DEFINE_ADV(OperatingSystemPythonInterface, ScriptInterpreterPythonOperatingSystemPythonInterface)

OperatingSystemPythonInterface::OperatingSystemPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: OperatingSystemInterface(), ScriptedThreadPythonInterface(interpreter) {}
Expand Down Expand Up @@ -84,18 +79,4 @@ OperatingSystemPythonInterface::GetRegisterContextForTID(lldb::tid_t tid) {
return obj->GetAsString()->GetValue().str();
}

void OperatingSystemPythonInterface::Initialize() {
const std::vector<llvm::StringRef> ci_usages = {
"settings set target.process.python-os-plugin-path <script-path>",
"settings set process.experimental.os-plugin-reports-all-threads [0/1]"};
const std::vector<llvm::StringRef> api_usages = {};
PluginManager::RegisterPlugin(
GetPluginNameStatic(), llvm::StringRef("Mock thread state"),
CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
}

void OperatingSystemPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,18 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_OPERATINGSYSTEMPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/OperatingSystemInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedThreadPythonInterface.h"

#include "ScriptedThreadPythonInterface.h"
#include "lldb/Interpreter/Interfaces/OperatingSystemInterface.h"
#include <optional>

namespace lldb_private {
class OperatingSystemPythonInterface
: virtual public OperatingSystemInterface,
virtual public ScriptedThreadPythonInterface,
public PluginInterface {
virtual public ScriptedThreadPythonInterface {
public:
OperatingSystemPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand All @@ -51,16 +41,6 @@ class OperatingSystemPythonInterface
StructuredData::DictionarySP GetRegisterInfo() override;

std::optional<std::string> GetRegisterContextForTID(lldb::tid_t tid) override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "OperatingSystemPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
} // namespace lldb_private

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,27 @@
//
//===----------------------------------------------------------------------===//

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
// LLDB Python header must be included first
#include "../lldb-python.h"

#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedPlatformPythonInterface.h"

#include "lldb/Target/ExecutionContext.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;
using Locker = ScriptInterpreterPythonImpl::Locker;

LLDB_PLUGIN_DEFINE_ADV(ScriptedPlatformPythonInterface, ScriptInterpreterPythonScriptedPlatformPythonInterface)

ScriptedPlatformPythonInterface::ScriptedPlatformPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedPlatformInterface(), ScriptedPythonInterface(interpreter) {}
Expand Down Expand Up @@ -100,14 +93,4 @@ Status ScriptedPlatformPythonInterface::KillProcess(lldb::pid_t pid) {
return GetStatusFromMethod("kill_process", pid);
}

void ScriptedPlatformPythonInterface::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), "Mock platform and interact with its processes.",
CreateInstance, eScriptLanguagePython, {});
}

void ScriptedPlatformPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif // LLDB_ENABLE_PYTHON
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPLATFORMPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPLATFORMPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedPythonInterface.h"
#include "ScriptedPythonInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedPlatformInterface.h"

namespace lldb_private {
class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
public ScriptedPythonInterface,
public PluginInterface {
public ScriptedPythonInterface {
public:
ScriptedPlatformPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand All @@ -52,16 +43,6 @@ class ScriptedPlatformPythonInterface : public ScriptedPlatformInterface,
Status LaunchProcess(lldb::ProcessLaunchInfoSP launch_info) override;

Status KillProcess(lldb::pid_t pid) override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "ScriptedPlatformPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
} // namespace lldb_private

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,29 @@
//
//===----------------------------------------------------------------------===//

#include "lldb/Host/Config.h"
#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#include "../lldb-python.h"
#endif

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
#include "../ScriptedThreadPythonInterface.h"
#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedProcessPythonInterface.h"

#include "ScriptedThreadPythonInterface.h"
#include <optional>

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;
using Locker = ScriptInterpreterPythonImpl::Locker;

LLDB_PLUGIN_DEFINE_ADV(ScriptedProcessPythonInterface, ScriptInterpreterPythonScriptedProcessPythonInterface)

ScriptedProcessPythonInterface::ScriptedProcessPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedProcessInterface(), ScriptedPythonInterface(interpreter) {}
Expand Down Expand Up @@ -216,24 +208,4 @@ StructuredData::DictionarySP ScriptedProcessPythonInterface::GetMetadata() {
return dict;
}

void ScriptedProcessPythonInterface::Initialize() {
const std::vector<llvm::StringRef> ci_usages = {
"process attach -C <script-name> [-k key -v value ...]",
"process launch -C <script-name> [-k key -v value ...]"};
const std::vector<llvm::StringRef> api_usages = {
"SBAttachInfo.SetScriptedProcessClassName",
"SBAttachInfo.SetScriptedProcessDictionary",
"SBTarget.Attach",
"SBLaunchInfo.SetScriptedProcessClassName",
"SBLaunchInfo.SetScriptedProcessDictionary",
"SBTarget.Launch"};
PluginManager::RegisterPlugin(
GetPluginNameStatic(), llvm::StringRef("Mock process state"),
CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
}

void ScriptedProcessPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,17 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPROCESSPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPROCESSPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedPythonInterface.h"

#include "ScriptedPythonInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedProcessInterface.h"
#include <optional>

namespace lldb_private {
class ScriptedProcessPythonInterface : public ScriptedProcessInterface,
public ScriptedPythonInterface,
public PluginInterface {
public ScriptedPythonInterface {
public:
ScriptedProcessPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand Down Expand Up @@ -77,16 +67,6 @@ class ScriptedProcessPythonInterface : public ScriptedProcessInterface,

StructuredData::DictionarySP GetMetadata() override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "ScriptedProcessPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }

private:
lldb::ScriptedThreadInterfaceSP CreateScriptedThreadInterface() override;
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
//
//===----------------------------------------------------------------------===//

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/Utility/Log.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

// LLDB Python header must be included first
#include "../lldb-python.h"

#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedPythonInterface.h"
#include <optional>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,16 @@
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON
// clang-format off
// LLDB Python header must be included first
#include "../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedInterface.h"
#include "lldb/Utility/DataBufferHeap.h"

#include <optional>
#include <sstream>
#include <tuple>
#include <type_traits>
#include <utility>

#if LLDB_ENABLE_PYTHON
#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedInterface.h"
#include "lldb/Utility/DataBufferHeap.h"

#include "../PythonDataObjects.h"
#include "../SWIGPythonBridge.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,23 @@
//
//===----------------------------------------------------------------------===//

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Core/PluginManager.h"
#include "lldb/Host/Config.h"
#include "lldb/Utility/Log.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

#include "../../SWIGPythonBridge.h"
#include "../../ScriptInterpreterPythonImpl.h"
// LLDB Python header must be included first
#include "../lldb-python.h"

#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedThreadPlanPythonInterface.h"

using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::python;

LLDB_PLUGIN_DEFINE_ADV(ScriptedThreadPlanPythonInterface, ScriptInterpreterPythonScriptedThreadPlanPythonInterface)

ScriptedThreadPlanPythonInterface::ScriptedThreadPlanPythonInterface(
ScriptInterpreterPythonImpl &interpreter)
: ScriptedThreadPlanInterface(), ScriptedPythonInterface(interpreter) {}
Expand Down Expand Up @@ -110,19 +102,4 @@ ScriptedThreadPlanPythonInterface::GetStopDescription(lldb::StreamSP &stream) {
return llvm::Error::success();
}

void ScriptedThreadPlanPythonInterface::Initialize() {
const std::vector<llvm::StringRef> ci_usages = {
"thread step-scripted -C <script-name> [-k key -v value ...]"};
const std::vector<llvm::StringRef> api_usages = {
"SBThread.StepUsingScriptedThreadPlan"};
PluginManager::RegisterPlugin(
GetPluginNameStatic(),
llvm::StringRef("Alter thread stepping logic and stop reason"),
CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
}

void ScriptedThreadPlanPythonInterface::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,17 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPLANPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPLANPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on

#endif

#include "lldb/Host/Config.h"
#include "lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h"

#if LLDB_ENABLE_PYTHON

#include "../ScriptedPythonInterface.h"

#include "ScriptedPythonInterface.h"
#include "lldb/Interpreter/Interfaces/ScriptedThreadPlanInterface.h"
#include <optional>

namespace lldb_private {
class ScriptedThreadPlanPythonInterface : public ScriptedThreadPlanInterface,
public ScriptedPythonInterface,
public PluginInterface {
public ScriptedPythonInterface {
public:
ScriptedThreadPlanPythonInterface(ScriptInterpreterPythonImpl &interpreter);

Expand All @@ -52,16 +41,6 @@ class ScriptedThreadPlanPythonInterface : public ScriptedThreadPlanInterface,
lldb::StateType GetRunState() override;

llvm::Error GetStopDescription(lldb::StreamSP &stream) override;

static void Initialize();

static void Terminate();

static llvm::StringRef GetPluginNameStatic() {
return "ScriptedThreadPlanPythonInterface";
}

llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
};
} // namespace lldb_private

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@
//
//===----------------------------------------------------------------------===//

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/Log.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

// LLDB Python header must be included first
#include "../lldb-python.h"

#include "../SWIGPythonBridge.h"
#include "../ScriptInterpreterPythonImpl.h"
#include "ScriptedThreadPythonInterface.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPYTHONINTERFACE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDTHREADPYTHONINTERFACE_H

#if LLDB_ENABLE_PYTHON
// clang-format off
// LLDB Python header must be included first
#include "../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"

#if LLDB_ENABLE_PYTHON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,12 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_PYTHONDATAOBJECTS_H

#include "lldb/Host/Config.h"

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"

#if LLDB_ENABLE_PYTHON

#include "lldb/Host/File.h"
#include "lldb/Utility/StructuredData.h"
Expand Down
15 changes: 5 additions & 10 deletions lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SWIGPYTHONBRIDGE_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"

#include <optional>
#include <string>

#include "lldb/Host/Config.h"

#if LLDB_ENABLE_PYTHON

// LLDB Python header must be included first
#include "lldb-python.h"

#include "Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-types.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@
//
//===----------------------------------------------------------------------===//

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "../../lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"
#include "lldb/lldb-enumerations.h"

#if LLDB_ENABLE_PYTHON

#include "Interfaces/OperatingSystemPythonInterface/OperatingSystemPythonInterface.h"
#include "Interfaces/ScriptedPlatformPythonInterface/ScriptedPlatformPythonInterface.h"
#include "Interfaces/ScriptedProcessPythonInterface/ScriptedProcessPythonInterface.h"
#include "Interfaces/ScriptedThreadPlanPythonInterface/ScriptedThreadPlanPythonInterface.h"
// LLDB Python header must be included first
#include "lldb-python.h"

#include "Interfaces/OperatingSystemPythonInterface.h"
#include "Interfaces/ScriptedPlatformPythonInterface.h"
#include "Interfaces/ScriptedProcessPythonInterface.h"
#include "Interfaces/ScriptedThreadPlanPythonInterface.h"
#include "Interfaces/ScriptedThreadPythonInterface.h"
#include "PythonDataObjects.h"
#include "PythonReadline.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHON_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"

#if LLDB_ENABLE_PYTHON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@
#ifndef LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHONIMPL_H
#define LLDB_PLUGINS_SCRIPTINTERPRETER_PYTHON_SCRIPTINTERPRETERPYTHONIMPL_H

#if LLDB_ENABLE_PYTHON

// clang-format off
// LLDB Python header must be included first
#include "lldb-python.h"
//clang-format on
#endif

#include "lldb/Host/Config.h"

#if LLDB_ENABLE_PYTHON

#include "lldb-python.h"

#include "PythonDataObjects.h"
#include "ScriptInterpreterPython.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@


class TestCaseClassTemplateNonTypeParameterPack(TestBase):
@expectedFailureAll(
oslist=["windows"], archs=["i[3-6]86", "x86_64"]
) # Fails to read memory from target.
@no_debug_info_test
def test(self):
self.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@


class TestCaseClassTemplateTypeParameterPack(TestBase):
@expectedFailureAll(
oslist=["windows"], archs=["i[3-6]86", "x86_64"]
) # Fails to read memory from target.
@no_debug_info_test
def test(self):
self.build()
Expand Down
1 change: 0 additions & 1 deletion llvm/bindings/ocaml/llvm/llvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ external vector_size : lltype -> int = "llvm_vector_size"
(*--... Operations on other types ..........................................--*)
external void_type : llcontext -> lltype = "llvm_void_type"
external label_type : llcontext -> lltype = "llvm_label_type"
external x86_mmx_type : llcontext -> lltype = "llvm_x86_mmx_type"
external type_by_name : llmodule -> string -> lltype option = "llvm_type_by_name"

external classify_value : llvalue -> ValueKind.t = "llvm_classify_value"
Expand Down
22 changes: 8 additions & 14 deletions llvm/include/llvm/Analysis/LoopAccessAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ class MemoryDepChecker {
///
/// Only checks sets with elements in \p CheckDeps.
bool areDepsSafe(const DepCandidates &AccessSets,
const MemAccessInfoList &CheckDeps,
const DenseMap<Value *, SmallVector<const Value *, 16>>
&UnderlyingObjects);
const MemAccessInfoList &CheckDeps);

/// No memory dependence was encountered that would inhibit
/// vectorization.
Expand Down Expand Up @@ -377,11 +375,8 @@ class MemoryDepChecker {
/// element access it records this distance in \p MinDepDistBytes (if this
/// distance is smaller than any other distance encountered so far).
/// Otherwise, this function returns true signaling a possible dependence.
Dependence::DepType
isDependent(const MemAccessInfo &A, unsigned AIdx, const MemAccessInfo &B,
unsigned BIdx,
const DenseMap<Value *, SmallVector<const Value *, 16>>
&UnderlyingObjects);
Dependence::DepType isDependent(const MemAccessInfo &A, unsigned AIdx,
const MemAccessInfo &B, unsigned BIdx);

/// Check whether the data dependence could prevent store-load
/// forwarding.
Expand Down Expand Up @@ -418,11 +413,9 @@ class MemoryDepChecker {
/// determined, or a struct containing (Distance, Stride, TypeSize, AIsWrite,
/// BIsWrite).
std::variant<Dependence::DepType, DepDistanceStrideAndSizeInfo>
getDependenceDistanceStrideAndSize(
const MemAccessInfo &A, Instruction *AInst, const MemAccessInfo &B,
Instruction *BInst,
const DenseMap<Value *, SmallVector<const Value *, 16>>
&UnderlyingObjects);
getDependenceDistanceStrideAndSize(const MemAccessInfo &A, Instruction *AInst,
const MemAccessInfo &B,
Instruction *BInst);
};

class RuntimePointerChecking;
Expand Down Expand Up @@ -824,7 +817,8 @@ replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE,
Value *Ptr);

/// If the pointer has a constant stride return it in units of the access type
/// size. Otherwise return std::nullopt.
/// size. If the pointer is loop-invariant, return 0. Otherwise return
/// std::nullopt.
///
/// Ensure that it does not wrap in the address space, assuming the predicate
/// associated with \p PSE is true.
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/AsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ class AsmPrinter : public MachineFunctionPass {
/// split stack prologue.
bool HasNoSplitStack = false;

/// True if debugging information is available in this module.
bool DbgInfoAvailable = false;

protected:
explicit AsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer);

Expand Down Expand Up @@ -430,6 +433,9 @@ class AsmPrinter : public MachineFunctionPass {
/// Get the CFISection type for the module.
CFISection getModuleCFISectionType() const { return ModuleCFISection; }

/// Returns true if valid debug info is present.
bool hasDebugInfo() const { return DbgInfoAvailable; }

bool needsSEHMoves();

/// Since emitting CFI unwind information is entangled with supporting the
Expand Down
9 changes: 9 additions & 0 deletions llvm/include/llvm/CodeGen/FunctionLoweringInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class FunctionLoweringInfo {
/// SelectionDAGISel::PrepareEHLandingPad().
unsigned ExceptionPointerVirtReg, ExceptionSelectorVirtReg;

/// The current call site index being processed, if any. 0 if none.
unsigned CurCallSite = 0;

/// Collection of dbg.declare instructions handled after argument
/// lowering and before ISel proper.
SmallPtrSet<const DbgDeclareInst *, 8> PreprocessedDbgDeclares;
Expand Down Expand Up @@ -281,6 +284,12 @@ class FunctionLoweringInfo {
Register getCatchPadExceptionPointerVReg(const Value *CPI,
const TargetRegisterClass *RC);

/// Set the call site currently being processed.
void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }

/// Get the call site currently being processed, if any. Return zero if none.
unsigned getCurrentCallSite() { return CurCallSite; }

private:
/// LiveOutRegInfo - Information about live out vregs.
IndexedMap<LiveOutInfo, VirtReg2IndexFunctor> LiveOutRegInfo;
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/MIRPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace llvm {

class MachineBasicBlock;
class MachineFunction;
class MachineModuleInfo;
class Module;
template <typename T> class SmallVectorImpl;

Expand Down
19 changes: 8 additions & 11 deletions llvm/include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class MachineConstantPool;
class MachineFrameInfo;
class MachineFunction;
class MachineJumpTableInfo;
class MachineModuleInfo;
class MachineRegisterInfo;
class MCContext;
class MCInstrDesc;
Expand Down Expand Up @@ -260,7 +259,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
const LLVMTargetMachine &Target;
const TargetSubtargetInfo *STI;
MCContext &Ctx;
MachineModuleInfo &MMI;

// RegInfo - Information about each register in use in the function.
MachineRegisterInfo *RegInfo;
Expand Down Expand Up @@ -395,15 +393,15 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {

/// \}

/// Clear all the members of this MachineFunction, but the ones used
/// to initialize again the MachineFunction.
/// More specifically, this deallocates all the dynamically allocated
/// objects and get rid of all the XXXInfo data structure, but keep
/// unchanged the references to Fn, Target, MMI, and FunctionNumber.
/// Clear all the members of this MachineFunction, but the ones used to
/// initialize again the MachineFunction. More specifically, this deallocates
/// all the dynamically allocated objects and get rids of all the XXXInfo data
/// structure, but keeps unchanged the references to Fn, Target, and
/// FunctionNumber.
void clear();
/// Allocate and initialize the different members.
/// In particular, the XXXInfo data structure.
/// \pre Fn, Target, MMI, and FunctionNumber are properly set.
/// \pre Fn, Target, and FunctionNumber are properly set.
void init();

public:
Expand Down Expand Up @@ -632,8 +630,8 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
const static unsigned int DebugOperandMemNumber;

MachineFunction(Function &F, const LLVMTargetMachine &Target,
const TargetSubtargetInfo &STI, unsigned FunctionNum,
MachineModuleInfo &MMI);
const TargetSubtargetInfo &STI, MCContext &Ctx,
unsigned FunctionNum);
MachineFunction(const MachineFunction &) = delete;
MachineFunction &operator=(const MachineFunction &) = delete;
~MachineFunction();
Expand Down Expand Up @@ -665,7 +663,6 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {

GISelChangeObserver *getObserver() const { return Observer; }

MachineModuleInfo &getMMI() const { return MMI; }
MCContext &getContext() const { return Ctx; }

/// Returns the Section this function belongs to.
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/MachineInstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ class MachineInstr
/// Return true if it is safe to move this instruction. If
/// SawStore is set to true, it means that there is a store (or call) between
/// the instruction's location and its intended destination.
bool isSafeToMove(AAResults *AA, bool &SawStore) const;
bool isSafeToMove(bool &SawStore) const;

/// Returns true if this instruction's memory access aliases the memory
/// access of Other.
Expand Down
38 changes: 0 additions & 38 deletions llvm/include/llvm/CodeGen/MachineModuleInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,6 @@ class MachineModuleInfo {
/// want.
MachineModuleInfoImpl *ObjFileMMI;

/// \name Exception Handling
/// \{

/// The current call site index being processed, if any. 0 if none.
unsigned CurCallSite = 0;

/// \}

// TODO: Ideally, what we'd like is to have a switch that allows emitting
// synchronous (precise at call-sites only) CFA into .eh_frame. However,
// even under this switch, we'd like .debug_frame to be precise when using
// -g. At this moment, there's no way to specify that some CFI directives
// go into .eh_frame only, while others go into .debug_frame only.

/// True if debugging information is available in this module.
bool DbgInfoAvailable = false;

/// True if this module is being built for windows/msvc, and uses floating
/// point. This is used to emit an undefined reference to _fltused.
bool UsesMSVCFloatingPoint = false;

/// Maps IR Functions to their corresponding MachineFunctions.
DenseMap<const Function*, std::unique_ptr<MachineFunction>> MachineFunctions;
/// Next unique number available for a MachineFunction.
Expand Down Expand Up @@ -186,23 +165,6 @@ class MachineModuleInfo {
return const_cast<MachineModuleInfo*>(this)->getObjFileInfo<Ty>();
}

/// Returns true if valid debug info is present.
bool hasDebugInfo() const { return DbgInfoAvailable; }

bool usesMSVCFloatingPoint() const { return UsesMSVCFloatingPoint; }

void setUsesMSVCFloatingPoint(bool b) { UsesMSVCFloatingPoint = b; }

/// \name Exception Handling
/// \{

/// Set the call site currently being processed.
void setCurrentCallSite(unsigned Site) { CurCallSite = Site; }

/// Get the call site currently being processed, if any. return zero if
/// none.
unsigned getCurrentCallSite() { return CurCallSite; }

/// \}
}; // End class MachineModuleInfo

Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/CodeGen/SDPatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ m_c_SetCC(const T0_P &LHS, const T1_P &RHS, const T2_P &CC) {
CC);
}

template <typename T0_P, typename T1_P, typename T2_P>
inline TernaryOpc_match<T0_P, T1_P, T2_P>
m_Select(const T0_P &Cond, const T1_P &T, const T2_P &F) {
return TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::SELECT, Cond, T, F);
}

// === Binary operations ===
template <typename LHS_P, typename RHS_P, bool Commutable = false,
bool ExcludeChain = false>
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/SelectionDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ struct KnownBits;
class LLVMContext;
class MachineBasicBlock;
class MachineConstantPoolValue;
class MachineModuleInfo;
class MCSymbol;
class OptimizationRemarkEmitter;
class ProfileSummaryInfo;
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class LiveIntervals;
class LiveVariables;
class MachineLoop;
class MachineMemOperand;
class MachineModuleInfo;
class MachineRegisterInfo;
class MCAsmInfo;
class MCInst;
Expand Down
119 changes: 55 additions & 64 deletions llvm/lib/Analysis/LoopAccessAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,6 @@ class AccessAnalysis {

const MemAccessInfoList &getDependenciesToCheck() const { return CheckDeps; }

const DenseMap<Value *, SmallVector<const Value *, 16>> &
getUnderlyingObjects() const {
return UnderlyingObjects;
}

private:
typedef MapVector<MemAccessInfo, SmallSetVector<Type *, 1>> PtrAccessMap;

Expand Down Expand Up @@ -1457,22 +1452,23 @@ static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR,
}

/// Check whether the access through \p Ptr has a constant stride.
std::optional<int64_t> llvm::getPtrStride(PredicatedScalarEvolution &PSE,
Type *AccessTy, Value *Ptr,
const Loop *Lp,
const DenseMap<Value *, const SCEV *> &StridesMap,
bool Assume, bool ShouldCheckWrap) {
std::optional<int64_t>
llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
const Loop *Lp,
const DenseMap<Value *, const SCEV *> &StridesMap,
bool Assume, bool ShouldCheckWrap) {
const SCEV *PtrScev = replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr);
if (PSE.getSE()->isLoopInvariant(PtrScev, Lp))
return {0};

Type *Ty = Ptr->getType();
assert(Ty->isPointerTy() && "Unexpected non-ptr");

if (isa<ScalableVectorType>(AccessTy)) {
LLVM_DEBUG(dbgs() << "LAA: Bad stride - Scalable object: " << *AccessTy
<< "\n");
return std::nullopt;
}

const SCEV *PtrScev = replaceSymbolicStrideSCEV(PSE, StridesMap, Ptr);

const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PtrScev);
if (Assume && !AR)
AR = PSE.getAsAddRec(Ptr);
Expand Down Expand Up @@ -1932,23 +1928,11 @@ static bool areStridedAccessesIndependent(uint64_t Distance, uint64_t Stride,
return ScaledDist % Stride;
}

/// Returns true if any of the underlying objects has a loop varying address,
/// i.e. may change in \p L.
static bool
isLoopVariantIndirectAddress(ArrayRef<const Value *> UnderlyingObjects,
ScalarEvolution &SE, const Loop *L) {
return any_of(UnderlyingObjects, [&SE, L](const Value *UO) {
return !SE.isLoopInvariant(SE.getSCEV(const_cast<Value *>(UO)), L);
});
}

std::variant<MemoryDepChecker::Dependence::DepType,
MemoryDepChecker::DepDistanceStrideAndSizeInfo>
MemoryDepChecker::getDependenceDistanceStrideAndSize(
const AccessAnalysis::MemAccessInfo &A, Instruction *AInst,
const AccessAnalysis::MemAccessInfo &B, Instruction *BInst,
const DenseMap<Value *, SmallVector<const Value *, 16>>
&UnderlyingObjects) {
const AccessAnalysis::MemAccessInfo &B, Instruction *BInst) {
const auto &DL = InnermostLoop->getHeader()->getDataLayout();
auto &SE = *PSE.getSE();
const auto &[APtr, AIsWrite] = A;
Expand All @@ -1966,39 +1950,30 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
BPtr->getType()->getPointerAddressSpace())
return MemoryDepChecker::Dependence::Unknown;

int64_t StrideAPtr =
getPtrStride(PSE, ATy, APtr, InnermostLoop, SymbolicStrides, true)
.value_or(0);
int64_t StrideBPtr =
getPtrStride(PSE, BTy, BPtr, InnermostLoop, SymbolicStrides, true)
.value_or(0);
std::optional<int64_t> StrideAPtr =
getPtrStride(PSE, ATy, APtr, InnermostLoop, SymbolicStrides, true, true);
std::optional<int64_t> StrideBPtr =
getPtrStride(PSE, BTy, BPtr, InnermostLoop, SymbolicStrides, true, true);

const SCEV *Src = PSE.getSCEV(APtr);
const SCEV *Sink = PSE.getSCEV(BPtr);

// If the induction step is negative we have to invert source and sink of the
// dependence when measuring the distance between them. We should not swap
// AIsWrite with BIsWrite, as their uses expect them in program order.
if (StrideAPtr < 0) {
if (StrideAPtr && *StrideAPtr < 0) {
std::swap(Src, Sink);
std::swap(AInst, BInst);
std::swap(StrideAPtr, StrideBPtr);
}

const SCEV *Dist = SE.getMinusSCEV(Sink, Src);

LLVM_DEBUG(dbgs() << "LAA: Src Scev: " << *Src << "Sink Scev: " << *Sink
<< "(Induction step: " << StrideAPtr << ")\n");
<< "\n");
LLVM_DEBUG(dbgs() << "LAA: Distance for " << *AInst << " to " << *BInst
<< ": " << *Dist << "\n");

// Needs accesses where the addresses of the accessed underlying objects do
// not change within the loop.
if (isLoopVariantIndirectAddress(UnderlyingObjects.find(APtr)->second, SE,
InnermostLoop) ||
isLoopVariantIndirectAddress(UnderlyingObjects.find(BPtr)->second, SE,
InnermostLoop))
return MemoryDepChecker::Dependence::IndirectUnsafe;

// Check if we can prove that Sink only accesses memory after Src's end or
// vice versa. At the moment this is limited to cases where either source or
// sink are loop invariant to avoid compile-time increases. This is not
Expand All @@ -2020,12 +1995,33 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
}
}

// Need accesses with constant strides and the same direction. We don't want
// to vectorize "A[B[i]] += ..." and similar code or pointer arithmetic that
// could wrap in the address space.
if (!StrideAPtr || !StrideBPtr || (StrideAPtr > 0 && StrideBPtr < 0) ||
(StrideAPtr < 0 && StrideBPtr > 0)) {
// Need accesses with constant strides and the same direction for further
// dependence analysis. We don't want to vectorize "A[B[i]] += ..." and
// similar code or pointer arithmetic that could wrap in the address space.

// If either Src or Sink are not strided (i.e. not a non-wrapping AddRec) and
// not loop-invariant (stride will be 0 in that case), we cannot analyze the
// dependence further and also cannot generate runtime checks.
if (!StrideAPtr || !StrideBPtr) {
LLVM_DEBUG(dbgs() << "Pointer access with non-constant stride\n");
return MemoryDepChecker::Dependence::IndirectUnsafe;
}

int64_t StrideAPtrInt = *StrideAPtr;
int64_t StrideBPtrInt = *StrideBPtr;
LLVM_DEBUG(dbgs() << "LAA: Src induction step: " << StrideAPtrInt
<< " Sink induction step: " << StrideBPtrInt << "\n");
// At least Src or Sink are loop invariant and the other is strided or
// invariant. We can generate a runtime check to disambiguate the accesses.
if (StrideAPtrInt == 0 || StrideBPtrInt == 0)
return MemoryDepChecker::Dependence::Unknown;

// Both Src and Sink have a constant stride, check if they are in the same
// direction.
if ((StrideAPtrInt > 0 && StrideBPtrInt < 0) ||
(StrideAPtrInt < 0 && StrideBPtrInt > 0)) {
LLVM_DEBUG(
dbgs() << "Pointer access with strides in different directions\n");
return MemoryDepChecker::Dependence::Unknown;
}

Expand All @@ -2034,22 +2030,20 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
DL.getTypeStoreSizeInBits(ATy) == DL.getTypeStoreSizeInBits(BTy);
if (!HasSameSize)
TypeByteSize = 0;
return DepDistanceStrideAndSizeInfo(Dist, std::abs(StrideAPtr),
std::abs(StrideBPtr), TypeByteSize,
return DepDistanceStrideAndSizeInfo(Dist, std::abs(StrideAPtrInt),
std::abs(StrideBPtrInt), TypeByteSize,
AIsWrite, BIsWrite);
}

MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
const MemAccessInfo &A, unsigned AIdx, const MemAccessInfo &B,
unsigned BIdx,
const DenseMap<Value *, SmallVector<const Value *, 16>>
&UnderlyingObjects) {
MemoryDepChecker::Dependence::DepType
MemoryDepChecker::isDependent(const MemAccessInfo &A, unsigned AIdx,
const MemAccessInfo &B, unsigned BIdx) {
assert(AIdx < BIdx && "Must pass arguments in program order");

// Get the dependence distance, stride, type size and what access writes for
// the dependence between A and B.
auto Res = getDependenceDistanceStrideAndSize(
A, InstMap[AIdx], B, InstMap[BIdx], UnderlyingObjects);
auto Res =
getDependenceDistanceStrideAndSize(A, InstMap[AIdx], B, InstMap[BIdx]);
if (std::holds_alternative<Dependence::DepType>(Res))
return std::get<Dependence::DepType>(Res);

Expand Down Expand Up @@ -2283,10 +2277,8 @@ MemoryDepChecker::Dependence::DepType MemoryDepChecker::isDependent(
return Dependence::BackwardVectorizable;
}

bool MemoryDepChecker::areDepsSafe(
const DepCandidates &AccessSets, const MemAccessInfoList &CheckDeps,
const DenseMap<Value *, SmallVector<const Value *, 16>>
&UnderlyingObjects) {
bool MemoryDepChecker::areDepsSafe(const DepCandidates &AccessSets,
const MemAccessInfoList &CheckDeps) {

MinDepDistBytes = -1;
SmallPtrSet<MemAccessInfo, 8> Visited;
Expand Down Expand Up @@ -2329,8 +2321,8 @@ bool MemoryDepChecker::areDepsSafe(
if (*I1 > *I2)
std::swap(A, B);

Dependence::DepType Type = isDependent(*A.first, A.second, *B.first,
B.second, UnderlyingObjects);
Dependence::DepType Type =
isDependent(*A.first, A.second, *B.first, B.second);
mergeInStatus(Dependence::isSafeForVectorization(Type));

// Gather dependences unless we accumulated MaxDependences
Expand Down Expand Up @@ -2685,8 +2677,7 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
if (Accesses.isDependencyCheckNeeded()) {
LLVM_DEBUG(dbgs() << "LAA: Checking memory dependencies\n");
DepsAreSafe = DepChecker->areDepsSafe(DependentAccesses,
Accesses.getDependenciesToCheck(),
Accesses.getUnderlyingObjects());
Accesses.getDependenciesToCheck());

if (!DepsAreSafe && DepChecker->shouldRetryWithRuntimeCheck()) {
LLVM_DEBUG(dbgs() << "LAA: Retrying with memory checks\n");
Expand Down
18 changes: 8 additions & 10 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ bool AsmPrinter::doInitialization(Module &M) {
MMI = MMIWP ? &MMIWP->getMMI() : nullptr;
HasSplitStack = false;
HasNoSplitStack = false;
DbgInfoAvailable = !M.debug_compile_units().empty();

AddrLabelSymbols = nullptr;

Expand Down Expand Up @@ -541,8 +542,7 @@ bool AsmPrinter::doInitialization(Module &M) {
if (EmitCodeView && TM.getTargetTriple().isOSWindows())
DebugHandlers.push_back(std::make_unique<CodeViewDebug>(this));
if (!EmitCodeView || M.getDwarfVersion()) {
assert(MMI && "MMI could not be nullptr here!");
if (MMI->hasDebugInfo()) {
if (hasDebugInfo()) {
DD = new DwarfDebug(this);
DebugHandlers.push_back(std::unique_ptr<DwarfDebug>(DD));
}
Expand Down Expand Up @@ -1277,8 +1277,7 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const {
if (MAI->usesCFIWithoutEH() && F.hasUWTable())
return CFISection::EH;

assert(MMI != nullptr && "Invalid machine module info");
if (MMI->hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
if (hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
return CFISection::Debug;

return CFISection::None;
Expand Down Expand Up @@ -1669,10 +1668,9 @@ void AsmPrinter::emitPCSections(const MachineFunction &MF) {
}

/// Returns true if function begin and end labels should be emitted.
static bool needFuncLabels(const MachineFunction &MF,
const MachineModuleInfo &MMI) {
if (!MF.getLandingPads().empty() || MF.hasEHFunclets() ||
MMI.hasDebugInfo() ||
static bool needFuncLabels(const MachineFunction &MF, const AsmPrinter &Asm) {
if (Asm.hasDebugInfo() || !MF.getLandingPads().empty() ||
MF.hasEHFunclets() ||
MF.getFunction().hasMetadata(LLVMContext::MD_pcsections))
return true;

Expand Down Expand Up @@ -1944,7 +1942,7 @@ void AsmPrinter::emitFunctionBody() {
// are automatically sized.
bool EmitFunctionSize = MAI->hasDotTypeDotSizeDirective() && !TT.isWasm();

if (needFuncLabels(*MF, *MMI) || EmitFunctionSize) {
if (EmitFunctionSize || needFuncLabels(*MF, *this)) {
// Create a symbol for the end of function.
CurrentFnEnd = createTempSymbol("func_end");
OutStreamer->emitLabel(CurrentFnEnd);
Expand Down Expand Up @@ -2588,7 +2586,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
if (F.hasFnAttribute("patchable-function-entry") ||
F.hasFnAttribute("function-instrument") ||
F.hasFnAttribute("xray-instruction-threshold") ||
needFuncLabels(MF, *MMI) || NeedsLocalForSize ||
needFuncLabels(MF, *this) || NeedsLocalForSize ||
MF.getTarget().Options.EmitStackSizeSection ||
MF.getTarget().Options.BBAddrMap || MF.hasBBLabels()) {
CurrentFnBegin = createTempSymbol("func_begin");
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
void CodeViewDebug::beginModule(Module *M) {
// If module doesn't have named metadata anchors or COFF debug section
// is not available, skip any debug info related stuff.
if (!MMI->hasDebugInfo() ||
if (!Asm->hasDebugInfo() ||
!Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) {
Asm = nullptr;
return;
Expand All @@ -636,7 +636,7 @@ void CodeViewDebug::beginModule(Module *M) {
}

void CodeViewDebug::endModule() {
if (!Asm || !MMI->hasDebugInfo())
if (!Asm || !Asm->hasDebugInfo())
return;

// The COFF .debug$S section consists of several subsections, each starting
Expand Down
13 changes: 5 additions & 8 deletions llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ bool DebugHandlerBase::isUnsignedDIType(const DIType *Ty) {
Ty->getTag() == dwarf::DW_TAG_unspecified_type;
}

static bool hasDebugInfo(const MachineModuleInfo *MMI,
const MachineFunction *MF) {
if (!MMI->hasDebugInfo())
return false;
static bool hasDebugInfo(const MachineFunction *MF) {
auto *SP = MF->getFunction().getSubprogram();
if (!SP)
return false;
Expand All @@ -258,7 +255,7 @@ static bool hasDebugInfo(const MachineModuleInfo *MMI,
void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
PrevInstBB = nullptr;

if (!Asm || !hasDebugInfo(MMI, MF)) {
if (!Asm || !hasDebugInfo(MF)) {
skippedNonDebugFunction();
return;
}
Expand Down Expand Up @@ -354,7 +351,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
}

void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
if (!Asm || !MMI->hasDebugInfo())
if (!Asm || !Asm->hasDebugInfo())
return;

assert(CurMI == nullptr);
Expand All @@ -380,7 +377,7 @@ void DebugHandlerBase::beginInstruction(const MachineInstr *MI) {
}

void DebugHandlerBase::endInstruction() {
if (!Asm || !MMI->hasDebugInfo())
if (!Asm || !Asm->hasDebugInfo())
return;

assert(CurMI != nullptr);
Expand Down Expand Up @@ -415,7 +412,7 @@ void DebugHandlerBase::endInstruction() {
}

void DebugHandlerBase::endFunction(const MachineFunction *MF) {
if (Asm && hasDebugInfo(MMI, MF))
if (Asm && hasDebugInfo(MF))
endFunctionImpl(MF);
DbgValues.clear();
DbgLabels.clear();
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,14 +1148,15 @@ sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
void DwarfDebug::beginModule(Module *M) {
DebugHandlerBase::beginModule(M);

if (!Asm || !MMI->hasDebugInfo())
if (!Asm)
return;

unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
M->debug_compile_units_end());
if (NumDebugCUs == 0)
return;

assert(NumDebugCUs > 0 && "Asm unexpectedly initialized");
assert(MMI->hasDebugInfo() &&
"DebugInfoAvailabilty unexpectedly not initialized");
SingleCU = NumDebugCUs == 1;
DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1>>
GVMap;
Expand Down Expand Up @@ -1433,7 +1434,7 @@ void DwarfDebug::endModule() {

// If we aren't actually generating debug info (check beginModule -
// conditionalized on the presence of the llvm.dbg.cu metadata node)
if (!Asm || !MMI->hasDebugInfo())
if (!Asm || !Asm->hasDebugInfo())
return;

// Finalize the debug info for the module.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/BranchFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ MachineBasicBlock::iterator findHoistingInsertPosAndDeps(MachineBasicBlock *MBB,
// Also avoid moving code above predicated instruction since it's hard to
// reason about register liveness with predicated instruction.
bool DontMoveAcrossStore = true;
if (!PI->isSafeToMove(nullptr, DontMoveAcrossStore) || TII->isPredicated(*PI))
if (!PI->isSafeToMove(DontMoveAcrossStore) || TII->isPredicated(*PI))
return MBB->end();

// Find out what registers are live. Note this routine is ignoring other live
Expand Down Expand Up @@ -2015,7 +2015,7 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
break;

bool DontMoveAcrossStore = true;
if (!TIB->isSafeToMove(nullptr, DontMoveAcrossStore))
if (!TIB->isSafeToMove(DontMoveAcrossStore))
break;

// Remove kills from ActiveDefsSet, these registers had short live ranges.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/DeadMachineInstructionElim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool DeadMachineInstructionElimImpl::isDead(const MachineInstr *MI) const {

// Don't delete instructions with side effects.
bool SawStore = false;
if (!MI->isSafeToMove(nullptr, SawStore) && !MI->isPHI())
if (!MI->isSafeToMove(SawStore) && !MI->isPHI())
return false;

// Examine each operand.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/EarlyIfConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) {

// We never speculate stores, so an AA pointer isn't necessary.
bool DontMoveAcrossStore = true;
if (!MI.isSafeToMove(nullptr, DontMoveAcrossStore)) {
if (!MI.isSafeToMove(DontMoveAcrossStore)) {
LLVM_DEBUG(dbgs() << "Can't speculate: " << MI);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool llvm::isTriviallyDead(const MachineInstr &MI,
// If we can move an instruction, we can remove it. Otherwise, it has
// a side-effect of some sort.
bool SawStore = false;
if (!MI.isSafeToMove(/*AA=*/nullptr, SawStore) && !MI.isPHI())
if (!MI.isSafeToMove(SawStore) && !MI.isPHI())
return false;

// Instructions without side-effects are dead iff they only define dead vregs.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/IfConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ bool IfConverter::IfConvertDiamond(BBInfo &BBI, IfcvtKind Kind,
static bool MaySpeculate(const MachineInstr &MI,
SmallSet<MCPhysReg, 4> &LaterRedefs) {
bool SawStore = true;
if (!MI.isSafeToMove(nullptr, SawStore))
if (!MI.isSafeToMove(SawStore))
return false;

for (const MachineOperand &MO : MI.operands()) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/LiveRangeEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ bool LiveRangeEdit::foldAsLoad(LiveInterval *LI,
// We also need to make sure it is safe to move the load.
// Assume there are stores between DefMI and UseMI.
bool SawStore = true;
if (!DefMI->isSafeToMove(nullptr, SawStore))
if (!DefMI->isSafeToMove(SawStore))
return false;

LLVM_DEBUG(dbgs() << "Try to fold single def: " << *DefMI
Expand Down Expand Up @@ -300,7 +300,7 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) {

// Use the same criteria as DeadMachineInstructionElim.
bool SawStore = false;
if (!MI->isSafeToMove(nullptr, SawStore)) {
if (!MI->isSafeToMove(SawStore)) {
LLVM_DEBUG(dbgs() << "Can't delete: " << Idx << '\t' << *MI);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/LiveRangeShrink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
}
}

if (!MI.isSafeToMove(nullptr, SawStore)) {
if (!MI.isSafeToMove(SawStore)) {
// If MI has side effects, it should become a barrier for code motion.
// IOM is rebuild from the next instruction to prevent later
// instructions from being moved before this MI.
Expand Down
17 changes: 11 additions & 6 deletions llvm/lib/CodeGen/MachineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ static inline Align getFnStackAlignment(const TargetSubtargetInfo *STI,
}

MachineFunction::MachineFunction(Function &F, const LLVMTargetMachine &Target,
const TargetSubtargetInfo &STI,
unsigned FunctionNum, MachineModuleInfo &mmi)
: F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
const TargetSubtargetInfo &STI, MCContext &Ctx,
unsigned FunctionNum)
: F(F), Target(Target), STI(&STI), Ctx(Ctx) {
FunctionNumber = FunctionNum;
init();
}
Expand Down Expand Up @@ -654,9 +654,14 @@ void MachineFunction::print(raw_ostream &OS, const SlotIndexes *Indexes) const {

/// True if this function needs frame moves for debug or exceptions.
bool MachineFunction::needsFrameMoves() const {
return getMMI().hasDebugInfo() ||
getTarget().Options.ForceDwarfFrameSection ||
F.needsUnwindTableEntry();
// TODO: Ideally, what we'd like is to have a switch that allows emitting
// synchronous (precise at call-sites only) CFA into .eh_frame. However, even
// under this switch, we'd like .debug_frame to be precise when using -g. At
// this moment, there's no way to specify that some CFI directives go into
// .eh_frame only, while others go into .debug_frame only.
return getTarget().Options.ForceDwarfFrameSection ||
F.needsUnwindTableEntry() ||
!F.getParent()->debug_compile_units().empty();
}

namespace llvm {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineFunctionAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MachineFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
.getCachedResult<MachineModuleAnalysis>(*F.getParent())
->getMMI();
auto MF = std::make_unique<MachineFunction>(
F, *TM, STI, Context.generateMachineFunctionNum(F), MMI);
F, *TM, STI, MMI.getContext(), Context.generateMachineFunctionNum(F));
MF->initTargetMachineFunctionInfo(STI);

// MRI callback for target specific initializations.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineInstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ void MachineInstr::substituteRegister(Register FromReg, Register ToReg,
/// isSafeToMove - Return true if it is safe to move this instruction. If
/// SawStore is set to true, it means that there is a store (or call) between
/// the instruction's location and its intended destination.
bool MachineInstr::isSafeToMove(AAResults *AA, bool &SawStore) const {
bool MachineInstr::isSafeToMove(bool &SawStore) const {
// Ignore stuff that we obviously can't move.
//
// Treat volatile loads as stores. This is not strictly necessary for
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineLICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ static bool isCopyFeedingInvariantStore(const MachineInstr &MI,
bool MachineLICMBase::IsLICMCandidate(MachineInstr &I, MachineLoop *CurLoop) {
// Check if it's safe to move the instruction.
bool DontMoveAcrossStore = !HoistConstLoads || !AllowedToHoistLoads[CurLoop];
if ((!I.isSafeToMove(AA, DontMoveAcrossStore)) &&
if ((!I.isSafeToMove(DontMoveAcrossStore)) &&
!(HoistConstStores && isInvariantStore(I, TRI, MRI))) {
LLVM_DEBUG(dbgs() << "LICM: Instruction not safe to move.\n");
return false;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/MachineLateInstrsCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ static bool isCandidate(const MachineInstr *MI, Register &DefedReg,
Register FrameReg) {
DefedReg = MCRegister::NoRegister;
bool SawStore = true;
if (!MI->isSafeToMove(nullptr, SawStore) || MI->isImplicitDef() ||
MI->isInlineAsm())
if (!MI->isSafeToMove(SawStore) || MI->isImplicitDef() || MI->isInlineAsm())
return false;
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI->getOperand(i);
Expand Down
8 changes: 1 addition & 7 deletions llvm/lib/CodeGen/MachineModuleInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ MachineModuleInfoImpl::~MachineModuleInfoImpl() = default;

void MachineModuleInfo::initialize() {
ObjFileMMI = nullptr;
CurCallSite = 0;
NextFnNum = 0;
UsesMSVCFloatingPoint = false;
DbgInfoAvailable = false;
}

void MachineModuleInfo::finalize() {
Expand All @@ -47,7 +44,6 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
MachineFunctions(std::move(MMI.MachineFunctions)) {
Context.setObjectFileInfo(TM.getObjFileLowering());
ObjFileMMI = MMI.ObjFileMMI;
CurCallSite = MMI.CurCallSite;
ExternalContext = MMI.ExternalContext;
TheModule = MMI.TheModule;
}
Expand Down Expand Up @@ -90,7 +86,7 @@ MachineFunction &MachineModuleInfo::getOrCreateMachineFunction(Function &F) {
if (I.second) {
// No pre-existing machine function, create a new one.
const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F);
MF = new MachineFunction(F, TM, STI, NextFnNum++, *this);
MF = new MachineFunction(F, TM, STI, getContext(), NextFnNum++);
MF->initTargetMachineFunctionInfo(STI);

// MRI callback for target specific initializations.
Expand Down Expand Up @@ -210,7 +206,6 @@ bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
Ctx.diagnose(
DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie));
});
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
return false;
}

Expand All @@ -235,6 +230,5 @@ MachineModuleAnalysis::run(Module &M, ModuleAnalysisManager &) {
Ctx.diagnose(
DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie));
});
MMI.DbgInfoAvailable = !M.debug_compile_units().empty();
return Result(MMI);
}
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/MachineSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,

// Check if it's safe to move the instruction.
bool SawStore = true;
if (!MI.isSafeToMove(AA, SawStore))
if (!MI.isSafeToMove(SawStore))
return false;

// Convergent operations may not be made control-dependent on additional
Expand Down Expand Up @@ -687,7 +687,7 @@ void MachineSinking::FindCycleSinkCandidates(
continue;
}
bool DontMoveAcrossStore = true;
if (!MI.isSafeToMove(AA, DontMoveAcrossStore)) {
if (!MI.isSafeToMove(DontMoveAcrossStore)) {
LLVM_DEBUG(dbgs() << "CycleSink: Instruction not safe to move.\n");
continue;
}
Expand Down Expand Up @@ -1654,7 +1654,7 @@ bool MachineSinking::SinkInstruction(MachineInstr &MI, bool &SawStore,
return false;

// Check if it's safe to move the instruction.
if (!MI.isSafeToMove(AA, SawStore))
if (!MI.isSafeToMove(SawStore))
return false;

// Convergent operations may not be made control-dependent on additional
Expand Down Expand Up @@ -1705,7 +1705,7 @@ bool MachineSinking::SinkInstruction(MachineInstr &MI, bool &SawStore,
bool TryBreak = false;
bool Store =
MI.mayLoad() ? hasStoreBetween(ParentBlock, SuccToSinkTo, MI) : true;
if (!MI.isSafeToMove(AA, Store)) {
if (!MI.isSafeToMove(Store)) {
LLVM_DEBUG(dbgs() << " *** NOTE: Won't sink load along critical edge.\n");
TryBreak = true;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/ModuloSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ void ModuloScheduleExpander::removeDeadInstructions(MachineBasicBlock *KernelBB,
bool SawStore = false;
// Check if it's safe to remove the instruction due to side effects.
// We can, and want to, remove Phis here.
if (!MI->isSafeToMove(nullptr, SawStore) && !MI->isPHI()) {
if (!MI->isSafeToMove(SawStore) && !MI->isPHI()) {
++MI;
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/RegisterCoalescer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
if (!definesFullReg(*DefMI, SrcReg))
return false;
bool SawStore = false;
if (!DefMI->isSafeToMove(AA, SawStore))
if (!DefMI->isSafeToMove(SawStore))
return false;
const MCInstrDesc &MCID = DefMI->getDesc();
if (MCID.getNumDefs() != 1)
Expand Down
16 changes: 0 additions & 16 deletions llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,11 +1203,6 @@ void FastISel::handleDbgInfo(const Instruction *II) {

if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DR)) {
assert(DLR->getLabel() && "Missing label");
if (!FuncInfo.MF->getMMI().hasDebugInfo()) {
LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DLR << "\n");
continue;
}

BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DLR->getDebugLoc(),
TII.get(TargetOpcode::DBG_LABEL))
.addMetadata(DLR->getLabel());
Expand Down Expand Up @@ -1402,12 +1397,6 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
case Intrinsic::dbg_declare: {
const DbgDeclareInst *DI = cast<DbgDeclareInst>(II);
assert(DI->getVariable() && "Missing variable");
if (!FuncInfo.MF->getMMI().hasDebugInfo()) {
LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DI
<< " (!hasDebugInfo)\n");
return true;
}

if (FuncInfo.PreprocessedDbgDeclares.contains(DI))
return true;

Expand Down Expand Up @@ -1446,11 +1435,6 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
case Intrinsic::dbg_label: {
const DbgLabelInst *DI = cast<DbgLabelInst>(II);
assert(DI->getLabel() && "Missing label");
if (!FuncInfo.MF->getMMI().hasDebugInfo()) {
LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n");
return true;
}

BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(TargetOpcode::DBG_LABEL)).addMetadata(DI->getLabel());
return true;
Expand Down
10 changes: 4 additions & 6 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6708,10 +6708,9 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
return;
case Intrinsic::eh_sjlj_callsite: {
ConstantInt *CI = cast<ConstantInt>(I.getArgOperand(0));
assert(DAG.getMMI()->getCurrentCallSite() == 0 &&
"Overlapping call sites!");
assert(FuncInfo.getCurrentCallSite() == 0 && "Overlapping call sites!");

DAG.getMMI()->setCurrentCallSite(CI->getZExtValue());
FuncInfo.setCurrentCallSite(CI->getZExtValue());
return;
}
case Intrinsic::eh_sjlj_functioncontext: {
Expand Down Expand Up @@ -8619,21 +8618,20 @@ SDValue SelectionDAGBuilder::lowerStartEH(SDValue Chain,
const BasicBlock *EHPadBB,
MCSymbol *&BeginLabel) {
MachineFunction &MF = DAG.getMachineFunction();
MachineModuleInfo &MMI = MF.getMMI();

// Insert a label before the invoke call to mark the try range. This can be
// used to detect deletion of the invoke via the MachineModuleInfo.
BeginLabel = MF.getContext().createTempSymbol();

// For SjLj, keep track of which landing pads go with which invokes
// so as to maintain the ordering of pads in the LSDA.
unsigned CallSiteIndex = MMI.getCurrentCallSite();
unsigned CallSiteIndex = FuncInfo.getCurrentCallSite();
if (CallSiteIndex) {
MF.setCallSiteBeginLabel(BeginLabel, CallSiteIndex);
LPadToCallSiteMap[FuncInfo.MBBMap[EHPadBB]].push_back(CallSiteIndex);

// Now that the call site is handled, stop tracking it.
MMI.setCurrentCallSite(0);
FuncInfo.setCurrentCallSite(0);
}

return DAG.getEHLabel(getCurSDLoc(), Chain, BeginLabel);
Expand Down
27 changes: 0 additions & 27 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,30 +417,6 @@ void SelectionDAGISelLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
MachineFunctionPass::getAnalysisUsage(AU);
}

static void computeUsesMSVCFloatingPoint(const Triple &TT, const Function &F,
MachineModuleInfo &MMI) {
// Only needed for MSVC
if (!TT.isWindowsMSVCEnvironment())
return;

// If it's already set, nothing to do.
if (MMI.usesMSVCFloatingPoint())
return;

for (const Instruction &I : instructions(F)) {
if (I.getType()->isFPOrFPVectorTy()) {
MMI.setUsesMSVCFloatingPoint(true);
return;
}
for (const auto &Op : I.operands()) {
if (Op->getType()->isFPOrFPVectorTy()) {
MMI.setUsesMSVCFloatingPoint(true);
return;
}
}
}
}

PreservedAnalyses
SelectionDAGISelPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
Expand Down Expand Up @@ -802,9 +778,6 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
}
}

// Determine if floating point is used for msvc
computeUsesMSVCFloatingPoint(TM.getTargetTriple(), Fn, *CurDAG->getMMI());

// Release function-specific state. SDB and CurDAG are already cleared
// at this point.
FuncInfo->clear();
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ bool TwoAddressInstructionImpl::rescheduleMIBelowKill(
return false;

bool SeenStore = true;
if (!MI->isSafeToMove(AA, SeenStore))
if (!MI->isSafeToMove(SeenStore))
return false;

if (TII->getInstrLatency(InstrItins, *MI) > 1)
Expand Down Expand Up @@ -1131,7 +1131,7 @@ bool TwoAddressInstructionImpl::rescheduleKillAboveMI(
return false;

bool SeenStore = true;
if (!KillMI->isSafeToMove(AA, SeenStore))
if (!KillMI->isSafeToMove(SeenStore))
return false;

SmallVector<Register, 2> Uses;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ bool SSACCmpConv::canSpeculateInstrs(MachineBasicBlock *MBB,

// We never speculate stores, so an AA pointer isn't necessary.
bool DontMoveAcrossStore = true;
if (!I.isSafeToMove(nullptr, DontMoveAcrossStore)) {
if (!I.isSafeToMove(DontMoveAcrossStore)) {
LLVM_DEBUG(dbgs() << "Can't speculate: " << I);
return false;
}
Expand Down
26 changes: 3 additions & 23 deletions llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,27 +2169,6 @@ bool AMDGPUInstructionSelector::selectG_SELECT(MachineInstr &I) const {
return Ret;
}

static int sizeToSubRegIndex(unsigned Size) {
switch (Size) {
case 32:
return AMDGPU::sub0;
case 64:
return AMDGPU::sub0_sub1;
case 96:
return AMDGPU::sub0_sub1_sub2;
case 128:
return AMDGPU::sub0_sub1_sub2_sub3;
case 256:
return AMDGPU::sub0_sub1_sub2_sub3_sub4_sub5_sub6_sub7;
default:
if (Size < 32)
return AMDGPU::sub0;
if (Size > 256)
return -1;
return sizeToSubRegIndex(llvm::bit_ceil(Size));
}
}

bool AMDGPUInstructionSelector::selectG_TRUNC(MachineInstr &I) const {
Register DstReg = I.getOperand(0).getReg();
Register SrcReg = I.getOperand(1).getReg();
Expand Down Expand Up @@ -2293,8 +2272,9 @@ bool AMDGPUInstructionSelector::selectG_TRUNC(MachineInstr &I) const {
return false;

if (SrcSize > 32) {
int SubRegIdx = sizeToSubRegIndex(DstSize);
if (SubRegIdx == -1)
unsigned SubRegIdx =
DstSize < 32 ? AMDGPU::sub0 : TRI.getSubRegFromChannel(0, DstSize / 32);
if (SubRegIdx == AMDGPU::NoSubRegister)
return false;

// Deal with weird cases where the class only partially supports the subreg
Expand Down
31 changes: 9 additions & 22 deletions llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ void AMDGPUInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo,
printU32ImmOperand(MI, OpNo, STI, O);
}

void AMDGPUInstPrinter::printU4ImmDecOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O) {
O << formatDec(MI->getOperand(OpNo).getImm() & 0xf);
}

void AMDGPUInstPrinter::printU16ImmDecOperand(const MCInst *MI, unsigned OpNo,
raw_ostream &O) {
O << formatDec(MI->getOperand(OpNo).getImm() & 0xffff);
Expand Down Expand Up @@ -719,29 +714,25 @@ void AMDGPUInstPrinter::printDefaultVccOperand(bool FirstOperand,
void AMDGPUInstPrinter::printWaitVDST(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI,
raw_ostream &O) {
O << " wait_vdst:";
printU4ImmDecOperand(MI, OpNo, O);
O << " wait_vdst:" << formatDec(MI->getOperand(OpNo).getImm());
}

void AMDGPUInstPrinter::printWaitVAVDst(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI,
raw_ostream &O) {
O << " wait_va_vdst:";
printU4ImmDecOperand(MI, OpNo, O);
O << " wait_va_vdst:" << formatDec(MI->getOperand(OpNo).getImm());
}

void AMDGPUInstPrinter::printWaitVMVSrc(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI,
raw_ostream &O) {
O << " wait_vm_vsrc:";
printU4ImmDecOperand(MI, OpNo, O);
O << " wait_vm_vsrc:" << formatDec(MI->getOperand(OpNo).getImm());
}

void AMDGPUInstPrinter::printWaitEXP(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI,
raw_ostream &O) {
O << " wait_exp:";
printU4ImmDecOperand(MI, OpNo, O);
O << " wait_exp:" << formatDec(MI->getOperand(OpNo).getImm());
}

bool AMDGPUInstPrinter::needsImpliedVcc(const MCInstrDesc &Desc,
Expand Down Expand Up @@ -1065,16 +1056,13 @@ void AMDGPUInstPrinter::printDPPCtrl(const MCInst *MI, unsigned OpNo,
O << formatDec((Imm & 0xc0) >> 6) << ']';
} else if ((Imm >= DppCtrl::ROW_SHL_FIRST) &&
(Imm <= DppCtrl::ROW_SHL_LAST)) {
O << "row_shl:";
printU4ImmDecOperand(MI, OpNo, O);
O << "row_shl:" << formatDec(Imm - DppCtrl::ROW_SHL0);
} else if ((Imm >= DppCtrl::ROW_SHR_FIRST) &&
(Imm <= DppCtrl::ROW_SHR_LAST)) {
O << "row_shr:";
printU4ImmDecOperand(MI, OpNo, O);
O << "row_shr:" << formatDec(Imm - DppCtrl::ROW_SHR0);
} else if ((Imm >= DppCtrl::ROW_ROR_FIRST) &&
(Imm <= DppCtrl::ROW_ROR_LAST)) {
O << "row_ror:";
printU4ImmDecOperand(MI, OpNo, O);
O << "row_ror:" << formatDec(Imm - DppCtrl::ROW_ROR0);
} else if (Imm == DppCtrl::WAVE_SHL1) {
if (AMDGPU::isGFX10Plus(STI)) {
O << "/* wave_shl is not supported starting from GFX10 */";
Expand Down Expand Up @@ -1126,15 +1114,14 @@ void AMDGPUInstPrinter::printDPPCtrl(const MCInst *MI, unsigned OpNo,
"than GFX90A/GFX10 */";
return;
}
printU4ImmDecOperand(MI, OpNo, O);
O << formatDec(Imm - DppCtrl::ROW_SHARE_FIRST);
} else if ((Imm >= DppCtrl::ROW_XMASK_FIRST) &&
(Imm <= DppCtrl::ROW_XMASK_LAST)) {
if (!AMDGPU::isGFX10Plus(STI)) {
O << "/* row_xmask is not supported on ASICs earlier than GFX10 */";
return;
}
O << "row_xmask:";
printU4ImmDecOperand(MI, OpNo, O);
O << "row_xmask:" << formatDec(Imm - DppCtrl::ROW_XMASK_FIRST);
} else {
O << "/* Invalid dpp_ctrl value */";
}
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class AMDGPUInstPrinter : public MCInstPrinter {
private:
void printU16ImmOperand(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O);
void printU4ImmDecOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printU16ImmDecOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
void printU32ImmOperand(const MCInst *MI, unsigned OpNo,
const MCSubtargetInfo &STI, raw_ostream &O);
Expand Down
Loading