LLVM学习笔记(58)

4.4. 目标机器对象

在main()函数的350行,TimeCompilations默认为1,可以通过隐藏的选项“-time-compilations”来指定它的值,它的作用是重复进行指定次数的编译,以得到更好的编译用时数据。而在这个循环中调用的compileModule(),则是执行编译的入口。

387     static int compileModule(char **argv, LLVMContext &Context) {

388       // Load the module to be compiled...

389       SMDiagnostic Err;

390       std::unique_ptr<Module> M;

391       std::unique_ptr<MIRParser> MIR;

392       Triple TheTriple;

393    

394       bool SkipModule = MCPU == "help" ||

395                         (!MAttrs.empty() && MAttrs.front() == "help");

396    

397       // If user just wants to list available options, skip module loading

398       if (!SkipModule) {

399         if (InputLanguage == "mir" ||

400             (InputLanguage == "" && StringRef(InputFilename).endswith_lower(".mir"))) {

401           MIR = createMIRParserFromFile(InputFilename, Err, Context);

402           if (MIR) {

403             M = MIR->parseIRModule();

404           } else

405             M = parseIRFile(InputFilename, Err, Context);

406          if (!M) {

407             Err.print(argv[0], errs() WithColor::error(errs(), argv[0]));

408             return 1;

409           }

410    

411         // If we are supposed to override the target triple, do so now.

412         if (!TargetTriple.empty())

413           M->setTargetTriple(Triple::normalize(TargetTriple));

414         TheTriple = Triple(M->getTargetTriple());

415       } else {

416         TheTriple = Triple(Triple::normalize(TargetTriple));

417       }

418    

419       if (TheTriple.getTriple().empty())

420         TheTriple.setTriple(sys::getDefaultTargetTriple());

421    

422       // Get the target specific parser.

423       std::string Error;

424       const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,

425                                                              Error);

426       if (!TheTarget) {

427         errs() << argv[0] << ": " << Error;

428         return 1;

430       }

431    

432       std::string CPUStr = getCPUStr(), FeaturesStr = getFeaturesStr();

433    

434       CodeGenOpt::Level OLvl = CodeGenOpt::Default;

435       switch (OptLevel) {

436       default:

437         errs()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值