[cfe-commits] r51398 - in /cfe/trunk: include/clang/AST/Attr.h include/clang/AST/Expr.h lib/AST/Expr.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/Sema/SemaDecl.cpp
Dan Gohman
gohman at apple.com
Wed May 21 17:50:06 PDT 2008
Author: djg
Date: Wed May 21 19:50:06 2008
New Revision: 51398
URL: http://llvm.org/viewvc/llvm-project?rev=51398&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Wed May 21 19:50:06 2008
@@ -14,7 +14,6 @@
#ifndef LLVM_CLANG_AST_ATTR_H
#define LLVM_CLANG_AST_ATTR_H
-#include "llvm/GlobalValue.h"
#include <cassert>
#include <string>
@@ -166,12 +165,20 @@
};
class VisibilityAttr : public Attr {
- llvm::GlobalValue::VisibilityTypes VisibilityType;
public:
- VisibilityAttr(llvm::GlobalValue::VisibilityTypes v) : Attr(Visibility),
+ /// @brief An enumeration for the kinds of visibility of symbols.
+ enum VisibilityTypes {
+ DefaultVisibility = 0,
+ HiddenVisibility,
+ ProtectedVisibility
+ };
+private:
+ VisibilityTypes VisibilityType;
+public:
+ VisibilityAttr(VisibilityTypes v) : Attr(Visibility),
VisibilityType(v) {}
- llvm::GlobalValue::VisibilityTypes getVisibility() const { return VisibilityType; }
+ VisibilityTypes getVisibility() const { return VisibilityType; }
// Implement isa/cast/dyncast/etc.
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed May 21 19:50:06 2008
@@ -723,10 +723,6 @@
/// aggregate Constant of ConstantInt(s).
void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const;
- /// 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);
-
virtual SourceRange getSourceRange() const {
return SourceRange(getBase()->getLocStart(), AccessorLoc);
}
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed May 21 19:50:06 2008
@@ -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 @@
}
}
-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,
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed May 21 19:50:06 2008
@@ -60,6 +60,16 @@
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 @@
// 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 @@
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 @@
// 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 @@
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");
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed May 21 19:50:06 2008
@@ -171,7 +171,7 @@
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
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed May 21 19:50:06 2008
@@ -350,6 +350,11 @@
/// 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
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed May 21 19:50:06 2008
@@ -82,6 +82,24 @@
&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 @@
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.
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Wed May 21 19:50:06 2008
@@ -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 @@
/// 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
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=51398&r1=51397&r2=51398&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 21 19:50:06 2008
@@ -2621,16 +2621,16 @@
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);
More information about the cfe-commits
mailing list