summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp20
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp2
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h5
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp20
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h6
5 files changed, 46 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 7fa2e37d9eb..b124e34be33 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -60,6 +60,16 @@ RValue CodeGenFunction::EmitAnyExpr(const Expr *E, llvm::Value *AggLoc,
return RValue::getAggregate(AggLoc);
}
+/// getAccessedFieldNo - Given an encoded value and a result number, return
+/// the input field number being accessed.
+unsigned CodeGenFunction::getAccessedFieldNo(unsigned Idx,
+ const llvm::Constant *Elts) {
+ if (isa<llvm::ConstantAggregateZero>(Elts))
+ return 0;
+
+ return cast<llvm::ConstantInt>(Elts->getOperand(Idx))->getZExtValue();
+}
+
//===----------------------------------------------------------------------===//
// LValue Expression Emission
@@ -197,7 +207,7 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV,
// extracting a single element. Just codegen as an extractelement.
const VectorType *ExprVT = ExprType->getAsVectorType();
if (!ExprVT) {
- unsigned InIdx = ExtVectorElementExpr::getAccessedFieldNo(0, Elts);
+ unsigned InIdx = getAccessedFieldNo(0, Elts);
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp"));
}
@@ -211,7 +221,7 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV,
if (NumResultElts == NumSourceElts) {
llvm::SmallVector<llvm::Constant*, 4> Mask;
for (unsigned i = 0; i != NumResultElts; ++i) {
- unsigned InIdx = ExtVectorElementExpr::getAccessedFieldNo(i, Elts);
+ unsigned InIdx = getAccessedFieldNo(i, Elts);
Mask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx));
}
@@ -227,7 +237,7 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV,
// Extract/Insert each element of the result.
for (unsigned i = 0; i != NumResultElts; ++i) {
- unsigned InIdx = ExtVectorElementExpr::getAccessedFieldNo(i, Elts);
+ unsigned InIdx = getAccessedFieldNo(i, Elts);
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
Elt = Builder.CreateExtractElement(Vec, Elt, "tmp");
@@ -338,13 +348,13 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, i);
Elt = Builder.CreateExtractElement(SrcVal, Elt, "tmp");
- unsigned Idx = ExtVectorElementExpr::getAccessedFieldNo(i, Elts);
+ unsigned Idx = getAccessedFieldNo(i, Elts);
llvm::Value *OutIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Idx);
Vec = Builder.CreateInsertElement(Vec, Elt, OutIdx, "tmp");
}
} else {
// If the Src is a scalar (not a vector) it must be updating one element.
- unsigned InIdx = ExtVectorElementExpr::getAccessedFieldNo(0, Elts);
+ unsigned InIdx = getAccessedFieldNo(0, Elts);
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx);
Vec = Builder.CreateInsertElement(Vec, SrcVal, Elt, "tmp");
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9c5c45de5e9..e4332f6e7fb 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -171,7 +171,7 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) {
CurFn->setCallingConv(llvm::CallingConv::Fast);
if (const VisibilityAttr *attr = FD->getAttr<VisibilityAttr>())
- CurFn->setVisibility(attr->getVisibility());
+ CodeGenModule::setVisibility(CurFn, attr->getVisibility());
// FIXME: else handle -fvisibility
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 0693781bce8..63d89a78c72 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -350,6 +350,11 @@ public:
/// GetAddrOfStaticLocalVar - Return the address of a static local variable.
llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
+
+ /// getAccessedFieldNo - Given an encoded value and a result number, return
+ /// the input field number being accessed.
+ static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts);
+
//===--------------------------------------------------------------------===//
// Declaration Emission
//===--------------------------------------------------------------------===//
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 7bf1e01b27e..ec61d667eed 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -82,6 +82,24 @@ void CodeGenModule::WarnUnsupported(const Decl *D, const char *Type) {
&Msg, 1);
}
+/// setVisibility - Set the visibility for the given LLVM GlobalValue
+/// according to the given clang AST visibility value.
+void CodeGenModule::setVisibility(llvm::GlobalValue *GV,
+ VisibilityAttr::VisibilityTypes Vis) {
+ switch (Vis) {
+ default: assert(0 && "Unknown visibility!");
+ case VisibilityAttr::DefaultVisibility:
+ GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
+ break;
+ case VisibilityAttr::HiddenVisibility:
+ GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
+ break;
+ case VisibilityAttr::ProtectedVisibility:
+ GV->setVisibility(llvm::GlobalValue::ProtectedVisibility);
+ break;
+ }
+}
+
/// AddGlobalCtor - Add a function to the list that will be called before
/// main() runs.
void CodeGenModule::AddGlobalCtor(llvm::Function * Ctor) {
@@ -467,7 +485,7 @@ void CodeGenModule::EmitGlobalVarInit(const VarDecl *D) {
GV->setInitializer(Init);
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
- GV->setVisibility(attr->getVisibility());
+ setVisibility(GV, attr->getVisibility());
// FIXME: else handle -fvisibility
// Set the llvm linkage type as appropriate.
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 8a3069e648b..bc216e4f485 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -16,6 +16,7 @@
#include "CodeGenTypes.h"
#include "CGObjCRuntime.h"
+#include "clang/AST/Attr.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
@@ -130,6 +131,11 @@ public:
/// specified decl yet.
void WarnUnsupported(const Decl *D, const char *Type);
+ /// setVisibility - Set the visibility for the given LLVM GlobalValue
+ /// according to the given clang AST visibility value.
+ static void setVisibility(llvm::GlobalValue *GV,
+ VisibilityAttr::VisibilityTypes);
+
private:
/// ReplaceMapValuesWith - This is a really slow and bad function that
/// searches for any entries in GlobalDeclMap that point to OldVal, changing
OpenPOWER on IntegriCloud