Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

32
external/llvm/utils/DSAclean.py vendored Executable file
View File

@@ -0,0 +1,32 @@
#! /usr/bin/python
#changelog:
#10/13/2005b: replaced the # in tmp(.#*)* with alphanumeric and _, this will then remove
#nodes such as %tmp.1.i and %tmp._i.3
#10/13/2005: exntended to remove variables of the form %tmp(.#)* rather than just
#%tmp.#, i.e. it now will remove %tmp.12.3.15 etc, additionally fixed a spelling error in
#the comments
#10/12/2005: now it only removes nodes and edges for which the label is %tmp.# rather
#than removing all lines for which the lable CONTAINS %tmp.#
import re
import sys
if( len(sys.argv) < 3 ):
print 'usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>'
sys.exit(1)
#get a file object
input = open(sys.argv[1], 'r')
output = open(sys.argv[2], 'w')
#we'll get this one line at a time...while we could just put the whole thing in a string
#it would kill old computers
buffer = input.readline()
while buffer != '':
if re.compile("label(\s*)=(\s*)\"\s%tmp(.\w*)*(\s*)\"").search(buffer):
#skip next line, write neither this line nor the next
buffer = input.readline()
else:
#this isn't a tmp Node, we can write it
output.write(buffer)
#prepare for the next iteration
buffer = input.readline()
input.close()
output.close()

111
external/llvm/utils/DSAextract.py vendored Normal file
View File

@@ -0,0 +1,111 @@
#! /usr/bin/python
#this is a script to extract given named nodes from a dot file, with
#the associated edges. An edge is kept iff for edge x -> y
# x and y are both nodes specified to be kept.
#known issues: if a line contains '->' and is not an edge line
#problems will occur. If node labels do not begin with
#Node this also will not work. Since this is designed to work
#on DSA dot output and not general dot files this is ok.
#If you want to use this on other files rename the node labels
#to Node[.*] with a script or something. This also relies on
#the length of a node name being 13 characters (as it is in all
#DSA dot output files)
#Note that the name of the node can be any substring of the actual
#name in the dot file. Thus if you say specify COLLAPSED
#as a parameter this script will pull out all COLLAPSED
#nodes in the file
#Specifying escape characters in the name like \n also will not work,
#as Python
#will make it \\n, I'm not really sure how to fix this
#currently the script prints the names it is searching for
#to STDOUT, so you can check to see if they are what you intend
import re
import string
import sys
if len(sys.argv) < 3:
print 'usage is ./DSAextract <dot_file_to_modify> \
<output_file> [list of nodes to extract]'
#open the input file
input = open(sys.argv[1], 'r')
#construct a set of node names
node_name_set = set()
for name in sys.argv[3:]:
node_name_set |= set([name])
#construct a list of compiled regular expressions from the
#node_name_set
regexp_list = []
for name in node_name_set:
regexp_list.append(re.compile(name))
#used to see what kind of line we are on
nodeexp = re.compile('Node')
#used to check to see if the current line is an edge line
arrowexp = re.compile('->')
node_set = set()
#read the file one line at a time
buffer = input.readline()
while buffer != '':
#filter out the unnecessary checks on all the edge lines
if not arrowexp.search(buffer):
#check to see if this is a node we are looking for
for regexp in regexp_list:
#if this name is for the current node, add the dot variable name
#for the node (it will be Node(hex number)) to our set of nodes
if regexp.search(buffer):
node_set |= set([re.split('\s+',buffer,2)[1]])
break
buffer = input.readline()
#test code
#print '\n'
print node_name_set
#print node_set
#open the output file
output = open(sys.argv[2], 'w')
#start the second pass over the file
input = open(sys.argv[1], 'r')
buffer = input.readline()
while buffer != '':
#there are three types of lines we are looking for
#1) node lines, 2) edge lines 3) support lines (like page size, etc)
#is this an edge line?
#note that this is no completely robust, if a none edge line
#for some reason contains -> it will be missidentified
#hand edit the file if this happens
if arrowexp.search(buffer):
#check to make sure that both nodes are in the node list
#if they are print this to output
nodes = arrowexp.split(buffer)
nodes[0] = string.strip(nodes[0])
nodes[1] = string.strip(nodes[1])
if nodes[0][:13] in node_set and \
nodes[1][:13] in node_set:
output.write(buffer)
elif nodeexp.search(buffer): #this is a node line
node = re.split('\s+', buffer,2)[1]
if node in node_set:
output.write(buffer)
else: #this is a support line
output.write(buffer)
buffer = input.readline()

View File

@@ -0,0 +1,5 @@
add_llvm_utility(FileCheck
FileCheck.cpp
)
target_link_libraries(FileCheck PRIVATE LLVMSupport)

File diff suppressed because it is too large Load Diff

382
external/llvm/utils/GenLibDeps.pl vendored Executable file
View File

