Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
3ef50b1a
Commit
3ef50b1a
authored
Jan 07, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'rebase'
parents
3a338555
83fb05b6
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
168 additions
and
446 deletions
+168
-446
Makefile
Makefile
+9
-4
llvm_patches/0008-Add-llvm.experimental.patchpoint.double.patch
...atches/0008-Add-llvm.experimental.patchpoint.double.patch
+1
-3
llvm_patches/0010-Expose-getSymbolLoadAddress-through-LoadedObjectInfo.patch
...xpose-getSymbolLoadAddress-through-LoadedObjectInfo.patch
+41
-0
llvm_revision.txt
llvm_revision.txt
+1
-1
src/.clang-format
src/.clang-format
+1
-0
src/asm_writing/rewriter.cpp
src/asm_writing/rewriter.cpp
+4
-5
src/capi/errors.cpp
src/capi/errors.cpp
+1
-1
src/codegen/codegen.cpp
src/codegen/codegen.cpp
+15
-17
src/codegen/dis.cpp
src/codegen/dis.cpp
+0
-231
src/codegen/dis.h
src/codegen/dis.h
+0
-46
src/codegen/entry.cpp
src/codegen/entry.cpp
+5
-1
src/codegen/irgen.cpp
src/codegen/irgen.cpp
+5
-35
src/codegen/irgen/irgenerator.cpp
src/codegen/irgen/irgenerator.cpp
+9
-7
src/codegen/memmgr.cpp
src/codegen/memmgr.cpp
+2
-2
src/codegen/memmgr.h
src/codegen/memmgr.h
+2
-1
src/codegen/profiling/dumprof.cpp
src/codegen/profiling/dumprof.cpp
+4
-3
src/codegen/profiling/oprofile.cpp
src/codegen/profiling/oprofile.cpp
+10
-11
src/codegen/profiling/pprof.cpp
src/codegen/profiling/pprof.cpp
+10
-11
src/codegen/stackmaps.cpp
src/codegen/stackmaps.cpp
+10
-32
src/codegen/unwinding.cpp
src/codegen/unwinding.cpp
+17
-30
tools/find_problem.py
tools/find_problem.py
+16
-2
tools/git_svn_gotorev.py
tools/git_svn_gotorev.py
+2
-0
tools/publicize.cpp
tools/publicize.cpp
+3
-3
No files found.
Makefile
View file @
3ef50b1a
...
...
@@ -366,9 +366,14 @@ endef
.PHONY
:
format check_format
format
:
cd
src
&&
find
\(
-name
'*.cpp'
-o
-name
'*.h'
\)
-print0
| xargs
-0
$(LLVM_BIN)
/clang-format
-style
=
file
-i
ifneq
($(USE_CMAKE),1)
check_format
:
$(ECHO)
checking formatting...
$(VERB)
cd
src
&&
../tools/check_format.sh
$(LLVM_BIN)
/clang-format
else
check_format
:
$(NINJA)
-C
$(HOME)
/pyston-build-release check-format
endif
.PHONY
:
analyze
analyze
:
...
...
@@ -741,12 +746,12 @@ endef
$(call link,_grwl,stdlib.grwl.bc.o $(SRCS
:
.cpp=.grwl.o)
,
$(LDFLAGS_RELEASE)
,
$(LLVM_RELEASE_DEPS))
$(call link,_grwl_dbg,stdlib.grwl_dbg.bc.o $(SRCS
:
.cpp=.grwl_dbg.o)
,
$(LDFLAGS)
,
$(LLVM_DEPS))
$(call link,_nosync,stdlib.nosync.bc.o $(SRCS
:
.cpp=.nosync.o)
,
$(LDFLAGS_RELEASE)
,
$(LLVM_RELEASE_DEPS))
pyston_oprof
:
$(OPT_OBJS) codegen/profiling/oprofile.o $(LLVM_DEPS)
pyston_oprof
:
$(OPT_OBJS)
src/
codegen/profiling/oprofile.o $(LLVM_DEPS)
$(ECHO)
Linking
$@
$(VERB)
$(CXX)
$(OPT_OBJS)
codegen/profiling/oprofile.o
$(LDFLAGS_RELEASE)
-lopagent
-o
$@
pyston_pprof
:
$(OPT_OBJS) codegen/profiling/pprof.release.o $(LLVM_DEPS)
$(VERB)
$(CXX)
$(OPT_OBJS)
src/
codegen/profiling/oprofile.o
$(LDFLAGS_RELEASE)
-lopagent
-o
$@
pyston_pprof
:
$(OPT_OBJS)
src/
codegen/profiling/pprof.release.o $(LLVM_DEPS)
$(ECHO)
Linking
$@
$(VERB)
$(CXX)
$(OPT_OBJS)
codegen/profiling/pprof.release.o
$(LDFLAGS_RELEASE)
-lprofiler
-o
$@
$(VERB)
$(CXX)
$(OPT_OBJS)
src/
codegen/profiling/pprof.release.o
$(LDFLAGS_RELEASE)
-lprofiler
-o
$@
pyston_prof
:
$(PROFILE_OBJS) $(LLVM_DEPS)
$(ECHO)
Linking
$@
$(VERB)
$(CXX)
$(PROFILE_OBJS)
$(LDFLAGS)
-pg
-o
$@
...
...
llvm_patches/0008-Add-llvm.experimental.patchpoint.double.patch
View file @
3ef50b1a
...
...
@@ -35,7 +35,7 @@ diff --git a/include/llvm/IR/Intrinsics.td b/include/llvm/IR/Intrinsics.td
index 1b9339a..45eecca 100644
--- a/include/llvm/IR/Intrinsics.td
+++ b/include/llvm/IR/Intrinsics.td
@@ -490,
6 +490,11
@@
def int_experimental_patchpoint_i64 : Intrinsic<[llvm_i64_ty],
@@ -490,
4 +490,9
@@
def int_experimental_patchpoint_i64 : Intrinsic<[llvm_i64_ty],
llvm_ptr_ty, llvm_i32_ty,
llvm_vararg_ty],
[Throws]>;
...
...
@@ -45,8 +45,6 @@ index 1b9339a..45eecca 100644
+ llvm_vararg_ty],
+ [Throws]>;
//===-------------------------- Other Intrinsics --------------------------===//
//
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index 72390a9..b624a63 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
...
...
llvm_patches/0010-Expose-getSymbolLoadAddress-through-LoadedObjectInfo.patch
0 → 100644
View file @
3ef50b1a
From 0fdc4cdde6c1642c2860a41af31f10f85153f1f6 Mon Sep 17 00:00:00 2001
From: Kevin Modzelewski <kevmod@gmail.com>
Date: Mon, 5 Jan 2015 04:10:04 +0000
Subject: [PATCH] Expose getSymbolLoadAddress through LoadedObjectInfo
---
include/llvm/ExecutionEngine/RuntimeDyld.h | 1 +
lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/include/llvm/ExecutionEngine/RuntimeDyld.h b/include/llvm/ExecutionEngine/RuntimeDyld.h
index 799fc34..ae8d699 100644
--- a/include/llvm/ExecutionEngine/RuntimeDyld.h
+++ b/include/llvm/ExecutionEngine/RuntimeDyld.h
@@ -60,6 +60,7 @@
public:
virtual object::OwningBinary<object::ObjectFile>
getObjectForDebug(const object::ObjectFile &Obj) const = 0;
+ uint64_t getSymbolLoadAddress(StringRef Name) const;
uint64_t getSectionLoadAddress(StringRef Name) const;
protected:
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index 00ac869..f7c5934 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -742,6 +742,11 @@
uint64_t RuntimeDyld::LoadedObjectInfo::getSectionLoadAddress(
return 0;
}
+uint64_t RuntimeDyld::LoadedObjectInfo::getSymbolLoadAddress(
+ StringRef SymbolName) const {
+ return RTDyld.getSymbolLoadAddress(SymbolName);
+}
+
RuntimeDyld::RuntimeDyld(RTDyldMemoryManager *mm) {
// FIXME: There's a potential issue lurking here if a single instance of
// RuntimeDyld is used to load multiple objects. The current implementation
--
1.9.1
llvm_revision.txt
View file @
3ef50b1a
22
2284
22
5000
src/.clang-format
View file @
3ef50b1a
...
...
@@ -2,6 +2,7 @@ BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: true # new in clang rev 222284
AlignOperands: true # new in clang rev 223117
AlignTrailingComments: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
...
...
src/asm_writing/rewriter.cpp
View file @
3ef50b1a
...
...
@@ -901,10 +901,9 @@ void Rewriter::finishAssembly(int continue_offset) {
void
Rewriter
::
commitReturning
(
RewriterVar
*
var
)
{
addAction
([
=
]()
{
var
->
getInReg
(
getReturnDestination
(),
true
/* allow_constant_in_reg */
);
var
->
bumpUse
();
},
{
var
},
ActionType
::
NORMAL
);
var
->
getInReg
(
getReturnDestination
(),
true
/* allow_constant_in_reg */
);
var
->
bumpUse
();
},
{
var
},
ActionType
::
NORMAL
);
commit
();
}
...
...
@@ -1214,7 +1213,7 @@ void Rewriter::addLocationToVar(RewriterVar* var, Location l) {
assert
(
vars_by_location
.
count
(
l
)
==
0
);
ASSERT
(
l
.
type
==
Location
::
Register
||
l
.
type
==
Location
::
XMMRegister
||
l
.
type
==
Location
::
Scratch
||
l
.
type
==
Location
::
Stack
,
||
l
.
type
==
Location
::
Stack
,
"%d"
,
l
.
type
);
var
->
locations
.
insert
(
l
);
...
...
src/capi/errors.cpp
View file @
3ef50b1a
...
...
@@ -65,7 +65,7 @@ extern "C" PyObject* PyErr_SetFromErrnoWithFilenameObject(PyObject* exc, PyObjec
s
=
_sys_errlist
[
i
];
}
else
{
int
len
=
FormatMessage
(
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_FROM_SYSTEM
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
|
FORMAT_MESSAGE_IGNORE_INSERTS
,
NULL
,
/* no message source */
i
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
/* Default language */
...
...
src/codegen/codegen.cpp
View file @
3ef50b1a
...
...
@@ -20,9 +20,10 @@
#include <unistd.h>
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/FileSystem.h"
#include "analysis/scoping_analysis.h"
#include "core/ast.h"
...
...
@@ -154,20 +155,15 @@ std::string FunctionAddressRegistry::getFuncNameAtAddress(void* addr, bool deman
class
RegistryEventListener
:
public
llvm
::
JITEventListener
{
public:
void
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
)
{
virtual
void
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
)
{
static
StatCounter
code_bytes
(
"code_bytes"
);
code_bytes
.
log
(
Obj
.
getData
().
size
());
llvm_error_code
code
;
for
(
llvm
::
object
::
symbol_iterator
I
=
Obj
.
begin_symbols
(),
E
=
Obj
.
end_symbols
();
I
!=
E
;
#if LLVMREV < 200442
I
=
I
.
increment
(
code
)
#else
++
I
#endif
)
{
llvm
::
object
::
section_iterator
section
(
Obj
.
end_sections
());
code
=
I
->
getSection
(
section
);
for
(
const
auto
&
sym
:
Obj
.
symbols
())
{
llvm
::
object
::
section_iterator
section
(
Obj
.
section_end
());
code
=
sym
.
getSection
(
section
);
assert
(
!
code
);
bool
is_text
;
#if LLVMREV < 219314
...
...
@@ -180,18 +176,20 @@ public:
continue
;
llvm
::
StringRef
name
;
uint64_t
addr
,
size
;
code
=
I
->
getName
(
name
);
assert
(
!
code
);
code
=
I
->
getAddress
(
addr
);
code
=
sym
.
getName
(
name
);
assert
(
!
code
);
code
=
I
->
getSize
(
size
);
uint64_t
size
;
code
=
sym
.
getSize
(
size
);
assert
(
!
code
);
if
(
name
==
".text"
)
continue
;
g
.
func_addr_registry
.
registerFunction
(
name
.
data
(),
(
void
*
)
addr
,
size
,
NULL
);
uint64_t
sym_addr
=
L
.
getSymbolLoadAddress
(
name
);
assert
(
sym_addr
);
g
.
func_addr_registry
.
registerFunction
(
name
.
data
(),
(
void
*
)
sym_addr
,
size
,
NULL
);
}
}
};
...
...
src/codegen/dis.cpp
deleted
100644 → 0
View file @
3a338555
// Copyright (c) 2014-2015 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "codegen/dis.h"
#if LLVMREV < 216983
#include <cstdio>
#include <iostream>
#include <unordered_map>
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
#include "llvm/IR/Mangler.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAtom.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler.h"
#include "llvm/MC/MCFunction.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCModule.h"
#include "llvm/MC/MCObjectDisassembler.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "codegen/codegen.h"
namespace
pyston
{
DisassemblerJITEventListener
::
DisassemblerJITEventListener
()
{
llvm
::
InitializeNativeTargetAsmPrinter
();
llvm
::
InitializeNativeTargetAsmParser
();
llvm
::
InitializeNativeTargetDisassembler
();
std
::
string
err
;
const
llvm
::
Target
*
target
=
llvm
::
TargetRegistry
::
getClosestTargetForJIT
(
err
);
assert
(
target
);
const
llvm
::
StringRef
triple
=
g
.
tm
->
getTargetTriple
();
// llvm::Triple *ltriple = new llvm::Triple(triple);
const
llvm
::
StringRef
CPU
=
""
;
const
llvm
::
MCRegisterInfo
*
MRI
=
target
->
createMCRegInfo
(
triple
);
assert
(
MRI
);
const
llvm
::
MCAsmInfo
*
MAI
=
target
->
createMCAsmInfo
(
*
MRI
,
triple
);
assert
(
MAI
);
const
llvm
::
MCInstrInfo
*
MII
=
target
->
createMCInstrInfo
();
assert
(
MII
);
std
::
string
FeaturesStr
;
const
llvm
::
MCSubtargetInfo
*
STI
=
target
->
createMCSubtargetInfo
(
triple
,
CPU
,
FeaturesStr
);
assert
(
STI
);
llvm
::
MCObjectFileInfo
*
MOFI
=
new
llvm
::
MCObjectFileInfo
();
llvm
::
MCContext
*
Ctx
=
new
llvm
::
MCContext
(
MAI
,
MRI
,
MOFI
);
assert
(
Ctx
);
assert
(
Ctx
->
getObjectFileInfo
());
MOFI
->
InitMCObjectFileInfo
(
triple
,
llvm
::
Reloc
::
Default
,
llvm
::
CodeModel
::
Default
,
*
Ctx
);
llvm
::
MCAsmBackend
*
TAB
=
target
->
createMCAsmBackend
(
*
MRI
,
triple
,
CPU
);
assert
(
TAB
);
int
AsmPrinterVariant
=
MAI
->
getAssemblerDialect
();
// 0 is ATT, 1 is Intel
IP
=
target
->
createMCInstPrinter
(
AsmPrinterVariant
,
*
MAI
,
*
MII
,
*
MRI
,
*
STI
);
assert
(
IP
);
llvm
::
MCCodeEmitter
*
CE
=
target
->
createMCCodeEmitter
(
*
MII
,
*
MRI
,
*
STI
,
*
Ctx
);
assert
(
CE
);
bool
verbose
=
false
;
#if LLVMREV < 208205
llvm
::
MCStreamer
*
streamer
=
target
->
createAsmStreamer
(
*
Ctx
,
llvm
::
ferrs
(),
verbose
,
true
,
true
,
IP
,
CE
,
TAB
,
true
);
#else
llvm
::
MCStreamer
*
streamer
=
target
->
createAsmStreamer
(
*
Ctx
,
llvm
::
ferrs
(),
verbose
,
true
,
IP
,
CE
,
TAB
,
true
);
#endif
assert
(
streamer
);
streamer
->
InitSections
();
streamer
->
SwitchSection
(
Ctx
->
getObjectFileInfo
()
->
getTextSection
());
asm_printer
=
target
->
createAsmPrinter
(
*
g
.
tm
,
*
streamer
);
assert
(
asm_printer
);
llvm
::
TargetOptions
Options
;
llvm
::
TargetMachine
*
tmachine
=
target
->
createTargetMachine
(
triple
,
""
,
""
,
Options
,
llvm
::
Reloc
::
Default
,
llvm
::
CodeModel
::
Default
,
llvm
::
CodeGenOpt
::
Default
);
// asm_printer->Mang = new llvm::Mangler(*Ctx, *tmachine->getDataLayout());
asm_printer
->
Mang
=
new
llvm
::
Mangler
(
tmachine
->
getDataLayout
());
DisAsm
=
target
->
createMCDisassembler
(
*
STI
,
*
Ctx
);
assert
(
DisAsm
);
MIA
=
target
->
createMCInstrAnalysis
(
MII
);
assert
(
MIA
);
}
void
DisassemblerJITEventListener
::
NotifyFunctionEmitted
(
const
llvm
::
Function
&
f
,
void
*
ptr
,
size_t
size
,
const
llvm
::
JITEvent_EmittedFunctionDetails
&
details
)
{
const
llvm
::
MachineFunction
&
MF
=
*
details
.
MF
;
//*const_cast<llvm::MachineFunction*>(details.MF);
printf
(
"emitted! %p %ld %s
\n
"
,
ptr
,
size
,
f
.
getName
().
data
());
// MF.dump();
// MF.print(llvm::errs());
asm_printer
->
MF
=
&
MF
;
for
(
llvm
::
MachineFunction
::
const_iterator
it
=
MF
.
begin
();
it
!=
MF
.
end
();
it
++
)
{
// it->dump();
asm_printer
->
EmitBasicBlockStart
(
*
it
);
for
(
llvm
::
MachineBasicBlock
::
const_instr_iterator
it2
=
it
->
instr_begin
();
it2
!=
it
->
instr_end
();
it2
++
)
{
// llvm::errs() << "dump:";
// it2->print(llvm::errs());
if
(
it2
->
getNumOperands
()
&&
(
it2
->
getOperand
(
0
).
getType
()
==
llvm
::
MachineOperand
::
MO_MCSymbol
))
{
// it2->print(llvm::errs());
// it2->getOperand(0).print(llvm::errs());
llvm
::
errs
()
<<
it2
->
getOperand
(
0
).
getMCSymbol
()
->
getName
()
<<
'\n'
;
}
else
{
asm_printer
->
EmitInstruction
(
it2
);
}
}
}
llvm
::
errs
()
<<
'\n'
;
llvm
::
errs
().
flush
();
}
void
DisassemblerJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
)
{
llvm
::
outs
()
<<
"An object has been emitted:
\n
"
;
llvm
::
error_code
code
;
for
(
llvm
::
object
::
section_iterator
I
=
Obj
.
begin_sections
(),
E
=
Obj
.
end_sections
();
I
!=
E
;)
{
llvm
::
StringRef
name
;
code
=
I
->
getName
(
name
);
assert
(
!
code
);
uint64_t
address
,
size
;
const
char
*
type
=
"unknown"
;
bool
b
;
code
=
I
->
isText
(
b
);
assert
(
!
code
);
if
(
b
)
type
=
"text"
;
code
=
I
->
isData
(
b
);
assert
(
!
code
);
if
(
b
)
type
=
"data"
;
code
=
I
->
isBSS
(
b
);
assert
(
!
code
);
if
(
b
)
type
=
"bss"
;
code
=
I
->
isReadOnlyData
(
b
);
assert
(
!
code
);
if
(
b
)
type
=
"rodata"
;
code
=
I
->
getAddress
(
address
);
assert
(
!
code
);
code
=
I
->
getSize
(
size
);
assert
(
!
code
);
printf
(
"Section: %s %s (%lx %lx)
\n
"
,
name
.
data
(),
type
,
address
,
size
);
#if LLVMREV < 200442
I
=
I
.
increment
(
code
);
#else
++
I
;
#endif
}
for
(
llvm
::
object
::
symbol_iterator
I
=
Obj
.
begin_symbols
(),
E
=
Obj
.
end_symbols
();
I
!=
E
;)
{
llvm
::
StringRef
name
;
uint64_t
addr
,
size
;
code
=
I
->
getName
(
name
);
assert
(
!
code
);
code
=
I
->
getAddress
(
addr
);
assert
(
!
code
);
code
=
I
->
getSize
(
size
);
assert
(
!
code
);
printf
(
"%lx %lx %s
\n
"
,
addr
,
addr
+
size
,
name
.
data
());
#if LLVMREV < 200442
I
=
I
.
increment
(
code
);
#else
++
I
;
#endif
}
llvm
::
MCObjectDisassembler
*
OD
=
new
llvm
::
MCObjectDisassembler
(
*
Obj
.
getObjectFile
(),
*
DisAsm
,
*
MIA
);
llvm
::
MCModule
*
Mod
=
OD
->
buildModule
(
true
);
// This is taken from llvm-objdump.cpp:
uint64_t
text_start
=
0
;
for
(
llvm
::
MCModule
::
const_atom_iterator
AI
=
Mod
->
atom_begin
(),
AE
=
Mod
->
atom_end
();
AI
!=
AE
;
++
AI
)
{
llvm
::
outs
()
<<
"Atom "
<<
(
*
AI
)
->
getName
()
<<
", starts at "
<<
(
void
*
)(
*
AI
)
->
getBeginAddr
()
<<
":
\n
"
;
if
((
*
AI
)
->
getName
()
==
".text"
)
text_start
=
(
*
AI
)
->
getBeginAddr
();
if
(
const
llvm
::
MCTextAtom
*
TA
=
llvm
::
dyn_cast
<
llvm
::
MCTextAtom
>
(
*
AI
))
{
for
(
llvm
::
MCTextAtom
::
const_iterator
II
=
TA
->
begin
(),
IE
=
TA
->
end
();
II
!=
IE
;
++
II
)
{
llvm
::
outs
()
<<
"0x"
;
llvm
::
outs
().
write_hex
(
II
->
Address
);
// llvm::outs() << " (+0x";
// llvm::outs().write_hex(II->Address - text_start);
llvm
::
outs
()
<<
" (+"
<<
II
->
Address
-
text_start
;
llvm
::
outs
()
<<
") "
;
IP
->
printInst
(
&
II
->
Inst
,
llvm
::
outs
(),
""
);
llvm
::
outs
()
<<
"
\n
"
;
}
}
}
llvm
::
outs
().
flush
();
}
}
#endif
src/codegen/dis.h
deleted
100644 → 0
View file @
3a338555
// Copyright (c) 2014-2015 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef PYSTON_CODEGEN_DIS_H
#define PYSTON_CODEGEN_DIS_H
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
namespace
llvm
{
class
MCDisassembler
;
class
MCInstrAnalysis
;
class
MCInstPrinter
;
}
namespace
pyston
{
class
DisassemblerJITEventListener
:
public
llvm
::
JITEventListener
{
private:
llvm
::
AsmPrinter
*
asm_printer
;
llvm
::
MCDisassembler
*
DisAsm
;
llvm
::
MCInstrAnalysis
*
MIA
;
llvm
::
MCInstPrinter
*
IP
;
public:
DisassemblerJITEventListener
();
virtual
void
NotifyFunctionEmitted
(
const
llvm
::
Function
&
f
,
void
*
ptr
,
size_t
size
,
const
llvm
::
JITEvent_EmittedFunctionDetails
&
details
);
virtual
void
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
);
};
}
#endif
src/codegen/entry.cpp
View file @
3ef50b1a
...
...
@@ -21,6 +21,7 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/IR/IRBuilder.h"
...
...
@@ -35,7 +36,6 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "codegen/codegen.h"
#include "codegen/dis.h"
#include "codegen/memmgr.h"
#include "codegen/profiling/profiling.h"
#include "codegen/stackmaps.h"
...
...
@@ -199,7 +199,11 @@ void initCodegen() {
#endif
eb
.
setEngineKind
(
llvm
::
EngineKind
::
JIT
);
// specify we only want the JIT, and not the interpreter fallback
#if LLVMREV < 223183
eb
.
setMCJITMemoryManager
(
createMemoryManager
().
release
());
#else
eb
.
setMCJITMemoryManager
(
createMemoryManager
());
#endif
// eb.setOptLevel(llvm::CodeGenOpt::None); // -O0
// eb.setOptLevel(llvm::CodeGenOpt::Less); // -O1
// eb.setOptLevel(llvm::CodeGenOpt::Default); // -O2, -Os
...
...
src/codegen/irgen.cpp
View file @
3ef50b1a
...
...
@@ -63,17 +63,6 @@ void MyInserter::InsertHelper(llvm::Instruction* I, const llvm::Twine& Name, llv
llvm
::
IRBuilderDefaultInserter
<
true
>::
InsertHelper
(
I
,
Name
,
BB
,
InsertPt
);
}
static
void
addIRDebugSymbols
(
llvm
::
Function
*
f
)
{
llvm
::
legacy
::
PassManager
mpm
;
llvm_error_code
code
=
llvm
::
sys
::
fs
::
create_directory
(
".debug_ir"
,
true
);
assert
(
!
code
);
mpm
.
add
(
llvm
::
createDebugIRPass
(
false
,
false
,
".debug_ir"
,
f
->
getName
()));
mpm
.
run
(
*
g
.
cur_module
);
}
static
void
optimizeIR
(
llvm
::
Function
*
f
,
EffortLevel
::
EffortLevel
effort
)
{
// TODO maybe should do some simple passes (ex: gvn?) if effort level isn't maximal?
// In general, this function needs a lot of tuning.
...
...
@@ -638,9 +627,10 @@ static void emitBBs(IRGenState* irstate, const char* bb_type, GuardList& out_gua
llvm
::
Value
*
reopt_test
=
emitter
->
getBuilder
()
->
CreateICmpSGT
(
new_call_count
,
getConstantInt
(
REOPT_THRESHOLDS
[
effort
],
g
.
i64
));
llvm
::
Value
*
md_vals
[]
=
{
llvm
::
MDString
::
get
(
g
.
context
,
"branch_weights"
),
getConstantInt
(
1
),
getConstantInt
(
1000
)
};
llvm
::
MDNode
*
branch_weights
=
llvm
::
MDNode
::
get
(
g
.
context
,
llvm
::
ArrayRef
<
llvm
::
Value
*>
(
md_vals
));
llvm
::
Metadata
*
md_vals
[]
=
{
llvm
::
MDString
::
get
(
g
.
context
,
"branch_weights"
),
llvm
::
ConstantAsMetadata
::
get
(
getConstantInt
(
1
)),
llvm
::
ConstantAsMetadata
::
get
(
getConstantInt
(
1000
))
};
llvm
::
MDNode
*
branch_weights
=
llvm
::
MDNode
::
get
(
g
.
context
,
llvm
::
ArrayRef
<
llvm
::
Metadata
*>
(
md_vals
));
llvm
::
BranchInst
*
guard
=
emitter
->
getBuilder
()
->
CreateCondBr
(
reopt_test
,
reopt_bb
,
llvm_entry_blocks
[
source
->
cfg
->
getStartingBlock
()],
branch_weights
);
...
...
@@ -1066,29 +1056,15 @@ static llvm::MDNode* setupDebugInfo(SourceInfo* source, llvm::Function* f, std::
std
::
string
producer
=
"pyston; git rev "
STRINGIFY
(
GITREV
);
llvm
::
DIFile
file
=
builder
.
createFile
(
fn
,
dir
);
#if LLVMREV < 214132
llvm
::
DIArray
param_types
=
builder
.
getOrCreateArray
(
llvm
::
None
);
#else
llvm
::
DITypeArray
param_types
=
builder
.
getOrCreateTypeArray
(
llvm
::
None
);
#endif
llvm
::
DICompositeType
func_type
=
builder
.
createSubroutineType
(
file
,
param_types
);
llvm
::
DISubprogram
func_info
=
builder
.
createFunction
(
file
,
f
->
getName
(),
f
->
getName
(),
file
,
lineno
,
func_type
,
false
,
true
,
lineno
+
1
,
0
,
true
,
f
);
// The 'variables' field gets initialized with a tag-prefixed array, but
// a later verifier asserts that there is no tag. Replace it with an empty array:
func_info
.
getVariables
()
->
replaceAllUsesWith
(
builder
.
getOrCreateArray
(
llvm
::
ArrayRef
<
llvm
::
Value
*>
()));
llvm
::
DICompileUnit
compile_unit
=
builder
.
createCompileUnit
(
llvm
::
dwarf
::
DW_LANG_Python
,
fn
,
dir
,
producer
,
true
,
""
,
0
);
llvm
::
DIArray
subprograms
=
builder
.
getOrCreateArray
(
&*
func_info
);
compile_unit
.
getSubprograms
()
->
replaceAllUsesWith
(
subprograms
);
compile_unit
.
getEnumTypes
()
->
replaceAllUsesWith
(
builder
.
getOrCreateArray
(
llvm
::
ArrayRef
<
llvm
::
Value
*>
()));
compile_unit
.
getRetainedTypes
()
->
replaceAllUsesWith
(
builder
.
getOrCreateArray
(
llvm
::
ArrayRef
<
llvm
::
Value
*>
()));
compile_unit
.
getGlobalVariables
()
->
replaceAllUsesWith
(
builder
.
getOrCreateArray
(
llvm
::
ArrayRef
<
llvm
::
Value
*>
()));
compile_unit
.
getImportedEntities
()
->
replaceAllUsesWith
(
builder
.
getOrCreateArray
(
llvm
::
ArrayRef
<
llvm
::
Value
*>
()));
builder
.
finalize
();
return
func_info
;
}
...
...
@@ -1259,12 +1235,6 @@ CompiledFunction* doCompile(SourceInfo* source, const OSREntryDescriptor* entry_
if
(
ENABLE_LLVMOPTS
)
optimizeIR
(
f
,
effort
);
bool
ENABLE_IR_DEBUG
=
false
;
if
(
ENABLE_IR_DEBUG
)
{
addIRDebugSymbols
(
f
);
// dumpPrettyIR(f);
}
g
.
cur_module
=
NULL
;
return
cf
;
...
...
src/codegen/irgen/irgenerator.cpp
View file @
3ef50b1a
...
...
@@ -320,9 +320,10 @@ private:
void
createExprTypeGuard
(
llvm
::
Value
*
check_val
,
AST_expr
*
node
,
CompilerVariable
*
node_value
)
{
assert
(
check_val
->
getType
()
==
g
.
i1
);
llvm
::
Value
*
md_vals
[]
=
{
llvm
::
MDString
::
get
(
g
.
context
,
"branch_weights"
),
getConstantInt
(
1000
),
getConstantInt
(
1
)
};
llvm
::
MDNode
*
branch_weights
=
llvm
::
MDNode
::
get
(
g
.
context
,
llvm
::
ArrayRef
<
llvm
::
Value
*>
(
md_vals
));
llvm
::
Metadata
*
md_vals
[]
=
{
llvm
::
MDString
::
get
(
g
.
context
,
"branch_weights"
),
llvm
::
ConstantAsMetadata
::
get
(
getConstantInt
(
1000
)),
llvm
::
ConstantAsMetadata
::
get
(
getConstantInt
(
1
))
};
llvm
::
MDNode
*
branch_weights
=
llvm
::
MDNode
::
get
(
g
.
context
,
llvm
::
ArrayRef
<
llvm
::
Metadata
*>
(
md_vals
));
// For some reason there doesn't seem to be the ability to place the new BB
// right after the current bb (can only place it *before* something else),
...
...
@@ -717,7 +718,7 @@ private:
void
_addAnnotation
(
const
char
*
message
)
{
llvm
::
Instruction
*
inst
=
emitter
.
getBuilder
()
->
CreateCall
(
llvm
::
Intrinsic
::
getDeclaration
(
g
.
cur_module
,
llvm
::
Intrinsic
::
donothing
));
llvm
::
Value
*
md_vals
[]
=
{
getConstantInt
(
0
)
};
llvm
::
Metadata
*
md_vals
[]
=
{
llvm
::
ConstantAsMetadata
::
get
(
getConstantInt
(
0
)
)
};
llvm
::
MDNode
*
mdnode
=
llvm
::
MDNode
::
get
(
g
.
context
,
md_vals
);
inst
->
setMetadata
(
message
,
mdnode
);
}
...
...
@@ -1855,9 +1856,10 @@ private:
OSR_THRESHOLD
=
100
;
llvm
::
Value
*
osr_test
=
emitter
.
getBuilder
()
->
CreateICmpSGT
(
newcount
,
getConstantInt
(
OSR_THRESHOLD
));
llvm
::
Value
*
md_vals
[]
=
{
llvm
::
MDString
::
get
(
g
.
context
,
"branch_weights"
),
getConstantInt
(
1
),
getConstantInt
(
1000
)
};
llvm
::
MDNode
*
branch_weights
=
llvm
::
MDNode
::
get
(
g
.
context
,
llvm
::
ArrayRef
<
llvm
::
Value
*>
(
md_vals
));
llvm
::
Metadata
*
md_vals
[]
=
{
llvm
::
MDString
::
get
(
g
.
context
,
"branch_weights"
),
llvm
::
ConstantAsMetadata
::
get
(
getConstantInt
(
1
)),
llvm
::
ConstantAsMetadata
::
get
(
getConstantInt
(
1000
))
};
llvm
::
MDNode
*
branch_weights
=
llvm
::
MDNode
::
get
(
g
.
context
,
llvm
::
ArrayRef
<
llvm
::
Metadata
*>
(
md_vals
));
emitter
.
getBuilder
()
->
CreateCondBr
(
osr_test
,
onramp
,
normal_target
,
branch_weights
);
// Emitting the actual OSR:
...
...
src/codegen/memmgr.cpp
View file @
3ef50b1a
...
...
@@ -227,8 +227,8 @@ PystonMemoryManager::~PystonMemoryManager() {
sys
::
Memory
::
releaseMappedMemory
(
RODataMem
.
AllocatedMem
[
i
]);
}
llvm
::
RTDyldMemoryManager
*
createMemoryManager
()
{
return
new
PystonMemoryManager
(
);
std
::
unique_ptr
<
llvm
::
RTDyldMemoryManager
>
createMemoryManager
()
{
return
std
::
unique_ptr
<
llvm
::
RTDyldMemoryManager
>
(
new
PystonMemoryManager
()
);
}
// These functions exist as instance methods of the RTDyldMemoryManager class,
...
...
src/codegen/memmgr.h
View file @
3ef50b1a
...
...
@@ -17,6 +17,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
namespace
llvm
{
class
RTDyldMemoryManager
;
...
...
@@ -24,7 +25,7 @@ class RTDyldMemoryManager;
namespace
pyston
{
llvm
::
RTDyldMemoryManager
*
createMemoryManager
();
std
::
unique_ptr
<
llvm
::
RTDyldMemoryManager
>
createMemoryManager
();
void
registerEHFrames
(
uint8_t
*
addr
,
uint64_t
load_addr
,
size_t
size
);
void
deregisterEHFrames
(
uint8_t
*
addr
,
uint64_t
load_addr
,
size_t
size
);
}
...
...
src/codegen/profiling/dumprof.cpp
View file @
3ef50b1a
...
...
@@ -15,7 +15,7 @@
#include <sstream>
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/
ExecutionEngine/ObjectImag
e.h"
#include "llvm/
Object/ObjectFil
e.h"
#include "codegen/profiling/profiling.h"
#include "core/common.h"
...
...
@@ -26,11 +26,12 @@ namespace pyston {
class
DumpJITEventListener
:
public
llvm
::
JITEventListener
{
private:
public:
virtual
void
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
);
virtual
void
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
);
};
static
int
num
=
0
;
void
DumpJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
)
{
void
DumpJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
)
{
llvm_error_code
code
;
std
::
ostringstream
os
(
""
);
...
...
src/codegen/profiling/oprofile.cpp
View file @
3ef50b1a
...
...
@@ -13,7 +13,7 @@
// limitations under the License.
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/
ExecutionEngine/ObjectImag
e.h"
#include "llvm/
Object/ObjectFil
e.h"
#include "opagent.h"
...
...
@@ -35,26 +35,26 @@ public:
virtual
~
OprofileJITEventListener
()
{
op_close_agent
(
agent
);
}
virtual
void
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
);
virtual
void
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
);
};
void
OprofileJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
)
{
void
OprofileJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
)
{
if
(
VERBOSITY
()
>=
1
)
printf
(
"An object has been emitted:
\n
"
);
llvm_error_code
code
;
for
(
llvm
::
object
::
symbol_iterator
I
=
Obj
.
begin_symbols
(),
E
=
Obj
.
end_symbols
();
I
!=
E
;
)
{
for
(
const
auto
&
sym
:
Obj
.
symbols
()
)
{
llvm
::
object
::
SymbolRef
::
Type
type
;
code
=
I
->
getType
(
type
);
code
=
sym
.
getType
(
type
);
assert
(
!
code
);
if
(
type
==
llvm
::
object
::
SymbolRef
::
ST_Function
)
{
llvm
::
StringRef
name
;
uint64_t
addr
,
size
;
code
=
I
->
getName
(
name
);
code
=
sym
.
getName
(
name
);
assert
(
!
code
);
code
=
I
->
getAddress
(
addr
);
assert
(
!
code
);
code
=
I
->
getSize
(
size
);
addr
=
L
.
getSymbolLoadAddress
(
name
);
code
=
sym
.
getSize
(
size
);
assert
(
!
code
);
if
(
VERBOSITY
()
>=
1
)
...
...
@@ -63,11 +63,10 @@ void OprofileJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj)
assert
(
r
==
0
);
//} else {
// llvm::StringRef name;
// code =
I->
getName(name);
// code =
sym.
getName(name);
// assert(!code);
// printf("Skipping %s\n", name.data());
}
++
I
;
}
}
...
...
src/codegen/profiling/pprof.cpp
View file @
3ef50b1a
...
...
@@ -13,7 +13,7 @@
// limitations under the License.
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/
ExecutionEngine/ObjectImag
e.h"
#include "llvm/
Object/ObjectFil
e.h"
#include "codegen/profiling/profiling.h"
#include "core/common.h"
...
...
@@ -29,23 +29,23 @@ public:
PprofJITEventListener
()
{
of
=
fopen
(
"pprof.jit"
,
"w"
);
}
virtual
~
PprofJITEventListener
()
{
fclose
(
of
);
}
virtual
void
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
);
virtual
void
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
);
};
void
PprofJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
)
{
llvm
::
error_code
code
;
for
(
llvm
::
object
::
symbol_iterator
I
=
Obj
.
begin_symbols
(),
E
=
Obj
.
end_symbols
();
I
!=
E
;)
{
void
PprofJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
)
{
llvm_error_code
code
;
for
(
const
auto
&
sym
:
Obj
.
symbols
())
{
llvm
::
object
::
SymbolRef
::
Type
type
;
code
=
I
->
getType
(
type
);
code
=
sym
.
getType
(
type
);
assert
(
!
code
);
if
(
type
==
llvm
::
object
::
SymbolRef
::
ST_Function
)
{
llvm
::
StringRef
name
;
uint64_t
addr
,
size
;
code
=
I
->
getName
(
name
);
code
=
sym
.
getName
(
name
);
assert
(
!
code
);
code
=
I
->
getAddress
(
addr
);
assert
(
!
code
);
code
=
I
->
getSize
(
size
);
addr
=
L
.
getSymbolLoadAddress
(
name
);
code
=
sym
.
getSize
(
size
);
assert
(
!
code
);
// fprintf(of, "%lx-%lx: %s\n", addr, addr + size, name.data());
...
...
@@ -55,7 +55,6 @@ void PprofJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
if
(
VERBOSITY
()
>=
1
)
printf
(
"%lx %lx %s
\n
"
,
addr
,
addr
+
size
,
name
.
data
());
}
++
I
;
}
}
...
...
src/codegen/stackmaps.cpp
View file @
3ef50b1a
...
...
@@ -21,7 +21,6 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/Object/ObjectFile.h"
#include "codegen/codegen.h"
...
...
@@ -43,7 +42,7 @@ StackMap* parseStackMap() {
class
StackmapJITEventListener
:
public
llvm
::
JITEventListener
{
private:
public:
virtual
void
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
);
virtual
void
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
);
};
// LLVM will silently not register the eh frames with libgcc if these functions don't exist;
...
...
@@ -57,23 +56,21 @@ extern void _force_link() {
__deregister_frame
(
nullptr
);
}
void
StackmapJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
)
{
void
StackmapJITEventListener
::
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
)
{
// llvm::outs() << "An object has been emitted:\n";
llvm_error_code
code
;
for
(
llvm
::
object
::
symbol_iterator
I
=
Obj
.
begin_symbols
(),
E
=
Obj
.
end_symbols
();
I
!=
E
;
)
{
for
(
const
auto
&
sec
:
Obj
.
sections
()
)
{
llvm
::
StringRef
name
;
code
=
I
->
getName
(
name
);
code
=
sec
.
getName
(
name
);
assert
(
!
code
);
if
(
name
==
"__LLVM_StackMaps"
)
{
uint64_t
stackmap_address
=
0
;
code
=
I
->
getAddress
(
stackmap_address
);
assert
(
!
code
);
// code = I->getSize(stackmap_size);
// assert(stackmap_size > 0);
// assert(!code);
if
(
name
==
".llvm_stackmaps"
)
{
uint64_t
stackmap_address
=
L
.
getSectionLoadAddress
(
name
);
assert
(
stackmap_address
>
0
);
if
(
VERBOSITY
()
>=
2
)
printf
(
"Found the stackmaps at stackmap_address 0x%lx
\n
"
,
stackmap_address
);
...
...
@@ -175,28 +172,9 @@ void StackmapJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj)
ptr
.
u32
++
;
// pad to 8-byte boundary
}
#ifndef NDEBUG
uint64_t
stackmap_size
;
llvm
::
object
::
section_iterator
section
(
Obj
.
end_sections
());
code
=
I
->
getSection
(
section
);
assert
(
!
code
);
#if LLVMREV < 219314
code
=
section
->
getSize
(
stackmap_size
);
assert
(
!
code
);
#else
stackmap_size
=
section
->
getSize
();
#endif
assert
(
stackmap_size
>
0
);
uint64_t
stackmap_size
=
sec
.
getSize
();
ASSERT
(
ptr
.
i8
-
start_ptr
==
stackmap_size
,
"%ld %ld"
,
ptr
.
i8
-
start_ptr
,
stackmap_size
);
#endif
}
#if LLVMREV < 200442
I
=
I
.
increment
(
code
);
#else
++
I
;
#endif
}
}
...
...
src/codegen/unwinding.cpp
View file @
3ef50b1a
...
...
@@ -20,8 +20,8 @@
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/Object/ObjectFile.h"
#include "codegen/ast_interpreter.h"
#include "codegen/codegen.h"
...
...
@@ -97,32 +97,33 @@ CompiledFunction* getCFForAddress(uint64_t addr) {
class
TracebacksEventListener
:
public
llvm
::
JITEventListener
{
public:
void
NotifyObjectEmitted
(
const
llvm
::
ObjectImage
&
Obj
)
{
std
::
unique_ptr
<
llvm
::
DIContext
>
Context
(
llvm
::
DIContext
::
getDWARFContext
(
*
Obj
.
getObjectFile
()));
virtual
void
NotifyObjectEmitted
(
const
llvm
::
object
::
ObjectFile
&
Obj
,
const
llvm
::
RuntimeDyld
::
LoadedObjectInfo
&
L
)
{
std
::
unique_ptr
<
llvm
::
DIContext
>
Context
(
llvm
::
DIContext
::
getDWARFContext
(
Obj
));
assert
(
g
.
cur_cf
);
llvm_error_code
ec
;
for
(
llvm
::
object
::
symbol_iterator
I
=
Obj
.
begin_symbols
(),
E
=
Obj
.
end_symbols
();
I
!=
E
&&
!
ec
;
++
I
)
{
for
(
const
auto
&
sym
:
Obj
.
symbols
()
)
{
llvm
::
object
::
SymbolRef
::
Type
SymType
;
if
(
I
->
getType
(
SymType
))
if
(
sym
.
getType
(
SymType
))
continue
;
if
(
SymType
==
llvm
::
object
::
SymbolRef
::
ST_Function
)
{
llvm
::
StringRef
Name
;
uint64_t
Addr
;
uint64_t
Size
;
if
(
I
->
getName
(
Name
))
if
(
sym
.
getName
(
Name
))
continue
;
if
(
I
->
getAddress
(
Addr
))
continue
;
if
(
I
->
getSize
(
Size
))
Addr
=
L
.
getSymbolLoadAddress
(
Name
);
assert
(
Addr
)
;
if
(
sym
.
getSize
(
Size
))
continue
;
// TODO this should be the Python name, not the C name:
#if LLVMREV < 208921
llvm
::
DILineInfoTable
lines
=
Context
->
getLineInfoForAddressRange
(
Addr
,
Size
,
llvm
::
DILineInfoSpecifier
::
FunctionName
|
llvm
::
DILineInfoSpecifier
::
FileLineInfo
|
llvm
::
DILineInfoSpecifier
::
AbsoluteFilePath
);
|
llvm
::
DILineInfoSpecifier
::
AbsoluteFilePath
);
#else
llvm
::
DILineInfoTable
lines
=
Context
->
getLineInfoForAddressRange
(
Addr
,
Size
,
llvm
::
DILineInfoSpecifier
(
llvm
::
DILineInfoSpecifier
::
FileLineInfoKind
::
AbsoluteFilePath
,
...
...
@@ -148,38 +149,24 @@ public:
uint64_t
text_addr
=
-
1
,
text_size
=
-
1
;
uint64_t
eh_frame_addr
=
-
1
,
eh_frame_size
=
-
1
;
for
(
llvm
::
object
::
section_iterator
I
=
Obj
.
begin_sections
(),
E
=
Obj
.
end_sections
();
I
!=
E
;
++
I
)
{
for
(
const
auto
&
sec
:
Obj
.
sections
()
)
{
llvm
::
StringRef
name
;
code
=
I
->
getName
(
name
);
code
=
sec
.
getName
(
name
);
assert
(
!
code
);
uint64_t
addr
,
size
;
if
(
name
==
".eh_frame"
)
{
assert
(
!
found_eh_frame
);
#if LLVMREV < 219314
if
(
I
->
getAddress
(
eh_frame_addr
))
continue
;
if
(
I
->
getSize
(
eh_frame_size
))
continue
;
#else
eh_frame_addr
=
I
->
getAddress
();
eh_frame_size
=
I
->
getSize
();
#endif
eh_frame_addr
=
L
.
getSectionLoadAddress
(
name
);
eh_frame_size
=
sec
.
getSize
();
if
(
VERBOSITY
())
printf
(
"eh_frame: %lx %lx
\n
"
,
eh_frame_addr
,
eh_frame_size
);
found_eh_frame
=
true
;
}
else
if
(
name
==
".text"
)
{
assert
(
!
found_text
);
#if LLVMREV < 219314
if
(
I
->
getAddress
(
text_addr
))
continue
;
if
(
I
->
getSize
(
text_size
))
continue
;
#else
text_addr
=
I
->
getAddress
();
text_size
=
I
->
getSize
();
#endif
text_addr
=
L
.
getSectionLoadAddress
(
name
);
text_size
=
sec
.
getSize
();
if
(
VERBOSITY
())
printf
(
"text: %lx %lx
\n
"
,
text_addr
,
text_size
);
...
...
tools/find_problem.py
View file @
3ef50b1a
...
...
@@ -22,9 +22,15 @@ def efficiency(rid):
return
learnt
/
effort
if
__name__
==
"__main__"
:
if
len
(
sys
.
argv
)
<
4
:
print
"Usage: python find_problem.py GOOD_REV BAD_REV make args"
print
" (anything after BAD_REV gets passed as arguments to a 'make' invocation)"
sys
.
exit
(
1
)
good_rev
,
bad_rev
=
sys
.
argv
[
1
:
3
]
good_rev
=
int
(
good_rev
)
bad_rev
=
int
(
bad_rev
)
assert
good_rev
<
bad_rev
args
=
sys
.
argv
[
3
:]
assert
args
...
...
@@ -37,22 +43,30 @@ if __name__ == "__main__":
# b = test(bad_rev, args)
# assert not b, "bad_rev must not work"
f
=
open
(
"find_problem.status"
,
"w"
)
f
.
write
(
"%d %d
\
n
"
%
(
good_rev
,
bad_rev
))
f
.
flush
()
while
bad_rev
>
good_rev
+
1
:
print
"%d is good, %d is bad"
%
(
good_rev
,
bad_rev
)
open
(
"find_problem.status"
,
"w"
).
write
(
"%d %d
\
n
"
%
(
good_rev
,
bad_rev
))
middle
=
(
good_rev
+
bad_rev
+
1
)
/
2
revs
=
range
(
good_rev
+
1
,
middle
+
1
)
revs
.
sort
(
reverse
=
True
,
key
=
efficiency
)
# print good_rev, bad_rev, (good_rev + bad_rev) / 2, revs[0]
next_rev
=
revs
[
0
]
print
>>
f
,
"Testing revision %d (p=%.1f%%)"
%
(
next_rev
,
100.0
*
(
next_rev
-
good_rev
)
/
(
bad_rev
-
good_rev
))
f
.
flush
()
print
"Testing revision %d (p=%.1f%%)"
%
(
next_rev
,
100.0
*
(
next_rev
-
good_rev
)
/
(
bad_rev
-
good_rev
))
b
=
test
(
next_rev
,
args
)
print
"Revision"
,
next_rev
,
"works"
if
b
else
"failed"
print
>>
f
,
"Revision"
,
next_rev
,
"works"
if
b
else
"failed"
f
.
flush
()
if
b
:
good_rev
=
next_rev
else
:
bad_rev
=
next_rev
open
(
"find_problem.status"
,
"w"
).
write
(
"%d %d
\
n
"
%
(
good_rev
,
bad_rev
))
print
"Rev %d is good, rev %d is bad"
%
(
good_rev
,
bad_rev
)
print
>>
f
,
"Rev %d is good, rev %d is bad"
%
(
good_rev
,
bad_rev
)
f
.
close
()
tools/git_svn_gotorev.py
View file @
3ef50b1a
...
...
@@ -89,6 +89,8 @@ if __name__ == "__main__":
continue
if
"support-varargs-intrinsics"
in
patch_fn
and
svn_rev
>=
220205
:
continue
if
"Expose-getSymbolLoadAddress"
in
patch_fn
and
svn_rev
<=
222840
:
continue
patch_fn
=
os
.
path
.
abspath
(
os
.
path
.
join
(
patch_dir
,
patch_fn
))
code
=
subprocess
.
call
([
"git"
,
"am"
,
patch_fn
],
cwd
=
repo
)
...
...
tools/publicize.cpp
View file @
3ef50b1a
...
...
@@ -140,16 +140,16 @@ bool updateTBAA(Function* f) {
assert
(
tbaa
->
getNumOperands
()
==
3
);
if
(
!
isConstant
(
llvm
::
cast
<
MDNode
>
(
tbaa
->
getOperand
(
0
)),
llvm
::
cast
<
ConstantInt
>
(
tbaa
->
getOperand
(
2
))
->
getSExtValue
()))
{
if
(
!
isConstant
(
llvm
::
cast
<
MDNode
>
(
tbaa
->
getOperand
(
0
)),
llvm
::
cast
<
ConstantInt
>
(
llvm
::
cast
<
ConstantAsMetadata
>
(
tbaa
->
getOperand
(
2
))
->
getValue
(
))
->
getSExtValue
()))
{
continue
;
}
std
::
vector
<
Value
*>
operands
;
std
::
vector
<
Metadata
*>
operands
;
for
(
int
i
=
0
;
i
<
tbaa
->
getNumOperands
();
i
++
)
{
operands
.
push_back
(
tbaa
->
getOperand
(
i
));
}
operands
.
push_back
(
Constant
Int
::
get
(
Type
::
getInt64Ty
(
c
),
1
));
operands
.
push_back
(
Constant
AsMetadata
::
get
(
ConstantInt
::
get
(
Type
::
getInt64Ty
(
c
),
1
)
));
MDNode
*
new_tbaa
=
MDNode
::
get
(
c
,
operands
);
it
->
setMetadata
(
LLVMContext
::
MD_tbaa
,
new_tbaa
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment