第一章: 理解 LLVM

LLVM系列第一章:编译LLVM源码 详细介绍如何利用CMake和Ninja工具来编译及安装LLVM。 阅读详情

JavaScript 是最受欢迎的编程语言之一。然而,JavaScript 有两个主要缺点:

  • 性能不可预测

    JavaScript 在 JavaScript 引擎提供的环境和运行时中执行。有各种各样的 JavaScript 引擎(V8、WebKit 和 Gecko)。它们都是不同构建的,并以不同的方式运行相同的 JavaScript 代码。再加上,JavaScript 是动态类型的。这意味着 JavaScript 引擎在执行 JavaScript 代码时需要猜测类型。这些因素导致了 JavaScript 执行的性能不可预测。对一种类型的 JavaScript 引擎的优化可能会在其他类型的 JavaScript 引擎上产生不良的副作用。这导致了性能的不可预测性。

  • 包大小

    JavaScript 引擎在下载整个 JavaScript 文件之前都会等待,然后才开始解析和执行。JavaScript 文件越大,等待时间就越长。这会降低应用程序的性能。像 webpack 这样的打包工具有助于最小化包大小。但当你的应用程序增长时,包大小呈指数级增长。

有没有一种工具既提供原生性能,又有更小的大小?是的,WebAssembly。

WebAssembly 是 web 和节点开发的未来。WebAssembly 是静态类型的且预编译的,因此它比 JavaScript 提供更好的性能。二进制的预编译提供了生成微小二进制包的选项。WebAssembly 允许像 Rust、C 和 C++ 这样的语言被编译成在 JavaScript 引擎中与 JavaScript 一起运行的二进制代码。所有 WebAssembly 编译器都在底层使用 LLVM 将原生代码转换成 WebAssembly 二进制代码。因此,了解 LLVM 是什么以及它如何工作是很重要的。

在本章中,我们将学习编译器的各种组件是什么以及它们是如何工作的。然后,我们将探索 LLVM 是什么以及它如何帮助编译语言。最后,我们将看到 LLVM 编译器是如何编译原生代码的。我们将在本章中涵盖以下主题:

  • 理解编译器
  • 探索 LLVM
  • LLVM 实战

技术要求

我们将使用 Clang,这是一个将 C/C++ 代码编译成原生代码的编译器。

对于 Linux 和 Mac 用户,Clang 应该是开箱即用的。

