{"id":2989,"date":"2013-09-01T15:08:09","date_gmt":"2013-09-01T06:08:09","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=2989"},"modified":"2013-09-01T15:08:09","modified_gmt":"2013-09-01T06:08:09","slug":"5-3-5-for%e3%83%ab%e3%83%bc%e3%83%97%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e3%82%b3%e3%83%bc%e3%83%89%e7%94%9f%e6%88%90","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/2989","title":{"rendered":"5.3.5. for\u30eb\u30fc\u30d7\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210"},"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\u7b2c5\u7ae0 \u4e07\u83ef\u93e1: \u8a00\u8a9e\u306e\u62e1\u5f35: \u5236\u5fa1\u30d5\u30ed\u30fc<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl05.html#code-generation-for-the-for-loop\" target=\"_blank\">\u7b2c3.5\u7bc0 for\u30eb\u30fc\u30d7\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210<\/a><\/p>\n<p>\u30b3\u30fc\u30c9\u751f\u6210\u306e\u6700\u521d\u306e\u90e8\u5206\u306f\u3001\u3068\u3066\u3082\u7c21\u5358\u3067\u3042\u308b\u3002<br \/>\n\u30eb\u30fc\u30d7\u5909\u6570\u306e\u521d\u671f\u5024\u305f\u3081\u306e\u958b\u59cb\u5f0f\u3092\u51fa\u529b\u3059\u308b\u3060\u3051\u3067\u3042\u308b\u3002\uff08we just output the start expression for the loop value:\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">Value *ForExprAST::Codegen() {\r\n  \/\/ \u30b9\u30b3\u30fc\u30d7\u5185\u306e\u5909\u6570\u306a\u3057\u3067\u3001\u307e\u305a\u958b\u59cb\u30b3\u30fc\u30c9\u3092\u51fa\u529b\u3059\u308b\u3002\r\n  Value *StartVal = Start-&gt;Codegen();\r\n  if (StartVal == 0) return 0;<\/pre>\n<p>\u3068\u308a\u3042\u3048\u305a\u3053\u308c\u306f\u7f6e\u3044\u3068\u3044\u3066\u3001\u6b21\u306f\u30eb\u30fc\u30d7\u306e\u672c\u6587\u3092\u958b\u59cb\u3059\u308b\u305f\u3081LLVM\u306e\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u6e96\u5099\u3059\u308b\u3002<br \/>\n<a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2987\" title=\"5.3.4. for\u30eb\u30fc\u30d7\u306e\u305f\u3081\u306eLLVM IR\">\u7b2c3.4\u7bc0\u306e\u4f8b<\/a>\u3060\u3068\u3001\u30eb\u30fc\u30d7\u672c\u6587\u5168\u4f53\u306f\u3072\u3068\u3064\u306e\u30d6\u30ed\u30c3\u30af\u3067\u3042\u308b\u304c\u3001\u672c\u6587\u306e\u30b3\u30fc\u30c9\u81ea\u4f53\u306f\u8907\u6570\u306e\u30d6\u30ed\u30c3\u30af\u304b\u3089\u69cb\u6210\u3055\u308c\u3046\u308b\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\n\uff08\u4f8b\u3048\u3070\u3001\u672c\u6587\u304c\u3055\u3089\u306bif\/then\/else\u3084for\/in\u5f0f\u3092\u542b\u3080\u5834\u5408\u3002\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30eb\u30fc\u30d7\u306e\u30d8\u30c3\u30c0\u306e\u305f\u3081\u306b\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b\u3002\r\n\/\/ \u73fe\u5728\u306e\u30d6\u30ed\u30c3\u30af\u306e\u5f8c\u306b\u633f\u5165\u3059\u308b\u3002\r\nFunction *TheFunction = Builder.GetInsertBlock()-&gt;getParent();\r\nBasicBlock *PreheaderBB = Builder.GetInsertBlock();\r\nBasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), &quot;loop&quot;, TheFunction);\r\n\r\n\/\/ \u73fe\u5728\u306e\u30d6\u30ed\u30c3\u30af\u304b\u3089LoopBB\u3078\u306e\u660e\u78ba\u306a\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\uff08br\u547d\u4ee4\uff09\u3092\u633f\u5165\u3059\u308b\u3002 \r\nBuilder.CreateBr(LoopBB);<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001if\/then\/else\u306e\u3068\u304d\u898b\u305f\u3082\u306e\u3068\u4f3c\u3066\u3044\u308b\u3002<br \/>\nphi\u30ce\u30fc\u30c9\u3092\u751f\u6210\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u30eb\u30fc\u30d7\u306e\u4e2d\u3078\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3059\u308b\u30d6\u30ed\u30c3\u30af\u3092\u899a\u3048\u3066\u304a\u304f\u3002<br \/>\n\u3053\u308c\u304c\u7d42\u308f\u3063\u305f\u3089\u3001\u30eb\u30fc\u30d7\u3092\u958b\u59cb\u3059\u308b\u5b9f\u969b\u306e\u30d6\u30ed\u30c3\u30af\u3068\u30012\u3064\u306e\u30d6\u30ed\u30c3\u30af\u306e\u9593\u3067\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3059\u308b\u305f\u3081\u306e\u7121\u6761\u4ef6\u5206\u5c90\uff08unconditional branch\uff09\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3068\u3044\u3046\u306e\u306f\u3001\u3042\u308b\u30d6\u30ed\u30c3\u30af\u304b\u3089\u305d\u306e\u6b21\u306e\u30d6\u30ed\u30c3\u30af\u3078\u30b8\u30e3\u30f3\u30d7\u306a\u3057\u306b\u5358\u306b\u51e6\u7406\u3092\u79fb\u3059\u4e8b\u3092\u610f\u5473\u3057\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u308b\u3002<br \/>\n\u4ee5\u524d\u3082\u8aac\u660e\u3057\u305f\u3068\u304a\u308a\u3001LLVM IR\u3067\u306f\u5358\u306a\u308b\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3067\u3042\u3063\u3066\u3082\u30d6\u30ed\u30c3\u30af\u306e\u6700\u5f8c\u306bbr\u547d\u4ee4\u3092\u7f6e\u304f\u5fc5\u8981\u304c\u3042\u308b\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ LoopBB\u306e\u633f\u5165\u3092\u958b\u59cb\u3002\r\nBuilder.SetInsertPoint(LoopBB);\r\n\r\n\/\/ Start\u306e\u305f\u3081\u306e\u30a8\u30f3\u30c8\u30ea\u306b\u3088\u3063\u3066phi\u30ce\u30fc\u30c9\u3092\u958b\u59cb\u3059\u308b\u3002\r\nPHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());\r\nVariable-&gt;addIncoming(StartVal, PreheaderBB);<\/pre>\n<p>\u3053\u308c\u3067\u3001\u30eb\u30fc\u30d7\u306e\u305f\u3081\u306e\u30d7\u30ea\u30d8\u30c3\u30c0\uff08preheader\uff09\u304c\u6e96\u5099\u3067\u304d\u305f\u306e\u3067\u3001\u30eb\u30fc\u30d7\u672c\u4f53\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306b\u3068\u308a\u304b\u304b\u308b\u3002<br \/>\n\u3053\u308c\u306b\u306f\u307e\u305a\u3001\u633f\u5165\u70b9\u3092\u79fb\u52d5\u3057\u3001\u30eb\u30fc\u30d7\u304c\u4f7f\u7528\u3059\u308b\u5909\u6570\u306e\u305f\u3081\u306ephi\u30ce\u30fc\u30c9\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u6211\u3005\u306f\u521d\u671f\u5024\uff08\u3068\u306a\u308b\u5f0f\uff09\u3092\u77e5\u3063\u3066\u308b\u306e\u3067\u3001\u305d\u308c\u3092phi\u30ce\u30fc\u30c9\u306b\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\n\u6700\u7d42\u7684\u306bphi\u306f\u6b21\u306e\u30eb\u30fc\u30d7\uff08backedge\uff09\u306e\u305f\u3081\u306e2\u756a\u76ee\u306e\u5024\u3092\u5f97\u308b\u3060\u308d\u3046\u304c\u3001\u3057\u304b\u3057\u307e\u3060\u305d\u308c\u306f\u6e96\u5099\u3067\u304d\u306a\u3044\u4e8b\u306b\u6ce8\u610f\u3002\uff08\u305d\u308c\u306f\u5b58\u5728\u3057\u306a\u3044\u306e\u3067\u3002\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u3001\u305d\u306e\u5909\u6570\u306fphi\u30ce\u30fc\u30c9\u3068\u7b49\u3057\u3044\u3068\u5b9a\u7fa9\u3055\u308c\u308b\u3002\r\n\/\/ \u305d\u308c\u304c\u65e2\u5b58\u306e\u5909\u6570\u3092\u4e0a\u66f8\u304d\u3057\u3066\u3057\u307e\u3063\u305f\u3089\u3001\u305d\u308c\u3092\u30ea\u30b9\u30c8\u30a2\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u3067\u3001\u3053\u3053\u3067\u4fdd\u5b58\u3059\u308b\u3002\r\nValue *OldVal = NamedValues&#x5B;VarName];\r\nNamedValues&#x5B;VarName] = Variable;\r\n\r\n\/\/ \u30eb\u30fc\u30d7\u306e\u672c\u4f53\u3092\u751f\u6210\u3059\u308b\u3002\u3053\u308c\u3084\u4ed6\u306e\u5f0f\u306f\u3001\u73fe\u5728\u306e\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u5909\u66f4\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002\r\n\/\/ \u672c\u6587\u3067\u8a08\u7b97\u3055\u308c\u305f\u7d50\u679c\u306f\u7121\u8996\u3059\u308b\u304c\u3001\u30a8\u30e9\u30fc\u306f\u9003\u3055\u306a\u3044\u3068\u3044\u3046\u4e8b\u306b\u6ce8\u610f\u3002\r\nif (Body-&gt;Codegen() == 0)\r\n  return 0;<\/pre>\n<p>\u3053\u306e\u90e8\u5206\u306e\u30b3\u30fc\u30c9\u306f\u3088\u308a\u9762\u767d\u3044\u3002<br \/>\nfor\u30eb\u30fc\u30d7\u306f\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u65b0\u3057\u3044\u5909\u6570\u3092\u53d6\u308a\u8fbc\u307e\u305b\u308b\u3002<br \/>\n\u3064\u307e\u308a\u3053\u3053\u306b\u6765\u3066\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u95a2\u6570\u306e\u5f15\u6570\u306e\u307f\u306a\u3089\u305a\u30eb\u30fc\u30d7\u5909\u6570\u3082\u542b\u307e\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u3053\u308c\u3092\u51e6\u7406\u3059\u308b\u306b\u306f\u3001\u30eb\u30fc\u30d7\u306e\u672c\u4f53\u306e\u30b3\u30fc\u30c9\u751f\u6210\u3092\u3059\u308b\u524d\u306b\u3001\u30eb\u30fc\u30d7\u5909\u6570\u3092\u305d\u306e\u540d\u524d\u3067\u73fe\u5728\u306e\u5024\u3068\u3057\u3066\u8ffd\u52a0\u3059\u308b\u3002<br \/>\n\u5916\u306e\u30b9\u30b3\u30fc\u30d7\u306b\u540c\u3058\u540d\u524d\u306e\u5909\u6570\u304c\u3042\u3063\u3066\u3082\u3088\u3044\u3068\u3044\u3046\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\n\u3053\u308c\u3092\u30a8\u30e9\u30fc\u3068\u3059\u308b\u3053\u3068\u306f\u7c21\u5358\uff08\u3059\u3067\u306bVarName\u306e\u30a8\u30f3\u30c8\u30ea\u304c\u3042\u308b\u304b\u78ba\u8a8d\u3057\u3066\u3001\u30a8\u30e9\u30fc\u3092\u751f\u6210\u3057null\u3092\u8fd4\u3059\u3060\u3051\u3067\u3042\u308b\uff09\u3060\u304c\u3001\u6211\u3005\u306f\u5909\u6570\u3092\u8986\u3044\u96a0\u3059\u3053\u3068\u3092\u8a31\u53ef\u3059\u308b\u3088\u3046\u306b\u3057\u305f\u3002<br \/>\n\u3053\u308c\u3092\u6b63\u3057\u304f\u51e6\u7406\u3059\u308b\u305f\u3081\u306b\u3001\u6f5c\u5728\u7684\u306b\u8986\u3044\u96a0\u3055\u308c\u308b\u5024\u3092OldVal\u3068\u3057\u3066\u4fdd\u6301\u3057\u3066\u304a\u304f\u3002\uff08\u3082\u3057\u8986\u3044\u96a0\u3055\u308c\u308b\u5909\u6570\u304c\u7121\u3051\u308c\u3070\u305d\u308c\u306f\u5358\u306bnull\u306b\u306a\u308b\u3002\uff09<\/p>\n<p>\u30eb\u30fc\u30d7\u5909\u6570\u304c\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f\u3089\u3001\u672c\u6587\u306eCodegen\u30e1\u30bd\u30c3\u30c9\u3092\u518d\u5e30\u7684\u306b\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u3053\u308c\u3067\u3001\u672c\u6587\u3067\u30eb\u30fc\u30d7\u5909\u6570\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3002<br \/>\n\u30eb\u30fc\u30d7\u5909\u6570\u306b\u5bfe\u3059\u308b\u3069\u306e\u3088\u3046\u306a\u53c2\u7167\u304c\u3042\u3063\u3066\u3082\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u9069\u5207\u306b\u898b\u3064\u3051\u3089\u308c\u308b\u3060\u308d\u3046\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30b9\u30c6\u30c3\u30d7\u5024\u306e\u751f\u6210\u3002\r\nValue *StepVal;\r\nif (Step) {\r\n  StepVal = Step-&gt;Codegen();\r\n  if (StepVal == 0) return 0;\r\n} else {\r\n  \/\/ \u6307\u5b9a\u3055\u308c\u306a\u3051\u308c\u30701.0\u3092\u4f7f\u3046\u3002\r\n  StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));\r\n}\r\n\r\nValue *NextVar = Builder.CreateFAdd(Variable, StepVal, &quot;nextvar&quot;);<\/pre>\n<p>\u3053\u308c\u3067\u672c\u6587\u306e\u30b3\u30fc\u30c9\u304c\u751f\u6210\u3055\u308c\u305f\u306e\u3067\u3001\u30b9\u30c6\u30c3\u30d7\u5024\u3001\u3082\u3057\u304f\u306f\u6307\u5b9a\u304c\u7121\u3051\u308c\u30701.0\u3092\u52a0\u7b97\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u6b21\u306e\u30eb\u30fc\u30d7\u5909\u6570\u306e\u5024\u3092\u8a08\u7b97\u3059\u308b\u3002<br \/>\nNextVar\u306f\u3001\u30eb\u30fc\u30d7\u306e\u6b21\u306e\u53cd\u5fa9\u306b\u304a\u3051\u308b\u30eb\u30fc\u30d7\u5909\u6570\u306e\u5024\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u7d42\u4e86\u6761\u4ef6\u3092\u8a08\u7b97\u3059\u308b\u3002\r\nValue *EndCond = End-&gt;Codegen();\r\nif (EndCond == 0) return EndCond;\r\n\r\n\/\/ 0.0\u3068\u6bd4\u8f03\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u6761\u4ef6\u3092\u771f\u507d\u5024\u306b\u5909\u63db\u3059\u308b\u3002\r\nEndCond = Builder.CreateFCmpONE(EndCond,\r\n                            ConstantFP::get(getGlobalContext(), APFloat(0.0)),\r\n                                &quot;loopcond&quot;);<\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3055\u305b\u308b\u3079\u304d\u304b\u3069\u3046\u304b\u3092\u6c7a\u5b9a\u3059\u308b\u305f\u3081\u306b\u3001\u30eb\u30fc\u30d7\u306e\u7d42\u4e86\u6761\u4ef6\u3092\u8a55\u4fa1\u3059\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001if\/then\/else\u306b\u304a\u3051\u308b\u6761\u4ef6\u306e\u8a55\u4fa1\u3068\u9177\u4f3c\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30eb\u30fc\u30d7\u5f8c\u306e\u30d6\u30ed\u30c3\u30af\u3092\u751f\u6210\u3057\u633f\u5165\u3059\u308b\u3002\r\nBasicBlock *LoopEndBB = Builder.GetInsertBlock();\r\nBasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), &quot;afterloop&quot;, TheFunction);\r\n\r\n\/\/ LoopEndBB\u306e\u672b\u5c3e\u3078\u3001\u6761\u4ef6\u5206\u5c90\u3092\u633f\u5165\u3059\u308b\u3002\r\nBuilder.CreateCondBr(EndCond, LoopBB, AfterBB);\r\n\r\n\/\/ \u3053\u308c\u4ee5\u964d\u306e\u30b3\u30fc\u30c9\u306f\u3001AfterBB\u306e\u5f8c\u306b\u633f\u5165\u3055\u308c\u308b\u3002\r\nBuilder.SetInsertPoint(AfterBB);<\/pre>\n<p>\u3042\u3068\u306f\u30eb\u30fc\u30d7\u306e\u672c\u6587\u306e\u30b3\u30fc\u30c9\u306e\u5b8c\u6210\u306b\u3088\u3063\u3066\u3001\u5236\u5fa1\u30d5\u30ed\u30fc\u3092\u7de0\u3081\u304f\u304f\u308b\u5fc5\u8981\u304c\u3042\u308b\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\n\u3053\u306e\u30b3\u30fc\u30c9\u306fend\u30d6\u30ed\u30c3\u30af\u3092\u8a18\u61b6\u3057\uff08phi\u30ce\u30fc\u30c9\u306e\u305f\u3081\u306b\uff09\u3001\u305d\u3057\u3066\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3059\u308b\u305f\u3081\u306eafterloop\u30d6\u30ed\u30c3\u30af\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u7d42\u4e86\u6761\u4ef6\u306e\u5024\u3092\u5143\u306b\u3001\u30eb\u30fc\u30d7\u3092\u307e\u3060\u7d9a\u3051\u308b\u304b\u3001\u30eb\u30fc\u30d7\u3092\u7d42\u308f\u3089\u305b\u308b\u304b\u3092\u9078\u629e\u3059\u308b\u305f\u3081\u306e\u6761\u4ef6\u5206\u5c90\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u3053\u306e\u5f8c\u306e\u30b3\u30fc\u30c9\u306f\u3001afterloop\u30d6\u30ed\u30c3\u30af\u306e\u5f8c\u306b\u51fa\u529b\u3055\u305b\u305f\u3044\u306e\u3067\u3001\u633f\u5165\u70b9\u3092AfterBB\u306b\u30bb\u30c3\u30c8\u3059\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u5f8c\u65b9\u306e\u305f\u3081\u3001phi\u30ce\u30fc\u30c9\u3078\u65b0\u3057\u3044\u30a8\u30f3\u30c8\u30ea\u3092\u8ffd\u52a0\u3059\u308b\u3002\r\n  Variable-&gt;addIncoming(NextVar, LoopEndBB);\r\n\r\n  \/\/ \u8986\u3044\u96a0\u3055\u308c\u3066\u3044\u305f\u5909\u6570\u3092\u5fa9\u5143\u3059\u308b\u3002\r\n  if (OldVal)\r\n    NamedValues&#x5B;VarName] = OldVal;\r\n  else\r\n    NamedValues.erase(VarName);\r\n\r\n  \/\/ for\u5f0f\u306f\u5e38\u306b0.0\u3092\u8fd4\u3059\u3002\r\n  return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));\r\n}<\/pre>\n<p>\u6700\u5f8c\u306e\u30b3\u30fc\u30c9\u306f\u3001\u3044\u304f\u3064\u304b\u306e\u5f8c\u7247\u4ed8\u3051\u3092\u51e6\u7406\u3059\u308b\u3002<br \/>\n\u3053\u3053\u3067\u306fNextVar\u5024\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30eb\u30fc\u30d7\u306ephi\u30ce\u30fc\u30c9\u3078\u6b21\u306e\u5024\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<br \/>\n\u305d\u306e\u5f8c\u3001for\u30eb\u30fc\u30d7\u306e\u5f8c\u306f\u30b9\u30b3\u30fc\u30d7\u5916\u3068\u306a\u308b\u306e\u3067\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30eb\u30fc\u30d7\u5909\u6570\u3092\u53d6\u308a\u9664\u304f\u3002<br \/>\n\u6700\u5f8c\u306b\u3001for\u30eb\u30fc\u30d7\u306f\u5e38\u306b0.0\u3092\u8fd4\u3059\u3088\u3046\u30b3\u30fc\u30c9\u751f\u6210\u3059\u308b\u306e\u3067\u3001\u305d\u308c\u304cForExprAST::Codegen\u306e\u623b\u308a\u5024\u3068\u306a\u308b\u3002<\/p>\n<p>\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u304a\u3051\u308b&#8221;\u4e07\u83ef\u93e1\u3078\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u306e\u8ffd\u52a0&#8221;\u306e\u7ae0\u3092\u5b8c\u4e86\u3059\u308b\u3002<br \/>\n\u3053\u306e\u7ae0\u3067\u306f\u30012\u3064\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u69cb\u9020\u3092\u8ffd\u52a0\u3057\u305f\u3002<br \/>\n\u305d\u3057\u3066\u3001\u305d\u308c\u3089\u3092\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u5b9f\u88c5\u8005\u306b\u5bfe\u3057\u3066\u3001\u7279\u306b\u77e5\u3063\u3066\u3044\u3066\u6b32\u3057\u3044LLLVM\u306e\u6027\u8cea\u306b\u3064\u3044\u3066\u8208\u5473\u3092\u8d77\u3053\u3055\u305b\u308b\u305f\u3081\u306b\u4f7f\u7528\u3057\u305f\u3002<br \/>\n\u6211\u3005\u306e\u30b5\u30fc\u30ac\u306e\u6b21\u306e\u7ae0\u3067\u306f\u3001\u3061\u3087\u3063\u3068\u9038\u8131\u3057\u3066\u3001\u6211\u3005\u306e\u7c97\u672b\u3067\u7d14\u771f\u306a\u8a00\u8a9e\u306b\u30e6\u30fc\u30b6\u30fc\u5b9a\u7fa9\u6f14\u7b97\u5b50\u3092\u8ffd\u52a0\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\u7b2c5\u7ae0 \u4e07\u83ef\u93e1: \u8a00\u8a9e\u306e\u62e1\u5f35: \u5236\u5fa1\u30d5\u30ed\u30fc<br \/>\n<a href=\"http:\/\/llvm.org\/docs\/tutorial\/LangImpl05.html#code-generation-for-the-for-loop\" target=\"_blank\">\u7b2c3.5\u7bc0 for\u30eb\u30fc\u30d7\u306e\u305f\u3081\u306e\u30b3\u30fc\u30c9\u751f\u6210<\/a><\/p>\n<p>\u30b3\u30fc\u30c9\u751f\u6210\u306e\u6700\u521d\u306e\u90e8\u5206\u306f\u3001\u3068\u3066\u3082\u7c21\u5358\u3067\u3042\u308b\u3002<br \/>\n\u30eb\u30fc\u30d7\u5909\u6570\u306e\u521d\u671f\u5024\u305f\u3081\u306e\u958b\u59cb\u5f0f\u3092\u51fa\u529b\u3059\u308b\u3060\u3051\u3067\u3042\u308b\u3002\uff08we just output the start expression for the loop value:\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">Value *ForExprAST::Codegen() {\r\n  \/\/ \u30b9\u30b3\u30fc\u30d7\u5185\u306e\u5909\u6570\u306a\u3057\u3067\u3001\u307e\u305a\u958b\u59cb\u30b3\u30fc\u30c9\u3092\u51fa\u529b\u3059\u308b\u3002\r\n  Value *StartVal = Start-&gt;Codegen();\r\n  if (StartVal == 0) return 0;<\/pre>\n<p>\u3068\u308a\u3042\u3048\u305a\u3053\u308c\u306f\u7f6e\u3044\u3068\u3044\u3066\u3001\u6b21\u306f\u30eb\u30fc\u30d7\u306e\u672c\u6587\u3092\u958b\u59cb\u3059\u308b\u305f\u3081LLVM\u306e\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u6e96\u5099\u3059\u308b\u3002<br \/>\n<a href=\"https:\/\/peta.okechan.net\/blog\/archives\/2987\" title=\"5.3.4. for\u30eb\u30fc\u30d7\u306e\u305f\u3081\u306eLLVM IR\">\u7b2c3.4\u7bc0\u306e\u4f8b<\/a>\u3060\u3068\u3001\u30eb\u30fc\u30d7\u672c\u6587\u5168\u4f53\u306f\u3072\u3068\u3064\u306e\u30d6\u30ed\u30c3\u30af\u3067\u3042\u308b\u304c\u3001\u672c\u6587\u306e\u30b3\u30fc\u30c9\u81ea\u4f53\u306f\u8907\u6570\u306e\u30d6\u30ed\u30c3\u30af\u304b\u3089\u69cb\u6210\u3055\u308c\u3046\u308b\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\n\uff08\u4f8b\u3048\u3070\u3001\u672c\u6587\u304c\u3055\u3089\u306bif\/then\/else\u3084for\/in\u5f0f\u3092\u542b\u3080\u5834\u5408\u3002\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30eb\u30fc\u30d7\u306e\u30d8\u30c3\u30c0\u306e\u305f\u3081\u306b\u65b0\u3057\u3044\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u4f5c\u6210\u3059\u308b\u3002\r\n\/\/ \u73fe\u5728\u306e\u30d6\u30ed\u30c3\u30af\u306e\u5f8c\u306b\u633f\u5165\u3059\u308b\u3002\r\nFunction *TheFunction = Builder.GetInsertBlock()-&gt;getParent();\r\nBasicBlock *PreheaderBB = Builder.GetInsertBlock();\r\nBasicBlock *LoopBB = BasicBlock::Create(getGlobalContext(), &quot;loop&quot;, TheFunction);\r\n\r\n\/\/ \u73fe\u5728\u306e\u30d6\u30ed\u30c3\u30af\u304b\u3089LoopBB\u3078\u306e\u660e\u78ba\u306a\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\uff08br\u547d\u4ee4\uff09\u3092\u633f\u5165\u3059\u308b\u3002 \r\nBuilder.CreateBr(LoopBB);<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001if\/then\/else\u306e\u3068\u304d\u898b\u305f\u3082\u306e\u3068\u4f3c\u3066\u3044\u308b\u3002<br \/>\nphi\u30ce\u30fc\u30c9\u3092\u751f\u6210\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3001\u30eb\u30fc\u30d7\u306e\u4e2d\u3078\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3059\u308b\u30d6\u30ed\u30c3\u30af\u3092\u899a\u3048\u3066\u304a\u304f\u3002<br \/>\n\u3053\u308c\u304c\u7d42\u308f\u3063\u305f\u3089\u3001\u30eb\u30fc\u30d7\u3092\u958b\u59cb\u3059\u308b\u5b9f\u969b\u306e\u30d6\u30ed\u30c3\u30af\u3068\u30012\u3064\u306e\u30d6\u30ed\u30c3\u30af\u306e\u9593\u3067\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3059\u308b\u305f\u3081\u306e\u7121\u6761\u4ef6\u5206\u5c90\uff08unconditional branch\uff09\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\n<em>\u8a33\u6ce8: \u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3068\u3044\u3046\u306e\u306f\u3001\u3042\u308b\u30d6\u30ed\u30c3\u30af\u304b\u3089\u305d\u306e\u6b21\u306e\u30d6\u30ed\u30c3\u30af\u3078\u30b8\u30e3\u30f3\u30d7\u306a\u3057\u306b\u5358\u306b\u51e6\u7406\u3092\u79fb\u3059\u4e8b\u3092\u610f\u5473\u3057\u3066\u3044\u308b\u3068\u601d\u308f\u308c\u308b\u3002<br \/>\n\u4ee5\u524d\u3082\u8aac\u660e\u3057\u305f\u3068\u304a\u308a\u3001LLVM IR\u3067\u306f\u5358\u306a\u308b\u30d5\u30a9\u30fc\u30eb\u30b9\u30eb\u30fc\u3067\u3042\u3063\u3066\u3082\u30d6\u30ed\u30c3\u30af\u306e\u6700\u5f8c\u306bbr\u547d\u4ee4\u3092\u7f6e\u304f\u5fc5\u8981\u304c\u3042\u308b\u3002<\/em><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ LoopBB\u306e\u633f\u5165\u3092\u958b\u59cb\u3002\r\nBuilder.SetInsertPoint(LoopBB);\r\n\r\n\/\/ Start\u306e\u305f\u3081\u306e\u30a8\u30f3\u30c8\u30ea\u306b\u3088\u3063\u3066phi\u30ce\u30fc\u30c9\u3092\u958b\u59cb\u3059\u308b\u3002\r\nPHINode *Variable = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), 2, VarName.c_str());\r\nVariable-&gt;addIncoming(StartVal, PreheaderBB);<\/pre>\n<p>\u3053\u308c\u3067\u3001\u30eb\u30fc\u30d7\u306e\u305f\u3081\u306e\u30d7\u30ea\u30d8\u30c3\u30c0\uff08preheader\uff09\u304c\u6e96\u5099\u3067\u304d\u305f\u306e\u3067\u3001\u30eb\u30fc\u30d7\u672c\u4f53\u306e\u30b3\u30fc\u30c9\u751f\u6210\u306b\u3068\u308a\u304b\u304b\u308b\u3002<br \/>\n\u3053\u308c\u306b\u306f\u307e\u305a\u3001\u633f\u5165\u70b9\u3092\u79fb\u52d5\u3057\u3001\u30eb\u30fc\u30d7\u304c\u4f7f\u7528\u3059\u308b\u5909\u6570\u306e\u305f\u3081\u306ephi\u30ce\u30fc\u30c9\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u6211\u3005\u306f\u521d\u671f\u5024\uff08\u3068\u306a\u308b\u5f0f\uff09\u3092\u77e5\u3063\u3066\u308b\u306e\u3067\u3001\u305d\u308c\u3092phi\u30ce\u30fc\u30c9\u306b\u8ffd\u52a0\u3059\u308b\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\n\u6700\u7d42\u7684\u306bphi\u306f\u6b21\u306e\u30eb\u30fc\u30d7\uff08backedge\uff09\u306e\u305f\u3081\u306e2\u756a\u76ee\u306e\u5024\u3092\u5f97\u308b\u3060\u308d\u3046\u304c\u3001\u3057\u304b\u3057\u307e\u3060\u305d\u308c\u306f\u6e96\u5099\u3067\u304d\u306a\u3044\u4e8b\u306b\u6ce8\u610f\u3002\uff08\u305d\u308c\u306f\u5b58\u5728\u3057\u306a\u3044\u306e\u3067\u3002\uff09<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30eb\u30fc\u30d7\u306e\u4e2d\u3067\u3001\u305d\u306e\u5909\u6570\u306fphi\u30ce\u30fc\u30c9\u3068\u7b49\u3057\u3044\u3068\u5b9a\u7fa9\u3055\u308c\u308b\u3002\r\n\/\/ \u305d\u308c\u304c\u65e2\u5b58\u306e\u5909\u6570\u3092\u4e0a\u66f8\u304d\u3057\u3066\u3057\u307e\u3063\u305f\u3089\u3001\u305d\u308c\u3092\u30ea\u30b9\u30c8\u30a2\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u3067\u3001\u3053\u3053\u3067\u4fdd\u5b58\u3059\u308b\u3002\r\nValue *OldVal = NamedValues&#x5B;VarName];\r\nNamedValues&#x5B;VarName] = Variable;\r\n\r\n\/\/ \u30eb\u30fc\u30d7\u306e\u672c\u4f53\u3092\u751f\u6210\u3059\u308b\u3002\u3053\u308c\u3084\u4ed6\u306e\u5f0f\u306f\u3001\u73fe\u5728\u306e\u57fa\u672c\u30d6\u30ed\u30c3\u30af\u3092\u5909\u66f4\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002\r\n\/\/ \u672c\u6587\u3067\u8a08\u7b97\u3055\u308c\u305f\u7d50\u679c\u306f\u7121\u8996\u3059\u308b\u304c\u3001\u30a8\u30e9\u30fc\u306f\u9003\u3055\u306a\u3044\u3068\u3044\u3046\u4e8b\u306b\u6ce8\u610f\u3002\r\nif (Body-&gt;Codegen() == 0)\r\n  return 0;<\/pre>\n<p>\u3053\u306e\u90e8\u5206\u306e\u30b3\u30fc\u30c9\u306f\u3088\u308a\u9762\u767d\u3044\u3002<br \/>\nfor\u30eb\u30fc\u30d7\u306f\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u65b0\u3057\u3044\u5909\u6570\u3092\u53d6\u308a\u8fbc\u307e\u305b\u308b\u3002<br \/>\n\u3064\u307e\u308a\u3053\u3053\u306b\u6765\u3066\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u306f\u95a2\u6570\u306e\u5f15\u6570\u306e\u307f\u306a\u3089\u305a\u30eb\u30fc\u30d7\u5909\u6570\u3082\u542b\u307e\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u3002<br \/>\n\u3053\u308c\u3092\u51e6\u7406\u3059\u308b\u306b\u306f\u3001\u30eb\u30fc\u30d7\u306e\u672c\u4f53\u306e\u30b3\u30fc\u30c9\u751f\u6210\u3092\u3059\u308b\u524d\u306b\u3001\u30eb\u30fc\u30d7\u5909\u6570\u3092\u305d\u306e\u540d\u524d\u3067\u73fe\u5728\u306e\u5024\u3068\u3057\u3066\u8ffd\u52a0\u3059\u308b\u3002<br \/>\n\u5916\u306e\u30b9\u30b3\u30fc\u30d7\u306b\u540c\u3058\u540d\u524d\u306e\u5909\u6570\u304c\u3042\u3063\u3066\u3082\u3088\u3044\u3068\u3044\u3046\u4e8b\u306b\u6ce8\u610f\u3002<br \/>\n\u3053\u308c\u3092\u30a8\u30e9\u30fc\u3068\u3059\u308b\u3053\u3068\u306f\u7c21\u5358\uff08\u3059\u3067\u306bVarName\u306e\u30a8\u30f3\u30c8\u30ea\u304c\u3042\u308b\u304b\u78ba\u8a8d\u3057\u3066\u3001\u30a8\u30e9\u30fc\u3092\u751f\u6210\u3057null\u3092\u8fd4\u3059\u3060\u3051\u3067\u3042\u308b\uff09\u3060\u304c\u3001\u6211\u3005\u306f\u5909\u6570\u3092\u8986\u3044\u96a0\u3059\u3053\u3068\u3092\u8a31\u53ef\u3059\u308b\u3088\u3046\u306b\u3057\u305f\u3002<br \/>\n\u3053\u308c\u3092\u6b63\u3057\u304f\u51e6\u7406\u3059\u308b\u305f\u3081\u306b\u3001\u6f5c\u5728\u7684\u306b\u8986\u3044\u96a0\u3055\u308c\u308b\u5024\u3092OldVal\u3068\u3057\u3066\u4fdd\u6301\u3057\u3066\u304a\u304f\u3002\uff08\u3082\u3057\u8986\u3044\u96a0\u3055\u308c\u308b\u5909\u6570\u304c\u7121\u3051\u308c\u3070\u305d\u308c\u306f\u5358\u306bnull\u306b\u306a\u308b\u3002\uff09<\/p>\n<p>\u30eb\u30fc\u30d7\u5909\u6570\u304c\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u306b\u30bb\u30c3\u30c8\u3055\u308c\u305f\u3089\u3001\u672c\u6587\u306eCodegen\u30e1\u30bd\u30c3\u30c9\u3092\u518d\u5e30\u7684\u306b\u547c\u3073\u51fa\u3059\u3002<br \/>\n\u3053\u308c\u3067\u3001\u672c\u6587\u3067\u30eb\u30fc\u30d7\u5909\u6570\u3092\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3002<br \/>\n\u30eb\u30fc\u30d7\u5909\u6570\u306b\u5bfe\u3059\u308b\u3069\u306e\u3088\u3046\u306a\u53c2\u7167\u304c\u3042\u3063\u3066\u3082\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u9069\u5207\u306b\u898b\u3064\u3051\u3089\u308c\u308b\u3060\u308d\u3046\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30b9\u30c6\u30c3\u30d7\u5024\u306e\u751f\u6210\u3002\r\nValue *StepVal;\r\nif (Step) {\r\n  StepVal = Step-&gt;Codegen();\r\n  if (StepVal == 0) return 0;\r\n} else {\r\n  \/\/ \u6307\u5b9a\u3055\u308c\u306a\u3051\u308c\u30701.0\u3092\u4f7f\u3046\u3002\r\n  StepVal = ConstantFP::get(getGlobalContext(), APFloat(1.0));\r\n}\r\n\r\nValue *NextVar = Builder.CreateFAdd(Variable, StepVal, &quot;nextvar&quot;);<\/pre>\n<p>\u3053\u308c\u3067\u672c\u6587\u306e\u30b3\u30fc\u30c9\u304c\u751f\u6210\u3055\u308c\u305f\u306e\u3067\u3001\u30b9\u30c6\u30c3\u30d7\u5024\u3001\u3082\u3057\u304f\u306f\u6307\u5b9a\u304c\u7121\u3051\u308c\u30701.0\u3092\u52a0\u7b97\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u6b21\u306e\u30eb\u30fc\u30d7\u5909\u6570\u306e\u5024\u3092\u8a08\u7b97\u3059\u308b\u3002<br \/>\nNextVar\u306f\u3001\u30eb\u30fc\u30d7\u306e\u6b21\u306e\u53cd\u5fa9\u306b\u304a\u3051\u308b\u30eb\u30fc\u30d7\u5909\u6570\u306e\u5024\u3067\u3042\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u7d42\u4e86\u6761\u4ef6\u3092\u8a08\u7b97\u3059\u308b\u3002\r\nValue *EndCond = End-&gt;Codegen();\r\nif (EndCond == 0) return EndCond;\r\n\r\n\/\/ 0.0\u3068\u6bd4\u8f03\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u6761\u4ef6\u3092\u771f\u507d\u5024\u306b\u5909\u63db\u3059\u308b\u3002\r\nEndCond = Builder.CreateFCmpONE(EndCond,\r\n                            ConstantFP::get(getGlobalContext(), APFloat(0.0)),\r\n                                &quot;loopcond&quot;);<\/pre>\n<p>\u6700\u5f8c\u306b\u3001\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3055\u305b\u308b\u3079\u304d\u304b\u3069\u3046\u304b\u3092\u6c7a\u5b9a\u3059\u308b\u305f\u3081\u306b\u3001\u30eb\u30fc\u30d7\u306e\u7d42\u4e86\u6761\u4ef6\u3092\u8a55\u4fa1\u3059\u308b\u3002<br \/>\n\u3053\u308c\u306f\u3001if\/then\/else\u306b\u304a\u3051\u308b\u6761\u4ef6\u306e\u8a55\u4fa1\u3068\u9177\u4f3c\u3057\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\/\/ \u30eb\u30fc\u30d7\u5f8c\u306e\u30d6\u30ed\u30c3\u30af\u3092\u751f\u6210\u3057\u633f\u5165\u3059\u308b\u3002\r\nBasicBlock *LoopEndBB = Builder.GetInsertBlock();\r\nBasicBlock *AfterBB = BasicBlock::Create(getGlobalContext(), &quot;afterloop&quot;, TheFunction);\r\n\r\n\/\/ LoopEndBB\u306e\u672b\u5c3e\u3078\u3001\u6761\u4ef6\u5206\u5c90\u3092\u633f\u5165\u3059\u308b\u3002\r\nBuilder.CreateCondBr(EndCond, LoopBB, AfterBB);\r\n\r\n\/\/ \u3053\u308c\u4ee5\u964d\u306e\u30b3\u30fc\u30c9\u306f\u3001AfterBB\u306e\u5f8c\u306b\u633f\u5165\u3055\u308c\u308b\u3002\r\nBuilder.SetInsertPoint(AfterBB);<\/pre>\n<p>\u3042\u3068\u306f\u30eb\u30fc\u30d7\u306e\u672c\u6587\u306e\u30b3\u30fc\u30c9\u306e\u5b8c\u6210\u306b\u3088\u3063\u3066\u3001\u5236\u5fa1\u30d5\u30ed\u30fc\u3092\u7de0\u3081\u304f\u304f\u308b\u5fc5\u8981\u304c\u3042\u308b\u3060\u3051\u3067\u3042\u308b\u3002<br \/>\n\u3053\u306e\u30b3\u30fc\u30c9\u306fend\u30d6\u30ed\u30c3\u30af\u3092\u8a18\u61b6\u3057\uff08phi\u30ce\u30fc\u30c9\u306e\u305f\u3081\u306b\uff09\u3001\u305d\u3057\u3066\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3059\u308b\u305f\u3081\u306eafterloop\u30d6\u30ed\u30c3\u30af\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u7d42\u4e86\u6761\u4ef6\u306e\u5024\u3092\u5143\u306b\u3001\u30eb\u30fc\u30d7\u3092\u307e\u3060\u7d9a\u3051\u308b\u304b\u3001\u30eb\u30fc\u30d7\u3092\u7d42\u308f\u3089\u305b\u308b\u304b\u3092\u9078\u629e\u3059\u308b\u305f\u3081\u306e\u6761\u4ef6\u5206\u5c90\u3092\u751f\u6210\u3059\u308b\u3002<br \/>\n\u3053\u306e\u5f8c\u306e\u30b3\u30fc\u30c9\u306f\u3001afterloop\u30d6\u30ed\u30c3\u30af\u306e\u5f8c\u306b\u51fa\u529b\u3055\u305b\u305f\u3044\u306e\u3067\u3001\u633f\u5165\u70b9\u3092AfterBB\u306b\u30bb\u30c3\u30c8\u3059\u308b\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">  \/\/ \u5f8c\u65b9\u306e\u305f\u3081\u3001phi\u30ce\u30fc\u30c9\u3078\u65b0\u3057\u3044\u30a8\u30f3\u30c8\u30ea\u3092\u8ffd\u52a0\u3059\u308b\u3002\r\n  Variable-&gt;addIncoming(NextVar, LoopEndBB);\r\n\r\n  \/\/ \u8986\u3044\u96a0\u3055\u308c\u3066\u3044\u305f\u5909\u6570\u3092\u5fa9\u5143\u3059\u308b\u3002\r\n  if (OldVal)\r\n    NamedValues&#x5B;VarName] = OldVal;\r\n  else\r\n    NamedValues.erase(VarName);\r\n\r\n  \/\/ for\u5f0f\u306f\u5e38\u306b0.0\u3092\u8fd4\u3059\u3002\r\n  return Constant::getNullValue(Type::getDoubleTy(getGlobalContext()));\r\n}<\/pre>\n<p>\u6700\u5f8c\u306e\u30b3\u30fc\u30c9\u306f\u3001\u3044\u304f\u3064\u304b\u306e\u5f8c\u7247\u4ed8\u3051\u3092\u51e6\u7406\u3059\u308b\u3002<br \/>\n\u3053\u3053\u3067\u306fNextVar\u5024\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30eb\u30fc\u30d7\u306ephi\u30ce\u30fc\u30c9\u3078\u6b21\u306e\u5024\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3002<br \/>\n\u305d\u306e\u5f8c\u3001for\u30eb\u30fc\u30d7\u306e\u5f8c\u306f\u30b9\u30b3\u30fc\u30d7\u5916\u3068\u306a\u308b\u306e\u3067\u3001\u30b7\u30f3\u30dc\u30eb\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u30eb\u30fc\u30d7\u5909\u6570\u3092\u53d6\u308a\u9664\u304f\u3002<br \/>\n\u6700\u5f8c\u306b\u3001for\u30eb\u30fc\u30d7\u306f\u5e38\u306b0.0\u3092\u8fd4\u3059\u3088\u3046\u30b3\u30fc\u30c9\u751f\u6210\u3059\u308b\u306e\u3067\u3001\u305d\u308c\u304cForExprAST::Codegen\u306e\u623b\u308a\u5024\u3068\u306a\u308b\u3002<\/p>\n<p>\u3053\u308c\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306b\u304a\u3051\u308b&#8221;\u4e07\u83ef\u93e1\u3078\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u306e\u8ffd\u52a0&#8221;\u306e\u7ae0\u3092\u5b8c\u4e86\u3059\u308b\u3002<br \/>\n\u3053\u306e\u7ae0\u3067\u306f\u30012\u3064\u306e\u5236\u5fa1\u30d5\u30ed\u30fc\u69cb\u9020\u3092\u8ffd\u52a0\u3057\u305f\u3002<br \/>\n\u305d\u3057\u3066\u3001\u305d\u308c\u3089\u3092\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u5b9f\u88c5\u8005\u306b\u5bfe\u3057\u3066\u3001\u7279\u306b\u77e5\u3063\u3066\u3044\u3066\u6b32\u3057\u3044LLLVM\u306e\u6027\u8cea\u306b\u3064\u3044\u3066\u8208\u5473\u3092\u8d77\u3053\u3055\u305b\u308b\u305f\u3081\u306b\u4f7f\u7528\u3057\u305f\u3002<br \/>\n\u6211\u3005\u306e\u30b5\u30fc\u30ac\u306e\u6b21\u306e\u7ae0\u3067\u306f\u3001\u3061\u3087\u3063\u3068\u9038\u8131\u3057\u3066\u3001\u6211\u3005\u306e\u7c97\u672b\u3067\u7d14\u771f\u306a\u8a00\u8a9e\u306b\u30e6\u30fc\u30b6\u30fc\u5b9a\u7fa9\u6f14\u7b97\u5b50\u3092\u8ffd\u52a0\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":[1,32],"tags":[466,467],"class_list":["post-2989","post","type-post","status-publish","format-standard","hentry","category-other","category-tech","tag-kaleidoscope","tag-llvm"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2989","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=2989"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/2989\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=2989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=2989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=2989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}