Skip to content

Commit

Permalink
Favour getOrInsertFunction and set dso_local to function
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniofrighetto committed Nov 21, 2023
1 parent 013943f commit 5adba12
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/passes/strings-encoding/StringEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,10 @@ bool StringEncoding::injectOnStackLoop(BasicBlock& BB, Instruction& I, Use& Op,
CastEncPtr = IRB.CreateBitCast(&G, IRB.getInt8PtrTy());
}

auto NewF = Function::Create(FDecode->getFunctionType(), llvm::GlobalValue::PrivateLinkage,
"__omvll_decode", BB.getModule());
auto *M = BB.getModule();
FunctionCallee DecodeCallee =
M->getOrInsertFunction("__omvll_decode", FDecode->getFunctionType());
auto *NewF = cast<Function>(DecodeCallee.getCallee());

ValueToValueMapTy VMap;
auto NewFArgsIt = NewF->arg_begin();
Expand All @@ -372,6 +374,7 @@ bool StringEncoding::injectOnStackLoop(BasicBlock& BB, Instruction& I, Use& Op,
}
SmallVector<ReturnInst*, 8> Returns;
CloneFunctionInto(NewF, FDecode, VMap, CloneFunctionChangeType::DifferentModule, Returns);
NewF->setDSOLocal(true);

std::vector<Value *> Args = {
CastClearBuffer, CastEncPtr ? CastEncPtr : EncPtr, KeyVal, VStrSize};
Expand Down Expand Up @@ -508,8 +511,9 @@ bool StringEncoding::processGlobal(BasicBlock& BB, Instruction&, Use& Op, Global
fatalError("Can't find the 'decode' routine");
}

auto NewF = Function::Create(FDecode->getFunctionType(), llvm::GlobalValue::PrivateLinkage,
"__omvll_decode", M);
FunctionCallee DecodeCallee =
M->getOrInsertFunction("__omvll_decode", FDecode->getFunctionType());
auto *NewF = cast<Function>(DecodeCallee.getCallee());

ValueToValueMapTy VMap;
auto NewFArgsIt = NewF->arg_begin();
Expand All @@ -519,6 +523,7 @@ bool StringEncoding::processGlobal(BasicBlock& BB, Instruction&, Use& Op, Global
}
SmallVector<ReturnInst*, 8> Returns;
CloneFunctionInto(NewF, FDecode, VMap, CloneFunctionChangeType::DifferentModule, Returns);
NewF->setDSOLocal(true);

std::vector<Value*> Args = {
DataPtr, DataPtr, KeyVal, VStrSize
Expand Down

0 comments on commit 5adba12

Please sign in to comment.