summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-05-22 00:50:06 +0000
committerDan Gohman <gohman@apple.com>2008-05-22 00:50:06 +0000
commit75d69da5abf01b22405ea91c2f2830a2ee4c3879 (patch)
tree6b0d1bbd05751b0d7dbc7d2a1196b1a8f425f720 /clang/lib
parentda8fb591484371b10700fdc43da48b972053216d (diff)
downloadbcm5719-llvm-75d69da5abf01b22405ea91c2f2830a2ee4c3879.tar.gz
bcm5719-llvm-75d69da5abf01b22405ea91c2f2830a2ee4c3879.zip
Move getAccessedFieldNo out of lib/AST/Expr.cpp into
lib/CodeGen/CGExpr.cpp and to change include/clang/AST/Attr.h to use its own enum for visibility types instead of using llvm::GlobalValue::VisibilityTypes. These changes eliminate dependencies in the AST library on LLVM's VMCore library. llvm-svn: 51398
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/Expr.cpp10
-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
-rw-r--r--clang/lib/Sema/SemaDecl.cpp10
7 files changed, 51 insertions, 22 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index e7babf42643..e21686cf4ef 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -16,7 +16,6 @@
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/TargetInfo.h"
-#include "llvm/Constants.h"
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -1082,15 +1081,6 @@ void ExtVectorElementExpr::getEncodedElementAccess(
}
}
-unsigned
-ExtVectorElementExpr::getAccessedFieldNo(unsigned Idx,
- const llvm::Constant *Elts) {
- if (isa<llvm::ConstantAggregateZero>(Elts))
- return 0;
-
- return cast<llvm::ConstantInt>(Elts->getOperand(Idx))->getZExtValue();
-}
-
// constructor for instance messages.
ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
QualType retType, ObjCMethodDecl *mproto,
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
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b0b50bab962..35f12c7207b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2621,16 +2621,16 @@ void Sema::HandleVisibilityAttribute(Decl *d, AttributeList *rawAttr) {
const char *TypeStr = Str->getStrData();
unsigned TypeLen = Str->getByteLength();
- llvm::GlobalValue::VisibilityTypes type;
+ VisibilityAttr::VisibilityTypes type;
if (TypeLen == 7 && !memcmp(TypeStr, "default", 7))
- type = llvm::GlobalValue::DefaultVisibility;
+ type = VisibilityAttr::DefaultVisibility;
else if (TypeLen == 6 && !memcmp(TypeStr, "hidden", 6))
- type = llvm::GlobalValue::HiddenVisibility;
+ type = VisibilityAttr::HiddenVisibility;
else if (TypeLen == 8 && !memcmp(TypeStr, "internal", 8))
- type = llvm::GlobalValue::HiddenVisibility; // FIXME
+ type = VisibilityAttr::HiddenVisibility; // FIXME
else if (TypeLen == 9 && !memcmp(TypeStr, "protected", 9))
- type = llvm::GlobalValue::ProtectedVisibility;
+ type = VisibilityAttr::ProtectedVisibility;
else {
Diag(rawAttr->getLoc(), diag::warn_attribute_type_not_supported,
"visibility", TypeStr);
OpenPOWER on IntegriCloud