Skip to content

Instantly share code, notes, and snippets.

@modocache
modocache / repro.cpp
Created Feb 28, 2020
A C++20 coroutines program that would not be pleasant to debug prior to some improvements I hope to make to LLVM.
View repro.cpp
#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 Feb 25, 2020
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 "/".)
View CMakeLists.txt
# 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})
View FunctionAnalysisManagerCGSCCProxyTest.cpp
#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 Nov 30, 2019
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.
View example-outlined.cpp
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 {
@modocache
modocache / PR36578.cpp
Last active Mar 19, 2018
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`.
View PR36578.cpp
#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() {}
};
@modocache
modocache / swiftc -Xfrontend -debug-time-compilation
Last active Feb 23, 2021
Swift compilation time debugging options and their outputs
View swiftc -Xfrontend -debug-time-compilation
===-------------------------------------------------------------------------===
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
View gist:67e5fca72d50da9cde6c6880bd5ee966
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)
@modocache
modocache / gist:6f63a3185e54324a708e3c79ec1a9797
Created Aug 31, 2017
Generate a graphviz file for just the Swift compiler libraries, not the stdlib or SDK overlays
View gist:6f63a3185e54324a708e3c79ec1a9797
cmake \
-H$HOME/local/Source/apple/standalone/swift \
-B$HOME/local/Source/apple/standalone/swift-build
-G Ninja \
-DCMAKE_INSTALL_PREFIX=$HOME/local/Source/apple/standalone/swift-install \
-DCMAKE_BUILD_TYPE="Release" \
-DSWIFT_PATH_TO_LLVM_SOURCE=$HOME/local/Source/apple/standalone/swift-llvm \
-DSWIFT_PATH_TO_LLVM_BUILD=$HOME/local/Source/apple/standalone/swift-llvm-build \
-DSWIFT_PATH_TO_CLANG_SOURCE=$HOME/local/Source/apple/standalone/swift-clang \
-DSWIFT_PATH_TO_CLANG_BUILD=$HOME/local/Source/apple/standalone/swift-llvm-build \
View yo.cpp
#define NEW_MY_INT_CLASS(num) MyClass<int>(num);
int gX = 10;
template <class T>
class MyClass {
private:
T Member;
public:
MyClass(T Member): Member(Member) {}
View clang.out
clang++ -ftime-report yo.cpp -o yo
===-------------------------------------------------------------------------===
Miscellaneous Ungrouped Timers
===-------------------------------------------------------------------------===
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
0.0350 ( 48.6%) 0.0030 (100.0%) 0.0380 ( 50.7%) 0.0379 ( 51.1%) Code Generation Time
0.0370 ( 51.4%) 0.0000 ( 0.0%) 0.0370 ( 49.3%) 0.0363 ( 48.9%) LLVM IR Generation Time
0.0720 (100.0%) 0.0030 (100.0%) 0.0750 (100.0%) 0.0742 (100.0%) Total