@@ -0,0 +1,382 @@
#!/usr/bin/perl -w
#
# Program: GenLibDeps.pl
#
# Synopsis: Generate HTML output that shows the dependencies between a set of
# libraries. The output of this script should periodically replace
# the similar content in the UsingLibraries.html document.
#
# Syntax: GenLibDeps.pl [-flat] <directory_with_libraries_in_it> [path_to_nm_binary]
#
use strict;
use warnings;
# Parse arguments...
my $FLAT = 0;
my $WHY = 0;
my $PEROBJ = 0;
my $PEROBJINCL = 0;
while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
shift;
last if /^--$/; # Stop processing arguments on --
# List command line options here...
if (/^-flat$/) { $FLAT = 1; next; }
if (/^-why/) { $WHY = 1; $FLAT = 1; next; }
if (/^-perobj$/) { $PEROBJ = 1; next; }
if (/^-perobjincl/) { $PEROBJINCL = 1; next;}
print "Unknown option: $_ : ignoring!\n";
}
# Give first option a name.
my $Directory = $ARGV[0];
if (!defined($Directory) || ! -d "$Directory") {
die "First argument must specify the directory containing LLVM libs\n";
}
my $nmPath = $ARGV[1];
# Find the "dot" program
my $DotPath="";
if (!$FLAT) {
chomp($DotPath = `which dot`);
die "Can't find 'dot'" if (! -x "$DotPath");
}
if (defined($ENV{NM})) {
chomp($nmPath=$ENV{NM});
}
if (!defined($nmPath) || $nmPath eq "") {
chomp($nmPath=`which nm`);
die "Can't find 'nm'" if (! -x "$nmPath");
}
my $ranlibPath;
if ($PEROBJ) {
$ranlibPath = $ARGV[2];
if (defined($ENV{RANLIB})) {
chomp($ranlibPath=$ENV{RANLIB});
}
if (!defined($ranlibPath) || $ranlibPath eq "") {
chomp($ranlibPath=`which ranlib`);
die "Can't find 'ranlib'" if (! -x "$ranlibPath");
}
}
# Open the directory and read its contents, sorting by name and differentiating
# by whether its a library (.a) or an object file (.o)
opendir DIR,$Directory;
my @files = readdir DIR;
closedir DIR;
my @libs = grep(/libLLVM.*\.(dylib|so|a)$/,sort(@files));
# Omit the all-of-llvm shared library.
@libs = grep(!/libLLVM-\d\.\d(svn)?\.(dylib|so)/, @libs);
my @objs = grep(/LLVM.*\.o$/,sort(@files));
# Declare the hashes we will use to keep track of the library and object file
# symbol definitions.
my %libdefs;
my %objdefs;
my %libobjs;
my %objdeps=();
# Gather library definitions at object file granularity (optional)
if ($PEROBJ) {
foreach my $lib (@libs ) {
`$ranlibPath $Directory/$lib`;
my $libpath = $lib;
$libpath =~ s/^libLLVM(.*)\.a/$1/;
$libpath =~ s/(.+)CodeGen$/Target\/$1/;
$libpath =~ s/(.+)AsmPrinter$/Target\/$1\/AsmPrinter/;
$libpath =~ s/(.+)AsmParser$/Target\/$1\/AsmParser/;
$libpath =~ s/(.+)Info$/Target\/$1\/TargetInfo/;
$libpath =~ s/(.+)Disassembler$/Target\/$1\/Disassembler/;
$libpath =~ s/SelectionDAG/CodeGen\/SelectionDAG/;
$libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/;
$libpath =~ s/^BitReader/Bitcode\/Reader/;
$libpath =~ s/^BitWriter/Bitcode\/Writer/;
$libpath =~ s/^MSIL/Target\/MSIL/;
$libpath =~ s/^Core/IR/;
$libpath =~ s/^Instrumentation/Transforms\/Instrumentation/;
$libpath =~ s/^Interpreter/ExecutionEngine\/Interpreter/;
$libpath =~ s/^JIT/ExecutionEngine\/JIT/;
$libpath =~ s/^ScalarOpts/Transforms\/Scalar/;
$libpath =~ s/^TransformUtils/Transforms\/Utils/;
$libpath =~ s/^ipa/Analysis\/IPA/;
$libpath =~ s/^ipo/Transforms\/IPO/;
$libpath = "lib/".$libpath."/";
open DEFS, "$nmPath -sg $Directory/$lib|";
while (<DEFS>) {
chomp;
if (/^([^ ]*) in ([^ ]*)/) {
my $objfile = $libpath.$2;
$objdefs{$1} = $objfile;
$objdeps{$objfile} = {};
$libobjs{$lib}{$objfile}=1;
# my $p = "../llvm/".$objfile;
# $p =~ s/Support\/reg(.*).o/Support\/reg$1.c/;
# $p =~ s/.o$/.cpp/;
# unless (-e $p) {
# die "$p\n"
# }
}
}
close DEFS or die "nm failed";
}
foreach my $lib (@libs ) {
my $libpath = $lib;
$libpath =~ s/^libLLVM(.*)\.a/$1/;
$libpath =~ s/(.+)CodeGen$/Target\/$1/;
$libpath =~ s/(.+)AsmPrinter$/Target\/$1\/AsmPrinter/;
$libpath =~ s/(.+)AsmParser$/Target\/$1\/AsmParser/;
$libpath =~ s/(.+)Info$/Target\/$1\/TargetInfo/;
$libpath =~ s/(.+)Disassembler$/Target\/$1\/Disassembler/;
$libpath =~ s/SelectionDAG/CodeGen\/SelectionDAG/;
$libpath =~ s/^AsmPrinter/CodeGen\/AsmPrinter/;
$libpath =~ s/^BitReader/Bitcode\/Reader/;
$libpath =~ s/^BitWriter/Bitcode\/Writer/;
$libpath =~ s/^MSIL/Target\/MSIL/;
$libpath =~ s/^Core/VMCore/;
$libpath =~ s/^Instrumentation/Transforms\/Instrumentation/;
$libpath =~ s/^Interpreter/ExecutionEngine\/Interpreter/;
$libpath =~ s/^JIT/ExecutionEngine\/JIT/;
$libpath =~ s/^ScalarOpts/Transforms\/Scalar/;
$libpath =~ s/^TransformUtils/Transforms\/Utils/;
$libpath =~ s/^ipa/Analysis\/IPA/;
$libpath =~ s/^ipo/Transforms\/IPO/;
$libpath = "lib/".$libpath."/";
open UDEFS, "$nmPath -Aup $Directory/$lib|";
while (<UDEFS>) {
chomp;
if (/:([^:]+):/) {
my $obj = $libpath.$1;
s/[^ ]+: *U //;
if (defined($objdefs{$_})) {
$objdeps{$obj}{$objdefs{$_}}=1;
}
}
}
close UDEFS or die "nm failed"
}
} else {
# Gather definitions from the libraries
foreach my $lib (@libs ) {
open DEFS, "$nmPath -g $Directory/$lib|";
while (<DEFS>) {
next if (! / [ABCDGRST] /);
s/^[^ ]* [ABCDGRST] //;
s/\015?\012//; # not sure if <DEFS> is in binmode and uses LF or CRLF.
# this strips both LF and CRLF.
$libdefs{$_} = $lib;
}
close DEFS or die "nm failed";
}
}
# Gather definitions from the object files.
foreach my $obj (@objs ) {
open DEFS, "$nmPath -g $Directory/$obj |";
while (<DEFS>) {
next if (! / [ABCDGRST] /);
s/^[^ ]* [ABCDGRST] //;
s/\015?\012//; # not sure if <DEFS> is in binmode and uses LF or CRLF.
# this strips both LF and CRLF.
$objdefs{$_} = $obj;
}
close DEFS or die "nm failed";
}
# Generate one entry in the <dl> list. This generates the <dt> and <dd> elements
# for one library or object file. The <dt> provides the name of the library or
# object. The <dd> provides a list of the libraries/objects it depends on.
sub gen_one_entry {
my $lib = $_[0];
my $lib_ns = $lib;
$lib_ns =~ s/(.*)\.[oa]/$1/;
if ($FLAT) {
print "$lib:";
if ($WHY) { print "\n"; }
} else {
print " <dt><b>$lib</b></dt><dd><ul>\n";
}
open UNDEFS,
"$nmPath -u $Directory/$lib | sed -e 's/^[ 0]* U //' | sort | uniq |";
my %DepLibs;
while (<UNDEFS>) {
chomp;
my $lib_printed = 0;
if (defined($libdefs{$_}) && $libdefs{$_} ne $lib) {
$DepLibs{$libdefs{$_}} = [] unless exists $DepLibs{$libdefs{$_}};
push(@{$DepLibs{$libdefs{$_}}}, $_);
} elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
if ($PEROBJ && !$PEROBJINCL) {
# -perobjincl makes .a files depend on .o files they contain themselves
# default is don't depend on these.
next if defined $libobjs{$lib}{$objdefs{$_}};
}
my $libroot = $lib;
$libroot =~ s/lib(.*).a/$1/;
if ($objdefs{$_} ne "$libroot.o") {
$DepLibs{$objdefs{$_}} = [] unless exists $DepLibs{$objdefs{$_}};
push(@{$DepLibs{$objdefs{$_}}}, $_);
}
}
}
close UNDEFS or die "nm failed";
unless(keys %DepLibs) {
# above failed
open UNDEFS, "$nmPath -u $Directory/$lib |";
while (<UNDEFS>) {
# to bypass non-working sed
if (' ' eq substr($_,0,2) and index($_,'U ')) {
$_ = substr($_,index($_,'U ')+2)
};
$_ = substr($_,index($_,' *U ')+5) if -1!=index($_,' *U ');
chomp;
my $lib_printed = 0;
if (defined($libdefs{$_}) && $libdefs{$_} ne $lib) {
$DepLibs{$libdefs{$_}} = [] unless exists $DepLibs{$libdefs{$_}};
push(@{$DepLibs{$libdefs{$_}}}, $_);
} elsif (defined($objdefs{$_}) && $objdefs{$_} ne $lib) {
my $libroot = $lib;
$libroot =~ s/lib(.*).a/$1/;
if ($objdefs{$_} ne "$libroot.o") {
$DepLibs{$objdefs{$_}} = [] unless exists $DepLibs{$objdefs{$_}};
push(@{$DepLibs{$objdefs{$_}}}, $_);
}
}
}
close UNDEFS or die "nm failed";
}
if ($PEROBJINCL) {
# include the .a's objects
for my $obj (keys %{$libobjs{$lib}}) {
$DepLibs{$obj} = ["<.a object>"] unless exists $DepLibs{$obj};
}
my $madechange = 1;
while($madechange) {
$madechange = 0;
my %temp = %DepLibs;
foreach my $obj (keys %DepLibs) {
foreach my $objdeps (keys %{$objdeps{$obj}}) {
next if defined $temp{$objdeps};
push(@{$temp{$objdeps}}, $obj);
$madechange = 1;
}
}
%DepLibs = %temp;
}
}
for my $key (sort keys %DepLibs) {
if ($FLAT) {
print " $key";
if ($WHY) {
print "\n";
my @syms = @{$DepLibs{$key}};
foreach my $sym (@syms) {
print " $sym\n";
}
}
} else {
print " <li>$key</li>\n";
}
my $suffix = substr($key,length($key)-1,1);
$key =~ s/(.*)\.[oa]/$1/;
if ($suffix eq "a") {
if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=0 ];\n" };
} else {
if (!$FLAT) { print DOT "$lib_ns -> $key [ weight=10];\n" };
}
}
if ($FLAT) {
if (!$WHY) {
print "\n";
}
} else {
print " </ul></dd>\n";
}
}
# Make sure we flush on write. This is slower but correct based on the way we
# write I/O in gen_one_entry.
$| = 1;
# Print the definition list tag
if (!$FLAT) {
print "<dl>\n";
open DOT, "| $DotPath -Tgif > libdeps.gif";
print DOT "digraph LibDeps {\n";
print DOT " size=\"40,15\"; \n";
print DOT " ratio=\"1.33333\"; \n";
print DOT " margin=\"0.25\"; \n";
print DOT " rankdir=\"LR\"; \n";
print DOT " mclimit=\"50.0\"; \n";
print DOT " ordering=\"out\"; \n";
print DOT " center=\"1\";\n";
print DOT "node [shape=\"box\",\n";
print DOT " color=\"#000088\",\n";
print DOT " fillcolor=\"#FFFACD\",\n";
print DOT " fontcolor=\"#3355BB\",\n";
print DOT " style=\"filled\",\n";
print DOT " fontname=\"sans\",\n";
print DOT " fontsize=\"24\"\n";
print DOT "];\n";
print DOT "edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
}
# Print libraries first
foreach my $lib (@libs) {
gen_one_entry($lib);
}
if ($PEROBJ) {
foreach my $obj (keys %objdeps) {
print "$obj:";
if (!$PEROBJINCL) {
foreach my $dep (keys %{$objdeps{$obj}}) {
print " $dep";
}
}
print "\n";
}
}
if (!$FLAT) {
print DOT "}\n";
close DOT;
open DOT, "| $DotPath -Tgif > objdeps.gif";
print DOT "digraph ObjDeps {\n";
print DOT " size=\"8,10\";\n";
print DOT " margin=\"0.25\";\n";
print DOT " rankdir=\"LR\";\n";
print DOT " mclimit=\"50.0\";\n";
print DOT " ordering=\"out\";\n";
print DOT " center=\"1\";\n";
print DOT "node [shape=\"box\",\n";
print DOT " color=\"#000088\",\n";
print DOT " fillcolor=\"#FFFACD\",\n";
print DOT " fontcolor=\"#3355BB\",\n";
print DOT " fontname=\"sans\",\n";
print DOT " style=\"filled\",\n";
print DOT " fontsize=\"24\"\n";
print DOT "];\n";
print DOT "edge [dir=\"forward\",style=\"solid\",color=\"#000088\"];\n";
}
# Print objects second
foreach my $obj (@objs) {
gen_one_entry($obj);
}
if (!$FLAT) {
print DOT "}\n";
close DOT;
# Print end tag of definition list element
print "</dl>\n";
}

