714 Commits

Author SHA1 Message Date
Gonsolo
33aaad9427
[Kaleidoscope] LLVM is not needed for chapter two (#69823)
Since the example (llvm/examples/Kaleidoscope/Chapter2/toy.cpp) is
self-contained there is no need to use LLVM.
2024-01-12 20:48:43 -08:00
Stefan Gränitz
b7d5b0d0ee
[Orc][examples] Revisit advanced LLJIT examples and tests (#76236)
Some maintenance on implementation and tests:
* Drop manual TargetMachineBuilder setup
* Drop addDebugSupport() in favor of Orc's enableDebuggerSupport()
* Check that debug support plugins append jit_code_entry
* Update and reduce sample input
2024-01-03 09:51:18 +01:00
Stefan Gränitz
d86a93782f
[Orc][examples] Drop target triple from input for remote debugging test (#74831)
https://github.com/llvm/llvm-project/pull/74764 reported that the
`lljit-with-remote-debugging` test fails on AArch64 hosts, because the
input IR file states arch x86_64 explicitly. In order to drop the target
triple we have to remove a check in the example implementation.

Not sure it's fully portable now, but at least it's better than before.
2023-12-08 22:10:03 +01:00
Fangrui Song
114325b86a Kaleidoscope-Ch8: use Reloc::PIC_
which has better portability across different OSes.
In addition, on many ELF OSes, this output relocatable file can be
linked without -no-pie.
2023-12-05 23:44:35 -08:00
Fangrui Song
dd3184c30f [unittest,examples] Replace uses of IRBuilder::getInt8PtrTy with getPtrTy. NFC 2023-11-27 08:29:13 -08:00
Logikable
3d2527ebe3
[Kaleidoscope] Switch to the new PassManager, revisited. (#72324)
Rollforward of #69032, which was reverted in
[63d19cf](63d19cfd85).

New: implemented changes in
https://github.com/llvm/llvm-project/pull/69032#issuecomment-1809250162.
Given the PassBuilder is how we expect users to register passes, the
tutorial should reflect that.
2023-11-16 09:13:56 -08:00
Amara Emerson
63d19cfd85 Revert "[Kaleidoscope] Switch to the new PassManager. (#69032)"
This reverts commit 7b94744e77aaf752abc2c6ab38ee3fdfafbeff9d.

This breaks the expensive checks bot: https://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-expensive/26026/

We didn't notice because it was broken for other reasons I think.
2023-11-13 14:38:14 -08:00
Paulo Matos
7b9d73c2f9
[NFC] Remove Type::getInt8PtrTy (#71029)
Replace this with PointerType::getUnqual().
Followup to the opaque pointer transition. Fixes an in-code TODO item.
2023-11-07 17:26:26 +01:00
Logikable
b8b7c3ba5c
[Kaleidoscope] Register new dependencies introduced by #69032. (#69510)
Broke https://lab.llvm.org/buildbot/#/builders/181/builds/24470.

Could we build the example/tutorial code in the submit checks? This
breakage wasn't caught at submit time.
2023-10-18 14:18:34 -07:00
Logikable
7b94744e77
[Kaleidoscope] Switch to the new PassManager. (#69032)
Using the new pass manager is more verbose; let me know if the tutorial
doesn't flow well with all the additions.
2023-10-18 09:25:50 -07:00
Konrad Kleine
5bd1b93cb2 Move CallInst::CreateFree to IRBuilderBase
Similarly to D158861 I'm moving the `CreateFree` method from `CallInst` to `IRBuilderBase`.

Differential Revision: https://reviews.llvm.org/D159418
2023-09-19 12:04:17 +02:00
Jie Fu
da57ced76d [examples] Remove unused variable 'BB' in BrainF.cpp (NFC)
/Users/jiefu/llvm-project/llvm/examples/BrainF/BrainF.cpp:92:15: error: unused variable 'BB' [-Werror,-Wunused-variable]
  BasicBlock* BB = builder->GetInsertBlock();
              ^
1 error generated.
2023-09-19 15:46:08 +08:00
Konrad Kleine
45bb45f2ae [llvm] Move CallInst::CreateMalloc to IRBuilderBase::CreateMalloc
This removes `CreateMalloc` from `CallInst` and adds it to the `IRBuilderBase`
class.

We no longer needed the `Instruction *InsertBefore` and
`BasicBlock *InsertAtEnd` arguments of the `createMalloc` helper
function because we're using `IRBuilder` now. That's why I we also don't
need 4 `CreateMalloc` functions, but only two.

Differential Revision: https://reviews.llvm.org/D158861
2023-09-19 09:05:48 +02:00
Arthur Eubanks
0a1aa6cda2
[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes (#66295)
This will make it easy for callers to see issues with and fix up calls
to createTargetMachine after a future change to the params of
TargetMachine.

This matches other nearby enums.

For downstream users, this should be a fairly straightforward
replacement,
e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive
or s/CGFT_/CodeGenFileType::
2023-09-14 14:10:14 -07:00
Lang Hames
d467396ae0 [emamples][OrcV2Examples] Fix a missing newline in LLJITRemovableCode output. 2023-07-30 08:51:42 -07:00
Jie Fu
c2cabe479b [examples] Fix -Wcast-qual in OrcV2Examples after D153911 (NFC)
/Users/jiefu/llvm-project/llvm/examples/OrcV2Examples/OrcV2CBindingsBasicUsage/OrcV2CBindingsBasicUsage.c:77:52: error: cast from 'char **' to 'const char **' must have all intermediate pointers const qualified to be safe [-Werror,-Wcast-qual]
  LLVMParseCommandLineOptions(argc, (const char **)argv, "");
                                                   ^
/Users/jiefu/llvm-project/llvm/examples/OrcV2Examples/OrcV2CBindingsAddObjectFile/OrcV2CBindingsAddObjectFile.c:63:52: error: cast from 'char **' to 'const char **' must have all intermediate pointers const qualified to be safe [-Werror,-Wcast-qual]
  LLVMParseCommandLineOptions(argc, (const char **)argv, "");
                                                   ^
/Users/jiefu/llvm-project/llvm/examples/OrcV2Examples/OrcV2CBindingsDumpObjects/OrcV2CBindingsDumpObjects.c:62:52: error: cast from 'char **' to 'const char **' must have all intermediate pointers const qualified to be safe [-Werror,-Wcast-qual]
  LLVMParseCommandLineOptions(argc, (const char **)argv, "");
                                                   ^
...
2023-07-19 14:55:58 +08:00
Carlo Bramini
a6ea0185d6 [llvm] CYGWIN: Fix build of some plugins/library/unittests
CYGWIN uses the same format of WIN32 for shared libraries.
As the comment says: "a shared library can't have undefined references", in this case CYGWIN must be handled like WIN32 by CMakeLists.txt, otherwise you will get several errors when linking because some symbols are undefined.
Attached patch fixes this issue and allows to complete the build process for those targets.

Differential Revision: https://reviews.llvm.org/D154794
2023-07-10 22:43:03 +03:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Lang Hames
13f5125f9d [tutorials] Add missing ExecutorSymbolDef header.
Similar to c118d05f9ed, but applied to the base Kaleidoscope series.
2023-06-21 08:51:17 -07:00
Lang Hames
c118d05f9e [tutorials][BuildingAJIT] Add missing ExecutorSymbolDef header. 2023-06-21 08:35:37 -07:00
Lang Hames
d120d77f72 [ORC] Simplify construction of EPCIndirectionUtils.
ExecutionSessions always have an ExecutorProcessControl object now, so we can
construct EPCIndirectionUtil objects directly from an ExecutionSession.
2023-06-07 16:28:07 -07:00
Tobias Hieta
b71edfaa4e
[NFC][Py Reformat] Reformat python files in llvm
This is the first commit in a series that will reformat
all the python files in the LLVM repository.

Reformatting is done with `black`.

See more information here:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Reviewed By: jhenderson, JDevlieghere, MatzeB

Differential Revision: https://reviews.llvm.org/D150545
2023-05-17 10:48:52 +02:00
Lang Hames
b92839c954 Re-apply "[ORC][LLJIT] Use JITLink by default on ELF/x86-64." with fixes.
This reapplies 85c649bc02a, which was reverted in 35767e43d62 due to failures
with some example programs. The fix was to add export_executable_symbols to the
example programs.
2023-04-23 10:20:09 +00:00
Lang Hames
231107a8b5 Re-apply "[ORC] LLJIT updates: ExecutorNativePlatform, default ..." with fixes.
This reapplies 371cb1af61d, which was reverted in 0b2240eda01 due to bot
failures.

The clang-repl test failure is fixed by dropping the process symbols definition
generator that was manually attached to the main JITDylib, since LLJIT now
exposes process symbols by default. (The bug was triggered when JIT'd code used
the process atexit provided by the generator, rather than the JIT atexit which
has been moved into the platform JITDylib).

Any LLJIT clients that see crashes in static destructors should likewise remove
any process symbol generators attached to their main JITDylib.
2023-04-08 02:40:58 +00:00
Stefan Gränitz
4c7f53b99c [Orc] Add AutoRegisterCode option for DebugObjectManagerPlugin
Configure the plugin to automatically call the debugger rendezvous breakpoint `__jit_debug_register_code()` for every translation unit (enabled) or never at all (disabled). Default API and behavior remain unchanged.

If AutoRegisterCode is turned off, it's the client's own responsibility to call the rendezvous breakpoint function at an appropriate time.
Depending on the complexity of the debugger's rendezvous breakpoint implementation, this can provide significant performance improvements in cases where many debug objects are added in sequence.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D147310
2023-04-03 15:38:07 +02:00
Lang Hames
8b1771bd9f [ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef.
ExecutorAddr was introduced in b8e5f918166 as an eventual replacement for
JITTargetAddress. ExecutorSymbolDef is introduced in this patch as a
replacement for JITEvaluatedSymbol: ExecutorSymbolDef is an (ExecutorAddr,
JITSymbolFlags) pair, where JITEvaluatedSymbol was a (JITTargetAddress,
JITSymbolFlags) pair.

A number of APIs had already migrated from JITTargetAddress to ExecutorAddr,
but many of ORC's internals were still using the older type. This patch aims
to address that.

Some public APIs are affected as well. If you need to migrate your APIs you can
use the following operations:

* ExecutorAddr::toPtr replaces jitTargetAddressToPointer and
  jitTargetAddressToFunction.

* ExecutorAddr::fromPtr replace pointerToJITTargetAddress.

* ExecutorAddr(JITTargetAddress) creates an ExecutorAddr value from a
  JITTargetAddress.

* ExecutorAddr::getValue() creates a JITTargetAddress value from an
  ExecutorAddr.

JITTargetAddress and JITEvaluatedSymbol will remain in JITSymbol.h for now, but
the aim will be to eventually deprecate and remove these types (probably when
MCJIT and RuntimeDyld are deprecated).
2023-03-27 17:37:58 -07:00
Lang Hames
2ad8e6e082 [examples] Add export_executable_symbols to HowToUseLLJIT example.
LLJIT needs access to symbols (e.g. llvm_orc_registerEHFrameSectionWrapper)
that will be defined in the executable when LLVM is linked statically.

Should fix https://github.com/llvm/llvm-project/issues/61712.
2023-03-26 18:27:54 +00:00
Arthur Eubanks
7c3c981442 [Passes] Remove some legacy passes
DFAJumpThreading
JumpThreading
LibCallsShrink
LoopVectorize
SLPVectorizer
DeadStoreElimination
AggressiveDCE
CorrelatedValuePropagation
IndVarSimplify

These are part of the optimization pipeline, of which the legacy version is deprecated and being removed.
2023-03-10 17:17:00 -08:00
Nikita Popov
4d513bd9a5 [Orc] Remove LLVMInitializeCore() calls from examples
Per discussion on D144970, these are no longer necessary.
2023-03-01 09:56:59 +01:00
Nikita Popov
abdefc895d [Orc] Try to fix linker error
Try to fix flang-aarch64-sharedlibs build.

7344f8a8442a9c3cef159445f71b4f2886ed2798 introduced a use of
LLVMCreatePassBuilderOptions(), which is part of the Passes
library, while previously only InstCombine was linked.
2023-02-28 17:42:47 +01:00
Nikita Popov
7344f8a844 [Orc] Use new pass manager in example
Invoke InstCombine via the new pass manager, instead of the
legacy pass manager.
2023-02-28 16:53:09 +01:00
Archibald Elliott
d768bf994f [NFC][TargetParser] Replace uses of llvm/Support/Host.h
The forwarding header is left in place because of its use in
`polly/lib/External/isl/interface/extract_interface.cc`, but I have
added a GCC warning about the fact it is deprecated, because it is used
in `isl` from where it is included by Polly.
2023-02-10 09:59:46 +00:00
Arthur Eubanks
84728a3d75 [Inliner] Remove legacy simple inliner
It's part of the optimization pipeline, of which the legacy pass manager version is deprecated.
2023-02-09 10:36:58 -08:00
Dhruv Chawla
1625530d76 [Kaleidoscope] Update code snippets in text to match full code listings
There were quite a few places in the tutorial where the snippets were not up to date with the full code listings given. I have updated all of the ones I could find, which mostly involves changing `.` to `->` when accessing through a `std::unique_ptr`, changing `while (1)` to `while (true)`, and other such small changes.

There are still however a few places where I am not sure what to do, such as:
- Chapter 4: `ParseTopLevelExpr()` in chapter 3 sets the ProtoTypeAST
             name to "", however it is referred to as "__anon_expr"
             in chapter 4. Would it be required to mention this change
             in chapter 4?
- Chapter 9: The code snippets refer to the top level expression as
             "main", however the full code listing refers to it as
             "__anon_expr". I think given the context of the chapter
             it makes sense to refer to it as "main", so I have
             updated the code listing to reflect that.
- Chapter 9: In chapter 9 the diff given for `HandleTopLevelExpression()`
             deletes code that is not mentioned anywhere else, so I am
             not sure what is to be done there.
- Miscellaneous: I don't think this is very important, however the
                 casing used for the first word of error messages
                 tends to vary between upper and lower case between
                 chapters and I do not know if it is worth reconciling
                 these differences.

Reviewed By: xgupta

Differential Revision: https://reviews.llvm.org/D142323
2023-01-31 23:31:02 +05:30
Sebastian Peryt
d291f1fd09 [LegacyPM] Port example pass SimplifyCFG to new PM
This is part of effort in removing -enable-new-pm flag.
As a prat of this effort one of example passes SimplifyCFG must
be ported to new PM which will allow to remove the flag
calls from the tests that are using this pass.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D137103
2023-01-10 15:42:01 -08:00
Lang Hames
23c1822d1a [examples] Fix leaks in OrcV2 c-bindings examples.
rdar://103599609
2022-12-23 21:11:47 -08:00
Lang Hames
a4e3457fb7 [examples] Direct HowToUseJIT readers to HowToUseLLJIT instead.
HowToUseJIT describes the older APIs. We want to discourage their use in new
projects.
2022-12-23 01:10:27 -08:00
Archibald Elliott
16c4c4e04c [Examples] Fix TargetParser Dependency 2022-12-20 12:51:57 +00:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00
Lang Hames
bf6d7ca987 [ORC] Add JITDylib argument to ResourceManager notify-removing/transferring ops.
In some cases it's helpful to group trackers by JITDylib. E.g. Platform classes
may want to track initializer symbols with a `JITDylib -> Tracker -> [ Symbol ]`
map. This makes it easy to collect all symbols for the JITDylib, while still
allowing efficient removal of a single tracker. Passing the JITDylib as an
argument to ResourceManager::notifyRemovingResources and
ResourceManager::notifyTransferringResources supports such use-cases.
2022-12-19 14:56:08 -08:00
Nikita Popov
9d3f9adf04 [Examples] Fix build (NFC)
Can't use VLA at file scope.
2022-12-19 09:38:44 +01:00
Wenzel Jakob
10d0bd44ae [C-API] Add example code to exercise new MCJIT-like-memory-manager API.
This example shows how to use the newly added
LLVMOrcCreateRTDyldObjectLinkingLayerWithMCJITMemoryManagerLikeCallbacks API.
2022-12-17 14:15:07 +11:00
Vasileios Porpodas
cb5ebfa282 [NFC] Cleanup: Remove instances of Function::getBasicBlockList()
This is part of a series of patches that aim at making Function::getBasicBlockList() private.

Differential Revision: https://reviews.llvm.org/D140121
2022-12-15 13:08:25 -08:00
Vasileios Porpodas
32b38d248f [NFC] Rename Instruction::insertAt() to Instruction::insertInto(), to be consistent with BasicBlock::insertInto()
Differential Revision: https://reviews.llvm.org/D140085
2022-12-15 12:27:45 -08:00
Vasileios Porpodas
80f2f1eabc [NFC] Rename Function::insertBasicBlockAt() to Function::insert().
I think this is a better name because it is what STL uses.

Differential Revision: https://reviews.llvm.org/D140068
2022-12-15 10:03:37 -08:00
Vasileios Porpodas
8580de156f [NFC] Fixes ModuleMaker example build failure caused by c143b77b30fc23f70aac94be66e412651771c0fc
Differential Revision: https://reviews.llvm.org/D140052
2022-12-14 14:52:02 -08:00
Vasileios Porpodas
dd3d679179 [NFC] Fixes BrainF example build failure caused by c143b77b30fc23f70aac94be66e412651771c0fc 2022-12-14 14:16:04 -08:00
Vasileios Porpodas
a19ae77d2a [IR][NFC] Adds Function::insertBasicBlockAt() to replace things like F->getBasicBlockList().insert()
This is part of a series of patches that aim at making Function::getBasicBlockList() private.

Differential Revision: https://reviews.llvm.org/D139906
2022-12-12 20:22:55 -08:00
Kazu Hirata
934942c033 [llvm] Don't include Optional.h (NFC)
These source files no longer use Optional<T>, so they do not need to
include Optional.h.

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-06 22:34:50 -08:00
Nikita Popov
92c96f29fa [Kaleidoscope] Fix build after std::optional changes 2022-12-05 08:37:08 +01:00