Commit a667fb85 by Karl Schimpf

Modify pnacl subzero to be able to read pnacl bitcode files.

BUG=None R=jfb@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/277033003
parent f7c9a141
#!/usr/bin/env python2
import argparse
import itertools
import os
import re
import subprocess
import sys
for p in sys.path:
if p.endswith('/toolchain_build/src/pnacl-subzero'):
sys.path.insert(0, p + '/pydir')
break
from utils import shellcmd
if __name__ == '__main__':
desc = 'Run llvm2ice on llvm file to produce ICE instructions.'
argparser = argparse.ArgumentParser(
description=desc,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
epilog='''
Runs in two modes, depending on whether the flag '--pnacl' is specified.
If flag '--pnacl' is omitted, it runs llvm2ice to (directly) generate
the corresponding ICE instructions.
If flag '--pnacl' is given, it first assembles and freezes the
llvm source file generating the corresponding PNaCl bitcode
file. The PNaCl bitcode file is then piped into llvm2ice to
generate the corresponding ICE instructions.
''')
argparser.add_argument(
'--llvm2ice', required=False, default='./llvm2ice', metavar='LLVM2ICE',
help='Path to llvm2ice driver program')
argparser.add_argument('--llvm-bin-path', required=False,
default=None, metavar='LLVM_BIN_PATH',
help='Path to LLVM executables ' +
'(for building PNaCl files)')
argparser.add_argument('--pnacl', required=False,
action='store_true',
help='Convert llvm source to PNaCl bitcode ' +
'file first')
argparser.add_argument('--echo-cmd', required=False,
action='store_true',
help='Trace command that generates ICE instructions')
argparser.add_argument('llfile', nargs=1,
metavar='LLVM_FILE',
help='Llvm source file')
args = argparser.parse_args()
llvm_bin_path = args.llvm_bin_path
llfile = args.llfile[0]
cmd = []
if args.pnacl:
cmd = [os.path.join(llvm_bin_path, 'llvm-as'), llfile, '-o', '-', '|',
os.path.join(llvm_bin_path, 'pnacl-freeze'),
'--allow-local-symbol-tables', '|']
cmd += [args.llvm2ice, '-verbose', 'inst', '-notranslate']
if args.pnacl:
cmd += ['--allow-local-symbol-tables', '--bitcode-format=pnacl']
else:
cmd.append(llfile)
stdout_result = shellcmd(cmd, echo=args.echo_cmd)
if not args.echo_cmd:
sys.stdout.write(stdout_result)
import subprocess
import sys
def shellcmd(command, echo=True):
if echo: print '[cmd]', command
if not isinstance(command, str):
command = ' '.join(command)
stdout_result = subprocess.check_output(command, shell=True)
if echo: sys.stdout.write(stdout_result)
return stdout_result
......@@ -577,7 +577,7 @@ static cl::list<Ice::VerboseItem> VerboseList(
clEnumValN(Ice::IceV_All, "all", "Use all verbose options"),
clEnumValN(Ice::IceV_None, "none", "No verbosity"), clEnumValEnd));
static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"),
cl::Required);
cl::init("-"));
static cl::opt<std::string> OutputFilename("o",
cl::desc("Override output filename"),
cl::init("-"),
......@@ -594,6 +594,16 @@ DisableTranslation("notranslate", cl::desc("Disable Subzero translation"));
static cl::opt<bool> SubzeroTimingEnabled(
"timing", cl::desc("Enable breakdown timing of Subzero translation"));
static cl::opt<NaClFileFormat>
InputFileFormat(
"bitcode-format",
cl::desc("Define format of input file:"),
cl::values(
clEnumValN(LLVMFormat, "llvm", "LLVM file (default)"),
clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"),
clEnumValEnd),
cl::init(LLVMFormat));
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv);
......@@ -603,7 +613,7 @@ int main(int argc, char **argv) {
{
Ice::Timer T;
Mod = ParseIRFile(IRFilename, Err, getGlobalContext());
Mod = NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext());
if (SubzeroTimingEnabled) {
std::cerr << "[Subzero timing] IR Parsing: " << T.getElapsedSec()
......
......@@ -2,45 +2,40 @@
import argparse
import itertools
import subprocess
import re
if __name__ == '__main__':
"""Runs llvm2ice on an input .ll file, and compares the output
against the input.
"""Compares a LLVM file with a subzero file for differences.
Before comparing, the input file is massaged to remove comments,
Before comparing, the LLVM file is massaged to remove comments,
blank lines, global variable definitions, external function
declarations, and possibly other patterns that llvm2ice does not
handle.
The output file and the massaged input file are compared line by
The subzero file and the massaged LLVM file are compared line by
line for differences. However, there is a regex defined such that
if the regex matches a line in the input file, that line and the
corresponding line in the output file are ignored. This lets us
if the regex matches a line in the LLVM file, that line and the
corresponding line in the subzero file are ignored. This lets us
ignore minor differences such as inttoptr and ptrtoint, and
printing of floating-point constants.
On success, no output is produced. On failure, each mismatch is
printed as two lines, one starting with 'SZ' and one starting with
'LL'.
printed as two lines, one starting with 'SZ' (subzero) and one
starting with 'LL' (LLVM).
"""
desc = 'Compare llvm2ice output against bitcode input.'
desc = 'Compare LLVM and subzero bitcode files.'
argparser = argparse.ArgumentParser(description=desc)
argparser.add_argument(
'llfile', nargs='?', default='-',
type=argparse.FileType('r'), metavar='FILE',
help='Textual bitcode file [default stdin]')
'llfile', nargs=1,
type=argparse.FileType('r'), metavar='LLVM_FILE',
help='LLVM bitcode file')
argparser.add_argument(
'--llvm2ice', required=False, default='./llvm2ice', metavar='LLVM2ICE',
help='Path to llvm2ice driver program [default ./llvm2ice]')
'szfile', nargs='?', default='-',
type=argparse.FileType('r'), metavar='SUBZERO_FILE',
help='Subzero bitcode file [default stdin]')
args = argparser.parse_args()
bitcode = args.llfile.readlines()
# Run llvm2ice and collect its output lines into sz_out.
command = [args.llvm2ice, '-verbose', 'inst', '-notranslate', '-']
p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
sz_out = p.communicate(input=''.join(bitcode))[0].splitlines()
bitcode = args.llfile[0].readlines()
sz_out = [ line.rstrip() for line in args.szfile.readlines()]
# Filter certain lines and patterns from the input, and collect
# the remainder into llc_out.
......@@ -63,11 +58,12 @@ if __name__ == '__main__':
lines_total = 0
lines_diff = 0
ignore_pattern = re.compile(
'|'.join([' -[0-9]', # negative constants
' (float|double) [-0-9]', # FP constants
'|'.join([' -[0-9]', # negative constants
' (float|double) [-0-9]', # FP constants
' (float|double) %\w+, [-0-9]',
' inttoptr ', # inttoptr pointer types
' ptrtoint ' # ptrtoint pointer types
' inttoptr ', # inttoptr pointer types
' ptrtoint ', # ptrtoint pointer types
' bitcast .*\* .* to .*\*' # bitcast pointer types
]))
for (sz_line, llc_line) in itertools.izip_longest(sz_out, llc_out):
lines_total += 1
......
......@@ -32,7 +32,13 @@ config.substitutions.append(('%{python}', sys.executable))
llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH'))
# Finding Subzero tools
config.substitutions.append(('%llvm2ice', os.path.join(bin_root, 'llvm2ice')))
llvm2icetool = os.path.join(bin_root, 'llvm2ice')
config.substitutions.append(
('%llvm2iceinsts', ' '.join([os.path.join(bin_root, 'llvm2iceinsts.py'),
'--llvm2ice', llvm2icetool,
'--llvm-bin-path', llvmbinpath
])))
config.substitutions.append(('%llvm2ice', llvm2icetool))
config.substitutions.append(('%szdiff', os.path.join(bin_root, 'szdiff.py')))
llvmbintools = ['FileCheck']
......
; RUIN: %llvm2ice --verbose none %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
@__init_array_start = internal constant [0 x i8] zeroinitializer, align 4
@__fini_array_start = internal constant [0 x i8] zeroinitializer, align 4
......@@ -719,8 +721,8 @@ entry:
define internal i64 @load64(i32 %a) {
entry:
%a.asptr = inttoptr i32 %a to i64*
%v0 = load i64* %a.asptr, align 1
%__1 = inttoptr i32 %a to i64*
%v0 = load i64* %__1, align 1
ret i64 %v0
}
; CHECK: load64:
......@@ -730,8 +732,8 @@ entry:
define internal void @store64(i32 %a, i64 %value) {
entry:
%a.asptr = inttoptr i32 %a to i64*
store i64 %value, i64* %a.asptr, align 1
%__2 = inttoptr i32 %a to i64*
store i64 %value, i64* %__2, align 1
ret void
}
; CHECK: store64:
......
; RUIN: %llvm2ice --verbose none %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @fixed_400(i32 %n) {
entry:
%array = alloca i8, i32 400, align 16
%array.asint = ptrtoint i8* %array to i32
call void @f1(i32 %array.asint)
%__2 = ptrtoint i8* %array to i32
call void @f1(i32 %__2)
ret void
; CHECK: sub esp, 400
; CHECK-NEXT: mov eax, esp
......@@ -19,8 +21,8 @@ declare void @f1(i32)
define void @variable_n(i32 %n) {
entry:
%array = alloca i8, i32 %n, align 16
%array.asint = ptrtoint i8* %array to i32
call void @f2(i32 %array.asint)
%__2 = ptrtoint i8* %array to i32
call void @f2(i32 %__2)
ret void
; CHECK: mov eax, dword ptr [ebp+8]
; CHECK-NEXT: sub esp, eax
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i32 @Add(i32 %a, i32 %b) {
; CHECK: define i32 @Add
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i64 @arithmetic_chain(i64 %foo, i64 %bar) {
entry:
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define internal i32 @cast_f2i(float %f) {
entry:
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @testBool(i32 %a, i32 %b) {
entry:
......
; RUIN: %llvm2ice %s -verbose inst | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i32 @simple_cond_branch(i32 %foo, i32 %bar) {
entry:
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i32 @fib(i32 %n) {
; CHECK: define i32 @fib
......
; RUIN: %llvm2ice --verbose none %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
@__init_array_start = internal constant [0 x i8] zeroinitializer, align 4
@__fini_array_start = internal constant [0 x i8] zeroinitializer, align 4
......@@ -9,12 +11,12 @@
define internal void @CallIndirect(i32 %f) {
entry:
%f.asptr = inttoptr i32 %f to void ()*
call void %f.asptr()
call void %f.asptr()
call void %f.asptr()
call void %f.asptr()
call void %f.asptr()
%__1 = inttoptr i32 %f to void ()*
call void %__1()
call void %__1()
call void %__1()
call void %__1()
call void %__1()
ret void
}
; CHECK: call [[REGISTER:[a-z]+]]
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i64 @simple_zext(i32 %arg) {
entry:
......
; RUIN: %llvm2ice %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @testBool(i32 %a, i32 %b) {
entry:
......
; RUIN: %llvm2ice %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
@i8v = common global i8 0, align 1
@i16v = common global i16 0, align 2
@i32v = common global i32 0, align 4
@i64v = common global i64 0, align 8
@u8v = common global i8 0, align 1
@u16v = common global i16 0, align 2
@u32v = common global i32 0, align 4
@u64v = common global i64 0, align 8
@i1 = common global i32 0, align 4
@i2 = common global i32 0, align 4
@u1 = common global i32 0, align 4
@u2 = common global i32 0, align 4
@i8v = global [1 x i8] zeroinitializer, align 1
@i16v = global [2 x i8] zeroinitializer, align 2
@i32v = global [4 x i8] zeroinitializer, align 4
@i64v = global [8 x i8] zeroinitializer, align 8
@u8v = global [1 x i8] zeroinitializer, align 1
@u16v = global [2 x i8] zeroinitializer, align 2
@u32v = global [4 x i8] zeroinitializer, align 4
@u64v = global [8 x i8] zeroinitializer, align 8
define void @from_int8() {
entry:
%v0 = load i8* @i8v, align 1
%__0 = bitcast [1 x i8]* @i8v to i8*
%v0 = load i8* %__0, align 1
%v1 = sext i8 %v0 to i16
store i16 %v1, i16* @i16v, align 1
%__3 = bitcast [2 x i8]* @i16v to i16*
store i16 %v1, i16* %__3, align 1
%v2 = sext i8 %v0 to i32
store i32 %v2, i32* @i32v, align 1
%__5 = bitcast [4 x i8]* @i32v to i32*
store i32 %v2, i32* %__5, align 1
%v3 = sext i8 %v0 to i64
store i64 %v3, i64* @i64v, align 1
%__7 = bitcast [8 x i8]* @i64v to i64*
store i64 %v3, i64* %__7, align 1
ret void
; CHECK: mov al, byte ptr [
; CHECK-NEXT: movsx cx, al
......@@ -38,13 +40,17 @@ entry:
define void @from_int16() {
entry:
%v0 = load i16* @i16v, align 1
%__0 = bitcast [2 x i8]* @i16v to i16*
%v0 = load i16* %__0, align 1
%v1 = trunc i16 %v0 to i8
store i8 %v1, i8* @i8v, align 1
%__3 = bitcast [1 x i8]* @i8v to i8*
store i8 %v1, i8* %__3, align 1
%v2 = sext i16 %v0 to i32
store i32 %v2, i32* @i32v, align 1
%__5 = bitcast [4 x i8]* @i32v to i32*
store i32 %v2, i32* %__5, align 1
%v3 = sext i16 %v0 to i64
store i64 %v3, i64* @i64v, align 1
%__7 = bitcast [8 x i8]* @i64v to i64*
store i64 %v3, i64* %__7, align 1
ret void
; CHECK: mov ax, word ptr [
; CHECK-NEXT: mov cx, ax
......@@ -59,13 +65,17 @@ entry:
define void @from_int32() {
entry:
%v0 = load i32* @i32v, align 1
%__0 = bitcast [4 x i8]* @i32v to i32*
%v0 = load i32* %__0, align 1
%v1 = trunc i32 %v0 to i8
store i8 %v1, i8* @i8v, align 1
%__3 = bitcast [1 x i8]* @i8v to i8*
store i8 %v1, i8* %__3, align 1
%v2 = trunc i32 %v0 to i16
store i16 %v2, i16* @i16v, align 1
%__5 = bitcast [2 x i8]* @i16v to i16*
store i16 %v2, i16* %__5, align 1
%v3 = sext i32 %v0 to i64
store i64 %v3, i64* @i64v, align 1
%__7 = bitcast [8 x i8]* @i64v to i64*
store i64 %v3, i64* %__7, align 1
ret void
; CHECK: mov eax, dword ptr [
; CHECK-NEXT: mov ecx, eax
......@@ -80,13 +90,17 @@ entry:
define void @from_int64() {
entry:
%v0 = load i64* @i64v, align 1
%__0 = bitcast [8 x i8]* @i64v to i64*
%v0 = load i64* %__0, align 1
%v1 = trunc i64 %v0 to i8
store i8 %v1, i8* @i8v, align 1
%__3 = bitcast [1 x i8]* @i8v to i8*
store i8 %v1, i8* %__3, align 1
%v2 = trunc i64 %v0 to i16
store i16 %v2, i16* @i16v, align 1
%__5 = bitcast [2 x i8]* @i16v to i16*
store i16 %v2, i16* %__5, align 1
%v3 = trunc i64 %v0 to i32
store i32 %v3, i32* @i32v, align 1
%__7 = bitcast [4 x i8]* @i32v to i32*
store i32 %v3, i32* %__7, align 1
ret void
; CHECK: mov eax, dword ptr [
; CHECK-NEXT: mov ecx, eax
......@@ -98,13 +112,17 @@ entry:
define void @from_uint8() {
entry:
%v0 = load i8* @u8v, align 1
%__0 = bitcast [1 x i8]* @u8v to i8*
%v0 = load i8* %__0, align 1
%v1 = zext i8 %v0 to i16
store i16 %v1, i16* @i16v, align 1
%__3 = bitcast [2 x i8]* @i16v to i16*
store i16 %v1, i16* %__3, align 1
%v2 = zext i8 %v0 to i32
store i32 %v2, i32* @i32v, align 1
%__5 = bitcast [4 x i8]* @i32v to i32*
store i32 %v2, i32* %__5, align 1
%v3 = zext i8 %v0 to i64
store i64 %v3, i64* @i64v, align 1
%__7 = bitcast [8 x i8]* @i64v to i64*
store i64 %v3, i64* %__7, align 1
ret void
; CHECK: mov al, byte ptr [
; CHECK-NEXT: movzx cx, al
......@@ -119,13 +137,17 @@ entry:
define void @from_uint16() {
entry:
%v0 = load i16* @u16v, align 1
%__0 = bitcast [2 x i8]* @u16v to i16*
%v0 = load i16* %__0, align 1
%v1 = trunc i16 %v0 to i8
store i8 %v1, i8* @i8v, align 1
%__3 = bitcast [1 x i8]* @i8v to i8*
store i8 %v1, i8* %__3, align 1
%v2 = zext i16 %v0 to i32
store i32 %v2, i32* @i32v, align 1
%__5 = bitcast [4 x i8]* @i32v to i32*
store i32 %v2, i32* %__5, align 1
%v3 = zext i16 %v0 to i64
store i64 %v3, i64* @i64v, align 1
%__7 = bitcast [8 x i8]* @i64v to i64*
store i64 %v3, i64* %__7, align 1
ret void
; CHECK: mov ax, word ptr [
; CHECK-NEXT: mov cx, ax
......@@ -140,13 +162,17 @@ entry:
define void @from_uint32() {
entry:
%v0 = load i32* @u32v, align 1
%__0 = bitcast [4 x i8]* @u32v to i32*
%v0 = load i32* %__0, align 1
%v1 = trunc i32 %v0 to i8
store i8 %v1, i8* @i8v, align 1
%__3 = bitcast [1 x i8]* @i8v to i8*
store i8 %v1, i8* %__3, align 1
%v2 = trunc i32 %v0 to i16
store i16 %v2, i16* @i16v, align 1
%__5 = bitcast [2 x i8]* @i16v to i16*
store i16 %v2, i16* %__5, align 1
%v3 = zext i32 %v0 to i64
store i64 %v3, i64* @i64v, align 1
%__7 = bitcast [8 x i8]* @i64v to i64*
store i64 %v3, i64* %__7, align 1
ret void
; CHECK: mov eax, dword ptr [
; CHECK-NEXT: mov ecx, eax
......@@ -160,13 +186,17 @@ entry:
define void @from_uint64() {
entry:
%v0 = load i64* @u64v, align 1
%__0 = bitcast [8 x i8]* @u64v to i64*
%v0 = load i64* %__0, align 1
%v1 = trunc i64 %v0 to i8
store i8 %v1, i8* @i8v, align 1
%__3 = bitcast [1 x i8]* @i8v to i8*
store i8 %v1, i8* %__3, align 1
%v2 = trunc i64 %v0 to i16
store i16 %v2, i16* @i16v, align 1
%__5 = bitcast [2 x i8]* @i16v to i16*
store i16 %v2, i16* %__5, align 1
%v3 = trunc i64 %v0 to i32
store i32 %v3, i32* @i32v, align 1
%__7 = bitcast [4 x i8]* @i32v to i32*
store i32 %v3, i32* %__7, align 1
ret void
; CHECK: mov eax, dword ptr [
; CHECK-NEXT: mov ecx, eax
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @foo() {
; CHECK: define void @foo()
......
; RUIN: %llvm2ice --verbose none %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
@__init_array_start = internal constant [0 x i8] zeroinitializer, align 4
@__fini_array_start = internal constant [0 x i8] zeroinitializer, align 4
......@@ -1017,8 +1019,8 @@ entry:
define internal float @loadFloat(i32 %a) {
entry:
%a.asptr = inttoptr i32 %a to float*
%v0 = load float* %a.asptr, align 4
%__1 = inttoptr i32 %a to float*
%v0 = load float* %__1, align 4
ret float %v0
}
; CHECK: loadFloat:
......@@ -1027,8 +1029,8 @@ entry:
define internal double @loadDouble(i32 %a) {
entry:
%a.asptr = inttoptr i32 %a to double*
%v0 = load double* %a.asptr, align 8
%__1 = inttoptr i32 %a to double*
%v0 = load double* %__1, align 8
ret double %v0
}
; CHECK: loadDouble:
......@@ -1037,8 +1039,8 @@ entry:
define internal void @storeFloat(i32 %a, float %value) {
entry:
%a.asptr = inttoptr i32 %a to float*
store float %value, float* %a.asptr, align 4
%__2 = inttoptr i32 %a to float*
store float %value, float* %__2, align 4
ret void
}
; CHECK: storeFloat:
......@@ -1046,8 +1048,8 @@ entry:
define internal void @storeDouble(i32 %a, double %value) {
entry:
%a.asptr = inttoptr i32 %a to double*
store double %value, double* %a.asptr, align 8
%__2 = inttoptr i32 %a to double*
store double %value, double* %__2, align 8
ret void
}
; CHECK: storeDouble:
......
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
; This is a smoke test for floating-point constant pooling. It tests
; pooling of various float and double constants (including positive
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
@intern_global = global i32 12, align 4
@extern_global = external global i32
; Note: We don't run this test using a PNaCl bitcode file, because
; external globals are not in the PNaCl ABI.
@intern_global = global [4 x i8] [i8 0, i8 0, i8 0, i8 12], align 4
@extern_global = external global [4 x i8]
define i32 @test_intern_global() {
; CHECK: define i32 @test_intern_global
entry:
%v0 = load i32* @intern_global, align 1
%__1 = bitcast [4 x i8]* @intern_global to i32*
%v0 = load i32* %__1, align 1
ret i32 %v0
}
define i32 @test_extern_global() {
; CHECK: define i32 @test_extern_global
entry:
%v0 = load i32* @extern_global, align 1
%__1 = bitcast [4 x i8]* @extern_global to i32*
%v0 = load i32* %__1, align 1
ret i32 %v0
}
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @dummy_icmp(i64 %foo, i64 %bar) {
; CHECK: define void @dummy_icmp
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
define void @dummy_inttoptr(i32 %addr_arg) {
entry:
%ptr = inttoptr i32 %addr_arg to i32*
ret void
; CHECK: %ptr = i32 %addr_arg
}
; ERRORS-NOT: ICE translation error
; DUMP-NOT: SZ
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @load_i64(i32 %addr_arg) {
entry:
%ptr64 = inttoptr i32 %addr_arg to i64*
%iv = load i64* %ptr64, align 1
%__1 = inttoptr i32 %addr_arg to i64*
%iv = load i64* %__1, align 1
ret void
; CHECK: %ptr64 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: %iv = load i64* {{.*}}, align 1
; CHECK-NEXT: ret void
}
define void @load_i32(i32 %addr_arg) {
entry:
%ptr32 = inttoptr i32 %addr_arg to i32*
%iv = load i32* %ptr32, align 1
%__1 = inttoptr i32 %addr_arg to i32*
%iv = load i32* %__1, align 1
ret void
; CHECK: %ptr32 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: %iv = load i32* {{.*}}, align 1
; CHECK-NEXT: ret void
}
define void @load_i16(i32 %addr_arg) {
entry:
%ptr16 = inttoptr i32 %addr_arg to i16*
%iv = load i16* %ptr16, align 1
%__1 = inttoptr i32 %addr_arg to i16*
%iv = load i16* %__1, align 1
ret void
; CHECK: %ptr16 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: %iv = load i16* {{.*}}, align 1
; CHECK-NEXT: ret void
}
define void @load_i8(i32 %addr_arg) {
entry:
%ptr8 = inttoptr i32 %addr_arg to i8*
%iv = load i8* %ptr8, align 1
%__1 = inttoptr i32 %addr_arg to i8*
%iv = load i8* %__1, align 1
ret void
; CHECK: %ptr8 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: %iv = load i8* {{.*}}, align 1
; CHECK-NEXT: ret void
}
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i32 @func_single_arg(i32 %a) {
; CHECK: define i32 @func_single_arg
......
; RUIN: %llvm2ice %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @testSelect(i32 %a, i32 %b) {
entry:
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
@i1 = common global i32 0, align 4
@i2 = common global i32 0, align 4
@u1 = common global i32 0, align 4
@u2 = common global i32 0, align 4
@i1 = global [4 x i8] zeroinitializer, align 4
@i2 = global [4 x i8] zeroinitializer, align 4
@u1 = global [4 x i8] zeroinitializer, align 4
define void @conv1() {
entry:
%v0 = load i32* @u1, align 1
%__0 = bitcast [4 x i8]* @u1 to i32*
%v0 = load i32* %__0, align 1
%sext = shl i32 %v0, 24
%v1 = ashr i32 %sext, 24
store i32 %v1, i32* @i1, align 1
%__4 = bitcast [4 x i8]* @i1 to i32*
store i32 %v1, i32* %__4, align 1
ret void
; CHECK: shl eax, 24
; CHECK-NEXT: sar eax, 24
......@@ -20,10 +23,12 @@ entry:
define void @conv2() {
entry:
%v0 = load i32* @u1, align 1
%__0 = bitcast [4 x i8]* @u1 to i32*
%v0 = load i32* %__0, align 1
%sext1 = shl i32 %v0, 16
%v1 = ashr i32 %sext1, 16
store i32 %v1, i32* @i2, align 1
%__4 = bitcast [4 x i8]* @i2 to i32*
store i32 %v1, i32* %__4, align 1
ret void
; CHECK: shl eax, 16
; CHECK-NEXT: sar eax, 16
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i64 @add_args_i64(i64 %arg1, i64 %arg2) {
entry:
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define internal i32 @simple_cond(i32 %a, i32 %n) {
entry:
......@@ -16,8 +18,8 @@ if.then:
if.else:
%gep_array = mul i32 %n, 4
%gep = add i32 %a, %gep_array
%gep.asptr = inttoptr i32 %gep to i32*
%v0 = load i32* %gep.asptr, align 1
%__6 = inttoptr i32 %gep to i32*
%v0 = load i32* %__6, align 1
br label %if.end
if.end:
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i32 @simple_loop(i32 %a, i32 %n) {
entry:
......@@ -12,8 +14,8 @@ for.body:
%sum.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]
%gep_array = mul i32 %i.06, 4
%gep = add i32 %a, %gep_array
%gep.asptr = inttoptr i32 %gep to i32*
%v0 = load i32* %gep.asptr, align 1
%__9 = inttoptr i32 %gep to i32*
%v0 = load i32* %__9, align 1
%add = add i32 %v0, %sum.05
%inc = add i32 %i.06, 1
%cmp = icmp slt i32 %inc, %n
......
; RUIN: %llvm2ice %s -verbose inst | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define void @store_i64(i32 %addr_arg) {
entry:
%ptr64 = inttoptr i32 %addr_arg to i64*
store i64 1, i64* %ptr64, align 1
%__1 = inttoptr i32 %addr_arg to i64*
store i64 1, i64* %__1, align 1
ret void
; CHECK: %ptr64 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: store i64 1, {{.*}}, align 1
; CHECK-NEXT: ret void
}
define void @store_i32(i32 %addr_arg) {
entry:
%ptr32 = inttoptr i32 %addr_arg to i32*
store i32 1, i32* %ptr32, align 1
%__1 = inttoptr i32 %addr_arg to i32*
store i32 1, i32* %__1, align 1
ret void
; CHECK: %ptr32 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: store i32 1, {{.*}}, align 1
; CHECK-NEXT: ret void
}
define void @store_i16(i32 %addr_arg) {
entry:
%ptr16 = inttoptr i32 %addr_arg to i16*
store i16 1, i16* %ptr16, align 1
%__1 = inttoptr i32 %addr_arg to i16*
store i16 1, i16* %__1, align 1
ret void
; CHECK: %ptr16 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: store i16 1, {{.*}}, align 1
; CHECK-NEXT: ret void
}
define void @store_i8(i32 %addr_arg) {
entry:
%ptr8 = inttoptr i32 %addr_arg to i8*
store i8 1, i8* %ptr8, align 1
%__1 = inttoptr i32 %addr_arg to i8*
store i8 1, i8* %__1, align 1
ret void
; CHECK: %ptr8 = i32 %addr_arg
; CHECK: %__1 = i32 %addr_arg
; CHECK-NEXT: store i8 1, {{.*}}, align 1
; CHECK-NEXT: ret void
}
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
; This file is lowered from C code that does some simple aritmetic with
; struct members. It's also built with the PNaCl toolchain so this is the
......@@ -9,37 +11,37 @@
define internal i32 @compute_important_function(i32 %v1, i32 %v2) {
entry:
%v1.asptr = inttoptr i32 %v1 to i32*
%_v0 = load i32* %v1.asptr, align 1
%__2 = inttoptr i32 %v1 to i32*
%_v0 = load i32* %__2, align 1
; CHECK: entry:
; CHECK-NEXT: %v1.asptr = i32 %v1
; CHECK-NEXT: %__2 = i32 %v1
; CHECK-NEXT: %_v0 = load i32* {{.*}}, align 1
%v2.asptr = inttoptr i32 %v2 to i32*
%_v1 = load i32* %v2.asptr, align 1
%__4 = inttoptr i32 %v2 to i32*
%_v1 = load i32* %__4, align 1
%gep = add i32 %v2, 12
%gep.asptr = inttoptr i32 %gep to i32*
%_v2 = load i32* %gep.asptr, align 1
%__7 = inttoptr i32 %gep to i32*
%_v2 = load i32* %__7, align 1
%mul = mul i32 %_v2, %_v1
%gep6 = add i32 %v1, 4
%gep6.asptr = inttoptr i32 %gep6 to i32*
%_v3 = load i32* %gep6.asptr, align 1
%__11 = inttoptr i32 %gep6 to i32*
%_v3 = load i32* %__11, align 1
%gep8 = add i32 %v2, 8
%gep8.asptr = inttoptr i32 %gep8 to i32*
%_v4 = load i32* %gep8.asptr, align 1
%__14 = inttoptr i32 %gep8 to i32*
%_v4 = load i32* %__14, align 1
%gep10 = add i32 %v2, 4
%gep10.asptr = inttoptr i32 %gep10 to i32*
%_v5 = load i32* %gep10.asptr, align 1
%__17 = inttoptr i32 %gep10 to i32*
%_v5 = load i32* %__17, align 1
%mul3 = mul i32 %_v5, %_v4
%gep12 = add i32 %v1, 8
%gep12.asptr = inttoptr i32 %gep12 to i32*
%_v6 = load i32* %gep12.asptr, align 1
%__21 = inttoptr i32 %gep12 to i32*
%_v6 = load i32* %__21, align 1
%mul7 = mul i32 %_v6, %_v3
%mul9 = mul i32 %mul7, %_v6
%gep14 = add i32 %v1, 12
%gep14.asptr = inttoptr i32 %gep14 to i32*
%_v7 = load i32* %gep14.asptr, align 1
%__26 = inttoptr i32 %gep14 to i32*
%_v7 = load i32* %__26, align 1
%mul11 = mul i32 %mul9, %_v7
%add4.neg = add i32 %mul, %_v0
%add = sub i32 %add4.neg, %_v3
......
; RUIN: %llvm2ice %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define i32 @testSwitch(i32 %a) {
entry:
......
; RUIN: %llvm2ice -verbose inst %s | FileCheck %s
; RUIN: %llvm2ice --verbose none %s | FileCheck --check-prefix=ERRORS %s
; RUN: %szdiff --llvm2ice=%llvm2ice %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts %s | %szdiff %s | FileCheck --check-prefix=DUMP %s
; RUN: %llvm2iceinsts --pnacl %s | %szdiff %s \
; RUN: | FileCheck --check-prefix=DUMP %s
define internal i32 @divide(i32 %num, i32 %den) {
entry:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment