Towards Ontology-Based Program Analysis

Yue Zhao, Guoyang Chen, Chunhua Liao, Xipeng ShenECOOP 2016 · DOI

TL;DR

This paper introduces PATO, a novel framework that leverages ontologies to standardize and unify program analysis. By representing program knowledge in a structured, semantic way, PATO aims to overcome limitations in current declarative program analysis, enabling better cooperation between analysis tools, guiding optimizations, and reducing the effort required for program preprocessing.

What Problem Does This Paper Address?

Developing program analyses is a complex and error-prone process, especially for general users. While declarative program analysis offers a more productive approach by using logic programming, it faces significant limitations:

  • Cooperation: Different analysis tools often use disparate representations of program information, making it difficult to compose them or reuse their results.
  • Optimization Guidance: Current analyses primarily focus on debugging and lack the ability to effectively integrate diverse knowledge (program, hardware, domain-specific) needed for program optimization.
  • Preprocessing Effort: Declarative analyses typically require a separate, often tedious, preprocessing step to extract program relations, which needs to be redeveloped for each new analysis.

This paper argues that these limitations stem from a lack of a systematic conceptual framework for representing program analysis knowledge.

Methods

The core innovation is the integration of ontologies into declarative program analysis. An ontology provides a standardized vocabulary and a formal way to represent knowledge within a domain. The authors developed a prototype framework called PATO (Program Analysis Through ontology) to demonstrate this approach.

Key aspects of PATO include:

  • Ontology-Based Program Representation: PATO uses an ontology to represent C programs and related knowledge. This ontology is designed to be generic and extensible.
  • Ontology Translator: A translator, built on top of a source-to-source compiler (ROSE), converts program code into OWL triples, forming the knowledge base.
  • Declarative Rules: Program analyses are expressed as Prolog rules that query the ontology-based knowledge base.
  • Scoped IRI Naming: A naming scheme using scoped IRIs is employed to manage program construct representations and mitigate issues caused by code changes.
  • Knowledge Base Management: A cache-like mechanism is used to manage the knowledge base efficiently, balancing space and retrieval speed.
  • PATO Framework: PATO integrates an OWL-based knowledge base, a Prolog reasoning engine, and APIs for building and querying the knowledge. It also offers a direct query interface for efficiency.

Datasets

The paper evaluates PATO using the NAS Parallel Benchmarks (NPB) for canonical loop analysis and other experiments. They also tested their system on three real-world programs: bzip2, gzip, and oggenc.

Key Insights and Ideas

  • Ontology as a Unifying Framework: Ontologies can serve as a common, standardized representation for program knowledge, bridging the gap between different analysis tools and compilers.
  • Seamless Knowledge Integration: By representing program constructs, hardware characteristics, and domain expertise within a single ontology, PATO can effectively link diverse knowledge sources, crucial for guiding complex optimizations.
  • Reduced Preprocessing Burden: A single, well-designed ontology can support multiple analyses, eliminating the need for separate preprocessing steps for each new analysis.
  • Enhanced Cooperation: Standardized representations simplify the integration and cooperation of analyses from different compilers (e.g., LLVM Clang and ROSE), leading to more precise results through synergy.
  • Declarative Power for Analysis: Leveraging logic programming on an ontology-based knowledge base inherits the productivity benefits of declarative programming for analysis development.

Key Results

  • Canonical Loop Analysis: PATO's declarative approach for canonical loop analysis was competitive with, and in some cases faster than, imperative implementations in the ROSE compiler. The PATO implementation was also significantly shorter (190 lines vs. 380 lines).
  • Pointer Analysis: The implementation of Andersen's pointer analysis in PATO required less than 500 lines of code (including preprocessing) and achieved fast analysis times (e.g., 2.1 seconds for bzip2).
  • Facilitating Cooperations (Liveness Analysis): Combining Liveness analysis results from LLVM Clang and ROSE using PATO led to an average precision improvement of over 10% and 20% respectively.
  • GPU Data Placement: PATO demonstrated similar placements to prior methods for GPU data placement optimization, with a slight increase in analysis time but significantly better extensibility due to its ontology-based approach.
  • Code Size Reduction: Across various analyses, PATO implementations were substantially shorter than imperative counterparts, highlighting the productivity gains.

Limitations and Future Work

The authors acknowledge that this work is a first step. The current ontology is primarily for C programs and GPU data placement. They suggest that a full ontology for program analysis would require:

  • Comprehensive Ontology Design: Defining a complete ontology for program analysis concepts (e.g., dominator, post-order, alias) and their relations.
  • Exploiting Ontology Potential: Further investigation into how ontologies can be more deeply integrated into program analysis and optimization beyond logic programming.
  • Community Effort: Achieving a standard Program Analysis ontology would require coordinated effort from the community.
  • Performance Optimization: While PATO shows good performance, further exploration of optimizations for logic reasoners and potential for customized parsers for specific scenarios is warranted.
  • Broader Language Support: Extending the ontology and framework to support other programming languages.

Summary updated

BibTeX
@inproceedings{zhao2016towards,
  author = {Yue Zhao and Guoyang Chen and Chunhua Liao and Xipeng Shen},
  title = {{Towards Ontology-Based Program Analysis}},
  booktitle = {ECOOP},
  year = {2016},
  doi = {10.4230/lipics.ecoop.2016.26},
}

Loading related content...

Figure