{"id":2945,"date":"2013-08-23T19:56:39","date_gmt":"2013-08-23T10:56:39","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=2945"},"modified":"2013-08-23T19:56:39","modified_gmt":"2013-08-23T10:56:39","slug":"3-5-%e3%83%89%e3%83%a9%e3%82%a4%e3%83%90%e3%81%ae%e5%a4%89%e6%9b%b4%e3%81%a8%e7%b5%90%e8%ab%96","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/2945","title":{"rendered":"3.5. \u30c9\u30e9\u30a4\u30d0\u306e\u5909\u66f4\u3068\u7d50\u8ad6"},"content":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c3\u7ae0 \u4e07\u83ef\u93e1: LLVM IR\u30b3\u30fc\u30c9\u306e\u751f\u6210<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl03.html#driver-changes-and-closing-thoughts\" target=\"_blank\">\u7b2c5\u7bc0 \u30c9\u30e9\u30a4\u30d0\u306e\u5909\u66f4\u3068\u7d50\u8ad6<\/a><\/p>\n<p>\u4eca\u306e\u3068\u3053\u308d\u3001LLVM\u306b\u5bfe\u3059\u308b\u30b3\u30fc\u30c9\u751f\u6210\u306f\u3001\u304d\u308c\u3044\u306aIR\u30b3\u30fc\u30eb\u3092\u898b\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3068\u3044\u3046\u4e8b\u4ee5\u5916\u306f\u3001\u5b9f\u969b\u306b\u306f\u3042\u307e\u308a\u5f79\u7acb\u305f\u306a\u3044\u3002<br \/>\nCodegen\u30e1\u30bd\u30c3\u30c9\u306b\u201dHandleDefinition&#8221;\u3084\u201dHandleExtern&#8221;\u306a\u3069\u306e\u95a2\u6570\u547c\u3073\u51fa\u3057\u3092\u8ffd\u52a0\u3059\u308b\u3068\u3001LLVM IR\u306e\u30c0\u30f3\u30d7\u304c\u898b\u308c\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001LLVM IR\u3092\u7c21\u5358\u306a\u95a2\u6570\u3067\u898b\u308c\u308b\u826f\u3044\u65b9\u6cd5\u3067\u3042\u308b\u3002<br \/>\n\u4f8b\u3048\u3070\u305d\u306e\u51fa\u529b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; 4+5;\r\nRead top-level expression:\r\ndefine double @0() {\r\nentry:\r\n  ret double 9.000000e+00\r\n}<\/pre>\n<p>\u69cb\u6587\u89e3\u6790\u5668\u304c\u3001\u30c8\u30c3\u30d7\u30ec\u30d9\u30eb\u306e\u5f0f\u3092\u3069\u306e\u3088\u3046\u306b\u533f\u540d\u95a2\u6570\u306b\u5909\u63db\u3059\u308b\u304b\u306b\u6ce8\u610f\u3002<br \/>\n\u3053\u308c\u306f\u3001\u6b21\u306e\u7ae0\u306b\u304a\u3044\u3066JIT\u30b5\u30dd\u30fc\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3068\u304d\u306b\u5f79\u7acb\u3064\u3060\u308d\u3046\u3002<br \/>\n\u30b3\u30fc\u30c9\u306f\u3001\u305d\u3063\u304f\u308a\u305d\u306e\u307e\u307e\u7ffb\u8a33\u3055\u308c\u3001IRBuilder\u306b\u3088\u308b\u7c21\u5358\u306a\u5b9a\u6570\u306e\u7573\u307f\u8fbc\u307f\u3092\u9664\u3044\u3066\u6700\u9069\u5316\u304c\u884c\u308f\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u306b\u3082\u6ce8\u610f\u3002<br \/>\n\u6700\u9069\u5316\u6a5f\u80fd\u306f\u6b21\u306e\u7ae0\u3067\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; def foo(a b) a*a + 2*a*b + b*b;\r\nRead function definition:\r\ndefine double @foo(double %a, double %b) {\r\nentry:\r\n  %multmp = fmul double %a, %a\r\n  %multmp1 = fmul double 2.000000e+00, %a\r\n  %multmp2 = fmul double %multmp1, %b\r\n  %addtmp = fadd double %multmp, %multmp2\r\n  %multmp3 = fmul double %b, %b\r\n  %addtmp4 = fadd double %addtmp, %multmp3\r\n  ret double %addtmp4\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u3001\u5e7e\u3064\u304b\u306e\u7c21\u5358\u306a\u8a08\u7b97\u3092\u793a\u3057\u3066\u3044\u308b\u3002<br \/>\n\u547d\u4ee4\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3057\u305fLLVM Builder\u306e\u547c\u3073\u51fa\u3057\u3068\u306e\u8457\u3057\u3044\u985e\u4f3c\u6027\u306b\u6ce8\u76ee\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; def bar(a) foo(a, 4.0) + bar(31337);\r\nRead function definition:\r\ndefine double @bar(double %a) {\r\nentry:\r\n  %calltmp = call double @foo(double %a, double 4.000000e+00)\r\n  %calltmp1 = call double @bar(double 3.133700e+04)\r\n  %addtmp = fadd double %calltmp, %calltmp1\r\n  ret double %addtmp\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u95a2\u6570\u547c\u3073\u51fa\u3057\u3092\u793a\u3057\u3066\u3044\u308b\u3002<br \/>\n\u3053\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u305f\u3068\u3057\u305f\u3089\u3001\u5b9f\u884c\u306b\u9577\u3044\u6642\u9593\u304c\u304b\u304b\u308b\u3067\u3042\u308d\u3046\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\n\u518d\u5e30\u3092\u4fbf\u5229\u306b\u3059\u308b\u305f\u3081\u3001\u3053\u306e\u5148\u306e\u7ae0\u3067\u3001\u6761\u4ef6\u4ed8\u304d\u5236\u5fa1\u30d5\u30ed\u30fc\u3092\u8ffd\u52a0\u3059\u308b\u4e88\u5b9a\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; extern cos(x);\r\nRead extern:\r\ndeclare double @cos(double)\r\n\r\nready&gt; cos(1.234);\r\nRead top-level expression:\r\ndefine double @1() {\r\nentry:\r\n  %calltmp = call double @cos(double 1.234000e+00)\r\n  ret double %calltmp\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u3001libm\u306e&#8221;cos&#8221;\u95a2\u6570\u306e\u305f\u3081\u306eextern\u5ba3\u8a00\u3068\u3001\u305d\u306e\u547c\u3073\u51fa\u3057\u3092\u793a\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; ^D\r\n; ModuleID = 'my cool jit'\r\n\r\ndefine double @0() {\r\nentry:\r\n  %addtmp = fadd double 4.000000e+00, 5.000000e+00\r\n  ret double %addtmp\r\n}\r\n\r\ndefine double @foo(double %a, double %b) {\r\nentry:\r\n  %multmp = fmul double %a, %a\r\n  %multmp1 = fmul double 2.000000e+00, %a\r\n  %multmp2 = fmul double %multmp1, %b\r\n  %addtmp = fadd double %multmp, %multmp2\r\n  %multmp3 = fmul double %b, %b\r\n  %addtmp4 = fadd double %addtmp, %multmp3\r\n  ret double %addtmp4\r\n}\r\n\r\ndefine double @bar(double %a) {\r\nentry:\r\n  %calltmp = call double @foo(double %a, double 4.000000e+00)\r\n  %calltmp1 = call double @bar(double 3.133700e+04)\r\n  %addtmp = fadd double %calltmp, %calltmp1\r\n  ret double %addtmp\r\n}\r\n\r\ndeclare double @cos(double)\r\n\r\ndefine double @1() {\r\nentry:\r\n  %calltmp = call double @cos(double 1.234000e+00)\r\n  ret double %calltmp\r\n}<\/pre>\n<p>\u5165\u529b\u4e2d\u306e\u30c7\u30e2\u3092\u7d42\u4e86\u3059\u308b\u3068\u304d\u3001\u751f\u6210\u3055\u308c\u305f\u30e2\u30b8\u30e5\u30fc\u30eb\u5168\u4f53\u306eIR\u306e\u30c0\u30f3\u30d7\u3092\u51fa\u529b\u3059\u308b\u3002<br \/>\n\u304a\u4e92\u3044\u306b\u53c2\u7167\u3057\u3042\u3063\u3066\u308b\u5168\u3066\u306e\u95a2\u6570\u3092\u542b\u3080\u5168\u4f53\u304c\u898b\u308c\u308b\u306e\u304c\u5206\u304b\u308b\u3068\u601d\u3046\u3002<br \/>\n\u3053\u308c\u3067\u4e07\u83ef\u93e1\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u7b2c3\u7ae0\u306f\u7d42\u308f\u308a\u3067\u3042\u308b\u3002<br \/>\n\u6b21\u306f\u3001\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001JIT\u30b3\u30fc\u30c9\u751f\u6210\u3068\u6700\u9069\u5316\u30b5\u30dd\u30fc\u30c8\u306e\u8ffd\u52a0\u306b\u3064\u3044\u3066\u8aac\u660e\u3059\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2836\" title=\"LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\">LLVM\u306b\u3088\u308b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u5b9f\u88c5\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u65e5\u672c\u8a9e\u8a33<\/a><br \/>\n\u7b2c3\u7ae0 \u4e07\u83ef\u93e1: LLVM IR\u30b3\u30fc\u30c9\u306e\u751f\u6210<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl03.html#driver-changes-and-closing-thoughts\" target=\"_blank\">\u7b2c5\u7bc0 \u30c9\u30e9\u30a4\u30d0\u306e\u5909\u66f4\u3068\u7d50\u8ad6<\/a><\/p>\n<p>\u4eca\u306e\u3068\u3053\u308d\u3001LLVM\u306b\u5bfe\u3059\u308b\u30b3\u30fc\u30c9\u751f\u6210\u306f\u3001\u304d\u308c\u3044\u306aIR\u30b3\u30fc\u30eb\u3092\u898b\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3068\u3044\u3046\u4e8b\u4ee5\u5916\u306f\u3001\u5b9f\u969b\u306b\u306f\u3042\u307e\u308a\u5f79\u7acb\u305f\u306a\u3044\u3002<br \/>\nCodegen\u30e1\u30bd\u30c3\u30c9\u306b\u201dHandleDefinition&#8221;\u3084\u201dHandleExtern&#8221;\u306a\u3069\u306e\u95a2\u6570\u547c\u3073\u51fa\u3057\u3092\u8ffd\u52a0\u3059\u308b\u3068\u3001LLVM IR\u306e\u30c0\u30f3\u30d7\u304c\u898b\u308c\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001LLVM IR\u3092\u7c21\u5358\u306a\u95a2\u6570\u3067\u898b\u308c\u308b\u826f\u3044\u65b9\u6cd5\u3067\u3042\u308b\u3002<br \/>\n\u4f8b\u3048\u3070\u305d\u306e\u51fa\u529b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; 4+5;\r\nRead top-level expression:\r\ndefine double @0() {\r\nentry:\r\n  ret double 9.000000e+00\r\n}<\/pre>\n<p>\u69cb\u6587\u89e3\u6790\u5668\u304c\u3001\u30c8\u30c3\u30d7\u30ec\u30d9\u30eb\u306e\u5f0f\u3092\u3069\u306e\u3088\u3046\u306b\u533f\u540d\u95a2\u6570\u306b\u5909\u63db\u3059\u308b\u304b\u306b\u6ce8\u610f\u3002<br \/>\n\u3053\u308c\u306f\u3001\u6b21\u306e\u7ae0\u306b\u304a\u3044\u3066JIT\u30b5\u30dd\u30fc\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3068\u304d\u306b\u5f79\u7acb\u3064\u3060\u308d\u3046\u3002<br \/>\n\u30b3\u30fc\u30c9\u306f\u3001\u305d\u3063\u304f\u308a\u305d\u306e\u307e\u307e\u7ffb\u8a33\u3055\u308c\u3001IRBuilder\u306b\u3088\u308b\u7c21\u5358\u306a\u5b9a\u6570\u306e\u7573\u307f\u8fbc\u307f\u3092\u9664\u3044\u3066\u6700\u9069\u5316\u304c\u884c\u308f\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u306b\u3082\u6ce8\u610f\u3002<br \/>\n\u6700\u9069\u5316\u6a5f\u80fd\u306f\u6b21\u306e\u7ae0\u3067\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; def foo(a b) a*a + 2*a*b + b*b;\r\nRead function definition:\r\ndefine double @foo(double %a, double %b) {\r\nentry:\r\n  %multmp = fmul double %a, %a\r\n  %multmp1 = fmul double 2.000000e+00, %a\r\n  %multmp2 = fmul double %multmp1, %b\r\n  %addtmp = fadd double %multmp, %multmp2\r\n  %multmp3 = fmul double %b, %b\r\n  %addtmp4 = fadd double %addtmp, %multmp3\r\n  ret double %addtmp4\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u3001\u5e7e\u3064\u304b\u306e\u7c21\u5358\u306a\u8a08\u7b97\u3092\u793a\u3057\u3066\u3044\u308b\u3002<br \/>\n\u547d\u4ee4\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3057\u305fLLVM Builder\u306e\u547c\u3073\u51fa\u3057\u3068\u306e\u8457\u3057\u3044\u985e\u4f3c\u6027\u306b\u6ce8\u76ee\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; def bar(a) foo(a, 4.0) + bar(31337);\r\nRead function definition:\r\ndefine double @bar(double %a) {\r\nentry:\r\n  %calltmp = call double @foo(double %a, double 4.000000e+00)\r\n  %calltmp1 = call double @bar(double 3.133700e+04)\r\n  %addtmp = fadd double %calltmp, %calltmp1\r\n  ret double %addtmp\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u95a2\u6570\u547c\u3073\u51fa\u3057\u3092\u793a\u3057\u3066\u3044\u308b\u3002<br \/>\n\u3053\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3057\u305f\u3068\u3057\u305f\u3089\u3001\u5b9f\u884c\u306b\u9577\u3044\u6642\u9593\u304c\u304b\u304b\u308b\u3067\u3042\u308d\u3046\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\n\u518d\u5e30\u3092\u4fbf\u5229\u306b\u3059\u308b\u305f\u3081\u3001\u3053\u306e\u5148\u306e\u7ae0\u3067\u3001\u6761\u4ef6\u4ed8\u304d\u5236\u5fa1\u30d5\u30ed\u30fc\u3092\u8ffd\u52a0\u3059\u308b\u4e88\u5b9a\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; extern cos(x);\r\nRead extern:\r\ndeclare double @cos(double)\r\n\r\nready&gt; cos(1.234);\r\nRead top-level expression:\r\ndefine double @1() {\r\nentry:\r\n  %calltmp = call double @cos(double 1.234000e+00)\r\n  ret double %calltmp\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u3001libm\u306e&#8221;cos&#8221;\u95a2\u6570\u306e\u305f\u3081\u306eextern\u5ba3\u8a00\u3068\u3001\u305d\u306e\u547c\u3073\u51fa\u3057\u3092\u793a\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">ready&gt; ^D\r\n; ModuleID = 'my cool jit'\r\n\r\ndefine double @0() {\r\nentry:\r\n  %addtmp = fadd double 4.000000e+00, 5.000000e+00\r\n  ret double %addtmp\r\n}\r\n\r\ndefine double @foo(double %a, double %b) {\r\nentry:\r\n  %multmp = fmul double %a, %a\r\n  %multmp1 = fmul double 2.000000e+00, %a\r\n  %multmp2 = fmul double %multmp1, %b\r\n  %addtmp = fadd double %multmp, %multmp2\r\n  %multmp3 = fmul double %b, %b\r\n  %addtmp4 = fadd double %addtmp, %multmp3\r\n  ret double %addtmp4\r\n}\r\n\r\ndefine double @bar(double %a) {\r\nentry:\r\n  %calltmp = call double @foo(double %a, double 4.000000e+00)\r\n  %calltmp1 = call double @bar(double 3.133700e+04)\r\n  %addtmp = fadd double %calltmp, %calltmp1\r\n  ret double %addtmp\r\n}\r\n\r\ndeclare double @cos(double)\r\n\r\ndefine double @1() {\r\nentry:\r\n  %calltmp = call double @cos(double 1.234000e+00)\r\n  ret double %calltmp\r\n}<\/pre>\n<p>\u5165\u529b\u4e2d\u306e\u30c7\u30e2\u3092\u7d42\u4e86\u3059\u308b\u3068\u304d\u3001\u751f\u6210\u3055\u308c\u305f\u30e2\u30b8\u30e5\u30fc\u30eb\u5168\u4f53\u306eIR\u306e\u30c0\u30f3\u30d7\u3092\u51fa\u529b\u3059\u308b\u3002<br \/>\n\u304a\u4e92\u3044\u306b\u53c2\u7167\u3057\u3042\u3063\u3066\u308b\u5168\u3066\u306e\u95a2\u6570\u3092\u542b\u3080\u5168\u4f53\u304c\u898b\u308c\u308b\u306e\u304c\u5206\u304b\u308b\u3068\u601d\u3046\u3002<br \/>\n\u3053\u308c\u3067\u4e07\u83ef\u93e1\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u7b2c3\u7ae0\u306f\u7d42\u308f\u308a\u3067\u3042\u308b\u3002<br \/>\n\u6b21\u306f\u3001\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001JIT\u30b3\u30fc\u30c9\u751f\u6210\u3068\u6700\u9069\u5316\u30b5\u30dd\u30fc\u30c8\u306e\u8ffd\u52a0\u306b\u3064\u3044\u3066\u8aac\u660e\u3059\u308b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[466,467],"class_list":["post-2945","post","type-post","status-publish","format-standard","hentry","category-tech","tag-kaleidoscope","tag-llvm"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=2945"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2945\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=2945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=2945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=2945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}