-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support atomicrmw instructions (with LLVM 10)
Fixes #12.
- Loading branch information
1 parent
5ccd3d0
commit fd56f3d
Showing
6 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
source_filename = "<no source file>" | ||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-apple-macosx10.15.0" | ||
|
||
define i32 @atomicrmwops(i32, i32) local_unnamed_addr { | ||
%addr = alloca i32, align 4 | ||
|
||
; initial value at %addr is %0 | ||
store i32 %0, i32* %addr, align 4 | ||
|
||
%3 = atomicrmw xchg i32* %addr, i32 %1 monotonic | ||
; now %3 is %0 and the value is %1 | ||
|
||
%4 = atomicrmw add i32* %addr, i32 %3 acquire | ||
; now %4 is %1 and the value is %1 + %3 (so, %1 + %0) | ||
|
||
%5 = atomicrmw sub i32* %addr, i32 %1 release | ||
; now %5 is %1 + %0 and the value is %0 | ||
|
||
%6 = atomicrmw and i32* %addr, i32 %4 acq_rel | ||
; now %6 is %0 and the value is %0 & %1 | ||
|
||
%7 = atomicrmw xor i32* %addr, i32 3 seq_cst | ||
; now %7 is %0 & %1 and the value is (%0 & %1) ^ 3 | ||
|
||
%8 = atomicrmw umax i32* %addr, i32 %0 monotonic | ||
; now %8 is (%0 & %1) ^ 3 and the value is umax(%8, %0) | ||
|
||
%9 = load i32, i32* %addr, align 4 | ||
|
||
ret i32 %9 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#![cfg(not(feature = "llvm-9"))] // With LLVM 9 and earlier, Haybale doesn't support AtomicRMW | ||
|
||
use haybale::solver_utils::PossibleSolutions; | ||
use haybale::*; | ||
|
||
fn init_logging() { | ||
// capture log messages with test harness | ||
let _ = env_logger::builder().is_test(true).try_init(); | ||
} | ||
|
||
fn get_project() -> Project { | ||
let modname = "tests/bcfiles/atomicrmw.bc"; | ||
Project::from_bc_path(modname) | ||
.unwrap_or_else(|e| panic!("Failed to parse module {:?}: {}", modname, e)) | ||
} | ||
|
||
#[test] | ||
fn atomicrmw() { | ||
init_logging(); | ||
let proj = get_project(); | ||
let funcname: String = "atomicrmwops".into(); | ||
let ret = get_possible_return_values_of_func( | ||
&funcname, | ||
vec![Some(0xFF00), Some(0x00FF)], | ||
&proj, | ||
Config::default(), | ||
None, | ||
10, | ||
); | ||
assert_eq!( | ||
ret, | ||
PossibleSolutions::exactly_one(ReturnValue::Return(0xFF00)) | ||
); | ||
} |