This repository has been archived by the owner on Mar 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make copy of ORC SimpleCompiler functor for LLILCCompiler
New functor will be extended to implement LLILC specific phase lists.
- Loading branch information
1 parent
6e17324
commit bcfa749
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//===--------------- include/Jit/compiler.h ---------------------*- C++ -*-===// | ||
// | ||
// LLILC | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// \brief Declaration of the compiler functor used in the ORC infrastructure | ||
/// to compile a module. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef COMPILER_H | ||
#define COMPILER_H | ||
|
||
#include "llvm/ExecutionEngine/ObjectMemoryBuffer.h" | ||
#include "llvm/IR/LegacyPassManager.h" | ||
#include "llvm/MC/MCContext.h" | ||
#include "llvm/Object/ObjectFile.h" | ||
#include "llvm/Target/TargetMachine.h" | ||
|
||
namespace llvm { | ||
namespace orc { | ||
|
||
/// @brief Default compile functor: Takes a single IR module and returns an | ||
/// ObjectFile. | ||
class LLILCCompiler { | ||
public: | ||
/// @brief Construct a simple compile functor with the given target. | ||
LLILCCompiler(TargetMachine &TM) : TM(TM) {} | ||
|
||
/// @brief Compile a Module to an ObjectFile. | ||
object::OwningBinary<object::ObjectFile> operator()(Module &M) const { | ||
SmallVector<char, 0> ObjBufferSV; | ||
raw_svector_ostream ObjStream(ObjBufferSV); | ||
|
||
legacy::PassManager PM; | ||
MCContext *Ctx; | ||
if (TM.addPassesToEmitMC(PM, Ctx, ObjStream)) | ||
llvm_unreachable("Target does not support MC emission."); | ||
PM.run(M); | ||
ObjStream.flush(); | ||
std::unique_ptr<MemoryBuffer> ObjBuffer( | ||
new ObjectMemoryBuffer(std::move(ObjBufferSV))); | ||
ErrorOr<std::unique_ptr<object::ObjectFile>> Obj = | ||
object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef()); | ||
// TODO: Actually report errors helpfully. | ||
typedef object::OwningBinary<object::ObjectFile> OwningObj; | ||
if (Obj) | ||
return OwningObj(std::move(*Obj), std::move(ObjBuffer)); | ||
return OwningObj(nullptr, nullptr); | ||
} | ||
|
||
private: | ||
TargetMachine &TM; | ||
}; | ||
} // namespace orc | ||
} // namespace llvm | ||
#endif // COMPILER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters