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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51398 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-05-22 00:50:06 +00:00
Родитель 3eb817e509
Коммит 4f8d123e3e
9 изменённых файлов: 62 добавлений и 30 удалений

Просмотреть файл

@ -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 @@ public:
};
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.

Просмотреть файл

@ -723,10 +723,6 @@ public:
/// 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);
}

Просмотреть файл

@ -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,

Просмотреть файл

@ -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");
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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
//===--------------------------------------------------------------------===//

Просмотреть файл

@ -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.

Просмотреть файл

@ -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

Просмотреть файл

@ -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);