27
external/llvm/utils/GetRepositoryPath vendored Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
usage() {
echo "usage: $0 <source root>"
echo " Prints the source control repository path of the given source"
echo " directory, the exact format of the revision string depends on the"
echo " source control system. If the source control system isn't known,"
echo " the output is empty and the exit code is 1."
exit 1
}
if [ $# != 1 ] || [ ! -d $1 ]; then
usage;
fi
cd $1
if [ -d .svn ]; then
svn info | grep '^URL:' | cut -d: -f2-
elif [ -f .git/svn/.metadata ]; then
git svn info | grep 'URL:' | cut -d: -f2-
elif [ -d .git ]; then
git remote -v | grep 'fetch' | awk '{ print $2 }' | head -n1
else
exit 1;
fi
exit 0

27
external/llvm/utils/GetSourceVersion vendored Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
usage() {
echo "usage: $0 <source root>"
echo " Prints the source control revision of the given source directory,"
echo " the exact format of the revision string depends on the source "
echo " control system. If the source control system isn't known, the output"
echo " is empty and the exit code is 1."
exit 1
}
if [ $# != 1 ] || [ ! -d $1 ]; then
usage;
fi
cd $1
if [ -d .svn ]; then
svnversion | sed -e "s#\([0-9]*\)[A-Z]*#\1#"
elif [ -f .git/svn/.metadata ]; then
git svn info | grep 'Revision:' | cut -d: -f2-
elif [ -d .git ]; then
git log -1 --pretty=format:%H
else
exit 1;
fi
exit 0

View File

@@ -0,0 +1,8 @@
add_llvm_utility(KillTheDoctor
KillTheDoctor.cpp
)
target_link_libraries(KillTheDoctor
LLVMSupport
psapi
)

File diff suppressed because it is too large Load Diff

29
external/llvm/utils/LLVMBuild.txt vendored Normal file
View File

@@ -0,0 +1,29 @@
;===- ./utils/LLVMBuild.txt ------------------------------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[common]
subdirectories = TableGen unittest
[component_0]
type = Group
name = BuildTools
parent = $ROOT
[component_1]
type = Group
name = UtilityTools
parent = $ROOT

View File

@@ -0,0 +1,7 @@
# Do this by hand instead of using add_llvm_utilities(), which
# tries to create a corresponding executable, which we don't want.
if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION)
set(LLVM_VISUALIZERS llvm.natvis)
add_custom_target(LLVMVisualizers SOURCES ${LLVM_VISUALIZERS})
set_target_properties(LLVMVisualizers PROPERTIES FOLDER "Utils")
endif()

View File

@@ -0,0 +1,246 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Visual Studio Native Debugging Visualizers for LLVM
For Visual Studio 2013 only, put this file into
"%USERPROFILE%\Documents\Visual Studio 2013\Visualizers" or create a symbolic link so it updates automatically.
For later versions of Visual Studio, no setup is required.
-->
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<!-- VS2013 -->
<Type Name="llvm::SmallVectorImpl&lt;*&gt;" Priority="MediumLow">
<DisplayString Condition="(($T1*)EndX - ($T1*)BeginX) == 0">empty</DisplayString>
<DisplayString Condition="(($T1*)EndX - ($T1*)BeginX) != 0">{{ size={($T1*)EndX - ($T1*)BeginX} }}</DisplayString>
<Expand>
<Item Name="[size]">($T1*)EndX - ($T1*)BeginX</Item>
<Item Name="[capacity]">($T1*)CapacityX - ($T1*)BeginX</Item>
<ArrayItems>
<Size>($T1*)EndX - ($T1*)BeginX</Size>
<ValuePointer>($T1*)BeginX</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<!-- VS2015 and up -->
<Type Name="llvm::SmallVectorImpl&lt;*&gt;">
<DisplayString IncludeView ="elt0" Condition="(($T1*)EndX - ($T1*)BeginX) == 0"></DisplayString>
<DisplayString IncludeView ="elt0">{(($T1*)BeginX)[0]}{*this,view(elt1)}</DisplayString>
<DisplayString IncludeView ="elt1" Condition="(($T1*)EndX - ($T1*)BeginX) == 1"></DisplayString>
<DisplayString IncludeView ="elt1">, {(($T1*)BeginX)[1]}{*this,view(elt2)}</DisplayString>
<DisplayString IncludeView ="elt2" Condition="(($T1*)EndX - ($T1*)BeginX) == 2"></DisplayString>
<DisplayString IncludeView ="elt2">, {(($T1*)BeginX)[2]}{*this,view(elt3)}</DisplayString>
<DisplayString IncludeView ="elt3" Condition="(($T1*)EndX - ($T1*)BeginX) == 3"></DisplayString>
<DisplayString IncludeView ="elt3">, {(($T1*)BeginX)[2]}{*this,view(elt4)}</DisplayString>
<DisplayString IncludeView ="elt4" Condition="(($T1*)EndX - ($T1*)BeginX) == 4"></DisplayString>
<DisplayString IncludeView ="elt4">, /* {(($T1*)EndX - ($T1*)BeginX) - 4} more*/ </DisplayString>
<DisplayString Condition="(($T1*)EndX - ($T1*)BeginX) == 0">empty</DisplayString>
<DisplayString Condition="(($T1*)EndX - ($T1*)BeginX) != 0">{{{*this,view(elt0)}}}</DisplayString>
<Expand>
<Item Name="[size]">($T1*)EndX - ($T1*)BeginX</Item>
<Item Name="[capacity]">($T1*)CapacityX - ($T1*)BeginX</Item>
<ArrayItems>
<Size>($T1*)EndX - ($T1*)BeginX</Size>
<ValuePointer>($T1*)BeginX</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="llvm::ArrayRef&lt;*&gt;">
<DisplayString Condition="Length == 0">empty</DisplayString>
<DisplayString Condition="Length != 0">{{ size={Length} }}</DisplayString>
<Expand>
<Item Name="[size]">Length</Item>
<ArrayItems>
<Size>Length</Size>
<ValuePointer>Data</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="llvm::SmallString&lt;*&gt;">
<DisplayString>{(const char*)BeginX,[(char*)EndX - (char*)BeginX] na}</DisplayString>
<StringView>(const char*)BeginX,[(char*)EndX - (char*)BeginX]</StringView>
<Expand>
<Item Name="[size]">(char*)EndX - (char*)BeginX</Item>
<Item Name="[capacity]">(char*)CapacityX - (char*)BeginX</Item>
<ArrayItems>
<Size>(char*)EndX - (char*)BeginX</Size>
<ValuePointer>(char*)BeginX</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="llvm::StringRef">
<DisplayString>{Data,[Length]s}</DisplayString>
<StringView>Data,[Length]s</StringView>
<Expand>
<Item Name="[size]">Length</Item>
<ArrayItems>
<Size>Length</Size>
<ValuePointer>Data</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="llvm::PointerIntPair&lt;*,*,*,*&gt;">
<DisplayString>{IntMask}: {($T1)(Value &amp; PointerBitMask)} [{($T3)((Value &gt;&gt; IntShift) &amp; IntMask)}]</DisplayString>
<Expand>
<Item Name="[ptr]">($T1)(Value &amp; PointerBitMask)</Item>
<Item Name="[int]">($T3)((Value &gt;&gt; IntShift) &amp; IntMask)</Item>
</Expand>
</Type>
<Type Name="llvm::PointerUnion&lt;*,*&gt;">
<DisplayString Condition="((Val.Value &gt;&gt; Val.IntShift) &amp; Val.IntMask) == 0">{"$T1", s8b}: {($T1)(Val.Value &amp; Val.PointerBitMask)}</DisplayString>
<DisplayString Condition="((Val.Value &gt;&gt; Val.IntShift) &amp; Val.IntMask) != 0">{"$T2", s8b}: {($T2)(Val.Value &amp; Val.PointerBitMask)}</DisplayString>
<Expand>
<ExpandedItem Condition="((Val.Value &gt;&gt; Val.IntShift) &amp; Val.IntMask) == 0">($T1)(Val.Value &amp; Val.PointerBitMask)</ExpandedItem>
<ExpandedItem Condition="((Val.Value &gt;&gt; Val.IntShift) &amp; Val.IntMask) != 0">($T2)(Val.Value &amp; Val.PointerBitMask)</ExpandedItem>
</Expand>
</Type>
<Type Name="llvm::PointerUnion3&lt;*,*,*&gt;">
<DisplayString Condition="(Val.Val.Value &amp; 2) != 2 &amp;&amp; (Val.Val.Value &amp; 1) != 1">{"$T1", s8b}: {($T1)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>
<DisplayString Condition="(Val.Val.Value &amp; 2) == 2">{"$T2", s8b}: {($T2)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>
<DisplayString Condition="(Val.Val.Value &amp; 1) == 1">{"$T3", s8b}: {($T3)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>
<Expand>
<ExpandedItem Condition="(Val.Val.Value &amp; 2) != 2 &amp;&amp; (Val.Val.Value &amp; 1) != 1">($T1)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)</ExpandedItem>
<ExpandedItem Condition="(Val.Val.Value &amp; 2) == 2">($T2)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)</ExpandedItem>
<ExpandedItem Condition="(Val.Val.Value &amp; 1) == 1">($T3)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)</ExpandedItem>
</Expand>
</Type>
<Type Name="llvm::PointerUnion4&lt;*,*,*,*&gt;">
<DisplayString Condition="(Val.Val.Value &amp; 3) != 3 &amp;&amp; (Val.Val.Value &amp; 2) != 2 &amp;&amp; (Val.Val.Value &amp; 1) != 1">{"$T1", s8b}: {($T1)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>
<DisplayString Condition="(Val.Val.Value &amp; 3) != 3 &amp;&amp; (Val.Val.Value &amp; 2) == 2">{"$T2", s8b}: {($T2)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>
<DisplayString Condition="(Val.Val.Value &amp; 3) != 3 &amp;&amp; (Val.Val.Value &amp; 1) == 1">{"$T3", s8b}: {($T3)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>
<DisplayString Condition="(Val.Val.Value &amp; 3) == 3">{"$T4", s8b}: {($T4)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)}</DisplayString>
<Expand>
<ExpandedItem Condition="(Val.Val.Value &amp; 3) != 3 &amp;&amp; (Val.Val.Value &amp; 2) != 2 &amp;&amp; (Val.Val.Value &amp; 1) != 1">($T1)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)</ExpandedItem>
<ExpandedItem Condition="(Val.Val.Value &amp; 3) != 3 &amp;&amp; (Val.Val.Value &amp; 2) == 2">($T2)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)</ExpandedItem>
<ExpandedItem Condition="(Val.Val.Value &amp; 3) != 3 &amp;&amp; (Val.Val.Value &amp; 1) == 1">($T3)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)</ExpandedItem>
<ExpandedItem Condition="(Val.Val.Value &amp; 3) == 3">($T4)((Val.Val.Value &gt;&gt; 2) &lt;&lt; 2)</ExpandedItem>
</Expand>
</Type>
<Type Name="llvm::iplist&lt;*,*&gt;">
<DisplayString Condition="Head == 0">{{ empty }}</DisplayString>
<DisplayString Condition="Head != 0">{{ head={Head} }}</DisplayString>
<Expand>
<LinkedListItems>
<HeadPointer>Head</HeadPointer>
<NextPointer>Next</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="llvm::IntrusiveRefCntPtr&lt;*&gt;">
<DisplayString Condition="Obj == 0">empty</DisplayString>
<DisplayString Condition="(Obj != 0) &amp;&amp; (Obj-&gt;ref_cnt == 1)">RefPtr [1 ref] {*Obj}</DisplayString>
<DisplayString Condition="(Obj != 0) &amp;&amp; (Obj-&gt;ref_cnt != 1)">RefPtr [{Obj-&gt;ref_cnt} refs] {*Obj}</DisplayString>
<Expand>
<Item Condition="Obj != 0" Name="[refs]">Obj-&gt;ref_cnt</Item>
<ExpandedItem Condition="Obj != 0">Obj</ExpandedItem>
</Expand>
</Type>
<Type Name="llvm::SmallPtrSet&lt;*,*&gt;">
<DisplayString Condition="CurArray == SmallArray">{{ [Small Mode] size={NumElements}, capacity={CurArraySize} }}</DisplayString>
<DisplayString Condition="CurArray != SmallArray">{{ [Big Mode] size={NumElements}, capacity={CurArraySize} }}</DisplayString>
<Expand>
<Item Name="[size]">NumElements</Item>
<Item Name="[capacity]">CurArraySize</Item>
<ArrayItems>
<Size>CurArraySize</Size>
<ValuePointer>($T1*)CurArray</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="llvm::DenseMap&lt;*,*,*&gt;">
<DisplayString Condition="NumEntries == 0">empty</DisplayString>
<DisplayString Condition="NumEntries != 0">{{ size={NumEntries}, buckets={NumBuckets} }}</DisplayString>
<Expand>
<Item Name="[size]">NumEntries</Item>
<Item Name="[buckets]">NumBuckets</Item>
<ArrayItems>
<Size>NumBuckets</Size>
<ValuePointer>Buckets</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="llvm::StringMap&lt;*,*&gt;">
<DisplayString>{{ size={NumItems}, buckets={NumBuckets} }}</DisplayString>
<Expand>
<Item Name="[size]">NumItems</Item>
<Item Name="[buckets]">NumBuckets</Item>
<ArrayItems>
<Size>NumBuckets</Size>
<ValuePointer>(MapEntryTy**)TheTable</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="llvm::StringMapEntry&lt;*&gt;">
<DisplayString Condition="StrLen == 0">empty</DisplayString>
<DisplayString Condition="StrLen != 0">({this+1,s}, {second})</DisplayString>
<Expand>
<Item Name="[key]">this+1,s</Item>
<Item Name="[value]" Condition="StrLen != 0">second</Item>
</Expand>
</Type>
<Type Name="llvm::Triple">
<DisplayString>{Data}</DisplayString>
</Type>
<Type Name="llvm::Optional&lt;*&gt;">
<DisplayString Condition="!hasVal">empty</DisplayString>
<DisplayString Condition="hasVal">{*(($T1 *)(unsigned char *)storage.buffer)}</DisplayString>
<Expand>
<Item Name="[underlying]" Condition="hasVal">*(($T1 *)(unsigned char *)storage.buffer)</Item>
</Expand>
</Type>
<!-- Since we're in MSVC, we can assume that the system is little endian. Therefore
the little and native cases just require a cast. Handle this easy case first. Use
a wildcard for the second template argument (the endianness), but we will use a
specific value of 0 later on for the big endian to give it priority for being a
better match. -->
<Type Name="llvm::support::detail::packed_endian_specific_integral&lt;*,*,1&gt;">
<DisplayString>{{little endian value = {*(($T1*)(unsigned char *)Value.buffer)} }}</DisplayString>
<Expand>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==1">(unsigned char *)Value.buffer,1</Item>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==2">(unsigned char *)Value.buffer,2</Item>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==4">(unsigned char *)Value.buffer,4</Item>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==8">(unsigned char *)Value.buffer,8</Item>
</Expand>
</Type>
<!-- Now handle the hard case of big endian. We need to do the swizzling here, but
we need to specialize it based on the size of the value type. -->
<Type Name="llvm::support::detail::packed_endian_specific_integral&lt;*,0,1&gt;">
<DisplayString Condition="sizeof($T1)==1">{{ big endian value = {*(unsigned char *)Value.buffer} }}</DisplayString>
<DisplayString Condition="sizeof($T1)==2">{{ big endian value = {(($T1)(*(unsigned char *)Value.buffer) &lt;&lt; 8)
| ($T1)(*((unsigned char *)Value.buffer+1))} }}</DisplayString>
<DisplayString Condition="sizeof($T1)==4">{{ big endian value = {(($T1)(*(unsigned char *)Value.buffer) &lt;&lt; 24)
| (($T1)(*((unsigned char *)Value.buffer+1)) &lt;&lt; 16)
| (($T1)(*((unsigned char *)Value.buffer+2)) &lt;&lt; 8)
| ($T1)(*((unsigned char *)Value.buffer+3))} }}</DisplayString>
<DisplayString Condition="sizeof($T1)==8">{{ big endian value = {(($T1)(*(unsigned char *)Value.buffer) &lt;&lt; 56)
| (($T1)(*((unsigned char *)Value.buffer+1)) &lt;&lt; 48)
| (($T1)(*((unsigned char *)Value.buffer+2)) &lt;&lt; 40)
| (($T1)(*((unsigned char *)Value.buffer+3)) &lt;&lt; 32)
| (($T1)(*((unsigned char *)Value.buffer+4)) &lt;&lt; 24)
| (($T1)(*((unsigned char *)Value.buffer+5)) &lt;&lt; 16)
| (($T1)(*((unsigned char *)Value.buffer+6)) &lt;&lt; 8)
| ($T1)(*((unsigned char *)Value.buffer+7))} }}</DisplayString>
<Expand>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==1">(unsigned char *)Value.buffer,1</Item>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==2">(unsigned char *)Value.buffer,2</Item>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==4">(unsigned char *)Value.buffer,4</Item>
<Item Name="[Raw Bytes]" Condition="sizeof($T1)==8">(unsigned char *)Value.buffer,8</Item>
</Expand>
</Type>
</AutoVisualizer>

