这周看方舟编译器的优化算法,越看越觉得迷惑。今天回归一下本源。
MAPLE IR is the common representation for programs compiled from different programming languages, which include general purpose languages like C, C++ and Java. MAPLE IR is extensible. As additional languages, including domain-specific languages, are compiled into MAPLE IR, more constructs will be added to represent constructs unique to each language.
任何语言都可以翻译成Maple IR 语言。以下列语句为例:
C source:

int fact(int n) {if(n!=1)return n*fact(n-1);else return 1;
}

Maple IR:

func &fact (var %n i32) i32 {if(ne i32 (dread i32 %n, constval i32 1) {call $fact (sub i32 (dread i32 %n, constval i32 1))return (mul i32 (dread i32 %n, regread i32 %%retval))}return(constval i32 1)
}

Since MAPLE lR is one lR that can exist at multiple levels of semantics, the level of a MAPLE IR program is dictated by the constraints that it adheres to. These constraints are of the following two types:
Opcodes allowed - The higher the level, the more types of opcodes allowed, including opcodes generated only from specific languages. At the lowest level, only opcodes that correspond one-to-one to operations in a general purpose processor are allowed.
Code structure - The program structure is hierarchical at the higher levels. The hierarchical constructs become less and less as lowering proceeds. At the lowest level, the program structure is flat, consisting of sequences of primitive instructions consumed by the general purpose processor.
也就是说,Maple IR是不支持不同粒度的,各种编程语言都有自己的Code Structure 和Opcodes,在更高粒度,就是更接近各种编程语言个性化的程序结构,会允许各种个性化运算的Opcode。但编译到更低层次,就更接近于x86、arm、这种处理器的原生指令。
There are three kinds of executable nodes in MAPLE IR:
Leaf nodes - Also called terminal nodes, these nodes denote a value at execution time, which may be a constant or the value of a storage unit.
Expression nodes - An expression node performs an operation on its operands to compute a result. lts result is a function of the values of its operands and nothing else. Each operand can be either a leaf node or another expression node. Expression nodes are the internal nodes of expression trees. The type field in the expression node gives the type associated with the result of the operation.
Statement nodes - These represent the flow of control. Execution starts at the entry of the function and continues sequentially statement by statement until a control flow statement is executed. Apart from modifying control flow, statements can also modify data storage in the program. A statement nodes has operands that can be leaf,
expression or statement nodes.
一个编程语言可以抽象成一棵树,Maple IR写出来的语言有三个节点:
Leaf Node,也就是C语言里的一个数字常量或是一个存储变量而已。
Expression Node,显然就是各种Leaf node的加加减减,组成的表达式树。
Statement Node就是C语言里的一行语句。如果是if条件语句,会改变程序执行的流程。

dassign $a(add i32(dread i32 $b, dread i32 $c))
dassign $a(sub i32(add i32(dread i32 $b, dread i32 $c),dread i32 $d))

Opcode是这种编程语言的一种操作符,可以理解为一个函数,无非是制定了参数和返回值类型。
The general rules regarding line breaks are as follows:
Each expression or statement node must occupy its own line, and each line cannot contain more than one expression or statement node.
When there is at least one operand that is not a leaf node, then all the operands of the current expression or statement node must be specified in separate new lines, including operands that are leaf nodes.
Comments can be specified via the character ‘#’, which can be regarded as the end of line character by the lR parser.
For human-edited MAPLE lR files, the line breaks are not enforced for expressions, as they do not affect the correctness of the program, since the end of operand specification is indicated by the closing parenthesis. But there must not be more than one statement node per line, because we do not use the ';'character to delimit statement boundary.
每句话最后无需分号隔开,直接根据括号是否匹配来决定一行,每行最多一个表达式节点。

软件工程作业-方舟学习笔记08-部分原理(续相关推荐

  1. 软件工程作业-方舟学习笔记01-认识phase

    上一篇是分析方舟编译器的准备阶段,这一篇开始正式开扒. 吃饭的时候看到了一篇非常好的博客↓ https://www.zhihu.com/column/c_1187372958643941376 答主I ...

  2. 软件工程作业-方舟学习笔记07-方舟构建方法

    这一篇比较一下SSA构建方法与传统编译器的区别和优化,先来看一组比较实例: 一般方法 SSA方法 a=b+c: a1=b1+c1: a=a+b: a2=a1+b1: b=a+c: b2=a2+c1: ...

  3. ESP32 单片机学习笔记 - 08 - WebSocket客户端

    前言,终于要到网络模型的最后一层,第四层,应用层,http.websocket的实践了. 文章目录 ESP32 单片机学习笔记 - 08 - WebSocket客户端 一.应用层协议 科普概念 二.编 ...

  4. 软件制造工程学习笔记(详尽版)

    软件制造工程学习笔记 第一章 软件工程学概述 软件危机 软件工程 第二章 软件设计基本概念 设计过程 设计原理* 模块化 抽象 第三章 详细设计 结构程序设计 人机界面设计 过程设计工具 程序流程图 ...

  5. JavaWeb黑马旅游网-学习笔记08【旅游线路详情】

    Java后端 学习路线 笔记汇总表[黑马程序员] JavaWeb黑马旅游网-学习笔记01[准备工作] JavaWeb黑马旅游网-学习笔记02[注册功能] JavaWeb黑马旅游网-学习笔记03[登陆和 ...

  6. 《软件需求》学习笔记

    为什么80%的码农都做不了架构师?>>>    <软件需求>学习笔记 前几天读了Karl E.Wiegers<软件需求>,书的内容写得非常好.我这里谈谈读了此 ...

  7. 【计算机网络学习笔记08】ICMP

    [计算机网络学习笔记08]ICMP 1 概念 由[RFC 792]定义的因特网控制报文协议(Internet Control Message Protocol,ICMP),被主机和路由器用来彼此沟通的 ...

  8. 华为HCIA-datacom 学习笔记11——AAA原理与配置

    华为HCIA-datacom 学习笔记11--AAA原理与配置 AAA原理与配置 1.AAA概述 认证(authentication):验证用户是否获得访问权,确定哪些用户可以访问网络 授权(auth ...

  9. TI CC1101学习笔记:工作原理简单入门

    众所周知,在IOT的市场应用中,从通信协议细分的话,有SUB-1G,2.4G,3G, 4G,以及最新推出的5G,虽然5G通信协议已经在崭露头角,但是不同的通信协议在不同的应用领域之中还是占据着一定的重 ...

  10. 软件开发流程--学习笔记

    软件开发流程--学习笔记 背景 产生原因及作用 个人理解 软件开发流程 需求 需求调研 需求分析 需求确认 设计 概要设计 详细设计 编码 测试 交付 维护 知识拓展 软件开发生命周期(SDLC) 软 ...

最新文章

  1. 将让企业获利的5个人工智能趋势
  2. CSP认证201512-2 消除类游戏[C++题解]:模拟
  3. c调用其他类的方法_Java 的 Native 方法——今天又进步了
  4. Linux 嵌入式启动以及优化(Z)
  5. MySQL 多表查询、连接查询(内连接、外连接)
  6. java 开发环境的搭建
  7. 深入学习js之——原型和原型链
  8. 据说,80%的人没有真正理解了Spring的依赖注入
  9. POJ 1741 Tree 树分治
  10. 集群之间数据拷贝distcp性能的调优
  11. 封装和参数调用(格式修改)
  12. mybatis mysql net教程_MyBatis 教程
  13. sql 给字段设置默认值,
  14. python运行出玫瑰花的代码_一支玫瑰 - python代码库 - 云代码
  15. Python 第六章 面向对象编程(MD模式)
  16. mac打开nh文件-cajviewer.dmg
  17. 200道Java灵魂考题:全部掌握拿下阿里P7腾讯T3.2
  18. Ubuntu 老版本下载
  19. 使用R语言并行提取栅格数据
  20. acmev2怎么用_lua-resty-acme: ACMEv2 客户端和 Let's Encrypt 证书的自动化管理

热门文章

  1. HHUOJ 1012 欧洲杯(水题)
  2. 赛码-回文串-java
  3. 赛码网在线考试无法使用外接摄像头解决方案
  4. 2018年北京信息科技大学第十届程序设计竞赛暨ACM选拔赛 C:计算几何
  5. php向mysql写入_PHP向MySql中插入数据
  6. 自己怎么压缩js文件?
  7. SCANV团队提供APPCMS安全漏洞独立补丁
  8. python颜色的数字代码_python – 更改QLCD数字的数字颜色
  9. vue3警告[Vue warn]: Extraneous non-emits event listeners (getVal) were passed to component but could n
  10. html5 css3时间特效,炫酷纯CSS3响应式垂直时间轴特效