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 [...]
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 [...]
The file is a module in tinylang, which makes it the compilation unit for LLVM. This carries a lot of information: bool IsOptimized = false;llvm::StringRef CUFlags;unsigned ObjCRunTimeVersion = 0;llvm::StringRef SplitName;llvm::DICompileUnit::DebugEmissionKind [...]
To support TBAA, we must add a new CGTBAA class. This class is responsible for generating the metadata nodes. Furthermore, we make the CGTBAA class a member of the CGModule [...]
To create the metadata, we must use the llvm::MDBuilder class, which is declared in the llvm/IR/MDBuilder.h header file. The data itself is stored in instances of the llvm::MDNode and llvm::MDString [...]
With these definitions, we can now define a relation on the access tags, which is used to evaluate if two pointers may alias each other or not. Let’s take a [...]