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 [...]
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 [...]
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 [...]
To create the debug metadata for the function, we have to create a type for the signature first, and then the metadata for the function itself. This is similar to [...]
To allow source-level debugging, we have to add debug information. Support for debug information in LLVM uses debug metadata to describe the types of the source language and other static [...]
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 [...]
To demonstrate the problem, let’s look at the following function:void doSomething(int *p, float *q) { *p = 42; *q = 3.1425;} The optimizer cannot decide if the pointers, p and q, point [...]