Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove special handling for string constructors #248

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions llvm/lib/CheerpUtils/NativeRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,6 @@ Function* CheerpNativeRewriterPass::getReturningConstructor(Module& M, Function*
return cast<Function>(M.getOrInsertFunction(Twine("cheerpCreate",called->getName()).str(),newFunctionType).getCallee());
}

static bool redundantStringConstructor(Instruction* ci, SmallVectorImpl<Value*>& initialArgs)
{
if (initialArgs.size() != 1)
return false;
Type* ty = ci->getOperand(0)->getType();
Type* argTy = initialArgs[0]->getType();
if (!argTy->isPointerTy() || !argTy->getPointerElementType()->isStructTy())
return false;
if (ty == argTy && ty->getPointerElementType()->getStructName() == StringRef("class._ZN6client6StringE"))
return true;
return false;
}

static bool isClientTransparent(Function* called)
{
if (auto* metadata = called->getMetadata("cheerp.clienttransparent"))
Expand Down Expand Up @@ -188,7 +175,9 @@ bool CheerpNativeRewriterPass::rewriteIfNativeConstructorCall(Module& M, Instruc
return false;

//Transparent client constructors only cast their argument to the type that
//is being constructed, without actually calling any constructor
//is being constructed, without actually calling any constructor. This also
//optimizes the case of String(String), by removing the constructor call
//entirely.
if (isClientTransparent(called))
{
auto* castInst = new BitCastInst(newI, PointerType::getUnqual(initialArgs[0]->getType()), "", callInst);
Expand All @@ -198,15 +187,6 @@ bool CheerpNativeRewriterPass::rewriteIfNativeConstructorCall(Module& M, Instruc
return true;
}

//We optimize the special case of String(String), removing the constructor
//call entirely
if (redundantStringConstructor(callInst, initialArgs))
{
new StoreInst(initialArgs[0], newI, callInst);
if (auto* inv = dyn_cast<InvokeInst>(callInst))
BranchInst::Create(inv->getNormalDest(), inv->getParent());
return true;
}
Function* newFunc = getReturningConstructor(M, called);
CallBase* newCall = nullptr;
Instruction* InsertPt = nullptr;
Expand Down
Loading