aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Function.h4
-rw-r--r--include/llvm/GlobalValue.h4
-rw-r--r--include/llvm/GlobalVariable.h4
-rw-r--r--lib/Linker/LinkModules.cpp18
-rw-r--r--lib/Transforms/IPO/ArgumentPromotion.cpp6
-rw-r--r--lib/Transforms/IPO/DeadArgumentElimination.cpp9
-rw-r--r--lib/Transforms/IPO/ExtractGV.cpp5
-rw-r--r--lib/Transforms/IPO/StructRetPromotion.cpp2
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp11
-rw-r--r--lib/Transforms/Utils/CloneModule.cpp5
-rw-r--r--lib/VMCore/Function.cpp12
-rw-r--r--lib/VMCore/Globals.cpp21
12 files changed, 59 insertions, 42 deletions
diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index 5dd8502d3a..ef82457926 100644
--- a/include/llvm/Function.h
+++ b/include/llvm/Function.h
@@ -204,6 +204,10 @@ public:
return paramHasAttr(1, ParamAttr::StructRet);
}
+ /// copyAttributesFrom - copy all additional attributes (those not needed to
+ /// create a Function) from the Function Src to this one.
+ void copyAttributesFrom(const GlobalValue *Src);
+
/// deleteBody - This method deletes the body of the function, and converts
/// the linkage to external.
///
diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h
index b13a122e1a..bc0c0a7937 100644
--- a/include/llvm/GlobalValue.h
+++ b/include/llvm/GlobalValue.h
@@ -110,6 +110,10 @@ public:
void setLinkage(LinkageTypes LT) { Linkage = LT; }
LinkageTypes getLinkage() const { return Linkage; }
+ /// copyAttributesFrom - copy all additional attributes (those not needed to
+ /// create a GlobalValue) from the GlobalValue Src to this one.
+ virtual void copyAttributesFrom(const GlobalValue *Src);
+
/// hasNotBeenReadFromBitcode - If a module provider is being used to lazily
/// stream in functions from disk, this method can be used to check to see if
/// the function has been read in yet or not. Unless you are working on the
diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h
index ac72b77e76..a578cd1c09 100644
--- a/include/llvm/GlobalVariable.h
+++ b/include/llvm/GlobalVariable.h
@@ -118,6 +118,10 @@ public:
bool isThreadLocal() const { return isThreadLocalSymbol; }
void setThreadLocal(bool Val) { isThreadLocalSymbol = Val; }
+ /// copyAttributesFrom - copy all additional attributes (those not needed to
+ /// create a GlobalVariable) from the GlobalVariable Src to this one.
+ void copyAttributesFrom(const GlobalValue *Src);
+
/// removeFromParent - This method unlinks 'this' from the containing module,
/// but does not delete it.
///
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index fae7d9d748..66c68ca87f 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -351,20 +351,10 @@ static void ForceRenaming(GlobalValue *GV, const std::string &Name) {
/// CopyGVAttributes - copy additional attributes (those not needed to construct
/// a GlobalValue) from the SrcGV to the DestGV.
static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
- // Propagate alignment, visibility and section info.
- DestGV->setAlignment(std::max(DestGV->getAlignment(), SrcGV->getAlignment()));
- DestGV->setSection(SrcGV->getSection());
- DestGV->setVisibility(SrcGV->getVisibility());
- if (const Function *SrcF = dyn_cast<Function>(SrcGV)) {
- Function *DestF = cast<Function>(DestGV);
- DestF->setCallingConv(SrcF->getCallingConv());
- DestF->setParamAttrs(SrcF->getParamAttrs());
- if (SrcF->hasCollector())
- DestF->setCollector(SrcF->getCollector());
- } else if (const GlobalVariable *SrcVar = dyn_cast<GlobalVariable>(SrcGV)) {
- GlobalVariable *DestVar = cast<GlobalVariable>(DestGV);
- DestVar->setThreadLocal(SrcVar->isThreadLocal());
- }
+ // Use the maximum alignment, rather than just copying the alignment of SrcGV.
+ unsigned Alignment = std::max(DestGV->getAlignment(), SrcGV->getAlignment());
+ DestGV->copyAttributesFrom(SrcGV);
+ DestGV->setAlignment(Alignment);
}
/// GetLinkageResult - This analyzes the two global values and determines what
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp
index b3d783d2ae..7dd94f5bc8 100644
--- a/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -478,15 +478,13 @@ Function *ArgPromotion::DoPromotion(Function *F,
// Create the new function body and insert it into the module...
Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
- NF->setCallingConv(F->getCallingConv());
+ NF->copyAttributesFrom(F);
// Recompute the parameter attributes list based on the new arguments for
// the function.
NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
ParamAttrsVec.clear();
-
- if (F->hasCollector())
- NF->setCollector(F->getCollector());
+
F->getParent()->getFunctionList().insert(F, NF);
NF->takeName(F);
diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 9b3efe0962..2dab695224 100644
--- a/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -163,10 +163,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
// Create the new function body and insert it into the module...
Function *NF = Function::Create(NFTy, Fn.getLinkage());
- NF->setCallingConv(Fn.getCallingConv());
- NF->setParamAttrs(Fn.getParamAttrs());
- if (Fn.hasCollector())
- NF->setCollector(Fn.getCollector());
+ NF->copyAttributesFrom(&Fn);
Fn.getParent()->getFunctionList().insert(&Fn, NF);
NF->takeName(&Fn);
@@ -556,10 +553,8 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
// Create the new function body and insert it into the module...
Function *NF = Function::Create(NFTy, F->getLinkage());
- NF->setCallingConv(F->getCallingConv());
+ NF->copyAttributesFrom(F);
NF->setParamAttrs(NewPAL);
- if (F->hasCollector())
- NF->setCollector(F->getCollector());
F->getParent()->getFunctionList().insert(F, NF);
NF->takeName(F);
diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp
index 46232b880b..03a8e5cebc 100644
--- a/lib/Transforms/IPO/ExtractGV.cpp
+++ b/lib/Transforms/IPO/ExtractGV.cpp
@@ -123,10 +123,7 @@ namespace {
if (std::find(Named.begin(), Named.end(), &*I) == Named.end()) {
Function *New = Function::Create(I->getFunctionType(),
GlobalValue::ExternalLinkage);
- New->setCallingConv(I->getCallingConv());
- New->setParamAttrs(I->getParamAttrs());
- if (I->hasCollector())
- New->setCollector(I->getCollector());
+ New->copyAttributesFrom(I);
// If it's not the named function, delete the body of the function
I->dropAllReferences();
diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp
index f857dce669..174a6fa767 100644
--- a/lib/Transforms/IPO/StructRetPromotion.cpp
+++ b/lib/Transforms/IPO/StructRetPromotion.cpp
@@ -232,7 +232,7 @@ Function *SRETPromotion::cloneFunctionBody(Function *F,
FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
- NF->setCallingConv(F->getCallingConv());
+ NF->copyAttributesFrom(F);
NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
F->getParent()->getFunctionList().insert(F, NF);
NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp
index 57369143b4..9e3fe32992 100644
--- a/lib/Transforms/Utils/CloneFunction.cpp
+++ b/lib/Transforms/Utils/CloneFunction.cpp
@@ -80,11 +80,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
assert(ValueMap.count(I) && "No mapping from source argument specified!");
#endif
- // Clone the parameter attributes
- NewFunc->setParamAttrs(OldFunc->getParamAttrs());
-
- // Clone the calling convention
- NewFunc->setCallingConv(OldFunc->getCallingConv());
+ // Clone any attributes.
+ NewFunc->copyAttributesFrom(OldFunc);
// Loop over all of the basic blocks in the function, cloning them as
// appropriate. Note that we save BE this way in order to handle cloning of
@@ -339,8 +336,8 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
E = OldFunc->arg_end(); II != E; ++II)
assert(ValueMap.count(II) && "No mapping from source argument specified!");
#endif
-
- PruningFunctionCloner PFC(NewFunc, OldFunc, ValueMap, Returns,
+
+ PruningFunctionCloner PFC(NewFunc, OldFunc, ValueMap, Returns,
NameSuffix, CodeInfo, TD);
// Clone the entry block, and anything recursively reachable from it.
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp
index e75f915cb9..c94c531b01 100644
--- a/lib/Transforms/Utils/CloneModule.cpp
+++ b/lib/Transforms/Utils/CloneModule.cpp
@@ -65,10 +65,7 @@ Module *llvm::CloneModule(const Module *M,
Function *NF =
Function::Create(cast<FunctionType>(I->getType()->getElementType()),
GlobalValue::ExternalLinkage, I->getName(), New);
- NF->setCallingConv(I->getCallingConv());
- NF->setParamAttrs(I->getParamAttrs());
- if (I->hasCollector())
- NF->setCollector(I->getCollector());
+ NF->copyAttributesFrom(I);
ValueMap[I]= NF;
}
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 49e69e1b2c..2ab1194949 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -284,6 +284,18 @@ void Function::clearCollector() {
}
}
+/// copyAttributesFrom - copy all additional attributes (those not needed to
+/// create a Function) from the Function Src to this one.
+void Function::copyAttributesFrom(const GlobalValue *Src) {
+ assert(isa<Function>(Src) && "Expected a Function!");
+ GlobalValue::copyAttributesFrom(Src);
+ const Function *SrcF = cast<Function>(Src);
+ setCallingConv(SrcF->getCallingConv());
+ setParamAttrs(SrcF->getParamAttrs());
+ if (SrcF->hasCollector())
+ setCollector(SrcF->getCollector());
+}
+
/// getIntrinsicID - This method returns the ID number of the specified
/// function, or Intrinsic::not_intrinsic if the function is not an
/// intrinsic, or if the pointer is null. This value is always defined to be
diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp
index 1a328d80f6..229b0127a4 100644
--- a/lib/VMCore/Globals.cpp
+++ b/lib/VMCore/Globals.cpp
@@ -79,7 +79,16 @@ void GlobalValue::destroyConstant() {
assert(0 && "You can't GV->destroyConstant()!");
abort();
}
-
+
+/// copyAttributesFrom - copy all additional attributes (those not needed to
+/// create a GlobalValue) from the GlobalValue Src to this one.
+void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
+ setAlignment(Src->getAlignment());
+ setSection(Src->getSection());
+ setVisibility(Src->getVisibility());
+}
+
+
//===----------------------------------------------------------------------===//
// GlobalVariable Implementation
//===----------------------------------------------------------------------===//
@@ -160,6 +169,16 @@ void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To,
this->setOperand(0, cast<Constant>(To));
}
+/// copyAttributesFrom - copy all additional attributes (those not needed to
+/// create a GlobalVariable) from the GlobalVariable Src to this one.
+void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
+ assert(isa<GlobalVariable>(Src) && "Expected a GlobalVariable!");
+ GlobalValue::copyAttributesFrom(Src);
+ const GlobalVariable *SrcVar = cast<GlobalVariable>(Src);
+ setThreadLocal(SrcVar->isThreadLocal());
+}
+
+
//===----------------------------------------------------------------------===//
// GlobalAlias Implementation
//===----------------------------------------------------------------------===//