[Python-checkins] r81093 - in python/branches/py3k-jit: Lib/sysconfig.py Makefile.pre.in Misc/python-config.in Unittests/PySmallPtrSetTest.cc Unittests/StatsTest.cc Util Util/PySmallPtrSet.cc Util/PySmallPtrSet.h Util/Stats.cc Util/Stats.h configure configure.in pyconfig.h.in
collin.winter
python-checkins at python.org
Wed May 12 00:32:18 CEST 2010
Author: collin.winter
Date: Wed May 12 00:32:18 2010
New Revision: 81093
Log:
Hook LLVM into the py3k-jit branch's build process; add utility code and
tests to verify that LLVM is working correctly. This currently builds
statically against LLVM; this will be addressed in a follow-up commit.
Reviewed at http://codereview.appspot.com/917043.
Added:
python/branches/py3k-jit/Unittests/PySmallPtrSetTest.cc
python/branches/py3k-jit/Unittests/StatsTest.cc
python/branches/py3k-jit/Util/
python/branches/py3k-jit/Util/PySmallPtrSet.cc
python/branches/py3k-jit/Util/PySmallPtrSet.h
python/branches/py3k-jit/Util/Stats.cc
python/branches/py3k-jit/Util/Stats.h
Modified:
python/branches/py3k-jit/ (props changed)
python/branches/py3k-jit/Lib/sysconfig.py
python/branches/py3k-jit/Makefile.pre.in
python/branches/py3k-jit/Misc/python-config.in
python/branches/py3k-jit/configure
python/branches/py3k-jit/configure.in
python/branches/py3k-jit/pyconfig.h.in
Modified: python/branches/py3k-jit/Lib/sysconfig.py
==============================================================================
--- python/branches/py3k-jit/Lib/sysconfig.py (original)
+++ python/branches/py3k-jit/Lib/sysconfig.py Wed May 12 00:32:18 2010
@@ -266,26 +266,52 @@
return os.path.join(get_path('stdlib'), "config", "Makefile")
-def _init_posix(vars):
- """Initialize the module as appropriate for POSIX systems."""
- # load the installed Makefile:
- makefile = _get_makefile_filename()
- try:
- _parse_makefile(makefile, vars)
- except IOError as e:
- msg = "invalid Python installation: unable to open %s" % makefile
- if hasattr(e, "strerror"):
- msg = msg + " (%s)" % e.strerror
- raise IOError(msg)
- # load the installed pyconfig.h:
- config_h = get_config_h_filename()
+def _get_sysconfig_filename():
+ """Return absolute pathname of the installed sysconfig file."""
+ if _PYTHON_BUILD:
+ return os.path.join(_PROJECT_BASE, "sysconfig")
+ return os.path.join(get_path("stdlib"), "config", "sysconfig")
+
+
+# Simple wrapper around parse_config_h() to simplify _parse_config_file().
+def _parse_config_h_filename(filename, g=None):
+ with open(filename) as fp:
+ return parse_config_h(fp, g)
+
+
+def _parse_config_file(filename, parse_func, config_dict):
+ """Parse a config file into a common dict.
+
+ Args:
+ filename: name of the config file.
+ parse_func: function to use to parse the file. This will be given
+ `filename` and `config_dict` as arguments, and should update
+ `config_dict` in-place.
+ config_dict: dictionary to update in-place.
+
+ Raises:
+ IOError: if the file could not be opened.
+ """
try:
- parse_config_h(open(config_h), vars)
+ parse_func(filename, config_dict)
except IOError as e:
- msg = "invalid Python installation: unable to open %s" % config_h
+ msg = "invalid Python installation: unable to open %s" % filename
if hasattr(e, "strerror"):
msg = msg + " (%s)" % e.strerror
raise IOError(msg)
+
+
+def _init_posix(vars):
+ """Initialize the module as appropriate for POSIX systems."""
+ # Load the installed Makefile.
+ _parse_config_file(_get_makefile_filename(), _parse_makefile, vars)
+
+ # Load the installed pyconfig.h.
+ _parse_config_file(get_config_h_filename(), _parse_config_h_filename, vars)
+
+ # Load the installed sysconfig file.
+ _parse_config_file(_get_sysconfig_filename(), _parse_makefile, vars)
+
# On MacOSX we need to check the setting of the environment variable
# MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
# it needs to be compatible.
Modified: python/branches/py3k-jit/Makefile.pre.in
==============================================================================
--- python/branches/py3k-jit/Makefile.pre.in (original)
+++ python/branches/py3k-jit/Makefile.pre.in Wed May 12 00:32:18 2010
@@ -35,6 +35,7 @@
AR= @AR@
RANLIB= @RANLIB@
SVNVERSION= @SVNVERSION@
+FORCE_C= @FORCE_C@
GNULD= @GNULD@
@@ -60,10 +61,11 @@
OPT= @OPT@
BASECFLAGS= @BASECFLAGS@
CFLAGS= $(BASECFLAGS) @CFLAGS@ $(OPT) $(EXTRA_CFLAGS)
+CXXFLAGS= $(BASECXXFLAGS) $(OPT) $(EXTRA_CXXFLAGS)
# Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
# be able to build extension modules using the directories specified in the
# environment variables
-CPPFLAGS= -I. -IInclude -I$(srcdir)/Include @CPPFLAGS@
+CPPFLAGS= -I. -IInclude -I$(srcdir) -I$(srcdir)/Include @CPPFLAGS@
LDFLAGS= @LDFLAGS@
LDLAST= @LDLAST@
SGI_ABI= @SGI_ABI@
@@ -74,6 +76,16 @@
CFLAGSFORSHARED=@CFLAGSFORSHARED@
# C flags used for building the interpreter object files
PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
+PY_CXXFLAGS= $(CXXFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE -Wno-write-strings
+
+# LLVM integration options
+WITH_LLVM= @WITH_LLVM@
+LLVM_CONFIG= @LLVM_CONFIG@
+LLVM_INC_DIR= @LLVM_INC_DIR@
+LLVM_BIN_DIR= @LLVM_BIN_DIR@
+LLVM_CXXFLAGS= @LLVM_CXXFLAGS@
+LLVM_LDFLAGS= @LLVM_LDFLAGS@
+LLVM_LIB_PATHS= @LLVM_LIB_PATHS@
# Machine-dependent subdirectories
@@ -322,6 +334,12 @@
$(MACHDEP_OBJS) \
$(THREADOBJ)
+# configure will do a LLVM_PYTHON_OBJS substitution that will expand
+# to one of these. This convolution is done to support BSD make.
+EMPTY=
+LLVM_PYTHON_OBJS= \
+ Util/PySmallPtrSet.o \
+ Util/Stats.o
##########################################################################
# Objects
@@ -371,6 +389,7 @@
$(PARSER_OBJS) \
$(OBJECT_OBJS) \
$(PYTHON_OBJS) \
+ $(@LLVM_PYTHON_OBJS@) \
$(MODULE_OBJS) \
$(SIGNAL_OBJS) \
$(MODOBJS)
@@ -408,12 +427,16 @@
$(MAKE) clean
$(MAKE) all CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov"
+sysconfig:
+ @case $(WITH_LLVM) in \
+ 1) ( echo "LLVM_CXXFLAGS=$(LLVM_CXXFLAGS)"; echo "LLVM_LDFLAGS=$(LLVM_LDFLAGS)" ) > sysconfig;; \
+ 0) touch sysconfig;; \
+ esac
# Build the interpreter
-$(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)
- $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \
- Modules/python.o \
- $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
+$(BUILDPYTHON): sysconfig Modules/python.o $(LIBRARY) $(LDLIBRARY)
+ $(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ Modules/python.o \
+ $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LLVM_LDFLAGS) $(LDLAST)
platform: $(BUILDPYTHON)
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
@@ -433,25 +456,25 @@
$(AR) $(ARFLAGS) $@ Modules/getbuildinfo.o
$(AR) $(ARFLAGS) $@ $(PARSER_OBJS)
$(AR) $(ARFLAGS) $@ $(OBJECT_OBJS)
- $(AR) $(ARFLAGS) $@ $(PYTHON_OBJS)
+ $(AR) $(ARFLAGS) $@ $(PYTHON_OBJS) $(@LLVM_PYTHON_OBJS@)
$(AR) $(ARFLAGS) $@ $(MODULE_OBJS) $(SIGNAL_OBJS)
$(AR) $(ARFLAGS) $@ $(MODOBJS)
$(RANLIB) $@
libpython$(VERSION).so: $(LIBRARY_OBJS)
if test $(INSTSONAME) != $(LDLIBRARY); then \
- $(LDSHARED) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+ $(LDSHARED) $(LLVM_LDFLAGS) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
$(LN) -f $(INSTSONAME) $@; \
else \
- $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+ $(LDSHARED) $(LLVM_LDFLAGS) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
fi
libpython$(VERSION).dylib: $(LIBRARY_OBJS)
- $(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+ $(CC) -dynamiclib -Wl,-single_module $(LLVM_LDFLAGS) $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
libpython$(VERSION).sl: $(LIBRARY_OBJS)
- $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
+ $(LDSHARED) $(LLVM_LDFLAGS) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
# Copy up the gdb python hooks into a position where they can be automatically
# loaded by gdb during Lib/test/test_gdb.py
@@ -497,7 +520,7 @@
# for a shared core library; otherwise, this rule is a noop.
$(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS)
if test -n "$(DLLLIBRARY)"; then \
- $(LDSHARED) $(LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
+ $(LDSHARED) $(LLVM_LDFLAGS) $(LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
$(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \
else true; \
fi
@@ -537,6 +560,7 @@
Modules/getbuildinfo.o: $(PARSER_OBJS) \
$(OBJECT_OBJS) \
$(PYTHON_OBJS) \
+ $(@LLVM_PYTHON_OBJS@) \
$(MODULE_OBJS) \
$(SIGNAL_OBJS) \
$(MODOBJS) \
@@ -717,6 +741,10 @@
# even without a C++ compiler. All commands are prefixed with - to make this
# happen.
+LLVM_UNITTEST_SRCS := \
+ $(srcdir)/Unittests/PySmallPtrSetTest.cc \
+ $(srcdir)/Unittests/StatsTest.cc
+
UNITTEST_SRCS := $(LIBRARY) \
$(srcdir)/Unittests/DatetimeTest.cc \
$(srcdir)/Unittests/DictTest.cc \
@@ -725,7 +753,8 @@
$(srcdir)/Unittests/ObjectTest.cc \
$(srcdir)/Unittests/UnicodeTest.cc \
$(srcdir)/Unittests/pytest_main.cc \
- Unittests/googletest/gtest.o
+ $(@LLVM_UNITTEST_SRCS@) \
+ Unittests/googletest/gtest.o \
Unittests/googletest/gtest.o:
-$(CXX) -c $(PY_CXXFLAGS) -I$(srcdir)/Unittests/googletest \
@@ -733,9 +762,13 @@
$(srcdir)/Unittests/googletest/src/gtest-all.cc
# The python-config line needs to come last, or this will be broken on Linux.
+#
+# gcc's TR1 <tuple> header depends on RTTI, so force googletest to use
+# its own tuple implementation.
AllUnitTests: $(UNITTEST_SRCS) $(srcdir)/Unittests/*.h build_all python-config
-$(CXX) $(CPPFLAGS) -I$(srcdir)/Unittests/googletest/include -o $@ \
$(UNITTEST_SRCS) -L. $(LDFLAGS) \
+ -DGTEST_HAS_RTTI=0 -DGTEST_HAS_TR1_TUPLE=0 \
`$(RUNSHARED) ./$(BUILDPYTHON) ./python-config --cflags --ldflags`
@@ -1162,6 +1195,9 @@
.c.o:
$(CC) -c $(PY_CFLAGS) -o $@ $<
+.cc.o:
+ $(CXX) -c $(LLVM_CXXFLAGS) $(PY_CXXFLAGS) -o $@ $<
+
# Run reindent on the library
reindent:
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
@@ -1213,6 +1249,7 @@
find . -name '*.s[ol]' -exec rm -f {} ';'
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
find build -name 'fficonfig.py' -exec rm -f {} ';' || true
+ rm -f sysconfig
-rm -f Lib/lib2to3/*Grammar*.pickle
profile-removal:
Modified: python/branches/py3k-jit/Misc/python-config.in
==============================================================================
--- python/branches/py3k-jit/Misc/python-config.in (original)
+++ python/branches/py3k-jit/Misc/python-config.in Wed May 12 00:32:18 2010
@@ -41,6 +41,7 @@
'-I' + sysconfig.get_path('platinclude')]
if opt == '--cflags':
flags.extend(getvar('CFLAGS').split())
+ flags.extend(getvar('LLVM_CXXFLAGS').split())
print(' '.join(flags))
elif opt in ('--libs', '--ldflags'):
@@ -51,6 +52,7 @@
if opt == '--ldflags':
if not getvar('Py_ENABLE_SHARED'):
libs.insert(0, '-L' + getvar('LIBPL'))
+ libs.extend(getvar('LLVM_LDFLAGS').split())
libs.extend(getvar('LINKFORSHARED').split())
print(' '.join(libs))
Added: python/branches/py3k-jit/Unittests/PySmallPtrSetTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/PySmallPtrSetTest.cc Wed May 12 00:32:18 2010
@@ -0,0 +1,58 @@
+#include "Util/PySmallPtrSet.h"
+#include "gtest/gtest.h"
+
+
+TEST(PySmallPtrSet, Basic)
+{
+ PySmallPtrSet *set = PySmallPtrSet_New();
+ ASSERT_TRUE(set != NULL);
+ EXPECT_EQ(0u, PySmallPtrSet_Size(set));
+
+ PyObject *five = (PyObject *)5;
+ PyObject *six = (PyObject *)6;
+ EXPECT_EQ(1, PySmallPtrSet_Insert(set, five));
+ EXPECT_EQ(1u, PySmallPtrSet_Size(set));
+
+ // Insert additional element; size goes up.
+ EXPECT_EQ(1, PySmallPtrSet_Insert(set, six));
+ EXPECT_EQ(2u, PySmallPtrSet_Size(set));
+
+ // Insert duplicate element; size unchanged.
+ EXPECT_EQ(0, PySmallPtrSet_Insert(set, five));
+ EXPECT_EQ(2u, PySmallPtrSet_Size(set));
+
+ // Erase elements.
+ EXPECT_EQ(1, PySmallPtrSet_Erase(set, five));
+ EXPECT_EQ(1, PySmallPtrSet_Erase(set, six));
+ EXPECT_EQ(0u, PySmallPtrSet_Size(set));
+
+ // Erase missing element.
+ EXPECT_EQ(0, PySmallPtrSet_Erase(set, five));
+
+ PySmallPtrSet_Del(set);
+}
+
+
+static void
+my_iter_func(PyObject *obj, void *counter)
+{
+ (*(int *)counter) += 2;
+}
+
+TEST(PySmallPtrSet, Iteration)
+{
+ int counter = 0;
+
+ PySmallPtrSet *set = PySmallPtrSet_New();
+ ASSERT_TRUE(set != NULL);
+
+ PyObject *five = (PyObject *)5;
+ PyObject *six = (PyObject *)6;
+ EXPECT_EQ(1, PySmallPtrSet_Insert(set, five));
+ EXPECT_EQ(1, PySmallPtrSet_Insert(set, six));
+
+ PySmallPtrSet_ForEach(set, my_iter_func, &counter);
+ EXPECT_EQ(4, counter);
+
+ PySmallPtrSet_Del(set);
+}
Added: python/branches/py3k-jit/Unittests/StatsTest.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Unittests/StatsTest.cc Wed May 12 00:32:18 2010
@@ -0,0 +1,18 @@
+#include "Util/Stats.h"
+#include "llvm/ADT/STLExtras.h"
+#include "gtest/gtest.h"
+#include <vector>
+
+using llvm::array_endof;
+
+TEST(Stats_Median, Odd)
+{
+ int values[] = {1, 7, 15};
+ EXPECT_EQ(7, Median(std::vector<int>(values, array_endof(values))));
+}
+
+TEST(Stats_Median, Even)
+{
+ float values[] = {1, 7, 8, 15};
+ EXPECT_EQ(7.5, Median(std::vector<float>(values, array_endof(values))));
+}
Added: python/branches/py3k-jit/Util/PySmallPtrSet.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Util/PySmallPtrSet.cc Wed May 12 00:32:18 2010
@@ -0,0 +1,68 @@
+#include "Util/PySmallPtrSet.h"
+
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+
+
+typedef llvm::SmallPtrSet<PyObject *, 8> PySmallPtrSet_Impl;
+
+typedef struct PySmallPtrSet {
+ PySmallPtrSet_Impl llvm_set;
+} PySmallPtrSet;
+
+
+// C'tors, d'tors
+PySmallPtrSet *
+PySmallPtrSet_New()
+{
+ PySmallPtrSet *set = PyMem_New(PySmallPtrSet, 1);
+ if (set == NULL)
+ return NULL;
+ new(set)PySmallPtrSet();
+
+ return set;
+}
+
+void
+PySmallPtrSet_Del(PySmallPtrSet *set)
+{
+ set->~PySmallPtrSet();
+ PyMem_Free(set);
+}
+
+int
+PySmallPtrSet_Insert(PySmallPtrSet *set, PyObject *obj)
+{
+ return set->llvm_set.insert(obj);
+}
+
+int
+PySmallPtrSet_Erase(PySmallPtrSet *set, PyObject *obj)
+{
+ return set->llvm_set.erase(obj);
+}
+
+unsigned
+PySmallPtrSet_Size(PySmallPtrSet *set)
+{
+ return set->llvm_set.size();
+}
+
+int
+PySmallPtrSet_Count(PySmallPtrSet *set, PyObject *obj)
+{
+ return set->llvm_set.count(obj);
+}
+
+void
+PySmallPtrSet_ForEach(PySmallPtrSet *set, PySmallPtrSetCallback callback,
+ void *callback_arg)
+{
+ // Copy the original set in case the callback modifies the set.
+ llvm::SmallVector<PyObject *, 8> contents(set->llvm_set.begin(),
+ set->llvm_set.end());
+ for (llvm::SmallVector<PyObject *, 8>::iterator i = contents.begin(),
+ end = contents.end(); i != end; ++i) {
+ callback(*i, callback_arg);
+ }
+}
Added: python/branches/py3k-jit/Util/PySmallPtrSet.h
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Util/PySmallPtrSet.h Wed May 12 00:32:18 2010
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// This file defines C wrappers for an llvm::SmallPtrSet<PyObject *>
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef UTIL_PYSMALLPTRSET_H
+#define UTIL_PYSMALLPTRSET_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "Python.h"
+
+
+typedef struct PySmallPtrSet PySmallPtrSet;
+typedef void(*PySmallPtrSetCallback)(PyObject *, void *);
+
+
+// C'tors, d'tors
+PySmallPtrSet *PySmallPtrSet_New(void);
+void PySmallPtrSet_Del(PySmallPtrSet *);
+
+/// Insert - This returns 1 if the pointer was new to the set, 0 if it
+/// was already in the set.
+int PySmallPtrSet_Insert(PySmallPtrSet *, PyObject *);
+
+/// Erase - If the set contains the specified pointer, remove it and return
+/// 1, otherwise return 0.
+int PySmallPtrSet_Erase(PySmallPtrSet *, PyObject *);
+
+/// Get the size of the set.
+unsigned PySmallPtrSet_Size(PySmallPtrSet *);
+
+/// Count - Return 1 if the specified pointer is in the set.
+int PySmallPtrSet_Count(PySmallPtrSet *, PyObject *);
+
+// Iterating over a C++ collection from C is a major pain in the ass, so we do
+// this: given a function pointer, call it once for each element in the set.
+// The void * will be provided as a second argument to the callback.
+// It is acceptable for the callback to modify the set; this will not change
+// the iteration behaviour.
+void PySmallPtrSet_ForEach(PySmallPtrSet *, PySmallPtrSetCallback, void *);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // UTIL_PYSMALLPTRSET_H
Added: python/branches/py3k-jit/Util/Stats.cc
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Util/Stats.cc Wed May 12 00:32:18 2010
@@ -0,0 +1,22 @@
+#include "Util/Stats.h"
+
+#include "pyconfig.h"
+
+#if HAVE_GETTIMEOFDAY
+#include <sys/time.h>
+int64_t Timer::GetTime()
+{
+ struct timeval tv;
+#ifdef GETTIMEOFDAY_NO_TZ
+ gettimeofday(&tv);
+#else
+ gettimeofday(&tv, 0);
+#endif
+ return int64_t(tv.tv_sec) * 1000000000 + int64_t(tv.tv_usec) * 1000;
+}
+#else // Need a different definition on other platforms.
+int64_t Timer::GetTime()
+{
+ return 0;
+}
+#endif // HAVE_GETTIMEOFDAY
Added: python/branches/py3k-jit/Util/Stats.h
==============================================================================
--- (empty file)
+++ python/branches/py3k-jit/Util/Stats.h Wed May 12 00:32:18 2010
@@ -0,0 +1,93 @@
+// -*- C++ -*-
+#ifndef UTIL_STATS_H
+#define UTIL_STATS_H
+
+#ifndef __cplusplus
+#error This header expects to be included only in C++ source
+#endif
+
+#include "llvm/Support/MutexGuard.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <algorithm>
+#include <numeric>
+#include <vector>
+
+// Calculate the median of a given data set. This assumes that the data is
+// sorted.
+template<typename ValueTy>
+ValueTy
+Median(const std::vector<ValueTy> &data)
+{
+ size_t mid_point = data.size() / 2;
+ if (data.size() % 2 == 0) {
+ ValueTy first = data[mid_point];
+ ValueTy second = data[mid_point - 1];
+ return (first + second) / 2;
+ } else {
+ return data[mid_point];
+ }
+}
+
+
+// Base class useful for collecting stats on vectors of individual data points.
+// This is intended to be used with llvm::ManagedStatic and will print
+// min, median, mean, max and sum statistics about the data vector when the
+// process shuts down.
+template<typename ValueTy>
+class DataVectorStats {
+public:
+ typedef std::vector<ValueTy> DataType;
+
+ // Append a new data point to the vector. This is thread-safe.
+ void RecordDataPoint(ValueTy data_point) {
+ llvm::MutexGuard locked(this->lock_);
+ this->data_.push_back(data_point);
+ }
+
+ DataVectorStats(const char *const name) : name_(name) {}
+
+ ~DataVectorStats() {
+ DataType data = this->data_;
+ if (data.size() == 0)
+ return;
+ ValueTy sum = std::accumulate(data.begin(), data.end(), ValueTy());
+ std::sort(data.begin(), data.end());
+
+ llvm::errs() << "\n" << this->name_ << ":\n";
+ llvm::errs() << "N: " << data.size() << "\n";
+ llvm::errs() << "Min: " << data[0] << "\n";
+ llvm::errs() << "Median: " << Median(data) << "\n";
+ llvm::errs() << "Mean: " << sum / data.size() << "\n";
+ llvm::errs() << "Max: " << *(data.end() - 1) << "\n";
+ llvm::errs() << "Sum: " << sum << "\n";
+ }
+
+private:
+ const char *const name_;
+ llvm::sys::Mutex lock_;
+ DataType data_;
+};
+
+/// An instance of this class records the time in ns between its
+/// construction and destruction into a DataVectorStats<int64_t>.
+class Timer {
+public:
+ Timer(DataVectorStats<int64_t> &stat)
+ : stat_(stat), start_time_(this->GetTime()) {}
+ ~Timer() {
+ int64_t end_time = this->GetTime();
+ int64_t elapsed = end_time - this->start_time_;
+ stat_.RecordDataPoint(elapsed);
+ }
+private:
+ // Returns the current time in nanoseconds. It doesn't matter
+ // what these ns count from since we only use them to compute time
+ // changes.
+ static int64_t GetTime();
+
+ DataVectorStats<int64_t> &stat_;
+ const int64_t start_time_;
+};
+
+#endif // UTIL_STATS_H
Modified: python/branches/py3k-jit/configure
==============================================================================
--- python/branches/py3k-jit/configure (original)
+++ python/branches/py3k-jit/configure Wed May 12 00:32:18 2010
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 80834 .
+# From configure.in Revision: 81086 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.65 for python 3.2.
#
@@ -625,6 +625,8 @@
LDCXXSHARED
LDSHARED
SO
+FORCE_C
+BASECXXFLAGS
LIBTOOL_CRUFT
OTHER_LIBTOOL_OPT
UNIVERSAL_ARCH_FLAGS
@@ -660,6 +662,14 @@
LDFLAGS
CFLAGS
CC
+LLVM_LIB_PATHS
+LLVM_LDFLAGS
+LLVM_CXXFLAGS
+LLVM_BIN_DIR
+LLVM_INC_DIR
+LLVM_PYTHON_OBJS
+WITH_LLVM
+LLVM_CONFIG
EXPORT_MACOSX_DEPLOYMENT_TARGET
CONFIGURE_MACOSX_DEPLOYMENT_TARGET
SGI_ABI
@@ -727,6 +737,7 @@
with_framework_name
enable_framework
with_gcc
+with_llvm
with_cxx_main
with_suffix
enable_shared
@@ -742,7 +753,6 @@
with_thread
enable_ipv6
with_doc_strings
-with_tsc
with_pymalloc
with_valgrind
with_wctype_functions
@@ -752,10 +762,13 @@
enable_big_digits
with_wide_unicode
with_computed_gotos
+with_instrumentation
+with_tsc
'
ac_precious_vars='build_alias
host_alias
target_alias
+LLVM_CONFIG
CC
CFLAGS
LDFLAGS
@@ -1393,6 +1406,11 @@
specify an alternate name of the framework built
with --enable-framework
--without-gcc never use gcc
+ --with(out)-llvm[=DIRECTORY]
+ build against a preinstalled LLVM or disable LLVM
+ integration entirely. Note that Python built with
+ --without-llvm cannot load extension modules built
+ with --with-llvm or vice-versa.
--with-cxx-main=<compiler>
compile main() and link python executable with C++
compiler
@@ -1413,7 +1431,6 @@
--with(out)-thread[=DIRECTORY]
deprecated; use --with(out)-threads
--with(out)-doc-strings disable/enable documentation strings
- --with(out)-tsc enable/disable timestamp counter profile
--with(out)-pymalloc disable/enable specialized mallocs
--with-valgrind Enable Valgrind support
--with-wctype-functions use wctype.h functions
@@ -1423,8 +1440,12 @@
--with-wide-unicode Use 4-byte Unicode characters (default is 2 bytes)
--with-computed-gotos Use computed gotos / threaded dispatch in evaluation
loop (not available on all compilers)
+ --with-instrumentation Compile in a bunch of runtime instrumentation useful
+ for optimizing Python itself. Requires --with-llvm.
+ --with(out)-tsc enable/disable timestamp counter profile
Some influential environment variables:
+ LLVM_CONFIG LLVM configuration script
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -3176,6 +3197,247 @@
(it is also a good idea to do 'make clean' before compiling)" "$LINENO" 5
fi
+# Check for --with-llvm=DIRECTORY or --without-llvm.
+#
+# Check for this really early so we can use it to toggle LINKCC.
+#
+# Expected behaviour:
+# - Omit --with-llvm: use llvm-config we find in the path or $LLVM_CONFIG
+# - --with-llvm (no DIRECTORY): Same
+# - --with-llvm=DIRECTORY: use the LLVM installed in DIRECTORY
+# - --without-llvm: disable everything that requires LLVM
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with(out)-llvm" >&5
+$as_echo_n "checking for --with(out)-llvm... " >&6; }
+
+# Check whether --with-llvm was given.
+if test "${with_llvm+set}" = set; then :
+ withval=$with_llvm; with_llvm=$withval
+else
+ with_llvm=yes
+fi
+
+
+if test "$with_llvm" = "no"
+then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
+$as_echo "disabled" >&6; }
+ WITH_LLVM=0
+ LLVM_PYTHON_OBJS="EMPTY"
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_llvm" >&5
+$as_echo "$with_llvm" >&6; }
+ WITH_LLVM=1
+ LLVM_PYTHON_OBJS="LLVM_PYTHON_OBJS"
+ if test "$with_llvm" = "yes"
+ then
+ # Extract the first word of "llvm-config", so it can be a program name with args.
+set dummy llvm-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_LLVM_CONFIG+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $LLVM_CONFIG in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LLVM_CONFIG="$LLVM_CONFIG" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_path_LLVM_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+LLVM_CONFIG=$ac_cv_path_LLVM_CONFIG
+if test -n "$LLVM_CONFIG"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_CONFIG" >&5
+$as_echo "$LLVM_CONFIG" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ if test -z "$LLVM_CONFIG"
+ then
+ as_fn_error "cannot find llvm-config on the PATH" "$LINENO" 5
+ fi
+ else
+ # Extract the first word of "llvm-config", so it can be a program name with args.
+set dummy llvm-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_path_LLVM_CONFIG+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $LLVM_CONFIG in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LLVM_CONFIG="$LLVM_CONFIG" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $with_llvm/bin
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_path_LLVM_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ ;;
+esac
+fi
+LLVM_CONFIG=$ac_cv_path_LLVM_CONFIG
+if test -n "$LLVM_CONFIG"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_CONFIG" >&5
+$as_echo "$LLVM_CONFIG" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ if test -z "$LLVM_CONFIG"
+ then
+ as_fn_error "cannot find llvm-config in $with_llvm/bin" "$LINENO" 5
+ fi
+ fi
+
+ LLVM_INC_DIR=`$LLVM_CONFIG --includedir`
+ LLVM_BIN_DIR=`$LLVM_CONFIG --bindir`
+ LLVM_CXXFLAGS=`$LLVM_CONFIG jit bitreader backend --cxxflags`
+ LLVM_LDFLAGS=`$LLVM_CONFIG jit bitreader backend --ldflags --libs | awk '{ORS=" "} {print $0}'`
+ LLVM_LIB_PATHS=`$LLVM_CONFIG jit bitreader backend --libfiles`
+
+ as_ac_File=`$as_echo "ac_cv_file_"$LLVM_BIN_DIR/clang"" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for \"$LLVM_BIN_DIR/clang\"" >&5
+$as_echo_n "checking for \"$LLVM_BIN_DIR/clang\"... " >&6; }
+if { as_var=$as_ac_File; eval "test \"\${$as_var+set}\" = set"; }; then :
+ $as_echo_n "(cached) " >&6
+else
+ test "$cross_compiling" = yes &&
+ as_fn_error "cannot check for file existence when cross compiling" "$LINENO" 5
+if test -r ""$LLVM_BIN_DIR/clang""; then
+ eval "$as_ac_File=yes"
+else
+ eval "$as_ac_File=no"
+fi
+fi
+eval ac_res=\$$as_ac_File
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+eval as_val=\$$as_ac_File
+ if test "x$as_val" = x""yes; then :
+
+else
+ as_fn_error "Did not find clang in $LLVM_BIN_DIR" "$LINENO" 5
+fi
+
+ as_ac_File=`$as_echo "ac_cv_file_"$LLVM_BIN_DIR/opt"" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for \"$LLVM_BIN_DIR/opt\"" >&5
+$as_echo_n "checking for \"$LLVM_BIN_DIR/opt\"... " >&6; }
+if { as_var=$as_ac_File; eval "test \"\${$as_var+set}\" = set"; }; then :
+ $as_echo_n "(cached) " >&6
+else
+ test "$cross_compiling" = yes &&
+ as_fn_error "cannot check for file existence when cross compiling" "$LINENO" 5
+if test -r ""$LLVM_BIN_DIR/opt""; then
+ eval "$as_ac_File=yes"
+else
+ eval "$as_ac_File=no"
+fi
+fi
+eval ac_res=\$$as_ac_File
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+eval as_val=\$$as_ac_File
+ if test "x$as_val" = x""yes; then :
+
+else
+ as_fn_error "Did not find opt in $LLVM_BIN_DIR" "$LINENO" 5
+fi
+
+ as_ac_File=`$as_echo "ac_cv_file_"$LLVM_BIN_DIR/llvm-link"" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for \"$LLVM_BIN_DIR/llvm-link\"" >&5
+$as_echo_n "checking for \"$LLVM_BIN_DIR/llvm-link\"... " >&6; }
+if { as_var=$as_ac_File; eval "test \"\${$as_var+set}\" = set"; }; then :
+ $as_echo_n "(cached) " >&6
+else
+ test "$cross_compiling" = yes &&
+ as_fn_error "cannot check for file existence when cross compiling" "$LINENO" 5
+if test -r ""$LLVM_BIN_DIR/llvm-link""; then
+ eval "$as_ac_File=yes"
+else
+ eval "$as_ac_File=no"
+fi
+fi
+eval ac_res=\$$as_ac_File
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+eval as_val=\$$as_ac_File
+ if test "x$as_val" = x""yes; then :
+
+else
+ as_fn_error "Did not find llvm-link in $LLVM_BIN_DIR" "$LINENO" 5
+fi
+
+ as_ac_File=`$as_echo "ac_cv_file_"$LLVM_BIN_DIR/llvm-dis"" | $as_tr_sh`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for \"$LLVM_BIN_DIR/llvm-dis\"" >&5
+$as_echo_n "checking for \"$LLVM_BIN_DIR/llvm-dis\"... " >&6; }
+if { as_var=$as_ac_File; eval "test \"\${$as_var+set}\" = set"; }; then :
+ $as_echo_n "(cached) " >&6
+else
+ test "$cross_compiling" = yes &&
+ as_fn_error "cannot check for file existence when cross compiling" "$LINENO" 5
+if test -r ""$LLVM_BIN_DIR/llvm-dis""; then
+ eval "$as_ac_File=yes"
+else
+ eval "$as_ac_File=no"
+fi
+fi
+eval ac_res=\$$as_ac_File
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+eval as_val=\$$as_ac_File
+ if test "x$as_val" = x""yes; then :
+
+else
+ as_fn_error "Did not find llvm-dis in $LLVM_BIN_DIR" "$LINENO" 5
+fi
+
+
+
+$as_echo "#define WITH_LLVM 1" >>confdefs.h
+
+fi
+
+
+
+
+
+
+
+
+
# If the user set CFLAGS, use this instead of the automatically
# determined setting
preset_cflags="$CFLAGS"
@@ -3996,16 +4258,31 @@
CXX=$withval
fi;;
esac
+
else
- with_cxx_main=no
- MAINCC='$(CC)'
+ case "$with_llvm" in
+ no) with_cxx_main=no
+ MAINCC='$(CC)';;
+ *) with_cxx_main=yes
+ MAINCC='$(CXX)';;
+ esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_cxx_main" >&5
$as_echo "$with_cxx_main" >&6; }
+if test "$with_cxx_main" = "no"
+then
+ if test "$with_llvm" != "no"
+ then
+ as_fn_error "\"Cannot specify both --without-cxx-main and --with-llvm\"" "$LINENO" 5;
+ fi
+fi
+
+# Use this in preference to AC_PROG_CXX, since --with-cxx-main=foo will override
+# CXX.
preset_cxx="$CXX"
if test -z "$CXX"
then
@@ -4722,10 +4999,9 @@
LDLIBRARYDIR=''
RUNSHARED=''
-# LINKCC is the command that links the python executable -- default is $(CC).
-# If CXX is set, and if it is needed to link a main function that was
-# compiled with CXX, LINKCC is CXX instead. Always using CXX is undesirable:
-# python might then depend on the C++ runtime
+# LINKCC is the command that links the python executable -- this depends on
+# the values of --with-llvm and --with-cxx-main.
+# Always using CXX is undesirable: python might then depend on the C++ runtime
# This is altered for AIX in order to build the export list before
# linking.
@@ -4839,7 +5115,7 @@
if test "$enable_framework"
then
LDLIBRARY='$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
- RUNSHARED=DYLD_FRAMEWORK_PATH="`pwd`:$DYLD_FRAMEWORK_PATH"
+ RUNSHARED=DYLD_FRAMEWORK_PATH="$(shell pwd):$DYLD_FRAMEWORK_PATH"
BLDLIBRARY=''
else
BLDLIBRARY='$(LDLIBRARY)'
@@ -4858,13 +5134,13 @@
SunOS*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-Wl,-R,$(LIBDIR) -L. -lpython$(VERSION)'
- RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
+ RUNSHARED='LD_LIBRARY_PATH=$(shell pwd):${LD_LIBRARY_PATH}'
INSTSONAME="$LDLIBRARY".$SOVERSION
;;
Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-L. -lpython$(VERSION)'
- RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
+ RUNSHARED='LD_LIBRARY_PATH=$(shell pwd):${LD_LIBRARY_PATH}'
case $ac_sys_system in
FreeBSD*)
SOVERSION=`echo $SOVERSION|cut -d "." -f 1`
@@ -4882,17 +5158,17 @@
;;
esac
BLDLIBRARY='-Wl,+b,$(LIBDIR) -L. -lpython$(VERSION)'
- RUNSHARED=SHLIB_PATH=`pwd`:${SHLIB_PATH}
+ RUNSHARED='SHLIB_PATH=$(shell pwd):${SHLIB_PATH}'
;;
OSF*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-rpath $(LIBDIR) -L. -lpython$(VERSION)'
- RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
+ RUNSHARED='LD_LIBRARY_PATH=$(shell pwd):${LD_LIBRARY_PATH}'
;;
Darwin*)
LDLIBRARY='libpython$(VERSION).dylib'
BLDLIBRARY='-L. -lpython$(VERSION)'
- RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}'
+ RUNSHARED='DYLD_LIBRARY_PATH=$(shell pwd):${DYLD_LIBRARY_PATH}'
;;
esac
@@ -5256,6 +5532,23 @@
fi
+if test "$with_llvm" != "no"
+then
+ LLVM_BUILD_MODE=`$LLVM_CONFIG --build-mode`
+ if echo $LLVM_BUILD_MODE | grep -e -Asserts &>/dev/null
+ then
+ if test "$Py_DEBUG" = "true"
+ then
+ as_fn_error "--with-pydebug requires +Asserts LLVM. Got \"$LLVM_BUILD_MODE\"" "$LINENO" 5
+ fi
+ else
+ if test "$Py_DEBUG" != "true"
+ then
+ as_fn_error "--without-pydebug requires -Asserts LLVM. Got \"$LLVM_BUILD_MODE\"" "$LINENO" 5
+ fi
+ fi
+fi
+
# XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
# merged with this chunk of code?
@@ -5276,25 +5569,18 @@
then
case $GCC in
yes)
- if test "$CC" != 'g++' ; then
- STRICT_PROTO="-Wstrict-prototypes"
- fi
- # For gcc 4.x we need to use -fwrapv so lets check if its supported
- if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then
- WRAP="-fwrapv"
- fi
case $ac_cv_prog_cc_g in
yes)
if test "$Py_DEBUG" = 'true' ; then
# Optimization messes up debuggers, so turn it off for
# debug builds.
- OPT="-g -O0 -Wall $STRICT_PROTO"
+ OPT="-g -O0 -Wall"
else
- OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
+ OPT="-g $WRAP -O3 -Wall"
fi
;;
*)
- OPT="-O3 -Wall $STRICT_PROTO"
+ OPT="-O3 -Wall"
;;
esac
case $ac_sys_system in
@@ -5388,6 +5674,43 @@
BASECFLAGS="$BASECFLAGS -fno-strict-aliasing"
fi
+ # Python violates C99 rules by treating signed overflow as
+ # 2s-compliment. GCC 4+ can generate bad code because of that, so
+ # use -fwrapv if it's supported
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -fwrapv" >&5
+$as_echo_n "checking whether $CC accepts -fwrapv... " >&6; }
+ ac_save_cc="$CC"
+ CC="$CC -fwrapv"
+ if test "$cross_compiling" = yes; then :
+ ac_cv_fwrapv_ok=no
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+int main() { return 0; }
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+ ac_cv_fwrapv_ok=yes
+else
+ ac_cv_fwrapv_ok=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+ conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+ CC="$ac_save_cc"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fwrapv_ok" >&5
+$as_echo "$ac_cv_fwrapv_ok" >&6; }
+ if test $ac_cv_fwrapv_ok = yes
+ then
+ BASECFLAGS="$BASECFLAGS -fwrapv"
+ fi
+
+ BASECFLAGS="$BASECFLAGS -Wall"
+
+ if test "$CC" != 'g++' ; then
+ STRICT_PROTO="-Wstrict-prototypes"
+ fi
+
# if using gcc on alpha, use -mieee to get (near) full IEEE 754
# support. Without this, treatment of subnormals doesn't follow
# the standard.
@@ -7422,6 +7745,22 @@
;;
esac
+
+# Only add -Wstrict-prototypes to the C flags, not C++. We do this
+# after BASECFLAGS is fully set up.
+BASECXXFLAGS="$BASECFLAGS"
+BASECFLAGS="$BASECFLAGS $STRICT_PROTO"
+
+# We force C compilation for some files so that we don't have to rename them.
+# Otherwise when configured --without-llvm, gcc will see the .cc extension and
+# compile the file as C++, which creates a dependency on libstdc++.
+
+FORCE_C=""
+if test "$GCC" == "yes"
+then
+ FORCE_C="-x c"
+fi
+
# Set info about shared libraries.
@@ -8996,7 +9335,7 @@
ipv6type=$i
ipv6lib=inet6
ipv6libdir=/usr/inet6/lib
- BASECFLAGS="-I/usr/inet6/include $BASECFLAGS"
+ CPPFLAGS="-I/usr/inet6/include $CPPFLAGS"
fi
;;
solaris)
@@ -9039,7 +9378,7 @@
ipv6type=$i;
ipv6lib=v6;
ipv6libdir=/usr/local/v6/lib;
- BASECFLAGS="-I/usr/local/v6/include $BASECFLAGS"
+ CPPFLAGS="-I/usr/local/v6/include $CPPFLAGS"
fi
rm -f conftest*
@@ -9141,29 +9480,6 @@
$as_echo "$with_doc_strings" >&6; }
# Check for Python-specific malloc support
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-tsc" >&5
-$as_echo_n "checking for --with-tsc... " >&6; }
-
-# Check whether --with-tsc was given.
-if test "${with_tsc+set}" = set; then :
- withval=$with_tsc;
-if test "$withval" != no
-then
-
-$as_echo "#define WITH_TSC 1" >>confdefs.h
-
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
-# Check for Python-specific malloc support
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-pymalloc" >&5
$as_echo_n "checking for --with-pymalloc... " >&6; }
@@ -13544,12 +13860,57 @@
fi
+# Check for --with-instrumentation
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-instrumentation" >&5
+$as_echo_n "checking for --with-instrumentation... " >&6; }
+# Check whether --with-instrumentation was given.
+if test "${with_instrumentation+set}" = set; then :
+ withval=$with_instrumentation;
+fi
-case $ac_sys_system in
- OSF*) as_fn_error "OSF* systems are deprecated unless somebody volunteers. Check http://bugs.python.org/issue8606" "$LINENO" 5 ;;
-esac
+if test "$with_instrumentation" = yes
+then
+
+$as_echo "#define Py_WITH_INSTRUMENTATION 1" >>confdefs.h
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; };
+ if test "WITH_LLVM" = "0"
+ then
+ as_fn_error "--with-instrumentation requires --with-llvm" "$LINENO" 5
+ fi
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; };
+fi
+
+# Check fine-grained interpreter profiling using hardware counters.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-tsc" >&5
+$as_echo_n "checking for --with-tsc... " >&6; }
+
+# Check whether --with-tsc was given.
+if test "${with_tsc+set}" = set; then :
+ withval=$with_tsc;
+if test "$withval" != no
+then
+
+$as_echo "#define WITH_TSC 1" >>confdefs.h
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ if test "WITH_LLVM" = "0"
+ then
+ as_fn_error "--with-tsc requires --with-llvm" "$LINENO" 5
+ fi
+else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
@@ -13560,7 +13921,7 @@
done
-SRCDIRS="Parser Grammar Objects Python Modules Mac Unittests Unittests/googletest"
+SRCDIRS="Parser Grammar Objects Python Modules Mac Unittests Unittests/googletest Util"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for build directories" >&5
$as_echo_n "checking for build directories... " >&6; }
for dir in $SRCDIRS; do
Modified: python/branches/py3k-jit/configure.in
==============================================================================
--- python/branches/py3k-jit/configure.in (original)
+++ python/branches/py3k-jit/configure.in Wed May 12 00:32:18 2010
@@ -26,7 +26,7 @@
dnl Last slash shouldn't be stripped if prefix=/
if test "$prefix" != "/"; then
prefix=`echo "$prefix" | sed -e 's/\/$//g'`
-fi
+fi
dnl This is for stuff that absolutely must end up in pyconfig.h.
dnl Please use pyport.h instead, if possible.
@@ -478,6 +478,82 @@
(it is also a good idea to do 'make clean' before compiling)])
fi
+# Check for --with-llvm=DIRECTORY or --without-llvm.
+#
+# Check for this really early so we can use it to toggle LINKCC.
+#
+# Expected behaviour:
+# - Omit --with-llvm: use llvm-config we find in the path or $LLVM_CONFIG
+# - --with-llvm (no DIRECTORY): Same
+# - --with-llvm=DIRECTORY: use the LLVM installed in DIRECTORY
+# - --without-llvm: disable everything that requires LLVM
+dnl quadrigraphs "@<:@" and "@:>@" produce "[" and "]" in the output
+AC_ARG_VAR(LLVM_CONFIG, [LLVM configuration script])
+AC_MSG_CHECKING(for --with(out)-llvm)
+AC_ARG_WITH(llvm,
+ AS_HELP_STRING([--with(out)-llvm@<:@=DIRECTORY@:>@],
+ [build against a preinstalled LLVM
+ or disable LLVM integration entirely. Note that
+ Python built with --without-llvm cannot load
+ extension modules built with --with-llvm or
+ vice-versa.]),
+ [with_llvm=$withval],
+ [with_llvm=yes])
+
+if test "$with_llvm" = "no"
+then
+ AC_MSG_RESULT(disabled)
+ WITH_LLVM=0
+ LLVM_PYTHON_OBJS="EMPTY"
+ LLVM_UNITTEST_SRCS="EMPTY"
+else
+ AC_MSG_RESULT($with_llvm)
+ WITH_LLVM=1
+ LLVM_PYTHON_OBJS="LLVM_PYTHON_OBJS"
+ LLVM_UNITTEST_SRCS="LLVM_UNITTEST_SRCS"
+ if test "$with_llvm" = "yes"
+ then
+ AC_PATH_PROG(LLVM_CONFIG, llvm-config)
+ if test -z "$LLVM_CONFIG"
+ then
+ AC_MSG_ERROR([cannot find llvm-config on the PATH])
+ fi
+ else
+ AC_PATH_PROG(LLVM_CONFIG, llvm-config, [], [$with_llvm/bin])
+ if test -z "$LLVM_CONFIG"
+ then
+ AC_MSG_ERROR([cannot find llvm-config in $with_llvm/bin])
+ fi
+ fi
+
+ LLVM_INC_DIR=`$LLVM_CONFIG --includedir`
+ LLVM_BIN_DIR=`$LLVM_CONFIG --bindir`
+ LLVM_CXXFLAGS=`$LLVM_CONFIG jit bitreader backend --cxxflags`
+ LLVM_LDFLAGS=`$LLVM_CONFIG jit bitreader backend --ldflags --libs | awk '{ORS=" "} {print $0}'`
+ LLVM_LIB_PATHS=`$LLVM_CONFIG jit bitreader backend --libfiles`
+
+ AC_CHECK_FILE("$LLVM_BIN_DIR/clang",
+ [], [AC_MSG_ERROR([Did not find clang in $LLVM_BIN_DIR])])
+ AC_CHECK_FILE("$LLVM_BIN_DIR/opt",
+ [], [AC_MSG_ERROR([Did not find opt in $LLVM_BIN_DIR])])
+ AC_CHECK_FILE("$LLVM_BIN_DIR/llvm-link",
+ [], [AC_MSG_ERROR([Did not find llvm-link in $LLVM_BIN_DIR])])
+ AC_CHECK_FILE("$LLVM_BIN_DIR/llvm-dis",
+ [], [AC_MSG_ERROR([Did not find llvm-dis in $LLVM_BIN_DIR])])
+
+ AC_DEFINE(WITH_LLVM, 1,
+ [Use LLVM for code generation. This makes things fast.])
+fi
+AC_SUBST(WITH_LLVM)
+AC_SUBST(LLVM_PYTHON_OBJS)
+AC_SUBST(LLVM_UNITTEST_SRCS)
+AC_SUBST(LLVM_INC_DIR)
+AC_SUBST(LLVM_BIN_DIR)
+AC_SUBST(LLVM_CXXFLAGS)
+AC_SUBST(LLVM_LDFLAGS)
+AC_SUBST(LLVM_LIB_PATHS)
+
+
# If the user set CFLAGS, use this instead of the automatically
# determined setting
preset_cflags="$CFLAGS"
@@ -506,12 +582,27 @@
then
CXX=$withval
fi;;
- esac], [
- with_cxx_main=no
- MAINCC='$(CC)'
+ esac
+], [
+ case "$with_llvm" in
+ no) with_cxx_main=no
+ MAINCC='$(CC)';;
+ *) with_cxx_main=yes
+ MAINCC='$(CXX)';;
+ esac
])
AC_MSG_RESULT($with_cxx_main)
+if test "$with_cxx_main" = "no"
+then
+ if test "$with_llvm" != "no"
+ then
+ AC_MSG_ERROR("Cannot specify both --without-cxx-main and --with-llvm");
+ fi
+fi
+
+# Use this in preference to AC_PROG_CXX, since --with-cxx-main=foo will override
+# CXX.
preset_cxx="$CXX"
if test -z "$CXX"
then
@@ -632,10 +723,9 @@
LDLIBRARYDIR=''
RUNSHARED=''
-# LINKCC is the command that links the python executable -- default is $(CC).
-# If CXX is set, and if it is needed to link a main function that was
-# compiled with CXX, LINKCC is CXX instead. Always using CXX is undesirable:
-# python might then depend on the C++ runtime
+# LINKCC is the command that links the python executable -- this depends on
+# the values of --with-llvm and --with-cxx-main.
+# Always using CXX is undesirable: python might then depend on the C++ runtime
# This is altered for AIX in order to build the export list before
# linking.
AC_SUBST(LINKCC)
@@ -723,7 +813,7 @@
if test "$enable_framework"
then
LDLIBRARY='$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
- RUNSHARED=DYLD_FRAMEWORK_PATH="`pwd`:$DYLD_FRAMEWORK_PATH"
+ RUNSHARED=DYLD_FRAMEWORK_PATH="$(shell pwd):$DYLD_FRAMEWORK_PATH"
BLDLIBRARY=''
else
BLDLIBRARY='$(LDLIBRARY)'
@@ -740,13 +830,13 @@
SunOS*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-Wl,-R,$(LIBDIR) -L. -lpython$(VERSION)'
- RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
+ RUNSHARED='LD_LIBRARY_PATH=$(shell pwd):${LD_LIBRARY_PATH}'
INSTSONAME="$LDLIBRARY".$SOVERSION
;;
Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-L. -lpython$(VERSION)'
- RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
+ RUNSHARED='LD_LIBRARY_PATH=$(shell pwd):${LD_LIBRARY_PATH}'
case $ac_sys_system in
FreeBSD*)
SOVERSION=`echo $SOVERSION|cut -d "." -f 1`
@@ -764,17 +854,17 @@
;;
esac
BLDLIBRARY='-Wl,+b,$(LIBDIR) -L. -lpython$(VERSION)'
- RUNSHARED=SHLIB_PATH=`pwd`:${SHLIB_PATH}
+ RUNSHARED='SHLIB_PATH=$(shell pwd):${SHLIB_PATH}'
;;
OSF*)
LDLIBRARY='libpython$(VERSION).so'
BLDLIBRARY='-rpath $(LIBDIR) -L. -lpython$(VERSION)'
- RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
+ RUNSHARED='LD_LIBRARY_PATH=$(shell pwd):${LD_LIBRARY_PATH}'
;;
Darwin*)
LDLIBRARY='libpython$(VERSION).dylib'
BLDLIBRARY='-L. -lpython$(VERSION)'
- RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}'
+ RUNSHARED='DYLD_LIBRARY_PATH=$(shell pwd):${DYLD_LIBRARY_PATH}'
;;
esac
@@ -843,6 +933,23 @@
fi],
[AC_MSG_RESULT(no)])
+if test "$with_llvm" != "no"
+then
+ LLVM_BUILD_MODE=`$LLVM_CONFIG --build-mode`
+ if echo $LLVM_BUILD_MODE | grep -e -Asserts &>/dev/null
+ then
+ if test "$Py_DEBUG" = "true"
+ then
+ AC_MSG_ERROR([--with-pydebug requires +Asserts LLVM. Got "$LLVM_BUILD_MODE"])
+ fi
+ else
+ if test "$Py_DEBUG" != "true"
+ then
+ AC_MSG_ERROR([--without-pydebug requires -Asserts LLVM. Got "$LLVM_BUILD_MODE"])
+ fi
+ fi
+fi
+
# XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
# merged with this chunk of code?
@@ -863,25 +970,18 @@
then
case $GCC in
yes)
- if test "$CC" != 'g++' ; then
- STRICT_PROTO="-Wstrict-prototypes"
- fi
- # For gcc 4.x we need to use -fwrapv so lets check if its supported
- if "$CC" -v --help 2>/dev/null |grep -- -fwrapv > /dev/null; then
- WRAP="-fwrapv"
- fi
case $ac_cv_prog_cc_g in
yes)
if test "$Py_DEBUG" = 'true' ; then
# Optimization messes up debuggers, so turn it off for
# debug builds.
- OPT="-g -O0 -Wall $STRICT_PROTO"
+ OPT="-g -O0 -Wall"
else
- OPT="-g $WRAP -O3 -Wall $STRICT_PROTO"
+ OPT="-g $WRAP -O3 -Wall"
fi
;;
*)
- OPT="-O3 -Wall $STRICT_PROTO"
+ OPT="-O3 -Wall"
;;
esac
case $ac_sys_system in
@@ -940,6 +1040,29 @@
BASECFLAGS="$BASECFLAGS -fno-strict-aliasing"
fi
+ # Python violates C99 rules by treating signed overflow as
+ # 2s-compliment. GCC 4+ can generate bad code because of that, so
+ # use -fwrapv if it's supported
+ AC_MSG_CHECKING(whether $CC accepts -fwrapv)
+ ac_save_cc="$CC"
+ CC="$CC -fwrapv"
+ AC_TRY_RUN([int main() { return 0; }],
+ ac_cv_fwrapv_ok=yes,
+ ac_cv_fwrapv_ok=no,
+ ac_cv_fwrapv_ok=no)
+ CC="$ac_save_cc"
+ AC_MSG_RESULT($ac_cv_fwrapv_ok)
+ if test $ac_cv_fwrapv_ok = yes
+ then
+ BASECFLAGS="$BASECFLAGS -fwrapv"
+ fi
+
+ BASECFLAGS="$BASECFLAGS -Wall"
+
+ if test "$CC" != 'g++' ; then
+ STRICT_PROTO="-Wstrict-prototypes"
+ fi
+
# if using gcc on alpha, use -mieee to get (near) full IEEE 754
# support. Without this, treatment of subnormals doesn't follow
# the standard.
@@ -1653,6 +1776,22 @@
;;
esac
+AC_SUBST(BASECXXFLAGS)
+# Only add -Wstrict-prototypes to the C flags, not C++. We do this
+# after BASECFLAGS is fully set up.
+BASECXXFLAGS="$BASECFLAGS"
+BASECFLAGS="$BASECFLAGS $STRICT_PROTO"
+
+# We force C compilation for some files so that we don't have to rename them.
+# Otherwise when configured --without-llvm, gcc will see the .cc extension and
+# compile the file as C++, which creates a dependency on libstdc++.
+AC_SUBST(FORCE_C)
+FORCE_C=""
+if test "$GCC" == "yes"
+then
+ FORCE_C="-x c"
+fi
+
# Set info about shared libraries.
AC_SUBST(SO)
AC_SUBST(LDSHARED)
@@ -2385,7 +2524,7 @@
ipv6type=$i
ipv6lib=inet6
ipv6libdir=/usr/inet6/lib
- BASECFLAGS="-I/usr/inet6/include $BASECFLAGS"
+ CPPFLAGS="-I/usr/inet6/include $CPPFLAGS"
fi
;;
solaris)
@@ -2415,7 +2554,7 @@
[ipv6type=$i;
ipv6lib=v6;
ipv6libdir=/usr/local/v6/lib;
- BASECFLAGS="-I/usr/local/v6/include $BASECFLAGS"])
+ CPPFLAGS="-I/usr/local/v6/include $CPPFLAGS"])
;;
zeta)
AC_EGREP_CPP(yes, [
@@ -2477,19 +2616,6 @@
AC_MSG_RESULT($with_doc_strings)
# Check for Python-specific malloc support
-AC_MSG_CHECKING(for --with-tsc)
-AC_ARG_WITH(tsc,
- AS_HELP_STRING([--with(out)-tsc],[enable/disable timestamp counter profile]),[
-if test "$withval" != no
-then
- AC_DEFINE(WITH_TSC, 1,
- [Define to profile with the Pentium timestamp counter])
- AC_MSG_RESULT(yes)
-else AC_MSG_RESULT(no)
-fi],
-[AC_MSG_RESULT(no)])
-
-# Check for Python-specific malloc support
AC_MSG_CHECKING(for --with-pymalloc)
AC_ARG_WITH(pymalloc,
AS_HELP_STRING([--with(out)-pymalloc], [disable/enable specialized mallocs]))
@@ -4149,21 +4275,52 @@
[Use computed gotos / threaded dispatch in evaluation loop (not available on all compilers)]),
[
if test "$withval" != no
-then
+then
AC_DEFINE(USE_COMPUTED_GOTOS, 1,
- [Define if you want to use computed gotos in ceval.c.])
+ [Define if you want to use computed gotos in ceval.c.])
AC_MSG_RESULT(yes)
else AC_MSG_RESULT(no)
fi],
[AC_MSG_RESULT(no)])
+# Check for --with-instrumentation
+AC_MSG_CHECKING(for --with-instrumentation)
+AC_ARG_WITH(instrumentation,
+ AS_HELP_STRING([--with-instrumentation],
+ [Compile in a bunch of runtime instrumentation useful
+ for optimizing Python itself. Requires --with-llvm.]))
+
+if test "$with_instrumentation" = yes
+then
+ AC_DEFINE(Py_WITH_INSTRUMENTATION, 1,
+ [Compile in a bunch of runtime instrumentation useful for optimizing
+ Python itself.])
+ AC_MSG_RESULT(yes);
+ if test "WITH_LLVM" = "0"
+ then
+ AC_MSG_ERROR([--with-instrumentation requires --with-llvm])
+ fi
+else
+ AC_MSG_RESULT(no);
+fi
-
-case $ac_sys_system in
- OSF*) AC_MSG_ERROR(OSF* systems are deprecated unless somebody volunteers. Check http://bugs.python.org/issue8606) ;;
-esac
-
-
+# Check fine-grained interpreter profiling using hardware counters.
+AC_MSG_CHECKING(for --with-tsc)
+AC_ARG_WITH(tsc,
+ AS_HELP_STRING([--with(out)-tsc],
+ [enable/disable timestamp counter profile]), [
+if test "$withval" != no
+then
+ AC_DEFINE(WITH_TSC, 1,
+ [Define to profile with the Pentium timestamp counter])
+ AC_MSG_RESULT(yes)
+ if test "WITH_LLVM" = "0"
+ then
+ AC_MSG_ERROR([--with-tsc requires --with-llvm])
+ fi
+else AC_MSG_RESULT(no)
+fi],
+[AC_MSG_RESULT(no)])
AC_SUBST(THREADHEADERS)
@@ -4173,7 +4330,7 @@
done
AC_SUBST(SRCDIRS)
-SRCDIRS="Parser Grammar Objects Python Modules Mac Unittests Unittests/googletest"
+SRCDIRS="Parser Grammar Objects Python Modules Mac Unittests Unittests/googletest Util"
AC_MSG_CHECKING(for build directories)
for dir in $SRCDIRS; do
if test ! -d $dir; then
Modified: python/branches/py3k-jit/pyconfig.h.in
==============================================================================
--- python/branches/py3k-jit/pyconfig.h.in (original)
+++ python/branches/py3k-jit/pyconfig.h.in Wed May 12 00:32:18 2010
@@ -958,6 +958,10 @@
/* Define as the size of the unicode type. */
#undef Py_UNICODE_SIZE
+/* Compile in a bunch of runtime instrumentation useful for optimizing Python
+ itself. */
+#undef Py_WITH_INSTRUMENTATION
+
/* assume C89 semantics that RETSIGTYPE is always void */
#undef RETSIGTYPE
@@ -1086,6 +1090,9 @@
/* Define to 1 if libintl is needed for locale functions. */
#undef WITH_LIBINTL
+/* Use LLVM for code generation. This makes things fast. */
+#undef WITH_LLVM
+
/* Define if you want to produce an OpenStep/Rhapsody framework (shared
library plus accessory files). */
#undef WITH_NEXT_FRAMEWORK
More information about the Python-checkins
mailing list