r174289 - CodeGen: Mark the runtime function __dynamic_cast as readonly & nounwind.
Benjamin Kramer
benny.kra at googlemail.com
Sun Feb 3 09:44:25 PST 2013
Author: d0k
Date: Sun Feb 3 11:44:25 2013
New Revision: 174289
URL: http://llvm.org/viewvc/llvm-project?rev=174289&view=rev
Log:
CodeGen: Mark the runtime function __dynamic_cast as readonly & nounwind.
This allows the optimizer to CSE dynamic_casts.
Modified:
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=174289&r1=174288&r2=174289&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Sun Feb 3 11:44:25 2013
@@ -1689,11 +1689,16 @@ static llvm::Constant *getDynamicCastFn(
CGF.ConvertType(CGF.getContext().getPointerDiffType());
llvm::Type *Args[4] = { Int8PtrTy, Int8PtrTy, Int8PtrTy, PtrDiffTy };
-
- llvm::FunctionType *FTy =
- llvm::FunctionType::get(Int8PtrTy, Args, false);
-
- return CGF.CGM.CreateRuntimeFunction(FTy, "__dynamic_cast");
+
+ llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
+
+ // Mark the function as nounwind readonly.
+ llvm::Attribute::AttrKind FuncAttrs[] = { llvm::Attribute::NoUnwind,
+ llvm::Attribute::ReadOnly };
+ llvm::AttributeSet Attrs = llvm::AttributeSet::get(
+ CGF.getLLVMContext(), llvm::AttributeSet::FunctionIndex, FuncAttrs);
+
+ return CGF.CGM.CreateRuntimeFunction(FTy, "__dynamic_cast", Attrs);
}
static llvm::Constant *getBadCastFn(CodeGenFunction &CGF) {
Modified: cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp?rev=174289&r1=174288&r2=174289&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp Sun Feb 3 11:44:25 2013
@@ -16,3 +16,5 @@ const B& f(A *a) {
}
return fail;
}
+
+// CHECK: declare i8* @__dynamic_cast(i8*, i8*, i8*, i64) nounwind readonly
More information about the cfe-commits
mailing list