Bring llvm.annotation* intrinsics support back to where it was in llvm-gcc: can
annotate global, local variables, struct fields, or arbitrary statements (using the __builtin_annotation), rdar://8037476. llvm-svn: 139423
This commit is contained in:
@@ -1018,3 +1018,50 @@ void CodeGenFunction::unprotectFromPeepholes(PeepholeProtection protection) {
|
||||
// In theory, we could try to duplicate the peepholes now, but whatever.
|
||||
protection.Inst->eraseFromParent();
|
||||
}
|
||||
|
||||
llvm::Value *CodeGenFunction::EmitAnnotationCall(llvm::Value *AnnotationFn,
|
||||
llvm::Value *AnnotatedVal,
|
||||
llvm::StringRef AnnotationStr,
|
||||
SourceLocation Location) {
|
||||
llvm::Value *Args[4] = {
|
||||
AnnotatedVal,
|
||||
Builder.CreateBitCast(CGM.EmitAnnotationString(AnnotationStr), Int8PtrTy),
|
||||
Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location), Int8PtrTy),
|
||||
CGM.EmitAnnotationLineNo(Location)
|
||||
};
|
||||
return Builder.CreateCall(AnnotationFn, Args);
|
||||
}
|
||||
|
||||
void CodeGenFunction::EmitVarAnnotations(const VarDecl *D, llvm::Value *V) {
|
||||
assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
|
||||
// FIXME We create a new bitcast for every annotation because that's what
|
||||
// llvm-gcc was doing.
|
||||
for (specific_attr_iterator<AnnotateAttr>
|
||||
ai = D->specific_attr_begin<AnnotateAttr>(),
|
||||
ae = D->specific_attr_end<AnnotateAttr>(); ai != ae; ++ai)
|
||||
EmitAnnotationCall(CGM.getIntrinsic(llvm::Intrinsic::var_annotation),
|
||||
Builder.CreateBitCast(V, CGM.Int8PtrTy, V->getName()),
|
||||
(*ai)->getAnnotation(), D->getLocation());
|
||||
}
|
||||
|
||||
llvm::Value *CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
|
||||
llvm::Value *V) {
|
||||
assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
|
||||
llvm::Type *VTy = V->getType();
|
||||
llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation,
|
||||
CGM.Int8PtrTy);
|
||||
|
||||
for (specific_attr_iterator<AnnotateAttr>
|
||||
ai = D->specific_attr_begin<AnnotateAttr>(),
|
||||
ae = D->specific_attr_end<AnnotateAttr>(); ai != ae; ++ai) {
|
||||
// FIXME Always emit the cast inst so we can differentiate between
|
||||
// annotation on the first field of a struct and annotation on the struct
|
||||
// itself.
|
||||
if (VTy != CGM.Int8PtrTy)
|
||||
V = Builder.Insert(new llvm::BitCastInst(V, CGM.Int8PtrTy));
|
||||
V = EmitAnnotationCall(F, V, (*ai)->getAnnotation(), D->getLocation());
|
||||
V = Builder.CreateBitCast(V, VTy);
|
||||
}
|
||||
|
||||
return V;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user