276
external/llvm/utils/Misc/zkill vendored Executable file
View File

@@ -0,0 +1,276 @@
#!/usr/bin/env python
import os
import re
import sys
def _write_message(kind, message):
import inspect, os, sys
# Get the file/line where this message was generated.
f = inspect.currentframe()
# Step out of _write_message, and then out of wrapper.
f = f.f_back.f_back
file,line,_,_,_ = inspect.getframeinfo(f)
location = '%s:%d' % (os.path.basename(file), line)
print >>sys.stderr, '%s: %s: %s' % (location, kind, message)
note = lambda message: _write_message('note', message)
warning = lambda message: _write_message('warning', message)
error = lambda message: (_write_message('error', message), sys.exit(1))
def re_full_match(pattern, str):
m = re.match(pattern, str)
if m and m.end() != len(str):
m = None
return m
def parse_time(value):
minutes,value = value.split(':',1)
if '.' in value:
seconds,fseconds = value.split('.',1)
else:
seconds = value
return int(minutes) * 60 + int(seconds) + float('.'+fseconds)
def extractExecutable(command):
"""extractExecutable - Given a string representing a command line, attempt
to extract the executable path, even if it includes spaces."""
# Split into potential arguments.
args = command.split(' ')
# Scanning from the beginning, try to see if the first N args, when joined,
# exist. If so that's probably the executable.
for i in range(1,len(args)):
cmd = ' '.join(args[:i])
if os.path.exists(cmd):
return cmd
# Otherwise give up and return the first "argument".
return args[0]
class Struct:
def __init__(self, **kwargs):
self.fields = kwargs.keys()
self.__dict__.update(kwargs)
def __repr__(self):
return 'Struct(%s)' % ', '.join(['%s=%r' % (k,getattr(self,k))
for k in self.fields])
kExpectedPSFields = [('PID', int, 'pid'),
('USER', str, 'user'),
('COMMAND', str, 'command'),
('%CPU', float, 'cpu_percent'),
('TIME', parse_time, 'cpu_time'),
('VSZ', int, 'vmem_size'),
('RSS', int, 'rss')]
def getProcessTable():
import subprocess
p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out,err = p.communicate()
res = p.wait()
if p.wait():
error('unable to get process table')
elif err.strip():
error('unable to get process table: %s' % err)
lns = out.split('\n')
it = iter(lns)
header = it.next().split()
numRows = len(header)
# Make sure we have the expected fields.
indexes = []
for field in kExpectedPSFields:
try:
indexes.append(header.index(field[0]))
except:
if opts.debug:
raise
error('unable to get process table, no %r field.' % field[0])
table = []
for i,ln in enumerate(it):
if not ln.strip():
continue
fields = ln.split(None, numRows - 1)
if len(fields) != numRows:
warning('unable to process row: %r' % ln)
continue
record = {}
for field,idx in zip(kExpectedPSFields, indexes):
value = fields[idx]
try:
record[field[2]] = field[1](value)
except:
if opts.debug:
raise
warning('unable to process %r in row: %r' % (field[0], ln))
break
else:
# Add our best guess at the executable.
record['executable'] = extractExecutable(record['command'])
table.append(Struct(**record))
return table
def getSignalValue(name):
import signal
if name.startswith('SIG'):
value = getattr(signal, name)
if value and isinstance(value, int):
return value
error('unknown signal: %r' % name)
import signal
kSignals = {}
for name in dir(signal):
if name.startswith('SIG') and name == name.upper() and name.isalpha():
kSignals[name[3:]] = getattr(signal, name)
def main():
global opts
from optparse import OptionParser, OptionGroup
parser = OptionParser("usage: %prog [options] {pid}*")
# FIXME: Add -NNN and -SIGNAME options.
parser.add_option("-s", "", dest="signalName",
help="Name of the signal to use (default=%default)",
action="store", default='INT',
choices=kSignals.keys())
parser.add_option("-l", "", dest="listSignals",
help="List known signal names",
action="store_true", default=False)
parser.add_option("-n", "--dry-run", dest="dryRun",
help="Only print the actions that would be taken",
action="store_true", default=False)
parser.add_option("-v", "--verbose", dest="verbose",
help="Print more verbose output",
action="store_true", default=False)
parser.add_option("", "--debug", dest="debug",
help="Enable debugging output",
action="store_true", default=False)
parser.add_option("", "--force", dest="force",
help="Perform the specified commands, even if it seems like a bad idea",
action="store_true", default=False)
inf = float('inf')
group = OptionGroup(parser, "Process Filters")
group.add_option("", "--name", dest="execName", metavar="REGEX",
help="Kill processes whose name matches the given regexp",
action="store", default=None)
group.add_option("", "--exec", dest="execPath", metavar="REGEX",
help="Kill processes whose executable matches the given regexp",
action="store", default=None)
group.add_option("", "--user", dest="userName", metavar="REGEX",
help="Kill processes whose user matches the given regexp",
action="store", default=None)
group.add_option("", "--min-cpu", dest="minCPU", metavar="PCT",
help="Kill processes with CPU usage >= PCT",
action="store", type=float, default=None)
group.add_option("", "--max-cpu", dest="maxCPU", metavar="PCT",
help="Kill processes with CPU usage <= PCT",
action="store", type=float, default=inf)
group.add_option("", "--min-mem", dest="minMem", metavar="N",
help="Kill processes with virtual size >= N (MB)",
action="store", type=float, default=None)
group.add_option("", "--max-mem", dest="maxMem", metavar="N",
help="Kill processes with virtual size <= N (MB)",
action="store", type=float, default=inf)
group.add_option("", "--min-rss", dest="minRSS", metavar="N",
help="Kill processes with RSS >= N",
action="store", type=float, default=None)
group.add_option("", "--max-rss", dest="maxRSS", metavar="N",
help="Kill processes with RSS <= N",
action="store", type=float, default=inf)
group.add_option("", "--min-time", dest="minTime", metavar="N",
help="Kill processes with CPU time >= N (seconds)",
action="store", type=float, default=None)
group.add_option("", "--max-time", dest="maxTime", metavar="N",
help="Kill processes with CPU time <= N (seconds)",
action="store", type=float, default=inf)
parser.add_option_group(group)
(opts, args) = parser.parse_args()
if opts.listSignals:
items = [(v,k) for k,v in kSignals.items()]
items.sort()
for i in range(0, len(items), 4):
print '\t'.join(['%2d) SIG%s' % (k,v)
for k,v in items[i:i+4]])
sys.exit(0)
# Figure out the signal to use.
signal = kSignals[opts.signalName]
signalValueName = str(signal)
if opts.verbose:
name = dict((v,k) for k,v in kSignals.items()).get(signal,None)
if name:
signalValueName = name
note('using signal %d (SIG%s)' % (signal, name))
else:
note('using signal %d' % signal)
# Get the pid list to consider.
pids = set()
for arg in args:
try:
pids.add(int(arg))
except:
parser.error('invalid positional argument: %r' % arg)
filtered = ps = getProcessTable()
# Apply filters.
if pids:
filtered = [p for p in filtered
if p.pid in pids]
if opts.execName is not None:
filtered = [p for p in filtered
if re_full_match(opts.execName,
os.path.basename(p.executable))]
if opts.execPath is not None:
filtered = [p for p in filtered
if re_full_match(opts.execPath, p.executable)]
if opts.userName is not None:
filtered = [p for p in filtered
if re_full_match(opts.userName, p.user)]
filtered = [p for p in filtered
if opts.minCPU <= p.cpu_percent <= opts.maxCPU]
filtered = [p for p in filtered
if opts.minMem <= float(p.vmem_size) / (1<<20) <= opts.maxMem]
filtered = [p for p in filtered
if opts.minRSS <= p.rss <= opts.maxRSS]
filtered = [p for p in filtered
if opts.minTime <= p.cpu_time <= opts.maxTime]
if len(filtered) == len(ps):
if not opts.force and not opts.dryRun:
error('refusing to kill all processes without --force')
if not filtered:
warning('no processes selected')
for p in filtered:
if opts.verbose:
note('kill(%r, %s) # (user=%r, executable=%r, CPU=%2.2f%%, time=%r, vmem=%r, rss=%r)' %
(p.pid, signalValueName, p.user, p.executable, p.cpu_percent, p.cpu_time, p.vmem_size, p.rss))
if not opts.dryRun:
try:
os.kill(p.pid, signal)
except OSError:
if opts.debug:
raise
warning('unable to kill PID: %r' % p.pid)
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,3 @@
add_llvm_utility(llvm-PerfectShuffle
PerfectShuffle.cpp
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
f2d304bfcf5b76c4e27073b71197a6abbedde6e8

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,197 @@
//===- AsmWriterInst.h - Classes encapsulating a printable inst -----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// These classes implement a parser for assembly strings.
//
//===----------------------------------------------------------------------===//
#include "AsmWriterInst.h"
#include "CodeGenTarget.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
using namespace llvm;
static bool isIdentChar(char C) {
return (C >= 'a' && C <= 'z') ||
(C >= 'A' && C <= 'Z') ||
(C >= '0' && C <= '9') ||
C == '_';
}
std::string AsmWriterOperand::getCode(bool PassSubtarget) const {
if (OperandType == isLiteralTextOperand) {
if (Str.size() == 1)
return "O << '" + Str + "';";
return "O << \"" + Str + "\";";
}
if (OperandType == isLiteralStatementOperand)
return Str;
std::string Result = Str + "(MI";
if (MIOpNo != ~0U)
Result += ", " + utostr(MIOpNo);
if (PassSubtarget)
Result += ", STI";
Result += ", O";
if (!MiModifier.empty())
Result += ", \"" + MiModifier + '"';
return Result + ");";
}
/// ParseAsmString - Parse the specified Instruction's AsmString into this
/// AsmWriterInst.
///
AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
unsigned Variant)
: CGI(&CGI), CGIIndex(CGIIndex) {
// NOTE: Any extensions to this code need to be mirrored in the
// AsmPrinter::printInlineAsm code that executes as compile time (assuming
// that inline asm strings should also get the new feature)!
std::string AsmString = CGI.FlattenAsmStringVariants(CGI.AsmString, Variant);
std::string::size_type LastEmitted = 0;
while (LastEmitted != AsmString.size()) {
std::string::size_type DollarPos =
AsmString.find_first_of("$\\", LastEmitted);
if (DollarPos == std::string::npos) DollarPos = AsmString.size();
// Emit a constant string fragment.
if (DollarPos != LastEmitted) {
for (; LastEmitted != DollarPos; ++LastEmitted)
switch (AsmString[LastEmitted]) {
case '\n':
AddLiteralString("\\n");
break;
case '\t':
AddLiteralString("\\t");
break;
case '"':
AddLiteralString("\\\"");
break;
case '\\':
AddLiteralString("\\\\");
break;
default:
AddLiteralString(std::string(1, AsmString[LastEmitted]));
break;
}
} else if (AsmString[DollarPos] == '\\') {
if (DollarPos+1 != AsmString.size()) {
if (AsmString[DollarPos+1] == 'n') {
AddLiteralString("\\n");
} else if (AsmString[DollarPos+1] == 't') {
AddLiteralString("\\t");
} else if (std::string("${|}\\").find(AsmString[DollarPos+1])
!= std::string::npos) {
AddLiteralString(std::string(1, AsmString[DollarPos+1]));
} else {
PrintFatalError("Non-supported escaped character found in instruction '" +
CGI.TheDef->getName() + "'!");
}
LastEmitted = DollarPos+2;
continue;
}
} else if (DollarPos+1 != AsmString.size() &&
AsmString[DollarPos+1] == '$') {
AddLiteralString("$"); // "$$" -> $
LastEmitted = DollarPos+2;
} else {
// Get the name of the variable.
std::string::size_type VarEnd = DollarPos+1;
// handle ${foo}bar as $foo by detecting whether the character following
// the dollar sign is a curly brace. If so, advance VarEnd and DollarPos
// so the variable name does not contain the leading curly brace.
bool hasCurlyBraces = false;
if (VarEnd < AsmString.size() && '{' == AsmString[VarEnd]) {
hasCurlyBraces = true;
++DollarPos;
++VarEnd;
}
while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
++VarEnd;
StringRef VarName(AsmString.data()+DollarPos+1, VarEnd-DollarPos-1);
// Modifier - Support ${foo:modifier} syntax, where "modifier" is passed
// into printOperand. Also support ${:feature}, which is passed into
// PrintSpecial.
std::string Modifier;
// In order to avoid starting the next string at the terminating curly
// brace, advance the end position past it if we found an opening curly
// brace.
if (hasCurlyBraces) {
if (VarEnd >= AsmString.size())
PrintFatalError("Reached end of string before terminating curly brace in '"
+ CGI.TheDef->getName() + "'");
// Look for a modifier string.
if (AsmString[VarEnd] == ':') {
++VarEnd;
if (VarEnd >= AsmString.size())
PrintFatalError("Reached end of string before terminating curly brace in '"
+ CGI.TheDef->getName() + "'");
std::string::size_type ModifierStart = VarEnd;
while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
++VarEnd;
Modifier = std::string(AsmString.begin()+ModifierStart,
AsmString.begin()+VarEnd);
if (Modifier.empty())
PrintFatalError("Bad operand modifier name in '"+ CGI.TheDef->getName() + "'");
}
if (AsmString[VarEnd] != '}')
PrintFatalError("Variable name beginning with '{' did not end with '}' in '"
+ CGI.TheDef->getName() + "'");
++VarEnd;
}
if (VarName.empty() && Modifier.empty())
PrintFatalError("Stray '$' in '" + CGI.TheDef->getName() +
"' asm string, maybe you want $$?");
if (VarName.empty()) {
// Just a modifier, pass this into PrintSpecial.
Operands.emplace_back("PrintSpecial", ~0U, Modifier);
} else {
// Otherwise, normal operand.
unsigned OpNo = CGI.Operands.getOperandNamed(VarName);
CGIOperandList::OperandInfo OpInfo = CGI.Operands[OpNo];
unsigned MIOp = OpInfo.MIOperandNo;
Operands.emplace_back(OpInfo.PrinterMethodName, MIOp, Modifier);
}
LastEmitted = VarEnd;
}
}
Operands.emplace_back("return;", AsmWriterOperand::isLiteralStatementOperand);
}
/// MatchesAllButOneOp - If this instruction is exactly identical to the
/// specified instruction except for one differing operand, return the differing
/// operand number. If more than one operand mismatches, return ~1, otherwise
/// if the instructions are identical return ~0.
unsigned AsmWriterInst::MatchesAllButOneOp(const AsmWriterInst &Other)const{
if (Operands.size() != Other.Operands.size()) return ~1;
unsigned MismatchOperand = ~0U;
for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
if (Operands[i] != Other.Operands[i]) {
if (MismatchOperand != ~0U) // Already have one mismatch?
return ~1U;
MismatchOperand = i;
}
}
return MismatchOperand;
}

