Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftshader
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
swiftshader
Commits
1eda90a1
Commit
1eda90a1
authored
Aug 04, 2015
by
Andrew Scull
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Order jump tables for deterministic or randomized emission.
BUG= R=stichnot@chromium.org, jvoung, stichnot Review URL:
https://codereview.chromium.org/1260183008
.
parent
c5c8957b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
17 deletions
+40
-17
IceGlobalContext.cpp
src/IceGlobalContext.cpp
+24
-3
IceGlobalContext.h
src/IceGlobalContext.h
+6
-5
IceSwitchLowering.h
src/IceSwitchLowering.h
+4
-3
IceTargetLoweringX8632.cpp
src/IceTargetLoweringX8632.cpp
+3
-3
IceTargetLoweringX8664.cpp
src/IceTargetLoweringX8664.cpp
+3
-3
No files found.
src/IceGlobalContext.cpp
View file @
1eda90a1
...
@@ -878,11 +878,32 @@ ConstantList GlobalContext::getConstantExternSyms() {
...
@@ -878,11 +878,32 @@ ConstantList GlobalContext::getConstantExternSyms() {
return
getConstPool
()
->
ExternRelocatables
.
getConstantPool
();
return
getConstPool
()
->
ExternRelocatables
.
getConstantPool
();
}
}
JumpTableDataList
GlobalContext
::
getJumpTables
()
{
JumpTableDataList
JumpTables
(
*
getJumpTableList
());
if
(
getFlags
().
shouldReorderPooledConstants
())
{
// If reorder-pooled-constants option is set to true, we need to shuffle the
// constant pool before emitting it.
RandomShuffle
(
JumpTables
.
begin
(),
JumpTables
.
end
(),
[
this
](
uint64_t
N
)
{
return
(
uint32_t
)
getRNG
().
next
(
N
);
});
}
else
{
// Make order deterministic by sorting into functions and then ID of the
// jump table within that function.
std
::
sort
(
JumpTables
.
begin
(),
JumpTables
.
end
(),
[](
const
JumpTableData
&
A
,
const
JumpTableData
&
B
)
{
if
(
A
.
getFunctionName
()
!=
B
.
getFunctionName
())
return
A
.
getFunctionName
()
<
B
.
getFunctionName
();
return
A
.
getId
()
<
B
.
getId
();
});
}
return
JumpTables
;
}
JumpTableData
&
GlobalContext
::
addJumpTable
(
IceString
FuncName
,
SizeT
Id
,
JumpTableData
&
GlobalContext
::
addJumpTable
(
IceString
FuncName
,
SizeT
Id
,
SizeT
NumTargets
)
{
SizeT
NumTargets
)
{
auto
JumpTable
s
=
getJumpTables
();
auto
JumpTable
List
=
getJumpTableList
();
JumpTable
s
->
emplace_back
(
FuncName
,
Id
,
NumTargets
);
JumpTable
List
->
emplace_back
(
FuncName
,
Id
,
NumTargets
);
return
JumpTable
s
->
back
();
return
JumpTable
List
->
back
();
}
}
TimerStackIdT
GlobalContext
::
newTimerStackID
(
const
IceString
&
Name
)
{
TimerStackIdT
GlobalContext
::
newTimerStackID
(
const
IceString
&
Name
)
{
...
...
src/IceGlobalContext.h
View file @
1eda90a1
...
@@ -212,9 +212,7 @@ public:
...
@@ -212,9 +212,7 @@ public:
ConstantList
getConstantExternSyms
();
ConstantList
getConstantExternSyms
();
/// Return a locked pointer to the registered jump tables.
/// Return a locked pointer to the registered jump tables.
LockedPtr
<
JumpTableDataList
>
getJumpTables
()
{
JumpTableDataList
getJumpTables
();
return
LockedPtr
<
JumpTableDataList
>
(
&
JumpTables
,
&
JumpTablesLock
);
}
/// Create a new jump table entry and return a reference to it.
/// Create a new jump table entry and return a reference to it.
JumpTableData
&
addJumpTable
(
IceString
FuncName
,
SizeT
Id
,
SizeT
NumTargets
);
JumpTableData
&
addJumpTable
(
IceString
FuncName
,
SizeT
Id
,
SizeT
NumTargets
);
...
@@ -467,9 +465,9 @@ private:
...
@@ -467,9 +465,9 @@ private:
std
::
unique_ptr
<
ConstantPool
>
ConstPool
;
std
::
unique_ptr
<
ConstantPool
>
ConstPool
;
ICE_CACHELINE_BOUNDARY
;
ICE_CACHELINE_BOUNDARY
;
// Managed by getJumpTable
s
()
// Managed by getJumpTable
List
()
GlobalLockType
JumpTablesLock
;
GlobalLockType
JumpTablesLock
;
JumpTableDataList
JumpTable
s
;
JumpTableDataList
JumpTable
List
;
ICE_CACHELINE_BOUNDARY
;
ICE_CACHELINE_BOUNDARY
;
// Managed by getErrorStatus()
// Managed by getErrorStatus()
...
@@ -522,6 +520,9 @@ private:
...
@@ -522,6 +520,9 @@ private:
LockedPtr
<
ConstantPool
>
getConstPool
()
{
LockedPtr
<
ConstantPool
>
getConstPool
()
{
return
LockedPtr
<
ConstantPool
>
(
ConstPool
.
get
(),
&
ConstPoolLock
);
return
LockedPtr
<
ConstantPool
>
(
ConstPool
.
get
(),
&
ConstPoolLock
);
}
}
LockedPtr
<
JumpTableDataList
>
getJumpTableList
()
{
return
LockedPtr
<
JumpTableDataList
>
(
&
JumpTableList
,
&
JumpTablesLock
);
}
LockedPtr
<
CodeStats
>
getStatsCumulative
()
{
LockedPtr
<
CodeStats
>
getStatsCumulative
()
{
return
LockedPtr
<
CodeStats
>
(
&
StatsCumulative
,
&
StatsLock
);
return
LockedPtr
<
CodeStats
>
(
&
StatsCumulative
,
&
StatsLock
);
}
}
...
...
src/IceSwitchLowering.h
View file @
1eda90a1
...
@@ -79,7 +79,6 @@ private:
...
@@ -79,7 +79,6 @@ private:
/// ELF section once the offsets from the start of the function are known.
/// ELF section once the offsets from the start of the function are known.
class
JumpTableData
{
class
JumpTableData
{
JumpTableData
()
=
delete
;
JumpTableData
()
=
delete
;
JumpTableData
(
const
JumpTableData
&
)
=
delete
;
JumpTableData
&
operator
=
(
const
JumpTableData
&
)
=
delete
;
JumpTableData
&
operator
=
(
const
JumpTableData
&
)
=
delete
;
public
:
public
:
...
@@ -87,7 +86,9 @@ public:
...
@@ -87,7 +86,9 @@ public:
:
FuncName
(
FuncName
),
Id
(
Id
)
{
:
FuncName
(
FuncName
),
Id
(
Id
)
{
TargetOffsets
.
reserve
(
NumTargets
);
TargetOffsets
.
reserve
(
NumTargets
);
}
}
JumpTableData
(
const
JumpTableData
&
)
=
default
;
JumpTableData
(
JumpTableData
&&
)
=
default
;
JumpTableData
(
JumpTableData
&&
)
=
default
;
JumpTableData
&
operator
=
(
JumpTableData
&&
)
=
default
;
void
pushTarget
(
intptr_t
Offset
)
{
TargetOffsets
.
emplace_back
(
Offset
);
}
void
pushTarget
(
intptr_t
Offset
)
{
TargetOffsets
.
emplace_back
(
Offset
);
}
...
@@ -98,8 +99,8 @@ public:
...
@@ -98,8 +99,8 @@ public:
}
}
private
:
private
:
const
IceString
FuncName
;
IceString
FuncName
;
const
SizeT
Id
;
SizeT
Id
;
std
::
vector
<
intptr_t
>
TargetOffsets
;
std
::
vector
<
intptr_t
>
TargetOffsets
;
};
};
...
...
src/IceTargetLoweringX8632.cpp
View file @
1eda90a1
...
@@ -243,8 +243,8 @@ void TargetDataX8632::lowerJumpTables() {
...
@@ -243,8 +243,8 @@ void TargetDataX8632::lowerJumpTables() {
switch
(
Ctx
->
getFlags
().
getOutFileType
())
{
switch
(
Ctx
->
getFlags
().
getOutFileType
())
{
case
FT_Elf
:
{
case
FT_Elf
:
{
ELFObjectWriter
*
Writer
=
Ctx
->
getObjectWriter
();
ELFObjectWriter
*
Writer
=
Ctx
->
getObjectWriter
();
for
(
const
JumpTableData
&
J
umpTable
:
*
Ctx
->
getJumpTables
())
for
(
const
JumpTableData
&
J
T
:
Ctx
->
getJumpTables
())
Writer
->
writeJumpTable
(
J
umpTable
,
llvm
::
ELF
::
R_386_32
);
Writer
->
writeJumpTable
(
J
T
,
llvm
::
ELF
::
R_386_32
);
}
break
;
}
break
;
case
FT_Asm
:
case
FT_Asm
:
// Already emitted from Cfg
// Already emitted from Cfg
...
@@ -253,7 +253,7 @@ void TargetDataX8632::lowerJumpTables() {
...
@@ -253,7 +253,7 @@ void TargetDataX8632::lowerJumpTables() {
if
(
!
BuildDefs
::
dump
())
if
(
!
BuildDefs
::
dump
())
return
;
return
;
Ostream
&
Str
=
Ctx
->
getStrEmit
();
Ostream
&
Str
=
Ctx
->
getStrEmit
();
for
(
const
JumpTableData
&
JT
:
*
Ctx
->
getJumpTables
())
{
for
(
const
JumpTableData
&
JT
:
Ctx
->
getJumpTables
())
{
Str
<<
"
\t
.section
\t
.rodata."
<<
JT
.
getFunctionName
()
Str
<<
"
\t
.section
\t
.rodata."
<<
JT
.
getFunctionName
()
<<
"$jumptable,
\"
a
\"
,@progbits
\n
"
;
<<
"$jumptable,
\"
a
\"
,@progbits
\n
"
;
Str
<<
"
\t
.align
\t
"
<<
typeWidthInBytes
(
getPointerType
())
<<
"
\n
"
;
Str
<<
"
\t
.align
\t
"
<<
typeWidthInBytes
(
getPointerType
())
<<
"
\n
"
;
...
...
src/IceTargetLoweringX8664.cpp
View file @
1eda90a1
...
@@ -240,9 +240,9 @@ void TargetDataX8664::lowerJumpTables() {
...
@@ -240,9 +240,9 @@ void TargetDataX8664::lowerJumpTables() {
switch
(
Ctx
->
getFlags
().
getOutFileType
())
{
switch
(
Ctx
->
getFlags
().
getOutFileType
())
{
case
FT_Elf
:
{
case
FT_Elf
:
{
ELFObjectWriter
*
Writer
=
Ctx
->
getObjectWriter
();
ELFObjectWriter
*
Writer
=
Ctx
->
getObjectWriter
();
for
(
const
JumpTableData
&
J
umpTable
:
*
Ctx
->
getJumpTables
())
for
(
const
JumpTableData
&
J
T
:
Ctx
->
getJumpTables
())
// TODO(jpp): not 386.
// TODO(jpp): not 386.
Writer
->
writeJumpTable
(
J
umpTable
,
llvm
::
ELF
::
R_386_32
);
Writer
->
writeJumpTable
(
J
T
,
llvm
::
ELF
::
R_386_32
);
}
break
;
}
break
;
case
FT_Asm
:
case
FT_Asm
:
// Already emitted from Cfg
// Already emitted from Cfg
...
@@ -251,7 +251,7 @@ void TargetDataX8664::lowerJumpTables() {
...
@@ -251,7 +251,7 @@ void TargetDataX8664::lowerJumpTables() {
if
(
!
BuildDefs
::
dump
())
if
(
!
BuildDefs
::
dump
())
return
;
return
;
Ostream
&
Str
=
Ctx
->
getStrEmit
();
Ostream
&
Str
=
Ctx
->
getStrEmit
();
for
(
const
JumpTableData
&
JT
:
*
Ctx
->
getJumpTables
())
{
for
(
const
JumpTableData
&
JT
:
Ctx
->
getJumpTables
())
{
Str
<<
"
\t
.section
\t
.rodata."
<<
JT
.
getFunctionName
()
Str
<<
"
\t
.section
\t
.rodata."
<<
JT
.
getFunctionName
()
<<
"$jumptable,
\"
a
\"
,@progbits
\n
"
;
<<
"$jumptable,
\"
a
\"
,@progbits
\n
"
;
Str
<<
"
\t
.align
\t
"
<<
typeWidthInBytes
(
getPointerType
())
<<
"
\n
"
;
Str
<<
"
\t
.align
\t
"
<<
typeWidthInBytes
(
getPointerType
())
<<
"
\n
"
;
...
...
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