Skip to content

Instantly share code, notes, and snippets.

View modocache's full-sized avatar

Brian Gesiak modocache

View GitHub Profile
@modocache
modocache / swiftc -Xfrontend -debug-time-compilation
Last active April 12, 2022 22:34
Swift compilation time debugging options and their outputs
===-------------------------------------------------------------------------===
Swift compilation
===-------------------------------------------------------------------------===
Total Execution Time: 0.0307 seconds (0.1196 wall clock)
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
0.0043 ( 39.3%) 0.0091 ( 45.6%) 0.0133 ( 43.4%) 0.0547 ( 45.7%) performSema
0.0030 ( 27.5%) 0.0070 ( 35.2%) 0.0100 ( 32.5%) 0.0437 ( 36.5%) performSema-loadStdlib
0.0011 ( 10.0%) 0.0011 ( 5.4%) 0.0022 ( 7.0%) 0.0081 ( 6.7%) performSema-parseAndCheckTypes
0.0008 ( 7.0%) 0.0009 ( 4.4%) 0.0016 ( 5.3%) 0.0067 ( 5.6%) Type checking / Semantic analysis
@modocache
modocache / repro.cpp
Created February 28, 2020 11:34
A C++20 coroutines program that would not be pleasant to debug prior to some improvements I hope to make to LLVM.
#include <cstdio>
#include <experimental/coroutine>
using namespace std::experimental;
struct coro {
struct promise_type {
coro get_return_object() {
auto handle = coroutine_handle<promise_type>::from_promise(*this);
return coro(handle);
@modocache
modocache / CMakeLists.txt
Created February 25, 2020 00:56
An example project, named 'llvm-project/examples', that demonstrates a small LLVM subproject that runs lit tests that include googletest executables. (Pretend "-" in file names are "/".)
# The CMake files in this project contain several additional checks, or examples
# of how to use LLVM CMake functions. These additional checks can be disabled by
# setting this option to 'OFF'.
option(EXAMPLES_CMAKE_TESTS
"Enable tests related to the example project's CMake configuration." ON)
# Most LLVM projects define '<PROJECTNAME>_SOURCE_DIR' and '_BINARY_DIR'
# in their CMake files. These can be used in many ways, such as to
# specify the path to our tests in our lit test config, lit.site.cfg.py.in.
set(EXAMPLES_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
#include "gtest/gtest.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/NoFolder.h"
#include "llvm/Passes/PassBuilder.h"
static void createCalls(llvm::LLVMContext &context, llvm::Module &module) {
llvm::Type *voidType = llvm::Type::getVoidTy(context);
@modocache
modocache / example-outlined.cpp
Created November 30, 2019 23:57
Each additional instantiation of 'foo' in 'example.cpp' adds ~3 seconds of compile time. Each additional instantiation in 'example-outlined.cpp', on the other hand, adds an additional 0.01 seconds.
This file has been truncated, but you can view the full file.
#include <string>
#include <iostream>
void bar_prologue_outlined() {
std::cout << [](int a, float b) -> int {
return a * 10 + b * 5;
}(1, 2.f) << std::endl;
std::cout << [](int a, float b, double c) -> auto {
return [a, b, c](const std::string &d) -> int {
std::cout << d << std::endl;
@modocache
modocache / gist:2ef5e3916b97b97a1aa9e0126208aea9
Created March 30, 2016 01:05
Attaching LLDB to a Debug build of Swift
$ lldb -- ../build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc -dump-parse ~/GitHub/tmp/hello.swift
(lldb) target create "../build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc"
Current executable set to '../build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc' (x86_64).
(lldb) settings set -- target.run-args "-dump-parse" "/Users/bgesiak/GitHub/tmp/hello.swift"
(lldb) process launch --stop-at-entry
Process 91478 stopped
* thread #1: tid = 0x1bd329, 0x00007fff5fc01000 dyld`_dyld_start, stop reason = signal SIGSTOP
frame #0: 0x00007fff5fc01000 dyld`_dyld_start
dyld`_dyld_start:
-> 0x7fff5fc01000 <+0>: popq %rdi
@modocache
modocache / jenkinsBuild.sh
Created August 20, 2012 18:54
Jenkins Build Script
#!/bin/sh
set -e
BUILD_NUMBER=$1
die () {
echo >&2 "$@"
@modocache
modocache / PR36578.cpp
Last active March 19, 2018 22:01
The LLVM IR output from https://godbolt.org/g/Gw9UZq, obtained using `clang++ -fcoroutines-ts PR36578.cpp -emit-llvm -O1 -Xclang -disable-llvm-passes -S`, with (PR36578.ll) and without (PR36578.nosan.ll) `-fsanitize=null`.
#include <experimental/coroutine>
struct task {
struct promise_type {
task get_return_object() { return task(); }
std::experimental::suspend_never initial_suspend() { return {}; }
std::experimental::suspend_never final_suspend() { return {}; }
void return_void() {}
void unhandled_exception() {}
};
# It's relatively easy to run Apple XCTest on OS X and swift-corelibs-xctest on Linux.
# Just look at apple/swift-corelibs-foundation for an example.
#
# But it's pretty difficult to run swift-corelibs-xctest on OS X.
#
# Let's say we have the following file:
#
# // main.swift
# import XCTest
# XCTMain([])
Undefined symbols for architecture x86_64:
"__T0S2Sx26stringInterpolationSegment_tcs23CustomStringConvertibleRzs20TextOutputStreamableRzlufCSS_Tg5", referenced from:
_main in main.o
"__T0s27_allocateUninitializedArraySayxG_BptBwlFSS_Tg5", referenced from:
_main in main.o
"__T0s27_allocateUninitializedArraySayxG_BptBwlFyp_Tg5", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)