Fix performance bug, review feedback on indexer changes (#818)
This commit is contained in:
+23
-22
@@ -128,7 +128,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
if (structDecl.def == null) {
|
if (structDecl.def == null) {
|
||||||
val definitionCursor = clang_getCursorDefinition(cursor)
|
val definitionCursor = clang_getCursorDefinition(cursor)
|
||||||
if (clang_Cursor_isNull(definitionCursor) == 0) {
|
if (clang_Cursor_isNull(definitionCursor) == 0) {
|
||||||
assert (clang_isCursorDefinition(definitionCursor) != 0)
|
assert(clang_isCursorDefinition(definitionCursor) != 0)
|
||||||
createStructDef(structDecl, cursor)
|
createStructDef(structDecl, cursor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,7 +285,8 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
result.methods.add(method)
|
result.methods.add(method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CXChildVisitResult.CXChildVisit_Continue
|
CXChildVisitResult.CXChildVisit_Continue
|
||||||
}
|
}
|
||||||
@@ -365,7 +366,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun convertCursorType(cursor: CValue<CXCursor>) =
|
private fun convertCursorType(cursor: CValue<CXCursor>) =
|
||||||
convertType(clang_getCursorType(cursor), clang_getDeclTypeAttributes(cursor))
|
convertType(clang_getCursorType(cursor), clang_getDeclTypeAttributes(cursor))
|
||||||
|
|
||||||
private inline fun objCType(supplier: () -> ObjCPointer) = when (library.language) {
|
private inline fun objCType(supplier: () -> ObjCPointer) = when (library.language) {
|
||||||
Language.C -> UnsupportedType
|
Language.C -> UnsupportedType
|
||||||
@@ -483,7 +484,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
|
|
||||||
private fun convertFunctionType(type: CValue<CXType>): Type {
|
private fun convertFunctionType(type: CValue<CXType>): Type {
|
||||||
val kind = type.kind
|
val kind = type.kind
|
||||||
assert (kind == CXType_Unexposed || kind == CXType_FunctionProto)
|
assert(kind == CXType_Unexposed || kind == CXType_FunctionProto)
|
||||||
|
|
||||||
return if (clang_isFunctionTypeVariadic(type) != 0) {
|
return if (clang_isFunctionTypeVariadic(type) != 0) {
|
||||||
VoidType // make this function pointer opaque.
|
VoidType // make this function pointer opaque.
|
||||||
@@ -500,27 +501,27 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
private val TARGET_ATTRIBUTE = "__target__"
|
private val TARGET_ATTRIBUTE = "__target__"
|
||||||
|
|
||||||
internal fun tokenizeExtent(cursor: CValue<CXCursor>): List<String> {
|
internal fun tokenizeExtent(cursor: CValue<CXCursor>): List<String> {
|
||||||
val translationUnit = clang_Cursor_getTranslationUnit(cursor)!!
|
val translationUnit = clang_Cursor_getTranslationUnit(cursor)!!
|
||||||
val cursorExtent = clang_getCursorExtent(cursor)
|
val cursorExtent = clang_getCursorExtent(cursor)
|
||||||
memScoped {
|
memScoped {
|
||||||
val tokensVar = alloc<CPointerVar<CXToken>>()
|
val tokensVar = alloc<CPointerVar<CXToken>>()
|
||||||
val numTokensVar = alloc<IntVar>()
|
val numTokensVar = alloc<IntVar>()
|
||||||
clang_tokenize(translationUnit, cursorExtent, tokensVar.ptr, numTokensVar.ptr)
|
clang_tokenize(translationUnit, cursorExtent, tokensVar.ptr, numTokensVar.ptr)
|
||||||
val numTokens = numTokensVar.value
|
val numTokens = numTokensVar.value
|
||||||
val tokens = tokensVar.value
|
val tokens = tokensVar.value
|
||||||
if (tokens == null) return emptyList<String>()
|
if (tokens == null) return emptyList<String>()
|
||||||
try {
|
try {
|
||||||
return (0 until numTokens).map {
|
return (0 until numTokens).map {
|
||||||
clang_getTokenSpelling(translationUnit, tokens[it].readValue()).convertAndDispose()
|
clang_getTokenSpelling(translationUnit, tokens[it].readValue()).convertAndDispose()
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
clang_disposeTokens(translationUnit, tokens, numTokens)
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
clang_disposeTokens(translationUnit, tokens, numTokens)
|
|
||||||
}
|
}
|
||||||
}
|
TODO()
|
||||||
TODO()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isSuitable(cursor: CValue<CXCursor>): Boolean {
|
private fun isSuitableFunction(cursor: CValue<CXCursor>): Boolean {
|
||||||
if (!isAvailable(cursor)) return false
|
if (!isAvailable(cursor)) return false
|
||||||
|
|
||||||
// If function is specific for certain target, ignore that, as we may be
|
// If function is specific for certain target, ignore that, as we may be
|
||||||
@@ -566,7 +567,7 @@ internal class NativeIndexImpl(val library: NativeLibrary) : NativeIndex() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CXIdxEntity_Function -> {
|
CXIdxEntity_Function -> {
|
||||||
if (isSuitable(cursor)) {
|
if (isSuitableFunction(cursor)) {
|
||||||
functionById[getDeclarationId(cursor)] = getFunction(cursor)
|
functionById[getDeclarationId(cursor)] = getFunction(cursor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -216,6 +216,9 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
|||||||
var phase: KonanPhase? = null
|
var phase: KonanPhase? = null
|
||||||
var depth: Int = 0
|
var depth: Int = 0
|
||||||
|
|
||||||
|
// Cache used for source offset->(line,column) mapping.
|
||||||
|
val fileEntryCache = mutableMapOf<String, SourceManager.FileEntry>()
|
||||||
|
|
||||||
protected fun separator(title: String) {
|
protected fun separator(title: String) {
|
||||||
println("\n\n--- ${title} ----------------------\n")
|
println("\n\n--- ${title} ----------------------\n")
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -93,9 +93,9 @@ class NaiveSourceBasedFileEntryImpl(override val name: String) : SourceManager.F
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------//
|
//-----------------------------------------------------------------------------//
|
||||||
|
|
||||||
class IrFileImpl(fileName: String) : IrFile {
|
class IrFileImpl(entry: SourceManager.FileEntry) : IrFile {
|
||||||
|
|
||||||
override val fileEntry = NaiveSourceBasedFileEntryImpl(fileName)
|
override val fileEntry = entry
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
|
import org.jetbrains.kotlin.ir.SourceManager
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltinOperatorDescriptorBase
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltinOperatorDescriptorBase
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
@@ -1433,8 +1434,15 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
fun getFileEntry(sourceFileName: String): SourceManager.FileEntry {
|
||||||
|
// We must cache file entries, otherwise we reparse same file many times.
|
||||||
|
return context.fileEntryCache.getOrPut(sourceFileName) {
|
||||||
|
NaiveSourceBasedFileEntryImpl(sourceFileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private inner class ReturnableBlockScope(val returnableBlock: IrReturnableBlockImpl) : FileScope(IrFileImpl(returnableBlock.sourceFileName)) {
|
private inner class ReturnableBlockScope(val returnableBlock: IrReturnableBlockImpl) :
|
||||||
|
FileScope(IrFileImpl(getFileEntry(returnableBlock.sourceFileName))) {
|
||||||
|
|
||||||
var bbExit : LLVMBasicBlockRef? = null
|
var bbExit : LLVMBasicBlockRef? = null
|
||||||
var resultPhi : LLVMValueRef? = null
|
var resultPhi : LLVMValueRef? = null
|
||||||
|
|||||||
Reference in New Issue
Block a user