[PATCH] D150453: [NFC] Refactor GlobalVariable Ctor
Guillaume Chatelet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 12 08:54:03 PDT 2023
gchatelet created this revision.
gchatelet added a reviewer: courbet.
Herald added a subscriber: hiraditya.
Herald added a project: All.
gchatelet requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Reuse logic from other ctor and remove code duplication.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150453
Files:
llvm/lib/IR/Globals.cpp
Index: llvm/lib/IR/Globals.cpp
===================================================================
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -44,9 +44,7 @@
return F->isMaterializable();
return false;
}
-Error GlobalValue::materialize() {
- return getParent()->materialize(this);
-}
+Error GlobalValue::materialize() { return getParent()->materialize(this); }
/// Override destroyConstantImpl to make sure it doesn't get called on
/// GlobalValue's because they shouldn't be treated like other constants.
@@ -438,23 +436,11 @@
ThreadLocalMode TLMode,
std::optional<unsigned> AddressSpace,
bool isExternallyInitialized)
- : GlobalObject(Ty, Value::GlobalVariableVal,
- OperandTraits<GlobalVariable>::op_begin(this),
- InitVal != nullptr, Link, Name,
- AddressSpace
- ? *AddressSpace
- : M.getDataLayout().getDefaultGlobalsAddressSpace()),
- isConstantGlobal(constant),
- isExternallyInitializedConstant(isExternallyInitialized) {
- assert(!Ty->isFunctionTy() && PointerType::isValidElementType(Ty) &&
- "invalid type for global variable");
- setThreadLocalMode(TLMode);
- if (InitVal) {
- assert(InitVal->getType() == Ty &&
- "Initializer should be the same type as the GlobalVariable!");
- Op<0>() = InitVal;
- }
-
+ : GlobalVariable(Ty, constant, Link, InitVal, Name, TLMode,
+ AddressSpace
+ ? *AddressSpace
+ : M.getDataLayout().getDefaultGlobalsAddressSpace(),
+ isExternallyInitialized) {
if (Before)
Before->getParent()->insertGlobalVariable(Before->getIterator(), this);
else
@@ -545,13 +531,9 @@
return create(Aliasee->getLinkage(), Name, Aliasee);
}
-void GlobalAlias::removeFromParent() {
- getParent()->removeAlias(this);
-}
+void GlobalAlias::removeFromParent() { getParent()->removeAlias(this); }
-void GlobalAlias::eraseFromParent() {
- getParent()->eraseAlias(this);
-}
+void GlobalAlias::eraseFromParent() { getParent()->eraseAlias(this); }
void GlobalAlias::setAliasee(Constant *Aliasee) {
assert((!Aliasee || Aliasee->getType() == getType()) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150453.521669.patch
Type: text/x-patch
Size: 2346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230512/698213e0/attachment.bin>
More information about the llvm-commits
mailing list