Giving labels to intrinsics and getting the address

call void @llvm.branchlike(label %thelabel)

Is it possible to give a label/BasicBlock* to an intrinsic? Similar to
labels for branches. No label type is currently defined in
Intrinsics.td, but would it be possible to add it there and
ValueTypes.td?

But I also want to take the address and put it into a physical
register and emit a desired x86 instruction.

Assuming I have the label, I should be able to do this in the Lowering
process with inline asm. Where I want the x86 instruction to be "0x0f,
0x36, 0x00" and label address put into register a.

// Get the label from instrinsic's arguments..
BasicBlock* theLabel = ...magic?...

// Create a function type that takes a label and returns void
std::vector<const Type*>asmArgs;
asmArgs.push_back(Type::LabelTy);
FunctionType* asmFuncTy = FunctionType::get(Type::VoidTy, asmArgs, false);

// Create inline asm that emits the desired opcode and prepares register a
InlineAsm* asm = InlineAsm::get(asmFuncTy, ".byte 0x0f, 0x36, 0x00",
"{ax},~{dirflag},~{fpsr},~{flags},~{memory}", true);

// Create call to the inline asm giving "the label" to put in register a
CallInst* callAsm = new CallInst(asm, theLabel);

// Replace the intrinsic with the call
CI->replaceAllUsesWith(callAsm);

Actually, now that I think about it, maybe I shouldn't even bother
using an intrinsic and directly use this inline asm. Assuming that the
following transformation won't cause basic blocks to be considered
dead.

%x = call i1 @llvm.myintrinsic(label %otherPath) ; @myintrinsic always
returns true
br i1 %x, label %mainPath, label %otherPath

Hopefully, even if the CFG optimizer finds that mainPath is always
taken, because there's a use of %otherPath by @myintrinsic, that path
won't be used. Additionally, to the rest of the compiler, data (e.g.,
%x) flows into *both* %mainPath and %otherPath.

Ed