summaryrefslogtreecommitdiff
path: root/compiler/cmm
diff options
context:
space:
mode:
authorAustin Seipp <austin@well-typed.com>2013-10-01 21:13:14 -0500
committerAustin Seipp <austin@well-typed.com>2013-10-01 21:26:47 -0500
commitfd74014079f14bd3ab50e328e52c44ef97d40e05 (patch)
treeda31c992a76d3816a4f1012ceb1eb4e68d0fb556 /compiler/cmm
parent627d1e008cbe4d9318b2466394420a968d1659da (diff)
downloadhaskell-fd74014079f14bd3ab50e328e52c44ef97d40e05.tar.gz
Add support for prefetch with locality levels.
This patch adds support for several new primitive operations which support using processor-specific instructions to help guide data and cache locality decisions. We have levels ranging from [0..3] For LLVM, we generate llvm.prefetch intrinsics at the proper locality level (similar to GCC.) For x86 we generate prefetch{NTA, t2, t1, t0} instructions. On SPARC and PowerPC, the locality levels are ignored. This closes #8256. Authored-by: Carter Tazio Schonwald <carter.schonwald@gmail.com> Signed-off-by: Austin Seipp <austin@well-typed.com>
Diffstat (limited to 'compiler/cmm')
-rw-r--r--compiler/cmm/CmmMachOp.hs18
-rw-r--r--compiler/cmm/CmmParse.y10
-rw-r--r--compiler/cmm/PprC.hs4
3 files changed, 24 insertions, 8 deletions
diff --git a/compiler/cmm/CmmMachOp.hs b/compiler/cmm/CmmMachOp.hs
index c009d15e25..684a4b9729 100644
--- a/compiler/cmm/CmmMachOp.hs
+++ b/compiler/cmm/CmmMachOp.hs
@@ -107,10 +107,10 @@ data MachOp
-- Vector element insertion and extraction operations
| MO_V_Insert Length Width -- Insert scalar into vector
| MO_V_Extract Length Width -- Extract scalar from vector
-
+
-- Integer vector operations
- | MO_V_Add Length Width
- | MO_V_Sub Length Width
+ | MO_V_Add Length Width
+ | MO_V_Sub Length Width
| MO_V_Mul Length Width
-- Signed vector multiply/divide
@@ -127,8 +127,8 @@ data MachOp
| MO_VF_Extract Length Width -- Extract scalar from vector
-- Floating point vector operations
- | MO_VF_Add Length Width
- | MO_VF_Sub Length Width
+ | MO_VF_Add Length Width
+ | MO_VF_Sub Length Width
| MO_VF_Neg Length Width -- unary -
| MO_VF_Mul Length Width
| MO_VF_Quot Length Width
@@ -528,8 +528,14 @@ data CallishMachOp
| MO_Touch -- Keep variables live (when using interior pointers)
-- Prefetch
- | MO_Prefetch_Data -- Prefetch hint. May change program performance but not
+ | MO_Prefetch_Data Int -- Prefetch hint. May change program performance but not
-- program behavior.
+ -- the Int can be 0-3. Needs to be known at compile time
+ -- to interact with code generation correctly.
+ -- TODO: add support for prefetch WRITES,
+ -- currently only exposes prefetch reads, which
+ -- would the majority of use cases in ghc anyways
+
-- Note that these three MachOps all take 1 extra parameter than the
-- standard C lib versions. The extra (last) parameter contains
diff --git a/compiler/cmm/CmmParse.y b/compiler/cmm/CmmParse.y
index ebd9278e15..a0c9bc4eb5 100644
--- a/compiler/cmm/CmmParse.y
+++ b/compiler/cmm/CmmParse.y
@@ -952,8 +952,16 @@ callishMachOps = listToUFM $
( "write_barrier", MO_WriteBarrier ),
( "memcpy", MO_Memcpy ),
( "memset", MO_Memset ),
- ( "memmove", MO_Memmove )
+ ( "memmove", MO_Memmove ),
+
+ ("prefetch0",MO_Prefetch_Data 0),
+ ("prefetch1",MO_Prefetch_Data 1),
+ ("prefetch2",MO_Prefetch_Data 2),
+ ("prefetch3",MO_Prefetch_Data 3)
+
-- ToDo: the rest, maybe
+ -- edit: which rest?
+ -- also: how do we tell CMM Lint how to type check callish macops?
]
parseSafety :: String -> P Safety
diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
index c468161c73..32fd8b4feb 100644
--- a/compiler/cmm/PprC.hs
+++ b/compiler/cmm/PprC.hs
@@ -759,7 +759,9 @@ pprCallishMachOp_for_C mop
MO_Add2 {} -> unsupported
MO_U_Mul2 {} -> unsupported
MO_Touch -> unsupported
- MO_Prefetch_Data -> unsupported
+ (MO_Prefetch_Data _ ) -> unsupported
+ --- we could support prefetch via "__builtin_prefetch"
+ --- Not adding it for now
where unsupported = panic ("pprCallishMachOp_for_C: " ++ show mop
++ " not supported!")