对于 Windows 用户,可以从以下链接安装 Clang:(https://llvm.org/docs/GettingStarted.html?highlight=installing clang windows#getting-the-source-code-and-building-llvm) 来安装 Clang。

《深入理解LLVM》第一章 LLVM简介 第一章 LLVM简介作者:史宁宁1.1 LLVM是什么LLVM是什么?这是一个虽然基础,但是也曾经让很多新入门的人迷惑的一个问题。从字面上来讲,LLVM(Low Level Virtual Machine)是一个底层虚拟机,LLVM曾经有一部分功能对虚拟机有所帮助。但是现在,LLVM所代表的基本和虚拟机没有关系了,也不在作为一个缩写使用了,而是直接作为一个名字使用。那么LLVM到底是什么? L 阅读详情

相关推荐

LLVM的编译链工具

通常我们在命令行上调用的clang工具,是Clang驱动程序,因为LLVM本质上只是一个编译器框架,所以需要一个驱动程序把整个编译器的功能串起来,clang能够监控整个编译器的流程,即能够调用到Clang和LLVM的各种库,最终实现编译的功能。来指定输出是汇编文件还是目标文件,若生成是目标文件,llc会调用LLVM中的汇编输出的代码库来工作(注意这个汇编器和gcc的汇编器也不同,它输入的是MI,是一种后端的中间表示)。clang能够调用起来整个编译器的流程,也就是上边其他工具调用的库,它很多都同样会调用。

panpan_jiang1的博客 1802

LLVM系列第三章:函数Function

用LLVM提供的C++ API,创建一个最简单的函数(Function),并打印出它的IR代码

Zhanglin_Wu的专栏, C++, Scrum, LLVM, 编译器 5716

LLVM系列第二十七章:理解IRBuilder

简单地分析一下LLVM API中的IRBuilder的作用和用法

Zhanglin_Wu的专栏, C++, Scrum, LLVM, 编译器 4611

跟随一条指令来看LLVM的基本结构

LLVM是一个很复杂的软件,了解LLVM的工作原理不是很容易,然而,对于刚开始接触LLVM整个框架的工作原理来说,详细而深入,不如广泛而浅显,所以有了这一篇文章。

SiberiaBear的专栏 4923

LLVM IR 理解

LLVM IR 理解 LLVM IR表示 LLVM IR有三个不同的形式: 内存中编译中间语言(IR) 保存在硬盘上的 bitcode(.bc 文件,适合快速被一个 JIT 编译器加载) 一个可读性的汇编语言表示(.ll 文件)。 LLVM为高效编译转换和分析,提供一个强大的中间表示。LLVM 的三种不同的形式都是等价的。以下是三种表示的转化方式。 LLVM 语言在轻量、底层、同时富有表现力,类型化,易于扩展。LLVM IR 语言目标是成为一种"通用中间语言",通过足够低层次,使高级语言可以清晰的映射。通

吴建明wujianming_110117 1505

LLVM系列第六章:函数返回值Return

用LLVM提供的C++ API,创建一个带有返回值(Return)的函数,并打印出它的IR代码

Zhanglin_Wu的专栏, C++, Scrum, LLVM, 编译器 2736

Vivado 2023.1及更早版本永久License全功能解锁:HLS、System Generator等IP核使用详解

本文深入解析Vivado 2023.1及更早版本的全功能许可证,详细指导如何解锁HLS、System Generator等高级IP核。通过许可证类型对比、功能验证方法和实战应用指南,帮助FPGA开发者充分利用Vivado工具套件,提升复杂系统设计和算法加速的效率。

weixin_31286719的博客 395

ESP32-S3 SPI接口实战:从引脚分配到高速通信配置

本文详细解析了ESP32-S3的SPI接口配置与高速通信优化技巧,从引脚分配到软件配置,再到DMA传输和时钟优化,帮助开发者快速掌握SPI通信技术。特别针对ESP32-S3的SPI2接口进行了实战演示,包括硬件连接和常见问题排查,适用于各类嵌入式开发项目。

weixin_29189373的博客 698

elegant(ELEctron Generation ANd Tracking)入门指南(1)

elegant (ELEctron Generation ANd Tracking),美国先进光子源(APS)所用的圆环加速器的模拟程。

qq_41106132的博客 1863

USB设备识别码VID和PID详解:如何查询和自定义你的设备ID

本文详细解析了USB设备识别码VID和PID的核心作用、查询方法及自定义配置技巧。VID(供应商识别码)和PID(产品识别码)是USB设备的唯一身份证,用于驱动匹配和功能识别。文章提供了Windows和Linux系统下的查询方法,并探讨了如何合法获取和自定义VID/PID,适合硬件开发者和DIY爱好者参考。

weixin_29168675的博客 1691

高通平台 Android T 蓝牙技术全解析:A2DP 与 AVRCP 核心代码路径与交互流程

A2DP 接收端 - 连接流程(AVDTP 打开)

专业开发者的博客,一个从事Android WiFi和蓝牙的工程师 295

微机接口 上机考试题目及代码

吉林大学微机接口 上机考试 A , B 卷内容及代码

一杯水果茶!足矣~ 2005

Modbus协议学习第一篇之基础概念

因工作需要而接触Modbus,正在恶补知识,利用博客的方式来加深理解和记忆,同时希望同行大佬能一起交流。

hzf978742221的博客 885

Python爬虫:爬取健身平台运动数据(跑步、骑行轨迹)

通过分析这些运动数据,用户能够了解自己的运动趋势、运动成绩,并作出相应的调整。通过使用Strava的API,我们成功地获取了用户的运动活动信息和运动轨迹数据,并进行了存储与可视化。Strava的API提供了丰富的数据接口,能够通过OAuth2认证获取用户的运动数据,包括历史数据、运动轨迹等信息。Strava的API还提供了获取活动轨迹数据的接口,返回的数据格式通常是GeoJSON格式,适用于地图可视化。随着大数据技术的发展,运动数据的分析和可视化为个人健康管理、运动训练计划的优化等提供了强大的支持。

2201_76125261的博客 1085

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Rust变量和类型
下一篇: 第二章: 学习Emscripten
段舸
博客等级 码龄3年 533粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址