[PATCH] D105972: Fix __attribute__((annotate("")) with non-zero globals AS
Alexander Richardson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 26 02:10:28 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7cab90a7b1c4: Fix __attribute__((annotate("")) with non-zero globals AS (authored by arichardson).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105972/new/
https://reviews.llvm.org/D105972
Files:
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenTypeCache.h
clang/test/CodeGen/annotations-global.c
Index: clang/test/CodeGen/annotations-global.c
===================================================================
--- clang/test/CodeGen/annotations-global.c
+++ clang/test/CodeGen/annotations-global.c
@@ -4,6 +4,7 @@
// RUN: FileCheck --check-prefix=BAR %s < %t1
// RUN: FileCheck --check-prefix=FOOS %s < %t1
// RUN: FileCheck --check-prefix=ADDRSPACE %s < %t1
+// RUN: %clang_cc1 %s -triple r600 -emit-llvm -o - | FileCheck %s --check-prefix AS1-GLOBALS
// END.
static __attribute((annotate("sfoo_0"))) __attribute((annotate("sfoo_1"))) char sfoo;
@@ -45,3 +46,8 @@
// ADDRSPACE: target triple
// ADDRSPACE: @llvm.global.annotations = appending global {{.*}} addrspacecast (i8 addrspace(1)* @addrspace1_var to i8*), {{.*}}
+
+// AS1-GLOBALS: target datalayout = "{{.+}}-A5-G1"
+// AS1-GLOBALS: @llvm.global.annotations = appending addrspace(1) global [11 x { i8 addrspace(1)*, i8 addrspace(1)*, i8 addrspace(1)*, i32, i8 addrspace(1)* }]
+// AS1-GLOBALS-SAME: { i8 addrspace(1)* @a.bar,
+// AS1-GLOBALS-SAME: { i8 addrspace(1)* @addrspace1_var,
Index: clang/lib/CodeGen/CodeGenTypeCache.h
===================================================================
--- clang/lib/CodeGen/CodeGenTypeCache.h
+++ clang/lib/CodeGen/CodeGenTypeCache.h
@@ -69,6 +69,12 @@
llvm::PointerType *AllocaInt8PtrTy;
};
+ /// void* in default globals address space
+ union {
+ llvm::PointerType *GlobalsVoidPtrTy;
+ llvm::PointerType *GlobalsInt8PtrTy;
+ };
+
/// The size and alignment of the builtin C type 'int'. This comes
/// up enough in various ABI lowering tasks to be worth pre-computing.
union {
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -130,8 +130,9 @@
C.getTargetInfo().getMaxPointerWidth());
Int8PtrTy = Int8Ty->getPointerTo(0);
Int8PtrPtrTy = Int8PtrTy->getPointerTo(0);
- AllocaInt8PtrTy = Int8Ty->getPointerTo(
- M.getDataLayout().getAllocaAddrSpace());
+ const llvm::DataLayout &DL = M.getDataLayout();
+ AllocaInt8PtrTy = Int8Ty->getPointerTo(DL.getAllocaAddrSpace());
+ GlobalsInt8PtrTy = Int8Ty->getPointerTo(DL.getDefaultGlobalsAddressSpace());
ASTAllocaAddressSpace = getTargetCodeGenInfo().getASTAllocaAddressSpace();
RuntimeCC = getTargetCodeGenInfo().getABIInfo().getRuntimeCC();
@@ -2532,7 +2533,7 @@
llvm::Constant *CodeGenModule::EmitAnnotationArgs(const AnnotateAttr *Attr) {
ArrayRef<Expr *> Exprs = {Attr->args_begin(), Attr->args_size()};
if (Exprs.empty())
- return llvm::ConstantPointerNull::get(Int8PtrTy);
+ return llvm::ConstantPointerNull::get(GlobalsInt8PtrTy);
llvm::FoldingSetNodeID ID;
for (Expr *E : Exprs) {
@@ -2556,7 +2557,7 @@
".args");
GV->setSection(AnnotationSection);
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
- auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, Int8PtrTy);
+ auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy);
Lookup = Bitcasted;
return Bitcasted;
@@ -2571,17 +2572,19 @@
*LineNoCst = EmitAnnotationLineNo(L),
*Args = EmitAnnotationArgs(AA);
- llvm::Constant *ASZeroGV = GV;
- if (GV->getAddressSpace() != 0) {
- ASZeroGV = llvm::ConstantExpr::getAddrSpaceCast(
- GV, GV->getValueType()->getPointerTo(0));
+ llvm::Constant *GVInGlobalsAS = GV;
+ if (GV->getAddressSpace() !=
+ getDataLayout().getDefaultGlobalsAddressSpace()) {
+ GVInGlobalsAS = llvm::ConstantExpr::getAddrSpaceCast(
+ GV, GV->getValueType()->getPointerTo(
+ getDataLayout().getDefaultGlobalsAddressSpace()));
}
// Create the ConstantStruct for the global annotation.
llvm::Constant *Fields[] = {
- llvm::ConstantExpr::getBitCast(ASZeroGV, Int8PtrTy),
- llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy),
- llvm::ConstantExpr::getBitCast(UnitGV, Int8PtrTy),
+ llvm::ConstantExpr::getBitCast(GVInGlobalsAS, GlobalsInt8PtrTy),
+ llvm::ConstantExpr::getBitCast(AnnoGV, GlobalsInt8PtrTy),
+ llvm::ConstantExpr::getBitCast(UnitGV, GlobalsInt8PtrTy),
LineNoCst,
Args,
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105972.368834.patch
Type: text/x-patch
Size: 4271 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210826/b0d61d14/attachment-0001.bin>
More information about the cfe-commits
mailing list