aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2007-01-12 19:20:47 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2007-01-12 19:20:47 +0000
commit7f70559bc47877bafc6dfa92b7df6b64650445fb (patch)
tree35e2a9f532175fdf23d0253f970ff2132448e5d9 /lib
parentab7752c1496c2913793305ba4b989a551c5617e1 (diff)
* PIC codegen for X86/Linux has been implemented
* PIC-aware internal structures in X86 Codegen have been refactored * Visibility (default/weak) has been added * Docs fixes (external weak linkage, visibility, formatting) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33136 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AsmParser/Lexer.l1
-rw-r--r--lib/AsmParser/Lexer.l.cvs1
-rw-r--r--lib/AsmParser/llvmAsmParser.y52
-rw-r--r--lib/AsmParser/llvmAsmParser.y.cvs52
-rw-r--r--lib/Bytecode/Reader/Analyzer.cpp7
-rw-r--r--lib/Bytecode/Reader/Reader.cpp36
-rw-r--r--lib/Bytecode/Writer/Writer.cpp22
-rw-r--r--lib/Target/CBackend/CBackend.cpp12
-rw-r--r--lib/Target/X86/README.txt4
-rwxr-xr-xlib/Target/X86/X86ATTAsmPrinter.cpp109
-rw-r--r--lib/Target/X86/X86AsmPrinter.cpp13
-rwxr-xr-xlib/Target/X86/X86AsmPrinter.h11
-rw-r--r--lib/Target/X86/X86ISelDAGToDAG.cpp17
-rw-r--r--lib/Target/X86/X86ISelLowering.cpp79
-rw-r--r--lib/Target/X86/X86RegisterInfo.cpp4
-rw-r--r--lib/Target/X86/X86Subtarget.cpp15
-rw-r--r--lib/Target/X86/X86Subtarget.h25
-rw-r--r--lib/Target/X86/X86TargetMachine.cpp21
-rw-r--r--lib/VMCore/AsmWriter.cpp20
19 files changed, 358 insertions, 143 deletions
diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l
index 5300b3dabe..22fe64bf0d 100644
--- a/lib/AsmParser/Lexer.l
+++ b/lib/AsmParser/Lexer.l
@@ -203,6 +203,7 @@ weak { return WEAK; }
appending { return APPENDING; }
dllimport { return DLLIMPORT; }
dllexport { return DLLEXPORT; }
+hidden { return HIDDEN; }
extern_weak { return EXTERN_WEAK; }
external { return EXTERNAL; }
implementation { return IMPLEMENTATION; }
diff --git a/lib/AsmParser/Lexer.l.cvs b/lib/AsmParser/Lexer.l.cvs
index 5300b3dabe..22fe64bf0d 100644
--- a/lib/AsmParser/Lexer.l.cvs
+++ b/lib/AsmParser/Lexer.l.cvs
@@ -203,6 +203,7 @@ weak { return WEAK; }
appending { return APPENDING; }
dllimport { return DLLIMPORT; }
dllexport { return DLLEXPORT; }
+hidden { return HIDDEN; }
extern_weak { return EXTERN_WEAK; }
external { return EXTERNAL; }
implementation { return IMPLEMENTATION; }
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index b84cf25150..52d8847d32 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -210,6 +210,7 @@ static struct PerFunctionInfo {
std::map<const Type*, ValueList> LateResolveValues;
bool isDeclare; // Is this function a forward declararation?
GlobalValue::LinkageTypes Linkage; // Linkage for forward declaration.
+ GlobalValue::VisibilityTypes Visibility;
/// BBForwardRefs - When we see forward references to basic blocks, keep
/// track of them here.
@@ -220,7 +221,8 @@ static struct PerFunctionInfo {
inline PerFunctionInfo() {
CurrentFunction = 0;
isDeclare = false;
- Linkage = GlobalValue::ExternalLinkage;
+ Linkage = GlobalValue::ExternalLinkage;
+ Visibility = GlobalValue::DefaultVisibility;
}
inline void FunctionStart(Function *M) {
@@ -245,6 +247,7 @@ static struct PerFunctionInfo {
CurrentFunction = 0;
isDeclare = false;
Linkage = GlobalValue::ExternalLinkage;
+ Visibility = GlobalValue::DefaultVisibility;
}
} CurFun; // Info for the current function...
@@ -648,7 +651,9 @@ static void setValueName(Value *V, char *NameStr) {
/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
/// this is a declaration, otherwise it is a definition.
static GlobalVariable *
-ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
+ParseGlobalVariable(char *NameStr,
+ GlobalValue::LinkageTypes Linkage,
+ GlobalValue::VisibilityTypes Visibility,
bool isConstantGlobal, const Type *Ty,
Constant *Initializer) {
if (isa<FunctionType>(Ty)) {
@@ -681,6 +686,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
CurModule.CurrentModule->getGlobalList().push_back(GV);
GV->setInitializer(Initializer);
GV->setLinkage(Linkage);
+ GV->setVisibility(Visibility);
GV->setConstant(isConstantGlobal);
InsertValue(GV, CurModule.Values);
return GV;
@@ -702,6 +708,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
GlobalVariable *GV =
new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
CurModule.CurrentModule);
+ GV->setVisibility(Visibility);
InsertValue(GV, CurModule.Values);
return GV;
}
@@ -898,6 +905,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
std::vector<llvm::Constant*> *ConstVector;
llvm::GlobalValue::LinkageTypes Linkage;
+ llvm::GlobalValue::VisibilityTypes Visibility;
llvm::FunctionType::ParameterAttributes ParamAttrs;
int64_t SInt64Val;
uint64_t UInt64Val;
@@ -940,6 +948,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%type <BoolVal> OptSideEffect // 'sideeffect' or not.
%type <Linkage> GVInternalLinkage GVExternalLinkage
%type <Linkage> FunctionDefineLinkage FunctionDeclareLinkage
+%type <Visibility> GVVisibilityStyle
%type <Endianness> BigOrLittle
// ValueRef - Unresolved reference to a definition or BB
@@ -1011,6 +1020,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
// Function Attributes
%token NORETURN
+// Visibility Styles
+%token DEFAULT HIDDEN
+
%start Module
%%
@@ -1081,6 +1093,11 @@ GVExternalLinkage
| EXTERNAL { $$ = GlobalValue::ExternalLinkage; }
;
+GVVisibilityStyle
+ : /*empty*/ { $$ = GlobalValue::DefaultVisibility; }
+ | HIDDEN { $$ = GlobalValue::HiddenVisibility; }
+ ;
+
FunctionDeclareLinkage
: /*empty*/ { $$ = GlobalValue::ExternalLinkage; }
| DLLIMPORT { $$ = GlobalValue::DLLImportLinkage; }
@@ -1225,7 +1242,7 @@ Types
if (isVarArg) Params.pop_back();
FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, Attrs);
- delete $3; // Delete the argument list
+ delete $3; // Delete the argument list
delete $1; // Delete the return type handle
$$ = new PATypeHolder(HandleUpRefs(FT));
CHECK_FOR_ERROR
@@ -1883,29 +1900,29 @@ Definition
}
CHECK_FOR_ERROR
}
- | OptAssign GlobalType ConstVal { /* "Externally Visible" Linkage */
- if ($3 == 0)
+ | OptAssign GVVisibilityStyle GlobalType ConstVal { /* "Externally Visible" Linkage */
+ if ($4 == 0)
GEN_ERROR("Global value initializer is not a constant!");
- CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, $2,
- $3->getType(), $3);
+ CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
+ $2, $3, $4->getType(), $4);
CHECK_FOR_ERROR
} GlobalVarAttributes {
CurGV = 0;
}
- | OptAssign GVInternalLinkage GlobalType ConstVal {
- if ($4 == 0)
+ | OptAssign GVInternalLinkage GVVisibilityStyle GlobalType ConstVal {
+ if ($5 == 0)
GEN_ERROR("Global value initializer is not a constant!");
- CurGV = ParseGlobalVariable($1, $2, $3, $4->getType(), $4);
+ CurGV = ParseGlobalVariable($1, $2, $3, $4, $5->getType(), $5);
CHECK_FOR_ERROR
} GlobalVarAttributes {
CurGV = 0;
}
- | OptAssign GVExternalLinkage GlobalType Types {
+ | OptAssign GVExternalLinkage GVVisibilityStyle GlobalType Types {
if (!UpRefs.empty())
- GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription());
- CurGV = ParseGlobalVariable($1, $2, $3, *$4, 0);
+ GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription());
+ CurGV = ParseGlobalVariable($1, $2, $3, $4, *$5, 0);
CHECK_FOR_ERROR
- delete $4;
+ delete $5;
} GlobalVarAttributes {
CurGV = 0;
CHECK_FOR_ERROR
@@ -2103,6 +2120,7 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')'
// correctly handle cases, when pointer to function is passed as argument to
// another function.
Fn->setLinkage(CurFun.Linkage);
+ Fn->setVisibility(CurFun.Visibility);
}
Fn->setCallingConv($1);
Fn->setAlignment($9);
@@ -2136,12 +2154,13 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')'
BEGIN : BEGINTOK | '{'; // Allow BEGIN or '{' to start a function
-FunctionHeader : FunctionDefineLinkage FunctionHeaderH BEGIN {
+FunctionHeader : FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN {
$$ = CurFun.CurrentFunction;
// Make sure that we keep track of the linkage type even if there was a
// previous "declare".
$$->setLinkage($1);
+ $$->setVisibility($2);
};
END : ENDTOK | '}'; // Allow end of '}' to end a function
@@ -2151,8 +2170,9 @@ Function : BasicBlockList END {
CHECK_FOR_ERROR
};
-FunctionProto : FunctionDeclareLinkage FunctionHeaderH {
+FunctionProto : FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH {
CurFun.CurrentFunction->setLinkage($1);
+ CurFun.CurrentFunction->setVisibility($2);
$$ = CurFun.CurrentFunction;
CurFun.FunctionDone();
CHECK_FOR_ERROR
diff --git a/lib/AsmParser/llvmAsmParser.y.cvs b/lib/AsmParser/llvmAsmParser.y.cvs
index b84cf25150..52d8847d32 100644
--- a/lib/AsmParser/llvmAsmParser.y.cvs
+++ b/lib/AsmParser/llvmAsmParser.y.cvs
@@ -210,6 +210,7 @@ static struct PerFunctionInfo {
std::map<const Type*, ValueList> LateResolveValues;
bool isDeclare; // Is this function a forward declararation?
GlobalValue::LinkageTypes Linkage; // Linkage for forward declaration.
+ GlobalValue::VisibilityTypes Visibility;
/// BBForwardRefs - When we see forward references to basic blocks, keep
/// track of them here.
@@ -220,7 +221,8 @@ static struct PerFunctionInfo {
inline PerFunctionInfo() {
CurrentFunction = 0;
isDeclare = false;
- Linkage = GlobalValue::ExternalLinkage;
+ Linkage = GlobalValue::ExternalLinkage;
+ Visibility = GlobalValue::DefaultVisibility;
}
inline void FunctionStart(Function *M) {
@@ -245,6 +247,7 @@ static struct PerFunctionInfo {
CurrentFunction = 0;
isDeclare = false;
Linkage = GlobalValue::ExternalLinkage;
+ Visibility = GlobalValue::DefaultVisibility;
}
} CurFun; // Info for the current function...
@@ -648,7 +651,9 @@ static void setValueName(Value *V, char *NameStr) {
/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
/// this is a declaration, otherwise it is a definition.
static GlobalVariable *
-ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
+ParseGlobalVariable(char *NameStr,
+ GlobalValue::LinkageTypes Linkage,
+ GlobalValue::VisibilityTypes Visibility,
bool isConstantGlobal, const Type *Ty,
Constant *Initializer) {
if (isa<FunctionType>(Ty)) {
@@ -681,6 +686,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
CurModule.CurrentModule->getGlobalList().push_back(GV);
GV->setInitializer(Initializer);
GV->setLinkage(Linkage);
+ GV->setVisibility(Visibility);
GV->setConstant(isConstantGlobal);
InsertValue(GV, CurModule.Values);
return GV;
@@ -702,6 +708,7 @@ ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
GlobalVariable *GV =
new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
CurModule.CurrentModule);
+ GV->setVisibility(Visibility);
InsertValue(GV, CurModule.Values);
return GV;
}
@@ -898,6 +905,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
std::vector<llvm::Constant*> *ConstVector;
llvm::GlobalValue::LinkageTypes Linkage;
+ llvm::GlobalValue::VisibilityTypes Visibility;
llvm::FunctionType::ParameterAttributes ParamAttrs;
int64_t SInt64Val;
uint64_t UInt64Val;
@@ -940,6 +948,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
%type <BoolVal> OptSideEffect // 'sideeffect' or not.
%type <Linkage> GVInternalLinkage GVExternalLinkage
%type <Linkage> FunctionDefineLinkage FunctionDeclareLinkage
+%type <Visibility> GVVisibilityStyle
%type <Endianness> BigOrLittle
// ValueRef - Unresolved reference to a definition or BB
@@ -1011,6 +1020,9 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
// Function Attributes
%token NORETURN
+// Visibility Styles
+%token DEFAULT HIDDEN
+
%start Module
%%
@@ -1081,6 +1093,11 @@ GVExternalLinkage
| EXTERNAL { $$ = GlobalValue::ExternalLinkage; }
;
+GVVisibilityStyle
+ : /*empty*/ { $$ = GlobalValue::DefaultVisibility; }
+ | HIDDEN { $$ = GlobalValue::HiddenVisibility; }
+ ;
+
FunctionDeclareLinkage
: /*empty*/ { $$ = GlobalValue::ExternalLinkage; }
| DLLIMPORT { $$ = GlobalValue::DLLImportLinkage; }
@@ -1225,7 +1242,7 @@ Types
if (isVarArg) Params.pop_back();
FunctionType *FT = FunctionType::get(*$1, Params, isVarArg, Attrs);
- delete $3; // Delete the argument list
+ delete $3; // Delete the argument list
delete $1; // Delete the return type handle
$$ = new PATypeHolder(HandleUpRefs(FT));
CHECK_FOR_ERROR
@@ -1883,29 +1900,29 @@ Definition
}
CHECK_FOR_ERROR
}
- | OptAssign GlobalType ConstVal { /* "Externally Visible" Linkage */
- if ($3 == 0)
+ | OptAssign GVVisibilityStyle GlobalType ConstVal { /* "Externally Visible" Linkage */
+ if ($4 == 0)
GEN_ERROR("Global value initializer is not a constant!");
- CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage, $2,
- $3->getType(), $3);
+ CurGV = ParseGlobalVariable($1, GlobalValue::ExternalLinkage,
+ $2, $3, $4->getType(), $4);
CHECK_FOR_ERROR
} GlobalVarAttributes {
CurGV = 0;
}
- | OptAssign GVInternalLinkage GlobalType ConstVal {
- if ($4 == 0)
+ | OptAssign GVInternalLinkage GVVisibilityStyle GlobalType ConstVal {
+ if ($5 == 0)
GEN_ERROR("Global value initializer is not a constant!");
- CurGV = ParseGlobalVariable($1, $2, $3, $4->getType(), $4);
+ CurGV = ParseGlobalVariable($1, $2, $3, $4, $5->getType(), $5);
CHECK_FOR_ERROR
} GlobalVarAttributes {
CurGV = 0;
}
- | OptAssign GVExternalLinkage GlobalType Types {
+ | OptAssign GVExternalLinkage GVVisibilityStyle GlobalType Types {
if (!UpRefs.empty())
- GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription());
- CurGV = ParseGlobalVariable($1, $2, $3, *$4, 0);
+ GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription());
+ CurGV = ParseGlobalVariable($1, $2, $3, $4, *$5, 0);
CHECK_FOR_ERROR
- delete $4;
+ delete $5;
} GlobalVarAttributes {
CurGV = 0;
CHECK_FOR_ERROR
@@ -2103,6 +2120,7 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')'
// correctly handle cases, when pointer to function is passed as argument to
// another function.
Fn->setLinkage(CurFun.Linkage);
+ Fn->setVisibility(CurFun.Visibility);
}
Fn->setCallingConv($1);
Fn->setAlignment($9);
@@ -2136,12 +2154,13 @@ FunctionHeaderH : OptCallingConv ResultTypes Name '(' ArgList ')'
BEGIN : BEGINTOK | '{'; // Allow BEGIN or '{' to start a function
-FunctionHeader : FunctionDefineLinkage FunctionHeaderH BEGIN {
+FunctionHeader : FunctionDefineLinkage GVVisibilityStyle FunctionHeaderH BEGIN {
$$ = CurFun.CurrentFunction;
// Make sure that we keep track of the linkage type even if there was a
// previous "declare".
$$->setLinkage($1);
+ $$->setVisibility($2);
};
END : ENDTOK | '}'; // Allow end of '}' to end a function
@@ -2151,8 +2170,9 @@ Function : BasicBlockList END {
CHECK_FOR_ERROR
};
-FunctionProto : FunctionDeclareLinkage FunctionHeaderH {
+FunctionProto : FunctionDeclareLinkage GVVisibilityStyle FunctionHeaderH {
CurFun.CurrentFunction->setLinkage($1);
+ CurFun.CurrentFunction->setVisibility($2);
$$ = CurFun.CurrentFunction;
CurFun.FunctionDone();
CHECK_FOR_ERROR
diff --git a/lib/Bytecode/Reader/Analyzer.cpp b/lib/Bytecode/Reader/Analyzer.cpp
index 899a534272..465e3b053e 100644
--- a/lib/Bytecode/Reader/Analyzer.cpp
+++ b/lib/Bytecode/Reader/Analyzer.cpp
@@ -162,6 +162,7 @@ public:
const Type* ElemType,
bool isConstant,
GlobalValue::LinkageTypes Linkage,
+ GlobalValue::VisibilityTypes Visibility,
unsigned SlotNum,
unsigned initSlot
) {
@@ -169,7 +170,9 @@ public:
*os << " GV: "
<< ( initSlot == 0 ? "Uni" : "I" ) << "nitialized, "
<< ( isConstant? "Constant, " : "Variable, ")
- << " Linkage=" << Linkage << " Type=";
+ << " Linkage=" << Linkage
+ << " Visibility="<< Visibility
+ << " Type=";
WriteTypeSymbolic(*os, ElemType, M);
*os << " Slot=" << SlotNum << " InitSlot=" << initSlot
<< "\n";
@@ -206,6 +209,7 @@ public:
*os << " Function Decl: ";
WriteTypeSymbolic(*os,Func->getType(),M);
*os <<", Linkage=" << Func->getLinkage();
+ *os <<", Visibility=" << Func->getVisibility();
*os << "\n";
}
}
@@ -311,6 +315,7 @@ public:
if (os) {
*os << " BLOCK: Function {\n"
<< " Linkage: " << Func->getLinkage() << "\n"
+ << " Visibility: " << Func->getVisibility() << "\n"
<< " Type: ";
WriteTypeSymbolic(*os,Func->getType(),M);
*os << "\n";
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index ce3826cb24..b91604acd7 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -1628,9 +1628,12 @@ void BytecodeReader::ParseFunctionBody(Function* F) {
unsigned FuncSize = BlockEnd - At;
GlobalValue::LinkageTypes Linkage = GlobalValue::ExternalLinkage;
+ GlobalValue::VisibilityTypes Visibility = GlobalValue::DefaultVisibility;
- unsigned LinkageType = read_vbr_uint();
- switch (LinkageType) {
+ unsigned rWord = read_vbr_uint();
+ unsigned LinkageID = rWord & 65535;
+ unsigned VisibilityID = rWord >> 16;
+ switch (LinkageID) {
case 0: Linkage = GlobalValue::ExternalLinkage; break;
case 1: Linkage = GlobalValue::WeakLinkage; break;
case 2: Linkage = GlobalValue::AppendingLinkage; break;
@@ -1644,8 +1647,17 @@ void BytecodeReader::ParseFunctionBody(Function* F) {
Linkage = GlobalValue::InternalLinkage;
break;
}
+ switch (VisibilityID) {
+ case 0: Visibility = GlobalValue::DefaultVisibility; break;
+ case 1: Visibility = GlobalValue::HiddenVisibility; break;
+ default:
+ error("Unknown visibility type: " + utostr(VisibilityID));
+ Visibility = GlobalValue::DefaultVisibility;
+ break;
+ }
F->setLinkage(Linkage);
+ F->setVisibility(Visibility);
if (Handler) Handler->handleFunctionBegin(F,FuncSize);
// Keep track of how many basic blocks we have read in...
@@ -1844,6 +1856,7 @@ void BytecodeReader::ParseModuleGlobalInfo() {
// Linkage, bit4+ = slot#
unsigned SlotNo = VarType >> 5;
unsigned LinkageID = (VarType >> 2) & 7;
+ unsigned VisibilityID = 0;
bool isConstant = VarType & 1;
bool hasInitializer = (VarType & 2) != 0;
unsigned Alignment = 0;
@@ -1853,10 +1866,12 @@ void BytecodeReader::ParseModuleGlobalInfo() {
if (LinkageID == 3 && !hasInitializer) {
unsigned ExtWord = read_vbr_uint();
// The extension word has this format: bit 0 = has initializer, bit 1-3 =
- // linkage, bit 4-8 = alignment (log2), bits 10+ = future use.
+ // linkage, bit 4-8 = alignment (log2), bit 9 = has section,
+ // bits 10-12 = visibility, bits 13+ = future use.
hasInitializer = ExtWord & 1;
LinkageID = (ExtWord >> 1) & 7;
Alignment = (1 << ((ExtWord >> 4) & 31)) >> 1;
+ VisibilityID = (ExtWord >> 10) & 7;
if (ExtWord & (1 << 9)) // Has a section ID.
GlobalSectionID = read_vbr_uint();
@@ -1877,7 +1892,16 @@ void BytecodeReader::ParseModuleGlobalInfo() {
Linkage = GlobalValue::InternalLinkage;
break;
}
-
+ GlobalValue::VisibilityTypes Visibility;
+ switch (VisibilityID) {
+ case 0: Visibility = GlobalValue::DefaultVisibility; break;
+ case 1: Visibility = GlobalValue::HiddenVisibility; break;
+ default:
+ error("Unknown visibility type: " + utostr(VisibilityID));
+ Visibility = GlobalValue::DefaultVisibility;
+ break;
+ }
+
const Type *Ty = getType(SlotNo);
if (!Ty)
error("Global has no type! SlotNo=" + utostr(SlotNo));
@@ -1891,6 +1915,7 @@ void BytecodeReader::ParseModuleGlobalInfo() {
GlobalVariable *GV = new GlobalVariable(ElTy, isConstant, Linkage,
0, "", TheModule);
GV->setAlignment(Alignment);
+ GV->setVisibility(Visibility);
insertValue(GV, SlotNo, ModuleValues);
if (GlobalSectionID != 0)
@@ -1904,7 +1929,8 @@ void BytecodeReader::ParseModuleGlobalInfo() {
// Notify handler about the global value.
if (Handler)
- Handler->handleGlobalVariable(ElTy, isConstant, Linkage, SlotNo,initSlot);
+ Handler->handleGlobalVariable(ElTy, isConstant, Linkage, Visibility,
+ SlotNo, initSlot);
// Get next item
VarType = read_vbr_uint();
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index c7003cdd7f..10a151d19c 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -960,6 +960,14 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
}
}
+static unsigned getEncodedVisibility(const GlobalValue *GV) {
+ switch (GV->getVisibility()) {
+ default: assert(0 && "Invalid visibility!");
+ case GlobalValue::DefaultVisibility: return 0;
+ case GlobalValue::HiddenVisibility: return 1;
+ }
+}
+
void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfoBlockID, *this);
@@ -979,7 +987,9 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// Fields: bit0 = isConstant, bit1 = hasInitializer, bit2-4=Linkage,
// bit5+ = Slot # for type.
- bool HasExtensionWord = (I->getAlignment() != 0) || I->hasSection();
+ bool HasExtensionWord = (I->getAlignment() != 0) ||
+ I->hasSection() ||
+ (I->getVisibility() != GlobalValue::DefaultVisibility);
// If we need to use the extension byte, set linkage=3(internal) and
// initializer = 0 (impossible!).
@@ -993,12 +1003,13 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
output_vbr(oSlot);
// The extension word has this format: bit 0 = has initializer, bit 1-3 =
- // linkage, bit 4-8 = alignment (log2), bit 9 = has SectionID,
- // bits 10+ = future use.
+ // linkage, bit 4-8 = alignment (log2), bit 9 = has SectionID,
+ // bits 10-12 = visibility, bits 13+ = future use.
unsigned ExtWord = (unsigned)I->hasInitializer() |
(getEncodedLinkage(I) << 1) |
((Log2_32(I->getAlignment())+1) << 4) |
- ((unsigned)I->hasSection() << 9);
+ ((unsigned)I->hasSection() << 9) |
+ (getEncodedVisibility(I) << 10);
output_vbr(ExtWord);
if (I->hasSection()) {
// Give section names unique ID's.
@@ -1102,7 +1113,8 @@ void BytecodeWriter::outputFunction(const Function *F) {
if (F->isExternal()) return;
BytecodeBlock FunctionBlock(BytecodeFormat::FunctionBlockID, *this);
- output_vbr(getEncodedLinkage(F));
+ unsigned rWord = (getEncodedVisibility(F) << 16) | getEncodedLinkage(F);
+ output_vbr(rWord);
// Get slot information about the function...
Table.incorporateFunction(F);
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index a0b4ceb7f1..1346acbb04 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -1290,6 +1290,11 @@ static void generateCompilerSpecificCode(std::ostream& Out) {
<< "#define __ATTRIBUTE_WEAK__\n"
<< "#endif\n\n";
+ // Add hidden visibility support. FIXME: APPLE_CC?
+ Out << "#if defined(__GNUC__)\n"
+ << "#define __HIDDEN__ __attribute__((visibility(\"hidden\")))\n"
+ << "#endif\n\n";
+
// Define NaN and Inf as GCC builtins if using GCC, as 0 otherwise
// From the GCC documentation:
//
@@ -1500,6 +1505,8 @@ bool CWriter::doInitialization(Module &M) {
Out << " __ATTRIBUTE_CTOR__";
if (StaticDtors.count(I))
Out << " __ATTRIBUTE_DTOR__";
+ if (I->hasHiddenVisibility())
+ Out << " __HIDDEN__";
if (I->hasName() && I->getName()[0] == 1)
Out << " LLVM_ASM(\"" << I->getName().c_str()+1 << "\")";
@@ -1531,6 +1538,8 @@ bool CWriter::doInitialization(Module &M) {
Out << " __ATTRIBUTE_WEAK__";
else if (I->hasExternalWeakLinkage())
Out << " __EXTERNAL_WEAK__";
+ if (I->hasHiddenVisibility())
+ Out << " __HIDDEN__";
Out << ";\n";
}
}
@@ -1559,6 +1568,9 @@ bool CWriter::doInitialization(Module &M) {
else if (I->hasWeakLinkage())
Out << " __ATTRIBUTE_WEAK__";
+ if (I->hasHiddenVisibility())
+ Out << " __HIDDEN__";
+
// If the initializer is not null, emit the initializer. If it is null,
// we try to avoid emitting large amounts of zeros. The problem with
// this, however, occurs when the variable has weak linkage. In this
diff --git a/lib/Target/X86/README.txt b/lib/Target/X86/README.txt
index c871a76486..7e365203a8 100644
--- a/lib/Target/X86/README.txt
+++ b/lib/Target/X86/README.txt
@@ -534,10 +534,6 @@ do not make use of.
//===---------------------------------------------------------------------===//
-We should handle __attribute__ ((__visibility__ ("hidden"))).
-
-//===---------------------------------------------------------------------===//
-
int %foo(int* %a, int %t) {
entry:
br label %cond_true
diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp
index ccc2965064..7edea6f074 100755
--- a/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -19,6 +19,7 @@
#include "X86MachineFunctionInfo.h"
#include "X86TargetMachine.h"
#include "X86TargetAsmInfo.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/CallingConv.h"
#include "llvm/Module.h"
#include "llvm/Support/Mangler.h"
@@ -29,6 +30,21 @@ using namespace llvm;
STATISTIC(EmittedInsts, "Number of machine instrs printed");
+static std::string computePICLabel(unsigned fnNumber,
+ const X86Subtarget* Subtarget)
+{
+ std::string label;
+
+ if (Subtarget->isTargetDarwin()) {
+ label = "\"L" + utostr_32(fnNumber) + "$pb\"";
+ } else if (Subtarget->isTargetELF()) {
+ label = ".Lllvm$" + utostr_32(fnNumber) + "$piclabel";
+ } else
+ assert(0 && "Don't know how to print PIC label!\n");
+
+ return label;
+}
+
/// getSectionForFunction - Return the section that we should emit the
/// specified function body into.
std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
@@ -109,12 +125,15 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
}
break;
}
+ if (F->hasHiddenVisibility())
+ O << "\t.hidden " << CurrentFnName << "\n";
+
O << CurrentFnName << ":\n";
// Add some workaround for linkonce linkage on Cygwin\MinGW
if (Subtarget->isTargetCygMing() &&
(F->getLinkage() == Function::LinkOnceLinkage ||
F->getLinkage() == Function::WeakLinkage))
- O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n";
+ O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n";
if (Subtarget->isTargetDarwin() ||
Subtarget->isTargetELF() ||
@@ -193,9 +212,14 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
if (!isMemOp) O << '$';
O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_"
<< MO.getJumpTableIndex();
- if (X86PICStyle == PICStyle::Stub &&
- TM.getRelocationModel() == Reloc::PIC_)
- O << "-\"L" << getFunctionNumber() << "$pb\"";
+
+ if (TM.getRelocationModel() == Reloc::PIC_) {
+ if (Subtarget->isPICStyleStub())
+ O << "-\"L" << getFunctionNumber() << "$pb\"";
+ else if (Subtarget->isPICStyleGOT())
+ O << "@GOTOFF";
+ }
+
if (isMemOp && Subtarget->is64Bit() && !NotRIPRel)
O << "(%rip)";
return;
@@ -205,9 +229,14 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
if (!isMemOp) O << '$';
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
<< MO.getConstantPoolIndex();
- if (X86PICStyle == PICStyle::Stub &&
- TM.getRelocationModel() == Reloc::PIC_)
- O << "-\"L" << getFunctionNumber() << "$pb\"";
+
+ if (TM.getRelocationModel() == Reloc::PIC_) {
+ if (Subtarget->isPICStyleStub())
+ O << "-\"L" << getFunctionNumber() << "$pb\"";
+ if (Subtarget->isPICStyleGOT())
+ O << "@GOTOFF";
+ }
+
int Offset = MO.getOffset();
if (Offset > 0)
O << "+" << Offset;
@@ -228,11 +257,11 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
bool isExt = (GV->isExternal() || GV->hasWeakLinkage() ||
GV->hasLinkOnceLinkage());
+ bool isHidden = GV->hasHiddenVisibility();
X86SharedAsmPrinter::decorateName(Name, GV);
- if (X86PICStyle == PICStyle::Stub &&
- TM.getRelocationModel() != Reloc::Static) {
+ if (Subtarget->isPICStyleStub()) {
// Link-once, External, or Weakly-linked global variables need
// non-lazily-resolved stubs
if (isExt) {
@@ -258,6 +287,12 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
O << "__imp_";
}
O << Name;
+
+ if (Subtarget->isPICStyleGOT() && isCallOp && isa<Function>(GV)) {
+ // Assemble call via PLT for non-local symbols
+ if (!isHidden || isExt)
+ O << "@PLT";
+ }
}
if (GV->hasExternalWeakLinkage())
@@ -269,31 +304,55 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
else if (Offset < 0)
O << Offset;
- if (isMemOp && Subtarget->is64Bit()) {
- if (isExt && TM.getRelocationModel() != Reloc::Static)
- O << "@GOTPCREL(%rip)";
- else if (!NotRIPRel)
- // Use rip when possible to reduce code size, except when index or
- // base register are also part of the address. e.g.
- // foo(%rip)(%rcx,%rax,4) is not legal
- O << "(%rip)";
+ if (isMemOp) {
+ if (isExt) {
+ if (Subtarget->isPICStyleGOT()) {
+ O << "@GOT";
+ } else if (Subtarget->isPICStyleRIPRel()) {
+ O << "@GOTPCREL(%rip)";
+ } if (Subtarget->is64Bit() && !NotRIPRel)
+ // Use rip when possible to reduce code size, except when
+ // index or base register are also part of the address. e.g.
+ // foo(%rip)(%rcx,%rax,4) is not legal
+ O << "(%rip)";