Implementing a new pass – Optimizing IR-3Implementing a new pass – Optimizing IR-3
The functionality of our new pass is now implemented. To be able to use our pass, we need to register it with the PassBuilder object. This can happen in two [...]
The functionality of our new pass is now implemented. To be able to use our pass, we need to register it with the PassBuilder object. This can happen in two [...]
NOTETwo macros can be used to define a counter variable. If you use the STATISTIC macro, then the statistic value will only be collected in a debug build if assertions [...]
A pass can perform arbitrary complex transformations on the LLVM IR. To illustrate the mechanics of adding a new pass, we add a pass that performs a simple instrumentation.To investigate [...]
The LLVM core libraries optimize the IR that your compiler creates and turn it into object code. This giant task is broken down into separate steps called passes. These passes [...]
LLVM uses a series of passes to optimize the IR. A pass operates on a unit of IR, such as a function or a module. The operation can be a [...]
void CGDebugInfo::emitProcedureEnd(ProcedureDeclaration *Decl, llvm::Function *Fn) {if (Fn && Fn->getSubprogram())DBuilder.finalizeSubprogram(Fn->getSubprogram());closeScope();} void CGDebugInfo::finalize() { DBuilder.finalize(); } Debug information should only be generated if the user requested it. This means that we will [...]
llvm::DIType *CGDebugInfo::getAliasType(AliasTypeDeclaration *Ty) {return DBuilder.createTypedef(getType(Ty->getType()), Ty->getName(),CU->getFile(), getLineNumber(Ty->getLocation()),getScope());} llvm::DIType *CGDebugInfo::getArrayType(ArrayTypeDeclaration *Ty) {auto *ATy =llvm::cast(CGM.convertType(Ty));const llvm::DataLayout &DL =CGM.getModule()->getDataLayout();Expr *Nums = Ty->getNums();uint64_t NumElements =llvm::cast(Nums)->getValue().getZExtValue();llvm::SmallVector Subscripts;Subscripts.push_back(DBuilder.getOrCreateSubrange(0, NumElements));return DBuilder.createArrayType(DL.getTypeSizeInBits(ATy) * 8,1 << Log2(DL.getABITypeAlign(ATy)), getType(Ty->getType()),DBuilder.getOrCreateArray(Subscripts));} llvm::DIType [...]
We encapsulate the generation of debug metadata in the new CGDebugInfo class. Additionally, we place the declaration in the tinylang/CodeGen/CGDebugInfo.h header file and the definition in the tinylang/CodeGen/CGDebugInfo.cpp file.The CGDebugInfo [...]
A debugger allows a programmer to step through an application line by line. For this, the debugger needs to know which machine instructions belong to which line in the source. [...]
Again, we have to specify a source location for the variable. An instance of llvm::DILocation is a container that holds the line and column of a location associated with a [...]