View File

@@ -0,0 +1,106 @@
//===- AsmWriterInst.h - Classes encapsulating a printable inst -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// These classes implement a parser for assembly strings. The parser splits
// the string into operands, which can be literal strings (the constant bits of
// the string), actual operands (i.e., operands from the MachineInstr), and
// dynamically-generated text, specified by raw C++ code.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
#define LLVM_UTILS_TABLEGEN_ASMWRITERINST_H
#include <string>
#include <vector>
namespace llvm {
class CodeGenInstruction;
class Record;
struct AsmWriterOperand {
enum OpType {
// Output this text surrounded by quotes to the asm.
isLiteralTextOperand,
// This is the name of a routine to call to print the operand.
isMachineInstrOperand,
// Output this text verbatim to the asm writer. It is code that
// will output some text to the asm.
isLiteralStatementOperand
} OperandType;
/// MiOpNo - For isMachineInstrOperand, this is the operand number of the
/// machine instruction.
unsigned MIOpNo;
/// Str - For isLiteralTextOperand, this IS the literal text. For
/// isMachineInstrOperand, this is the PrinterMethodName for the operand..
/// For isLiteralStatementOperand, this is the code to insert verbatim
/// into the asm writer.
std::string Str;
/// MiModifier - For isMachineInstrOperand, this is the modifier string for
/// an operand, specified with syntax like ${opname:modifier}.
std::string MiModifier;
// To make VS STL happy
AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {}
AsmWriterOperand(const std::string &LitStr,
OpType op = isLiteralTextOperand)
: OperandType(op), Str(LitStr) {}
AsmWriterOperand(const std::string &Printer,
unsigned _MIOpNo,
const std::string &Modifier,
OpType op = isMachineInstrOperand)
: OperandType(op), MIOpNo(_MIOpNo), Str(Printer), MiModifier(Modifier) {}
bool operator!=(const AsmWriterOperand &Other) const {
if (OperandType != Other.OperandType || Str != Other.Str) return true;
if (OperandType == isMachineInstrOperand)
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
return false;
}
bool operator==(const AsmWriterOperand &Other) const {
return !operator!=(Other);
}
/// getCode - Return the code that prints this operand.
std::string getCode(bool PassSubtarget) const;
};
class AsmWriterInst {
public:
std::vector<AsmWriterOperand> Operands;
const CodeGenInstruction *CGI;
unsigned CGIIndex;
AsmWriterInst(const CodeGenInstruction &CGI, unsigned CGIIndex,
unsigned Variant);
/// MatchesAllButOneOp - If this instruction is exactly identical to the
/// specified instruction except for one differing operand, return the
/// differing operand number. Otherwise return ~0.
unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
private:
void AddLiteralString(const std::string &Str) {
// If the last operand was already a literal text string, append this to
// it, otherwise add a new operand.
if (!Operands.empty() &&
Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
Operands.back().Str.append(Str);
else
Operands.push_back(AsmWriterOperand(Str));
}
};
}
#endif

View File

@@ -0,0 +1,177 @@
//===- Attributes.cpp - Generate attributes -------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/TableGen/Record.h"
#include <algorithm>
#include <string>
#include <vector>
using namespace llvm;
#define DEBUG_TYPE "attr-enum"
namespace {
class Attributes {
public:
Attributes(RecordKeeper &R) : Records(R) {}
void emit(raw_ostream &OS);
private:
void emitTargetIndependentEnums(raw_ostream &OS);
void emitConversionFn(raw_ostream &OS);
void emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr);
void printEnumAttrClasses(raw_ostream &OS,
const std::vector<Record *> &Records);
void printStrBoolAttrClasses(raw_ostream &OS,
const std::vector<Record *> &Records);
RecordKeeper &Records;
};
} // End anonymous namespace.
void Attributes::emitTargetIndependentEnums(raw_ostream &OS) {
OS << "#ifdef GET_ATTR_ENUM\n";
OS << "#undef GET_ATTR_ENUM\n";
std::vector<Record*> Attrs =
Records.getAllDerivedDefinitions("EnumAttr");
for (auto A : Attrs)
OS << A->getName() << ",\n";
OS << "#endif\n";
}
void Attributes::emitConversionFn(raw_ostream &OS) {
OS << "#ifdef GET_ATTR_KIND_FROM_NAME\n";
OS << "#undef GET_ATTR_KIND_FROM_NAME\n";
std::vector<Record*> Attrs =
Records.getAllDerivedDefinitions("EnumAttr");
OS << "static Attribute::AttrKind getAttrKindFromName(StringRef AttrName) {\n";
OS << " return StringSwitch<Attribute::AttrKind>(AttrName)\n";
for (auto A : Attrs) {
OS << " .Case(\"" << A->getValueAsString("AttrString");
OS << "\", Attribute::" << A->getName() << ")\n";
}
OS << " .Default(Attribute::None);\n";
OS << "}\n\n";
OS << "#endif\n";
}
void Attributes::emitFnAttrCompatCheck(raw_ostream &OS, bool IsStringAttr) {
OS << "#ifdef GET_ATTR_COMPAT_FUNC\n";
OS << "#undef GET_ATTR_COMPAT_FUNC\n";
OS << "struct EnumAttr {\n";
OS << " static bool isSet(const Function &Fn,\n";
OS << " Attribute::AttrKind Kind) {\n";
OS << " return Fn.hasFnAttribute(Kind);\n";
OS << " }\n\n";
OS << " static void set(Function &Fn,\n";
OS << " Attribute::AttrKind Kind, bool Val) {\n";
OS << " if (Val)\n";
OS << " Fn.addFnAttr(Kind);\n";
OS << " else\n";
OS << " Fn.removeFnAttr(Kind);\n";
OS << " }\n";
OS << "};\n\n";
OS << "struct StrBoolAttr {\n";
OS << " static bool isSet(const Function &Fn,\n";
OS << " StringRef Kind) {\n";
OS << " auto A = Fn.getFnAttribute(Kind);\n";
OS << " return A.getValueAsString().equals(\"true\");\n";
OS << " }\n\n";
OS << " static void set(Function &Fn,\n";
OS << " StringRef Kind, bool Val) {\n";
OS << " Fn.addFnAttr(Kind, Val ? \"true\" : \"false\");\n";
OS << " }\n";
OS << "};\n\n";
printEnumAttrClasses(OS ,Records.getAllDerivedDefinitions("EnumAttr"));
printStrBoolAttrClasses(OS , Records.getAllDerivedDefinitions("StrBoolAttr"));
OS << "static inline bool hasCompatibleFnAttrs(const Function &Caller,\n"
<< " const Function &Callee) {\n";
OS << " bool Ret = true;\n\n";
std::vector<Record *> CompatRules =
Records.getAllDerivedDefinitions("CompatRule");
for (auto *Rule : CompatRules) {
StringRef FuncName = Rule->getValueAsString("CompatFunc");
OS << " Ret &= " << FuncName << "(Caller, Callee);\n";
}
OS << "\n";
OS << " return Ret;\n";
OS << "}\n\n";
std::vector<Record *> MergeRules =
Records.getAllDerivedDefinitions("MergeRule");
OS << "static inline void mergeFnAttrs(Function &Caller,\n"
<< " const Function &Callee) {\n";
for (auto *Rule : MergeRules) {
StringRef FuncName = Rule->getValueAsString("MergeFunc");
OS << " " << FuncName << "(Caller, Callee);\n";
}
OS << "}\n\n";
OS << "#endif\n";
}
void Attributes::printEnumAttrClasses(raw_ostream &OS,
const std::vector<Record *> &Records) {
OS << "// EnumAttr classes\n";
for (const auto *R : Records) {
OS << "struct " << R->getName() << "Attr : EnumAttr {\n";
OS << " static enum Attribute::AttrKind getKind() {\n";
OS << " return llvm::Attribute::" << R->getName() << ";\n";
OS << " }\n";
OS << "};\n";
}
OS << "\n";
}
void Attributes::printStrBoolAttrClasses(raw_ostream &OS,
const std::vector<Record *> &Records) {
OS << "// StrBoolAttr classes\n";
for (const auto *R : Records) {
OS << "struct " << R->getName() << "Attr : StrBoolAttr {\n";
OS << " static StringRef getKind() {\n";
OS << " return \"" << R->getValueAsString("AttrString") << "\";\n";
OS << " }\n";
OS << "};\n";
}
OS << "\n";
}
void Attributes::emit(raw_ostream &OS) {
emitTargetIndependentEnums(OS);
emitConversionFn(OS);
emitFnAttrCompatCheck(OS, false);
}
namespace llvm {
void EmitAttributes(RecordKeeper &RK, raw_ostream &OS) {
Attributes(RK).emit(OS);
}
} // End llvm namespace.

Some files were not shown because too many files have changed in this diff Show More