Skip to content

Commit d5f0aca

Browse files
committed
Add PA functions for load/store instructions
1 parent 7bc1a8d commit d5f0aca

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

llvm/include/llvm/Cheerp/PointerAnalyzer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,15 @@ class PointerAnalyzer
281281
POINTER_KIND getPointerKindForStoredType( llvm::Type * pointerType ) const;
282282
POINTER_KIND getPointerKindForMemberPointer( const TypeAndIndex& baseAndIndex ) const;
283283
POINTER_KIND getPointerKindForMember( const TypeAndIndex& baseAndIndex ) const;
284+
POINTER_KIND getPointerKindForLoadStore(const llvm::Value* v) const;
284285
POINTER_KIND getPointerKindForArgumentTypeAndIndex( const TypeAndIndex& argTypeAndIndex ) const;
285286
POINTER_KIND getPointerKindForArgument( const llvm::Argument* A ) const;
286287
POINTER_KIND getPointerKindForJSExportedType (llvm::Type* pointerType) const;
287288
const PointerKindWrapper& getFinalPointerKindWrapper(const llvm::Value* v ) const;
288289
static TypeAndIndex getBaseStructAndIndexFromGEP( const llvm::Value* v );
289290
const llvm::ConstantInt* getConstantOffsetForPointer( const llvm::Value* ) const;
290291
const llvm::ConstantInt* getConstantOffsetForMember( const TypeAndIndex& baseAndIndex ) const;
292+
const llvm::ConstantInt* getConstantOffsetForLoadStore(const llvm::Value* v) const;
291293

292294
/**
293295
* Functions to manually invalidate the cache

llvm/lib/CheerpUtils/PointerAnalyzer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,11 @@ POINTER_KIND PointerAnalyzer::getPointerKindForMember(const TypeAndIndex& baseAn
17231723
return getPointerKindForMemberImpl(baseAndIndex, PACache);
17241724
}
17251725

1726+
POINTER_KIND PointerAnalyzer::getPointerKindForLoadStore(const llvm::Value* v) const
1727+
{
1728+
return getPointerKind(v);
1729+
}
1730+
17261731
TypeAndIndex PointerAnalyzer::getBaseStructAndIndexFromGEP(const Value* p)
17271732
{
17281733
if(!isGEP(p))
@@ -1826,6 +1831,11 @@ const llvm::ConstantInt* PointerAnalyzer::getConstantOffsetForMember( const Type
18261831
return ret.getPointerOffset();
18271832
}
18281833

1834+
const llvm::ConstantInt* PointerAnalyzer::getConstantOffsetForLoadStore(const llvm::Value* v) const
1835+
{
1836+
return getConstantOffsetForPointer(v);
1837+
}
1838+
18291839
void PointerAnalyzer::invalidate(const Value * v)
18301840
{
18311841
assert(status == MODIFIABLE);

llvm/lib/CheerpUtils/Utility.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,10 @@ bool InstElemIterator::isTwoElems(const llvm::Instruction* I, llvm::Type* Ty, in
14781478
{
14791479
if(!Ty->isStructTy())
14801480
{
1481+
// avoid calling getPointerKind for store instruction
1482+
if (isa<StoreInst>(I))
1483+
return Ty->isPointerTy() && PA.getPointerKindForLoadStore(I) == SPLIT_REGULAR && !PA.getConstantOffsetForLoadStore(I);
1484+
14811485
return Ty->isPointerTy() && PA.getPointerKind(I) == SPLIT_REGULAR && !PA.getConstantOffsetForPointer(I);
14821486
}
14831487
auto* STy = llvm::cast<llvm::StructType>(Ty);

llvm/lib/CheerpWriter/CheerpWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4557,7 +4557,7 @@ void CheerpWriter::compileLoad(const LoadInst& li, PARENT_PRIORITY parentPrio)
45574557
}
45584558
else if(Ty->isPointerTy())
45594559
{
4560-
elemPtrKind = PA.getPointerKind(&li);
4560+
elemPtrKind = PA.getPointerKindForLoadStore(&li);
45614561
}
45624562
bool isOffset = ie.ptrIdx == 1;
45634563
compileLoadElem(li, Ty, STy, ptrKind, elemPtrKind, isOffset, elemRegKind, ie.structIdx, asmjs, parentPrio);
@@ -4755,7 +4755,7 @@ void CheerpWriter::compileStore(const StoreInst& si)
47554755
}
47564756
else if(Ty->isPointerTy())
47574757
{
4758-
elemPtrKind = PA.getPointerKind(&si);
4758+
elemPtrKind = PA.getPointerKindForLoadStore(&si);
47594759
}
47604760
bool isOffset = ie.ptrIdx == 1;
47614761
compileStoreElem(si, Ty, STy, ptrKind, elemPtrKind, isOffset, elemRegKind, ie.totalIdx, ie.structIdx, asmjs);

0 commit comments

Comments
 (0)