diff options
author | Duncan Sands <baldrick@free.fr> | 2008-05-26 19:58:59 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2008-05-26 19:58:59 +0000 |
commit | 28c3cff8250b3fe2adc6479306fe7dbdb48a1bdb (patch) | |
tree | 7228a30f4d1d804257ae14016a3b4c254de30c06 /lib/VMCore | |
parent | 78ecf0d7b1ee7b1c44825d746b2f64e3a14aeb9b (diff) | |
download | external_llvm-28c3cff8250b3fe2adc6479306fe7dbdb48a1bdb.zip external_llvm-28c3cff8250b3fe2adc6479306fe7dbdb48a1bdb.tar.gz external_llvm-28c3cff8250b3fe2adc6479306fe7dbdb48a1bdb.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51567 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Function.cpp | 12 | ||||
-rw-r--r-- | lib/VMCore/Globals.cpp | 21 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index 49e69e1..2ab1194 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 1a328d8..229b012 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 //===----------------------------------------------------------------------===// |