-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CIR] Add a new volatile flag to distinguish volatile accesses (#402)
This patch adds a new `volatile` tag to the following operations to distinguish volatile loads and stores from normal loads and stores: - `cir.load` - `cir.store` - `cir.get_bitfield` - `cir.set_bitfield` Besides, this patch also updates the CodeGen and LLVMIR lowering code to start emitting CIR and LLVMIR operations with volatile flag.
- Loading branch information
Showing
7 changed files
with
151 additions
and
38 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir-enable -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
int test_load(volatile int *ptr) { | ||
return *ptr; | ||
} | ||
|
||
// CHECK: cir.func @_Z9test_loadPVi | ||
// CHECK: %{{.+}} = cir.load volatile | ||
|
||
void test_store(volatile int *ptr) { | ||
*ptr = 42; | ||
} | ||
|
||
// CHECK: cir.func @_Z10test_storePVi | ||
// CHECK: cir.store volatile | ||
|
||
struct Foo { | ||
int x; | ||
volatile int y; | ||
volatile int z: 4; | ||
}; | ||
|
||
int test_load_field1(volatile Foo *ptr) { | ||
return ptr->x; | ||
} | ||
|
||
// CHECK: cir.func @_Z16test_load_field1PV3Foo | ||
// CHECK: %[[MemberAddr:.*]] = cir.get_member | ||
// CHECK: %{{.+}} = cir.load volatile %[[MemberAddr]] | ||
|
||
int test_load_field2(Foo *ptr) { | ||
return ptr->y; | ||
} | ||
|
||
// CHECK: cir.func @_Z16test_load_field2P3Foo | ||
// CHECK: %[[MemberAddr:.+]] = cir.get_member | ||
// CHECK: %{{.+}} = cir.load volatile %[[MemberAddr]] | ||
|
||
int test_load_field3(Foo *ptr) { | ||
return ptr->z; | ||
} | ||
|
||
// CHECK: cir.func @_Z16test_load_field3P3Foo | ||
// CHECK: %[[MemberAddr:.+]] = cir.get_member | ||
// CHECK: %{{.+}} = cir.load volatile %[[MemberAddr]] | ||
|
||
void test_store_field1(volatile Foo *ptr) { | ||
ptr->x = 42; | ||
} | ||
|
||
// CHECK: cir.func @_Z17test_store_field1PV3Foo | ||
// CHECK: %[[MemberAddr:.+]] = cir.get_member | ||
// CHECK: cir.store volatile %{{.+}}, %[[MemberAddr]] | ||
|
||
void test_store_field2(Foo *ptr) { | ||
ptr->y = 42; | ||
} | ||
|
||
// CHECK: cir.func @_Z17test_store_field2P3Foo | ||
// CHECK: %[[MemberAddr:.+]] = cir.get_member | ||
// CHECK: cir.store volatile %{{.+}}, %[[MemberAddr]] | ||
|
||
void test_store_field3(Foo *ptr) { | ||
ptr->z = 4; | ||
} | ||
|
||
// CHECK: cir.func @_Z17test_store_field3P3Foo | ||
// CHECK: %[[MemberAddr:.+]] = cir.get_member | ||
// CHECK: cir.store volatile %{{.+}}, %[[MemberAddr]] |
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