Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex D
GHC
Commits
3b1d920e
Commit
3b1d920e
authored
Jun 18, 2013
by
dterei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to call functions with metadata as arguments to LLVM
backend.
parent
280a7ec6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
16 deletions
+51
-16
compiler/llvmGen/Llvm.hs
compiler/llvmGen/Llvm.hs
+1
-1
compiler/llvmGen/Llvm/AbsSyn.hs
compiler/llvmGen/Llvm/AbsSyn.hs
+21
-0
compiler/llvmGen/Llvm/MetaData.hs
compiler/llvmGen/Llvm/MetaData.hs
+18
-8
compiler/llvmGen/Llvm/PpLlvm.hs
compiler/llvmGen/Llvm/PpLlvm.hs
+4
-3
compiler/llvmGen/Llvm/Types.hs
compiler/llvmGen/Llvm/Types.hs
+7
-4
No files found.
compiler/llvmGen/Llvm.hs
View file @
3b1d920e
...
...
@@ -25,7 +25,7 @@ module Llvm (
-- * Call Handling
LlvmCallConvention
(
..
),
LlvmCallType
(
..
),
LlvmParameterListType
(
..
),
LlvmLinkageType
(
..
),
LlvmFuncAttr
(
..
),
LlvmLinkageType
(
..
),
LlvmFuncAttr
(
..
),
MetaArgs
(
..
),
-- * Operations and Comparisons
LlvmCmpOp
(
..
),
LlvmMachOp
(
..
),
LlvmCastOp
(
..
),
...
...
compiler/llvmGen/Llvm/AbsSyn.hs
View file @
3b1d920e
...
...
@@ -65,6 +65,16 @@ data LlvmFunction = LlvmFunction {
type
LlvmFunctions
=
[
LlvmFunction
]
-- | LLVM function call arguments.
data
MetaArgs
=
ArgVar
LlvmVar
-- ^ Regular LLVM variable as argument.
|
ArgMeta
MetaExpr
-- ^ Metadata as argument.
deriving
(
Eq
)
instance
Show
MetaArgs
where
show
(
ArgVar
v
)
=
show
v
show
(
ArgMeta
m
)
=
show
m
-- | LLVM ordering types for synchronization purposes. (Introduced in LLVM
-- 3.0). Please see the LLVM documentation for a better description.
data
LlvmSyncOrdering
...
...
@@ -251,6 +261,17 @@ data LlvmExpression
-}
|
Call
LlvmCallType
LlvmVar
[
LlvmVar
]
[
LlvmFuncAttr
]
{- |
Call a function as above but potentially taking metadata as arguments.
* tailJumps: CallType to signal if the function should be tail called
* fnptrval: An LLVM value containing a pointer to a function to be
invoked. Can be indirect. Should be LMFunction type.
* args: Arguments that may include metadata.
* attrs: A list of function attributes for the call. Only NoReturn,
NoUnwind, ReadOnly and ReadNone are valid here.
-}
|
CallM
LlvmCallType
LlvmVar
[
MetaArgs
]
[
LlvmFuncAttr
]
{- |
Merge variables from different basic blocks which are predecessors of this
basic block in a new variable of type tp.
...
...
compiler/llvmGen/Llvm/MetaData.hs
View file @
3b1d920e
...
...
@@ -73,6 +73,16 @@ data MetaVal
|
MetaValNode
Int
deriving
(
Eq
)
instance
Show
MetaExpr
where
show
(
MetaStr
s
)
=
"metadata !
\"
"
++
unpackFS
s
++
"
\"
"
show
(
MetaNode
n
)
=
"metadata !"
++
show
n
show
(
MetaVar
v
)
=
show
v
show
(
MetaExpr
es
)
=
intercalate
", "
$
map
show
es
instance
Show
MetaVal
where
show
(
MetaValExpr
e
)
=
"!{ "
++
show
e
++
"}"
show
(
MetaValNode
n
)
=
"!"
++
show
n
-- | Associated some metadata with a specific label for attaching to an
-- instruction.
type
MetaData
=
(
LMString
,
MetaVal
)
...
...
@@ -86,15 +96,15 @@ data MetaDecl
-- ('!0 = metadata !{ <metadata expression> }' form).
|
MetaUnamed
Int
MetaExpr
instance
Show
MetaExpr
where
show
(
MetaStr
s
)
=
"metadata !
\"
"
++
unpackFS
s
++
"
\"
"
show
(
MetaNode
n
)
=
"metadata !"
++
show
n
show
(
MetaVar
v
)
=
show
v
show
(
MetaExpr
es
)
=
intercalate
", "
$
map
show
es
-- | LLVM function call arguments.
data
MetaArgs
=
ArgVar
LlvmVar
-- ^ Regular LLVM variable as argument.
|
ArgMeta
MetaExpr
-- ^ Metadata as argument.
deriving
(
Eq
)
instance
Show
Meta
Val
where
show
(
MetaValExpr
e
)
=
"!{ "
++
show
e
++
"}"
show
(
MetaValNode
n
)
=
"!"
++
show
n
instance
Show
Meta
Args
where
show
(
ArgVar
v
)
=
show
v
show
(
ArgMeta
m
)
=
show
m
{-
Note: Metadata encoding
...
...
compiler/llvmGen/Llvm/PpLlvm.hs
View file @
3b1d920e
...
...
@@ -228,6 +228,7 @@ ppLlvmExpression expr
Alloca
tp
amount
->
ppAlloca
tp
amount
LlvmOp
op
left
right
->
ppMachOp
op
left
right
Call
tp
fp
args
attrs
->
ppCall
tp
fp
args
attrs
CallM
tp
fp
args
attrs
->
ppCall
tp
fp
args
attrs
Cast
op
from
to
->
ppCast
op
from
to
Compare
op
left
right
->
ppCmpOp
op
left
right
Extract
vec
idx
->
ppExtract
vec
idx
...
...
@@ -246,8 +247,8 @@ ppLlvmExpression expr
-- | Should always be a function pointer. So a global var of function type
-- (since globals are always pointers) or a local var of pointer function type.
ppCall
::
LlvmCallType
->
LlvmVar
->
[
LlvmVar
]
->
[
LlvmFuncAttr
]
->
SDoc
ppCall
ct
fptr
val
s
attrs
=
case
fptr
of
ppCall
::
(
Show
a
)
=>
LlvmCallType
->
LlvmVar
->
[
a
]
->
[
LlvmFuncAttr
]
->
SDoc
ppCall
ct
fptr
arg
s
attrs
=
case
fptr
of
--
-- if local var function pointer, unwrap
LMLocalVar
_
(
LMPointer
(
LMFunction
d
))
->
ppCall'
d
...
...
@@ -263,7 +264,7 @@ ppCall ct fptr vals attrs = case fptr of
where
ppCall'
(
LlvmFunctionDecl
_
_
cc
ret
argTy
params
_
)
=
let
tc
=
if
ct
==
TailCall
then
text
"tail "
else
empty
ppValues
=
ppCommaJoin
val
s
ppValues
=
ppCommaJoin
arg
s
ppParams
=
map
(
texts
.
fst
)
params
ppArgTy
=
(
hcat
$
intersperse
comma
ppParams
)
<>
(
case
argTy
of
...
...
compiler/llvmGen/Llvm/Types.hs
View file @
3b1d920e
...
...
@@ -47,6 +47,7 @@ data LlvmType
|
LMVoid
-- ^ Void type
|
LMStruct
[
LlvmType
]
-- ^ Structure type
|
LMAlias
LlvmAlias
-- ^ A type alias
|
LMMetadata
-- ^ LLVM Metadata
-- | Function type, used to create pointers to functions
|
LMFunction
LlvmFunctionDecl
...
...
@@ -64,6 +65,8 @@ instance Show LlvmType where
show
(
LMLabel
)
=
"label"
show
(
LMVoid
)
=
"void"
show
(
LMStruct
tys
)
=
"<{"
++
(
commaCat
tys
)
++
"}>"
show
(
LMAlias
(
s
,
_
)
)
=
"%"
++
unpackFS
s
show
(
LMMetadata
)
=
"metadata"
show
(
LMFunction
(
LlvmFunctionDecl
_
_
_
r
varg
p
_
))
=
let
varg'
=
case
varg
of
...
...
@@ -74,7 +77,6 @@ instance Show LlvmType where
args
=
intercalate
", "
$
map
(
show
.
fst
)
p
in
show
r
++
" ("
++
args
++
varg'
++
")"
show
(
LMAlias
(
s
,
_
))
=
"%"
++
unpackFS
s
-- | An LLVM section definition. If Nothing then let LLVM decide the section
type
LMSection
=
Maybe
LMString
...
...
@@ -252,9 +254,10 @@ getLink _ = Internal
-- | Add a pointer indirection to the supplied type. 'LMLabel' and 'LMVoid'
-- cannot be lifted.
pLift
::
LlvmType
->
LlvmType
pLift
(
LMLabel
)
=
error
"Labels are unliftable"
pLift
(
LMVoid
)
=
error
"Voids are unliftable"
pLift
x
=
LMPointer
x
pLift
LMLabel
=
error
"Labels are unliftable"
pLift
LMVoid
=
error
"Voids are unliftable"
pLift
LMMetadata
=
error
"Metadatas are unliftable"
pLift
x
=
LMPointer
x
-- | Lower a variable of 'LMPointer' type.
pVarLift
::
LlvmVar
->
LlvmVar
...
...
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