[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / llvm / examples / OrcV2Examples / ExampleModules.h
blob53da756e15f78d08425b110cc354e731936c1adc
1 //===----- ExampleModules.h - IR modules for LLJIT examples -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Example modules for LLJIT examples
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_EXAMPLES_ORCV2EXAMPLES_EXAMPLEMODULES_H
14 #define LLVM_EXAMPLES_ORCV2EXAMPLES_EXAMPLEMODULES_H
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/IRReader/IRReader.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/SourceMgr.h"
25 const llvm::StringRef Add1Example =
26 R"(
27 define i32 @add1(i32 %x) {
28 entry:
29 %r = add nsw i32 %x, 1
30 ret i32 %r
32 )";
34 inline llvm::Error createSMDiagnosticError(llvm::SMDiagnostic &Diag) {
35 using namespace llvm;
36 std::string Msg;
38 raw_string_ostream OS(Msg);
39 Diag.print("", OS);
41 return make_error<StringError>(std::move(Msg), inconvertibleErrorCode());
44 inline llvm::Expected<llvm::orc::ThreadSafeModule>
45 parseExampleModule(llvm::StringRef Source, llvm::StringRef Name) {
46 using namespace llvm;
47 auto Ctx = std::make_unique<LLVMContext>();
48 SMDiagnostic Err;
49 if (auto M = parseIR(MemoryBufferRef(Source, Name), Err, *Ctx))
50 return orc::ThreadSafeModule(std::move(M), std::move(Ctx));
52 return createSMDiagnosticError(Err);
55 inline llvm::Expected<llvm::orc::ThreadSafeModule>
56 parseExampleModuleFromFile(llvm::StringRef FileName) {
57 using namespace llvm;
58 auto Ctx = std::make_unique<LLVMContext>();
59 SMDiagnostic Err;
61 if (auto M = parseIRFile(FileName, Err, *Ctx))
62 return orc::ThreadSafeModule(std::move(M), std::move(Ctx));
64 return createSMDiagnosticError(Err);
67 #endif // LLVM_EXAMPLES_ORCV2EXAMPLES_EXAMPLEMODULES_H