mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-07 10:11:57 +00:00
Factor code to copy global value attributes like
the section or the visibility from one global value to another: copyAttributesFrom. This is particularly useful for duplicating functions: previously this was done by explicitly copying each attribute in turn at each place where a new function was created out of an old one, with the result that obscure attributes were regularly forgotten (like the collector or the section). Hopefully now everything is uniform and nothing is forgotten. llvm-svn: 51567
This commit is contained in:
parent
15d473d75a
commit
fa995d7cc5
@ -204,6 +204,10 @@ public:
|
|||||||
return paramHasAttr(1, ParamAttr::StructRet);
|
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
|
/// deleteBody - This method deletes the body of the function, and converts
|
||||||
/// the linkage to external.
|
/// the linkage to external.
|
||||||
///
|
///
|
||||||
|
@ -110,6 +110,10 @@ public:
|
|||||||
void setLinkage(LinkageTypes LT) { Linkage = LT; }
|
void setLinkage(LinkageTypes LT) { Linkage = LT; }
|
||||||
LinkageTypes getLinkage() const { return Linkage; }
|
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
|
/// 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
|
/// 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
|
/// the function has been read in yet or not. Unless you are working on the
|
||||||
|
@ -118,6 +118,10 @@ public:
|
|||||||
bool isThreadLocal() const { return isThreadLocalSymbol; }
|
bool isThreadLocal() const { return isThreadLocalSymbol; }
|
||||||
void setThreadLocal(bool Val) { isThreadLocalSymbol = Val; }
|
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,
|
/// removeFromParent - This method unlinks 'this' from the containing module,
|
||||||
/// but does not delete it.
|
/// but does not delete it.
|
||||||
///
|
///
|
||||||
|
@ -351,20 +351,10 @@ static void ForceRenaming(GlobalValue *GV, const std::string &Name) {
|
|||||||
/// CopyGVAttributes - copy additional attributes (those not needed to construct
|
/// CopyGVAttributes - copy additional attributes (those not needed to construct
|
||||||
/// a GlobalValue) from the SrcGV to the DestGV.
|
/// a GlobalValue) from the SrcGV to the DestGV.
|
||||||
static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
|
static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
|
||||||
// Propagate alignment, visibility and section info.
|
// Use the maximum alignment, rather than just copying the alignment of SrcGV.
|
||||||
DestGV->setAlignment(std::max(DestGV->getAlignment(), SrcGV->getAlignment()));
|
unsigned Alignment = std::max(DestGV->getAlignment(), SrcGV->getAlignment());
|
||||||
DestGV->setSection(SrcGV->getSection());
|
DestGV->copyAttributesFrom(SrcGV);
|
||||||
DestGV->setVisibility(SrcGV->getVisibility());
|
DestGV->setAlignment(Alignment);
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetLinkageResult - This analyzes the two global values and determines what
|
/// GetLinkageResult - This analyzes the two global values and determines what
|
||||||
|
@ -478,15 +478,13 @@ Function *ArgPromotion::DoPromotion(Function *F,
|
|||||||
|
|
||||||
// Create the new function body and insert it into the module...
|
// Create the new function body and insert it into the module...
|
||||||
Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
|
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
|
// Recompute the parameter attributes list based on the new arguments for
|
||||||
// the function.
|
// the function.
|
||||||
NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
|
NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
|
||||||
ParamAttrsVec.clear();
|
ParamAttrsVec.clear();
|
||||||
|
|
||||||
if (F->hasCollector())
|
|
||||||
NF->setCollector(F->getCollector());
|
|
||||||
F->getParent()->getFunctionList().insert(F, NF);
|
F->getParent()->getFunctionList().insert(F, NF);
|
||||||
NF->takeName(F);
|
NF->takeName(F);
|
||||||
|
|
||||||
|
@ -163,10 +163,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
|
|||||||
|
|
||||||
// Create the new function body and insert it into the module...
|
// Create the new function body and insert it into the module...
|
||||||
Function *NF = Function::Create(NFTy, Fn.getLinkage());
|
Function *NF = Function::Create(NFTy, Fn.getLinkage());
|
||||||
NF->setCallingConv(Fn.getCallingConv());
|
NF->copyAttributesFrom(&Fn);
|
||||||
NF->setParamAttrs(Fn.getParamAttrs());
|
|
||||||
if (Fn.hasCollector())
|
|
||||||
NF->setCollector(Fn.getCollector());
|
|
||||||
Fn.getParent()->getFunctionList().insert(&Fn, NF);
|
Fn.getParent()->getFunctionList().insert(&Fn, NF);
|
||||||
NF->takeName(&Fn);
|
NF->takeName(&Fn);
|
||||||
|
|
||||||
@ -556,10 +553,8 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
|
|||||||
|
|
||||||
// Create the new function body and insert it into the module...
|
// Create the new function body and insert it into the module...
|
||||||
Function *NF = Function::Create(NFTy, F->getLinkage());
|
Function *NF = Function::Create(NFTy, F->getLinkage());
|
||||||
NF->setCallingConv(F->getCallingConv());
|
NF->copyAttributesFrom(F);
|
||||||
NF->setParamAttrs(NewPAL);
|
NF->setParamAttrs(NewPAL);
|
||||||
if (F->hasCollector())
|
|
||||||
NF->setCollector(F->getCollector());
|
|
||||||
F->getParent()->getFunctionList().insert(F, NF);
|
F->getParent()->getFunctionList().insert(F, NF);
|
||||||
NF->takeName(F);
|
NF->takeName(F);
|
||||||
|
|
||||||
|
@ -123,10 +123,7 @@ namespace {
|
|||||||
if (std::find(Named.begin(), Named.end(), &*I) == Named.end()) {
|
if (std::find(Named.begin(), Named.end(), &*I) == Named.end()) {
|
||||||
Function *New = Function::Create(I->getFunctionType(),
|
Function *New = Function::Create(I->getFunctionType(),
|
||||||
GlobalValue::ExternalLinkage);
|
GlobalValue::ExternalLinkage);
|
||||||
New->setCallingConv(I->getCallingConv());
|
New->copyAttributesFrom(I);
|
||||||
New->setParamAttrs(I->getParamAttrs());
|
|
||||||
if (I->hasCollector())
|
|
||||||
New->setCollector(I->getCollector());
|
|
||||||
|
|
||||||
// If it's not the named function, delete the body of the function
|
// If it's not the named function, delete the body of the function
|
||||||
I->dropAllReferences();
|
I->dropAllReferences();
|
||||||
|
@ -232,7 +232,7 @@ Function *SRETPromotion::cloneFunctionBody(Function *F,
|
|||||||
|
|
||||||
FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
|
FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
|
||||||
Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
|
Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
|
||||||
NF->setCallingConv(F->getCallingConv());
|
NF->copyAttributesFrom(F);
|
||||||
NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
|
NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
|
||||||
F->getParent()->getFunctionList().insert(F, NF);
|
F->getParent()->getFunctionList().insert(F, NF);
|
||||||
NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
|
NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
|
||||||
|
@ -80,11 +80,8 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
|
|||||||
assert(ValueMap.count(I) && "No mapping from source argument specified!");
|
assert(ValueMap.count(I) && "No mapping from source argument specified!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Clone the parameter attributes
|
// Clone any attributes.
|
||||||
NewFunc->setParamAttrs(OldFunc->getParamAttrs());
|
NewFunc->copyAttributesFrom(OldFunc);
|
||||||
|
|
||||||
// Clone the calling convention
|
|
||||||
NewFunc->setCallingConv(OldFunc->getCallingConv());
|
|
||||||
|
|
||||||
// Loop over all of the basic blocks in the function, cloning them as
|
// 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
|
// appropriate. Note that we save BE this way in order to handle cloning of
|
||||||
|
@ -65,10 +65,7 @@ Module *llvm::CloneModule(const Module *M,
|
|||||||
Function *NF =
|
Function *NF =
|
||||||
Function::Create(cast<FunctionType>(I->getType()->getElementType()),
|
Function::Create(cast<FunctionType>(I->getType()->getElementType()),
|
||||||
GlobalValue::ExternalLinkage, I->getName(), New);
|
GlobalValue::ExternalLinkage, I->getName(), New);
|
||||||
NF->setCallingConv(I->getCallingConv());
|
NF->copyAttributesFrom(I);
|
||||||
NF->setParamAttrs(I->getParamAttrs());
|
|
||||||
if (I->hasCollector())
|
|
||||||
NF->setCollector(I->getCollector());
|
|
||||||
ValueMap[I]= NF;
|
ValueMap[I]= NF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
/// getIntrinsicID - This method returns the ID number of the specified
|
||||||
/// function, or Intrinsic::not_intrinsic if the function is not an
|
/// 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
|
/// intrinsic, or if the pointer is null. This value is always defined to be
|
||||||
|
@ -80,6 +80,15 @@ void GlobalValue::destroyConstant() {
|
|||||||
abort();
|
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
|
// GlobalVariable Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -160,6 +169,16 @@ void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
this->setOperand(0, cast<Constant>(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
|
// GlobalAlias Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user