139 Commits

Author SHA1 Message Date
hev
a8874cf50b
[llvm][IR] Add per-global code model attribute (#72077)
This adds a per-global code model attribute, which can override the
target's code model to access global variables.

Suggested-by: Arthur Eubanks <aeubanks@google.com>
Link: https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816
Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944
2023-12-05 09:42:53 +08:00
Guillaume Chatelet
ce9b89f8be [NFC] Refactor GlobalVariable Ctor
Reuse logic from other ctor and remove code duplication.

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D150453
2023-05-15 07:30:07 +00:00
Vasileios Porpodas
823186b14d Recommit: [NFC][IR] Make Module::getGlobalList() private
This reverts commit cb5f239363a3c94db5425c105fcd45e77d2a16a9.
2023-02-14 15:12:51 -08:00
Vasileios Porpodas
cb5f239363 Revert "[NFC][IR] Make Module::getGlobalList() private"
This reverts commit ed3e3ee9e30dfbffd2170a770a49b36a7f444916.
2023-02-14 14:29:42 -08:00
Vasileios Porpodas
ed3e3ee9e3 [NFC][IR] Make Module::getGlobalList() private
This patch adds several missing GlobalList modifier functions, like
removeGlobalVariable(), eraseGlobalVariable() and insertGlobalVariable().
There is no longer need to access the list directly so it also makes
getGlobalList() private.

Differential Revision: https://reviews.llvm.org/D144027
2023-02-14 14:25:10 -08:00
Vasileios Porpodas
d180443570 [NFC][IR] Make Module::getIFuncList() private.
This patch adds several missing IFuncList modifier functions, like
removeIFunc(), eraseIFunc() and insertIFunc().
There is no longer need to access the list directly so it also makes
getIFuncList() private.

Differential Revision: https://reviews.llvm.org/D143968
2023-02-14 09:28:06 -08:00
Vasileios Porpodas
afad153a08 Recommit: [NFC][IR] Make Module::getAliasList() private
This reverts commit 6d4a674acbc56458bb084878d82d16e393d45a6b.
2023-02-13 20:07:56 -08:00
Vasileios Porpodas
6d4a674acb Revert "[NFC][IR] Make Module::getAliasList() private"
This reverts commit b64f7d028bdcaf679130afeed9518c09663f6dc8.
2023-02-13 19:12:30 -08:00
Vasileios Porpodas
b64f7d028b [NFC][IR] Make Module::getAliasList() private
This patch adds several missing AliasList modifier functions, like
removeAlias(), eraseAlias() and insertAlias().
There is no longer need to access the list directly so it also makes
getAliaList() private.

Differential Revision: https://reviews.llvm.org/D143958
2023-02-13 18:45:12 -08:00
Archibald Elliott
62c7f035b4 [NFC][TargetParser] Remove llvm/ADT/Triple.h
I also ran `git clang-format` to get the headers in the right order for
the new location, which has changed the order of other headers in two
files.
2023-02-07 12:39:46 +00:00
Guillaume Chatelet
ffc1205bde [reland][NFC] Transition GlobalObject alignment from MaybeAlign to Align
This is a follow up on https://reviews.llvm.org/D142459#4081179.
This first patch adds an overload to `GlobalObject::setAlignment` that accepts an `Align` type.
This already handles most of the calls.

This patch also converts a few call sites to the new type when this is safe.

Here is the list of the remaining call sites:

 - [clang/lib/CodeGen/CodeGenModule.cpp:1688](e195e6bad6/clang/lib/CodeGen/CodeGenModule.cpp (L1688))
 - [llvm/lib/AsmParser/LLParser.cpp:1309](e195e6bad6/llvm/lib/AsmParser/LLParser.cpp (L1309))
 - [llvm/lib/AsmParser/LLParser.cpp:6050](e195e6bad6/llvm/lib/AsmParser/LLParser.cpp (L6050))
 - [llvm/lib/Bitcode/Reader/BitcodeReader.cpp:3871](e195e6bad6/llvm/lib/Bitcode/Reader/BitcodeReader.cpp (L3871))
 - [llvm/lib/Bitcode/Reader/BitcodeReader.cpp:4030](e195e6bad6/llvm/lib/Bitcode/Reader/BitcodeReader.cpp (L4030))
 - [llvm/lib/IR/Core.cpp:2018](e195e6bad6/llvm/lib/IR/Core.cpp (L2018))
 - [llvm/lib/IR/Globals.cpp:141](e195e6bad6/llvm/lib/IR/Globals.cpp (L141))
 - [llvm/lib/Linker/IRMover.cpp:660](e195e6bad6/llvm/lib/Linker/IRMover.cpp (L660))
 - [llvm/lib/Linker/LinkModules.cpp:361](e195e6bad6/llvm/lib/Linker/LinkModules.cpp (L361))
 - [llvm/lib/Linker/LinkModules.cpp:362](e195e6bad6/llvm/lib/Linker/LinkModules.cpp (L362))
 - [llvm/lib/Transforms/IPO/MergeFunctions.cpp:782](e195e6bad6/llvm/lib/Transforms/IPO/MergeFunctions.cpp (L782))
 - [llvm/lib/Transforms/IPO/MergeFunctions.cpp:840](e195e6bad6/llvm/lib/Transforms/IPO/MergeFunctions.cpp (L840))
 - [llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1813](e195e6bad6/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp (L1813))
 - [llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp:27](e195e6bad6/llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp (L27))

Differential Revision: https://reviews.llvm.org/D142708
2023-01-31 15:09:10 +00:00
Guillaume Chatelet
e098ee726e Revert D142708 "[NFC] Transition GlobalObject alignment from MaybeAlign to Align"
This is breaking the build bots. e.g.,
https://lab.llvm.org/buildbot/#/builders/121/builds/27549

This reverts commit 6717efe74da825214cb4d307ad35e5fbda353301.
2023-01-31 14:12:51 +00:00
Guillaume Chatelet
6717efe74d [NFC] Transition GlobalObject alignment from MaybeAlign to Align
This is a follow up on https://reviews.llvm.org/D142459#4081179.
This first patch adds an overload to `GlobalObject::setAlignment` that accepts an `Align` type.
This already handles most of the calls.

This patch also converts a few call sites to the new type when this is safe.

Here is the list of the remaining call sites:

 - [clang/lib/CodeGen/CodeGenModule.cpp:1688](e195e6bad6/clang/lib/CodeGen/CodeGenModule.cpp (L1688))
 - [llvm/lib/AsmParser/LLParser.cpp:1309](e195e6bad6/llvm/lib/AsmParser/LLParser.cpp (L1309))
 - [llvm/lib/AsmParser/LLParser.cpp:6050](e195e6bad6/llvm/lib/AsmParser/LLParser.cpp (L6050))
 - [llvm/lib/Bitcode/Reader/BitcodeReader.cpp:3871](e195e6bad6/llvm/lib/Bitcode/Reader/BitcodeReader.cpp (L3871))
 - [llvm/lib/Bitcode/Reader/BitcodeReader.cpp:4030](e195e6bad6/llvm/lib/Bitcode/Reader/BitcodeReader.cpp (L4030))
 - [llvm/lib/IR/Core.cpp:2018](e195e6bad6/llvm/lib/IR/Core.cpp (L2018))
 - [llvm/lib/IR/Globals.cpp:141](e195e6bad6/llvm/lib/IR/Globals.cpp (L141))
 - [llvm/lib/Linker/IRMover.cpp:660](e195e6bad6/llvm/lib/Linker/IRMover.cpp (L660))
 - [llvm/lib/Linker/LinkModules.cpp:361](e195e6bad6/llvm/lib/Linker/LinkModules.cpp (L361))
 - [llvm/lib/Linker/LinkModules.cpp:362](e195e6bad6/llvm/lib/Linker/LinkModules.cpp (L362))
 - [llvm/lib/Transforms/IPO/MergeFunctions.cpp:782](e195e6bad6/llvm/lib/Transforms/IPO/MergeFunctions.cpp (L782))
 - [llvm/lib/Transforms/IPO/MergeFunctions.cpp:840](e195e6bad6/llvm/lib/Transforms/IPO/MergeFunctions.cpp (L840))
 - [llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:1813](e195e6bad6/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp (L1813))
 - [llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp:27](e195e6bad6/llvm/tools/llvm-reduce/deltas/ReduceGlobalObjects.cpp (L27))

Differential Revision: https://reviews.llvm.org/D142708
2023-01-31 13:59:58 +00:00
Guillaume Chatelet
43024b4ce4 [rereland][Alignment][NFC] Remove access to deprecated GlobalObject::getAlignment from llvm
Differential Revision: https://reviews.llvm.org/D139836
2022-12-13 12:23:30 +00:00
Guillaume Chatelet
6fe6d8d329 Revert "[reland][Alignment][NFC] Remove access to deprecated GlobalObject::getAlignment from llvm"
This reverts commit 3bbfaee23d41c099547c652f87b252ab6e1f6c46.
2022-12-12 21:18:15 +00:00
Guillaume Chatelet
3bbfaee23d [reland][Alignment][NFC] Remove access to deprecated GlobalObject::getAlignment from llvm
Differential Revision: https://reviews.llvm.org/D139836
2022-12-12 16:38:18 +00:00
Guillaume Chatelet
7e10a6a606 Revert D139836 "[Alignment][NFC] Remove deprecated GlobalObject::getAlignment"
This breaks lldb.

This reverts commit f3f15ca27fbb433ad5a65b1a1e0a071d2e9af505.
2022-12-12 15:05:16 +00:00
Guillaume Chatelet
f3f15ca27f [Alignment][NFC] Remove deprecated GlobalObject::getAlignment
Differential Revision: https://reviews.llvm.org/D139836
2022-12-12 14:50:39 +00:00
Fangrui Song
89fae41ef1 [IR] llvm::Optional => std::optional
Many llvm/IR/* files have been migrated by other contributors.
This migrates most remaining files.
2022-12-05 04:13:11 +00:00
Kazu Hirata
e842c06c2d [IR] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02 20:05:20 -08:00
Matt Arsenault
f883e75497 GlobalIFunc: Make allowed constant expressions stricter
This was allowing getelementptr with offsets, which doesn't make
sense. My initial attempt to use stripPointerCasts broke a few tests
involving aliases; add a new targeted verifier test for aliases.

This also provides the fix from D138537 for free, and also adds
support for addrspacecast (D138538) for free. Merge the tests in from
those.

I'm not really sure why findBaseObject exists; it seems redundant with
stripPointerCasts* (I'm also not really sure why getelementptrs are
allowed off of functions).
2022-12-02 15:20:57 -05:00
Matt Arsenault
4e0ca5ef00 GlobalValue: Move trivial getAddressSpace getter to header 2022-11-28 15:25:45 -05:00
Florian Hahn
5913d77056
[Globals] Treat nobuiltin fns as maybe-derefined.
Callsites could be marked as `builtin` while calling `nobuiltin`
functions. This can lead to problems, if local optimizations apply
transformations based on the semantics of the builtin, but then IPO
treats the function as `nobuiltin` and applies a transform that breaks
builtin semantics (assumed earlier).

To avoid this, mark such functions as maybey-derefined, to avoid IPO
transforms on them that may break assumptions of earlier calls.

Fixes #57075
Fixes #48366

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D97735
2022-08-23 13:45:10 +01:00
Schrodinger ZHU Yifan
304027206c [ThinLTO] Support aliased GlobalIFunc
Fixes https://github.com/llvm/llvm-project/issues/56290: when an ifunc is
aliased in LTO, clang will attempt to create an alias summary; however, as ifunc
is not included in the module summary, doing so will lead to crash.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D129009
2022-07-20 15:30:38 -07:00
Kazu Hirata
e0e687a615 [llvm] Don't use Optional::hasValue (NFC) 2022-06-20 10:38:12 -07:00
Mitch Phillips
ed5a349b89 Make setSanitizerMetadata byval.
This fixes a UaF bug in llvm::GlobalObject::copyAttributesFrom, where a
sanitizer metadata object is captured by reference, and passed by
reference to llvm::GlobalValue::setSanitizerMetadata. The reference
comes from the same map that the new value is going to be inserted to,
and the map insertion triggers iterator invalidation - leading to a
use-after-free on the dangling reference.

This patch fixes that bug by making setSanitizerMetadata's argument
byval. This should also systematically prevent the problem from
happening in future, as it's a very easy pattern to have. This shouldn't
be any performance problem, the SanitizerMetadata struct is a bitfield
POD.
2022-06-16 14:47:27 -07:00
Kazu Hirata
974dbb20bd [IR] Call DenseMap::erase directly (NFC)
We can erase an item in DenseMap without checking its membership first.
2022-06-12 10:47:06 -07:00
Mitch Phillips
8db981d463 Add sanitizer-specific GlobalValue attributes.
Plan is the migrate the global variable metadata for sanitizers, that's
currently carried around generally in the 'llvm.asan.globals' section,
onto the global variable itself.

This patch adds the attribute and plumbs it through the LLVM IR and
bitcode formats, but is a no-op other than that so far.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D126100
2022-06-10 12:28:18 -07:00
serge-sans-paille
e188aae406 Cleanup header dependencies in LLVMCore
Based on the output of include-what-you-use.

This is a big chunk of changes. It is very likely to break downstream code
unless they took a lot of care in avoiding hidden ehader dependencies, something
the LLVM codebase doesn't do that well :-/

I've tried to summarize the biggest change below:

- llvm/include/llvm-c/Core.h: no longer includes llvm-c/ErrorHandling.h
- llvm/IR/DIBuilder.h no longer includes llvm/IR/DebugInfo.h
- llvm/IR/IRBuilder.h no longer includes llvm/IR/IntrinsicInst.h
- llvm/IR/LLVMRemarkStreamer.h no longer includes llvm/Support/ToolOutputFile.h
- llvm/IR/LegacyPassManager.h no longer include llvm/Pass.h
- llvm/IR/Type.h no longer includes llvm/ADT/SmallPtrSet.h
- llvm/IR/PassManager.h no longer includes llvm/Pass.h nor llvm/Support/Debug.h

And the usual count of preprocessed lines:
$ clang++ -E  -Iinclude -I../llvm/include ../llvm/lib/IR/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l
before: 6400831
after:  6189948

200k lines less to process is no that bad ;-)

Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup

Differential Revision: https://reviews.llvm.org/D118652
2022-02-02 06:54:20 +01:00
Fangrui Song
bc56097817 [GlobalValue] Make dso_local function work with comdat nodeduplicate
This fixes -fno-semantic-interposition -fsanitize-coverage incompatibility.

-fPIC -fno-semantic-interposition may add dso_local to an external linkage
function. -fsanitize-coverage instrumentation does not clear dso_local when
adding comdat nodeduplicate. This causes a compatibility issue: the function
symbol may be referenced by a PC-relative relocation without using the local
alias. In -shared mode, ld will report a relocation error.

The fix is to either clear dso_local when adding comdat nodeduplicate, or
supporting comdat nodeduplicate. The latter is more appropriate, because a
comdat nodeduplicate is like not using comdat.

Note: The comdat condition was originally added by D77429 to not use local alias
for a hidden external linkage function in a deduplicate comdat. The condition
has been unused since the code was refactored to only use local alias for
default visibility symbols.
Note: `canBenefitFromLocalAlias` is used by clang/lib/CodeGen/CodeGenModule.cpp
and we don't want to add dso_local to default visibility external linkage comdat any
(clang/test/CodeGenCUDA/usual-deallocators.cu).

Differential Revision: https://reviews.llvm.org/D117190
2022-01-13 16:37:14 -08:00
Nikita Popov
32808cfb24 [IR] Track users of comdats
Track all GlobalObjects that reference a given comdat, which allows
determining whether a function in a comdat is dead without scanning
the whole module.

In particular, this makes filterDeadComdatFunctions() have complexity
O(#DeadFunctions) rather than O(#SymbolsInModule), which addresses
half of the compile-time issue exposed by D115545.

Differential Revision: https://reviews.llvm.org/D115864
2022-01-06 09:13:58 +01:00
Arthur Eubanks
1172712f46 [NFC] Replace some deprecated getAlignment() calls with getAlign()
Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D115370
2021-12-09 08:43:19 -08:00
Itay Bookstein
848812a55e [Verifier] Add verification logic for GlobalIFuncs
Verify that the resolver exists, that it is a defined
Function, and that its return type matches the ifunc's
type. Add corresponding check to BitcodeReader, change
clang to emit the correct type, and fix tests to comply.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D112349
2021-10-31 20:00:57 -07:00
Itay Bookstein
08ed216000 [IR] Refactor GlobalIFunc to inherit from GlobalObject, Remove GlobalIndirectSymbol
As discussed in:
* https://reviews.llvm.org/D94166
* https://lists.llvm.org/pipermail/llvm-dev/2020-September/145031.html

The GlobalIndirectSymbol class lost most of its meaning in
https://reviews.llvm.org/D109792, which disambiguated getBaseObject
(now getAliaseeObject) between GlobalIFunc and everything else.
In addition, as long as GlobalIFunc is not a GlobalObject and
getAliaseeObject returns GlobalObjects, a GlobalAlias whose aliasee
is a GlobalIFunc cannot currently be modeled properly. Creating
aliases for GlobalIFuncs does happen in the wild (e.g. glibc). In addition,
calling getAliaseeObject on a GlobalIFunc will currently return nullptr,
which is undesirable because it should return the object itself for
non-aliases.

This patch refactors the GlobalIFunc class to inherit directly from
GlobalObject, and removes GlobalIndirectSymbol (while inlining the
relevant parts into GlobalAlias and GlobalIFunc). This allows for
calling getAliaseeObject() on a GlobalIFunc to return the GlobalIFunc
itself, making getAliaseeObject() more consistent and enabling
alias-to-ifunc to be properly modeled in the IR.

I exercised some judgement in the API clients of GlobalIndirectSymbol:
some were 'monomorphized' for GlobalAlias and GlobalIFunc, and
some remained shared (with the type adapted to become GlobalValue).

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D108872
2021-10-20 10:29:47 -07:00
Itay Bookstein
40ec1c0f16 [IR][NFC] Rename getBaseObject to getAliaseeObject
To better reflect the meaning of the now-disambiguated {GlobalValue,
GlobalAlias}::getBaseObject after breaking off GlobalIFunc::getResolverFunction
(D109792), the function is renamed to getAliaseeObject.
2021-10-06 19:33:10 -07:00
Fangrui Song
1a6e1ee42a Resolve {GlobalValue,GloalIndirectSymol}::getBaseObject confusion
While both GlobalAlias and GlobalIFunc are GlobalIndirectSymbol, their
`getIndirectSymbol()` usage is quite different (GlobalIFunc's resolver
is an entity different from GlobalIFunc itself).

As discussed on https://lists.llvm.org/pipermail/llvm-dev/2020-September/144904.html
("[IR] Modelling of GlobalIFunc"), the name `getBaseObject` is confusing when
used with GlobalIFunc.

To resolve the confusion:

* Move GloalIndirectSymol::getBaseObject to GlobalAlias:: (GlobalIFunc should use `getResolver` instead)
* Change GlobalValue::getBaseObject not to inspect GlobalIFunc. Note: the function has 7 references.
* Add GlobalIFunc::getResolverFunction to peel off potential ConstantExpr indirection
  (`strlen` in `test/LTO/Resolution/X86/ifunc.ll`)

Note: GlobalIFunc::getResolver (like GlobalAlias::getAliasee which does not peel
off ConstantExpr indirection) is kept to be used by ValueEnumerator.

Reviewed By: ibookstein

Differential Revision: https://reviews.llvm.org/D109792
2021-09-23 09:23:35 -07:00
Arthur Eubanks
99173fd03a [NFC] Use Aliasee to determine Type and AddrSpace in GlobalAlias::create()
As opposed to going through the Aliasee type.

For opaque pointers, we're trying to remove uses of PointerType::getElementType().

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D101715
2021-05-02 11:50:08 -07:00
Alex Richardson
3bc4157556 Add a default address space for globals to DataLayout
This is similar to the existing alloca and program address spaces (D37052)
and should be used when creating/accessing global variables.
We need this in our CHERI fork of LLVM to place all globals in address space 200.
This ensures that values are accessed using CHERI load/store instructions
instead of the normal MIPS/RISC-V ones.

The problem this is trying to fix is that most of the time the type of
globals is created using a simple PointerType::getUnqual() (or ::get() with
the default address-space value of 0). This does not work for us and we get
assertion/compilation/instruction selection failures whenever a new call
is added that uses the default value of zero.

In our fork we have removed the default parameter value of zero for most
address space arguments and use DL.getProgramAddressSpace() or
DL.getGlobalsAddressSpace() whenever possible. If this change is accepted,
I will upstream follow-up patches to use DL.getGlobalsAddressSpace() instead
of relying on the default value of 0 for PointerType::get(), etc.

This patch and the follow-up changes will not have any functional changes
for existing backends with the default globals address space of zero.
A follow-up commit will change the default globals address space for
AMDGPU to 1.

Reviewed By: dylanmckay

Differential Revision: https://reviews.llvm.org/D70947
2020-11-20 15:46:52 +00:00
Ben Dunbobbin
4cb016cd2d [X86][ELF] Prefer lowering MC_GlobalAddress operands to .Lfoo$local for STV_DEFAULT only
This patch restricts the behaviour of referencing via .Lfoo$local
local aliases, introduced in https://reviews.llvm.org/D73230, to
STV_DEFAULT globals only.

Hidden symbols via --fvisiblity=hidden (https://gcc.gnu.org/wiki/Visibility)
is an important scenario.

Benefits:

- Improves the size of object files by using fewer STT_SECTION symbols.

- The code reads a bit better (it was not obvious to me without going
  back to the code reviews why the canBenefitFromLocalAlias function
  currently doesn't consider visibility).

- There is also a side benefit in restoring the effectiveness of the
  --wrap linker option and making the behavior of --wrap consistent
  between LTO and normal builds for references within a translation-unit.
  Note: this --wrap behavior (which is specific to LLD) should not be
  considered reliable. See comments on https://reviews.llvm.org/D73230
  for more.

Differential Revision: https://reviews.llvm.org/D85782
2020-08-14 00:09:15 +01:00
Eli Friedman
a2caa3b614 Remove GlobalValue::getAlignment().
This function is deceptive at best: it doesn't return what you'd expect.
If you have an arbitrary GlobalValue and you want to determine the
alignment of that pointer, Value::getPointerAlignment() returns the
correct value.  If you want the actual declared alignment of a function
or variable, GlobalObject::getAlignment() returns that.

This patch switches all the users of GlobalValue::getAlignment to an
appropriate alternative.

Differential Revision: https://reviews.llvm.org/D80368
2020-06-23 19:13:42 -07:00
Itay Bookstein
df9d64ed9c [IR] Add missing GlobalAlias copying of ThreadLocalMode attribute
Summary:
Previously, GlobalAlias::copyAttributesFrom did not preserve ThreadLocalMode,
causing incorrect IR generation in IR linking flows. This patch pushes the code
responsible for copying this attribute from GlobalVariable::copyAttributesFrom
down to GlobalValue::copyAttributesFrom so that it is shared by GlobalAlias.
Fixes PR46297.

Reviewers: tejohnson, pcc, hans

Reviewed By: tejohnson, hans

Subscribers: hiraditya, ibookstein, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81605
2020-06-16 20:15:27 -07:00
Fangrui Song
9d55e4ee13 Make explicit -fno-semantic-interposition (in -fpic mode) infer dso_local
-fno-semantic-interposition is currently the CC1 default. (The opposite
disables some interprocedural optimizations.) However, it does not infer
dso_local: on most targets accesses to ExternalLinkage functions/variables
defined in the current module still need PLT/GOT.

This patch makes explicit -fno-semantic-interposition infer dso_local,
so that PLT/GOT can be eliminated if targets implement local aliases
for AsmPrinter::getSymbolPreferLocal (currently only x86).

Currently we check whether the module flag "SemanticInterposition" is 0.
If yes, infer dso_local. In the future, we can infer dso_local unless
"SemanticInterposition" is 1: frontends other than clang will also
benefit from the optimization if they don't bother setting the flag.
(There will be risks if they do want ELF interposition: they need to set
"SemanticInterposition" to 1.)
2020-05-25 20:48:18 -07:00
Craig Topper
7392820f98 [Align] Remove operations on MaybeAlign that asserted that it had a defined value.
If the caller needs to reponsible for making sure the MaybeAlign
has a value, then we should just make the caller convert it to an Align
with operator*.

I explicitly deleted the relational comparison operators that
were being inherited from Optional. It's unclear what the meaning
of two MaybeAligns were one is defined and the other isn't
should be. So make the caller reponsible for defining the behavior.

I left the ==/!= operators from Optional. But now that exposed a
weird quirk that ==/!= between Align and MaybeAlign required the
MaybeAlign to be defined. But now we use the operator== from
Optional that takes an Optional and the Value.

Differential Revision: https://reviews.llvm.org/D80455
2020-05-22 21:54:28 -07:00
Guillaume Chatelet
39cfba9e33 [Alignment][NFC] Remove deprecated functions introduced in 10.0.0
Summary:
24 March 2020: LLVM 10.0.0 is out.
I gathered all deprecated function introduced between 9 and 10 and cleaned them up so they will be removed from 11.

> git log -p -S LLVM_ATTRIBUTE_DEPRECATED llvmorg-9.0.0..llvmorg-10.0.0

Reviewers: courbet

Subscribers: hiraditya, jfb, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77409
2020-04-06 12:07:18 +00:00
serge-sans-paille
fd09f12f32 Implement -fsemantic-interposition
First attempt at implementing -fsemantic-interposition.

Rely on GlobalValue::isInterposable that already captures most of the expected
behavior.

Rely on a ModuleFlag to state whether we should respect SemanticInterposition or
not. The default remains no.

So this should be a no-op if -fsemantic-interposition isn't used, and if it is,
isInterposable being already used in most optimisation, they should honor it
properly.

Note that it only impacts architecture compiled with -fPIC and no pie.

Differential Revision: https://reviews.llvm.org/D72829
2020-01-31 14:02:33 +01:00
Benjamin Kramer
adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Guillaume Chatelet
0e62011df8 [Alignment][NFC] Remove dependency on GlobalObject::setAlignment(unsigned)
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet

Subscribers: arsenm, mehdi_amini, jvesely, nhaehnle, hiraditya, steven_wu, dexonsmith, dang, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D68944

llvm-svn: 374880
2019-10-15 11:24:36 +00:00
Bill Wendling
73be7cf5aa Use parenthses to silence warning.
llvm-svn: 368105
2019-08-06 22:47:47 +00:00
Guillaume Chatelet
396521378f [LLVM][Alignment] Introduce Alignment In GlobalObject
Summary:
This is patch is part of a serie to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: jfb

Subscribers: hiraditya, dexonsmith, llvm-commits, courbet

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65748

Address comments

llvm-svn: 368000
2019-08-06 09:03:21 +00:00
Peter Collingbourne
72391ab4f1 IR: Teach GlobalIndirectSymbol::getBaseObject() to handle more kinds of expressions.
For aliases, any expression that lowers at the MC level to global_object or
global_object+constant is valid at the object file level. getBaseObject()
should return a result if the aliasee ends up being of that form even if
the IR used to produce it is somewhat unconventional.

Note that this is different from what stripInBoundsOffsets() and that family
of functions is doing. Those functions are concerned about semantic properties
of IR, whereas here we only care about the lowering result.

Therefore reimplement getBaseObject() in a way that matches the lowering
result. This fixes a crash when producing a summary for aliases such as
that in the included test case.

Differential Revision: https://reviews.llvm.org/D65115

llvm-svn: 366952
2019-07-24 22:23:05 +00:00