Skip to content

Commit

Permalink
Rename 'IntrinsicDescription::getOrDefine' to 'getOrDeclare'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanvdc committed Feb 19, 2019
1 parent d7eac82 commit f06b7c8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/llvm-final-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ bool FinalLowerGC::doInitialization(Module &M) {
initAll(M);

// Initialize platform-specific references.
queueRootFunc = getOrDefine(jl_well_known::GCQueueRoot);
poolAllocFunc = getOrDefine(jl_well_known::GCPoolAlloc);
bigAllocFunc = getOrDefine(jl_well_known::GCBigAlloc);
queueRootFunc = getOrDeclare(jl_well_known::GCQueueRoot);
poolAllocFunc = getOrDeclare(jl_well_known::GCPoolAlloc);
bigAllocFunc = getOrDeclare(jl_well_known::GCBigAlloc);

GlobalValue *functionList[] = {queueRootFunc, poolAllocFunc, bigAllocFunc};
unsigned j = 0;
Expand Down
14 changes: 7 additions & 7 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S) {
// Create a call to the `julia.gc_alloc_bytes` intrinsic, which is like
// `julia.gc_alloc_obj` except it doesn't set the tag.
auto newI = builder.CreateCall(
getOrDefine(jl_intrinsics::GCAllocBytes),
getOrDeclare(jl_intrinsics::GCAllocBytes),
{ CI->getArgOperand(0), CI->getArgOperand(1) });
newI->takeName(CI);

Expand Down Expand Up @@ -1797,7 +1797,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S) {
auto trigTerm = SplitBlockAndInsertIfThen(chldNotMarked, mayTrigTerm, false,
MDB.createBranchWeights(Weights));
builder.SetInsertPoint(trigTerm);
builder.CreateCall(getOrDefine(jl_intrinsics::queueGCRoot), parent);
builder.CreateCall(getOrDeclare(jl_intrinsics::queueGCRoot), parent);
CI->eraseFromParent();
}
if (maxframeargs == 0 && Frame) {
Expand Down Expand Up @@ -1851,7 +1851,7 @@ void LateLowerGCFrame::PlaceGCFrameStore(State &S, unsigned R, unsigned MinColor

// Get the slot address.
auto slotAddress = CallInst::Create(
getOrDefine(jl_intrinsics::getGCFrameSlot),
getOrDeclare(jl_intrinsics::getGCFrameSlot),
{GCFrame, ConstantInt::get(T_int32, Colors[R] + MinColorRoot)});

slotAddress->insertBefore(InsertionPoint);
Expand Down Expand Up @@ -1901,13 +1901,13 @@ void LateLowerGCFrame::PlaceRootsAndUpdateCalls(std::vector<int> &Colors, State
unsigned NRoots = MaxColor + 1 + S.Allocas.size();
// Create and push a GC frame.
auto gcframe = CallInst::Create(
getOrDefine(jl_intrinsics::newGCFrame),
getOrDeclare(jl_intrinsics::newGCFrame),
{ConstantInt::get(T_size, NRoots)},
"gcframe");
gcframe->insertBefore(&*F->getEntryBlock().begin());

auto pushGcframe = CallInst::Create(
getOrDefine(jl_intrinsics::pushGCFrame),
getOrDeclare(jl_intrinsics::pushGCFrame),
{gcframe, ConstantInt::get(T_size, NRoots)});
pushGcframe->insertAfter(ptlsStates);

Expand All @@ -1916,7 +1916,7 @@ void LateLowerGCFrame::PlaceRootsAndUpdateCalls(std::vector<int> &Colors, State
for (AllocaInst *AI : S.Allocas) {
// Pick a slot for the alloca.
auto slotAddress = CallInst::Create(
getOrDefine(jl_intrinsics::getGCFrameSlot),
getOrDeclare(jl_intrinsics::getGCFrameSlot),
{gcframe, ConstantInt::get(T_int32, AllocaSlot++)});
slotAddress->insertAfter(gcframe);
slotAddress->takeName(AI);
Expand All @@ -1943,7 +1943,7 @@ void LateLowerGCFrame::PlaceRootsAndUpdateCalls(std::vector<int> &Colors, State
for(Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
if (isa<ReturnInst>(I->getTerminator())) {
auto popGcframe = CallInst::Create(
getOrDefine(jl_intrinsics::popGCFrame),
getOrDeclare(jl_intrinsics::popGCFrame),
{gcframe});
popGcframe->insertBefore(I->getTerminator());
}
Expand Down
12 changes: 6 additions & 6 deletions src/llvm-pass-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ llvm::Function *JuliaPassContext::getOrNull(
return module->getFunction(desc.name);
}

llvm::Function *JuliaPassContext::getOrDefine(
llvm::Function *JuliaPassContext::getOrDeclare(
const jl_intrinsics::IntrinsicDescription &desc) const
{
auto local = getOrNull(desc);
if (local) {
return local;
}
else {
return desc.define(*module, *this);
return desc.declare(*module, *this);
}
}

Expand Down Expand Up @@ -221,8 +221,8 @@ namespace jl_well_known {
const WellKnownFunctionDescription GCBigAlloc(
GC_BIG_ALLOC_NAME,
[](llvm::Module &M, const JuliaPassContext &context) {
// Get or define `julia.gc_alloc_bytes` so we can copy its attributes.
auto allocBytes = context.getOrDefine(jl_intrinsics::GCAllocBytes);
// Get or declare `julia.gc_alloc_bytes` so we can copy its attributes.
auto allocBytes = context.getOrDeclare(jl_intrinsics::GCAllocBytes);

auto bigAllocFunc = Function::Create(
FunctionType::get(
Expand All @@ -244,8 +244,8 @@ namespace jl_well_known {
const WellKnownFunctionDescription GCPoolAlloc(
GC_POOL_ALLOC_NAME,
[](llvm::Module &M, const JuliaPassContext &context) {
// Get or define `julia.gc_alloc_bytes` so we can copy its attributes.
auto allocBytes = context.getOrDefine(jl_intrinsics::GCAllocBytes);
// Get or declare `julia.gc_alloc_bytes` so we can copy its attributes.
auto allocBytes = context.getOrDeclare(jl_intrinsics::GCAllocBytes);

auto poolAllocFunc = Function::Create(
FunctionType::get(
Expand Down
21 changes: 11 additions & 10 deletions src/llvm-pass-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ struct JuliaPassContext;
// A namespace for Julia intrinsic descriptions.
namespace jl_intrinsics {
// A description of an intrinsic that can be used to find existing
// intrinsics and materialize new intrinsics if necessary.
// intrinsics and declare new intrinsics if necessary.
struct IntrinsicDescription final {
// The type of function that defines a new intrinsic.
typedef llvm::Function *(*DefinitionFunction)(llvm::Module&, const JuliaPassContext&);
// The type of function that declares an intrinsic.
typedef llvm::Function *(*DeclarationFunction)(llvm::Module&, const JuliaPassContext&);

// Creates an intrinsic description with a particular
// name and definition function.
// name and declaration function.
IntrinsicDescription(
const llvm::StringRef &name,
const DefinitionFunction &define)
: name(name), define(define)
const DeclarationFunction &declare)
: name(name), declare(declare)
{ }

// The intrinsic's name.
llvm::StringRef name;
// A function that defines the intrinsic in a module.
DefinitionFunction define;
// A function that declares the intrinsic in a module.
DeclarationFunction declare;
};
}

Expand Down Expand Up @@ -94,8 +94,9 @@ struct JuliaPassContext {

// Gets the intrinsic or well-known function that conforms to
// the given description if it exists in the module. If not,
// creates the intrinsic and adds it to the module.
llvm::Function *getOrDefine(
// declares the intrinsic or well-known function and adds it
// to the module.
llvm::Function *getOrDeclare(
const jl_intrinsics::IntrinsicDescription &desc) const;
};

Expand Down

0 comments on commit f06b7c8

Please sign in to comment.