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 [...]
To be useful, the type metadata described in the previous section needs to be associated with variables of the source program. For a global variable, this is pretty easy. The [...]
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 [...]
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 [...]
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 [...]
The IR for the division is generated inside the visit(BinaryOp &) method. Instead of just generating a sdiv instruction, we must generate an IR to compare the divisor with 0. [...]