Skip to content

Commit

Permalink
Add overrides for llvm.prefetch{.p018} (#839)
Browse files Browse the repository at this point in the history
Fixes #838.
  • Loading branch information
RyanGlScott authored Sep 3, 2021
1 parent 5ec0854 commit e5d7499
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ declare_overrides =
, basic_llvm_override LLVM.llvmObjectsizeOverride_32_null_dynamic
, basic_llvm_override LLVM.llvmObjectsizeOverride_64_null_dynamic

, basic_llvm_override LLVM.llvmPrefetchOverride
, basic_llvm_override LLVM.llvmPrefetchOverride_preLLVM10

, basic_llvm_override LLVM.llvmStacksave
, basic_llvm_override LLVM.llvmStackrestore

Expand Down
30 changes: 30 additions & 0 deletions crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/LLVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,36 @@ llvmObjectsizeOverride_64_null_dynamic =
[llvmOvr| i64 @llvm.objectsize.i64.p0i8( i8*, i1, i1, i1 ) |]
(\memOps sym args -> Ctx.uncurryAssignment (callObjectsize_null_dynamic sym memOps knownNat) args)

-- | This instruction is a hint to code generators, which means that it is a
-- no-op for us.
--
-- <https://releases.llvm.org/12.0.0/docs/LangRef.html#llvm-prefetch-intrinsic LLVM docs>
llvmPrefetchOverride ::
(IsSymInterface sym, HasPtrWidth wptr) =>
LLVMOverride p sym
(EmptyCtx ::> LLVMPointerType wptr ::> BVType 32 ::> BVType 32 ::> BVType 32)
UnitType
llvmPrefetchOverride =
[llvmOvr| void @llvm.prefetch.p0i8( i8*, i32, i32, i32 ) |]
(\_memOps _sym _args -> pure ())

-- | This instruction is a hint to code generators, which means that it is a
-- no-op for us.
--
-- See also 'llvmPrefetchOverride'. This version exists for compatibility with
-- pre-10 versions of LLVM, where llvm.prefetch always assumed that the first
-- argument resides in address space 0.
--
-- <https://releases.llvm.org/12.0.0/docs/LangRef.html#llvm-prefetch-intrinsic LLVM docs>
llvmPrefetchOverride_preLLVM10 ::
(IsSymInterface sym, HasPtrWidth wptr) =>
LLVMOverride p sym
(EmptyCtx ::> LLVMPointerType wptr ::> BVType 32 ::> BVType 32 ::> BVType 32)
UnitType
llvmPrefetchOverride_preLLVM10 =
[llvmOvr| void @llvm.prefetch( i8*, i32, i32, i32 ) |]
(\_memOps _sym _args -> pure ())

llvmFshl ::
(1 <= w, IsSymInterface sym) =>
NatRepr w ->
Expand Down
5 changes: 5 additions & 0 deletions crux-llvm/test-data/golden/T838.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int main() {
int x = 0;
__builtin_prefetch(&x);
return x;
}
1 change: 1 addition & 0 deletions crux-llvm/test-data/golden/T838.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Crux] Overall status: Valid.

0 comments on commit e5d7499

Please sign in to comment.