Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #417 from AndyAyersMS/Localloc
Browse files Browse the repository at this point in the history
Implement support for localloc.
  • Loading branch information
AndyAyersMS committed Apr 18, 2015
2 parents 1f1bdd6 + 089a03b commit b60b5bf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
4 changes: 1 addition & 3 deletions include/Reader/readerir.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,7 @@ class GenIR : public ReaderBase {
ReaderAlignType Alignment, bool IsVolatile) override;

IRNode *loadNull() override;
IRNode *localAlloc(IRNode *Arg, bool ZeroInit) override {
throw NotYetImplementedException("localAlloc");
};
IRNode *localAlloc(IRNode *Arg, bool ZeroInit) override;
IRNode *loadFieldAddress(CORINFO_RESOLVED_TOKEN *ResolvedToken,
IRNode *Obj) override;

Expand Down
9 changes: 9 additions & 0 deletions lib/Jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ if (WIN32)
${LLILCJIT_EXPORTS_DEF_TEMP} ${LLILCJIT_EXPORTS_DEF})

set(SHARED_LIB_SOURCES ${SOURCES} ${LLILCJIT_EXPORTS_DEF})

# For windows we need to specify the CoreCLR environment
set(LLILC_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}-coreclr")
else()
if (UNIX)
set(LLILCJIT_LINK_LIBRARIES ${LLILCJIT_LINK_LIBRARIES} coreclrpal)
endif()

set(SHARED_LIB_SOURCES ${SOURCES})

# For non-windows we can use the default triple for now
set(LLILC_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
endif()

message(STATUS "LLILC_TARGET_TRIPLE is ${LLILC_TARGET_TRIPLE}")
add_definitions(-DLLILC_TARGET_TRIPLE="${LLILC_TARGET_TRIPLE}")

set(LLVM_EXPORTED_SYMBOL_FILE ${LLILCJIT_EXPORTS_DEF})

add_llilcjit_library(
Expand Down
2 changes: 1 addition & 1 deletion lib/Jit/LLILCJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ CorJitResult LLILCJit::compileMethod(ICorJitInfo *JitInfo,
Context.LLVMContext = &PerThreadState->LLVMContext;
std::unique_ptr<Module> M = Context.getModuleForMethod(MethodInfo);
Context.CurrentModule = M.get();
Context.CurrentModule->setTargetTriple(LLVM_DEFAULT_TARGET_TRIPLE);
Context.CurrentModule->setTargetTriple(LLILC_TARGET_TRIPLE);
Context.TheABIInfo = ABIInfo::get(*Context.CurrentModule);

// Initialize per invocation JIT options. This should be done after the
Expand Down
23 changes: 23 additions & 0 deletions lib/Reader/readerir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5424,6 +5424,29 @@ bool GenIR::abs(IRNode *Argument, IRNode **Result) {
return false;
}

IRNode *GenIR::localAlloc(IRNode *Arg, bool ZeroInit) {
// Note that we've seen a localloc in this method, since it has repercussions
// on other aspects of code generation.
this->HasLocAlloc = true;

// Arg is the number of bytes to allocate. Result must be pointer-aligned.
const unsigned int Alignment = TargetPointerSizeInBits / 8;
LLVMContext &Context = *JitContext->LLVMContext;
Type *Ty = Type::getInt8Ty(Context);
AllocaInst *LocAlloc = LLVMBuilder->CreateAlloca(Ty, Arg, "LocAlloc");
LocAlloc->setAlignment(Alignment);

// Zero the allocated region if so requested.
if (ZeroInit) {
Value *ZeroByte = ConstantInt::get(Context, APInt(8, 0, true));
Type *VoidTy = Type::getVoidTy(Context);
callHelperImpl(CORINFO_HELP_MEMSET, VoidTy, (IRNode *)LocAlloc,
(IRNode *)ZeroByte, Arg);
}

return (IRNode *)LocAlloc;
}

#pragma endregion

#pragma region STACK MAINTENANCE
Expand Down

0 comments on commit b60b5bf

Please sign in to comment.