summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorRenato Golin <renato.golin@linaro.org>2014-06-05 16:45:22 +0000
committerRenato Golin <renato.golin@linaro.org>2014-06-05 16:45:22 +0000
commit6649699a62886e564642cf5cb0cd067a89f5ca42 (patch)
treea2390e3cfb782d6ef6682a6c7fd00ea016dc3931 /lib/CodeGen/CGExpr.cpp
parent705e8b161676304b8f4dabdf819ae0909d10c69a (diff)
downloadclang-6649699a62886e564642cf5cb0cd067a89f5ca42.tar.gz
clang-6649699a62886e564642cf5cb0cd067a89f5ca42.tar.bz2
clang-6649699a62886e564642cf5cb0cd067a89f5ca42.tar.xz
Add pointer types to global named register
This patch adds support for pointer types in global named registers variables. It'll be lowered as a pair of read/write_register and inttoptr/ptrtoint calls. Also adds some early checks on types on SemaDecl to avoid the assert. Tests changed accordingly. (PR19837) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210274 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index e77c4b048a..a43093e553 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1350,12 +1350,22 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV) {
/// @brief Load of global gamed gegisters are always calls to intrinsics.
RValue CodeGenFunction::EmitLoadOfGlobalRegLValue(LValue LV) {
- assert(LV.getType()->isIntegerType() && "Bad type for register variable");
+ assert((LV.getType()->isIntegerType() || LV.getType()->isPointerType()) &&
+ "Bad type for register variable");
llvm::MDNode *RegName = dyn_cast<llvm::MDNode>(LV.getGlobalReg());
assert(RegName && "Register LValue is not metadata");
- llvm::Type *Types[] = { CGM.getTypes().ConvertType(LV.getType()) };
+
+ // We accept integer and pointer types only
+ llvm::Type *OrigTy = CGM.getTypes().ConvertType(LV.getType());
+ llvm::Type *Ty = OrigTy;
+ if (OrigTy->isPointerTy())
+ Ty = CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
+ llvm::Type *Types[] = { Ty };
+
llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, Types);
- llvm::Value* Call = Builder.CreateCall(F, RegName);
+ llvm::Value *Call = Builder.CreateCall(F, RegName);
+ if (OrigTy->isPointerTy())
+ Call = Builder.CreateIntToPtr(Call, OrigTy);
return RValue::get(Call);
}
@@ -1601,12 +1611,22 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
/// @brief Store of global named registers are always calls to intrinsics.
void CodeGenFunction::EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst) {
- assert(Dst.getType()->isIntegerType() && "Bad type for register variable");
+ assert((Dst.getType()->isIntegerType() || Dst.getType()->isPointerType()) &&
+ "Bad type for register variable");
llvm::MDNode *RegName = dyn_cast<llvm::MDNode>(Dst.getGlobalReg());
assert(RegName && "Register LValue is not metadata");
- llvm::Type *Types[] = { CGM.getTypes().ConvertType(Dst.getType()) };
+
+ // We accept integer and pointer types only
+ llvm::Type *OrigTy = CGM.getTypes().ConvertType(Dst.getType());
+ llvm::Type *Ty = OrigTy;
+ if (OrigTy->isPointerTy())
+ Ty = CGM.getTypes().getDataLayout().getIntPtrType(OrigTy);
+ llvm::Type *Types[] = { Ty };
+
llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::write_register, Types);
llvm::Value *Value = Src.getScalarVal();
+ if (OrigTy->isPointerTy())
+ Value = Builder.CreatePtrToInt(Value, Ty);
Builder.CreateCall2(F, RegName, Value);
}